Esempio n. 1
0
 public ReturnValue SaveSupplier(int id, int type, string name, string person, string phone, string address, bool valid, string remark)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model   = c.Suppliers.FirstOrDefault(p => p.supplierId == id);
             var hadname = c.Suppliers.FirstOrDefault(p => p.type == type && p.supplierName == name);
             if (model == null)
             {
                 #region 添加
                 if (hadname != null)
                 {
                     return new ReturnValue {
                                status = false, message = "名称已存在,不能重复添加"
                     }
                 }
                 ;
                 model              = new Supplier();
                 model.address      = address;
                 model.phone        = phone;
                 model.remark       = remark;
                 model.supplierName = name;
                 model.type         = type;
                 model.person       = person;
                 model.valid        = valid;
                 c.Suppliers.Add(model);
                 #endregion
             }
             else
             {
                 #region 修改
                 if (hadname != null && hadname.supplierId != id)
                 {
                     return new ReturnValue {
                                status = false, message = "同种物料已存在,不能重复添加"
                     }
                 }
                 ;
                 model.address        = address;
                 model.phone          = phone;
                 model.remark         = remark;
                 model.supplierName   = name;
                 model.person         = person;
                 model.valid          = valid;
                 c.Entry(model).State = EntityState.Modified;
                 #endregion
             }
             c.SaveChanges(); return(new ReturnValue {
                 status = true
             });
         }
         catch (Exception ex)
         {
             return(new ReturnValue {
                 status = false, message = "操作失败:" + ex.Message
             });
         }
     }
 }
Esempio n. 2
0
 public ReturnValue SaveDictionary(string type, string key, string value, string lable, string remark)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var m = c.Dictionaries.FirstOrDefault(p => p.dictionaryKey == key);
             if (type == "add")
             {
                 #region 添加
                 if (m != null)
                 {
                     return new ReturnValue {
                                status = false, message = "字典已存在,不能重复添加"
                     }
                 }
                 ;
                 m = new Dictionary();
                 m.dictionaryKey   = key;
                 m.dictionaryLable = lable;
                 m.dictionaryValue = value;
                 m.remark          = remark;
                 c.Dictionaries.Add(m);
                 #endregion
             }
             else if (type == "edit")
             {
                 #region 修改
                 if (m == null)
                 {
                     return new ReturnValue {
                                status = false, message = "字典不存在"
                     }
                 }
                 ;
                 m.dictionaryLable = lable;
                 m.dictionaryValue = value;
                 m.remark          = remark;
                 c.Entry(m).State  = EntityState.Modified;
                 #endregion
             }
             else
             {
                 return new ReturnValue {
                            status = false, message = "操作类别错误"
                 }
             };
             c.SaveChanges(); return(new ReturnValue {
                 status = true
             });
         }
         catch (Exception ex)
         {
             return(new ReturnValue {
                 status = false, message = "操作失败:" + ex.Message
             });
         }
     }
 }
Esempio n. 3
0
        public Customers Add(Customers model)
        {
            db.Customers.Add(model);
            db.SaveChanges();

            return(model);
        }
Esempio n. 4
0
 public ReturnValue SaveDepartment(int id, bool valid, string depName, string phone, string leader, string remark)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model   = c.Departments.FirstOrDefault(p => p.depId == id);
             var hadname = c.Departments.FirstOrDefault(p => p.depName == depName);
             if (model == null)
             {
                 #region 添加
                 if (hadname != null)
                 {
                     return new ReturnValue {
                                status = false, message = "名称已存在,不能重复添加"
                     }
                 }
                 ;
                 model         = new Department();
                 model.depName = depName;
                 model.leader  = leader;
                 model.phone   = phone;
                 model.remark  = remark;
                 model.valid   = valid;
                 c.Departments.Add(model);
                 #endregion
             }
             else
             {
                 #region 修改
                 if (hadname != null && hadname.depId != id)
                 {
                     return new ReturnValue {
                                status = false, message = "名称已存在,不能重复添加"
                     }
                 }
                 ;
                 model.depName        = depName;
                 model.leader         = leader;
                 model.phone          = phone;
                 model.valid          = valid;
                 model.remark         = remark;
                 c.Entry(model).State = EntityState.Modified;
                 #endregion
             }
             c.SaveChanges(); return(new ReturnValue {
                 status = true
             });
         }
         catch (Exception ex)
         {
             return(new ReturnValue {
                 status = false, message = "操作失败:" + ex.Message
             });
         }
     }
 }
Esempio n. 5
0
 public bool SaveRoleFunction(int role, string[] add, string[] delete)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             #region 添加
             foreach (var item in add)
             {
                 if (item == "")
                 {
                     continue;
                 }
                 var ha = c.FunctionRights.FirstOrDefault(p => p.roleSn == role && p.functionNo == item);
                 if (ha == null)
                 {
                     FunctionRight r = new FunctionRight();
                     r.functionNo = item;
                     r.roleSn     = role;
                     c.FunctionRights.Add(r);
                 }
             }
             c.SaveChanges();
             #endregion
             #region  除
             foreach (var item in delete)
             {
                 var ha = c.FunctionRights.FirstOrDefault(p => p.roleSn == role && p.functionNo == item);
                 if (ha != null)
                 {
                     c.FunctionRights.Remove(ha);
                 }
             }
             c.SaveChanges();
             #endregion
             return(true);
         }
         catch
         { return(false); }
     }
 }
Esempio n. 6
0
        public ParkingService(InvoicingContext context)
        {
            _context = context;

            if (_context.Parkings.Count() == 0)
            {
                _context.Parkings.Add(new Parking {
                    Name = "Parking one"
                });
                _context.SaveChanges();
            }
        }
Esempio n. 7
0
        public ReturnValue SaveRole(int id, string name, string remark, bool price)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model   = c.Roles.FirstOrDefault(p => p.roleSn == id);
                    var hadname = c.Roles.FirstOrDefault(p => p.roleName == name);
                    if (model == null)
                    {
                        #region 添加
                        if (hadname != null)
                        {
                            return new ReturnValue {
                                       status = false, message = "角色已存在,不能重复添加"
                            }
                        }
                        ;

                        model          = new Role();
                        model.remark   = remark;
                        model.roleName = name; model.showPrice = price;
                        c.Roles.Add(model);
                        #endregion
                    }
                    else
                    {
                        #region 修改
                        if (hadname != null && hadname.roleSn != id)
                        {
                            return new ReturnValue {
                                       status = false, message = "角色已存在,不能重复添加"
                            }
                        }
                        ;
                        model.remark         = remark;
                        model.roleName       = name; model.showPrice = price;
                        c.Entry(model).State = EntityState.Modified;
                        #endregion
                    }
                    c.SaveChanges(); return(new ReturnValue {
                        status = true
                    });
                }
                catch (Exception ex)
                {
                    return(new ReturnValue {
                        status = false, message = "操作失败:" + ex.Message
                    });
                }
            }
        }
Esempio n. 8
0
 public CustomerService(InvoicingContext context)
 {
     _context = context;
     if (_context.Customers.Count() == 0)
     {
         _context.Customers.Add(new Customer {
             Name = "Regular Customer", Type = CustomerType.regular
         });
         _context.Customers.Add(new Customer {
             Name = "Premium Customer", Type = CustomerType.premium
         });
         _context.SaveChanges();
     }
 }
Esempio n. 9
0
 public bool SaveChanges()
 {
     try
     {
         _invoicingContext.SaveChanges();
         return(true);
     }
     catch
     {
         // Something went wrong
         _invoicingContext.Dispose();
         return(false);
     }
 }
Esempio n. 10
0
 public bool SaveSendMessage(MsgSend send)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             c.MsgSends.Add(send);
             c.SaveChanges(); return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
     }
 }
Esempio n. 11
0
 public bool ChangeEmployeeStatus(int id, bool status)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model = c.Employees.FirstOrDefault(p => p.staffId == id);
             model.status = status;
             c.SaveChanges(); return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Esempio n. 12
0
 public bool DeleteRequire(string no)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var r = c.PurchaseRequires.FirstOrDefault(p => p.requireNo == no);
             if (r != null)
             {
                 var list = c.PurchaseRequireDetails.Where(p => p.requireNo == no);
                 if (list != null)
                 {
                     foreach (var item in list)
                     {
                         c.PurchaseRequireDetails.Remove(item);
                     }
                 }
                 #region 如果是自动生成,则原订单可再次申请
                 var order = c.BomOrders.FirstOrDefault(p => p.bomOrderNo == r.bomOrderNo);
                 if (order != null)
                 {
                     var orderdetail = c.BomOrderDetails.Where(p => p.bomOrderNo == order.bomOrderNo).ToList();
                     if (orderdetail != null)
                     {
                         foreach (var item in orderdetail)
                         {
                             item.hadRequire     = false;
                             c.Entry(item).State = EntityState.Modified;
                         }
                     }
                 }
                 #endregion
                 c.PurchaseRequires.Remove(r);
                 c.SaveChanges();
                 return(true);
             }
             return(false);
         }
         catch
         {
             return(false);
         }
     }
 }
Esempio n. 13
0
        public bool ChangeBillStatus(string no, int status, int staff)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model = c.BillCosts.FirstOrDefault(p => p.billNo == no);
                    if (status == -1)
                    {
                        model.status   = 4;
                        model.checkRes = false;
                    }
                    else
                    {
                        if (model.status == 0)
                        {
                            model.status = 1;

                            model.checkRes = true;
                        }
                        else if (model.status == 1)
                        {
                            model.status   = 0;
                            model.checkRes = false;
                        }
                        else if (model.status == 4)
                        {
                            model.status = 0;

                            model.checkRes = false;
                        }
                    }
                    model.staffCheck     = staff;
                    c.Entry(model).State = EntityState.Modified;
                    c.SaveChanges();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
Esempio n. 14
0
 public bool DeleteReturn(string no)
 {
     using (var c = new InvoicingContext())
     {
         var model = c.PurchaseReturns.FirstOrDefault(p => p.returnNo == no);
         if (model != null)
         {
             var details = c.PurchaseReturnDetails.Where(p => p.returnNo == no);
             foreach (var item in details)
             {
                 c.PurchaseReturnDetails.Remove(item);
             }
             c.PurchaseReturns.Remove(model);
             c.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Esempio n. 15
0
 public ReturnValue DeleteDictionary(string key)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model = c.Dictionaries.FirstOrDefault(p => p.dictionaryKey == key);
             c.Dictionaries.Remove(model);
             c.SaveChanges(); return(new ReturnValue {
                 status = true
             });
         }
         catch (Exception ex)
         {
             return(new ReturnValue {
                 status = false, message = "操作失败:" + ex.Message
             });
         }
     }
 }
Esempio n. 16
0
 public ReturnValue DeleteMaterial(string no)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model = c.Materials.FirstOrDefault(p => p.materialNo == no);
             c.Materials.Remove(model);
             c.SaveChanges(); return(new ReturnValue {
                 status = true
             });
         }
         catch (Exception ex)
         {
             return(new ReturnValue {
                 status = false, message = "操作失败:" + ex.Message
             });
         }
     }
 }
Esempio n. 17
0
 public ReturnValue DeleteRole(int id)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model = c.Roles.FirstOrDefault(p => p.roleSn == id);
             c.Roles.Remove(model);
             c.SaveChanges(); return(new ReturnValue {
                 status = true
             });
         }
         catch (Exception ex)
         {
             return(new ReturnValue {
                 status = false, message = "操作失败:" + ex.Message
             });
         }
     }
 }
Esempio n. 18
0
 public ReturnValue UpdatePwd(int staff, string oldpwd, string newpwd)
 {
     using (var c = new InvoicingContext())
     {
         var model = c.Employees.FirstOrDefault(p => p.staffId == staff);
         if (model == null)
         {
             return new ReturnValue {
                        status = false, message = "用户不存在"
             }
         }
         ;
         if (model.isUser == false)
         {
             return new ReturnValue {
                        status = false, message = "该员工为非系统用户"
             }
         }
         ;
         if (!model.status)
         {
             return new ReturnValue {
                        status = false, message = "该用户已被锁定"
             }
         }
         ;
         if (model.userPwd.ToLower() != oldpwd.ToLower())
         {
             return new ReturnValue {
                        status = false, message = "旧密码输入错误"
             }
         }
         ;
         model.userPwd        = newpwd;
         c.Entry(model).State = EntityState.Modified;
         c.SaveChanges();
         return(new ReturnValue {
             status = true, message = ""
         });
     }
 }
Esempio n. 19
0
 public ReturnValue SetUser(int id, bool isuer, string userid, string pwd, int role, bool valid, string remark, int utype)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model = c.Employees.FirstOrDefault(p => p.staffId == id);
             if (model == null)
             {
                 return new ReturnValue {
                            status = false, message = "员工不存在"
                 }
             }
             ;
             model.isUser = isuer;
             model.userId = userid;
             model.status = valid;
             model.remark = remark; model.rigthType = utype;
             if (pwd != "")
             {
                 model.userPwd = pwd;
             }
             if (role != 0)
             {
                 model.roleSn = role;
             }
             c.Entry(model).State = EntityState.Modified;
             c.SaveChanges();
             return(new ReturnValue {
                 status = true
             });
         }
         catch (Exception ex)
         {
             return(new ReturnValue {
                 status = false, message = "操作失败:" + ex.Message
             });
         }
     }
 }
Esempio n. 20
0
        public bool ChangeRequireStatus(string no, int status, string checkstaff)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model = c.PurchaseRequires.FirstOrDefault(p => p.requireNo == no);
                    if (status == -1)
                    {
                        model.status     = 4;
                        model.checkStaff = checkstaff;
                    }
                    else
                    {
                        if (model.status == 0)
                        {
                            model.status = 1;
                        }
                        else if (model.status == 1)
                        {
                            model.status = 0;
                        }
                        else if (model.status == 4)
                        {
                            model.status = 0;
                        }

                        model.checkStaff = checkstaff;
                    }
                    c.Entry(model).State = EntityState.Modified;
                    c.SaveChanges();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
Esempio n. 21
0
 public bool ChangeSettleStatus(string no, int status, int staff)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model  = c.Settlements.FirstOrDefault(p => p.settleNo == no);
             var person = c.Employees.FirstOrDefault(p => p.staffId == staff);
             if (status == -1)
             {
                 model.status = 4;
             }
             else
             {
                 if (model.status == 0)
                 {
                     model.status = 1;
                 }
                 else if (model.status == 1)
                 {
                     model.status = 0;
                 }
                 else if (model.status == 4)
                 {
                     model.status = 0;
                 }
             }
             model.checkStaff     = person != null ? person.staffName : "";
             model.checkDate      = DateTime.Now;
             c.Entry(model).State = EntityState.Modified;
             c.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Esempio n. 22
0
        public Parked Create(ParkedDTO parkedDTO)
        {
            Customer customer = _context.Customers.FirstOrDefault(c => c.Id == parkedDTO.customerId);
            Parking  parking  = _context.Parkings.FirstOrDefault(p => p.Id == parkedDTO.parkingId);

            if (customer == null || parking == null)
            {
                throw new Exception("You need to provide valid customerId and parkingId to create a Parked item.");
            }
            else if (parkedDTO.inTime > parkedDTO.outTime)
            {
                throw new Exception("'Date Out' have to be greater than 'Date In'.");
            }

            Parked parked = new Parked();

            parked.Customer = customer;
            parked.Parking  = parking;
            parked.inTime   = parkedDTO.inTime;
            parked.outTime  = parkedDTO.outTime;

            TimeSpan timeSpent = parked.outTime - parked.inTime;
            int      halfHours = (int)Math.Ceiling(timeSpent.TotalMinutes / 30);

            if (parked.inTime.Hour >= 7 && parked.inTime.Hour < 19)
            {
                parked.Value = customer.Type == 0 ? halfHours * 1.5 : halfHours;
            }
            else
            {
                parked.Value = customer.Type == 0 ? halfHours : halfHours * 0.75;
            }

            _context.Parkeds.Add(parked);
            _context.SaveChanges();

            return(parked);
        }
Esempio n. 23
0
        public bool DeletePurchase(string no)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var r = c.Purchases.FirstOrDefault(p => p.purchaseNo == no);
                    if (r != null)
                    {
                        var list = c.PurchaseDetails.Where(p => p.purchaseNo == no);

                        if (list != null)
                        {
                            foreach (var item in list)
                            {
                                //var require = c.PurchaseRequireDetails.FirstOrDefault(p => p.detailSn == item.requireDetailSn);
                                //if (require!=null)
                                //{
                                //    require.buyAmount -= item.poAmount;
                                //    c.Entry(require).State = EntityState.Modified;
                                //}
                                c.PurchaseDetails.Remove(item);
                            }
                        }
                        c.Purchases.Remove(r);
                        c.SaveChanges();
                        return(true);
                    }
                    return(false);
                }
                catch
                {
                    return(false);
                }
            }
        }
Esempio n. 24
0
 public Customer Create(Customer customer)
 {
     _context.Customers.Add(customer);
     _context.SaveChanges();
     return(customer);
 }
Esempio n. 25
0
        public ReturnValue SaveRequirDetail(string no, List <PurchaseRequireDetailModel> list, string remark)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model = c.PurchaseRequires.FirstOrDefault(p => p.requireNo == no && p.status == 0);
                    if (model == null)
                    {
                        return new ReturnValue {
                                   status = false, message = "不存在申请单"
                        }
                    }
                    ;
                    if (list == null || list.Count < 1)
                    {
                        return new ReturnValue {
                                   status = false, message = "不存在申请单"
                        }
                    }
                    ;
                    foreach (var item in list)
                    {
                        if (item.type == "")
                        {
                            continue;
                        }

                        if (item.type == "delete")
                        {
                            var d = c.PurchaseRequireDetails.FirstOrDefault(p => p.detailSn == item.detailSn);
                            if (d != null)
                            {
                                c.PurchaseRequireDetails.Remove(d);
                            }
                        }
                        else if (item.type == "edit")
                        {
                            var d = c.PurchaseRequireDetails.FirstOrDefault(p => p.detailSn == item.detailSn);
                            if (d != null)
                            {
                                d.materialNo     = item.materialNo;
                                d.orderAmount    = item.orderAmount;
                                d.remark         = item.remark;
                                d.createDate     = item.needdate;
                                c.Entry(d).State = EntityState.Modified;
                            }
                        }
                        else if (item.type == "add")
                        {
                            PurchaseRequireDetail d = new PurchaseRequireDetail();
                            d.materialNo  = item.materialNo;
                            d.orderAmount = item.orderAmount;
                            d.buyAmount   = 0;
                            d.requireNo   = no;
                            d.remark      = item.remark;
                            d.createDate  = item.needdate;
                            c.PurchaseRequireDetails.Add(d);
                        }
                    }
                    #region 申请单
                    if (model.remark != remark)
                    {
                        model.remark = remark;

                        c.Entry(model).State = EntityState.Modified;
                    }
                    #endregion
                    c.SaveChanges(); return(new ReturnValue {
                        status = true, message = ""
                    });
                }
                catch (Exception ex)
                {
                    return(new ReturnValue {
                        status = false, message = "保存失败:" + ex.Message
                    });
                }
            }
        }
Esempio n. 26
0
        public ReturnValue ChangeReturnStatus(string no, int status, string checkstaff)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model  = c.PurchaseReturns.FirstOrDefault(p => p.returnNo == no);
                    var detail = c.PurchaseReturnDetails.Where(p => p.returnNo == no);
                    if (status == -1)
                    {
                        if (model.status == 1)
                        {
                            foreach (var item in detail)
                            {
                                #region 从审核通过到作废,采购明细数量回去,入库明细数量回去,库存回去
                                var depot = c.DepotDetails.FirstOrDefault(p => p.depotId == item.depotId && p.materialNo == item.materialNo);
                                if (depot != null)
                                {
                                    depot.depotAmount   += item.returnAmount;
                                    c.Entry(depot).State = EntityState.Modified;
                                }
                                var stock = c.StockInDetails.FirstOrDefault(p => p.detailSn == item.stockinDetailSn);
                                if (stock != null)
                                {
                                    stock.returnAmount  -= item.returnAmount;
                                    c.Entry(stock).State = EntityState.Modified;
                                }
                                var orderdetail = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.purchaseDetailSn);
                                if (orderdetail != null)
                                {
                                    orderdetail.poRemain     -= item.returnAmount;
                                    orderdetail.returnAmount -= item.returnAmount;
                                }
                                #endregion
                            }
                        }
                        model.status     = 4;
                        model.checkStaff = checkstaff;
                    }
                    else
                    {
                        if (model.status == 0)
                        {
                            model.status     = 1;
                            model.checkStaff = checkstaff;
                            foreach (var item in detail)
                            {
                                #region 审核通过
                                var depot = c.DepotDetails.FirstOrDefault(p => p.depotId == item.depotId && p.materialNo == item.materialNo);
                                if (depot != null)
                                {
                                    depot.depotAmount   -= item.returnAmount;
                                    c.Entry(depot).State = EntityState.Modified;
                                }
                                var stock = c.StockInDetails.FirstOrDefault(p => p.detailSn == item.stockinDetailSn);
                                if (stock != null)
                                {
                                    stock.returnAmount  += item.returnAmount;
                                    c.Entry(stock).State = EntityState.Modified;
                                }
                                var orderdetail = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.purchaseDetailSn);
                                if (orderdetail != null)
                                {
                                    orderdetail.poRemain     += item.returnAmount;
                                    orderdetail.returnAmount += item.returnAmount;
                                }
                                #endregion
                            }
                        }
                        else if (model.status == 1)
                        {
                            model.status     = 0;
                            model.checkStaff = checkstaff;
                            foreach (var item in detail)
                            {
                                #region 从审核通过到返审,采购明细数量回去,入库明细数量回去,库存回去
                                var depot = c.DepotDetails.FirstOrDefault(p => p.depotId == item.depotId && p.materialNo == item.materialNo);
                                if (depot != null)
                                {
                                    depot.depotAmount   += item.returnAmount;
                                    c.Entry(depot).State = EntityState.Modified;
                                }
                                var stock = c.StockInDetails.FirstOrDefault(p => p.detailSn == item.stockinDetailSn);
                                if (stock != null)
                                {
                                    stock.returnAmount  -= item.returnAmount;
                                    c.Entry(stock).State = EntityState.Modified;
                                }
                                var orderdetail = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.purchaseDetailSn);
                                if (orderdetail != null)
                                {
                                    orderdetail.poRemain     -= item.returnAmount;
                                    orderdetail.returnAmount -= item.returnAmount;
                                }
                                #endregion
                            }
                        }
                        else if (model.status == 4)
                        {
                            model.status     = 0;
                            model.checkStaff = checkstaff;
                        }
                    }
                    c.Entry(model).State = EntityState.Modified;
                    c.SaveChanges();

                    #region 更新采购单是否完工
                    List <string> hadno = new List <string>();
                    foreach (var item in detail)
                    {
                        if (hadno.Contains(item.stockinNo))
                        {
                            continue;
                        }
                        hadno.Add(item.stockinNo);
                        SqlParameter[] sqlparams = new SqlParameter[1];
                        sqlparams[0] = new SqlParameter("@stockinno", item.stockinNo);
                        var result = (from p in c.Purchases.SqlQuery(" exec usp_over_purchase @stockinno", sqlparams) select p).ToList();
                        c.SaveChanges();
                    }
                    #endregion

                    return(new ReturnValue {
                        status = true
                    });
                }
                catch (Exception ex)
                {
                    return(new ReturnValue {
                        message = "操作失败:" + ex.Message, status = false
                    });
                }
            }
        }
Esempio n. 27
0
        public ReturnValue SavePurchaseDetail2(string no, List <PurchaseDetailModel> list, int supplier, string remark)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model = c.Purchases.FirstOrDefault(p => p.purchaseNo == no && p.status == 0);
                    if (model == null)
                    {
                        return new ReturnValue {
                                   status = false, message = "不存在采购单"
                        }
                    }
                    ;
                    if (list == null || list.Count < 1)
                    {
                        return new ReturnValue {
                                   status = false, message = "不存在采购单"
                        }
                    }
                    ;
                    double amount = model.totalAmount;
                    double cost   = model.totalCost;
                    foreach (var item in list)
                    {
                        if (item.type == "")
                        {
                            continue;
                        }

                        //var require = c.PurchaseRequireDetails.FirstOrDefault(p => p.detailSn == item.requireDetailSn);
                        //if (require == null) continue;


                        if (item.type == "delete")
                        {
                            var d = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.detailSn);
                            if (d != null)
                            {
                                amount -= d.poAmount;
                                cost   -= d.poAmount * d.poPrice;
                                //require.buyAmount -= d.poAmount;
                                c.PurchaseDetails.Remove(d);
                            }
                        }
                        else if (item.type == "edit")
                        {
                            var d = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.detailSn);
                            if (d != null)
                            {
                                d.materialNo = item.materialNo;
                                amount      += item.poAmount - d.poAmount;
                                cost        -= d.poAmount * d.poPrice;
                                cost        += item.poAmount * item.poPrice;
                                d.poPrice    = item.poPrice;
                                var hadpo = d.poAmount; //原有采购数量
                                d.poRemain = item.poRemain + (item.poAmount - d.poAmount);
                                d.poAmount = item.poAmount;
                                d.sendDate = item.sendDate;
                                d.remark   = item.remark;
                                //require.buyAmount = (require.buyAmount - hadpo + item.poAmount);

                                c.Entry(d).State = EntityState.Modified;
                            }
                        }
                        else if (item.type == "add")
                        {
                            PurchaseDetail d = new PurchaseDetail();
                            d.materialNo      = item.materialNo;
                            d.poAmount        = item.poAmount;
                            d.poPrice         = item.poPrice;
                            d.poRemain        = item.poAmount;
                            d.purchaseNo      = no;
                            amount           += item.poAmount;
                            cost             += item.poAmount * item.poPrice;
                            d.requireDetailSn = item.requireDetailSn;
                            d.requireNo       = item.requireNo;
                            d.sendDate        = item.sendDate;
                            d.remark          = item.remark;
                            //require.buyAmount += item.poAmount;

                            c.PurchaseDetails.Add(d);
                        }
                        //c.Entry(require).State = EntityState.Modified;
                    }
                    #region 申请单
                    model.supplierId     = supplier;
                    model.remark         = remark;
                    model.totalCost      = cost;
                    model.totalAmount    = amount;
                    c.Entry(model).State = EntityState.Modified;

                    #endregion
                    c.SaveChanges(); return(new ReturnValue {
                        status = true, message = ""
                    });
                }
                catch (Exception ex)
                {
                    return(new ReturnValue {
                        status = false, message = "保存失败:" + ex.Message
                    });
                }
            }
        }
Esempio n. 28
0
        public ReturnValue SaveReturnDetail(string no, List <ReturnDetailModel> list, int supplier, string remark, string deport)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model = c.PurchaseReturns.FirstOrDefault(p => p.returnNo == no && p.status == 0);
                    if (model == null)
                    {
                        return new ReturnValue {
                                   status = false, message = "不存在采购退单"
                        }
                    }
                    ;
                    if (list == null || list.Count < 1)
                    {
                        return new ReturnValue {
                                   status = false, message = "不存在采购退单"
                        }
                    }
                    ;
                    foreach (var item in list)
                    {
                        if (item.type == "")
                        {
                            continue;
                        }

                        if (item.type == "delete")
                        {
                            var d = c.PurchaseReturnDetails.FirstOrDefault(p => p.detailSn == item.returnSn);
                            if (d != null)
                            {
                                c.PurchaseReturnDetails.Remove(d);
                            }
                        }
                        else if (item.type == "edit")
                        {
                            var d = c.PurchaseReturnDetails.FirstOrDefault(p => p.detailSn == item.returnSn);
                            if (d != null)
                            {
                                d.materialNo     = item.materialNo;
                                d.returnAmount   = item.returnAmount;
                                d.remark         = item.remark;
                                d.depotId        = item.depotId;
                                c.Entry(d).State = EntityState.Modified;
                            }
                        }
                        else if (item.type == "add")
                        {
                            PurchaseReturnDetail d = new PurchaseReturnDetail();
                            var order = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.purchaseDetailSn);
                            //var stockin = c.StockInDetails.FirstOrDefault(p => p.detailSn == item.stockinDetailSn);
                            //stockin.returnAmount += item.returnAmount;
                            d.materialNo       = item.materialNo;
                            d.returnAmount     = item.returnAmount;
                            d.returnNo         = no;
                            d.depotId          = item.depotId;
                            d.remark           = item.remark;
                            d.buyPrice         = order.poPrice;
                            d.purchaseDetailSn = item.purchaseDetailSn;
                            d.purchaseNo       = item.purchaseNo;
                            d.stockinDetailSn  = item.stockinDetailSn;
                            d.stockinNo        = item.stockinNo;
                            c.PurchaseReturnDetails.Add(d);
                        }
                    }
                    #region 申请单
                    if (model.remark != remark || model.deportStaff != deport)
                    {
                        model.remark = remark;

                        model.deportStaff    = deport;
                        c.Entry(model).State = EntityState.Modified;
                    }
                    #endregion
                    c.SaveChanges(); return(new ReturnValue {
                        status = true, message = ""
                    });
                }
                catch (Exception ex)
                {
                    return(new ReturnValue {
                        status = false, message = "保存失败:" + ex.Message
                    });
                }
            }
        }
Esempio n. 29
0
        public bool ChangeStockInStatus(string no, int status, string checkstaff)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model  = c.StockIns.FirstOrDefault(p => p.stockInNo == no);
                    var detail = c.StockInDetails.Where(p => p.stockinNo == no);
                    if (status == -1)
                    {
                        if (model.status == 1)
                        {
                            foreach (var item in detail)
                            {
                                #region 审核通过 作废,吐出库存
                                var depot = c.DepotDetails.FirstOrDefault(p => p.depotId == item.depotId && p.materialNo == item.materialNo);
                                if (depot != null)
                                {
                                    depot.depotAmount   -= (item.inAmount - item.returnAmount);
                                    c.Entry(depot).State = EntityState.Modified;
                                }
                                #endregion

                                #region 采购单入库,对应采购单未完工,加回未入库数量
                                if (item.purchaseDetailSn > 0)
                                {
                                    var purchasedetail = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.purchaseDetailSn);
                                    if (purchasedetail != null)
                                    {
                                        purchasedetail.poRemain += (item.inAmount - item.returnAmount);
                                    }
                                }
                                #endregion
                            }
                        }
                        model.checkStaff = checkstaff;
                        model.status     = 4;
                    }
                    else
                    {
                        if (model.status == 0)
                        {
                            model.status     = 1;
                            model.checkStaff = checkstaff;
                            foreach (var item in detail)
                            {
                                #region 审核通过 ,加入出库存
                                var depot = c.DepotDetails.FirstOrDefault(p => p.depotId == item.depotId && p.materialNo == item.materialNo);
                                if (depot != null)
                                {
                                    depot.depotAmount   += (item.inAmount - item.returnAmount);
                                    c.Entry(depot).State = EntityState.Modified;
                                }
                                else
                                {
                                    DepotDetail newdepot = new DepotDetail();
                                    newdepot.depotAmount = (item.inAmount - item.returnAmount);
                                    newdepot.depotId     = item.depotId;
                                    newdepot.depotSafe   = item.inAmount;
                                    newdepot.materialNo  = item.materialNo;
                                    c.DepotDetails.Add(newdepot);
                                }
                                #endregion

                                #region 采购单入库,对应采购单加上入库数量
                                if (item.purchaseDetailSn > 0)
                                {
                                    var purchasedetail = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.purchaseDetailSn);
                                    if (purchasedetail != null)
                                    {
                                        purchasedetail.poRemain -= (item.inAmount - item.returnAmount);
                                        if (purchasedetail.poRemain < 0)
                                        {
                                            return(false);
                                        }
                                        if (purchasedetail.returnAmount > 0)
                                        {
                                            purchasedetail.returnAmount -= (item.inAmount - item.returnAmount);
                                        }
                                    }
                                }
                                #endregion
                            }
                        }
                        else if (model.status == 1)
                        {
                            model.status     = 0;
                            model.checkStaff = checkstaff;
                            foreach (var item in detail)
                            {
                                #region 返审,吐出库存
                                var depot = c.DepotDetails.FirstOrDefault(p => p.depotId == item.depotId && p.materialNo == item.materialNo);
                                if (depot != null)
                                {
                                    depot.depotAmount   -= (item.inAmount - item.returnAmount);
                                    c.Entry(depot).State = EntityState.Modified;
                                }
                                #endregion

                                #region 采购单入库,对应采购单未完工,加回未入库数量
                                if (item.purchaseDetailSn > 0)
                                {
                                    var purchasedetail = c.PurchaseDetails.FirstOrDefault(p => p.detailSn == item.purchaseDetailSn);
                                    if (purchasedetail != null)
                                    {
                                        purchasedetail.poRemain += (item.inAmount - item.returnAmount);
                                    }
                                }
                                #endregion
                            }
                        }
                        else if (model.status == 4)
                        {
                            model.checkStaff = checkstaff; model.status = 0;
                        }
                    }
                    c.Entry(model).State = EntityState.Modified;
                    c.SaveChanges();

                    #region 更新采购单是否完工
                    SqlParameter[] sqlparams = new SqlParameter[1];
                    sqlparams[0] = new SqlParameter("@stockinno", no);
                    var result = (from p in c.Purchases.SqlQuery(" exec usp_over_purchase @stockinno", sqlparams) select p).ToList();
                    c.SaveChanges();
                    #endregion

                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
Esempio n. 30
0
        public bool ChangePurchaseStatus(string no, int status, string checkstaff)
        {
            using (var c = new InvoicingContext())
            {
                try
                {
                    var model = c.Purchases.FirstOrDefault(p => p.purchaseNo == no);
                    if (status == -1)
                    {
                        if (model.status == 1 && model.type == 1)
                        {
                            #region 审核通过 作废,更新申请单采购数量
                            var detail = c.PurchaseDetails.Where(p => p.purchaseNo == no);
                            foreach (var item in detail)
                            {
                                var require = c.PurchaseRequireDetails.FirstOrDefault(p => p.detailSn == item.requireDetailSn);
                                if (require == null)
                                {
                                    continue;
                                }
                                require.buyAmount     -= item.poAmount;
                                c.Entry(require).State = EntityState.Modified;
                            }

                            #endregion
                        }
                        model.status     = 4;
                        model.checkStaff = checkstaff;
                    }
                    else
                    {
                        if (model.status == 0)
                        {
                            model.status     = 1;
                            model.checkStaff = checkstaff;
                            #region 审核通过,更新申请单采购数量
                            if (model.type == 1)
                            {
                                var detail = c.PurchaseDetails.Where(p => p.purchaseNo == no);
                                foreach (var item in detail)
                                {
                                    var require = c.PurchaseRequireDetails.FirstOrDefault(p => p.detailSn == item.requireDetailSn);
                                    if (require == null)
                                    {
                                        continue;
                                    }
                                    require.buyAmount     += item.poAmount;
                                    c.Entry(require).State = EntityState.Modified;
                                }
                            }
                            #endregion
                        }
                        else if (model.status == 1)
                        {
                            model.status     = 0;
                            model.checkStaff = checkstaff;
                            #region 返审,更新申请单采购数量
                            if (model.type == 1)
                            {
                                var detail = c.PurchaseDetails.Where(p => p.purchaseNo == no);
                                foreach (var item in detail)
                                {
                                    var require = c.PurchaseRequireDetails.FirstOrDefault(p => p.detailSn == item.requireDetailSn);
                                    if (require == null)
                                    {
                                        continue;
                                    }
                                    require.buyAmount     -= item.poAmount;
                                    c.Entry(require).State = EntityState.Modified;
                                }
                            }
                            #endregion
                        }
                        else if (model.status == 4)
                        {
                            model.checkStaff = checkstaff; model.status = 0;
                        }
                    }
                    c.Entry(model).State = EntityState.Modified;
                    c.SaveChanges();

                    #region 更新申请单是否完工
                    SqlParameter[] sqlparams = new SqlParameter[1];
                    sqlparams[0] = new SqlParameter("@purchaseno", no);
                    var result = (from p in c.Purchases.SqlQuery(" exec usp_over_purchaseRequire @purchaseno", sqlparams) select p).ToList();
                    c.SaveChanges();
                    #endregion

                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }