-
Notifications
You must be signed in to change notification settings - Fork 7
/
ProcessingManager.cs
1147 lines (983 loc) · 37.8 KB
/
ProcessingManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#r "System.Drawing"
using System.Drawing;
// Parameters
int formWidth = 500;
int formHeight = 700;
string batchName = string.Empty;
string batchNameFull = string.Empty;
string processingType = string.Empty;
bool IsExpOrCol = false;
bool hasSaved = false;
bool seqEnabled = false;
bool darkModeEnabled = false;
int mp = 0;
string[] processingTypeList = {"automatic","full","calculate","clearValues","defragment","dataOnly"};
string[] infoList = {
"Select the tables/partitions to process in this batch."
,"Here is a summary of the selected batch."
};
string batchPrefix = "TabularProcessingBatch_";
int batchPrefixLen = batchPrefix.Length;
var sb_ExportScript = new System.Text.StringBuilder();
string newline = Environment.NewLine;
string ebiURL = @"https://www.elegantbi.com";
// Start screen
System.Windows.Forms.Form newForm = new System.Windows.Forms.Form();
System.Windows.Forms.Panel startPanel = new System.Windows.Forms.Panel();
System.Windows.Forms.RadioButton newbatchButton = new System.Windows.Forms.RadioButton();
System.Windows.Forms.RadioButton existingbatchButton = new System.Windows.Forms.RadioButton();
System.Windows.Forms.ComboBox batchComboBox = new System.Windows.Forms.ComboBox();
System.Windows.Forms.Button goButton = new System.Windows.Forms.Button();
System.Windows.Forms.Label homeToolLabel = new System.Windows.Forms.Label();
System.Windows.Forms.LinkLabel ebiHome = new System.Windows.Forms.LinkLabel();
// Main screen
System.Windows.Forms.Panel topPanel = new System.Windows.Forms.Panel();
System.Windows.Forms.Panel namePanel = new System.Windows.Forms.Panel();
System.Windows.Forms.Panel typePanel = new System.Windows.Forms.Panel();
System.Windows.Forms.Panel infoPanel = new System.Windows.Forms.Panel();
System.Windows.Forms.Panel treePanel = new System.Windows.Forms.Panel();
System.Net.WebClient w = new System.Net.WebClient();
System.Windows.Forms.TreeView treeView = new System.Windows.Forms.TreeView();
System.Windows.Forms.Label typeLabel = new System.Windows.Forms.Label();
System.Windows.Forms.ComboBox typeComboBox = new System.Windows.Forms.ComboBox();
System.Windows.Forms.CheckBox sequenceCheckBox = new System.Windows.Forms.CheckBox();
System.Windows.Forms.CheckBox summarySequenceCheckBox = new System.Windows.Forms.CheckBox();
System.Windows.Forms.TextBox batchNameTextBox = new System.Windows.Forms.TextBox();
System.Windows.Forms.ComboBox batchNameComboBox = new System.Windows.Forms.ComboBox();
System.Windows.Forms.Label nameLabel = new System.Windows.Forms.Label();
System.Windows.Forms.Label toolNameLabel = new System.Windows.Forms.Label();
System.Windows.Forms.Label infoLabel = new System.Windows.Forms.Label();
System.Windows.Forms.NumericUpDown maxPNumeric = new System.Windows.Forms.NumericUpDown();
System.Windows.Forms.NumericUpDown summaryMaxPNumeric = new System.Windows.Forms.NumericUpDown();
System.Windows.Forms.Label maxPLabel = new System.Windows.Forms.Label();
System.Windows.Forms.ToolTip maxPLabelToolTip = new System.Windows.Forms.ToolTip();
maxPLabelToolTip.SetToolTip(maxPLabel, "Specify the maximum number of threads used during processing. " + newline + "Valid values are any postive integer." + newline + "Setting the value to 1 equals not parallel (uses one thread).");
System.Windows.Forms.ImageList imageList = new System.Windows.Forms.ImageList();
System.Windows.Forms.ImageList imageList2 = new System.Windows.Forms.ImageList();
System.Windows.Forms.Button saveButton = new System.Windows.Forms.Button();
System.Windows.Forms.ToolTip saveButtonToolTip = new System.Windows.Forms.ToolTip();
saveButtonToolTip.SetToolTip(saveButton, "Saves the changes back to the model");
System.Windows.Forms.Button deleteButton = new System.Windows.Forms.Button();
System.Windows.Forms.ToolTip deleteButtonToolTip = new System.Windows.Forms.ToolTip();
deleteButtonToolTip.SetToolTip(deleteButton, "Deletes this batch");
System.Windows.Forms.Button summaryButton = new System.Windows.Forms.Button();
System.Windows.Forms.ToolTip summaryButtonToolTip = new System.Windows.Forms.ToolTip();
summaryButtonToolTip.SetToolTip(summaryButton, "Navigate to the summary page");
System.Windows.Forms.Button scriptButton = new System.Windows.Forms.Button();
System.Windows.Forms.ToolTip scriptButtonToolTip = new System.Windows.Forms.ToolTip();
scriptButtonToolTip.SetToolTip(scriptButton, "Saves a script to your desktop with the instructions to create the selected batch");
System.Windows.Forms.Button backButton = new System.Windows.Forms.Button();
System.Windows.Forms.ToolTip backButtonToolTip = new System.Windows.Forms.ToolTip();
backButtonToolTip.SetToolTip(backButton, "Navigate back the main page");
System.Windows.Forms.ToolTip sequenceCheckBoxToolTip = new System.Windows.Forms.ToolTip();
sequenceCheckBoxToolTip.SetToolTip(sequenceCheckBox, "Check this box to enable sequential processing");
System.Windows.Forms.Label saveComment = new System.Windows.Forms.Label();
// Summary Screen
System.Windows.Forms.TreeView summaryTreeView = new System.Windows.Forms.TreeView();
System.Windows.Forms.ComboBox summarytypeComboBox = new System.Windows.Forms.ComboBox();
// Colors
System.Drawing.Color sideColor = ColorTranslator.FromHtml("#BFBFBF");
System.Drawing.Color bkgrdColor = ColorTranslator.FromHtml("#F2F2F2");
System.Drawing.Color lighttextColor = Color.White;
System.Drawing.Color darktextColor = Color.Black;
System.Drawing.Color visibleColor = darktextColor;
System.Drawing.Color hiddenColor = Color.Gray;
System.Drawing.Color darkModeBack = ColorTranslator.FromHtml("#444444");
System.Drawing.Color darkModeName = ColorTranslator.FromHtml("#F2C811");
System.Drawing.Color darkModeText = Color.White;
// Fonts
System.Drawing.Font toolNameFont = new Font("Century Gothic", 22);
System.Drawing.Font elegantFont = new Font("Century Gothic", 10, FontStyle.Italic);
System.Drawing.Font homeToolNameFont = new Font("Century Gothic", 24);
System.Drawing.Font stdFont = new Font("Century Gothic", 10);
// Form
newForm.TopLevel = true;
newForm.BackColor = bkgrdColor;
newForm.Text = "Processing Manager";
newForm.Size = new Size(formWidth,formHeight);
newForm.MaximumSize = new Size(formWidth,formHeight);
newForm.MinimumSize = new Size(formWidth,formHeight);
newForm.Controls.Add(startPanel);
newForm.Controls.Add(topPanel);
newForm.Controls.Add(namePanel);
newForm.Controls.Add(typePanel);
newForm.Controls.Add(infoPanel);
newForm.Controls.Add(treePanel);
int panelX = 0;
startPanel.Controls.Add(newbatchButton);
startPanel.Controls.Add(existingbatchButton);
startPanel.Controls.Add(batchComboBox);
startPanel.Controls.Add(goButton);
startPanel.Controls.Add(homeToolLabel);
startPanel.Visible = true;
startPanel.Size = new Size(formWidth,formHeight);
startPanel.Location = new Point(0,0);
startPanel.Controls.Add(ebiHome);
ebiHome.Text = "Designed by Elegant BI";
ebiHome.Size = new Size(200,40);
ebiHome.Location = new Point(165,460);
ebiHome.Font = elegantFont;
ebiHome.LinkClicked += (System.Object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) => {
System.Diagnostics.Process.Start(ebiURL);
};
// Panels
topPanel.Visible = false;
topPanel.Size = new Size(formWidth,70);
topPanel.Location = new Point(panelX,0);
topPanel.BackColor = bkgrdColor;
namePanel.Visible = false;
namePanel.Size = new Size(formWidth,30);
namePanel.Location = new Point(panelX,70);
namePanel.BackColor = bkgrdColor;
typePanel.Visible = false;
typePanel.Size = new Size(formWidth,30);
typePanel.Location = new Point(panelX,100);
typePanel.BackColor = bkgrdColor;
infoPanel.Visible = false;
infoPanel.Size = new Size(formWidth,30);
infoPanel.Location = new Point(panelX,130);
infoPanel.BackColor = bkgrdColor;
treePanel.Visible = false;
treePanel.Size = new Size(formWidth,500);
treePanel.Location = new Point(panelX,160);
treePanel.BackColor = bkgrdColor;
// Add items to panels
topPanel.Controls.Add(toolNameLabel);
topPanel.Controls.Add(saveButton);
topPanel.Controls.Add(deleteButton);
topPanel.Controls.Add(summaryButton);
topPanel.Controls.Add(scriptButton);
topPanel.Controls.Add(backButton);
namePanel.Controls.Add(nameLabel);
namePanel.Controls.Add(batchNameTextBox);
namePanel.Controls.Add(batchNameComboBox);
typePanel.Controls.Add(typeLabel);
typePanel.Controls.Add(typeComboBox);
typePanel.Controls.Add(summarytypeComboBox);
typePanel.Controls.Add(sequenceCheckBox);
typePanel.Controls.Add(summarySequenceCheckBox);
infoPanel.Controls.Add(infoLabel);
infoPanel.Controls.Add(maxPNumeric);
infoPanel.Controls.Add(summaryMaxPNumeric);
infoPanel.Controls.Add(maxPLabel);
treePanel.Controls.Add(treeView);
treePanel.Controls.Add(summaryTreeView);
treePanel.Controls.Add(saveComment);
// Start Screen Objects
homeToolLabel.Text = "Processing Manager";
homeToolLabel.Size = new Size(450,100);
homeToolLabel.Location = new Point(80,150);
homeToolLabel.Font = homeToolNameFont;
newbatchButton.Size = new Size(250,25);
newbatchButton.Location = new Point(130,250);
newbatchButton.Text = "Create New Processing Batch";
newbatchButton.Font = stdFont;
existingbatchButton.Size = new Size(250,25);
existingbatchButton.Location = new Point(130,280);
existingbatchButton.Text = "Modify Existing Processing Batch";
existingbatchButton.Font = stdFont;
batchComboBox.Visible = false;
batchComboBox.Size = new Size(180,20);
batchComboBox.Location = new Point(150,320);
batchComboBox.Font = stdFont;
goButton.Visible = false;
goButton.Size = new Size(100,30);
goButton.Text = "Go";
goButton.Font = stdFont;
int labelX = 10;
int labelY = 9;
// Main Screen Objects
toolNameLabel.Visible = true;
toolNameLabel.Size = new Size(330,50);
toolNameLabel.Location = new Point(5,15);
toolNameLabel.Text = "Processing Manager";
toolNameLabel.Font = toolNameFont;
nameLabel.Visible = true;
nameLabel.Size = new Size(70,20);
nameLabel.Location = new Point(labelX,labelY);
nameLabel.Text = "Batch Name:";
batchNameTextBox.Visible = true;
batchNameTextBox.Size = new Size(220,30);
batchNameTextBox.Location = new Point(80,5);
batchNameTextBox.Enabled = false;
batchNameComboBox.Visible = false;
batchNameComboBox.Size = new Size(220,30);
batchNameComboBox.Location = new Point(80,5);
batchNameComboBox.Enabled = true;
typeLabel.Visible = true;
typeLabel.Size = new Size(90,20);
typeLabel.Location = new Point(labelX,labelY);
typeLabel.Text = "Processing Type:";
typeComboBox.Visible = true;
typeComboBox.Size = new Size(200,20);
typeComboBox.Location = new Point(100,5);
typeComboBox.Enabled = true;
// Add items to processing type combo box
for (int i=0; i<processingTypeList.Count(); i++)
{
typeComboBox.Items.Add(processingTypeList[i]);
summarytypeComboBox.Items.Add(processingTypeList[i]);
}
int checkboxWidth = 90;
int gap = 10;
summarytypeComboBox.Visible = false;
summarytypeComboBox.Size = new Size(200,20);
summarytypeComboBox.Location = new Point(100,5);
summarytypeComboBox.Enabled = false;
sequenceCheckBox.Visible = true;
sequenceCheckBox.Size = new Size(checkboxWidth,20);
sequenceCheckBox.Location = new Point(formWidth-gap-checkboxWidth,7);
sequenceCheckBox.Checked = false;
sequenceCheckBox.Enabled = true;
sequenceCheckBox.Text = "Sequence";
summarySequenceCheckBox.Visible = false;
summarySequenceCheckBox.Size = new Size(checkboxWidth,20);
summarySequenceCheckBox.Location = new Point(formWidth-gap-checkboxWidth,7);
summarySequenceCheckBox.Checked = false;
summarySequenceCheckBox.Enabled = false;
summarySequenceCheckBox.Text = "Sequence";
maxPNumeric.Visible = false;
maxPNumeric.Size = new Size(45,20);
maxPNumeric.Location = new Point(345,5);
summaryMaxPNumeric.Visible = false;
summaryMaxPNumeric.Size = new Size(45,20);
summaryMaxPNumeric.Location = new Point(345,5);
summaryMaxPNumeric.Enabled = false;
maxPLabel.Visible = false;
maxPLabel.Size = new Size(90,20);
maxPLabel.Location = new Point(394,7);
maxPLabel.Text = "Max Parallelism";
infoLabel.Visible = true;
infoLabel.Size = new Size(300,30);
infoLabel.Location = new Point(labelX,labelY);
infoLabel.Text = infoList[0];
treeView.Visible = true;
treeView.Size = new Size(formWidth - 35,480);
treeView.Location = new Point(gap,gap);
treeView.StateImageList = new System.Windows.Forms.ImageList();
treeView.BackColor = Color.White;
treeView.CheckBoxes = false;
summaryTreeView.Visible = false;
summaryTreeView.Size = new Size(formWidth - 35,480);
summaryTreeView.Location = new Point(gap,gap);
summaryTreeView.StateImageList = new System.Windows.Forms.ImageList();
summaryTreeView.BackColor = bkgrdColor;
summaryTreeView.CheckBoxes = false;
// Add images from web to Image List
var urlPrefix = "https://raw.githubusercontent.com/m-kovalsky/Tabular/master/Icons/";
var urlSuffix = "Icon.png";
string[] imageURLList = { "Table", "Partition", "SummaryTable", "SummaryPartition", "Model", "SummaryModel","SaveDark", "Script", "Delete","ForwardArrow", "BackArrow"};
for (int i = 0; i < imageURLList.Count(); i++)
{
var url = urlPrefix + imageURLList[i] + urlSuffix;
byte[] imageByte = w.DownloadData(url);
System.IO.MemoryStream ms = new System.IO.MemoryStream(imageByte);
System.Drawing.Image im = System.Drawing.Image.FromStream(ms);
if (i<6)
{
imageList.Images.Add(im);
}
else
{
imageList2.Images.Add(im);
}
}
string[] stateimageURLList = { "Unchecked", "Checked", "PartiallyChecked" };
for (int i = 0; i < stateimageURLList.Count(); i++)
{
var url = urlPrefix + stateimageURLList[i] + urlSuffix;
byte[] imageByte = w.DownloadData(url);
System.IO.MemoryStream ms = new System.IO.MemoryStream(imageByte);
System.Drawing.Image im = System.Drawing.Image.FromStream(ms);
treeView.StateImageList.Images.Add(im);
}
imageList.ImageSize = new Size(16, 16);
treeView.ImageList = imageList;
summaryTreeView.ImageList = imageList;
imageList2.ImageSize = new Size(23, 23);
saveButton.ImageList = imageList2;
deleteButton.ImageList = imageList2;
summaryButton.ImageList = imageList2;
scriptButton.ImageList = imageList2;
backButton.ImageList = imageList2;
// Lambda expression for all the steps to next page
System.Action<int> NextStep = stepNumber =>
{
if (stepNumber == 0)
{
treeView.Nodes.Clear();
// Add model node
string modelName = Model.Database.Name;
var mn = treeView.Nodes.Add(modelName);
mn.ImageIndex = 4;
mn.SelectedImageIndex = 4;
mn.StateImageIndex = 0;
foreach (var t in Model.Tables.OrderBy(a => a.Name).ToList())
{
// Add table nodes
string tableName = t.Name;
var tn = mn.Nodes.Add(tableName);
tn.ImageIndex = 0;
tn.SelectedImageIndex = 0;
tn.StateImageIndex = 0;
// Add partition sub-nodes
foreach (var p in t.Partitions.OrderBy(a => a.Name).ToList())
{
string pName = p.Name;
var x = tn.Nodes.Add(pName);
x.ImageIndex = 1;
x.SelectedImageIndex = 1;
x.StateImageIndex = 0;
}
}
}
else if (stepNumber == 1)
{
treeView.Nodes.Clear();
batchNameFull = batchPrefix+batchName;
if (seqEnabled)
{
maxPNumeric.Visible = true;
sequenceCheckBox.Checked = true;
}
else
{
maxPNumeric.Visible = false;
sequenceCheckBox.Checked = false;
}
// Add model node
string modelName = Model.Database.Name;
var mn = treeView.Nodes.Add(modelName);
mn.ImageIndex = 4;
mn.SelectedImageIndex = 4;
if (Model.Tables.Any(a => a.HasAnnotation(batchNameFull)) || Model.AllPartitions.Any(b => b.HasAnnotation(batchNameFull)))
{
mn.StateImageIndex = 2;
}
else
{
mn.StateImageIndex = 1;
}
// Add nodes to treeview
foreach (var t in Model.Tables.OrderBy(a => a.Name).ToList())
{
// Add table nodes
string tableName = t.Name;
var tn = mn.Nodes.Add(tableName);
tn.ImageIndex = 0;
tn.SelectedImageIndex = 0;
tn.StateImageIndex = 0;
if (t.HasAnnotation(batchNameFull) || mn.StateImageIndex == 1)
{
tn.StateImageIndex = 1;
}
else if (t.Partitions.Any(b => b.HasAnnotation(batchNameFull)))
{
tn.StateImageIndex = 2;
}
// Add partition sub-nodes
foreach (var p in t.Partitions.OrderBy(a => a.Name).ToList())
{
string pName = p.Name;
var x = tn.Nodes.Add(pName);
x.ImageIndex = 1;
x.SelectedImageIndex = 1;
x.StateImageIndex = 0;
if (t.HasAnnotation(batchNameFull))
{
x.StateImageIndex = 1;
}
else if (p.HasAnnotation(batchNameFull))
{
x.StateImageIndex = 1;
}
}
}
}
else if (stepNumber == 2)
{
summaryTreeView.Nodes.Clear();
batchNameFull = batchPrefix+batchName;
sb_ExportScript.Clear();
sb_ExportScript.Append("string batchNameFull =\""+batchNameFull+"\";" + newline);
sb_ExportScript.Append("string processingType =\""+processingType+"\";" + newline + newline);
// Script: Remove existing annotations
sb_ExportScript.Append("foreach (var t in Model.Tables.ToList())"+newline+"{"+newline+" t.RemoveAnnotation(batchNameFull);"+newline+"}" + newline + newline);
sb_ExportScript.Append("foreach (var p in Model.AllPartitions)"+newline+"{"+newline+" p.RemoveAnnotation(batchNameFull);"+newline+"}" + newline + newline);
// Script: Update model annotation
if (summarySequenceCheckBox.Checked)
{
sb_ExportScript.Append("Model.SetAnnotation(batchNameFull,processingType"+"+\"_"+Convert.ToInt32(summaryMaxPNumeric.Value).ToString()+"\");" + newline + newline);
}
else
{
sb_ExportScript.Append("Model.SetAnnotation(batchNameFull,processingType);" + newline + newline);
}
// Add model node
string modelName = Model.Database.Name;
var mn = summaryTreeView.Nodes.Add(modelName);
mn.ImageIndex = 5;
mn.SelectedImageIndex = 5;
if (Model.Tables.Any(a => a.HasAnnotation(batchNameFull)) || Model.AllPartitions.Any(b => b.HasAnnotation(batchNameFull)))
{
mn.StateImageIndex = 2;
}
else
{
mn.StateImageIndex = 1;
}
// Add nodes to treeview
foreach (var t in Model.Tables.Where(a => a.HasAnnotation(batchNameFull) || a.Partitions.Any(b => b.HasAnnotation(batchNameFull))).OrderBy(a => a.Name).ToList())
{
// Add table nodes
string tableName = t.Name;
var tn = mn.Nodes.Add(tableName);
tn.ImageIndex = 2;
tn.SelectedImageIndex = 2;
if (t.HasAnnotation(batchNameFull))
{
sb_ExportScript.Append("Model.Tables[\""+tableName+"\"].SetAnnotation(batchNameFull,\"1\");" + newline);
}
else if (t.Partitions.Any(b => b.HasAnnotation(batchNameFull)))
{
}
// Add partition sub-nodes
foreach (var p in t.Partitions.Where(a => a.HasAnnotation(batchNameFull)).OrderBy(a => a.Name).ToList())
{
string pName = p.Name;
var x = tn.Nodes.Add(pName);
x.ImageIndex = 3;
x.SelectedImageIndex = 3;
if (t.HasAnnotation(batchNameFull))
{
}
else if (p.HasAnnotation(batchNameFull))
{
sb_ExportScript.Append("Model.Tables[\""+tableName+"\"].Partitions[\""+pName+"\"].SetAnnotation(batchNameFull,\"1\");" + newline);
}
}
}
}
};
int goButtonX = 190;
int goButtonY = 330;
// Event Handlers (Start Screen)
newbatchButton.Click += (System.Object sender, System.EventArgs e) => {
goButton.Visible = true;
goButton.Location = new Point(goButtonX, goButtonY);
batchComboBox.Visible = false;
goButton.Enabled = true;
batchComboBox.Text = string.Empty;
batchNameTextBox.Enabled = true;
};
batchComboBox.SelectedValueChanged += (System.Object sender, System.EventArgs e) => {
goButton.Enabled = true;
};
existingbatchButton.Click += (System.Object sender, System.EventArgs e) => {
goButton.Location = new Point(goButtonX, goButtonY+30);
batchComboBox.Visible = true;
goButton.Visible = true;
goButton.Enabled = false;
batchNameTextBox.Enabled = false;
// Populate Batch Combo Box
batchComboBox.Items.Clear();
foreach(var x in Model.GetAnnotations().Where(a => a.StartsWith(batchPrefix)))
{
batchComboBox.Items.Add(x.Substring(batchPrefixLen));
}
if (batchComboBox.SelectedItem == null)
{
goButton.Enabled = false;
}
};
goButton.Click += (System.Object sender, System.EventArgs e) => {
startPanel.Visible = false;
topPanel.Visible = true;
namePanel.Visible = true;
typePanel.Visible = true;
infoPanel.Visible = true;
treePanel.Visible = true;
if (existingbatchButton.Checked == true)
{
batchName = batchComboBox.Text;
batchNameFull = batchPrefix+batchName;
batchNameTextBox.Text = batchName;
batchNameTextBox.Enabled = false;
string ann = Model.GetAnnotation(batchNameFull);
if (ann.Contains("_"))
{
processingType = ann.Substring(0,ann.IndexOf("_"));
seqEnabled = true;
mp = Convert.ToInt32(ann.Substring(ann.IndexOf("_")+1));
maxPNumeric.Value = mp;
}
else
{
processingType = ann;
}
typeComboBox.Text = processingType;
NextStep(1);
}
else
{
//batchName = batchNameTextBox.Text;
NextStep(0);
}
};
treeView.AfterExpand += (System.Object sender, System.Windows.Forms.TreeViewEventArgs e) => {
IsExpOrCol = true;
};
treeView.AfterCollapse += (System.Object sender, System.Windows.Forms.TreeViewEventArgs e) => {
IsExpOrCol = true;
};
treeView.NodeMouseClick += (System.Object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e) => {
if (IsExpOrCol == false)
{
if (e.Node.StateImageIndex != 1)
{
e.Node.StateImageIndex = 1;
}
else if (e.Node.StateImageIndex == 1)
{
e.Node.StateImageIndex = 0;
}
// Model
if (e.Node.ImageIndex == 4)
{
if (e.Node.StateImageIndex == 1)
{
foreach (System.Windows.Forms.TreeNode childNode in e.Node.Nodes)
{
childNode.StateImageIndex = 1;
foreach (System.Windows.Forms.TreeNode gChildNode in childNode.Nodes)
{
gChildNode.StateImageIndex = 1;
}
}
}
else if (e.Node.StateImageIndex == 0)
{
foreach (System.Windows.Forms.TreeNode childNode in e.Node.Nodes)
{
childNode.StateImageIndex = 0;
foreach (System.Windows.Forms.TreeNode gChildNode in childNode.Nodes)
{
gChildNode.StateImageIndex = 0;
}
}
}
}
if (e.Node.ImageIndex == 0)
{
int tableNodeCount = e.Node.Parent.Nodes.Count;
int tableNodeCheckedCount = 0;
// If parent node is checked, check all child nodes
if (e.Node.StateImageIndex == 1)
{
foreach (System.Windows.Forms.TreeNode childNode in e.Node.Nodes)
{
childNode.StateImageIndex = 1;
tableNodeCheckedCount++;
}
}
// If parent node is unchecked, uncheck all child nodes
else if (e.Node.StateImageIndex == 0)
{
foreach (System.Windows.Forms.TreeNode childNode in e.Node.Nodes)
{
childNode.StateImageIndex = 0;
}
}
if (tableNodeCheckedCount == tableNodeCount)
{
e.Node.Parent.StateImageIndex = 1;
}
else if (tableNodeCheckedCount > 0)
{
e.Node.Parent.StateImageIndex = 2;
}
}
else if (e.Node.ImageIndex == 1)
{
int childNodeCount = e.Node.Parent.Nodes.Count;
int childNodeCheckedCount = 0;
foreach (System.Windows.Forms.TreeNode n in e.Node.Parent.Nodes)
{
if (n.StateImageIndex == 1)
{
childNodeCheckedCount++;
}
}
// If all child nodes are checked, set parent node to checked
if (childNodeCheckedCount == childNodeCount)
{
e.Node.Parent.StateImageIndex = 1;
}
// If no child nodes are checked, set parent node to unchecked
else if (childNodeCheckedCount == 0)
{
e.Node.Parent.StateImageIndex = 0;
}
// If not all children nodes are selected, set parent node to partially checked icon
else if (childNodeCheckedCount < childNodeCount)
{
e.Node.Parent.StateImageIndex = 2;
}
}
foreach (System.Windows.Forms.TreeNode modelNode in treeView.Nodes)
{
int tableNodeCount = modelNode.Nodes.Count;
int tableNodeCheckedCount = 0;
int partitionNodeCheckedCount = 0;
foreach (System.Windows.Forms.TreeNode tableNode in modelNode.Nodes)
{
if (tableNode.StateImageIndex == 1)
{
tableNodeCheckedCount++;
}
foreach(System.Windows.Forms.TreeNode partitionNode in tableNode.Nodes)
{
if (partitionNode.StateImageIndex == 1)
{
partitionNodeCheckedCount++;
}
}
}
if (tableNodeCheckedCount == tableNodeCount)
{
modelNode.StateImageIndex = 1;
}
else if (tableNodeCheckedCount == 0 && partitionNodeCheckedCount == 0)
{
modelNode.StateImageIndex = 0;
}
else
{
modelNode.StateImageIndex = 2;
}
}
}
IsExpOrCol = false;
};
// Top buttons
int saveButtonX = 385;
int buttonY = 25;
int buttonGap = 30;
int buttonSize = 25;
saveButton.Visible = true;
saveButton.ImageIndex = 0;
saveButton.Size = new Size(buttonSize,buttonSize);
saveButton.Location = new Point(saveButtonX,buttonY);
saveButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
saveButton.FlatAppearance.BorderSize = 0;
saveButton.TabStop = false;
deleteButton.Visible = true;
deleteButton.ImageIndex = 2;
deleteButton.Size = new Size(buttonSize,buttonSize);
deleteButton.Location = new Point(saveButtonX+(buttonGap*1),buttonY);
deleteButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
deleteButton.FlatAppearance.BorderSize = 0;
deleteButton.TabStop = false;
summaryButton.Visible = true;
summaryButton.ImageIndex = 3;
summaryButton.Size = new Size(buttonSize,buttonSize);
summaryButton.Location = new Point(saveButtonX+(buttonGap*2),buttonY);
summaryButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
summaryButton.FlatAppearance.BorderSize = 0;
summaryButton.TabStop = false;
scriptButton.Visible = false;
scriptButton.ImageIndex = 1;
scriptButton.Size = new Size(buttonSize,buttonSize);
scriptButton.Location = new Point(saveButtonX+(buttonGap*1),buttonY);
scriptButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
scriptButton.FlatAppearance.BorderSize = 0;
scriptButton.TabStop = false;
backButton.Visible = false;
backButton.ImageIndex = 4;
backButton.Size = new Size(buttonSize,buttonSize);
backButton.Location = new Point(saveButtonX+(buttonGap*2),buttonY);
backButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
backButton.FlatAppearance.BorderSize = 0;
backButton.TabStop = false;
saveButton.MouseEnter += (System.Object sender, System.EventArgs e) => {
saveButton.ImageIndex = 0;
saveButton.FlatAppearance.BorderSize = 0;
};
saveButton.MouseLeave += (System.Object sender, System.EventArgs e) => {
saveButton.ImageIndex = 0;
saveButton.FlatAppearance.BorderSize = 0;
};
deleteButton.MouseEnter += (System.Object sender, System.EventArgs e) => {
deleteButton.ImageIndex = 2;
deleteButton.FlatAppearance.BorderSize = 0;
};
deleteButton.MouseLeave += (System.Object sender, System.EventArgs e) => {
deleteButton.ImageIndex = 2;
deleteButton.FlatAppearance.BorderSize = 0;
};
summaryButton.MouseEnter += (System.Object sender, System.EventArgs e) => {
summaryButton.ImageIndex = 3;
summaryButton.FlatAppearance.BorderSize = 0;
};
summaryButton.MouseLeave += (System.Object sender, System.EventArgs e) => {
summaryButton.ImageIndex = 3;
summaryButton.FlatAppearance.BorderSize = 0;
};
scriptButton.MouseEnter += (System.Object sender, System.EventArgs e) => {
scriptButton.ImageIndex = 1;
scriptButton.FlatAppearance.BorderSize = 0;
};
scriptButton.MouseLeave += (System.Object sender, System.EventArgs e) => {
scriptButton.ImageIndex = 1;
scriptButton.FlatAppearance.BorderSize = 0;
};
backButton.MouseEnter += (System.Object sender, System.EventArgs e) => {
backButton.ImageIndex = 4;
backButton.FlatAppearance.BorderSize = 0;
};
backButton.MouseLeave += (System.Object sender, System.EventArgs e) => {
backButton.ImageIndex = 4;
backButton.FlatAppearance.BorderSize = 0;
};
saveButton.Click += (System.Object sender, System.EventArgs e) => {
batchName = batchNameTextBox.Text;
processingType = typeComboBox.Text;
if (sequenceCheckBox.Checked)
{
seqEnabled = true;
mp = Convert.ToInt32(maxPNumeric.Value);
}
if (batchName.Length > 0)
{
batchNameFull = batchPrefix+batchName;
}
int tableNodeSelCount = 0;
int partitionNodeSelCount = 0;
foreach (System.Windows.Forms.TreeNode modelNode in treeView.Nodes)
{
foreach (System.Windows.Forms.TreeNode tableNode in modelNode.Nodes)
{
if (tableNode.StateImageIndex == 1)
{
tableNodeSelCount++;
}
foreach (System.Windows.Forms.TreeNode partitionNode in tableNode.Nodes)
{
if (partitionNode.StateImageIndex == 1)
{
partitionNodeSelCount++;
}
}
}
}
if (batchName.Length == 0)
{
Error("Batch not saved. Must enter a valid batch name.");
}
else if (processingType.Length == 0)
{
Error("Batch not saved. Must enter a valid processing type.");
}
else if (newbatchButton.Checked == true && Model.HasAnnotation(batchNameFull) && hasSaved == false)
{
Error("Batch not saved. Batch name cannot be the same as an existing batch name. Please enter a different batch name.");
}
else if (tableNodeSelCount == 0 && partitionNodeSelCount == 0)
{
Error("Batch not saved. Batch must have at least one table or partition selected.");
}
else
{
// Update Model annotation
if (seqEnabled == true && mp == 0)
{
Error("Max Parallelism must be greater than 0");
return;
}
else if (seqEnabled == true && mp > 0)
{
Model.SetAnnotation(batchNameFull,processingType+"_"+mp.ToString());
}
else
{
Model.SetAnnotation(batchNameFull,processingType);
}
foreach (System.Windows.Forms.TreeNode modelNode in treeView.Nodes)
{
foreach (System.Windows.Forms.TreeNode rootNode in modelNode.Nodes)
{
string tableName = rootNode.Text;
// Update table annotations
if (rootNode.StateImageIndex == 1 && modelNode.StateImageIndex != 1)
{
Model.Tables[tableName].SetAnnotation(batchNameFull,"1");
foreach (var p in Model.AllPartitions.Where(a => a.Table.Name == tableName))
{
p.RemoveAnnotation(batchNameFull);
}
}
else
{
Model.Tables[tableName].RemoveAnnotation(batchNameFull);
}
foreach (System.Windows.Forms.TreeNode childNode in rootNode.Nodes)
{
string partitionName = childNode.Text;
// Update partition annotations
if (childNode.StateImageIndex == 1 && rootNode.StateImageIndex != 1)
{
Model.Tables[tableName].Partitions[partitionName].SetAnnotation(batchNameFull,"1");
}
else if (childNode.StateImageIndex == 0)
{
Model.Tables[tableName].Partitions[partitionName].RemoveAnnotation(batchNameFull);
}
}
}
}
hasSaved = true;
}
};
deleteButton.Click += (System.Object sender, System.EventArgs e) => {
if (batchName.Length == 0)
{
Warning("A valid batch name has not been entered. This batch has not been deleted.");
}
else
{
if (System.Windows.Forms.MessageBox.Show("Are you sure you want to delete the '"+batchName+"' batch?","Delete Batch",System.Windows.Forms.MessageBoxButtons.YesNo,System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
batchNameFull = batchPrefix+batchName;
Model.RemoveAnnotation(batchNameFull);
foreach (var t in Model.Tables.ToList())
{
t.RemoveAnnotation(batchNameFull);
foreach( var p in t.Partitions.ToList())
{
p.RemoveAnnotation(batchNameFull);
}
}