예제 #1
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);
        }
예제 #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));
        }
        public IActionResult onDeleteDataMaterial(int nMaterialID)
        {
            CResutlWebMethod  result = new CResutlWebMethod();
            PTTGSP_DWSContext db     = new PTTGSP_DWSContext();

            result.sStatus = STFunction.process_Success();
            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));
        }
예제 #5
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 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));
        }