protected void Page_Load(object sender, EventArgs e) { if (UserAcc.UserExpired()) { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } else { if (!IsPostBack) { UserAcc ua = UserAcc.GetObjUser(); hidUserID.Value = ua.nUserID + ""; hidEncryptUserID.Value = STCrypt.Encrypt(hidUserID.Value); SetData(hidUserID.Value.toIntNullToZero()); //txtOldPass.Attributes.Add("type", "password"); //string strID = Request.QueryString["strid"]; //if (!string.IsNullOrEmpty(strID)) //{ // hidUserID.Value = STCrypt.Decrypt(strID); // SetData(hidUserID.Value.toIntNullToZero()); // hidEncryptUserID.Value = STCrypt.Encrypt(hidUserID.Value); //} } } }
protected void Page_Load(object sender, EventArgs e) { if (!UserAcc.UserExpired()) { if (!IsPostBack) { setCBL(); string sQueryStrIndID = Request.QueryString["in"]; if (!string.IsNullOrEmpty(sQueryStrIndID)) { hdfIndID.Value = STCrypt.Encrypt(sQueryStrIndID); ((_MP_EPI_FORMS)this.Master).hdfPRMS = SystemFunction.GetPermissionMenu(15) + ""; ((_MP_EPI_FORMS)this.Master).hdfCheckRole = UserAcc.GetObjUser().nRoleID + ""; } else { SetBodyEventOnLoad(SystemFunction.DialogWarningRedirect(SystemFunction.Msg_HeadWarning, "Invalid Data", "Intensity_from.aspx"));// กรณีเข้ามาด้วย link ที่ไม่มี Querystring } } } else { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } }
protected void Page_Load(object sender, EventArgs e) { if (UserAcc.UserExpired()) { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } else { if (!IsPostBack) { string strID = Request.QueryString["strid"]; if (!string.IsNullOrEmpty(strID)) { hdfEncryptCompanyID.Value = STCrypt.Decrypt(strID); SetData(hdfEncryptCompanyID.Value.toIntNullToZero()); hdfEncryptCompanyID.Value = STCrypt.Encrypt(hdfEncryptCompanyID.Value); } else { //CR. 06.02.2019 Sync from SAP txtCode.Enabled = false; txtCompanyName.Enabled = false; } } } }
protected void Page_Load(object sender, EventArgs e) { if (UserAcc.UserExpired()) { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } else { if (!IsPostBack) { PTTGC_EPIEntities db = new PTTGC_EPIEntities(); string str = Request.QueryString["strid"]; if (!string.IsNullOrEmpty(str)) { int nFacID = SystemFunction.GetIntNullToZero(STCrypt.Decrypt(str)); hdfFacID.Value = str; ltrCreate.Text = "<a class=\"btn btn-primary btn-sm btn-block\" href=\"admin_asset_update.aspx?strid=" + HttpUtility.UrlEncode(str) + "\"><i class=\"fa fa-plus\"></i> Create Sub-facility</a>"; var itemHeader = db.mTFacility.FirstOrDefault(w => w.ID == nFacID); if (itemHeader != null) { var itemCompany = db.mTCompany.FirstOrDefault(w => w.ID == itemHeader.CompanyID); ltrHeader.Text = "<a href='admin_company_lst.aspx' style='color:white'>Organization</a> > <a style='color:white' href='admin_facility_lst.aspx?strid=" + HttpUtility.UrlEncode(STCrypt.Encrypt(itemCompany.ID + "")) + "'> " + itemCompany.Name + "</a> > " + itemHeader.Name;//กำหนด Header } } SystemFunction.BindDropdownPageSize(ddlPageSize, null); } } }
protected void Page_Load(object sender, EventArgs e) { string strID = ""; string[] userindname = HttpContext.Current.User.Identity.Name.Split('\\'); if (userindname.Length >= 2) { strID = userindname[1] + ""; } else//for test { strID = ""; } string sUrl = ""; if (userindname.Length >= 2) { sUrl = "~/login.aspx?strad=" + Server.UrlEncode(STCrypt.Encrypt(strID)) + "&&smod=%Agf4D%"; } else//for test { sUrl = "~/login.aspx"; } Response.Redirect(sUrl); }
public static List <TDataSAPFacility> SearchSAPFacility(string sSearch, string sFacilityID, string sAssesstID) { List <TDataSAPFacility> lstData = new List <TDataSAPFacility>(); PTTGC_EPIEntities db = new PTTGC_EPIEntities(); int nFacID = STCrypt.Decrypt(sFacilityID).toIntNullToZero(); var dataFac = db.mTFacility.FirstOrDefault(w => w.ID == nFacID); if (dataFac != null) { var dataCompany = db.mTCompany.FirstOrDefault(w => w.ID == dataFac.CompanyID); if (dataCompany != null) { int?nAssessetID = null; if (!string.IsNullOrEmpty(sAssesstID)) { nAssessetID = STCrypt.Decrypt(sAssesstID).toIntNull(); } var qFacSAPCode = db.mTFacility.Where(w => w.cDel == "N" && w.nLevel == 2 && !string.IsNullOrEmpty(w.sRefFacCode) && (nAssessetID.HasValue ? w.ID != nAssessetID : true)).Select(s => s.sRefFacCode).ToList(); sSearch = sSearch.Trims().ToLower(); var dataVPlant = db.v_TM_SAP_ALLFAC.Where(w => w.sType == "P" && !qFacSAPCode.Contains(w.sCode) && w.sCompCode == dataCompany.sCode && ((w.sName + "").ToLower().Contains(sSearch) || (w.sShortName + "").ToLower().Contains(sSearch) || (w.sCode + "").ToLower().Contains(sSearch))).Select(s => new TDataSAPFacility { sCode = s.sCode, sName = s.sCode + " - " + s.sName }).OrderBy(o => o.sName).Take(30).ToList(); var dataVComp = db.v_TM_SAP_ALLFAC.Where(w => w.sType == "O" && !qFacSAPCode.Contains(w.sCode) && ((w.sName + "").ToLower().Contains(sSearch) || (w.sShortName + "").ToLower().Contains(sSearch) || (w.sCode + "").ToLower().Contains(sSearch))).Select(s => new TDataSAPFacility { sCode = s.sCode, sName = s.sCode + " - " + s.sName }).OrderBy(o => o.sName).Take(30).ToList(); lstData = dataVPlant.Concat(dataVComp).OrderBy(o => o.sName).Take(30).ToList(); } } return(lstData); }
public static string STCDecrypt(this string instance) { if (!string.IsNullOrEmpty(instance)) { return(STCrypt.Decrypt(instance)); } else { return(""); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!UserAcc.UserExpired()) { PTTGC_EPIEntities db = new PTTGC_EPIEntities(); string str = Request.QueryString["strid"]; string strFacID = Request.QueryString["strFacID"]; int nFacilityID = 0; bool IsNew = false; if (!string.IsNullOrEmpty(str)) { hdfReturnStr.Value += "&&strid=" + HttpUtility.UrlEncode(str); int nComID = SystemFunction.GetIntNullToZero(STCrypt.Decrypt(str)); hdfComType.Value = nComID == 1 ? "PTT" : "GC"; hdfComID.Value = str; var itemCompany = db.mTCompany.FirstOrDefault(w => w.ID == nComID && w.cDel == "N"); if (itemCompany != null) { if (!string.IsNullOrEmpty(strFacID)) { IsNew = false; nFacilityID = SystemFunction.GetIntNullToZero(STCrypt.Decrypt(strFacID)); hdfFacilityID.Value = strFacID; var itemFacility = db.mTFacility.FirstOrDefault(w => w.cDel == "N" && w.ID == nFacilityID); if (itemFacility != null) { ltrHeader.Text = "<a href='admin_company_lst.aspx' style='color:white'>Organization</a> > <a href='admin_facility_lst.aspx?strid=" + HttpUtility.UrlEncode(str) + "' style='color:white'>" + itemCompany.Name + "</a> > " + itemFacility.Name + " > Edit";//กำหนด Header กรณีเข้ามา EDIT } } else { IsNew = true; ltrHeader.Text = "<a href='admin_company_lst.aspx' style='color:white'>Organization</a> > <a href='admin_facility_lst.aspx?strid=" + HttpUtility.UrlEncode(str) + "' style='color:white'>" + itemCompany.Name + "</a> > Facility > Create";//กำหนด Header กรณีเข้ามา ADD } hdfIsNew.Value = IsNew ? "C" : "E"; } setDDL_Cbl(IsNew, nComID); setData(nFacilityID); } if (string.IsNullOrEmpty(str) && string.IsNullOrEmpty(strFacID)) { SetBodyEventOnLoad(SystemFunction.DialogWarningRedirect(SystemFunction.Msg_HeadWarning, "Invalid Data", "admin_company_lst.aspx"));// กรณีเข้ามาด้วย link ที่ไม่มี Querystring } } else { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } } }
public static sysGlobalClass.CResutlWebMethod ForgetPassword(string sEmail, string sUsername) { PTTGC_EPIEntities db = new PTTGC_EPIEntities(); sysGlobalClass.CResutlWebMethod result = new sysGlobalClass.CResutlWebMethod(); sEmail = sEmail.ToLower(); sUsername = sUsername.ToLower(); var lstUser = db.mTUser.Where(w => w.cActive == "Y" && w.cDel == "N" && w.Username.ToLower() == sUsername && w.Email.ToLower() == sEmail).ToList(); if (lstUser.Any()) { var Data = lstUser.First(); string sTitle = ""; string sText = ""; string subject = ""; string message = ""; string sURL = ""; string sFoot = "";// "Should you have any questions about RD&T work process."; // sURL = Applicationpath + "login_forget.aspx?str=" + SystemFunction.Encrypt_UrlEncrypt(nDocID + ""); subject = "Password Confirmation | " + SystemFunction.SystemName + ""; sText += "<p>Your password is " + STCrypt.Decrypt(Data.PasswordEncrypt) + "</p>"; string From = SystemFunction.GetSystemMail; string To = Data.Email; message = string.Format(GET_TemplateEmail(), "Dear " + Data.Firstname + ' ' + Data.Lastname, sText, sURL, sFoot, "", ""); Workflow.DataMail_log log = new Workflow.DataMail_log(); log = SystemFunction.SendMailAll(From, To, "", "", subject, message, ""); log.nDataID = SystemFunction.GetIntNullToZero(Data.ID + ""); log.sPageName = "login.aspx"; new Workflow().SaveLogMail(log); if (log.bStatus) { result.Status = SystemFunction.process_Success; } } else { result.Status = SystemFunction.process_Failed; result.Msg = "data not found user"; } return(result); }
public static sysGlobalClass.TRetunrLoadData CreateLinkExport(IntensityClass it) { sysGlobalClass.TRetunrLoadData o = new sysGlobalClass.TRetunrLoadData(); try { if (!UserAcc.UserExpired()) { string sPath = "#"; switch (it.nOperationType) { case 4: sPath = "export_epi_input_intensity_1.aspx"; ssTRetunrLoadData_1 = GetLoadData(it); break; case 11: sPath = "export_epi_input_intensity_2.aspx"; ssTRetunrLoadData_2 = GetLoadData(it); break; case 13: sPath = "export_epi_input_intensity_3.aspx"; ssTRetunrLoadData_3 = GetLoadData(it); break; case 14: sPath = "export_epi_input_intensity_4.aspx"; ssTRetunrLoadData_4 = GetLoadData(it); break; } if (sPath != "#") { sPath = sPath + "?str1=" + HttpUtility.UrlEncode(STCrypt.Encrypt(it.nFacility + "")) + "&&str2=" + HttpUtility.UrlEncode(STCrypt.Encrypt(it.sYear + "")); } o.sPath = sPath; //var lst = GetLoadData(it); o.sStatus = SystemFunction.process_Success; o.sMsg = ""; } else { o.sStatus = SystemFunction.process_SessionExpired; o.sMsg = "Session Expired !!"; } } catch (Exception ex) { o.sStatus = SystemFunction.process_Failed; o.sMsg = ex.ToString(); } return(o); }
protected void Page_Load(object sender, EventArgs e) { string str = Request.QueryString["strad"]; string sm = Request.QueryString["smod"]; string sAD = ""; if (!string.IsNullOrEmpty(sm)) { if (!string.IsNullOrEmpty(str)) { hdfUserAD.Value = STCrypt.Decrypt(str); } } }
protected void Page_Load(object sender, EventArgs e) { string sIN = Request.QueryString["in"] + ""; string sOT = Request.QueryString["ot"] + ""; if (!string.IsNullOrEmpty(sIN)) { hdfsIndicator.Value = STCrypt.Decrypt(sIN); } if (!string.IsNullOrEmpty(sOT)) { hdfsOperationType.Value = STCrypt.Decrypt(sOT); } SystemFunction.ListYearsDESC(ddlYear, "-select-", "en-US", "th-TH", short.Parse(ConfigurationSettings.AppSettings["startYear"].ToString())); }
protected void Page_Load(object sender, EventArgs e) { SetBodyEventOnLoad(""); if (UserAcc.UserExpired()) { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } else { if (!IsPostBack) { PTTGC_EPIEntities env = new PTTGC_EPIEntities(); string sFormID = Request.QueryString["strid"]; // Form ID string sLevel = Request.QueryString["strlevel"]; // Level (L1 = 3,L2 = 4 ,L0 = 2) After Decrypt int nFormID = 0; int.TryParse(STCrypt.Decrypt(sFormID), out nFormID); var gDataForm = env.TEPI_Forms.FirstOrDefault(w => w.FormID == nFormID); if (!string.IsNullOrEmpty(sFormID)) { if (gDataForm != null) { hidFacility.Value = gDataForm.FacilityID.ToString(); hidIndicator.Value = gDataForm.IDIndicator.ToString(); hidOperationType.Value = gDataForm.OperationTypeID.ToString(); hidYear.Value = gDataForm.sYear; var qOpera = env.mOperationType.FirstOrDefault(w => w.ID == gDataForm.OperationTypeID); var qFac = env.mTFacility.FirstOrDefault(w => w.ID == gDataForm.FacilityID); var qGroupInd = env.mTIndicator.FirstOrDefault(w => w.ID == gDataForm.IDIndicator); lblGroupIndicator.Text = qGroupInd != null ? qGroupInd.Indicator : ""; lblOperationtype.Text = qOpera.Name; lblFacility.Text = qFac != null ? qFac.Name : ""; lblYear.Text = gDataForm.sYear; } hidFormID.Value = STCrypt.Decrypt(sFormID); if (!string.IsNullOrEmpty(sLevel)) { hidLevel.Value = STCrypt.Decrypt(sLevel); } } else { Response.Redirect("epi_mytask.aspx"); } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string str = Request.QueryString["str"]; if (!string.IsNullOrEmpty(str)) { string sDataDecrypt = STCrypt.Decrypt(str); var arrDataDecrypt = sDataDecrypt.Split('|'); string sIncID = arrDataDecrypt[0]; string sOprtID = arrDataDecrypt[1]; string sFacID = arrDataDecrypt[2]; string sYear = arrDataDecrypt[3]; ExportData(sIncID, sOprtID, sFacID, sYear); } } }
protected void Page_Load(object sender, EventArgs e) { if (UserAcc.UserExpired()) { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } else { if (!IsPostBack) { string strID = Request.QueryString["str"]; if (!string.IsNullOrEmpty(strID)) { hdfProductID.Value = STCrypt.Decrypt(strID); SetData(hdfProductID.Value); } } } }
protected void Page_Load(object sender, EventArgs e) { if (UserAcc.UserExpired()) { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } else { if (!IsPostBack) { string str = Request.QueryString["strid"]; if (!string.IsNullOrEmpty(str)) { hidEncyptID.Value = str; hidnID.Value = STCrypt.Decrypt(str); SETDATA(hidnID.Value); } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SystemFunction.BindDropdownPageSize(ddlPageSize, null); SystemFunction.BindDropdownPageSize(ddlPageSizeGC, null); if (!UserAcc.UserExpired()) { string str = Request.QueryString["strid"]; if (!string.IsNullOrEmpty(str)) { if (SystemFunction.GetIntNullToZero(STCrypt.Decrypt(str)) != 1) { SetBodyEventOnLoad("$('div[id$=divContentGC]').show();$('div[id$=divContent]').hide()"); } else { SetBodyEventOnLoad("$('div[id$=divContentGC]').hide();$('div[id$=divContent]').show()"); } PTTGC_EPIEntities db = new PTTGC_EPIEntities(); int nComID = SystemFunction.GetIntNullToZero(STCrypt.Decrypt(str)); hdfComID.Value = STCrypt.Encrypt(nComID + ""); var itemCompany = db.mTCompany.FirstOrDefault(w => w.ID == nComID && w.cDel == "N"); if (itemCompany != null) { ltrHeader.Text = "<a href='admin_company_lst.aspx' style='color:white'>Organization</a> > " + itemCompany.Name;//กำหนด Header } ltrCreateGC.Text = "<a class=\"btn btn-primary btn-sm btn-block\" href=\"admin_facility_update.aspx?strid=" + HttpUtility.UrlEncode(STCrypt.Encrypt(nComID + "")) + "\"><i class=\"fa fa-plus\"></i> Create Facility</a>"; ltrCreate.Text = "<a class=\"btn btn-primary btn-sm btn-block\" href=\"admin_facility_update.aspx?strid=" + HttpUtility.UrlEncode(STCrypt.Encrypt(nComID + "")) + "\"><i class=\"fa fa-plus\"></i> Create Facility</a>"; } else { SetBodyEventOnLoad(SystemFunction.DialogWarningRedirect(SystemFunction.Msg_HeadWarning, "Invalid Data", "admin_company_lst.aspx"));// กรณีเข้ามาด้วย link ที่ไม่มี Querystring } } else { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } } }
protected void Page_Load(object sender, EventArgs e) { if (!UserAcc.UserExpired()) { string str1 = Request.QueryString["str1"] + ""; string str2 = Request.QueryString["str2"] + ""; if (ssTRetunrLoadData_1 != null) { if (ssTRetunrLoadData_1.lstIn.Count > 0) { string sFacility = ""; string sYear = ""; if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2)) { sFacility = STCrypt.Decrypt(str1); sYear = STCrypt.Decrypt(str2); } Export_EXCEL(sFacility, sYear); } } } }
protected void Page_Load(object sender, EventArgs e) { if (UserAcc.UserExpired()) { SetBodyEventOnLoad(SystemFunction.PopupLogin()); } else { if (!IsPostBack) { SystemFunction.BindDropdownPageSize(ddlPageSize, null); string OperationID = Request.QueryString["strid"]; if (!string.IsNullOrEmpty(OperationID)) { int nID = int.Parse(STCrypt.Decrypt(OperationID)); hdfEncryptOperationID.Value = OperationID; hdfOperationID.Value = STCrypt.Decrypt(hdfEncryptOperationID.Value); SETDATA(nID); } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string sIN = Request.QueryString["in"] + ""; // Indicator; string sOT = Request.QueryString["ot"] + ""; // OperationType; string year = Request.QueryString["year"] + ""; // Year ; string fac = Request.QueryString["fac"] + ""; // Facility; string status = Request.QueryString["status"] + ""; //Status Approve with edit content if (!string.IsNullOrEmpty(sIN)) { hdfsIndicator.Value = STCrypt.Decrypt(sIN); } if (!string.IsNullOrEmpty(sOT)) { hdfsOperationType.Value = STCrypt.Decrypt(sOT); } if (!string.IsNullOrEmpty(fac)) { hdfsFacility.Value = STCrypt.Decrypt(fac); } if (!string.IsNullOrEmpty(year)) { hdfsYear.Value = STCrypt.Decrypt(year); } if (!string.IsNullOrEmpty(status)) { hdfsStatus.Value = STCrypt.Decrypt(status); } if (!UserAcc.UserExpired()) { hdfIsAdmin.Value = SystemFunction.IsSuperAdmin() == true ? "Y" : "N"; } SystemFunction.ListYearsDESC(ddlYear, "-select-", "en-US", "th-TH", short.Parse(ConfigurationSettings.AppSettings["startYear"].ToString())); } }
public static string DecryptParameter(this string instance) { return(!string.IsNullOrEmpty(instance) ? STCrypt.Decrypt(instance) : ""); }
public static string EncryptParameter(this string instance) { return(!string.IsNullOrEmpty(instance) ? HttpUtility.UrlEncode(STCrypt.Encrypt(instance)) : ""); }
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>(); string sSearch = itemSearch.sSearch.Trims().ToLower(); string sStatus = itemSearch.sStatus.Trims().ToLower(); int nComID = SystemFunction.GetIntNullToZero(STCrypt.Decrypt(itemSearch.sComID)); lstData = db.mTFacility.Where(w => w.cDel == "N" && w.nLevel == 0 && w.CompanyID == nComID && (!string.IsNullOrEmpty(sSearch) ? w.Name.ToLower().Contains(sSearch) : true) && (!string.IsNullOrEmpty(sStatus) ? w.cActive.ToLower().Contains(sStatus) : true)).Select(s => new TDataTable { nCompanyID = s.CompanyID, nFacilityID = s.ID, sFacilityName = s.Name, sStatus = s.cActive == "Y" ? "Active" : "Inactive", dUpdate = s.dUpdate, }).OrderByDescending(o => o.dUpdate).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.sFacilityName).ToList(); break; case 2: lstData = lstData.OrderBy(o => o.sStatus).ToList(); break; case 3: lstData = lstData.OrderBy(o => o.dUpdate).ToList(); break; case 4: lstData = lstData.OrderBy(o => o.dUpdate).ToList(); break; } } break; case SystemFunction.DESC: { switch (nSortCol) { case 1: lstData = lstData.OrderByDescending(o => o.sFacilityName).ToList(); break; case 2: lstData = lstData.OrderByDescending(o => o.sStatus).ToList(); break; case 3: lstData = lstData.OrderByDescending(o => o.dUpdate).ToList(); break; case 4: lstData = lstData.OrderByDescending(o => o.dUpdate).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_facility_update.aspx?strid=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.nCompanyID.ToString())) + "&&strFacID=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.nFacilityID.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); }
public static sysGlobalClass.TRetunrLoadData SaveData(IntensityClass it) { sysGlobalClass.TRetunrLoadData result = new sysGlobalClass.TRetunrLoadData(); string sStatus = it.rt.nStatusWF + ""; string sStatusTemp = sStatus; int nFormID = 0; try { if (!UserAcc.UserExpired()) { if (it.rt.lstIn != null) { PTTGC_EPIEntities db = new PTTGC_EPIEntities(); var ef = db.TEPI_Forms.FirstOrDefault(w => w.IDIndicator == it.nIndicator && w.sYear == it.sYear && w.OperationTypeID == it.nOperationType && w.FacilityID == it.nFacility); if (ef == null) { nFormID = (db.TEPI_Forms.Any() ? db.TEPI_Forms.Max(m => m.FormID) : 0) + 1; ef = new TEPI_Forms(); ef.FormID = nFormID; ef.sAddBy = UserAcc.GetObjUser().nUserID; ef.dAddDate = DateTime.Now; ef.sYear = it.sYear; ef.IDIndicator = it.nIndicator; ef.OperationTypeID = it.nOperationType; ef.FacilityID = it.nFacility; db.TEPI_Forms.Add(ef); } else { nFormID = ef.FormID; } if (!SystemFunction.IsSuperAdmin()) { ef.ResponsiblePerson = UserAcc.GetObjUser().nUserID; ef.sUpdateBy = UserAcc.GetObjUser().nUserID; ef.dUpdateDate = DateTime.Now; } var ot = db.TIntensity_Other.Where(w => w.FormID == nFormID).ToList(); int nReportID = (db.TEPI_Workflow.Any() ? db.TEPI_Workflow.Max(m => m.nReportID) : 0) + 1; if (sStatus == "24") { sStatus = "0"; } List <string> lstMonthAdd = new List <string>(); for (int i = 1; i <= 12; i++) { lstMonthAdd.Add(i + ""); } foreach (string i in lstMonthAdd) { int nM = SystemFunction.GetIntNullToZero(i); var ef_wf = db.TEPI_Workflow.FirstOrDefault(w => w.FormID == nFormID && w.nMonth == nM); int?nStatus = 0; int nStatusID = SystemFunction.GetIntNullToZero(sStatus); if (ef_wf == null) { ef_wf = new TEPI_Workflow(); ef_wf.nReportID = nReportID; ef_wf.FormID = nFormID; ef_wf.nMonth = nM; db.TEPI_Workflow.Add(ef_wf); if (!SystemFunction.IsSuperAdmin()) { ef_wf.nStatusID = nStatus; ef_wf.nActionBy = UserAcc.GetObjUser().nUserID; ef_wf.dAction = DateTime.Now; } nReportID++; } } if (sStatusTemp != "24" && sStatusTemp != "2") { db.TIntensity_Other.RemoveRange(ot); db.SaveChanges(); it.rt.lstIn.ForEach(f => { var td = db.TIntensityDominator.FirstOrDefault(w => w.FormID == nFormID && w.ProductID == f.ProductID); int nVersion = (db.TIntensity_Remark.Any(w => w.FormID == nFormID && w.ProductID == f.ProductID) ? db.TIntensity_Remark.Where(w => w.FormID == nFormID && w.ProductID == f.ProductID).Max(m => m.nVersion) : 0) + 1; if (td == null) { td = new TIntensityDominator(); td.ProductID = f.ProductID; td.FormID = nFormID; db.TIntensityDominator.Add(td); } td.UnitID = 0; td.M1 = f.M1; td.M2 = f.M2; td.M3 = f.M3; td.M4 = f.M4; td.M5 = f.M5; td.M6 = f.M6; td.M7 = f.M7; td.M8 = f.M8; td.M9 = f.M9; td.M10 = f.M10; td.M11 = f.M11; td.M12 = f.M12; td.UnitID = f.UnitID; if (!string.IsNullOrEmpty(f.nTotal)) { td.nTotal = f.nTotal; } td.Target = f.Target; var rm = new TIntensity_Remark(); rm.FormID = nFormID; rm.ProductID = f.ProductID; rm.nVersion = nVersion; rm.sRemark = f.sRemark; if (!SystemFunction.IsSuperAdmin()) { rm.dAddDate = DateTime.Now; rm.sAddBy = UserAcc.GetObjUser().nUserID; } int nUnit = f.UnitID; db.TIntensity_Remark.Add(rm); f.lstarrDetail.Where(w => w.IsActive == true).ToList().ForEach(f2 => { var to = db.TIntensity_Other.Where(w => w.FormID == nFormID && w.ProductID == f2.nProductID && w.UnderProductID == f2.UnderProductID).FirstOrDefault(); if (to == null) { to = new TIntensity_Other(); to.ProductID = f2.nProductID; to.FormID = nFormID; to.UnderProductID = f2.UnderProductID; db.TIntensity_Other.Add(to); } to.UnitID = nUnit; to.UnitID = 0; to.M1 = f2.M1; to.M2 = f2.M2; to.M3 = f2.M3; to.M4 = f2.M4; to.M5 = f2.M5; to.M6 = f2.M6; to.M7 = f2.M7; to.M8 = f2.M8; to.M9 = f2.M9; to.M10 = f2.M10; to.M11 = f2.M11; to.M12 = f2.M12; to.Target = f2.sTarget; to.ProductName = f2.sIndicator; }); }); #region SAVE FILE if (it.rt.lstDataFile.Count > 0) { string sPathSave = string.Format(it.sFolderInPathSave, nFormID); SystemFunction.CreateDirectory(sPathSave); //ลบไฟล์เดิมที่เคยมีและกดลบจากหน้าเว็บ var qDelFile = it.rt.lstDataFile.Where(w => w.IsNewFile == false && w.sDelete == "Y").ToList(); if (qDelFile.Any()) { foreach (var qf in qDelFile) { var query = db.TEPI_Forms_File.FirstOrDefault(w => w.FormID == nFormID && w.sSysFileName == qf.SaveToFileName); if (query != null) { new SystemFunction().DeleteFileInServer(query.sPath, query.sSysFileName); // new SystemFunction2().DeleteFileInServer(query.sSysPath, query.sSysFileName); db.TEPI_Forms_File.Remove(query); ///db.TAuditPlan_AttachFile.Remove(query); } } db.SaveChanges(); } //Save New File Only var lstSave = it.rt.lstDataFile.Where(w => w.sDelete == "N").ToList(); if (lstSave.Any()) { int nFileID = db.TEPI_Forms_File.Where(w => w.FormID == nFormID).Any() ? db.TEPI_Forms_File.Where(w => w.FormID == nFormID).Max(m => m.nFileID) + 1 : 1; lstSave.ForEach(f => { string sSystemFileName = ""; if (f.IsNewFile == true) { sSystemFileName = nFormID + "_" + nFileID + "-" + DateTime.Now.ToString("ddMMyyyyHHmmss") + "." + SystemFunction.GetFileNameFromFileupload(f.SaveToFileName, ""); SystemFunction.UpFile2Server(f.SaveToPath, sPathSave, f.SaveToFileName, sSystemFileName); f.ID = nFileID; } var t = db.TEPI_Forms_File.FirstOrDefault(w => w.nFileID == f.ID && w.FormID == nFormID); if (t == null) { t = new TEPI_Forms_File(); t.FormID = nFormID; t.nFileID = nFileID; t.sSysFileName = sSystemFileName; t.sFileName = f.FileName; t.sPath = sPathSave; db.TEPI_Forms_File.Add(t); nFileID++; } t.sDescription = f.sDescription; if (!SystemFunction.IsSuperAdmin()) { t.dAdd = DateTime.Now; t.nAddBy = UserAcc.GetObjUser().nUserID; } }); } } #endregion } db.SaveChanges(); new EPIFunc().RecalculateMaterial(it.nOperationType, it.nFacility, it.sYear); new EPIFunc().RecalculateWaste(it.nOperationType, it.nFacility, it.sYear); new EPIFunc().RecalculateWater(it.nOperationType, it.nFacility, it.sYear); } if (sStatusTemp != "27") { new Workflow().UpdateHistoryStatus(nFormID); } int nStatusTemp = SystemFunction.GetIntNullToZero(sStatusTemp); if (nStatusTemp != 0) { string sMode = ""; switch (nStatusTemp) { case 1: sMode = "SM"; break; case 2: sMode = "RQ"; break; case 24: sMode = "RC"; break; case 27: sMode = "APC"; break; } if (!string.IsNullOrEmpty(sMode)) { var wf = new Workflow().WorkFlowAction(nFormID, it.lstMonth, sMode, UserAcc.GetObjUser().nUserID, UserAcc.GetObjUser().nRoleID, it.rt.sComment); result.sStatus = wf.Status; result.sMsg = wf.Msg; } else { if (UserAcc.GetObjUser().nRoleID == 4)//ENVI Corporate (L2) >> Req.09.04.2019 Send email to L0 on L2 Modified data. { new Workflow().SendEmailToL0onL2EditData(it.sYear, it.nIndicator, it.nFacility, it.nOperationType); } result.sStatus = SystemFunction.process_Success; result.sMsg = ""; } } else { result.sStatus = SystemFunction.process_Success; result.sMsg = ""; } } else { result.sStatus = SystemFunction.process_SessionExpired; result.sMsg = "Session Expired !!"; } } catch (Exception ex) { result.sStatus = SystemFunction.process_Failed; result.sMsg = ex.ToString(); } string sPath = "#"; switch (it.nOperationType) { case 4: sPath = "epi_input_intensity_1.aspx"; ssTRetunrLoadData_1 = GetLoadData(it); break; case 11: sPath = "epi_input_intensity_2.aspx"; ssTRetunrLoadData_2 = GetLoadData(it); break; case 13: sPath = "epi_input_intensity_3.aspx"; ssTRetunrLoadData_3 = GetLoadData(it); break; case 14: sPath = "epi_input_intensity_4.aspx"; ssTRetunrLoadData_4 = GetLoadData(it); break; } if (sPath != "#") { sPath = sPath + "?in=" + HttpUtility.UrlEncode(STCrypt.Encrypt(it.nIndicator + "")) + "&&ot=" + HttpUtility.UrlEncode(STCrypt.Encrypt(it.nOperationType + "")); } result.sPath = sPath; return(result); }
public static CResultLogin Login(string sUserName, string sPassword, string sMode) { CResultLogin result = new CResultLogin(); PTTGC_EPIEntities db = new PTTGC_EPIEntities(); List <TDataRole> lstData = new List <TDataRole>(); if (!string.IsNullOrEmpty(sUserName) && (string.IsNullOrEmpty(sMode) ? !string.IsNullOrEmpty(sPassword) : true)) { string sPassEncypt = STCrypt.Encrypt(sPassword); var User = db.mTUser.Where(w => w.Username == sUserName && (string.IsNullOrEmpty(sMode) ? w.PasswordEncrypt == sPassEncypt : true) && w.cDel == "N" && w.cActive == "Y").ToList(); if (User.Any()) { int nUserID = User.Any() ? User.First().ID : 0; int nRoleID = 0; var lst_Role = db.mTUserInRole.Where(w => w.nUID == nUserID).Select(s => s.nRoleID).Distinct().ToList(); var lstDataRole = db.mTUserRole.ToList(); if (lst_Role.Count > 1) { result.Status = SystemFunction.process_Failed; result.Msg = "muti"; result.nUserID = nUserID; lstData = GetRolePermission(nUserID + ""); result.TDataRole = lstData; return(result); } else { if (lst_Role.Any()) { nRoleID = lst_Role.First(); } string sNameRole = lstDataRole.Any() ? lstDataRole.First(w => w.ID == nRoleID).Name : ""; UserAcc ua = (new UserAcc { nUserID = nUserID, nRoleID = nRoleID, sFullName = User.First().Firstname + ' ' + User.First().Lastname, sActionRoleName = sNameRole, }); UserAcc.SetObjUser(ua); result.Status = SystemFunction.process_Success; } } else { if (!string.IsNullOrEmpty(sMode)) { result.Status = SystemFunction.process_Failed; result.Msg = "User account not Register."; } else { result.Status = SystemFunction.process_Failed; result.Msg = "User account and password incorrect."; } } } return(result); }
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>(); string sCon = ""; string sSearch = itemSearch.sSearch.Trims().ToLower(); string sStatus = itemSearch.sStatus.Trims().ToLower(); if (!string.IsNullOrEmpty(sSearch)) { sCon += @" AND sName LIKE '%" + sSearch + "%' "; } if (!string.IsNullOrEmpty(sStatus)) { sCon += @" AND (LOWER(cActive) = '" + sStatus + @"') "; } var TB_Effluent_Product = db.TEffluent_OtherProduct_Point.ToList(); //IsUse string _SQL = @" select nUnitID ,sName ,CASE WHEN cActive = 'Y' THEN 'Active' ELSE 'Inactive' END as sStatus ,dUpdate from TM_Effluent_Unit where cDel = 'N' " + sCon + @" ORDER BY dUpdate DESC"; DataTable dt = CommonFunction.Get_Data(SystemFunction.strConnect, _SQL); lstData = CommonFunction.ConvertDatableToList <TDataTable>(dt).ToList(); foreach (var item in lstData) { item.sUpdate = item.dUpdate.DateString(); item.sLink = "<a class='btn btn-warning' href='admin_master_effluent_otherunit_update.aspx?str=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.nUnitID.ToString())) + "'><i class='fa fa-edit'></i> Edit</a>"; item.nIsUse = TB_Effluent_Product.Any(a => a.nUnitID == item.nUnitID) ? TB_Effluent_Product.Where(a => a.nUnitID == item.nUnitID).Count() : 0; } #region//SORT int?nSortCol = SystemFunction.GetIntNull(itemSearch.sIndexCol); switch ((itemSearch.sOrderBy + "").ToLower()) { case SystemFunction.ASC: { switch (nSortCol) { case 1: lstData = lstData.OrderBy(o => o.sName).ToList(); break; case 2: lstData = lstData.OrderBy(o => o.sStatus).ToList(); break; case 3: lstData = lstData.OrderBy(o => o.sUpdate).ToList(); break; } } break; case SystemFunction.DESC: { switch (nSortCol) { case 1: lstData = lstData.OrderByDescending(o => o.sName).ToList(); break; case 2: lstData = lstData.OrderByDescending(o => o.sStatus).ToList(); break; case 3: lstData = lstData.OrderByDescending(o => o.sUpdate).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(); var lstDataFac = db.mTFacility.Where(w => w.cDel == "N").ToList(); 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); }
public static sysGlobalClass.CResutlWebMethod SaveToDB(string sDesc, string sID, List <dataFileContactUs> objFile) { sysGlobalClass.CResutlWebMethod result = new sysGlobalClass.CResutlWebMethod(); PTTGC_EPIEntities db = new PTTGC_EPIEntities(); DateTime now = DateTime.Now; if (UserAcc.UserExpired()) { result.Status = SystemFunction.process_SessionExpired; } else { try { UserAcc ua = UserAcc.GetObjUser(); if (!string.IsNullOrEmpty(sID)) { string sPathSend = ""; int nID = int.Parse(STCrypt.Decrypt(sID)); var Query = db.TContactUs.FirstOrDefault(w => w.cDel == "N" && w.nContactID == nID); if (Query != null) { Query.sAnswer = sDesc; Query.cStatusAns = "2"; Query.dAnswer = now; Query.dUpdate = now; Query.nAnswerBy = UserAcc.GetObjUser().nUserID; if (objFile.Count > 0 && objFile != null) { string sPathSave = string.Format(sFolderInPathSave, nID); SystemFunction.CreateDirectory(sPathSave); //string sPathSave = string.Format(sFolderInPathSave, nID); //SystemFunction.CreateDirectory(sPathSave); var f = objFile.First(); string sSystemFileName = nID + "_" + "-" + DateTime.Now.ToString("ddMMyyyyHHmmss") + "." + SystemFunction.GetFileNameFromFileupload(f.sFileName, ""); //SystemFunction2.GetFileType(item.SaveToFileName); SystemFunction.UpFile2Server(f.sPath, sPathSave, f.sSysFileName, sSystemFileName); Query.sAnsFile = f.sFileName; Query.sAnsSysFile = sSystemFileName; Query.sAnsPath = sPathSave; sPathSend = HttpContext.Current.Server.MapPath("./") + sPathSave + sSystemFileName; } var Ispass = db.SaveChanges() > 0; if (Ispass) { string To = Query.sContactEmail; // Contact Mail string AdminContactmail = WebConfigurationManager.AppSettings["ContactMail"] + ""; // Mail Admin //string To1 = "*****@*****.**"; string sSubject = SystemFunction.sAbbrSystem + " : Contact Us." + Query.sSubject; string sGurl = SystemFunction.RequestUrl() + WebConfigurationManager.AppSettings["DefaultPage"] + ""; string sHtml = @" <table align='left' border='0' cellspacing='2' cellpadding='3'> <tr> <td align='left'>Dear: " + Query.sContactName + @"</td> </tr> <tr> <td align='left'>Subject: " + Query.sSubject + @"</td> </tr> <tr> <td align='left'>Description: " + Query.sDetail + @"</td> </tr> <tr> <td align='left'>Answer: " + Query.sAnswer + @"</td> </tr> </table>"; Workflow.DataMail_log log = new Workflow.DataMail_log(); string ccMail = ""; var lstUser = db.mTUser.FirstOrDefault(w => w.ID == ua.nUserID); if (lstUser != null) { ccMail = lstUser.Email; } log = SystemFunction.SendMailAll(AdminContactmail, To, ccMail, "", sSubject, sHtml, sPathSend != "" ? sPathSend.Replace("/", "\\") : ""); log.nDataID = SystemFunction.GetIntNullToZero(nID + ""); log.sPageName = "admin_ContactUs_update.aspx"; new Workflow().SaveLogMail(log); if (log.bStatus) { result.Status = SystemFunction.process_Success; } } } } } catch (Exception e) { result.Msg = e.Message; result.Status = SystemFunction.process_Failed; } result.Status = SystemFunction.process_Success; } return(result); }
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>(); string sSearch = itemSearch.sSearch.Trims().ToLower(); string sStatus = itemSearch.sStatus.Trims().ToLower(); if (!string.IsNullOrEmpty(sStatus)) { sStatus = sStatus == "w" ? null : sStatus; } lstData = db.TContactUs.Where(w => w.cDel == "N" && (!string.IsNullOrEmpty(sSearch) ? w.sContactName.ToLower().Contains(sSearch) : true) && (sStatus != "" ? w.cStatusAns == sStatus : true)).Select(s => new TDataTable { nContactID = s.nContactID, sContactName = s.sContactName, cStatusAns = s.cStatusAns == null ? "Wait" : s.cStatusAns == "1" ? "Read" : "Success", cStatus = s.cStatusAns, dCreate = s.dCreate, dUpdate = s.dUpdate, }).OrderByDescending(o => o.dUpdate).ToList(); //lstData = db.mTCompany.Where(w => w.cDel == "N" && (!string.IsNullOrEmpty(sSearch) ? w.Name.ToLower().Contains(sSearch) : true)).Select(s => new TDataTable //{ // nCompID = s.ID, // sCompName = s.Name, // sStatus = s.cActive == "Y" ? "Active" : "Inactive", // dUpdate = s.dUpdate //}).OrderByDescending(o => o.dUpdate).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.sContactName).ToList(); break; case 2: lstData = lstData.OrderBy(o => o.dCreate).ToList(); break; case 3: lstData = lstData.OrderBy(o => o.cStatus).ToList(); break; //case 4: lstData = lstData.OrderBy(o => o.nCountFacility).ToList(); break; } } break; case SystemFunction.DESC: { switch (nSortCol) { case 1: lstData = lstData.OrderByDescending(o => o.sContactName).ToList(); break; case 2: lstData = lstData.OrderByDescending(o => o.dCreate).ToList(); break; case 3: lstData = lstData.OrderByDescending(o => o.cStatus).ToList(); break; //case 4: lstData = lstData.OrderByDescending(o => o.nCountFacility).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) { var color = item.cStatus == null ? "warning" : item.cStatus == "1" ? "primary" : "success"; var Wordding = item.cStatus == null ? "Reply" : item.cStatus == "1" ? "Read" : "View"; var icon = item.cStatus == null ? "edit" : item.cStatus == "1" ? "search" : "search"; item.sUpdate = item.dUpdate.DateString(); item.sCreate = item.dCreate.DateString(); item.sLink = "<a class='btn btn-" + color + "' href='admin_ContactUs_update.aspx?strid=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.nContactID.ToString())) + "'><i class='fa fa-" + icon + "'></i> " + Wordding + "</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); }
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>(); string sSearch = itemSearch.sSearch.Trims().ToLower(); string sStatus = itemSearch.sStatus.Trims().ToLower(); lstData = db.mTCompany.Where(w => w.cDel == "N" && (!string.IsNullOrEmpty(sSearch) ? w.Name.ToLower().Contains(sSearch) : true) && (!string.IsNullOrEmpty(sStatus) ? w.cActive.ToLower().Contains(sStatus) : true)).Select(s => new TDataTable { nCompID = s.ID, sCompName = s.Name, sStatus = s.cActive == "Y" ? "Active" : "Inactive", dUpdate = s.dUpdate, SearchBy = "", }).OrderByDescending(o => o.dUpdate).ToList(); var lstDataFac = db.mTFacility.Where(w => w.cDel == "N").ToList(); var lstCompanyID_SearchBySub = db.mTFacility.Where(w => w.cActive == "Y" && w.cDel == "N" && w.nLevel == 2 && (!string.IsNullOrEmpty(sSearch) ? w.Name.ToLower().Contains(sSearch) : false)).Select(s => new { s.CompanyID }).Distinct().ToList(); var lstCompanyID_SearchBySubLve1 = db.mTFacility.Where(w => w.cActive == "Y" && w.cDel == "N" && w.nLevel == 1 && (!string.IsNullOrEmpty(sSearch) ? w.Name.ToLower().Contains(sSearch) : false)).Select(s => new { s.CompanyID }).Distinct().ToList(); if (lstCompanyID_SearchBySub.Any()) { List <int> lstComID = new List <int>(); lstComID = lstCompanyID_SearchBySub.Select(s => s.CompanyID).ToList(); var lstCompany = db.mTCompany.Where(w => w.cDel == "N" && lstComID.Contains(w.ID)).Select(s => s.ID).ToList(); if (lstCompany.Any()) { foreach (var item in lstCompany) { ///// Check ว่ามีไอดีนี้ในบริษัทไหม ถ้าไม่มีค่อย แอด เพิ่ม var q = lstData.FirstOrDefault(w => w.nCompID == item); if (q == null) { List <TDataTable> lstDataSub2 = new List <TDataTable>(); lstDataSub2 = db.mTCompany.Where(w => w.cDel == "N" && w.ID == item).Select(s => new TDataTable { nCompID = s.ID, sCompName = s.Name, sStatus = s.cActive == "Y" ? "Active" : "Inactive", dUpdate = s.dUpdate, SearchBy = "Y", }).OrderByDescending(o => o.dUpdate).ToList(); lstData.AddRange(lstDataSub2); } } } } if (lstCompanyID_SearchBySubLve1.Any()) { List <int> lstComID = new List <int>(); lstComID = lstCompanyID_SearchBySubLve1.Select(s => s.CompanyID).ToList(); var lstCompany = db.mTCompany.Where(w => w.cDel == "N" && lstComID.Contains(w.ID)).Select(s => s.ID).ToList(); if (lstCompany.Any()) { foreach (var item in lstCompany) { ///// Check ว่ามีไอดีนี้ในบริษัทไหม ถ้าไม่มีค่อย แอด เพิ่ม var q = lstData.FirstOrDefault(w => w.nCompID == item); if (q == null) { List <TDataTable> lstDataSub1 = new List <TDataTable>(); lstDataSub1 = db.mTCompany.Where(w => w.cDel == "N" && w.ID == item).Select(s => new TDataTable { nCompID = s.ID, sCompName = s.Name, sStatus = s.cActive == "Y" ? "Active" : "Inactive", dUpdate = s.dUpdate, SearchBy = "Y", }).OrderByDescending(o => o.dUpdate).ToList(); lstData.AddRange(lstDataSub1); } } } } foreach (var item in lstData) { string sLinkFacility = ""; item.nCountFacility = lstDataFac.Where(w => w.CompanyID == item.nCompID && w.cDel == "N" && (item.nCompID == 1 ? w.nLevel == 0 : w.nLevel == 1)).Count(); sLinkFacility = "<div class='btn-group'>" + "<a class='btn btn-sm btn-primary' href='admin_facility_lst.aspx?strid=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.nCompID.ToString())) + "'><span class='badge'>" + lstDataFac.Where(w => w.CompanyID == item.nCompID && w.cDel == "N" && (item.nCompID == 1 ? w.nLevel == 0 : w.nLevel == 1)).Count() + "</span></a>" + "<a class='btn btn-sm btn-info' href='admin_facility_update.aspx?strid=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.nCompID.ToString())) + "'><i class='fa fa-plus'></i></a>" + "</div>"; 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.nCompID.ToString())) + "'><i class='fa fa-edit'></i> Edit</a>"; //item.sLinkFacility = "<a class='btn btn-info' href='admin_facility_lst.aspx?strid=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.nCompID.ToString())) + "'><i class='fa fa-search'></i></a>"; item.sLinkFacility = sLinkFacility; } #region//SORT int?nSortCol = SystemFunction.GetIntNull(itemSearch.sIndexCol); switch ((itemSearch.sOrderBy + "").ToLower()) { case SystemFunction.ASC: { switch (nSortCol) { case 1: lstData = lstData.OrderBy(o => o.sCompName).ToList(); break; case 2: lstData = lstData.OrderBy(o => o.sStatus).ToList(); break; case 3: lstData = lstData.OrderBy(o => o.dUpdate).ToList(); break; case 4: lstData = lstData.OrderBy(o => o.nCountFacility).ToList(); break; } } break; case SystemFunction.DESC: { switch (nSortCol) { case 1: lstData = lstData.OrderByDescending(o => o.sCompName).ToList(); break; case 2: lstData = lstData.OrderByDescending(o => o.sStatus).ToList(); break; case 3: lstData = lstData.OrderByDescending(o => o.dUpdate).ToList(); break; case 4: lstData = lstData.OrderByDescending(o => o.nCountFacility).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(); 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); }
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>(); string sCon = ""; string sSearch = itemSearch.sSearch.Trims().ToLower(); string sStatus = itemSearch.sStatus.Trims().ToLower(); if (!string.IsNullOrEmpty(sSearch)) { sCon += @" AND (LOWER(w.sCode) LIKE '%" + sSearch + "%' OR LOWER(w.sName) LIKE '%" + sSearch + "%' OR LOWER(td.sName) LIKE '%" + sSearch + "%') "; } if (!string.IsNullOrEmpty(sStatus)) { sCon += @" AND (LOWER(w.cActive) = '" + sStatus + @"') "; } var Data_type = db.TData_Type.AsEnumerable().Where(w => w.cActive == "Y").ToList(); //GetDataTYPE_Name var TB_Waste_Product = db.TWaste_Product_data.ToList(); //IsUse string _SQL = @" SELECT w.ID as nWasteID ,w.sCode as sCode ,w.sName as sName ,w.nTypeID as nTypeID ,w.dUpdate ,td.sName as sTypeName ,CASE WHEN w.cActive = 'Y' THEN 'Active' ELSE 'Inactive' END as sStatus FROM TM_WasteDisposal w LEFT JOIN TData_Type td ON w.nTypeID = td.nID WHERE w.cDel = 'N' " + sCon + @" ORDER BY w.dUpdate DESC "; DataTable dt = CommonFunction.Get_Data(SystemFunction.strConnect, _SQL); lstData = CommonFunction.ConvertDatableToList <TDataTable>(dt).ToList(); //lstData = db.TM_WasteDisposal.Where(w => w.cDel == "N" && (!string.IsNullOrEmpty(sSearch) ? w.sName.ToLower().Contains(sSearch) || w.sCode.ToLower().Contains(sSearch) : true) && (!string.IsNullOrEmpty(sStatus) ? w.cActive.ToLower().Contains(sStatus) : true)).Select(s => new TDataTable //{ // nWasteID = s.ID, // sCode = s.sCode, // sName = s.sName, // nTypeID = s.nTypeID, // sStatus = s.cActive == "Y" ? "Active" : "Inactive", // dUpdate = s.dUpdate //}).OrderByDescending(o => o.dUpdate).ToList(); foreach (var item in lstData) { item.sUpdate = item.dUpdate.DateString(); item.sLink = "<a class='btn btn-warning' href='admin_master_waste_update.aspx?str=" + HttpContext.Current.Server.UrlEncode(STCrypt.Encrypt(item.nWasteID.ToString())) + "'><i class='fa fa-edit'></i> Edit</a>"; //item.sTypeName = Data_type.Any(a => a.nID == item.nTypeID) ? Data_type.First(a => a.nID == item.nTypeID).sName : ""; item.nIsUse = TB_Waste_Product.Any(a => a.nDisposalID == item.nWasteID) ? TB_Waste_Product.Where(a => a.nDisposalID == item.nWasteID).Count() : 0; } #region//SORT int?nSortCol = SystemFunction.GetIntNull(itemSearch.sIndexCol); switch ((itemSearch.sOrderBy + "").ToLower()) { case SystemFunction.ASC: { switch (nSortCol) { case 1: lstData = lstData.OrderBy(o => o.sTypeName).ToList(); break; case 2: lstData = lstData.OrderBy(o => o.sName).ToList(); break; case 3: lstData = lstData.OrderBy(o => o.sStatus).ToList(); break; } } break; case SystemFunction.DESC: { switch (nSortCol) { case 1: lstData = lstData.OrderByDescending(o => o.sTypeName).ToList(); break; case 2: lstData = lstData.OrderByDescending(o => o.sName).ToList(); break; case 3: lstData = lstData.OrderByDescending(o => o.sStatus).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(); var lstDataFac = db.mTFacility.Where(w => w.cDel == "N").ToList(); 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); }