Example #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
             });
         }
     }
 }
Example #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
             });
         }
     }
 }
Example #3
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
             });
         }
     }
 }
Example #4
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
                    });
                }
            }
        }
Example #5
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);
         }
     }
 }
Example #6
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);
                }
            }
        }
Example #7
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 = ""
         });
     }
 }
Example #8
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
             });
         }
     }
 }
Example #9
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);
                }
            }
        }
Example #10
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);
         }
     }
 }
Example #11
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);
                }
            }
        }
Example #12
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);
                }
            }
        }
Example #13
0
 public ReturnValue SaveMaterial(string type, string fix, string no, bool valid, string name, string bigcate, string category, string model, string unit, string orderno, string remark, string fastcode, string pinyin, string tunumber, int xslength)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var m  = c.Materials.FirstOrDefault(p => p.materialNo == no);
             var mn = c.Materials.FirstOrDefault(p => p.materialName == name && p.materialModel == model);
             if (tunumber == null)
             {
                 tunumber = "";
             }
             if (type == "add")
             {
                 #region 添加
                 var ht = c.Materials.FirstOrDefault(p => p.tunumber == tunumber && p.tunumber != "");
                 if (ht != null)
                 {
                     return new ReturnValue {
                                status = false, message = "物料已存在,不能重复添加!"
                     }
                 }
                 ;
                 if (m != null || mn != null)
                 {
                     return new ReturnValue {
                                status = false, message = "物料已存在,不能重复添加"
                     }
                 }
                 ;
                 m               = new Material();
                 m.category      = category;
                 m.bigcate       = bigcate;
                 m.materialModel = model;
                 m.materialName  = name;
                 m.materialNo    = GetNewNo(fix);// no;
                 m.orderNo       = orderno;
                 m.remark        = remark;
                 m.unit          = unit;
                 m.valid         = valid;
                 m.pinyin        = pinyin;
                 m.fastcode      = fastcode;
                 m.tunumber      = tunumber; m.xslength = xslength;
                 c.Materials.Add(m);
                 #endregion
             }
             else if (type == "edit")
             {
                 #region 修改
                 if (mn != null && m.materialNo != mn.materialNo)
                 {
                     return new ReturnValue {
                                status = false, message = "物料已存在,不能重复添加"
                     }
                 }
                 ;
                 var ht = c.Materials.FirstOrDefault(p => p.tunumber == tunumber && p.tunumber != "" && m.materialNo != p.materialNo);
                 if (ht != null)
                 {
                     return new ReturnValue {
                                status = false, message = "物料已存在,不能重复添加!"
                     }
                 }
                 ;
                 m.category       = category;
                 m.bigcate        = bigcate;
                 m.materialModel  = model;
                 m.materialName   = name;
                 m.orderNo        = orderno;
                 m.remark         = remark;
                 m.unit           = unit; m.valid = valid; m.xslength = xslength;
                 m.pinyin         = pinyin;
                 m.fastcode       = fastcode;
                 m.tunumber       = tunumber;
                 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
             });
         }
     }
 }
Example #14
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
                    });
                }
            }
        }
Example #15
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
                    });
                }
            }
        }
Example #16
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
                    });
                }
            }
        }
Example #17
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
                    });
                }
            }
        }
Example #18
0
 public ReturnValue SaveEmployee(int id, int depId, string name, string mobile, string email, string duty, bool valid, string remark)
 {
     using (var c = new InvoicingContext())
     {
         try
         {
             var model   = c.Employees.FirstOrDefault(p => p.staffId == id);
             var hadname = c.Employees.FirstOrDefault(p => p.staffName == name);
             if (model == null)
             {
                 #region 添加
                 if (hadname != null)
                 {
                     return new ReturnValue {
                                status = false, message = "名称已存在,不能重复添加"
                     }
                 }
                 ;
                 model           = new Employee();
                 model.depId     = depId;
                 model.duty      = duty;
                 model.email     = email;
                 model.isUser    = false;
                 model.mobile    = mobile;
                 model.remark    = remark;
                 model.staffName = name;
                 model.status    = valid;
                 c.Employees.Add(model);
                 #endregion
             }
             else
             {
                 #region 修改
                 if (hadname != null && hadname.staffId != id)
                 {
                     return new ReturnValue {
                                status = false, message = "名称已存在,不能重复添加"
                     }
                 }
                 ;
                 model.depId          = depId;
                 model.duty           = duty;
                 model.email          = email;
                 model.remark         = remark;
                 model.mobile         = mobile;
                 model.remark         = remark;
                 model.staffName      = name;
                 model.status         = 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
             });
         }
     }
 }