예제 #1
0
        public string Put([FromBody] tbEmployee employee)
        {
            try
            {
                tbEmployee tbEmployee = _db.tbEmployee.Where(b => b.EmployeeNo == employee.EmployeeNo).First();
                tbEmployee.EmployeeName = employee.EmployeeName;


                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return("success");
        }
예제 #2
0
 public string Put([FromBody] ProductInfoes product)
 {
     try
     {
         ProductInfoes productInfoes = _db.ProductInfoes.Where(b => b.ProductNo == product.ProductNo).First();
         productInfoes.Capcity        = Convert.ToInt32(product.Capcity);
         productInfoes.EffectiveMonth = Convert.ToInt32(product.EffectiveMonth);
         productInfoes.EffectiveDay   = Convert.ToInt32(product.EffectiveDay);
         _db.SaveChanges();
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
     return("success");
 }
예제 #3
0
        public string Post([FromBody] List <ProductVendorSettle> listProductVendorSettl)
        {
            try
            {
                string vendorNo = "";
                if (listProductVendorSettl.Count > 0)
                {
                    vendorNo = listProductVendorSettl[0].VendorNo;

                    List <VendorProducts> listVendorProducts = _db.VendorProducts.Where(x => x.VendorNo == vendorNo).ToList();
                    foreach (VendorProducts vendorProducts in listVendorProducts)
                    {
                        _db.VendorProducts.Remove(vendorProducts);
                    }

                    _db.SaveChanges();
                }
                else
                {
                    return("接收設定資料失敗!!");
                }

                foreach (ProductVendorSettle productVendorSettle in listProductVendorSettl)
                {
                    if (productVendorSettle.Manufacture.Equals("1"))
                    {
                        VendorProducts insertVendorProducts = new VendorProducts();
                        insertVendorProducts.VendorNo    = vendorNo;
                        insertVendorProducts.ProductNo   = productVendorSettle.ProductNo;
                        insertVendorProducts.ProductName = productVendorSettle.ProductName;
                        insertVendorProducts.spec        = productVendorSettle.Spec;


                        _db.VendorProducts.Add(insertVendorProducts);
                        _db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return("success");
        }
        public string Post(string InventoryDate, string InventoryNo, string PalletsNo, string CaseNo, string BagNo)
        {
            try
            {
                IEnumerable <InventoryBody> InventoryBag = _db.InventoryBody.Where(e => e.InventoryNo == InventoryNo && e.BagNo == BagNo).AsEnumerable();
                if (InventoryBag.Count() > 0)
                {
                    return("新增失敗,已盤過此袋號!");
                }
                PackingLists PackingLists = _db.PackingLists.Where(e => e.BagNo == BagNo).FirstOrDefault();
                if (PackingLists == null)
                {
                    return("新增失敗,不合法的袋子!");
                }
                PackingLists = _db.PackingLists.Where(e => e.PalletsNo == PalletsNo && e.CaseNo == CaseNo).First();
                InventoryBody InventoryPallets = _db.InventoryBody.Where(e => e.InventoryNo == InventoryNo).FirstOrDefault();
                if (true)
                {
                    InventoryBody Add_Bag = new InventoryBody();
                    Add_Bag.InventoryNo   = InventoryNo;
                    Add_Bag.BagNo         = BagNo;
                    Add_Bag.CaseNo        = CaseNo;
                    Add_Bag.PalletsNo     = PalletsNo;
                    Add_Bag.Lot           = PackingLists.Lot;
                    Add_Bag.StockNo       = InventoryPallets.StockNo;
                    Add_Bag.InventoryDate = DateTime.Now.ToString("yyyyMMdd");
                    Add_Bag.InventoryTime = DateTime.Now.ToString("hhmmss");
                    Add_Bag.InventoryMan  = InventoryPallets.InventoryMan;

                    _db.InventoryBody.Add(Add_Bag);
                    _db.SaveChanges();
                }

                return("success");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
예제 #5
0
        public string Post([FromBody] tbGroup group)
        {
            try
            {
                tbGroup tbGroup = _db.tbGroup.Where(x => x.GroupID == group.GroupID).FirstOrDefault();

                if (tbGroup != null)
                {
                    return("已存在此群組ID!!");
                }



                _db.tbGroup.Add(group);

                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return("success");
        }
예제 #6
0
        public string Put([FromBody] tbEmpGroup empGroup)
        {
            try
            {
                string[]      arrGroupID   = empGroup.GroupID.Split(','); //更改過後的GroupID
                List <string> listDGroupID = new List <string>();         //需要刪除的GroupID
                List <string> listAGroupID = new List <string>();         //需要新增的GroupID

                bool flag = true;

                List <tbEmpGroup> listTbEmpGroup = _db.tbEmpGroup.Where(b => b.EmployeeNo == empGroup.EmployeeNo).ToList();

                //紀錄刪除項目
                foreach (tbEmpGroup mtbEmpGroup in listTbEmpGroup)
                {
                    flag = true;
                    for (int i = 0; i < arrGroupID.Length; i++)
                    {
                        if (mtbEmpGroup.GroupID.Equals(arrGroupID[i]))
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag == true)
                    {
                        listDGroupID.Add(mtbEmpGroup.GroupID);
                    }
                }

                //紀錄新增項目
                for (int i = 0; i < arrGroupID.Length; i++)
                {
                    flag = true;
                    foreach (tbEmpGroup mtbEmpGroup in listTbEmpGroup)
                    {
                        if (arrGroupID[i].Equals(mtbEmpGroup.GroupID))
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag == true)
                    {
                        listAGroupID.Add(arrGroupID[i]);
                    }
                }

                //資料庫刪除
                foreach (string groupID in listDGroupID)
                {
                    tbEmpGroup tbEmpGroup = _db.tbEmpGroup.Where(b => b.EmployeeNo == empGroup.EmployeeNo).Where(c => c.GroupID == groupID).First();
                    _db.tbEmpGroup.Remove(tbEmpGroup);
                }

                //資料庫新增
                foreach (string groupID in listAGroupID)
                {
                    tbEmpGroup tbEmpGroup = new tbEmpGroup();
                    tbEmpGroup.EmployeeNo = empGroup.EmployeeNo;
                    tbEmpGroup.GroupID    = groupID;
                    _db.tbEmpGroup.Add(tbEmpGroup);

                    _db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return("success");
        }
        public string Post(string InventoryDate, string InventoryNo)
        {
            try
            {
                InventoryHead Inventory    = _db.InventoryHead.Where(e => e.InventoryNo == InventoryNo && e.InventoryDate == InventoryDate).FirstOrDefault();
                string        InventoryMan = (from a in _db.InventoryBody.Where(e => e.InventoryNo == InventoryNo) select new { a.InventoryMan }).First().InventoryMan;
                if (Inventory.IsSummary == "N" || Inventory.IsSummary == "0")
                {
                    //應盤項目
                    var Should = (from a in _db.vRecords
                                  join b in (from w in _db.InventoryBody.Where(e => e.InventoryNo == InventoryNo)
                                             group w by new { w.StockNo } into Stock
                                             select new
                    {
                        Stock.Key.StockNo
                    })
                                  on a.WarehouseNo equals b.StockNo
                                  join c in _db.PackingLists
                                  on a.BagNo equals c.BagNo
                                  select new
                    {
                        a.BagNo,
                        c.CaseNo,
                        c.PalletsNo,
                        a.Lot,
                        StockNo = a.WarehouseNo
                    }).Distinct().ToList();
                    //實盤項目
                    var Actual = (from a in _db.InventoryBody.Where(e => e.InventoryNo == InventoryNo)

                                  select new
                    {
                        a.BagNo,
                        a.CaseNo,
                        a.PalletsNo,
                        a.Lot,
                        a.StockNo
                    }).ToList();

                    var Loss = Should.Except(Actual);
                    List <InventoryAdjust> LossAdj = (from a in Loss
                                                      select new InventoryAdjust
                    {
                        InventoryNo = InventoryNo,
                        BagNo = a.BagNo,
                        CaseNo = a.CaseNo,
                        PalletsNo = a.PalletsNo,
                        Lot = a.Lot,
                        StockNo = a.StockNo,
                        OriQty = 1,
                        InventoryQty = 0,
                        AdjQty = 1,
                        InventoryDate = Inventory.InventoryDate,
                        InventoryTime = Inventory.InventoryTime,
                        InventoryMan = InventoryMan
                    }).ToList();

                    var Surplus = Actual.Except(Should);
                    List <InventoryAdjust> SurplusAdj = (from b in Surplus
                                                         select new InventoryAdjust
                    {
                        InventoryNo = InventoryNo,
                        BagNo = b.BagNo,
                        CaseNo = b.CaseNo,
                        PalletsNo = b.PalletsNo,
                        Lot = b.Lot,
                        StockNo = b.StockNo,
                        OriQty = 0,
                        InventoryQty = 1,
                        AdjQty = 1,
                        InventoryDate = Inventory.InventoryDate,
                        InventoryTime = Inventory.InventoryTime,
                        InventoryMan = InventoryMan,
                    }).ToList();
                    using (var dbContextTransaction = _db.Database.BeginTransaction())
                    {
                        try
                        {
                            foreach (InventoryAdjust Insert_loss in LossAdj)
                            {
                                _db.InventoryAdjust.Add(Insert_loss);
                            }
                            foreach (InventoryAdjust Insert_loss in SurplusAdj)
                            {
                                _db.InventoryAdjust.Add(Insert_loss);
                            }
                            Inventory.IsSummary = "Y";
                            _db.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                            return(ex.Message);
                        }
                    }
                }
                else
                {
                    return("盤點底稿-" + InventoryNo + "已彙總,無法再彙總!");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("success");
        }