public CResutlWebMethod SetOrder(int nGroupID, string sOrder) { CResutlWebMethod result = new CResutlWebMethod(); PTTGSP_DWSContext db = new PTTGSP_DWSContext(); result.sStatus = STFunction.process_Success(); List <TB_Material_Group> listtb_material_group = db.TB_Material_Group.ToList(); TB_Material_Group otb_material_group = listtb_material_group.FirstOrDefault(w => w.nGroupID == nGroupID); if (otb_material_group != null) { otb_material_group.nOrder = sOrder.ToInt(); int n = 0; var lstItem_OTHER = listtb_material_group.Where(w => w.nGroupID != nGroupID && w.IsDel == false).OrderBy(o => o.nOrder).ToList(); lstItem_OTHER.ForEach(i => { n += 1; if (n == sOrder.ToInt()) { n += 1; } i.nOrder = n; }); db.SaveChanges(); } else { result.sMsg = "ไม่พบข้อมูลไม่ถูกต้อง"; result.sStatus = STFunction.process_Warning(); } return(result); }
public IActionResult ParcelGroup_Del_data(int[] nGroupID) { CResutlWebMethod result = new CResutlWebMethod(); PTTGSP_DWSContext db = new PTTGSP_DWSContext(); if (nGroupID.Length > 0) { List <TB_Material_Group> tb_material_group = db.TB_Material_Group.Where(w => nGroupID.Contains(w.nGroupID)).ToList(); foreach (var i in tb_material_group) { i.IsDel = true; db.SaveChanges(); } SetOrderAll(); result.sStatus = STFunction.process_Success(); } else { result.sStatus = STFunction.process_Warning(); } return(Ok(result)); }
public IActionResult Savedata(V_Material_Category oV_Material_Category) { CResutlWebMethod result = new CResutlWebMethod(); PTTGSP_DWSContext db = new PTTGSP_DWSContext(); result.sStatus = STFunction.process_Success(); try { if (!db.V_Material_Category.Any(w => w.sCategoryName.ToLower().Trim() == oV_Material_Category.sCategoryName.ToLower().Trim() && w.nCategoryID != oV_Material_Category.nCategoryID)) { if (!db.V_Material_Category.Any(w => w.sCategoryCode.ToLower().Trim() == oV_Material_Category.sCategoryCode.ToLower().Trim() && w.nCategoryID != oV_Material_Category.nCategoryID)) { TB_Material_Category otb_material_category = db.TB_Material_Category.Where(w => w.nCategoryID == oV_Material_Category.nCategoryID).FirstOrDefault(); if (otb_material_category == null) { otb_material_category = new TB_Material_Category(); otb_material_category.dCreate = DateTime.Now; db.TB_Material_Category.Add(otb_material_category); } otb_material_category.nGroupID = oV_Material_Category.nGroupID.ToInt(); otb_material_category.sCategoryCode = oV_Material_Category.sCategoryCode; otb_material_category.sName = oV_Material_Category.sCategoryName; otb_material_category.sDetail = oV_Material_Category.sDetail; otb_material_category.nOrder = oV_Material_Category.nOrder; otb_material_category.IsActive = oV_Material_Category.IsActive; otb_material_category.dUpdate = DateTime.Now; db.SaveChanges(); } else { result.sMsg = "รหัสประเภทวัสดุนี้มีในระบบแล้ว"; result.sStatus = STFunction.process_Warning(); } } else { result.sMsg = "ชื่อประเภทวัสดุนี้มีในระบบแล้ว"; result.sStatus = STFunction.process_Warning(); } } catch (Exception e) { result.sStatus = STFunction.process_Failed(); result.sMsg = e.ToString(); } return(Ok(result)); }
public IActionResult Savedata(TB_Material_Group TB_Material_Group) { CResutlWebMethod result = new CResutlWebMethod(); PTTGSP_DWSContext db = new PTTGSP_DWSContext(); result.sStatus = STFunction.process_Success(); try { if (!db.TB_Material_Group.Any(w => w.sName.ToLower().Trim() == TB_Material_Group.sName.ToLower().Trim() && w.nGroupID != TB_Material_Group.nGroupID && w.IsDel != true)) { TB_Material_Group tb_material_group = db.TB_Material_Group.Where(w => w.nGroupID == TB_Material_Group.nGroupID).FirstOrDefault(); if (tb_material_group == null) { tb_material_group = new TB_Material_Group(); tb_material_group.dCreate = DateTime.Now; db.TB_Material_Group.Add(tb_material_group); } tb_material_group.sName = TB_Material_Group.sName; tb_material_group.sDetail = TB_Material_Group.sDetail; tb_material_group.nOrder = TB_Material_Group.nOrder; tb_material_group.IsActive = TB_Material_Group.IsActive; tb_material_group.dUpdate = DateTime.Now; db.SaveChanges(); } else { result.sMsg = "ชื่อกลุ่มวัสดุนี้มีในระบบแล้ว"; result.sStatus = STFunction.process_Warning(); } } catch (Exception e) { result.sStatus = STFunction.process_Failed(); result.sMsg = e.ToString(); } return(Ok(result)); }
public IActionResult GetMaterialGroup__Del_data(int[] nCategoryID) { CResutlWebMethod result = new CResutlWebMethod(); PTTGSP_DWSContext db = new PTTGSP_DWSContext(); if (nCategoryID.Length > 0) { List <TB_Material_Category> listtb_material_category = db.TB_Material_Category.Where(w => nCategoryID.Contains(w.nCategoryID)).ToList(); foreach (var i in listtb_material_category) { i.IsDel = true; db.SaveChanges(); } SetOrderAll(); result.sStatus = STFunction.process_Success(); } else { result.sStatus = STFunction.process_Warning(); } return(Ok(result)); }
public SysModalGlobal.CResutlWebMethod SavetoDB([FromBody] TB_Material_Location data) { PTTGSP_DWSContext db = new PTTGSP_DWSContext(); var result = new SysModalGlobal.CResutlWebMethod(); try { var MaterialLocation = db.TB_Material_Location.ToList(); var duplicate = (from a in db.TB_Material_Location where !a.IsDel && a.sName.Trim().ToLower() == data.sName.Trim().ToLower() && a.nLocationID != data.nLocationID select a).FirstOrDefault(); if (duplicate != null) { // result.sStatus = SysGlobal.SysFunc.process_Duplicate; result.sStatus = STFunction.process_Warning(); result.sMsg = "สถานที่เก็บวัสดุนี้มีในระบบอยู่แล้ว"; return(result); } var nLocationID = (MaterialLocation.Any() ? MaterialLocation.Max(m => m.nLocationID) : 0) + 1; if (data.nLocationID == 0) { db.TB_Material_Location.Add(new TB_Material_Location { sName = data.sName, sDetail = data.sDetail, IsActive = data.IsActive, IsDel = false, dCreate = DateTime.Now, sCreateBy = data.sCreateBy, dUpdate = DateTime.Now, sUpdateBy = data.sUpdateBy, }); db.SaveChanges(); } else { var oldnID = (from a in db.TB_Material_Location where a.nLocationID == data.nLocationID select a).FirstOrDefault(); if (oldnID != null) { oldnID.sName = data.sName; oldnID.sDetail = data.sDetail; oldnID.IsActive = data.IsActive; oldnID.IsDel = false; oldnID.dUpdate = DateTime.Now; oldnID.sUpdateBy = data.sUpdateBy; db.SaveChanges(); } } result.sStatus = SysFunc.process_Success; } catch (Exception e) { result.sStatus = SysFunc.process_Error; result.sMsg = e.Message; } return(result); }
public SysModalGlobal.CResutlWebMethod SavetoDB([FromBody] lstSavedata data) { PTTGSP_DWSContext db = new PTTGSP_DWSContext(); var result = new SysModalGlobal.CResutlWebMethod(); try { var Work = db.TB_Work.ToList(); var WorkMaterials = db.TB_Work_Material.ToList(); var duplicate = (from a in db.TB_Work where !a.IsDel && a.sName.Trim().ToLower() == data.sName.Trim().ToLower() && a.nWorkID != data.nWorkID select a).FirstOrDefault(); if (duplicate != null) { // result.sStatus = SysGlobal.SysFunc.process_Duplicate; result.sStatus = STFunction.process_Warning(); result.sMsg = "ลักษณะงานนี้มีในระบบอยู่แล้ว"; return(result); } var nWorkID = (Work.Any() ? Work.Max(m => m.nWorkID) : 0) + 1; if (data.nWorkID == 0) { TB_Work a = new TB_Work() { sName = data.sName, nReasonID = data.nReasonID, sDetail = data.sDetail, IsActive = data.IsActive, IsDel = false, dCreate = DateTime.Now, sCreateBy = data.sCreateBy, dUpdate = DateTime.Now, sUpdateBy = data.sUpdateBy, }; db.TB_Work.Add(a); db.SaveChanges(); db = new PTTGSP_DWSContext(); foreach (var per in data.lstWorkMaterial) { //data.lstWorkMaterial.Remove(per); if (per.nWorkID == 0) { TB_Work_Material s = new TB_Work_Material(); s.nWorkID = nWorkID; s.nMaterialID = per.nMaterialID; s.nAmount = per.nAmount; s.IsActive = per.IsActive; db.TB_Work_Material.Add(s); } else { var edit = db.TB_Work_Material.FirstOrDefault(w => w.nWorkID == per.nWorkID); if (edit != null) { edit.nMaterialID = per.nMaterialID; edit.nAmount = per.nAmount; edit.IsActive = per.IsActive; } } } db.SaveChanges(); } else { var oldnID = (from a in db.TB_Work where a.nWorkID == data.nWorkID select a).FirstOrDefault(); if (oldnID != null) { oldnID.sName = data.sName; oldnID.nReasonID = data.nReasonID; oldnID.sDetail = data.sDetail; oldnID.IsActive = data.IsActive; oldnID.IsDel = false; oldnID.dUpdate = DateTime.Now; oldnID.sUpdateBy = data.sUpdateBy; db.SaveChanges(); } foreach (var per in data.lstWorkMaterial) { if (nWorkID != 0) { var editdata = db.TB_Work_Material.FirstOrDefault(w => w.nWorkID == per.nWorkID); if (editdata != null) { db.TB_Work_Material.Remove(editdata); editdata.nAmount = per.nAmount; editdata.IsActive = per.IsActive; } } } db.SaveChanges(); foreach (var per in data.lstWorkMaterial) { TB_Work_Material s = new TB_Work_Material(); s.nMaterialID = per.nMaterialID; s.nAmount = per.nAmount; s.IsActive = per.IsActive; db.TB_Work_Material.Add(s); } db.SaveChanges(); } result.sStatus = SysFunc.process_Success; } catch (Exception e) { result.sStatus = SysFunc.process_Error; result.sMsg = e.Message; } return(result); }