-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
1722 lines (1610 loc) · 67.9 KB
/
MainWindow.xaml.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using System.IO;
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using System.Web;
using System.Web.Script.Serialization;
using System.Drawing;
namespace ProjectWRQuery {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : System.Windows.Window {
public MainWindow() {
string[] args = Environment.GetCommandLineArgs();
InitializeComponent();
string[] validUsers = { "usernames" };//update to run
string strUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
int indDomain = strUserName.LastIndexOf("\\")+1;
string user = strUserName.Substring(indDomain, strUserName.Length - indDomain);
int i = args.Count();
if (true) { //update for validuser check
BackgroundWorker bw1 = new BackgroundWorker();
if (args.Count() > 1) {
string fileName = args[1];
bw1.DoWork += new DoWorkEventHandler(updateFromFile);
bw1.RunWorkerAsync(fileName);
initBtn.IsEnabled = false;
updateBtn.IsEnabled = false;
pBar.Visibility = Visibility.Hidden;
} else {
bw1.DoWork += new DoWorkEventHandler(getPList);
bw1.RunWorkerAsync();
initBtn.IsEnabled = false;
updateBtn.IsEnabled = false;
pBar.Visibility = Visibility.Hidden;
}
} else {
initBtn.IsEnabled = false;
updateBtn.IsEnabled = false;
status.Content = "Not an allowed user, contact SCT.";
pBar.Visibility = Visibility.Hidden;
}
//status.Content = strUserName;
}
public void updateFromFile(object sender, DoWorkEventArgs e) {
string filename = (string) e.Argument;
updater(filename);
}
public List<DevT> getWRplus(string PID) {
SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;
List<DevT> dis = new List<DevT>();
try {
con = new SqlConnection(String.Format("redacted"));//update ot run
con.Open();
#region QueryString
string qryStr = "Select WR, WRStatus, VAR, VARStatus, VARNeedByDate, ForwardTypes.ForwardTypeName as Priority from (" +
"SELECT Bug.ProblemID as WR, ProgressStatusTypes.ProgressStatusName as WRStatus, Bug2.ProblemID as VAR, ProgressStatusTypes2.ProgressStatusName as VARStatus, Bug2.TaskPlannedStartDate as VARNeedByDate, Bug2.CrntForwardTypeID as VARPriority " +
"FROM SWISEDB.dbo.Bug, SWISEDB.dbo.Bug Bug2, SWISEDB.dbo.BugLinks, SWISEDB.dbo.Project, SWISEDB.dbo.ProgressStatusTypes, SWISEDB.dbo.ProgressStatusTypes ProgressStatusTypes2 " +
"WHERE " +
"Bug.ProjectID = 17 and Bug2.ProjectID = Project.ProjectID and " +
"BugLinks.LinkedBugID = Bug.BugID and " +
"BugLinks.LinkedProjectID = Bug.ProjectID and " +
"BugLinks.ProjectID = Project.ProjectID and " +
"Bug2.BugID = BugLinks.BugID and " +
"Bug2.ProjectID = BugLinks.ProjectID and " +
"Bug.ProgressStatusID = ProgressStatusTypes.ProgressStatusID and " +
"Bug.ProjectID = ProgressStatusTypes.ProjectID and " +
"Bug2.ProgressStatusID = ProgressStatusTypes2.ProgressStatusID and " +
"Bug2.ProjectID = ProgressStatusTypes2.ProjectID and " +
"Project.ProjectName like '" + PID + "%' " +
"UNION " +
"SELECT Bug.ProblemID as WR, ProgressStatusTypes.ProgressStatusName as WRStatus, Bug2.ProblemID as VAR, ProgressStatusTypes2.ProgressStatusName as VARStatus, Bug2.TaskPlannedStartDate as VARNeedByDate, Bug2.CrntForwardTypeID as VARPriority " +
"FROM SWISEDB.dbo.Bug, SWISEDB.dbo.Bug Bug2, SWISEDB.dbo.BugLinks, SWISEDB.dbo.Project, SWISEDB.dbo.ProgressStatusTypes, SWISEDB.dbo.ProgressStatusTypes ProgressStatusTypes2 " +
"WHERE " +
"Bug.ProjectID = 17 and Bug2.ProjectID = Project.ProjectID and " +
"BugLinks.BugID = Bug.BugID and " +
"BugLinks.ProjectID = Bug.ProjectID and " +
"BugLinks.LinkedProjectID = Project.ProjectID and " +
"Bug2.BugID = BugLinks.LinkedBugID and " +
"Bug2.ProjectID = BugLinks.LinkedProjectID and " +
"Bug.ProgressStatusID = ProgressStatusTypes.ProgressStatusID and " +
"Bug.ProjectID = ProgressStatusTypes.ProjectID and " +
"Bug2.ProgressStatusID = ProgressStatusTypes2.ProgressStatusID and " +
"Bug2.ProjectID = ProgressStatusTypes2.ProjectID and " +
"Project.ProjectName like '" + PID + "%' ) q" +
"Left Join ForwardTypes on ForwardTypes.ProjectID = 1450 and ForwardTypes.OrderNo+1 = VARPriority";
#endregion
cmd = new SqlCommand(qryStr);
cmd.Connection = con;
rdr = cmd.ExecuteReader();
while (rdr.HasRows) {
while (rdr.Read()) {
string dWR = "";
string dWRstatus = "";
string dIVnum = "";
string dIVstatus = "";
string dNBD = "Date Not Set";//need by date
string dNBE = "Event Not Set";//need by event
try {
dWR = rdr[0].ToString().Substring(3, rdr[0].ToString().Length - 3);
} catch { }
try { dWRstatus = rdr[1].ToString(); } catch { }
try { dIVnum = rdr[2].ToString(); } catch { }
try { dIVstatus = rdr[3].ToString(); } catch { }
try {
dNBD = rdr[4].ToString();
if (dNBD == "")
dNBD = "Date Not Set";
} catch { dNBD = "Date Not Set"; }
try { dNBE = rdr[5].ToString(); } catch { dNBE = "Event Not Set"; }
DevT d = new DevT(dWR, dWRstatus, dIVnum, dIVstatus,dNBD,dNBE);
dis.Add(d);
}
rdr.NextResult();
}
} catch (Exception e) {
string m = e.Message;
rdr = null;
} finally {
if (rdr != null) {
rdr.Close();
}
if (con.State == ConnectionState.Open) {
con.Close();
}
}
return dis;
}
public List<DevT> getWRs(string PID) {
SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;
//List<string> WRs = new List<string>();
List<DevT> dis = new List<DevT>();
try {
con = new SqlConnection(String.Format("redacted"));//update to run
con.Open();
string qryStr = "SELECT Bug.ProblemID as WR, ProgressStatusTypes.ProgressStatusName as WRStatus, Bug2.ProblemID as VAR, ProgressStatusTypes2.ProgressStatusName as VARStatus " +
"FROM SWISEDB.dbo.Bug, SWISEDB.dbo.Bug Bug2, SWISEDB.dbo.BugLinks, SWISEDB.dbo.Project, SWISEDB.dbo.ProgressStatusTypes, SWISEDB.dbo.ProgressStatusTypes ProgressStatusTypes2 " +
"WHERE " +
"Bug.ProjectID = 17 and Bug2.ProjectID = Project.ProjectID and " +
"BugLinks.LinkedBugID = Bug.BugID and " +
"BugLinks.LinkedProjectID = Bug.ProjectID and " +
"BugLinks.ProjectID = Project.ProjectID and " +
"Bug2.BugID = BugLinks.BugID and " +
"Bug2.ProjectID = BugLinks.ProjectID and " +
"Bug.ProgressStatusID = ProgressStatusTypes.ProgressStatusID and " +
"Bug.ProjectID = ProgressStatusTypes.ProjectID and " +
"Bug2.ProgressStatusID = ProgressStatusTypes2.ProgressStatusID and "+
"Bug2.ProjectID = ProgressStatusTypes2.ProjectID and "+
"Project.ProjectName like '" + PID + "%' " +
"UNION " +
"SELECT Bug.ProblemID as WR, ProgressStatusTypes.ProgressStatusName as WRStatus, Bug2.ProblemID as VAR, ProgressStatusTypes2.ProgressStatusName as VARStatus " +
"FROM SWISEDB.dbo.Bug, SWISEDB.dbo.Bug Bug2, SWISEDB.dbo.BugLinks, SWISEDB.dbo.Project, SWISEDB.dbo.ProgressStatusTypes, SWISEDB.dbo.ProgressStatusTypes ProgressStatusTypes2 " +
"WHERE " +
"Bug.ProjectID = 17 and Bug2.ProjectID = Project.ProjectID and " +
"BugLinks.BugID = Bug.BugID and " +
"BugLinks.ProjectID = Bug.ProjectID and " +
"BugLinks.LinkedProjectID = Project.ProjectID and " +
"Bug2.BugID = BugLinks.LinkedBugID and " +
"Bug2.ProjectID = BugLinks.LinkedProjectID and " +
"Bug.ProgressStatusID = ProgressStatusTypes.ProgressStatusID and " +
"Bug.ProjectID = ProgressStatusTypes.ProjectID and " +
"Bug2.ProgressStatusID = ProgressStatusTypes2.ProgressStatusID and " +
"Bug2.ProjectID = ProgressStatusTypes2.ProjectID and " +
"Project.ProjectName like '" + PID + "%' ";
#region OldString
//string qryStr = "SELECT Bug.ProblemID as WR, Bug2.ProblemID as VAR " +
// "FROM SWISEDB.dbo.Bug, SWISEDB.dbo.Bug Bug2, SWISEDB.dbo.BugLinks, SWISEDB.dbo.Project " +
// "WHERE " +
// "Bug.ProjectID = 17 and Bug2.ProjectID = Project.ProjectID and " +
// "BugLinks.LinkedBugID = Bug.BugID and " +
// "BugLinks.LinkedProjectID = Bug.ProjectID and " +
// "BugLinks.ProjectID = Project.ProjectID and " +
// "Bug2.BugID = BugLinks.BugID and " +
// "Bug2.ProjectID = BugLinks.ProjectID and " +
// "Project.ProjectName like '" ID + "%' " +
// "UNION " +
// "SELECT Bug.ProblemID as WR, Bug2.ProblemID as VAR " +
// "FROM SWISEDB.dbo.Bug, SWISEDB.dbo.Bug Bug2, SWISEDB.dbo.BugLinks, SWISEDB.dbo.Project " +
// "WHERE " +
// "Bug.ProjectID = 17 and Bug2.ProjectID = Project.ProjectID and " +
// "BugLinks.BugID = Bug.BugID and " +
// "BugLinks.ProjectID = Bug.ProjectID and " +
// "BugLinks.LinkedProjectID = Project.ProjectID and " +
// "Bug2.BugID = BugLinks.LinkedBugID and " +
// "Bug2.ProjectID = BugLinks.LinkedProjectID and " +
// "Project.ProjectName like '" ID + "%' ";
#endregion
cmd = new SqlCommand(qryStr);
cmd.Connection = con;
rdr = cmd.ExecuteReader();
while (rdr.HasRows) {
while (rdr.Read()) {
string IVt = "";
string WRt = "";
string RDt = "";
string IVs = "";
try {
WRt = rdr[0].ToString().Substring(3, rdr[0].ToString().Length - 3);
} catch { }
try { IVt = rdr[1].ToString(); } catch { }
try { RDt = rdr[2].ToString(); } catch { }
try { IVs = rdr[3].ToString(); } catch { }
DevT d = new DevT(WRt, IVt, RDt,IVs,"","");
dis.Add(d);
}
rdr.NextResult();
}
} catch (Exception e) {
string m = e.Message;
rdr = null;
} finally {
if (rdr != null) {
rdr.Close();
}
if (con.State == ConnectionState.Open) {
con.Close();
}
}
return dis;
}
public WR pJSON(string qTxt) {//list<string> qTxts
JiraResource resource = new JiraResource();
string bURL = "https://redacted.atlassian.net/rest/api/latest/search?jql="; //base url, update to run
string JSONdata = null;
int statusCode = 0;
Stream s;
StreamReader r;
HttpWebResponse webRes;
HttpWebRequest WebReq = WebRequest.Create(bURL + qTxt) as HttpWebRequest;
WebReq.ContentType = "application/json";
WebReq.Method = "GET";
WebReq.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(resource.m_Username + ":" + resource.m_Password));
try {
webRes = (HttpWebResponse)WebReq.GetResponse();
s = webRes.GetResponseStream();
r = new StreamReader(s);
JSONdata = r.ReadToEnd();
statusCode = (int)webRes.StatusCode;
s.Close();
r.Close();
} catch (WebException e) {
s = e.Response.GetResponseStream();
r = new StreamReader(s);
JSONdata = r.ReadToEnd();
statusCode = (int)((HttpWebResponse)e.Response).StatusCode;
s.Close();
r.Close();
}
try {
//JavaScriptSerializer jss = new JavaScriptSerializer();
//jss.RegisterConverters = unnull;
WR tem = new JavaScriptSerializer().Deserialize<WR>(JSONdata);
return tem;
} catch (Exception e) {
string m = e.Message;
}
return null;
}
public List<string> getPID() {
SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;
bool fail = false;
List<string> pids = new List<string>();
try {
con = new SqlConnection(String.Format("redacted"));//update to run
con.Open();
string qryStr = "select ProjectName from Project where ProjectName not like '*%' order by ProjectName";
cmd = new SqlCommand(qryStr);
cmd.Connection = con;
rdr = cmd.ExecuteReader();
while (rdr.Read()) {
pids.Add(rdr[0].ToString());
}
} catch {
rdr = null;
fail = true;
} finally {
if (rdr != null) {
rdr.Close();
}
if (con.State == ConnectionState.Open) {
con.Close();
}
}
Dispatcher.Invoke((System.Action)delegate() {
if (fail) {
status.Content = "Couldn't connect to DevTrack.";
} else {
status.Content = "";
updateBtn.IsEnabled = true;
}
//status.Content = "";
});
return pids;
}
public void getPList(object sender, DoWorkEventArgs e) {
List<string> rdr = getPID();
Dispatcher.Invoke((System.Action)delegate() {
foreach (string pid in rdr) {
pBox.Items.Add(pid);
}
pBox.SelectedItem = "System Certification Team";
//status.Content = "";
});
}
//public string filterOut(List<string> list, string keep) {
// string res = "";
// if (list == null) {
// list = new List<string>();
// list.Add("");
// }
// try {
// string filter = keep.Substring(0, keep.IndexOf(":") - 1);
// foreach (string s in list) {
// if (s.Contains(filter))
// res += s + ", ";
// }
// } catch {
// res += "Error decoding, ";
// }
// return res;
//}
public static string unnull(object Value) {
return Value == null ? "xxx" : Value.ToString();
}
public static string undate(string ugly) {
//"2015-01-16T16:47:29.000-0600"
//temp=11/26/2014 12:00:00 AM
//releasedate=2014-11-26
string[] a = new string[3];
try {
a = ugly.Substring(0, ugly.IndexOf("T")).Split(new Char[] { '-' }).ToArray();
string[] b = { a[1].TrimStart('0'), a[2].TrimStart('0'), a[0] };
return string.Join("/", b);
} catch {
return a[0];
}
}
public static string getDStatus(string WR, List<DevT> DevTrack) {
foreach (DevT d in DevTrack) {
if (d.WR == WR) {
return d.status;
}
}
return "N/A";
}
public static string getIVStatus(string WR, List<DevT> DevTrack) {
foreach (DevT d in DevTrack) {
if (d.WR == WR) {
return d.IVstatus;
}
}
return "N/A";
}
public static string getNBDE(string WR, List<DevT> DevTrack) {
foreach (DevT d in DevTrack) {
if (d.WR == WR) {
string temp = d.NeedByEvent+Environment.NewLine+Environment.NewLine+d.NeedByDate;
return temp;
}
}
return "N/A";
}
public static int getJIRAtotal(string jqry) {
JiraResource resource = new JiraResource();
string bURL = "https://redacted.atlassian.net/rest/api/latest/search?jql="; //base url, update to run
string JSONdata = null;
int statusCode = 0;
Stream s;
StreamReader r;
HttpWebResponse webRes;
HttpWebRequest WebReq = WebRequest.Create(bURL + jqry+"&startAt=0&maxResults=0") as HttpWebRequest;
WebReq.ContentType = "application/json";
WebReq.Method = "GET";
WebReq.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(resource.m_Username + ":" + resource.m_Password));
try {
webRes = (HttpWebResponse)WebReq.GetResponse();
s = webRes.GetResponseStream();
r = new StreamReader(s);
JSONdata = r.ReadToEnd();
statusCode = (int)webRes.StatusCode;
s.Close();
r.Close();
} catch (WebException e) {
s = e.Response.GetResponseStream();
r = new StreamReader(s);
JSONdata = r.ReadToEnd();
statusCode = (int)((HttpWebResponse)e.Response).StatusCode;
s.Close();
r.Close();
}
try {
//"{\"startAt\":0,\"maxResults\":0,\"total\":549,\"issues\":[]}"
//{"startAt":0,"maxResults":0,"total":549,"issues":[]}
//pos 36
int x = JSONdata.LastIndexOf(',');
int i = Convert.ToInt32(JSONdata.Substring(36, JSONdata.LastIndexOf(',') - 36));
return i;
} catch (Exception e) {
string m = e.Message;
}
return 0;
}
public static string getIV(string WR, List<DevT> DevTrack) {
foreach (DevT d in DevTrack) {
if (d.WR == WR) {
return d.IV;
}
}
return "N/A";
}
static bool ContainsLoop(List<string> list, string value) {
for (int i = 0; i < list.Count; i++) {
if (list[i] == value) {
return true;
}
}
return false;
}
public static List<string> getList(Excel.Worksheet xlSheet, int colNum) {
Excel.Range usedRange = xlSheet.UsedRange.Columns[colNum];
int rr = usedRange.Rows.Count;
List<string> slist = new List<string>();
for (int i = 1; i <= rr; i++) {
try { slist.Add(xlSheet.Cells[i, colNum].Value.ToString()); }catch{}
}
releaseObject(usedRange);
//releaseObject(xlSheet);
return slist;
}
public int getIndex(List<string> Keys, string value) {//turbo fast
int index = -1;
Parallel.For(0, Keys.Count, i => {
if (Keys[i] == value) {
index= i;
}
});
return index;
}
//public string getSuite(string JKEY) {
// switch (JKEY.Substring(0,JKEY.IndexOf("-"))) {
// case "CSM":
// return "Platform Server";
// case "VM":
// return "Platform Visualizaiton";
// case "CCM":
// return "System Management";
// case "SCADAMAIN":
// return "SCADA";
// case "COMMSMAINT":
// return "COMMS";
// case "CHRNSMAINT":
// return "ISR";
// case "ISRMAINT":
// return "ISR";
// case "GMSMAINT":
// return "GMS";
// case "EMSMAINT":
// return "EMS";
// case "DMSMAINT":
// return "DMS";
// case "GASMAINT":
// return "Fluid/Gas";
// default:
// return "N/A";
// }
//}
public List<string> DevTWRs(List<DevT> LinkedWRs) {
List<string> WRVals = new List<string>();
Parallel.ForEach(LinkedWRs, Issue => {
WRVals.Add(Issue.WR);
});
return WRVals;
}
public List<string> ReturnedWRs(List<WR> data) {
List<string> WRs = new List<string>();
Parallel.ForEach(data, deets => {
Parallel.ForEach(deets.issues, issue => {
try {
WRs.Add(issue.fields.customfield_10401);
} catch { }
});
});
return WRs;
}
public List<string> CompareDJ(List<DevT> DevTrack, List<WR> data){
List<string> dne = new List<string>();
List<string> WRs = ReturnedWRs(data);
foreach (DevT dt in DevTrack) {
if (getIndex(WRs, dt.WR) < 0) {
dne.Add(dt.WR);
}
}
//Parallel.ForEach(DevTrack, dt => {
// int i = getIndex(WRs, dt.WR);
// if (i < 0) {
// dne.Add(dt.WR);
// }
//});
return dne;
}
public bool createWRPR(string file, string pid, List<WR> data, List<DevT> DevTrack) {
bool result = false;
List<string> cautions = new List<string>();
Excel.Application excelApp = null;
Excel.Workbook workbook = null;
Excel.Sheets sheets = null;
Excel.Worksheet dataSheet = null;
Excel.Range xlR = null;
//int rowS = 3;
//int colS = 1;
try {
excelApp = new Excel.Application();
workbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
sheets = workbook.Sheets;
dataSheet = sheets[1];
dataSheet.Name = DateTime.Now.Month.ToString("00") + "-" + DateTime.Now.Day.ToString("00") + "-" + DateTime.Now.Year.ToString().Substring(2, 2);;
//int p = 0;
#region Header format
string[] headers = { "WR#","WR Status", "Variance", "Project", "DevTeam", "Product", "Version", "Severity", "Project Delivery Priority", "Need by Event/Date", "Date Created", "Linked Variances", "Summary", "Description","Certification Assessment","Certification Required" };
object[,] xlHeader = new object[1,headers.Length];
for(int i =0;i<headers.Length;i++){
xlHeader[0,i] = headers[i];
}
xlR = dataSheet.Range["A1","P1"];//xlGetStr
xlR.Value2 = xlHeader;
#endregion
dataSheet.get_Range("A:P", Type.Missing).EntireColumn.VerticalAlignment = XlVAlign.xlVAlignCenter;
dataSheet.get_Range("A:P", Type.Missing).EntireColumn.WrapText = true;
dataSheet.get_Range("A:P", Type.Missing).EntireColumn.ColumnWidth = 12;
dataSheet.get_Range("J:L", Type.Missing).EntireColumn.ColumnWidth = 18;
dataSheet.get_Range("M:O", Type.Missing).EntireColumn.ColumnWidth = 32;
dataSheet.get_Range("N:N", Type.Missing).EntireColumn.ColumnWidth = 50;
dataSheet.get_Range("F:F", Type.Missing).EntireColumn.ColumnWidth = 22;
int rowCount = 2; //start at row 2
foreach (WR dd in data) {
foreach (Jissues info in dd.issues) {
WRQuery WRQ = new WRQuery(info, pid);
string[] newLine = { WRQ.WR, getDStatus(WRQ.WR, DevTrack), getIV(WRQ.WR, DevTrack), pid, WRQ.Suite, WRQ.Product, WRQ.CurrentRelease, WRQ.IssueType, WRQ.ProjDeliveryPriority, getNBDE(WRQ.WR, DevTrack), WRQ.Created, WRQ.Variances, "'" + WRQ.Summary, "'" + WRQ.Description };
object[,] xlNewLine = new object[1, newLine.Length];
for (int i = 0; i < newLine.Length; i++) {
xlNewLine[0, i] = newLine[i];
}
xlR = dataSheet.Range["A" + rowCount, "N" + rowCount];
xlR.Value2 = xlNewLine;
rowCount++;
}
}
xlR = dataSheet.get_Range("A1:P" + (rowCount-1));
dataSheet.ListObjects.AddEx(XlListObjectSourceType.xlSrcRange, xlR, Type.Missing, Excel.XlYesNoGuess.xlYes, Type.Missing).Name = "MyTableStyle";
dataSheet.ListObjects.get_Item("MyTableStyle").TableStyle = "TableStyleLight8";
dataSheet.get_Range("A1", "P1").EntireRow.RowHeight = 15;
bool readOnly = false;
excelApp.DisplayAlerts = false;
workbook.SaveAs(file, XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, readOnly, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing);
workbook.Close(true, Type.Missing, Type.Missing);
excelApp.Quit();
//releaseObject(rangg);
//releaseObject(merg);
//releaseObject(mergB);
result = true;
} catch (Exception e) {
string m = e.Message;
Dispatcher.Invoke((System.Action)delegate() {
status.Content = "ugh Excel failed.. try again?";
});
result = false;
} finally {
releaseObject(xlR);
releaseObject(dataSheet);
releaseObject(sheets);
releaseObject(workbook);
releaseObject(excelApp);
}
return result;
}
public bool createBlankXL(string file, string pid, List<WR> data, List<DevT> DevTrack) {
bool result = false;
List<string> cautions = new List<string>();
Excel.Application excelApp = null;
Excel.Workbook workbook = null;
Excel.Sheets sheets = null;
Excel.Worksheet dataSheet = null;
int rowS = 3;
int colS = 1;
try {
excelApp = new Excel.Application();
workbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
sheets = workbook.Sheets;
dataSheet = sheets[1];
dataSheet.Name = "Data";
int p = 0;
#region Header format
dataSheet.Cells[rowS - 2, colS] = pid;
dataSheet.Cells[rowS - 2, colS + 1] = "Initialized: " + DateTime.Now.Month.ToString("00") + "/" + DateTime.Now.Day.ToString("00") + "/" + DateTime.Now.Year.ToString().Substring(2, 2);
dataSheet.Cells[rowS - 1, colS + p] = "JIRA ID";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Variances";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "WR";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Issue Type";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Team";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Product";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Release Submitted Against";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Summary";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Proj. Del. Priority";
//dataSheet.Cells[rowS - 1, colS + p] = "Variance Status";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "IV Status";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Original Statuses";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Status Change?";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Current Statuses";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Original Commitment";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Change?";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Current Commitment";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Original Release Date";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Date Change?";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Current Release Date";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Original Target Release";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Rel. Change?";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Current Target Release";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Created Date";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Requested Date";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Resolution Date";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Required for Certification";
p++;
dataSheet.Cells[rowS - 1, colS + p] = "Justification";
p++;
#endregion
//string test = null;
int i = rowS;
double j = 100.0;
double k = j / data.Count();
List<string> JKEYS = new List<string>();
JKEYS.Add(" ");
bool IVTest = true;
bool IsFilterStatus = false;
bool ivStatCert = true;
Dispatcher.Invoke((System.Action)delegate() {
IVTest = IVCheck.IsChecked.Value;
IsFilterStatus = StatusFilter.IsChecked.Value;
if (ivStats.Text != "DevTrack") {
ivStatCert = false;
}
});
#region data formatting
foreach (WR dd in data) {
foreach (Jissues info in dd.issues) {
//foreach (Jissues info in dd.issues) {
WRQuery WRQ = new WRQuery(info, pid);
if (!ContainsLoop(JKEYS,WRQ.JKey)) {
int o = 0;
string IVValue = "";
if (IVTest&&DevTrack!=null) {
IVValue = getIV(WRQ.WR, DevTrack);
} else {
IVValue = WRQ.Variances;
}
dataSheet.Cells[i, colS + o] = WRQ.JKey;//JIRA ID
JKEYS.Add(WRQ.JKey);
o++;
dataSheet.Cells[i, colS + o] = IVValue;
o++;
dataSheet.Cells[i, colS + o] = WRQ.WR;
o++;
dataSheet.Cells[i, colS + o] = WRQ.IssueType;
o++;
dataSheet.Cells[i, colS + o] = WRQ.Suite;//just team //getSuite(WRQ.JKey);
o++;
dataSheet.Cells[i, colS + o] = WRQ.Product;
o++;
dataSheet.Cells[i, colS + o] = WRQ.CurrentRelease;
o++;
dataSheet.Cells[i, colS + o] = "'"+WRQ.Summary;
o++;
dataSheet.Cells[i, colS + o] = WRQ.ProjDeliveryPriority;
o++;
if (ivStatCert&&DevTrack!=null) {
dataSheet.Cells[i, colS + o] = getIVStatus(WRQ.WR, DevTrack);
} else {
dataSheet.Cells[i, colS + o] = WRQ.FirstVarianceStatus;
}
o++;
//if (DevTrack != null) {
// dataSheet.Cells[i, colS + o] = "DevT: " + getDStatus(WRQ.WR, DevTrack) + Environment.NewLine + "JIRA as " + WRQ.Resolution + Environment.NewLine + WRQ.Status;
//} else {
dataSheet.Cells[i, colS + o] = WRQ.Resolution+Environment.NewLine+WRQ.Status;
//}
o++;
dataSheet.Cells[i, colS + o] = "No Change";
o++;
//if (DevTrack != null) {
// dataSheet.Cells[i, colS + o] = "DevT: " + getDStatus(WRQ.WR, DevTrack) + Environment.NewLine + "JIRA as " + WRQ.Resolution + Environment.NewLine + WRQ.Status;
//} else {
dataSheet.Cells[i, colS + o] = WRQ.Resolution + Environment.NewLine + WRQ.Status;
//}
o++;
dataSheet.Cells[i, colS + o] = WRQ.Commitment;
o++;
dataSheet.Cells[i, colS + o] = "No Change";
o++;//change?
dataSheet.Cells[i, colS + o] = WRQ.Commitment;
o++;//latest commitment
dataSheet.Cells[i, colS + o] = WRQ.DueDate;
o++;
dataSheet.Cells[i, colS + o] = "No Change";
o++;//change?
dataSheet.Cells[i, colS + o] = WRQ.DueDate;
o++;//latest planned due date
dataSheet.Cells[i, colS + o] = WRQ.TargetRelease;
o++;
dataSheet.Cells[i, colS + o] = "No Change";
o++;//change?
dataSheet.Cells[i, colS + o] = WRQ.TargetRelease;
o++;//latest target release
dataSheet.Cells[i, colS + o] = WRQ.Created;
o++;
dataSheet.Cells[i, colS + o] = WRQ.RequestedDate;
o++;
dataSheet.Cells[i, colS + o] = WRQ.ResolutionDate;
i++;
}
}
Dispatcher.Invoke((System.Action)delegate() {
pBar.Value += k;
});
}
#endregion
#region Color, width, borders, etc
int maxRowsA = dataSheet.UsedRange.Rows.Count;
Excel.Range rangg = dataSheet.get_Range("A2:AA"+maxRowsA.ToString());
dataSheet.ListObjects.AddEx(XlListObjectSourceType.xlSrcRange, rangg, Type.Missing, Excel.XlYesNoGuess.xlYes, Type.Missing).Name = "MyTableStyle";
dataSheet.ListObjects.get_Item("MyTableStyle").TableStyle = "TableStyleMedium1";
dataSheet.get_Range("A:AA", Type.Missing).EntireColumn.VerticalAlignment = XlVAlign.xlVAlignCenter;
dataSheet.get_Range("B:Z", Type.Missing).EntireColumn.WrapText = true;
dataSheet.get_Range("A:F", Type.Missing).EntireColumn.ColumnWidth = 12;
dataSheet.get_Range("G:G", Type.Missing).EntireColumn.ColumnWidth = 21;
dataSheet.get_Range("C:C", Type.Missing).EntireColumn.ColumnWidth = 8;
dataSheet.get_Range("H:H", Type.Missing).EntireColumn.ColumnWidth = 32;
dataSheet.get_Range("I:Y", Type.Missing).EntireColumn.ColumnWidth = 18;
dataSheet.get_Range("Z:Z", Type.Missing).EntireColumn.ColumnWidth = 15;
dataSheet.get_Range("AA:AA", Type.Missing).EntireColumn.ColumnWidth = 32;
dataSheet.get_Range("H:H", Type.Missing).EntireColumn.HorizontalAlignment = XlHAlign.xlHAlignCenter;
dataSheet.get_Range("C:C", Type.Missing).EntireColumn.HorizontalAlignment = XlHAlign.xlHAlignCenter;
dataSheet.get_Range("I:Y", Type.Missing).EntireColumn.HorizontalAlignment = XlHAlign.xlHAlignCenter;
dataSheet.get_Range("A:AA", Type.Missing).Cells.Font.Size = 8;
dataSheet.get_Range("A2", "AA2").Cells.Font.Size = 11;
dataSheet.get_Range("A1", Type.Missing).Cells.Font.Size = 11;
dataSheet.get_Range("A2", "AA2").Cells.Font.Bold = true;
dataSheet.get_Range("A1", Type.Missing).Cells.Font.Bold = true;
//dataSheet.get_Range("A:G", Type.Missing).EntireColumn.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.SkyBlue);
dataSheet.get_Range("A2", "AA2").HorizontalAlignment = XlHAlign.xlHAlignLeft;
dataSheet.get_Range("A2", "AA2").Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
dataSheet.get_Range("A2", "I2").Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DeepSkyBlue);
dataSheet.get_Range("J2", "M2").Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Orange);
dataSheet.get_Range("N2", "Y2").Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.MediumSeaGreen);
dataSheet.get_Range("Z2", "AA2").Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightCoral);
dataSheet.get_Range("A1", "AA1").Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
dataSheet.get_Range("A:AA", Type.Missing).Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
dataSheet.get_Range("A1", "AA1").Borders.LineStyle = XlLineStyle.xlLineStyleNone;
dataSheet.get_Range("I1", "AA1").HorizontalAlignment = XlHAlign.xlHAlignLeft;
#endregion
//excelApp.Cells.Locked = true;
//excelApp.get_Range("A:S",Type.Missing).Locked = true;
Dispatcher.Invoke((System.Action)delegate() {
status.Content = "Checking for errors...";
});
List<string> NotInJIRA = new List<string>();
if (DevTrack != null) {
NotInJIRA = CompareDJ(DevTrack, data);
}
Excel.Range merg = dataSheet.get_Range("D1", "H1");
Excel.Range mergB = dataSheet.get_Range("I1", "P1");
merg.Merge(Type.Missing);
mergB.Merge(Type.Missing);
dataSheet.get_Range("A1", "AA1").EntireRow.RowHeight = 50;
dataSheet.get_Range("A1", Type.Missing).WrapText = true;
if (cautions.Count > 0) {
dataSheet.Cells[1, 4] = "Info: " + string.Join(", ", cautions);
} else {
dataSheet.Cells[1, 4] = "";
}
if (NotInJIRA.Count > 0) {
string cautCell = dataSheet.get_Range("D1", Type.Missing).Value;
if (cautCell == "") {
dataSheet.Cells[1, 4] = "DevT WRs not in JIRA: " + string.Join(", ", NotInJIRA);
} else {
dataSheet.Cells[1, 4] = cautCell + Environment.NewLine + "DevT WRs not in JIRA: " + string.Join(", ", NotInJIRA);
}
}
//dataSheet.Cells[1, 4] = "Info: " + string.Join(", ", cautions);
//if (NotInJIRA.Count > 0) {
// dataSheet.Cells[1, 9] = "DevT WRs not in JIRA: " + string.Join(", ", NotInJIRA);
//}
Dispatcher.Invoke((System.Action)delegate() {
status.Content = "Saving file...";
});
bool readOnly = true;
excelApp.DisplayAlerts = false;
workbook.SaveAs(file, XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, readOnly, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing);
workbook.Close(true, Type.Missing, Type.Missing);
excelApp.Quit();
releaseObject(rangg);
releaseObject(merg);
releaseObject(mergB);
result = true;
} catch (Exception e) {
string m = e.Message;
Dispatcher.Invoke((System.Action)delegate() {
status.Content = "ugh Excel failed.. try again?";
});
result = false;
} finally {
releaseObject(dataSheet);
releaseObject(sheets);
releaseObject(workbook);
releaseObject(excelApp);
}
return result;
}
public bool dateComp(string worksheetDate, string JIRADate) {
//string temp = undate(JIRADate + "T");
worksheetDate += " ";
if (worksheetDate.Substring(0, worksheetDate.IndexOf(" ")) == undate(JIRADate + "T")) {
return true;
} else {
return false;
}
}
public bool updateMain(Excel.Worksheet frontPage, List<string> JKeys, string IVStatus, string IssueType, string projDelPrio, string JKey, string SWDCommit, string PlanReleaseDate, string TargetRelease, string RequestedDate/*statuses*/,string DWR, List<DevT> LinkedWRs) {
int commitCell = 14;
int issueType = 4;
int projdelprio = 9;
int releaseDateCell = 17;
int ivstatusn = 10;
int targetCell = 20;
int requestCell = 11;//Original Status
int acctCell = 26;
//int indexer = getIndex(DevTWRs(LinkedWRs), DWR);
int index = getIndex(JKeys, JKey)+1;//JKeys.FindIndex(s => s == JKey); //WTF SLOW
string acceptance = "";
try { acceptance = frontPage.Cells[index, acctCell].Value.ToString(); } catch { }
if (acceptance != "") {
acceptance = "Was: " + acceptance;
}
if (index >0) {//if exists
frontPage.Cells[index, commitCell+2] = SWDCommit;
frontPage.Cells[index, issueType] = IssueType;
frontPage.Cells[index, projdelprio] = projDelPrio;
frontPage.Cells[index, ivstatusn] = IVStatus;
string temp = "";
try{temp=frontPage.Cells[index, commitCell].Value.ToString();}catch{}
if (temp == SWDCommit) {
frontPage.Cells[index, commitCell+1] = "No Change";
} else {
frontPage.Cells[index, commitCell+1] = "Changed!";
frontPage.get_Range("A" + index, "I" + index).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
frontPage.Cells[index, commitCell + 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Violet);
frontPage.Cells[index, acctCell] = acceptance;
}
temp = "xxx";
frontPage.Cells[index, releaseDateCell+2] = PlanReleaseDate;
try { temp = frontPage.Cells[index, releaseDateCell].Value.ToString(); } catch { }
if ( dateComp(temp, PlanReleaseDate)) {
frontPage.Cells[index, releaseDateCell+1] = "No Change";
} else {
frontPage.Cells[index, releaseDateCell+1] = "Changed!";
frontPage.get_Range("A" + index, "I" + index).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
frontPage.Cells[index, releaseDateCell + 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Violet);
frontPage.Cells[index, acctCell] = acceptance;
}
frontPage.Cells[index, targetCell+2] = TargetRelease;
temp = "xxx";
try { temp = frontPage.Cells[index, targetCell].Value.ToString(); } catch { }
if (temp == TargetRelease) {
frontPage.Cells[index, targetCell+1] = "No Change";
} else {
frontPage.Cells[index, targetCell + 1] = "Changed!";
frontPage.get_Range("A" + index, "I" + index).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
frontPage.Cells[index, targetCell + 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Violet);
frontPage.Cells[index, acctCell] = acceptance;
}
frontPage.Cells[index, requestCell+2] = RequestedDate;
temp = "xxx";
try { temp = frontPage.Cells[index, requestCell].Value.ToString(); } catch { }
if (temp==RequestedDate) {
frontPage.Cells[index, requestCell+1] = "No Change";
} else {
frontPage.Cells[index, requestCell + 1] = "Changed!";
frontPage.get_Range("A" + index, "I" + index).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
frontPage.Cells[index, requestCell + 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Violet);
frontPage.Cells[index, acctCell] = acceptance;
}
return true;
}