public personel_info GetPersonelInfoByCode(string Code) { PISContext db = new PISContext(); PISFunction PISFunction = new PISFunction(); var fitercode = PISFunction.WST_CODE; personel_info opersonel_info = new personel_info(); List <position> oposition = new List <position>(); var query = (from o in db.personel_info.Where(w => fitercode.Contains(w.WSTCODE) && w.CODE == Code) from u in db.unit.Where(w => w.unitcode == o.UNITCODE).DefaultIfEmpty() from p in db.position.Where(w => w.poscode == o.POSCODE).DefaultIfEmpty() select new Personel_Info() { sFNAME = o.FNAME, sLNAME = o.LNAME, sEmailAddr = o.EmailAddr, sLongname = u.longname, sUnitabbr = u.unitabbr, sPosition = p.t_name } ).FirstOrDefault(); return(opersonel_info); }
public List <oSetSearch> SetSearch(string SearchBy) { List <oSetSearch> osetsearch = new List <oSetSearch>(); List <personel_info> listpersonel_info = new List <personel_info>(); PTTGSP_DWSContext db = new PTTGSP_DWSContext(); PISContext pis = new PISContext(); PISFunction PISFunction = new PISFunction(); var fitercode = PISFunction.WST_CODE; var cf4 = db.TM_Config.FirstOrDefault(w => w.nID == 4); string sUnitCode_GSP = cf4 != null ? cf4.sValue : "80000563"; var listunitcode = PISFunction.ListUnit_ToLower(sUnitCode_GSP).Select(s => s.CODE).ToList(); listpersonel_info = pis.personel_info.Where(w => fitercode.Contains(w.WSTCODE) && (SearchBy == "3"? !listunitcode.Contains(w.UNITCODE): listunitcode.Contains(w.UNITCODE))).ToList(); osetsearch = (from a in listpersonel_info select new oSetSearch { value = a.CODE, label = a.CODE + " " + "-" + " " + a.FNAME + " " + a.LNAME, Search = a.CODE + " " + a.FNAME + " " + a.LNAME, }).OrderBy(o => o.label).ToList(); return(osetsearch); }
public WithdrawalRetrunlst GetData_List(Withdrawal_Search data) { db = new PTTGSP_DWSContext(); pis = new PISContext(); WithdrawalRetrunlst result = new WithdrawalRetrunlst(); List <Withdrawal_history_H> H_TB = new List <Withdrawal_history_H>(); int?nReasonID; int?sStepID; if (!string.IsNullOrEmpty(data.sReasonID)) { nReasonID = data.sReasonID.ToIntOrNull(); } else { nReasonID = null; } if (!string.IsNullOrEmpty(data.sStepID)) { sStepID = data.sStepID.ToIntOrNull(); } else { sStepID = null; } var lstData = (from R in db.T_Request.Where(w => (!string.IsNullOrEmpty(data.sRequestNo) ? (w.sRequestNo.ToLower().Contains(data.sRequestNo.ToLower().Trim())) : true)) from Re in db.TB_Reason.Where(w => w.nReasonID == R.nReasonID && (nReasonID.HasValue ? w.nReasonID == nReasonID : true)) from U in db.TB_User.Where(w => w.sEmployeeID == R.sCreateBy && (!string.IsNullOrEmpty(data.sEmployeeID) ? (w.sEmployeeID.ToLower().Contains(data.sEmployeeID.ToLower().Trim())) : true)) from SR in db.TM_Step_Request.Where(w => w.nStepID == R.nStepID && (sStepID.HasValue ? w.nStepID == sStepID : true)) select new { R.nRequestID, R.sRequestNo, //เลขที่ใบขอเบิก R.sCreateBy, //รหัสผู้ขอเบิก U.sFirstName, //ชื่อผู้ขอเบิก U.sLastName, //นามสกุลผู้ขอเบิก R.nReasonID, //เหตุผลในการเบิก sReasonName = Re.sName, //ชื่อเหตุผลในการเบิก R.dCreate, //วันที่เบิก R.nRequest_TotalPrice, R.sOrgID, //หน่วยงาน R.nStepID, //สถานะของรายการ SR.sName //ชื่อสถานะของรายการ }).ToList(); foreach (var i in lstData) { List <Withdrawal_history_S> S_TB = new List <Withdrawal_history_S>(); var H = new Withdrawal_history_H(); var lstSub = db.T_Request_Material.Where(w => w.IsApprove == true && w.nRequestID == i.nRequestID).Select(s => new Withdrawal_history_S { IsApprove = s.IsApprove, nMaterialID = s.nMaterialID, nPay_Amount = s.nPay_Amount, sNote = s.sNote, nPay_Price = s.nPay_Price, nPay_TotalPrice = s.nPay_TotalPrice, nRequestID = s.nRequestID, nRequest_Amount = s.nRequest_Amount, nRequest_Price = s.nRequest_Price, nRequest_TotalPrice = s.nRequest_TotalPrice, }).ToList(); foreach (var sub in lstSub) { Withdrawal_history_S s = new Withdrawal_history_S(); var Materials = db.TB_Materials.FirstOrDefault(w => w.nMaterialID == sub.nMaterialID); if (Materials != null) { s.sMaterialCode = Materials.sMaterialCode; // รหัสวัสดุ s.sMaterialName = Materials.sName; // ชื่อวัสดุ var Unit = db.TB_Material_Unit.FirstOrDefault(f => f.nUnitID == Materials.nUnitID); if (Unit != null) { s.sUnitName = Unit.sName; // หน่วยนับ } else { s.sUnitName = ""; } } s.nRequest_Amount = sub.nRequest_Amount; // จำนวนขอเบิก s.nPay_Amount = sub.nPay_Amount; //จำนวนที่ได้รับ s.nPay_TotalPrice = sub.nPay_TotalPrice; //ราคารวม S_TB.Add(s); } if (lstSub.Count > 0) { H.nReasonID = i.nReasonID; H.nRequestID = i.nRequestID; H.nRequest_TotalPrice = i.nRequest_TotalPrice; H.nStepID = i.nStepID; H.sCreateBy = i.sCreateBy; H.sFullName = i.sFirstName + " " + i.sLastName; H.sReasonName = i.sReasonName; H.sOrgID = i.sOrgID; H.sRequestNo = i.sRequestNo; H.StepName = i.sName; //H.dCreate = i.dCreate.SetMonth_th(); H.sub_List = S_TB; H_TB.Add(H); } } result.Withdrawal_history_H = H_TB; var lstStep = db.TM_Step_Request.OrderBy(o => o.sName).ToList(); var lstReason = db.TB_Reason.Where(w => !w.IsDel && w.IsActive).OrderBy(o => o.sName).ToList(); result.TB_Reason = lstReason; result.TM_Step_Request = lstStep; var lstUser = (from U in db.TB_User.Where(w => w.IsActive && !w.IsDel) select new lstAutoCompleted_Withdrawal { sEmployeeID = U.sEmployeeID, value = U.sEmployeeID, label = U.sEmployeeID + " " + "-" + " " + U.sFirstName + " " + U.sLastName, sFirstName = U.sFirstName, sLastName = U.sLastName, sOrgID = U.sOrgID, sOrgName = U.sOrgName, sPosName = U.sPosName, } ).OrderBy(o => o.sFirstName).ToList(); var lstUnit_DB = pis.unit.Where(w => (w.DUMMY_RELATIONSHIP == "1-1" || w.DUMMY_RELATIONSHIP.StartsWith("1-1-"))).ToList(); //หน่วยงาน var cf4 = db.TM_Config.FirstOrDefault(w => w.nID == 4); string sUnitCode_GSP = cf4 != null ? cf4.sValue : "80000563"; var lstMember = PISFunction.ListUnit_ToLower(sUnitCode_GSP).Select(s => s.CODE).ToList(); // string[] arrWSTCode = new string[] { "A", "B", "I", "J" }; // string[] arrPersonel = new string[] { }; // var lstMember = PISFunction.AllReportTo_EmpCode("270073"); // var lstPersonel = (from p in pis.personel_info.Where(w => lstMember.Contains(w.CODE)) // select new lstAutoCompleted_RequestApproval // { // sCODE = p.CODE, // รหัส user // value = p.CODE, // label = p.CODE + " " + "-" + " " + p.FULLNAMETH, // sPrefix = p.INAME, // คำนำหน้า // sFirstName = p.FNAME, // sLastName = p.LNAME, // sFullName = p.FULLNAMETH, // } //).OrderBy(o => o.sFirstName).ToList(); result.lstAutoCompleted = lstUser; return(result); }
public IActionResult SignIn(AuthenProperties props) { try { string sToken = ""; string sMessage = ""; var r = IConfig["AppSettings:BypassCode"] == props.sPassword ? new IProcessResult() { Success = true } : PISFunction.LDAP_Connect("ptt", props.sUsername, props.sPassword); if (r.Success) { TokenJWTSecret tk = null; var emp = pis.personel_info.FirstOrDefault(w => w.CODE == props.sUsername); if (emp != null) { bool isGSP = IsGSP(emp.UNITCODE); int nRoleID = 0; var lstUser = db.TB_User .Where(w => !w.IsDel && w.IsActive && ((w.sEmployeeID == emp.CODE && w.sOrgID == emp.UNITCODE) || w.sEmpCode_MG == emp.CODE)) .Select(s => new { s.sEmployeeID, s.nRoleID }).ToList(); var usr = lstUser.FirstOrDefault(w => w.sEmployeeID == emp.CODE); if (usr != null) { nRoleID = usr.nRoleID; } if (isGSP || lstUser.Any()) { tk = new TokenJWTSecret(); tk.sEmployeeCode = emp.CODE; tk.sUnitCode = emp.UNITCODE; tk.nRoleID = nRoleID; tk.isRightToRequest = isGSP || nRoleID == 3; tk.sName = emp.FNAME + " " + emp.LNAME; tk.sEmail = emp.EmailAddr; var pos = pis.position.FirstOrDefault(w => w.poscode == emp.POSCODE); tk.sPosition = pos != null ? pos.AB_NAME : emp.POSNAME; var unit = pis.unit.FirstOrDefault(w => w.unitcode == emp.UNITCODE); tk.sOrganization = unit != null ? unit.unitabbr : ""; List <string> lstBand_Allow = new List <string>() { "AA", "AB", "AC0", "AC1", "AD" }; var lstEmpCode_ReportTo = PISFunction.RepInfo.AllReportTo(emp.CODE, pis) .Where(w => w.sEmpCode != emp.CODE && lstBand_Allow.Contains(w.sBand)) .Select(s => s.sEmpCode).ToList(); int nEmp_ReportTo = lstEmpCode_ReportTo.Count; tk.sEmpCode_MG1 = nEmp_ReportTo > 0 ? lstEmpCode_ReportTo[0] : emp.CODE; tk.sEmpCode_MG2 = nEmp_ReportTo > 1 ? lstEmpCode_ReportTo[1] : ""; tk.sEmpCode_MG3 = nEmp_ReportTo > 2 ? lstEmpCode_ReportTo[2] : ""; } } if (tk != null) { tk.sSecretKey = IConfig["jwt:Key"]; tk.sIssuer = IConfig["jwt:Issuer"]; tk.sAudience = IConfig["jwt:Audience"]; tk.dTimeout = DateTime.Now.AddMinutes(IConfig["jwt:Expire"].ToDouble()); sToken = IAuthen.SignIn(tk); } else { sMessage = "ไม่พบข้อมูลผู้ใช้งาน"; } } else { sMessage = "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง"; } return(Ok(new { code = StatusCodes.Status200OK, token = sToken, message = sMessage })); } catch (Exception ex) { return(Ok(new { code = StatusCodes.Status404NotFound, message = ex })); } }