public SysModalGlobal.CResutlWebMethod DeleteData(string str)
        {
            PTTGSP_DWSContext db = new PTTGSP_DWSContext();

            SysModalGlobal.CResutlWebMethod result = new SysModalGlobal.CResutlWebMethod();

            try
            {
                if (!String.IsNullOrEmpty(str))
                {
                    var data        = str.Split(',').Select(Int32.Parse).ToList();
                    var lstWorkMate = db.TB_Work_Material.Where(w => data.Contains(w.nWorkID)).ToList();

                    foreach (var item in lstWorkMate)
                    {
                        db.TB_Work_Material.Remove(item);
                    }
                    db.SaveChanges();

                    var lstnID  = db.TB_Work.Where(w => !w.IsDel).ToList();
                    var lstData = lstnID.Where(w => data.Contains(w.nWorkID)).ToList();
                    lstData.ForEach(f => f.IsDel = true);

                    db.SaveChanges();
                    result.sStatus = SysFunc.process_Success;
                }
            }
            catch (Exception e)
            {
                result.sStatus = SysFunc.process_Error;
                result.sMsg    = e.Message;
            }
            return(result);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public ResultAPI Del_lst(GetnID data)
        {
            ResultAPI result = new ResultAPI();

            db = new PTTGSP_DWSContext();
            if (data.nID.Count > 0)
            {
                var del_Materials = db.TB_Materials.Where(w => data.nID.Contains(w.nMaterialID)).ToList();
                foreach (var i in del_Materials)
                {
                    i.IsDel = true;
                    db.SaveChanges();
                }
                db = new PTTGSP_DWSContext();
                var del_Materials_File = db.TB_Materials_File.Where(w => data.nID.Contains(w.nMaterialID)).ToList();
                db.TB_Materials_File.RemoveRange(del_Materials_File);
                foreach (var item in data.nID)
                {
                    string Path            = "/UploadFile/Supplies/Supplies_" + item;
                    bool   directoryExists = Directory.Exists(Path);
                    Directory.Delete(Path, true);
                    Console.WriteLine("top-level directory exists: " + directoryExists);
                }

                db.SaveChanges();

                result.Status = ResultStatus.Success;
            }
            else
            {
                result.Status = ResultStatus.Warning;
            }
            return(result);
        }
Exemplo n.º 4
0
        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 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 ResultAPI Del_lst(GetnID data)
        {
            ResultAPI result = new ResultAPI();

            if (data.nID.Count > 0)
            {
                var qData = db.TB_Vendor.Where(w => data.nID.Contains(w.nVendorID)).ToList();
                foreach (var i in qData)
                {
                    i.IsDel = true;
                    db.SaveChanges();
                }
                db.SaveChanges();

                result.Status = ResultStatus.Success;
            }
            else
            {
                result.Status = ResultStatus.Warning;
            }
            return(result);
        }
Exemplo n.º 7
0
        public void SetOrderAll()
        {
            PTTGSP_DWSContext        db = new PTTGSP_DWSContext();
            List <TB_Material_Group> listtb_material_group = db.TB_Material_Group.Where(w => w.IsDel == false).OrderBy(o => o.nOrder).ToList();

            if (listtb_material_group != null)
            {
                int neworder = 1;
                foreach (TB_Material_Group otb_material_group in listtb_material_group)
                {
                    otb_material_group.nOrder = neworder;
                    neworder++;
                }
                db.SaveChanges();
            }
        }
        public void SetOrderAll()
        {
            PTTGSP_DWSContext           db = new PTTGSP_DWSContext();
            List <TB_Material_Category> listtb_material_category = db.TB_Material_Category.Where(w => w.IsDel == false).OrderBy(o => o.nOrder).ToList();

            if (listtb_material_category != null)
            {
                int neworder = 1;
                foreach (TB_Material_Category otb_material_category in listtb_material_category)
                {
                    otb_material_category.nOrder = neworder;
                    neworder++;
                }
                db.SaveChanges();
            }
        }
        public ResultAPI SaveData(List <GetLimit_lst> data)
        {
            db = new PTTGSP_DWSContext();
            ResultAPI result = new ResultAPI();

            try
            {
                foreach (var i in data)
                {
                    if (i.sValue.ToDecimalOrNull() != null)
                    {
                        var Update = db.TM_Config.FirstOrDefault(f => f.nID == i.nID);
                        if (Update != null)
                        {
                            Update.nValue = i.sValue.ToDecimalOrNull();
                        }
                        else
                        {
                            result.Message = "ข้อมูลไม่ถูกต้อง !";
                            result.Status  = ResultStatus.Error;
                            return(result);
                        }
                        db.SaveChanges();
                    }
                    else
                    {
                        result.Message = "จำนวนเงินวงเงินไม่ถูกต้อง !";
                        result.Status  = ResultStatus.Warning;
                        return(result);
                    }
                }
                result.Status = ResultStatus.Success;
                return(result);
            }
            catch (Exception er)
            {
                result.Message = er.Message;
                result.Status  = ResultStatus.Error;
                return(result);
            }
        }
Exemplo n.º 10
0
        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 SysModalGlobal.CResutlWebMethod DeleteData(string str)
        {
            PTTGSP_DWSContext db = new PTTGSP_DWSContext();

            SysModalGlobal.CResutlWebMethod result = new SysModalGlobal.CResutlWebMethod();

            try
            {
                if (!String.IsNullOrEmpty(str))
                {
                    var data   = str.Split(',').Select(Int32.Parse).ToList();
                    var lstnID = db.TB_Material_Location.Where(w => !w.IsDel).ToList();

                    var lstMaterial = db.TB_Materials.Where(w => !w.IsDel).ToList();


                    var lstData = lstnID.Where(w => data.Contains(w.nLocationID)).ToList();
                    lstData.ForEach(f =>
                    {
                        var IsUse = lstMaterial.Where(w => w.nLocationID == f.nLocationID).ToList();
                        if (IsUse.Count() == 0)
                        {
                            f.IsDel = true;
                        }
                    });

                    db.SaveChanges();
                    result.sStatus = SysFunc.process_Success;
                }
            }
            catch (Exception e)
            {
                result.sStatus = SysFunc.process_Error;
                result.sMsg    = e.Message;
            }
            return(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 IActionResult Requestapproval(data data)
        {
            CResutlWebMethod  result = new CResutlWebMethod();
            PTTGSP_DWSContext db     = new PTTGSP_DWSContext();

            result.sStatus = STFunction.process_Success();

            try
            {
                ///-----------TB_Stock_Update
                TB_Stock_Update tb_stock_update = db.TB_Stock_Update.Where(w => w.nRequestID == data.oV_Stock_Update.nRequestID).FirstOrDefault();

                if (tb_stock_update == null)
                {
                    tb_stock_update = new TB_Stock_Update();

                    var countrunning = db.TB_Stock_Update.Where(w => w.dCreate.Month == DateTime.Now.Month && w.dCreate.Year == DateTime.Now.Year).ToList().Count();
                    var running      = "AS-" + DateTime.Now.AddYears(543).Year.ToString().Substring(2) + String.Format("{0:D2}", DateTime.Now.Month) + String.Format("{0:D4}", countrunning);

                    tb_stock_update.sRequestNo = running;
                    tb_stock_update.dCreate    = DateTime.Now;
                    db.TB_Stock_Update.Add(tb_stock_update);
                }
                tb_stock_update.nStepID           = data.oV_Stock_Update.nStepID ?? 0;
                tb_stock_update.dUpdateStockDate  = Convert.ToDateTime(data.oV_Stock_Update.sUpdatekc);
                tb_stock_update.sReason           = data.oV_Stock_Update.sReason;
                tb_stock_update.nTotalPrice_Minus = data.oV_Materials.Select(s => s.nTotalPrice_Minus ?? 0).Sum();
                tb_stock_update.nTotalPrice_Plus  = data.oV_Materials.Select(s => s.nTotalPrice_Plus ?? 0).Sum();
                tb_stock_update.nStepID           = 1;
                tb_stock_update.dUpdate           = DateTime.Now;

                db.SaveChanges();



                ///-----------TB_Stock_Update_Material
                List <TB_Stock_Update_Material> list_stock_update_material = db.TB_Stock_Update_Material.Where(w => w.nRequestID == tb_stock_update.nRequestID).ToList();

                if (list_stock_update_material != null)
                {
                    foreach (TB_Stock_Update_Material otb_stock_update_material in list_stock_update_material)
                    {
                        db.TB_Stock_Update_Material.Remove(otb_stock_update_material);
                    }
                }


                foreach (V_Materials ov_materials in data.oV_Materials)
                {
                    TB_Stock_Update_Material otb_stock_update_material = new TB_Stock_Update_Material();

                    otb_stock_update_material.nRequestID  = tb_stock_update.nRequestID;
                    otb_stock_update_material.nMaterialID = ov_materials.nMaterialID;
                    otb_stock_update_material.nAmount     = ov_materials.nAmount;
                    otb_stock_update_material.sCause      = ov_materials.sReason;

                    db.TB_Stock_Update_Material.Add(otb_stock_update_material);
                    db.SaveChanges();
                }



                TB_Stock_Update_Approval otb_stock_update_approval = new TB_Stock_Update_Approval();

                otb_stock_update_approval.nActionID  = 1;
                otb_stock_update_approval.dCreate    = DateTime.Now;
                otb_stock_update_approval.nRequestID = tb_stock_update.nRequestID;

                db.TB_Stock_Update_Approval.Add(otb_stock_update_approval);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                result.sStatus = SysFunc.process_Error;
                result.sMsg    = e.Message;
            }

            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 IActionResult Savedata(RequestApproval_save data)
        {
            string EmpCode = "580589";

            foreach (var i in data.lst)
            {
                int ActionID      = data.nActionID.Value;
                var UpdateRequest = db.T_Request.FirstOrDefault(w => w.nRequestID == i.nRequestID);
                if (UpdateRequest != null)
                {
                    if (UpdateRequest.sEmpCode_MG1 == EmpCode)
                    {
                        if (ActionID == 2)
                        {
                            UpdateRequest.IsApproved_MG1 = true;               //อนุมัติ
                        }
                        if (ActionID == 5)
                        {
                            UpdateRequest.IsApproved_MG1 = false;               //ส่งกลับแก้ไข
                        }
                        if (ActionID == 6)
                        {
                            UpdateRequest.IsApproved_MG1 = false;               // ยกเลิก
                        }
                    }
                    else if (UpdateRequest.sEmpCode_MG2 == EmpCode)
                    {
                        if (ActionID == 2)
                        {
                            UpdateRequest.IsApproved_MG2 = true;               //อนุมัติ
                        }
                        if (ActionID == 5)
                        {
                            UpdateRequest.IsApproved_MG2 = false;               //ส่งกลับแก้ไข
                        }
                        if (ActionID == 6)
                        {
                            UpdateRequest.IsApproved_MG2 = false;               // ยกเลิก
                        }
                    }
                    else if (UpdateRequest.sEmpCode_MG3 == EmpCode)
                    {
                        if (ActionID == 2)
                        {
                            UpdateRequest.IsApproved_MG3 = true;               //อนุมัติ
                        }
                        if (ActionID == 5)
                        {
                            UpdateRequest.IsApproved_MG3 = false;               //ส่งกลับแก้ไข
                        }
                        if (ActionID == 6)
                        {
                            UpdateRequest.IsApproved_MG3 = false;               // ยกเลิก
                        }
                    }
                    bool IsPass_MG1 = true;
                    bool IsPass_MG2 = true;
                    bool IsPass_MG3 = true;
                    if (UpdateRequest.sEmpCode_MG1 != null)
                    {
                        if (UpdateRequest.IsApproved_MG1 != null)
                        {
                            IsPass_MG1 = true;
                        }
                        else
                        {
                            IsPass_MG1 = false;
                        }
                    }
                    if (UpdateRequest.sEmpCode_MG2 != null)
                    {
                        if (UpdateRequest.IsApproved_MG2 != null)
                        {
                            IsPass_MG2 = true;
                        }
                        else
                        {
                            IsPass_MG2 = false;
                        }
                    }
                    if (UpdateRequest.sEmpCode_MG3 != null)
                    {
                        if (UpdateRequest.IsApproved_MG3 != null)
                        {
                            IsPass_MG3 = true;
                        }
                        else
                        {
                            IsPass_MG3 = false;
                        }
                    }

                    if (IsPass_MG1 && IsPass_MG2 && IsPass_MG3)
                    {
                        UpdateRequest.nStepID = 2;
                    }
                }
                var nID_Last = db.T_Request_Approval.Any() ? db.T_Request_Approval.Max(m => m.nID) : 0;
                db.T_Request_Approval.Add(new T_Request_Approval()
                {
                    nActionID  = ActionID,
                    nID        = nID_Last + 1,
                    nRequestID = i.nRequestID,
                    nRoleID    = 4,
                    sNote      = i.sNote,
                    dCreate    = DateTime.Now,
                    sCreateBy  = EmpCode,
                });
                foreach (var s in i.sub_List)
                {
                    var update = db.T_Request_Material.FirstOrDefault(w => w.nMaterialID == s.nMaterialID && w.nRequestID == i.nRequestID);
                    if (update != null)
                    {
                        if (s.IsApprove == null || s.IsApprove == true)
                        {
                            update.nPay_Amount     = s.nPay_Amount; //จำนวนที่อนุมัติ
                            update.nPay_Price      = s.nPay_Price;
                            update.nPay_TotalPrice = s.nPay_TotalPrice;
                            update.IsApprove       = true;
                        }
                        else
                        {
                            update.sNote     = s.sNote;
                            update.IsApprove = false;;
                        }
                    }
                }
            }
            db.SaveChanges();
            return(Ok(ResultStatus.Success));
        }
Exemplo n.º 16
0
        public IActionResult Request_Save(int nRequestID, DATA_Request d)
        {
            IProcessResult r = new IProcessResult();

            try
            {
                PTTGSP_DWSContext db   = new PTTGSP_DWSContext();
                UserAccount       ua   = IAuthen.SessionInfo();
                DateTime          dNow = DateTime.Now;

                var req = db.T_Request.FirstOrDefault(w => w.nRequestID == d.nRequestID);
                if (req == null)
                {
                    #region string sReqCode = ...;
                    string sReqCode              = "";
                    string sReqCode_Prefix       = "RS-" + dNow.ToStringFromDate("yyMM", "th-TH");
                    var    lstReqCode_samePrefix = db.T_Request.Where(w => w.sRequestNo.StartsWith(sReqCode_Prefix)).Select(s => s.sRequestNo).ToList();
                    string sReqCode_Last         = lstReqCode_samePrefix.Any() ? lstReqCode_samePrefix.Max() : "";
                    if (string.IsNullOrEmpty(sReqCode_Last))
                    {
                        sReqCode = sReqCode_Prefix + "1".PadLeft(4, '0');
                    }
                    else
                    {
                        int n = sReqCode_Last.Substring(sReqCode_Last.Length - 4).ToIntOrNull() ?? 1;
                        sReqCode = sReqCode_Prefix + n.ToString().PadLeft(4, '0');
                    }
                    #endregion

                    req = new T_Request()
                    {
                        sRequestNo        = sReqCode,
                        sOrgID            = ua.sUnitCode,
                        IsFastTrack       = d.isFastTrack,
                        sDetail_FastTrack = d.sFastTrackDetail,
                        nWorkID           = d.nWorkID,
                        nStepID           = 1,
                        IsCancel          = false,
                        sCreateBy         = ua.sEmployeeCode,
                        dCreate           = dNow
                    };
                    db.T_Request.Add(req);
                }

                req.sLocation      = d.sLocation;
                req.nReasonID      = d.nReasonID.Value;
                req.sDetail_Reason = d.sReasonDetail;
                req.sEmpCode_MG1   = ua.sEmpCode_MG1; req.IsApproved_MG1 = null;
                req.sEmpCode_MG2   = ua.sEmpCode_MG2; req.IsApproved_MG2 = null;
                req.sEmpCode_MG3   = ua.sEmpCode_MG3; req.IsApproved_MG3 = null;
                req.IsRevisit      = false;
                req.sUpdateBy      = ua.sEmployeeCode;
                req.dUpdate        = dNow;

                #region List<T_Request_Material> lstMaterial_ToSave = new List<T_Request_Material>() {...};
                List <T_Request_Material> lstMaterial_ToSave = new List <T_Request_Material>();

                var lstMaterialID = d.lstMaterial_Selected.Select(s => s.ItemID).ToList();
                var lstMaterial   = db.TB_Materials
                                    .Where(w => !w.IsDel && w.IsActive && lstMaterialID.Contains(w.nMaterialID))
                                    .Select(s => new { s.nMaterialID, s.nPrice }).ToList();

                decimal nTotalPrice = 0;
                d.lstMaterial_Selected.ForEach(m_selected =>
                {
                    var m_db = lstMaterial.FirstOrDefault(w => w.nMaterialID == m_selected.ItemID);
                    if (m_db != null)
                    {
                        var m = new T_Request_Material()
                        {
                            nMaterialID = m_selected.ItemID
                        };
                        m.nRequest_Amount     = m.nPay_Amount = m_selected.Amount;
                        m.nRequest_Price      = m.nPay_Price = m_db.nPrice;
                        m.nRequest_TotalPrice = m.nPay_TotalPrice = m_selected.Amount * m_db.nPrice;

                        nTotalPrice += m.nRequest_TotalPrice;

                        lstMaterial_ToSave.Add(m);
                    }
                });
                #endregion

                req.nRequest_TotalPrice = req.nPay_TotalPrice = nTotalPrice;

                db.SaveChanges();
                db = new PTTGSP_DWSContext();

                db.T_Request_Material.RemoveRange(db.T_Request_Material.Where(w => w.nRequestID == req.nRequestID));
                lstMaterial_ToSave.ForEach(m => { m.nRequestID = req.nRequestID; db.T_Request_Material.Add(m); });

                db.SaveChanges();
                r.Success = true;
            }
            catch (Exception ex)
            {
                r.Message = ex.Message;
            }

            return(Ok(r));
        }
        public ResultAPI SaveData(GetSeller_Edit data)
        {
            db = new PTTGSP_DWSContext();
            ResultAPI result = new ResultAPI();

            if (data.nVendorID == 0)                                                                              //create
            {
                var CheckCode = db.TB_Vendor.FirstOrDefault(w => w.sCompanyCode == data.sCompanyCode && w.IsDel); //Check CompanyCode
                if (CheckCode != null)
                {
                    result.Message = "มีรหัสบริษัทในระบบแล้ว !";
                    result.Status  = ResultStatus.Warning;
                }
                else
                {
                    TB_Vendor s = new TB_Vendor();
                    s.sCompanyCode = data.sCompanyCode;
                    s.sCompanyName = data.sCompanyName;
                    s.sContactName = data.sContactName;
                    s.sEmail       = data.sEmail;
                    s.sTel         = data.sTel;
                    s.sDetail      = data.sDetail;
                    s.IsActive     = data.IsActive == "0" ? true : false;
                    s.sCreateBy    = "";
                    s.sUpdateBy    = "";
                    s.dCreate      = DateTime.Now;
                    s.dUpdate      = DateTime.Now;
                    db.TB_Vendor.Add(s);

                    result.Status = ResultStatus.Success;
                }
            }
            else //Update
            {
                var CheckCode = db.TB_Vendor.FirstOrDefault(w => w.sCompanyCode == data.sCompanyCode && w.IsDel); //Check CompanyCode
                if (CheckCode != null)
                {
                    result.Message = "มีรหัสบริษัทในระบบแล้ว !";
                    result.Status  = ResultStatus.Warning;
                }
                else
                {
                    int nID    = data.nVendorID;
                    var Update = db.TB_Vendor.FirstOrDefault(w => w.nVendorID == nID);
                    if (Update != null)
                    {
                        Update.sCompanyCode = data.sCompanyCode;
                        Update.sCompanyName = data.sCompanyName;
                        Update.sContactName = data.sContactName;
                        Update.sEmail       = data.sEmail;
                        Update.sTel         = data.sTel;
                        Update.sDetail      = data.sDetail;
                        Update.IsActive     = data.IsActive == "0" ? true : false;
                        Update.sUpdateBy    = "";
                        Update.dUpdate      = DateTime.Now;

                        result.Status = ResultStatus.Success;
                    }
                    else
                    {
                        result.Message = "ข้อมูลไม่ถูกต้อง !";
                        result.Status  = ResultStatus.Error;
                    }
                }
            }
            db.SaveChanges();
            return(result);
        }
Exemplo n.º 18
0
        public ActionResult SaveData(SaveSupplies data)
        {
            db = new PTTGSP_DWSContext();
            SaveSupplies result      = new SaveSupplies();
            int          nMaterialID = data.nMaterialID.ToIntOrZero();
            var          ChackData   = db.TB_Materials.FirstOrDefault(f => f.nMaterialID == nMaterialID);

            if (ChackData != null) //Update
            {
                ChackData.sName            = data.sName;
                ChackData.nUnitID          = data.nUnitID.ToIntOrZero();
                ChackData.nPrice           = data.nPrice.ToDecimalOrZero();
                ChackData.nLocationID      = data.nLocationID.ToIntOrZero();
                ChackData.sBinLocation     = data.sBinLocation;
                ChackData.nMin             = data.nMin.ToIntOrZero();
                ChackData.nMax             = data.nMax.ToIntOrZero();
                ChackData.nReOrderPoint    = data.nReOrderPoint.ToIntOrZero();
                ChackData.nMaxReserve      = data.nMaxReserve.ToIntOrZero();
                ChackData.nDuplicateDay    = data.nDuplicateDay.ToIntOrZero();
                ChackData.sDetail_Material = data.sDetail_Material;
                ChackData.sDetail          = data.sDetail;
                ChackData.IsActive         = data.IsActive;

                foreach (var item in data.file)
                {
                    if (item.IsNewFile)
                    {
                        string sNewPath        = "Supplies";
                        string sTepmPath       = "Temp";
                        string foldersTempPath = MapCurrentPath(sTepmPath + "/");
                        string foldersNewPath  = MapCurrentPath(sNewPath + "/");
                        string sNewTemp        = "UploadFile/" + sNewPath + "/" + item.sSaveToFileName;

                        ChackData.sFile_Name    = item.sFileName;
                        ChackData.sFile_SysName = item.sSaveToFileName;
                        ChackData.sFile_Path    = "/" + sNewTemp;

                        SysFunc.FolderCreate(sNewPath);

                        string OldTemp = foldersTempPath + item.sSaveToFileName;
                        string NewTemp = foldersNewPath + item.sSaveToFileName;

                        System.IO.File.Move(OldTemp, NewTemp);
                    }
                }

                ChackData.dUpdate   = DateTime.Now;
                ChackData.sUpdateBy = "";

                if (data.listfile.Any())
                {
                    foreach (var item in data.listfile)
                    {
                        if (item.IsNewFile)
                        {
                            string sNewPath        = "Supplies/Supplies_" + nMaterialID;
                            string sTepmPath       = "Temp";
                            string foldersTempPath = MapCurrentPath(sTepmPath + "/");
                            string foldersNewPath  = MapCurrentPath(sNewPath + "/");
                            string sNewTemp        = "UploadFile/" + sNewPath + "/" + item.sSaveToFileName;

                            var Countfile = db.TB_Materials_File.Where(w => w.nMaterialID == nMaterialID).Count();
                            Countfile = Countfile + 1;

                            TB_Materials_File f = new TB_Materials_File();
                            f.nMaterialID   = nMaterialID;
                            f.nItem         = Countfile;
                            f.sFile_Name    = item.sFileName;
                            f.sFile_Path    = "/" + sNewTemp;
                            f.sFile_SysName = item.sSaveToFileName;

                            SysFunc.FolderCreate(sNewPath);
                            string OldTemp = foldersTempPath + item.sSaveToFileName;
                            string NewTemp = foldersNewPath + item.sSaveToFileName;

                            System.IO.File.Move(OldTemp, NewTemp);

                            db.TB_Materials_File.Add(f);
                        }
                    }
                }
                db.SaveChanges();
            }
            else //create
            {
                int CategoryID = data.nCategoryID.ToIntOrZero();
                var CreateCode = db.TB_Material_Category.FirstOrDefault(w => w.nCategoryID == CategoryID);
                if (CreateCode != null)
                {
                    string MaterialCode  = "";
                    var    CountCategory = db.TB_Materials.Where(w => w.nCategoryID == CreateCode.nCategoryID).Count();
                    if (CountCategory != 0)
                    {
                        string plusone = (CountCategory + 1) + "";
                        MaterialCode = plusone.PadLeft(3, '0');
                    }
                    else
                    {
                        MaterialCode = "001";
                    }

                    TB_Materials s = new TB_Materials();
                    s.sMaterialCode    = CreateCode.sCategoryCode + "-" + MaterialCode;
                    s.nGroupID         = data.nGroupID.ToIntOrZero();
                    s.nCategoryID      = data.nCategoryID.ToIntOrZero();
                    s.sName            = data.sName;
                    s.nUnitID          = data.nUnitID.ToIntOrZero();
                    s.nPrice           = data.nPrice.ToDecimalOrZero();
                    s.nLocationID      = data.nLocationID.ToIntOrZero();
                    s.sBinLocation     = data.sBinLocation;
                    s.nMin             = data.nMin.ToIntOrZero();
                    s.nMax             = data.nMax.ToIntOrZero();
                    s.nReOrderPoint    = data.nReOrderPoint.ToIntOrZero();
                    s.nMaxReserve      = data.nMaxReserve.ToIntOrZero();
                    s.nDuplicateDay    = data.nDuplicateDay.ToIntOrZero();
                    s.sDetail_Material = data.sDetail_Material;
                    s.sDetail          = data.sDetail;

                    foreach (var item in data.file)
                    {
                        string sNewPath        = "Supplies";
                        string sTepmPath       = "Temp";
                        string foldersTempPath = MapCurrentPath(sTepmPath + "/");
                        string foldersNewPath  = MapCurrentPath(sNewPath + "/");
                        string sNewTemp        = "UploadFile/" + sNewPath + "/" + item.sSaveToFileName;

                        s.sFile_Name    = item.sFileName;
                        s.sFile_SysName = item.sSaveToFileName;
                        s.sFile_Path    = "/" + sNewTemp;

                        if (item.IsNewFile)
                        {
                            SysFunc.FolderCreate(sNewPath);
                            string OldTemp = foldersTempPath + item.sSaveToFileName;
                            string NewTemp = foldersNewPath + item.sSaveToFileName;
                            System.IO.File.Move(OldTemp, NewTemp);
                        }
                    }
                    s.IsActive  = data.IsActive;
                    s.dCreate   = DateTime.Now;
                    s.dUpdate   = DateTime.Now;
                    s.sCreateBy = "";
                    s.sUpdateBy = "";
                    db.TB_Materials.Add(s);
                    db.SaveChanges();

                    if (data.listfile.Any())
                    {
                        db = new PTTGSP_DWSContext();
                        int Countfile = 1;
                        foreach (var item in data.listfile)
                        {
                            string sNewPath        = "Supplies/Supplies_" + s.nMaterialID;
                            string sTepmPath       = "Temp";
                            string foldersTempPath = MapCurrentPath(sTepmPath + "/");
                            string foldersNewPath  = MapCurrentPath(sNewPath + "/");
                            string sNewTemp        = "UploadFile/" + sNewPath + "/" + item.sSaveToFileName;

                            TB_Materials_File f = new TB_Materials_File();
                            f.nMaterialID   = s.nMaterialID;
                            f.nItem         = Countfile;
                            f.sFile_Name    = item.sFileName;
                            f.sFile_Path    = "/" + sNewTemp;
                            f.sFile_SysName = item.sSaveToFileName;
                            Countfile++;

                            if (item.IsNewFile)
                            {
                                SysFunc.FolderCreate(sNewPath);
                                string OldTemp = foldersTempPath + item.sSaveToFileName;
                                string NewTemp = foldersNewPath + item.sSaveToFileName;

                                System.IO.File.Move(OldTemp, NewTemp);
                            }
                            db.TB_Materials_File.Add(f);
                        }
                        db.SaveChanges();
                    }
                    db = new PTTGSP_DWSContext();
                    TB_Materials_BP BP = new TB_Materials_BP();
                    BP.nMaterialID  = s.nMaterialID;
                    BP.nMat_Balance = 0;
                    BP.nMat_Pending = 0;
                    BP.nMat_BP      = 0;
                    db.TB_Materials_BP.Add(BP);
                    db.SaveChanges();
                }
            }
            result.Status = ResultStatus.Success;
            return(Ok(result));
        }
Exemplo n.º 19
0
        public ResultAPI SaveData(latReceive_Save data)
        {
            latReceive_Save result = new latReceive_Save();

            db = new PTTGSP_DWSContext();
            CultureInfo TH = new CultureInfo("th-TH");
            CultureInfo EN = new CultureInfo("en-US");

            DateTime dt = DateTime.Now;

            if (data.nRequestID == 0)
            {
                int nRequestID = data.nRequestID;
                var Update     = db.TB_Goods_Receive.FirstOrDefault(w => w.nRequestID == nRequestID);
                if (Update == null)
                {
                    string RequestNo = "";
                    var    nID_Last  = db.TB_Goods_Receive.Any() ? db.TB_Goods_Receive.Max(m => m.nRequestID) : 0;
                    var    GenCode   = db.TB_Goods_Receive.Where(w => w.dCreate.Month == DateTime.Now.Month && w.dCreate.Year == DateTime.Now.Year).Count();
                    if (GenCode != 0)
                    {
                        string plusone = (GenCode + 1) + "";
                        RequestNo = plusone.PadLeft(4, '0');
                    }
                    else
                    {
                        RequestNo = "0001";
                    }
                    string sYear      = dt.ToString("yy", TH);
                    string sdate      = dt.ToString("dd", TH);
                    string sRequestNo = "GR-" + sYear + sdate + RequestNo;

                    Update = new TB_Goods_Receive()
                    {
                        nRequestID = nID_Last + 1,
                        sRequestNo = sRequestNo,
                        sCreateBy  = "",
                        dUpdate    = DateTime.Now,
                        sUpdateBy  = "",
                        dCreate    = DateTime.Now
                    };

                    db.TB_Goods_Receive.Add(Update);
                }
                Update.nSourceID = data.sSourceID.ToIntOrZero();
                Update.sRefNo    = data.sRefNo;

                Update.dDocDate     = Convert.ToDateTime(data.sDocDate, cultures);
                Update.dReceiveDate = Convert.ToDateTime(data.sReceiveDate, cultures);
                Update.nVendorID    = data.sVendorID.ToIntOrZero();
                Update.sNote        = data.sNote;
                Update.nTotalPrice  = data.nTotalPrice.ToIntOrZero();
                Update.dCreate      = DateTime.Now;
                Update.sUpdateBy    = "";

                foreach (var item in data.file)
                {
                    if (item.IsNewFile)
                    {
                        string sNewPath        = "Good_Receive/Good_Receive_" + Update.nRequestID;
                        string sTepmPath       = "Temp";
                        string foldersTempPath = MapCurrentPath(sTepmPath + "/");
                        string foldersNewPath  = MapCurrentPath(sNewPath + "/");
                        string sNewTemp        = "UploadFile/" + sNewPath + "/" + item.sSaveToFileName;

                        Update.sFile_Name    = item.sFileName;
                        Update.sFile_SysName = item.sSaveToFileName;
                        Update.sFile_Path    = "/" + sNewTemp;

                        SysFunc.FolderCreate(sNewPath);

                        string OldTemp = foldersTempPath + item.sSaveToFileName;
                        string NewTemp = foldersNewPath + item.sSaveToFileName;

                        System.IO.File.Move(OldTemp, NewTemp);
                    }
                }
                foreach (var i in data.sub_TB)
                {
                    TB_Goods_Receive_Material s = new TB_Goods_Receive_Material();
                    s.nRequestID  = Update.nRequestID;
                    s.nMaterialID = i.nMaterialID;
                    s.nAmount     = i.nNumber.ToIntOrZero();
                    s.nPrice      = i.nPriceperpiece.ToDecimalOrZero();
                    s.nTotalPrice = i.nSum;

                    db.TB_Goods_Receive_Material.Add(s);
                }

                db.SaveChanges();
            }
            result.Status = ResultStatus.Success;
            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);
        }