-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_work_flow.aspx.cs
690 lines (657 loc) · 30.5 KB
/
admin_work_flow.aspx.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
using sysExtension;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class admin_work_flow : System.Web.UI.Page
{
private void SetBodyEventOnLoad(string myFunc)
{
((_MP_Front)this.Master).SetBodyEventOnLoad(myFunc);
}
protected void Page_Load(object sender, EventArgs e)
{
if (UserAcc.UserExpired())
{
SetBodyEventOnLoad(SystemFunction.PopupLogin());
}
else
{
if (!IsPostBack)
{
SystemFunction.BindDropdownPageSize(ddlPageSize, null);
GETDDL();
int Prms = SystemFunction.GetPermissionMenu(36);
//hdfPrmsMenu.Value = Prms + "";
//bool isView = Prms == 1;
//if (isView)
//{
// DivCreate_Workflow.Visible = false;
// ckbAll.Visible = false;
// btnDel.Visible = false;
//}
}
}
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static TRetunrLoadData LoadData(CSearch itemSearch)
{
TRetunrLoadData result = new TRetunrLoadData();
if (!UserAcc.UserExpired())
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
List<TDataTable> lstData = new List<TDataTable>();
//var Indicator = db.mTIndicator.ToList();
//var Facility = db.mTFacility.Where(w => w.cActive == "Y" && w.cDel == "N").ToList();
//var Operation = db.mOperationType.Where(w => w.cActive == "Y" && w.cDel == "N").ToList();
//var TbUser = db.mTUser.Where(w => w.cActive == "Y" && w.cDel == "N").ToList();
int Operation_ID = 0;
string sCon = "";
int nRoleID = UserAcc.GetObjUser().nRoleID;
int nUserID = UserAcc.GetObjUser().nUserID;
if (nRoleID == 6)
{
var Get_Fac = db.mTUser_FacilityPermission.Where(w => w.nUserID == nUserID && w.nRoleID == nRoleID).ToList(); // User And Role Get Facility
var lst_SubFac = Get_Fac.Select(id => id.nFacilityID).ToList(); //Facility ID in Company_admin
if (lst_SubFac.Any())
{
string Format = "";
lst_SubFac.ForEach(f =>
{
int FacID = f;
Format += "," + FacID + "";
});
Format = Format.Remove(0, 1);
sCon += @" AND mtf.IDFac IN (" + Format + ") ";
//sCon += @" AND tu.ID IN (" + Format + ") ";
}
}
string sSearch = itemSearch.sSearch.Trims().ToLower();
if (!string.IsNullOrEmpty(sSearch))
{
sCon += @" AND (LOWER(tu.Firstname) LIKE '%" + sSearch + "%' COLLATE THAI_CI_AI OR LOWER(tu.Lastname) LIKE '%" + sSearch + "%' COLLATE THAI_CI_AI OR LOWER(tu1.Firstname) LIKE '%" + sSearch + "%' COLLATE THAI_CI_AI OR LOWER(tu1.Lastname) LIKE '%" + sSearch + "%' COLLATE THAI_CI_AI) ";
}
if (!string.IsNullOrEmpty(itemSearch.sOperationID))
{
sCon += @" AND mf.OperationTypeID = " + itemSearch.sOperationID + @" ";
}
if (!string.IsNullOrEmpty(itemSearch.sFacilityID))
{
sCon += @" AND mtf.IDFac = " + itemSearch.sFacilityID + @" ";
}
if (!string.IsNullOrEmpty(itemSearch.sIndicatorID))
{
sCon += @" AND mtf.IDIndicator = " + itemSearch.sIndicatorID + @" ";
}
//&& (!string.IsNullOrEmpty(sSearch) ? w.Name.ToLower().Contains(sSearch) : true)
string _SQL = @" SELECT mtf.IDFac as IDFac
,mtf.IDIndicator as IDIndicator
,mtf.L1 as L1
,mtf.L2 as L2
,mtf.dUpdate as dUpdate
,mti.Indicator as sGroupName
,mf.OperationTypeID as IDOperation
,ISNULL(mot.Name,'') as sOperationName
,ISNULL(mf.Name,'') as sFacilityName
,ISNULL(tu.Firstname,'') +' '+ ISNULL(tu.Lastname,'') AS sManagerName
,ISNULL(tu1.Firstname,'') +' '+ ISNULL(tu1.Lastname,'') AS sEnvironName
FROM mTWorkFlow mtf
INNER JOIN mTIndicator mti ON mtf.IDIndicator = mti.ID
INNER JOIN mTFacility mf ON mf.ID = mtf.IDFac AND mf.cActive = 'Y' AND mf.cDel = 'N'
INNER JOIN mOperationType mot ON mot.ID = mf.OperationTypeID AND mot.cActive = 'Y' AND mot.cDel = 'N'
LEFT JOIN mTUser tu ON tu.ID = mtf.L1 AND tu.cActive = 'Y' AND tu.cDel = 'N'
LEFT JOIN mTUser tu1 ON tu1.ID = mtf.L2 AND tu1.cActive = 'Y' AND tu1.cDel = 'N'
WHERE mtf.cDel ='N' " + sCon + @"
ORDER BY mtf.dUpdate DESC ";
DataTable dt = CommonFunction.Get_Data(SystemFunction.strConnect, _SQL);
lstData = CommonFunction.ConvertDatableToList<TDataTable>(dt).ToList();
//CommonFunction.
//lstData = db.mTWorkFlow.Where(w => w.cDel == "N").AsEnumerable().Select(s => new TDataTable
//{
// IDFac = s.IDFac,
// IDOperation = Operation_ID = Facility.Any(a => a.ID == s.IDFac && a.cDel == "N" && a.cActive == "Y") ? Facility.First(a => a.ID == s.IDFac && a.cDel == "N" && a.cActive == "Y").OperationTypeID : 0,
// IDIndicator = s.IDIndicator,
// sFacilityName = Facility.Any(a => a.ID == s.IDFac) ? Facility.First(a => a.ID == s.IDFac && a.cDel == "N" && a.cActive == "Y").Name : "",
// sGroupName = Indicator.Any(a => a.ID == s.IDIndicator) ? Indicator.First(a => a.ID == s.IDIndicator).Indicator : "",
// sOperationName = Operation.Any(a => a.ID == Operation_ID) ? Operation.First(a => a.ID == Operation_ID).Name : "",
// L1 = s.L1,
// L2 = s.L2,
// dUpdate = s.dUpdate,
// sManagerName = TbUser.Any(a => a.ID == s.L1) ? TbUser.First(a => a.ID == s.L1 && a.cActive == "Y" && a.cDel == "N").Firstname + ' ' + TbUser.First(a => a.ID == s.L1 && a.cActive == "Y" && a.cDel == "N").Lastname : "",
// sEnvironName = TbUser.Any(a => a.ID == s.L2) ? TbUser.First(a => a.ID == s.L2 && a.cActive == "Y" && a.cDel == "N").Firstname + ' ' + TbUser.First(a => a.ID == s.L2 && a.cActive == "Y" && a.cDel == "N").Lastname : "",
//}).OrderByDescending(o => o.dUpdate).ToList();
lstData = lstData.Where(w => w.sOperationName != "" && w.sFacilityName != "").ToList();
#region//SORT
int? nSortCol = SystemFunction.GetIntNull(itemSearch.sIndexCol);
switch ((itemSearch.sOrderBy + "").ToLower())
{
case SystemFunction.ASC:
{
switch (nSortCol)
{
case 1: lstData = lstData.OrderBy(o => o.sOperationName).ToList(); break;
case 2: lstData = lstData.OrderBy(o => o.sFacilityName).ToList(); break;
case 3: lstData = lstData.OrderBy(o => o.sGroupName).ToList(); break;
case 4: lstData = lstData.OrderBy(o => o.sManagerName).ToList(); break;
case 5: lstData = lstData.OrderBy(o => o.sEnvironName).ToList(); break;
}
}
break;
case SystemFunction.DESC:
{
switch (nSortCol)
{
case 1: lstData = lstData.OrderByDescending(o => o.sOperationName).ToList(); break;
case 2: lstData = lstData.OrderByDescending(o => o.sFacilityName).ToList(); break;
case 3: lstData = lstData.OrderByDescending(o => o.sGroupName).ToList(); break;
case 4: lstData = lstData.OrderByDescending(o => o.sManagerName).ToList(); break;
case 5: lstData = lstData.OrderByDescending(o => o.sEnvironName).ToList(); break;
}
}
break;
}
#endregion
#region//Final Action >> Skip Take Data For Javasacript
sysGlobalClass.Pagination dataPage = new sysGlobalClass.Pagination();
dataPage = SystemFunction.GetPaginationSmall(SystemFunction.GetIntNullToZero(itemSearch.sPageSize), SystemFunction.GetIntNullToZero(itemSearch.sPageIndex), lstData.Count);
lstData = lstData.Skip(dataPage.nSkipData).Take(dataPage.nTakeData).ToList();
//foreach (var item in lstData)
//{
// item.sUpdate = item.dUpdate.DateString();
// item.sLink = "<a class='btn btn-warning' href='admin_company_update.aspx?strid=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.IDOperation.ToString())) + "'><i class='fa fa-edit'></i> Edit</a>";
//}
result.lstData = lstData;
result.nPageCount = dataPage.nPageCount;
result.nPageIndex = dataPage.nPageIndex;
result.sPageInfo = dataPage.sPageInfo;
result.sContentPageIndex = dataPage.sContentPageIndex;
result.nStartItemIndex = dataPage.nStartItemIndex;
#endregion
}
else
{
result.Status = SystemFunction.process_SessionExpired;
}
return result;
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static sysGlobalClass.CResutlWebMethod DeleteData(string[] arrValue)
{
sysGlobalClass.CResutlWebMethod result = new sysGlobalClass.CResutlWebMethod();
if (!UserAcc.UserExpired())
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
List<int> lstDelID = new List<int>();
if (arrValue != null)
foreach (var item in arrValue)
{
string[] strArr = null;
char[] splitchar = { ',' };
strArr = item.Split(splitchar);
int nFacID = int.Parse(strArr[0]);
int nGroupID = int.Parse(strArr[1]);
int nUserID = UserAcc.GetObjUser().nUserID;
db.mTWorkFlow.Where(w => w.IDFac == nFacID && w.IDIndicator == nGroupID).ToList().ForEach(x =>
{
db.mTWorkFlow.Remove(x);
//x.cDel = "Y";
//x.dUpdate = DateTime.Now;
//x.nUpdateID = nUserID;
});
}
db.SaveChanges();
result.Status = SystemFunction.process_Success;
}
else
{
result.Status = SystemFunction.process_SessionExpired;
}
return result;
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static TRetunrLoadData ConfirmData(List<TDataDupicate> lstData, List<TDataFacAndIndicator> lstData_Save)
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
TRetunrLoadData result = new TRetunrLoadData();
string Del_SQL = "";
string Insert_SQL = "";
DateTime now = DateTime.Now;
int nUserID = UserAcc.GetObjUser().nUserID;
if (UserAcc.UserExpired())
{
result.Status = SystemFunction.process_SessionExpired;
}
else
{
if (lstData.Count > 0)
{
foreach (var item in lstData)
{
Del_SQL += @" DELETE FROM mTWorkFlow WHERE IDFac = " + item.nFacID + @" AND IDIndicator = " + item.nIndicatorID + @" ";
Insert_SQL += @" INSERT INTO mTWorkFlow (IDFac,IDIndicator,L1,L2,nUpdateID,dUpdate,cDel) VALUES ('" + item.nFacID + @"','" + item.nIndicatorID + @"','" + item.sManagerID + @"','" + item.sEnvironID + @"','" + nUserID + @"','" + now + @"','N') ";
}
SystemFunction.ExecuteSQL(SystemFunction.strConnect, Del_SQL);
SystemFunction.ExecuteSQL(SystemFunction.strConnect, Insert_SQL);
result.Status = SystemFunction.process_Success;
}
else
{
result.Status = SystemFunction.process_Failed;
result.Msg = "Data not found";
}
if (lstData_Save.Count > 0)
{
foreach (var item in lstData_Save)
{
Del_SQL += @" DELETE FROM mTWorkFlow WHERE IDFac = " + item.nFacID + @" AND IDIndicator = " + item.nIndicatorID + @" ";
Insert_SQL += @" INSERT INTO mTWorkFlow (IDFac,IDIndicator,L1,L2,nUpdateID,dUpdate,cDel) VALUES ('" + item.nFacID + @"','" + item.nIndicatorID + @"','" + item.sManagerID + @"','" + item.sEnvironID + @"','" + nUserID + @"','" + now + @"','N') ";
}
SystemFunction.ExecuteSQL(SystemFunction.strConnect, Del_SQL);
SystemFunction.ExecuteSQL(SystemFunction.strConnect, Insert_SQL);
result.Status = SystemFunction.process_Success;
}
}
return result;
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static TRetunrLoadData AddOperation(List<string> lst_Operation, List<string> lst_Facility, List<string> lst_GroupIndicator, string sManagerID, string sEnvironID)
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
TRetunrLoadData result = new TRetunrLoadData();
List<TDataFacAndIndicator> lstData = new List<TDataFacAndIndicator>();
List<TDataFacAndIndicator> lstDataToSave = new List<TDataFacAndIndicator>();
List<TDataDupicate> lstDataDuplicate = new List<TDataDupicate>();
if (!UserAcc.UserExpired())
{
Func<int?, int?, bool> CheckDuplicateID = (IDFac, IDIndicator) =>
{
bool Isdup = false;
var q = db.mTWorkFlow.Where(w => w.IDFac == IDFac && w.IDIndicator == IDIndicator && w.cDel == "N");
Isdup = q.Any();
return Isdup;
};
if (lst_Facility != null)
{
int nFacID = 0;
int nIndicatorID = 0;
foreach (var Fac in lst_Facility)
{
nFacID = int.Parse(Fac);
var lstFac = db.mTFacility.Where(w => w.ID == nFacID && w.cDel == "N" && w.cActive == "Y").ToList();
if (lst_GroupIndicator != null)
{
foreach (var Indicator in lst_GroupIndicator)
{
nIndicatorID = int.Parse(Indicator);
var lstIndicator = db.mTIndicator.Where(w => w.ID == nIndicatorID).ToList();
lstData.Add(new TDataFacAndIndicator
{
nFacID = nFacID,
sFacName = lstFac.Any() ? lstFac.First(a => a.ID == nFacID).Name : "",
nIndicatorID = nIndicatorID,
sIndicatorName = lstIndicator.Any() ? lstIndicator.First(a => a.ID == nIndicatorID).Indicator : "",
});
}
lstData.Distinct().ToList();
}
}
string _SQL = "";
if (lstData.Any())
{
DateTime now = DateTime.Now;
int nUserID = UserAcc.GetObjUser().nUserID;
bool Ispass = true;
foreach (var item in lstData)
{
if (!CheckDuplicateID(item.nFacID, item.nIndicatorID))
{
_SQL += @" INSERT INTO mTWorkFlow (IDFac,IDIndicator,L1,L2,nUpdateID,dUpdate,cDel) VALUES ('" + item.nFacID + @"','" + item.nIndicatorID + @"','" + sManagerID + @"','" + sEnvironID + @"','" + nUserID + @"','" + now + @"','N') ";
//result.Status = SystemFunction.process_Success;
lstDataToSave.Add(new TDataFacAndIndicator
{
nFacID = item.nFacID,
nIndicatorID = item.nIndicatorID,
sManagerID = sManagerID,
sEnvironID = sEnvironID,
sFacName = item.sFacName,
sIndicatorName = item.sIndicatorName,
});
}
else
{
//result.Msg += " (Facility : " + item.sFacName + ") And (Group Indicator : " + item.sIndicatorName + ") ! </br>";
result.Status = SystemFunction.process_Failed;
Ispass = false;
lstDataDuplicate.Add(new TDataDupicate
{
nFacID = item.nFacID,
nIndicatorID = item.nIndicatorID,
sManagerID = sManagerID,
sEnvironID = sEnvironID,
sFacName = item.sFacName,
sIndicatorName = item.sIndicatorName,
});
//return result;
}
}
if (Ispass)
{
SystemFunction.ExecuteSQL(SystemFunction.strConnect, _SQL);
result.Status = SystemFunction.process_Success;
}
}
}
}
else
{
result.Status = SystemFunction.process_SessionExpired;
}
if (lstDataDuplicate.Any())
{
var lstFacility = lstDataDuplicate.Select(s => s.nFacID).Distinct().ToList();
if (lstFacility.Any())
{
result.Msg = " Facilities has been saved. Do you want to save again ?</br></br>";
foreach (var i in lstFacility)
{
int nFacID = i;
var lst = lstDataDuplicate.Where(w => w.nFacID == nFacID).ToList();
if (lst.Any())
{
result.Msg += " Facility : " + lst.First().sFacName + " </br>";
lst.ForEach(f =>
{
result.Msg += " - Group Indicator : " + f.sIndicatorName + " </br>";
});
result.Msg += "</br>";
}
}
}
}
result.lstToSave = lstDataToSave.Distinct().ToList();
result.lstDuplicate = lstDataDuplicate.Distinct().ToList();
result.lstMapping = lstData.Distinct().ToList();
return result;
}
#region ByDropdown
private void GETDDL()
{
int nRoleID = UserAcc.GetObjUser().nRoleID;
int nUserID = UserAcc.GetObjUser().nUserID;
DDL_Role_Manager();
DDL_Role_Environ();
DDL_OperationType(nRoleID, nUserID);
DDL_GroupIndicator();
// DDL_Facility();
}
private void DDL_Role_Manager()
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
//var lstManager = db.mTUser_FacilityPermission.Where(w => w.nRoleID == 3).Select(s => new { nUserID = s.nUserID }).Distinct().ToList();
var lstManager = db.mTUserInRole.Where(w => w.nRoleID == 3).Select(s => new { nUserID = s.nUID }).Distinct().ToList();
List<DropDownList> lstDropDown = new List<DropDownList>();
if (lstManager.Any())
{
lstManager.ForEach(f =>
{
db.mTUser.Where(w => w.cDel == "N" && w.cActive == "Y" && w.ID == f.nUserID).ToList().ForEach(f2 =>
{
lstDropDown.Add(new DropDownList()
{
Value = f2.ID,
Text = f2.Firstname + ' ' + f2.Lastname,
});
});
});
if (lstDropDown.Any())
{
ddlManager.DataSource = lstDropDown;
ddlManager.DataValueField = "Value";
ddlManager.DataTextField = "Text";
ddlManager.DataBind();
}
}
ddlManager.Items.Insert(0, new ListItem("- Manager -", ""));
}
private void DDL_Role_Environ()
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
List<DropDownList> lstDropDown = new List<DropDownList>();
//var lstEnviron = db.mTUser_FacilityPermission.Where(w => w.nRoleID == 4).Select(s => new { nUserID = s.nUserID }).Distinct().ToList();
var lstEnviron = db.mTUserInRole.Where(w => w.nRoleID == 4).Select(s => new { nUserID = s.nUID }).Distinct().ToList();
if (lstEnviron.Any())
{
lstEnviron.ForEach(f =>
{
db.mTUser.Where(w => w.cDel == "N" && w.cActive == "Y" && w.ID == f.nUserID).ToList().ForEach(f2 =>
{
lstDropDown.Add(new DropDownList()
{
Value = f2.ID,
Text = f2.Firstname + ' ' + f2.Lastname,
});
});
if (lstDropDown.Any())
{
ddlEnviron.DataSource = lstDropDown;
ddlEnviron.DataValueField = "Value";
ddlEnviron.DataTextField = "Text";
ddlEnviron.DataBind();
}
});
}
ddlEnviron.Items.Insert(0, new ListItem("- Environment -", ""));
}
private void DDL_OperationType(int nRoleID, int nUserID)
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
var lstOperationType = db.mOperationType.Where(w => w.cDel == "N" && w.cActive == "Y" && w.cManage == "N").Select(s => new { Value = s.ID, Text = s.Name }).ToList();
if (lstOperationType.Count() > 0)
{
ddlOperationType.DataSource = lstOperationType;
ddlOperationType.DataValueField = "Value";
ddlOperationType.DataTextField = "Text";
ddlOperationType.DataBind();
//ddlOperationType.Items.Insert(0, new ListItem("- Operation Type -", ""));
}
var lstOperationType_Search = db.mOperationType.Where(w => w.cDel == "N" && w.cActive == "Y" && w.cManage == "N").Select(s => new { Value = s.ID, Text = s.Name }).ToList();
//if (nRoleID == 6)
//{
// var db1 = (from a in db.mTUser_FacilityPermission select a).ToList();
// var db2 = (from a in db.mTFacility select a).ToList();
// var db3 = (from a in db.mOperationType select a).ToList();
// //var lstOperationType_1 = db.mOperationType.Where(w => w.cDel == "N" && w.cActive == "Y" && w.cManage == "N").Select(s => new { Value = s.ID, Text = s.Name }).ToList();
// lstOperationType_Search = (from a in db1
// join b in db2 on a.nFacilityID equals b.ID
// join c in db3 on b.OperationTypeID equals c.ID
// where a.nUserID == nUserID
// select new { Value = c.ID, Text = c.Name }).Distinct().ToList();
//}
if (lstOperationType_Search.Count() > 0)
{
ddlOperationSearch.DataSource = lstOperationType_Search;
ddlOperationSearch.DataValueField = "Value";
ddlOperationSearch.DataTextField = "Text";
ddlOperationSearch.DataBind();
ddlOperationSearch.Items.Insert(0, new ListItem("- Operation type -", ""));
}
}
private void DDL_GroupIndicator()
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
var lstGroup = db.mTIndicator.OrderBy(o => o.nOrder).Select(s => new { Value = s.ID, Text = s.Indicator }).ToList();
if (lstGroup.Count() > 0)
{
ddlGroupIndicator.DataSource = lstGroup;
ddlGroupIndicator.DataValueField = "Value";
ddlGroupIndicator.DataTextField = "Text";
ddlGroupIndicator.DataBind();
//ddlGroupIndicator.Items.Insert(0, new ListItem("- Operation Type -", ""));
}
var lstGroup_Search = db.mTIndicator.OrderBy(o => o.nOrder).Select(s => new { Value = s.ID, Text = s.Indicator }).ToList();
if (lstGroup_Search.Count() > 0)
{
ddlIndicatorSearch.DataSource = lstGroup_Search;
ddlIndicatorSearch.DataValueField = "Value";
ddlIndicatorSearch.DataTextField = "Text";
ddlIndicatorSearch.DataBind();
ddlIndicatorSearch.Items.Insert(0, new ListItem("- Indicator -", ""));
}
}
private void DDL_Facility()
{
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
var lstFacility = db.mTFacility.Where(w => w.cDel == "N" && w.cActive == "Y" && w.nLevel == 2).OrderBy(o => o.Name).Select(s => new { Value = s.ID, Text = s.Name }).ToList();
if (lstFacility.Count() > 0)
{
ddlFacilitySearch.DataSource = lstFacility;
ddlFacilitySearch.DataValueField = "Value";
ddlFacilitySearch.DataTextField = "Text";
ddlFacilitySearch.DataBind();
ddlFacilitySearch.Items.Insert(0, new ListItem("- Sub facility -", ""));
}
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static TRetunrLoadData Get_Facility(List<int> lst)
{
//if (lst == null) lst = new List<string>();
TRetunrLoadData result = new TRetunrLoadData();
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
int nRoleID = UserAcc.GetObjUser().nRoleID;
int nUserID = UserAcc.GetObjUser().nUserID;
if (UserAcc.UserExpired())
{
result.Status = SystemFunction.process_SessionExpired;
}
else
{
List<sysGlobalClass.T_Facility> lstFacility = new List<sysGlobalClass.T_Facility>();
if (lst.Any())
{
lstFacility = SystemFunction.Get_SubFacility_ByMuti(lst, nUserID, nRoleID);
}
result.lstData_Facility = lstFacility.Distinct().ToList();
}
return result;
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static TRetunrLoadData Get_Facility_Seach(string operationID)
{
//if (lst == null) lst = new List<string>();
TRetunrLoadData result = new TRetunrLoadData();
PTTGC_EPIEntities db = new PTTGC_EPIEntities();
if (UserAcc.UserExpired())
{
result.Status = SystemFunction.process_SessionExpired;
}
else
{
int nRoleID = UserAcc.GetObjUser().nRoleID;
int nUserID = UserAcc.GetObjUser().nUserID;
List<sysGlobalClass.T_Facility> lstFacility = new List<sysGlobalClass.T_Facility>();
if (!string.IsNullOrEmpty(operationID))
{
int nID = int.Parse(operationID);
lstFacility = SystemFunction.Get_SubFacility(nID, nUserID, nRoleID);
}
result.lstData_Facility = lstFacility.Distinct().ToList();
}
return result;
}
#endregion
#region class
[Serializable]
public class CSearch : sysGlobalClass.CommonLoadData
{
public string sSearch { get; set; }
public string sStatus { get; set; }
public string sPrms { get; set; }
public string sOperationID { get; set; }
public string sIndicatorID { get; set; }
public string sFacilityID { get; set; }
}
[Serializable]
public class T_Facility
{
public int nFacilityID { get; set; }
public string sFacilityName { get; set; }
public int? nHeaderID { get; set; }
public int? nLevel { get; set; }
public string sRelation { get; set; }
public int nOperationTypeID { get; set; }
public string sOperationName { get; set; }
}
[Serializable]
public class TRetunrLoadData : sysGlobalClass.Pagination
{
public string Msg { get; set; }
public string Status { get; set; }
public List<TDataDupicate> lstDuplicate { get; set; }
public List<TDataFacAndIndicator> lstMapping { get; set; }
public List<TDataFacAndIndicator> lstToSave { get; set; }
public List<TDataTable> lstData { get; set; }
public List<sysGlobalClass.T_Facility> lstData_Facility { get; set; }
}
[Serializable]
public class TDataTable
{
public int IDOperation { get; set; }
public int IDFac { get; set; }
public int IDIndicator { get; set; }
public int? L1 { get; set; }
public int? L2 { get; set; }
public int? L3 { get; set; }
public int? L4 { get; set; }
public int? nUpdateID { get; set; }
public string sManagerName { get; set; }
public string sEnvironName { get; set; }
public DateTime? dUpdate { get; set; }
public string cDel { get; set; }
public string sGroupName { get; set; }
public string sFacilityName { get; set; }
public string sOperationName { get; set; }
public string sUpdate { get; set; }
public string sStatus { get; set; }
public string sLink { get; set; }
}
[Serializable]
public class TDataFacAndIndicator
{
public int nFacID { get; set; }
public string sFacName { get; set; }
public int nIndicatorID { get; set; }
public string sIndicatorName { get; set; }
public string sManagerID { get; set; }
public string sEnvironID { get; set; }
}
[Serializable]
public class TDataDupicate
{
public int nFacID { get; set; }
public string sFacName { get; set; }
public int nIndicatorID { get; set; }
public string sIndicatorName { get; set; }
public string sManagerID { get; set; }
public string sEnvironID { get; set; }
public int nUserID { get; set; }
public DateTime? dDate { get; set; }
}
[Serializable]
public class DropDownList
{
public int Value { get; set; }
public string Text { get; set; }
}
#endregion
}