Exemple #1
0
        //出庫
        public String IssuanceIntoDB(String sStaffID, String sProd, String sFuncCode)
        {
            String sResult = "";

            try
            {
                //Inventory Info = db.Inventory.Find(ClearInfo.FirstOrDefault().Prod);

                if (db.Inventory.Where(i => i.Prod == sProd).Count() > 0)
                {
                    var Info = db.Inventory.Where(i => i.Prod == sProd).FirstOrDefault();
                    //先刪除庫存資料
                    db.Inventory.Remove(Info);
                    db.SaveChanges();
                    //將異動資料寫入歷史記錄資料表
                    var HistoryInfo = new HistoryInventory
                    {
                        Type            = Info.Type,
                        Prod            = Info.Prod,
                        Thickness       = Info.Thickness,
                        Widt            = Info.Widt,
                        Leng            = Info.Leng,
                        Splice          = Info.Splice,
                        Ptno            = Info.Ptno,
                        ProductDate     = Convert.ToDateTime(Info.ProductDate),
                        CustomerNO      = Info.CustomerNO,
                        StaffID         = sStaffID,
                        TransactionDate = Convert.ToDateTime(Info.TransactionDate),
                        SrnmType        = sFuncCode,
                        NewWeight       = Info.NewWeight,
                        ZoneSN          = Info.ZoneSN,
                        ZoneID          = Info.ZoneID,
                        PackNo          = Info.PackNo,
                        Thickness2      = Info.Thickness2
                    };
                    db.HistoryInventory.Add(HistoryInfo);
                    db.SaveChanges();
                    sResult = "true";
                }
                else
                {
                    sResult = "無" + sProd + "此筆資料,此筆資料可能已出庫!!";
                }
            }
            catch (Exception ex)
            {
                sResult = ex.ToString();
            }
            return(sResult);
        }
Exemple #2
0
        //入庫
        public String ReceiptIntoDB(String sStaffID, String sZoneNo, String sZoneSN, String sFuncCode, List <String> InfoList, String sCopper, String sCustomer, String sCtlNo1, String sCtlNo2)
        {
            String sResult = "";
            //取得ZoneID
            String sZoneID = GetZoneID(sZoneNo);
            //取得松電工的支號
            String sProd = (sCopper.Equals("4")) ? InfoList[3].ToString() : InfoList[0].ToString();
            var    Info  = new Inventory();

            try
            {
                if (db.Inventory.Where(i => i.Prod == sProd).Count() > 0)
                {
                    sResult = sProd + ",此筆資料,已入庫!!";
                }
                else
                {
                    if (InfoList.Count == 12 && sCopper.Equals("1"))
                    {
                        //設定日期格式
                        DateTime dt = SetDateTime(int.Parse(InfoList[7].Substring(0, 4)),
                                                  int.Parse(InfoList[7].Substring(4, 2)),
                                                  int.Parse(InfoList[7].Substring(6, 2)));
                        Info = new Inventory
                        {
                            Thickness       = InfoList[2],
                            Widt            = InfoList[3],
                            Type            = InfoList[10],
                            Prod            = InfoList[0],
                            Leng            = int.Parse((InfoList[4])),
                            NewWeight       = float.Parse(InfoList[5]),
                            SrnmType        = sFuncCode,
                            ProductDate     = dt,
                            TransactionDate = DateTime.Now,
                            StaffID         = sStaffID,
                            ZoneID          = sZoneID,
                            ZoneSN          = sZoneSN,
                            Splice          = InfoList[6],
                            Ptno            = InfoList[11],
                            CustomerNO      = sCustomer,
                            PackNo          = InfoList[9],
                            Thickness2      = InfoList[1],
                            CtlNo1          = sCtlNo1,
                            CtlNo2          = sCtlNo2
                        };
                    }

                    //松電工
                    else if (InfoList.Count == 12 && sCopper.Equals("4"))
                    {
                        //設定日期格式
                        DateTime dt = SetDateTime(int.Parse(InfoList[9].Substring(0, 4)),
                                                  int.Parse(InfoList[9].Substring(4, 2)),
                                                  int.Parse(InfoList[9].Substring(6, 2)));
                        Info = new Inventory
                        {
                            Thickness       = InfoList[5],
                            Widt            = InfoList[6],
                            Type            = InfoList[11],
                            Prod            = InfoList[3],
                            Leng            = int.Parse((InfoList[7])),
                            NewWeight       = float.Parse(InfoList[2]),
                            SrnmType        = sFuncCode,
                            ProductDate     = dt,
                            TransactionDate = DateTime.Now,
                            StaffID         = sStaffID,
                            ZoneID          = sZoneID,
                            ZoneSN          = sZoneSN,
                            Splice          = InfoList[8],
                            Ptno            = InfoList[0],
                            CustomerNO      = sCustomer,
                            PackNo          = InfoList[10],
                            Thickness2      = InfoList[4],
                            CtlNo1          = sCtlNo1,
                            CtlNo2          = sCtlNo2
                        };
                    }
                    //日系一般
                    else if (InfoList.Count == 9 && sCopper.Equals("5"))
                    {
                        //設定日期格式
                        DateTime dt = SetDateTime(int.Parse(InfoList[5].Substring(0, 2)) + 2000,
                                                  int.Parse(InfoList[5].Substring(2, 2)),
                                                  int.Parse(InfoList[5].Substring(4, 2)));
                        Info = new Inventory
                        {
                            //Thickness = InfoList[1],日系一般沒有此項資料
                            Widt            = InfoList[2],
                            Type            = InfoList[6],
                            Prod            = InfoList[0],
                            Leng            = int.Parse((InfoList[3])),
                            NewWeight       = float.Parse(InfoList[4]),
                            SrnmType        = sFuncCode,
                            ProductDate     = dt,
                            TransactionDate = DateTime.Now,
                            StaffID         = sStaffID,
                            ZoneID          = sZoneID,
                            ZoneSN          = sZoneSN,
                            //Splice = InfoList[5],沒有接頭數
                            CustomerNO = sCustomer,
                            CtlNo1     = sCtlNo1,
                            CtlNo2     = sCtlNo2,
                            Thickness2 = InfoList[1],
                            Ptno       = InfoList[7]
                                         //特殊記項為,InfoList[8],尚無用到
                        };
                    }
                    else if (InfoList.Count == 9)
                    //else
                    {
                        //設定日期格式
                        DateTime dt = SetDateTime(int.Parse(InfoList[6].Substring(0, 2)) + 2000,
                                                  int.Parse(InfoList[6].Substring(2, 2)),
                                                  int.Parse(InfoList[6].Substring(4, 2)));
                        Info = new Inventory
                        {
                            //Thickness = InfoList[2],
                            //Widt = InfoList[3],
                            //Type = InfoList[9],
                            //Prod = InfoList[1],
                            //Leng = int.Parse((InfoList[4])),
                            //NewWeight = float.Parse(InfoList[5]),
                            //SrnmType = sFuncCode,
                            //ProductDate = dt,
                            //TransactionDate = DateTime.Now,
                            //StaffID = sStaffID,
                            //ZoneID = sZoneID,
                            //ZoneSN = sZoneSN,
                            //Splice = InfoList[6],
                            ////Ptno = InfoList[11]

                            Thickness       = InfoList[1],
                            Widt            = InfoList[2],
                            Type            = InfoList[8],
                            Prod            = InfoList[0],
                            Leng            = int.Parse((InfoList[3])),
                            NewWeight       = float.Parse(InfoList[4]),
                            SrnmType        = sFuncCode,
                            ProductDate     = dt,
                            TransactionDate = DateTime.Now,
                            StaffID         = sStaffID,
                            ZoneID          = sZoneID,
                            ZoneSN          = sZoneSN,
                            Splice          = InfoList[5],
                            CustomerNO      = sCustomer,
                            CtlNo1          = sCtlNo1,
                            CtlNo2          = sCtlNo2
                                              //Ptno = InfoList[11]
                        };
                    }
                    db.Inventory.Add(Info);
                    db.SaveChanges();
                    //將異動資料寫入歷史記錄資料表
                    var HistoryInfo = new HistoryInventory
                    {
                        Type            = Info.Type,
                        Prod            = Info.Prod,
                        Thickness       = Info.Thickness,
                        Widt            = Info.Widt,
                        Leng            = Info.Leng,
                        Splice          = Info.Splice,
                        Ptno            = Info.Ptno,
                        ProductDate     = Convert.ToDateTime(Info.ProductDate),
                        CustomerNO      = Info.CustomerNO,
                        StaffID         = sStaffID,
                        TransactionDate = Convert.ToDateTime(Info.TransactionDate),
                        SrnmType        = sFuncCode,
                        NewWeight       = Info.NewWeight,
                        ZoneSN          = Info.ZoneSN,
                        ZoneID          = Info.ZoneID,
                        PackNo          = Info.PackNo,
                        Thickness2      = Info.Thickness2
                    };
                    db.HistoryInventory.Add(HistoryInfo);
                    db.SaveChanges();
                    sResult = "true";
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                sResult = ex.ToString();
            };
            return(sResult);
        }
 public ActionResult ImportInfo()
 {
     //需要盤點程序結束的狀態且是ImportInventory有資料的情況下,才能進行盤盈匯入
     if (db.SysPara.Where(r => r.ParaName == "Inventory").FirstOrDefault().ParaValue.Equals("false") && db.ImportInventory.Count() > 0)
     {
         //先查詢要匯入的資料
         foreach (var result in db.ImportInventory)
         {
             //先將資料記錄到HistoryInventory
             var HistoryInfo = new HistoryInventory
             {
                 Type = result.Type,
                 Prod = result.Prod,
                 Thickness = result.Thickness,
                 Widt = result.Widt,
                 Leng = result.Leng,
                 Splice = result.Splice,
                 Ptno = result.Ptno,
                 ProductDate = Convert.ToDateTime(result.ProductDate),
                 CustomerNO = result.CustomerNO,
                 TransactionDate = Convert.ToDateTime(result.TransactionDate),
                 SrnmType = "4",
                 NewWeight = result.NewWeight,
                 ZoneSN = result.ZoneSN,
                 ZoneID = result.ZoneID,
                 PackNo = result.PackNo,
                 Thickness2 = result.Thickness2
             };
             db.HistoryInventory.Add(HistoryInfo);
             db.SaveChanges();
             //再寫入庫存table
             var ImportInfo = new Inventory
             {
                 Type = result.Type,
                 Prod = result.Prod,
                 Thickness = result.Thickness,
                 Widt = result.Widt,
                 Leng = result.Leng,
                 Splice = result.Splice,
                 Ptno = result.Ptno,
                 ProductDate = Convert.ToDateTime(result.ProductDate),
                 CustomerNO = result.CustomerNO,
                 TransactionDate = Convert.ToDateTime(result.TransactionDate),
                 SrnmType = "4",
                 NewWeight = result.NewWeight,
                 ZoneSN = result.ZoneSN,
                 ZoneID = result.ZoneID,
                 PackNo = result.PackNo,
                 Thickness2 = result.Thickness2
             };
             db.Inventory.Add(ImportInfo);
             db.SaveChanges();
             //刪除每一筆ImportInventory的資料
             db.ImportInventory.Remove(result);
             if (TryUpdateModel(result))
             {
                 db.SaveChanges();
             }
         }
         //如果前此盤點時,完全都沒有需要盤虧刪除的資料,仍要把tempInventory的資料刪除
         if (db.ClearInventory.Count() == 0)
         {
             var TempResult = db.TempInventory.Select(s => s).ToList();
             //刪除tempinventory的所有資料
             db.TempInventory.RemoveRange(TempResult);
             db.SaveChanges();
         }
     }
     //當ClearInventory與ImportInventory資料都為0,
     //表示此盤點程序與庫存資料已經核對完畢,則將db的參數改為true
     if (db.ClearInventory.Count() == 0 && db.ImportInventory.Count() == 0)
     {
         try
         {
             if (ModelState.IsValid)
             {
                 var SysPara = db.SysPara.Where(r => r.ParaName == "Inventory");
                 if (SysPara != null)
                 {
                     SysPara.FirstOrDefault().ParaValue = "true";
                     db.SaveChanges();
                 }
             }
         }
         catch (Exception ex)
         {
         };
     }
     //return View();
     return RedirectToAction("Index", "BarCodeWebDiffInventory");
 }
Exemple #4
0
        //入庫
        public String ReceiptIntoDB(String sStaffID, String sZoneNo, String sZoneSN, String sFuncCode, List<String> InfoList, String sCopper, String sCustomer, String sCtlNo1, String sCtlNo2)
        {
            String sResult = "";
            //取得ZoneID
            String sZoneID = GetZoneID(sZoneNo);
            //取得松電工的支號
            String sProd = (sCopper.Equals("4")) ? InfoList[3].ToString() : InfoList[0].ToString();
            var Info = new Inventory();
            try
            {
                if (db.Inventory.Where(i => i.Prod == sProd).Count() > 0)
                {
                    sResult = sProd + ",此筆資料,已入庫!!";
                }
                else
                {
                    if (InfoList.Count == 12 && sCopper.Equals("1"))
                    {
                        //設定日期格式
                        DateTime dt = SetDateTime(int.Parse(InfoList[7].Substring(0, 4)),
                                                  int.Parse(InfoList[7].Substring(4, 2)),
                                                  int.Parse(InfoList[7].Substring(6, 2)));
                        Info = new Inventory
                        {
                            Thickness = InfoList[2],
                            Widt = InfoList[3],
                            Type = InfoList[10],
                            Prod = InfoList[0],
                            Leng = int.Parse((InfoList[4])),
                            NewWeight = float.Parse(InfoList[5]),
                            SrnmType = sFuncCode,
                            ProductDate = dt,
                            TransactionDate = DateTime.Now,
                            StaffID = sStaffID,
                            ZoneID = sZoneID,
                            ZoneSN = sZoneSN,
                            Splice = InfoList[6],
                            Ptno = InfoList[11],
                            CustomerNO = sCustomer,
                            PackNo = InfoList[9],
                            Thickness2 = InfoList[1],
                            CtlNo1 = sCtlNo1,
                            CtlNo2 = sCtlNo2
                        };
                    }

                    //松電工
                    else if (InfoList.Count == 12 && sCopper.Equals("4"))
                    {
                        //設定日期格式
                        DateTime dt = SetDateTime(int.Parse(InfoList[9].Substring(0, 4)),
                                                  int.Parse(InfoList[9].Substring(4, 2)),
                                                  int.Parse(InfoList[9].Substring(6, 2)));
                        Info = new Inventory
                        {
                            Thickness = InfoList[5],
                            Widt = InfoList[6],
                            Type = InfoList[11],
                            Prod = InfoList[3],
                            Leng = int.Parse((InfoList[7])),
                            NewWeight = float.Parse(InfoList[2]),
                            SrnmType = sFuncCode,
                            ProductDate = dt,
                            TransactionDate = DateTime.Now,
                            StaffID = sStaffID,
                            ZoneID = sZoneID,
                            ZoneSN = sZoneSN,
                            Splice = InfoList[8],
                            Ptno = InfoList[0],
                            CustomerNO = sCustomer,
                            PackNo = InfoList[10],
                            Thickness2 = InfoList[4],
                            CtlNo1 = sCtlNo1,
                            CtlNo2 = sCtlNo2
                        };
                    }
                    //日系一般
                    else if (InfoList.Count == 9 && sCopper.Equals("5"))
                    {
                        //設定日期格式
                        DateTime dt = SetDateTime(int.Parse(InfoList[5].Substring(0, 2)) + 2000,
                                                  int.Parse(InfoList[5].Substring(2, 2)),
                                                  int.Parse(InfoList[5].Substring(4, 2)));
                        Info = new Inventory
                        {
                            //Thickness = InfoList[1],日系一般沒有此項資料
                            Widt = InfoList[2],
                            Type = InfoList[6],
                            Prod = InfoList[0],
                            Leng = int.Parse((InfoList[3])),
                            NewWeight = float.Parse(InfoList[4]),
                            SrnmType = sFuncCode,
                            ProductDate = dt,
                            TransactionDate = DateTime.Now,
                            StaffID = sStaffID,
                            ZoneID = sZoneID,
                            ZoneSN = sZoneSN,
                            //Splice = InfoList[5],沒有接頭數
                            CustomerNO = sCustomer,
                            CtlNo1 = sCtlNo1,
                            CtlNo2 = sCtlNo2,
                            Thickness2 = InfoList[1],
                            Ptno = InfoList[7]
                            //特殊記項為,InfoList[8],尚無用到
                        };
                    }
                    else if (InfoList.Count == 9)
                    //else
                    {
                        //設定日期格式
                        DateTime dt = SetDateTime(int.Parse(InfoList[6].Substring(0, 2)) + 2000,
                                                  int.Parse(InfoList[6].Substring(2, 2)),
                                                  int.Parse(InfoList[6].Substring(4, 2)));
                        Info = new Inventory
                        {
                            //Thickness = InfoList[2],
                            //Widt = InfoList[3],
                            //Type = InfoList[9],
                            //Prod = InfoList[1],
                            //Leng = int.Parse((InfoList[4])),
                            //NewWeight = float.Parse(InfoList[5]),
                            //SrnmType = sFuncCode,
                            //ProductDate = dt,
                            //TransactionDate = DateTime.Now,
                            //StaffID = sStaffID,
                            //ZoneID = sZoneID,
                            //ZoneSN = sZoneSN,
                            //Splice = InfoList[6],
                            ////Ptno = InfoList[11]

                            Thickness = InfoList[1],
                            Widt = InfoList[2],
                            Type = InfoList[8],
                            Prod = InfoList[0],
                            Leng = int.Parse((InfoList[3])),
                            NewWeight = float.Parse(InfoList[4]),
                            SrnmType = sFuncCode,
                            ProductDate = dt,
                            TransactionDate = DateTime.Now,
                            StaffID = sStaffID,
                            ZoneID = sZoneID,
                            ZoneSN = sZoneSN,
                            Splice = InfoList[5],
                            CustomerNO = sCustomer,
                            CtlNo1 = sCtlNo1,
                            CtlNo2 = sCtlNo2
                            //Ptno = InfoList[11]
                        };
                    }
                    db.Inventory.Add(Info);
                    db.SaveChanges();
                    //將異動資料寫入歷史記錄資料表
                    var HistoryInfo = new HistoryInventory
                    {
                        Type = Info.Type,
                        Prod = Info.Prod,
                        Thickness = Info.Thickness,
                        Widt = Info.Widt,
                        Leng = Info.Leng,
                        Splice = Info.Splice,
                        Ptno = Info.Ptno,
                        ProductDate = Convert.ToDateTime(Info.ProductDate),
                        CustomerNO = Info.CustomerNO,
                        StaffID = sStaffID,
                        TransactionDate = Convert.ToDateTime(Info.TransactionDate),
                        SrnmType = sFuncCode,
                        NewWeight = Info.NewWeight,
                        ZoneSN = Info.ZoneSN,
                        ZoneID = Info.ZoneID,
                        PackNo = Info.PackNo,
                        Thickness2 = Info.Thickness2
                    };
                    db.HistoryInventory.Add(HistoryInfo);
                    db.SaveChanges();
                    sResult = "true";
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                sResult = ex.ToString();
            };
            return sResult;
        }
Exemple #5
0
        //出庫
        public String IssuanceIntoDB(String sStaffID, String sProd, String sFuncCode)
        {
            String sResult = "";
            try
            {
                //Inventory Info = db.Inventory.Find(ClearInfo.FirstOrDefault().Prod);

                if (db.Inventory.Where(i => i.Prod == sProd).Count() > 0)
                {
                    var Info = db.Inventory.Where(i => i.Prod == sProd).FirstOrDefault();
                    //先刪除庫存資料
                    db.Inventory.Remove(Info);
                    db.SaveChanges();
                    //將異動資料寫入歷史記錄資料表
                    var HistoryInfo = new HistoryInventory
                    {
                        Type = Info.Type,
                        Prod = Info.Prod,
                        Thickness = Info.Thickness,
                        Widt = Info.Widt,
                        Leng = Info.Leng,
                        Splice = Info.Splice,
                        Ptno = Info.Ptno,
                        ProductDate = Convert.ToDateTime(Info.ProductDate),
                        CustomerNO = Info.CustomerNO,
                        StaffID = sStaffID,
                        TransactionDate = Convert.ToDateTime(Info.TransactionDate),
                        SrnmType = sFuncCode,
                        NewWeight = Info.NewWeight,
                        ZoneSN = Info.ZoneSN,
                        ZoneID = Info.ZoneID,
                        PackNo = Info.PackNo,
                        Thickness2 = Info.Thickness2
                    };
                    db.HistoryInventory.Add(HistoryInfo);
                    db.SaveChanges();
                    sResult = "true";
                }
                else
                {
                    sResult = "無"+ sProd +"此筆資料,此筆資料可能已出庫!!";
                }
            }
            catch (Exception ex)
            {
                sResult = ex.ToString();
            }
            return sResult;
        }
 public ActionResult CreateReceiptInfo(IEnumerable<InventoryView> receiptInfo)
 {
     try
     {
         if (ModelState.IsValid)
         {
              //前端使用者輸入庫位名稱,透過此方法取得ZoneID
             //String sZoneID = oDB.GetZoneID(receiptInfo.FirstOrDefault().ZoneNo);
             //寫入庫存table
             var Inventory = new Inventory
             {
                 Type = receiptInfo.FirstOrDefault().Type,
                 Prod = receiptInfo.FirstOrDefault().Prod,
                 Thickness = receiptInfo.FirstOrDefault().Thickness,
                 Widt = receiptInfo.FirstOrDefault().Widt,
                 Leng = receiptInfo.FirstOrDefault().Leng,
                 Splice = receiptInfo.FirstOrDefault().Splice,
                 Ptno = receiptInfo.FirstOrDefault().Ptno,
                 ProductDate = Convert.ToDateTime(receiptInfo.FirstOrDefault().ProductDate),
                 CustomerNO = receiptInfo.FirstOrDefault().CustomerName,//前端客戶名稱欄位用來存放使用者輸入的客戶代碼
                 TransactionDate = Convert.ToDateTime(receiptInfo.FirstOrDefault().TransactionDate),
                 SrnmType = "2",
                 StaffID = receiptInfo.FirstOrDefault().StaffID,
                 NewWeight = receiptInfo.FirstOrDefault().NewWeight,
                 ZoneSN = oDB.MakeSN(),
                 ZoneID = oDB.GetZoneID(receiptInfo.FirstOrDefault().ZoneNo),
                 PackNo = receiptInfo.FirstOrDefault().PackNo,
                 Thickness2 = receiptInfo.FirstOrDefault().Thickness2,
                 CtlNo1 = receiptInfo.FirstOrDefault().CtlNo1,
                 CtlNo2 = receiptInfo.FirstOrDefault().CtlNo2,
             };
             if (TryUpdateModel(Inventory))
             {
                 db.Inventory.Add(Inventory);
                 db.SaveChanges();
             }
             //將資料寫入歷史資料庫
             //oDB.InsertHistoryInfo(Inventory, Session["Account"].ToString(), "2");
             //將資料寫入歷史資料庫
             var HistoryInfo = new HistoryInventory
             {
                 Type = Inventory.Type,
                 Prod = Inventory.Prod,
                 Thickness = Inventory.Thickness,
                 Widt = Inventory.Widt,
                 Leng = Inventory.Leng,
                 Splice = Inventory.Splice,
                 Ptno = Inventory.Ptno,
                 ProductDate = Convert.ToDateTime(Inventory.ProductDate),
                 CustomerNO = Inventory.CustomerNO,
                 TransactionDate = Convert.ToDateTime(Inventory.TransactionDate),
                 SrnmType = "2",
                 StaffID = Inventory.StaffID,
                 NewWeight = Inventory.NewWeight,
                 ZoneSN = Inventory.ZoneSN,
                 ZoneID = Inventory.ZoneID,
                 PackNo = Inventory.PackNo,
                 Thickness2 = Inventory.Thickness2,
                 CtlNo1 = Inventory.CtlNo1,
                 CtlNo2 = Inventory.CtlNo2,
             };
             if (TryUpdateModel(HistoryInfo))
             {
                 db.HistoryInventory.Add(HistoryInfo);
                 db.SaveChanges();
             }
         }
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException ex)
     {
     };
     return Json(null);
 }
        public JsonResult DeleteInfo(IEnumerable<ClearInventoryView> ClearInfo)
        {
            try
            { //需要盤點程序結束的狀態且是ClearInventory有資料的情況下,才能進行盈虧刪除
                if (db.SysPara.Where(r => r.ParaName == "Inventory").FirstOrDefault().ParaValue.Equals("false") && db.ClearInventory.Count() > 0)
                {
                    Inventory Info = db.Inventory.Find(ClearInfo.FirstOrDefault().Prod);
                    ClearInventory Clear_Info = db.ClearInventory.Find(ClearInfo.FirstOrDefault().Prod);
                    if (ModelState.IsValid)
                    {
                        //盤虧刪除
                        //先刪除庫存資料
                        db.Inventory.Remove(Info);
                        //再刪除ClearInventory的資料
                        db.ClearInventory.Remove(Clear_Info);
                        if (TryUpdateModel(Info))
                        {
                            db.SaveChanges();
                        }
                    }
                    //將異動資料寫入歷史記錄資料表
                    var HistoryInfo = new HistoryInventory
                    {
                        Type = Info.Type,
                        Prod = Info.Prod,
                        Thickness = Info.Thickness,
                        Widt = Info.Widt,
                        Leng = Info.Leng,
                        Splice = Info.Splice,
                        Ptno = Info.Ptno,
                        ProductDate = Convert.ToDateTime(Info.ProductDate),
                        CustomerNO = Info.CustomerNO,
                        StaffID = Session["Account"].ToString(),
                        TransactionDate = Convert.ToDateTime(Info.TransactionDate),
                        SrnmType = "5",
                        NewWeight = Info.NewWeight,
                        ZoneSN = Info.ZoneSN,
                        ZoneID = Info.ZoneID,
                        PackNo = Info.PackNo,
                        Thickness2 = Info.Thickness2
                    };
                    db.HistoryInventory.Add(HistoryInfo);
                    db.SaveChanges();
                }

                //當ClearInventory與ImportInventory資料都為0,
                //表示此盤點程序與庫存資料已經核對完畢,則將db的參數改為true
                if (db.ClearInventory.Count() == 0 && db.ImportInventory.Count() == 0)
                {
                    try
                    {
                        if (ModelState.IsValid)
                        {
                            var SysPara = db.SysPara.Where(r => r.ParaName == "Inventory");
                            if (SysPara != null)
                            {
                                SysPara.FirstOrDefault().ParaValue = "true";
                                db.SaveChanges();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    };
                }
            }
            catch(Exception ex)
            {

            }
            return Json(null);
        }