source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.Tools.SchemaBuilder/SchemaBuilderWindow.cs@ 1492

Last change on this file since 1492 was 1146, checked in by Sam Habiel, 14 years ago

Initial Import of BMX4

File size: 16.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using IndianHealthService.BMXNet.WinForm;
9using IndianHealthService.BMXNet.Services;
10using IndianHealthService.BMXNet.WinForm.Configuration;
11
12namespace IndianHealthService.BMXNet.Tools.SchemaBuilder
13{
14 public partial class SchemaBuilderWindow : Form
15 {
16 public SchemaBuilderWindow()
17 {
18 InitializeComponent();
19 }
20
21 private BMXSchemaDoc _document;
22
23 public BMXSchemaDoc Document
24 {
25 get { return _document; }
26 set { _document = value; }
27 }
28
29 private string _appName = "BMXSchemaBuilder";
30
31 public string AppName
32 {
33 get { return _appName; }
34 set { _appName = value; }
35 }
36
37 private bool m_bDragDropStart;
38
39 #region Methods
40
41
42 protected override void Dispose(bool disposing)
43 {
44 if (disposing)
45 {
46 if (components != null)
47 {
48 components.Dispose();
49 }
50 }
51 base.Dispose(disposing);
52 }
53
54
55
56 private WinFramework _framework = null;
57
58 public WinFramework Framework
59 {
60 get { return _framework; }
61 set { _framework = value; }
62 }
63
64 private RemoteSession _remoteSession = null;
65
66 public RemoteSession RemoteSession
67 {
68 get { return _remoteSession; }
69 set { _remoteSession = value; }
70 }
71
72
73
74 private void frmMain_Load(object sender, System.EventArgs e)
75 {
76 this.Login(false);
77 }
78
79 protected void Login(bool isServerSwitch)
80 {
81 try
82 {
83 if (this.Framework == null)
84 {
85 this.Framework = WinFramework.CreateWithNetworkBroker(true);
86 this.Framework.LoadConnectionSpecs(LocalPersistentStore.CreateDefaultStorage(true), "SchemaBuilder");
87
88 LoginProcess login = this.Framework.CreateLoginProcess();
89 login.IsSwitchServerModeEnabled = isServerSwitch;
90
91 if (login.HasDefaultConnectionWithUseWindowsAuth)
92 {
93 login.AttemptWindowsAuthLogin();
94 }
95
96 if (!login.WasLoginAttempted || !login.WasSuccessful)
97 {
98 login.AttemptUserInputLogin("Schema Builder Login", 3, true, this);
99 }
100
101 if (!login.WasSuccessful)
102 {
103 this.Close();
104 return;
105 }
106 LocalSession local = this.Framework.LocalSession;
107
108 if ((this.Framework.Context.User.Division == null) && !this.Framework.AttemptUserInputSetDivision("Set Initial Division", this))
109 {
110 this.Close();
111 return;
112 }
113
114 this.RemoteSession = this.Framework.PrimaryRemoteSession;
115
116
117 this.UpdateTitle();
118 this.SetGridStyle();
119 this.LoadFileTree();
120 this.LoadNewSchema();
121 this.FormatSchemaFieldsGrid();
122 }
123 }
124 catch (Exception problem)
125 {
126 this.Framework.LocalSession.Notify(this.AppName, problem);
127 }
128 }
129
130 private void UpdateTitle()
131 {
132
133 }
134
135 private void LoadFileTree()
136 {
137 try
138 {
139 tvFile.BeginUpdate();
140 tvFile.Nodes.Clear();
141
142 DataTable dtFile = this.RemoteSession.TableFromCommand("BMX ADO SS^FILEMAN FILES^^B~A~ZZZ~5000");
143
144 //DataView dvFile = new DataView(dtFile);
145
146 this.AddSubFileNodes(tvFile.Nodes, dtFile);
147 }
148 catch (Exception ex)
149 {
150 throw ex;
151 }
152 finally
153 {
154 tvFile.EndUpdate();
155 }
156 }
157
158 private DataTable GetSubfiles(string sFileNum)
159 {
160 return this.RemoteSession.TableFromCommand("BMX ADO SS^SUBFILES^^~~~~~SFIT~BMXADOS1~" + sFileNum + "~");
161 }
162
163 public void LoadNewSchema()
164 {
165 this.Document = new BMXSchemaDoc();
166 this.Document.RemoteSession = this.RemoteSession;
167 this.Document.NewSchema();
168 this.ugrdSchemaFields.DataSource = this.Document.SchemaFields;
169 this.Text = this.AppName + " - " + this.Document.SchemaName;
170 string sGridText = "Schema File: ";
171 this.ugrdSchemaFields.Text = sGridText;
172 }
173
174
175 #endregion Methods
176
177 #region TreeNode
178
179 private void AddSubFileNodes(TreeNodeCollection nodParentColl, DataTable dt)
180 {
181 string sFileName;
182 string sExpand;
183 string sFileNumber;
184 DataView dvFile = new DataView(dt);
185 DataRowView drv;
186 TreeNode tn;
187 for (int j = 0; j < dvFile.Count; j++)
188 {
189 drv = dvFile[j];
190 sFileName = drv["NAME"].ToString();
191 sFileNumber = drv["BMXIEN"].ToString();
192 sExpand = drv["SUBFILES PRESENT?"].ToString();
193 tn = new TreeNode(sFileName);
194 tn.Text = sFileName;
195 tn.Tag = sFileNumber;
196 if (sExpand == "+")
197 {
198 tn.Nodes.Add(".");
199 }
200 nodParentColl.Add(tn);
201 }
202 }
203
204 private void tvFile_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
205 {
206 try
207 {
208 string sNode = e.Node.Text;
209 string sFileNumber = e.Node.Tag.ToString();
210 string sCmd = "BMX ADO SS^FIELDS^^~~~~~FLDIT~BMXADOS1~" + sFileNumber + "~";
211 DataTable dtFields = this.RemoteSession.TableFromCommand(sCmd,new DataSet(),"FIELDS");
212
213 this.grdFieldList.DataSource = dtFields;
214 }
215 catch (Exception ex)
216 {
217 this.Framework.LocalSession.Notify("Error in " + this.AppName, ex);
218 }
219
220 }
221
222 private void tvFile_BeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
223 {
224 try
225 {
226 string sNode = e.Node.Text;
227 string sFileNumber = e.Node.Tag.ToString();
228 e.Node.Nodes.Clear();
229 DataTable dtSubFiles = this.GetSubfiles(sFileNumber);
230 AddSubFileNodes(e.Node.Nodes, dtSubFiles);
231 }
232 catch (Exception ex)
233 {
234 this.Framework.LocalSession.Notify("Error in " + this.AppName, ex);
235 }
236 }
237
238
239 #endregion TreeNode
240
241 #region MouseHandlers
242
243 private void grdFieldList_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
244 {
245 m_bDragDropStart = false;
246 }
247
248 private void grdFieldList_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
249 {
250 if (!m_bDragDropStart)
251 {
252 m_bDragDropStart = true;
253 string[] sData = new string[2];
254 DataGridCell dCell = grdFieldList.CurrentCell;
255 dCell.ColumnNumber = 0;
256 sData[0] = grdFieldList[dCell].ToString();
257 dCell.ColumnNumber = 1;
258 sData[1] = grdFieldList[dCell].ToString();
259 DragDropEffects effect = DoDragDrop(sData, DragDropEffects.Move);
260 }
261 }
262
263 private void grdFieldList_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
264 {
265 }
266
267 #endregion MouseHandlers
268
269
270
271 #region UltraGrid
272
273 private void SetGridStyle()
274 {
275 //Fileman Fields Grid
276 DataGridTableStyle tsFields = new DataGridTableStyle();
277 tsFields.MappingName = "FIELDS";
278 tsFields.ReadOnly = true;
279 tsFields.RowHeadersVisible = false;
280
281 // Add FIELD NUMBER column style.
282 DataGridColumnStyle colFieldNumber = new DataGridTextBoxColumn();
283 colFieldNumber.MappingName = "BMXIEN";
284 colFieldNumber.HeaderText = "Field Number";
285 colFieldNumber.Width = 100;
286 tsFields.GridColumnStyles.Add(colFieldNumber);
287 // Add FIELD NAME column style.
288 DataGridColumnStyle colFieldName = new DataGridTextBoxColumn();
289 colFieldName.MappingName = "NAME";
290 colFieldName.HeaderText = "Field Name";
291 colFieldName.Width = 290;
292 tsFields.GridColumnStyles.Add(colFieldName);
293
294 this.grdFieldList.TableStyles.Add(tsFields);
295 }
296
297 private void FormatSchemaFieldsGrid()
298 {
299 Infragistics.Win.ValueListsCollection vlSchemaFields;
300 Infragistics.Win.UltraWinGrid.UltraGridBand bndSchemaFields;
301
302 vlSchemaFields = ugrdSchemaFields.DisplayLayout.ValueLists;
303 vlSchemaFields.Add("YesNo");
304 vlSchemaFields["YesNo"].ValueListItems.Add("YES");
305 vlSchemaFields["YesNo"].ValueListItems.Add("NO");
306 vlSchemaFields.Add("DataType");
307 vlSchemaFields["DataType"].ValueListItems.Add("TEXT");
308 vlSchemaFields["DataType"].ValueListItems.Add("DATE");
309 vlSchemaFields["DataType"].ValueListItems.Add("INTEGER");
310 vlSchemaFields["DataType"].ValueListItems.Add("NUMBER");
311
312 bndSchemaFields = ugrdSchemaFields.DisplayLayout.Bands[0];
313 bndSchemaFields.Columns["READ ONLY"].ValueList = vlSchemaFields["YesNo"];
314 bndSchemaFields.Columns["KEY FIELD"].ValueList = vlSchemaFields["YesNo"];
315 bndSchemaFields.Columns["NULL ALLOWED"].ValueList = vlSchemaFields["YesNo"];
316 bndSchemaFields.Columns["IEN AUTOMATICALLY INCLUDED"].ValueList = vlSchemaFields["YesNo"];
317 bndSchemaFields.Columns["DATA TYPE"].ValueList = vlSchemaFields["DataType"];
318
319 bndSchemaFields.Columns["BMXIEN"].Hidden = true;
320 bndSchemaFields.Columns["BMXIEN1"].Hidden = true;
321
322 }
323
324 private void ugrdSchemaFields_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
325 {
326 try
327 {
328 m_bDragDropStart = false;
329
330 string[] sData = (string[])e.Data.GetData(typeof(string[]));
331 DataTable dt = (DataTable)ugrdSchemaFields.DataSource;
332 DataRow dr = dt.NewRow();
333 double nField = Convert.ToDouble(sData[0]);
334 string sField = nField.ToString(".#####");
335 dr["FIELD NUMBER"] = sField;
336 dr["COLUMN HEADER"] = sData[1];
337 dt.Rows.Add(dr);
338 Document.SchemaFields = dt;
339 ugrdSchemaFields.DataSource = Document.SchemaFields;
340 ugrdSchemaFields.Refresh();
341 }
342 catch (Exception ex)
343 {
344 this.Framework.LocalSession.Notify("Error in " + this.AppName, ex);
345 }
346 }
347
348 private void ugrdSchemaFields_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
349 {
350
351 if (e.Data.GetDataPresent(typeof(string[])))
352 {
353 string[] sData = (string[])e.Data.GetData(typeof(string[]));
354 DataTable dt = (DataTable)ugrdSchemaFields.DataSource;
355 double nField = Convert.ToDouble(sData[0]);
356 string sField = nField.ToString(".#####");
357 string header = sData[1];
358 //check if present
359
360
361
362 if ((e.KeyState & 8) == 8) //CTRL key
363 {
364 e.Effect = DragDropEffects.Copy;
365 }
366 else
367 {
368 e.Effect = DragDropEffects.Move;
369 }
370 }
371 else
372 {
373 e.Effect = DragDropEffects.None;
374 }
375
376
377 }
378
379 private void ugrdSchemaFields_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
380 {
381 e.Layout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortMulti;
382 }
383 #endregion UltraGrid
384
385 #region MenuHandlers
386
387 private void mnuHelpAbout_Click(object sender, System.EventArgs e)
388 {
389 new AboutDialog().ShowDialog(this);
390 }
391
392 private void mnuViewFiles_Click(object sender, System.EventArgs e)
393 {
394 mnuViewFiles.Checked = !(mnuViewFiles.Checked);
395 pnlFileField.Visible = mnuViewFiles.Checked;
396 }
397
398 private void mnuViewStatusBar_Click(object sender, System.EventArgs e)
399 {
400 mnuViewStatusBar.Checked = !(mnuViewStatusBar.Checked);
401 this.statusBar1.Visible = mnuViewStatusBar.Checked;
402 }
403
404 private void mnuFileNewSchema_Click(object sender, System.EventArgs e)
405 {
406 this.LoadNewSchema();
407 }
408
409 private void mnuFileSave_Click(object sender, System.EventArgs e)
410 {
411 try
412 {
413 if (Document.SchemaIEN == 0)
414 {
415 //prompt for a name
416 DSaveSchema dSave = new DSaveSchema();
417 if (dSave.ShowDialog() == DialogResult.Cancel)
418 return;
419 this.Document.SaveSchema(dSave.SchemaName);
420 this.Text = this.AppName + " - " + Document.SchemaName;
421
422 }
423 else
424 {
425 this.Document.SaveSchema();
426 }
427 }
428 catch (Exception ex)
429 {
430 this.Framework.LocalSession.Notify("Error in " + this.AppName, ex);
431 }
432 }
433
434 private void mnuFileOpenSchema_Click(object sender, System.EventArgs e)
435 {
436 //Display a dialog to select from existing schemas
437 DSelectSchema dss = new DSelectSchema();
438 dss.InitializePage(this.RemoteSession);
439 if (dss.ShowDialog() == DialogResult.Cancel)
440 return;
441
442 Document.OpenSchema(dss.SchemaIEN, dss.SchemaName, dss.FileNumber);
443 ugrdSchemaFields.DataSource = Document.SchemaFields;
444 ugrdSchemaFields.Refresh();
445
446 string sGridText = "Schema File: " + Document.SchemaFileName + " (Number " + Document.SchemaFileNumber.ToString() + ")";
447 if (Document.SchemaReadOnlyDataset == true)
448 sGridText += " [Dataset is ReadOnly]";
449 this.ugrdSchemaFields.Text = sGridText;
450 this.Text = this.AppName + " - " + Document.SchemaName;
451 }
452
453 private void mnuSetSchemaFile_Click(object sender, System.EventArgs e)
454 {
455 Document.SchemaFileName = this.tvFile.SelectedNode.Text;
456 Document.SchemaFileNumber = Convert.ToDouble(this.tvFile.SelectedNode.Tag);
457 ugrdSchemaFields.Text = "Schema File: " + Document.SchemaFileName;
458 ugrdSchemaFields.Text += " (Number " + Document.SchemaFileNumber.ToString() + ")";
459 }
460
461
462 #endregion MenuHandlers
463
464 private void mnuFileExit_Click(object sender, EventArgs e)
465 {
466 this.Close();
467 }
468
469 private void SchemaBuilderWindow_FormClosed(object sender, FormClosedEventArgs e)
470 {
471 this.Framework.Close();
472 }
473
474 private void changeRpmsLogin_Click(object sender, EventArgs e)
475 {
476 this.tvFile.Nodes.Clear();
477 this.ugrdSchemaFields.DisplayLayout.ValueLists.Clear();
478 this.grdFieldList.DataSource = null;
479 this.ugrdSchemaFields.DataSource = null;
480 this.ugrdSchemaFields.Text = "";
481 this.grdFieldList.TableStyles.Clear();
482
483 this.Framework.Close();
484 this.Framework = null;
485 this.Login(true);
486
487 }
488
489
490
491 }
492}
Note: See TracBrowser for help on using the repository browser.