Subversion Repositories DevTools

Rev

Rev 2141 | Rev 2153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2141 Rev 2151
Line 6... Line 6...
6
using System.Text;
6
using System.Text;
7
using System.IO;
7
using System.IO;
8
 
8
 
9
namespace EA_ReqPro
9
namespace EA_ReqPro
10
{
10
{
11
	/// <summary>
11
   /// <summary>
12
	/// Summary description for ExportToReqProCSVForm.
12
   /// Summary description for ExportToReqProCSVForm.
13
	/// </summary>
13
   /// </summary>
14
	public class ExportToReqProCSVForm : System.Windows.Forms.Form
14
   public class ExportToReqProCSVForm : System.Windows.Forms.Form
15
	{
15
   {
16
      private StringBuilder csv_text;
16
      private StringBuilder csv_text;
17
 
17
 
18
      private System.Windows.Forms.Button button_ok;
18
      private System.Windows.Forms.Button button_ok;
19
      private System.Windows.Forms.Button button_cancel;
19
      private System.Windows.Forms.Button button_cancel;
20
      private System.Windows.Forms.TextBox textBox_tag;
20
      private System.Windows.Forms.TextBox textBox_tag;
21
      private System.Windows.Forms.Label label1;
21
      private System.Windows.Forms.Label label1;
22
      private System.Windows.Forms.CheckBox checkBox_IgnoreWronglyTaggedItems;
22
      private System.Windows.Forms.CheckBox checkBox_IgnoreWronglyTaggedItems;
-
 
23
 
23
		/// <summary>
24
      /// <summary>
24
		/// Required designer variable.
25
      /// Required designer variable.
25
		/// </summary>
26
      /// </summary>
26
		private System.ComponentModel.Container components = null;
27
      private System.ComponentModel.Container components = null;
27
 
28
 
28
		public ExportToReqProCSVForm()
29
      public ExportToReqProCSVForm()
29
		{
30
      {
30
			//
31
         //
31
			// Required for Windows Form Designer support
32
         // Required for Windows Form Designer support
32
			//
33
         //
33
			InitializeComponent();
34
         InitializeComponent();
34
 
35
 
35
			//
36
         //
36
			// TODO: Add any constructor code after InitializeComponent call
37
         // TODO: Add any constructor code after InitializeComponent call
37
			//
38
         //
38
		}
39
      }
39
 
40
 
40
		/// <summary>
41
      /// <summary>
41
		/// Clean up any resources being used.
42
      /// Clean up any resources being used.
42
		/// </summary>
43
      /// </summary>
43
		protected override void Dispose( bool disposing )
44
      protected override void Dispose( bool disposing )
44
		{
45
      {
45
			if( disposing )
46
         if( disposing )
46
			{
47
         {
47
				if(components != null)
48
            if(components != null)
48
				{
49
            {
49
					components.Dispose();
50
               components.Dispose();
50
				}
51
            }
51
			}
52
         }
52
			base.Dispose( disposing );
53
         base.Dispose( disposing );
53
		}
54
      }
54
 
55
 
55
		#region Windows Form Designer generated code
56
      #region Windows Form Designer generated code
56
		/// <summary>
57
      /// <summary>
57
		/// Required method for Designer support - do not modify
58
      /// Required method for Designer support - do not modify
58
		/// the contents of this method with the code editor.
59
      /// the contents of this method with the code editor.
59
		/// </summary>
60
      /// </summary>
60
		private void InitializeComponent()
61
      private void InitializeComponent()
61
		{
62
      {
62
         this.button_ok = new System.Windows.Forms.Button();
63
         this.button_ok = new System.Windows.Forms.Button();
63
         this.button_cancel = new System.Windows.Forms.Button();
64
         this.button_cancel = new System.Windows.Forms.Button();
64
         this.textBox_tag = new System.Windows.Forms.TextBox();
65
         this.textBox_tag = new System.Windows.Forms.TextBox();
65
         this.label1 = new System.Windows.Forms.Label();
66
         this.label1 = new System.Windows.Forms.Label();
66
         this.checkBox_IgnoreWronglyTaggedItems = new System.Windows.Forms.CheckBox();
67
         this.checkBox_IgnoreWronglyTaggedItems = new System.Windows.Forms.CheckBox();
Line 117... Line 118...
117
         this.Controls.Add(this.checkBox_IgnoreWronglyTaggedItems);
118
         this.Controls.Add(this.checkBox_IgnoreWronglyTaggedItems);
118
         this.Controls.Add(this.textBox_tag);
119
         this.Controls.Add(this.textBox_tag);
119
         this.Controls.Add(this.label1);
120
         this.Controls.Add(this.label1);
120
         this.Controls.Add(this.button_cancel);
121
         this.Controls.Add(this.button_cancel);
121
         this.Controls.Add(this.button_ok);
122
         this.Controls.Add(this.button_ok);
-
 
123
         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
122
         this.Name = "ExportToReqProCSVForm";
124
         this.Name = "ExportToReqProCSVForm";
-
 
125
         this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
123
         this.Text = "Export To ReqPro CSV";
126
         this.Text = "Export To ReqPro CSV";
-
 
127
         this.TopMost = true;
124
         this.ResumeLayout(false);
128
         this.ResumeLayout(false);
125
 
129
 
126
      }
130
      }
127
		#endregion
131
      #endregion
128
 
132
 
129
 
133
 
130
      /// <summary>
134
      /// <summary>
131
      /// Export the requirements found in the selected package to a ReqPro CSV file.
135
      /// Export the requirements found in the selected package to a ReqPro CSV file.
132
      /// </summary>
136
      /// </summary>
133
      /// <param name="ea_repository"></param>
137
      /// <param name="ea_repository"></param>
134
      public void Export(EA.Repository ea_repository)
138
      public void Export()
135
      {
139
      {
136
         object o;
140
         object o;
137
         EA.ObjectType type;
141
         EA.ObjectType type;
138
         type = ea_repository.GetTreeSelectedItem(out o);
142
         type = Main.EA_Repository.GetTreeSelectedItem(out o);
139
         if (type == EA.ObjectType.otPackage)
143
         if (type == EA.ObjectType.otPackage)
140
         {
144
         {
141
            EA.Package EA_ParentPackage = (EA.Package)o;
145
            EA.Package EA_ParentPackage = (EA.Package)o;
142
 
146
 
143
            // Choose CSV file name and location
147
            // Choose CSV file name and location
144
            SaveFileDialog ofd = new SaveFileDialog();
148
            SaveFileDialog ofd = new SaveFileDialog();
145
            ofd.Title = "Select Name of Export file";
149
            ofd.Title = "Select Name of Export file";
146
            ofd.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
150
            ofd.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
147
            DialogResult dlgRes = ofd.ShowDialog();
151
            DialogResult dlgRes = ofd.ShowDialog();
148
            if (dlgRes == DialogResult.OK)
152
            if (dlgRes == DialogResult.OK)
149
            {
153
            {
150
               ea_repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
154
               Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
151
               ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exporting to ReqPro CSV File", -1);
155
               Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exporting to ReqPro CSV File", -1);
152
 
156
 
153
               // Begin to build the CSV file content, starting with the header line ReqPro requires.
157
               // Begin to build the CSV file content, starting with the header line ReqPro requires.
154
               csv_text = new StringBuilder();
158
               csv_text = new StringBuilder();
155
               csv_text.Append( String.Format("\"{0} Tag\",\"Requirement text\",\"Name\"\r\n", textBox_tag.Text));
159
               csv_text.Append( String.Format("\"{0} Tag\",\"Requirement text\",\"Name\"\r\n", textBox_tag.Text));
156
 
160
 
157
               // recursively descend the package
161
               // recursively descend the package
158
               parse_package(ea_repository, EA_ParentPackage, 0);
162
               parse_package(EA_ParentPackage, 0);
159
 
163
 
160
               // write the CSV file content
164
               // write the CSV file content
161
               TextWriter tw = new StreamWriter( ofd.FileName );
165
               TextWriter tw = new StreamWriter( ofd.FileName );
162
               tw.WriteLine(csv_text.ToString());
166
               tw.WriteLine(csv_text.ToString());
163
               tw.Close();
167
               tw.Close();
164
               MessageBox.Show("Export Completed");
168
               MessageBoxEx.Show("Export Completed");
165
            }
169
            }
166
         }
170
         }
167
      }
171
      }
168
 
172
 
169
      /// <summary>
173
      /// <summary>
Line 173... Line 177...
173
      /// by the user for the export.
177
      /// by the user for the export.
174
      /// </summary>
178
      /// </summary>
175
      /// <param name="ea_repository"></param>
179
      /// <param name="ea_repository"></param>
176
      /// <param name="thePackage"></param>
180
      /// <param name="thePackage"></param>
177
      /// <param name="recurse_level"></param>
181
      /// <param name="recurse_level"></param>
178
      private void parse_package(EA.Repository ea_repository, EA.Package thePackage, int recurse_level)
182
      private void parse_package(EA.Package thePackage, int recurse_level)
179
      {
183
      {
180
         // consume elements - we have to use a special sorting class here because of peculiarties
184
         // consume elements - we have to use a special sorting class here because of peculiarties
181
         // in the way EA holds the elements in the collections. 
185
         // in the way EA holds the elements in the collections.
182
         EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
186
         EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
183
         EA.Element theElement = null;
187
         EA.Element theElement = null;
184
         int theElementsRelativeLevel = 0;
188
         int theElementsRelativeLevel = 0;
185
         if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
189
         if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
186
         {
190
         {
Line 201... Line 205...
201
                     string name = theElement.Name.Substring( pos, theElement.Name.Length-pos );
205
                     string name = theElement.Name.Substring( pos, theElement.Name.Length-pos );
202
                     name = name.Trim();
206
                     name = name.Trim();
203
 
207
 
204
                     csv_text.Append( String.Format( "\"{0}\",\"{1}\",\"{2}\"\r\n", tag, theElement.Notes, name) );
208
                     csv_text.Append( String.Format( "\"{0}\",\"{1}\",\"{2}\"\r\n", tag, theElement.Notes, name) );
205
 
209
 
206
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exported : " + theElement.Name, theElement.ElementID );
210
                     Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exported : " + theElement.Name, theElement.ElementID );
207
                  }
211
                  }
208
                  // else if user has asked us to ignore wrong tags...
212
                  // else if user has asked us to ignore wrong tags...
209
                  else if (false == checkBox_IgnoreWronglyTaggedItems.Checked)
213
                  else if (false == checkBox_IgnoreWronglyTaggedItems.Checked)
210
                  {
214
                  {
211
                     csv_text.Append( String.Format( "\"{0}\",\"{1}\",\"{2}\"\r\n", textBox_tag.Text, theElement.Notes, theElement.Name) );
215
                     csv_text.Append( String.Format( "\"{0}\",\"{1}\",\"{2}\"\r\n", textBox_tag.Text, theElement.Notes, theElement.Name) );
212
 
216
 
213
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exported : " + theElement.Name, theElement.ElementID );
217
                     Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Exported : " + theElement.Name, theElement.ElementID );
214
                  }
218
                  }
215
                  // else ignore this requirement
219
                  // else ignore this requirement
216
                  else
220
                  else
217
                  {
221
                  {
218
                     ea_repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Ignored : " + theElement.Name, theElement.ElementID );
222
                     Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Ignored : " + theElement.Name, theElement.ElementID );
219
                  }
223
                  }
220
               }
224
               }
221
            } while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
225
            } while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
222
         }
226
         }
223
 
227
 
224
         // Scan through the packages within this package.
228
         // Scan through the packages within this package.
225
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
229
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
226
         {
230
         {
227
            // recurse
231
            // recurse
228
            parse_package(ea_repository, lowerLevelPackage, recurse_level+1);
232
            parse_package(lowerLevelPackage, recurse_level+1);
229
         }
233
         }
230
      }
234
      }
231
 
-
 
232
	}
235
   }
233
}
236
}