Example #1
0
        public ActionResult Newmodification(SYS_SalesCustomer sys_SalesCustomer) //新增&修改客户
        {
            //判断是否为零,零为新增,否则为修改
            int SalesCustomerID = sys_SalesCustomer.SalesCustomerID;

            try
            {
                if (SalesCustomerID == 0)
                {
                    //新增
                    myModels.SYS_SalesCustomer.Add(sys_SalesCustomer);
                    myModels.SaveChanges();
                }
                else
                {
                    //修改
                    myModels.Entry(sys_SalesCustomer).
                    State = System.Data.Entity.EntityState.Modified;
                    myModels.SaveChanges();
                }
            }
            catch (Exception)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
        public ActionResult UpdateSales(SYS_SalesCustomer Sales)
        {
            var strMsg = "failed";

            try
            {
                //判断修改后的数据是否与数据库数据重复
                var oldSalesRow = (from tbSales in myModels.SYS_SalesCustomer
                                   where tbSales.SalesCustomerID != Sales.SalesCustomerID &&
                                   (tbSales.CustomerCode == Sales.CustomerCode ||
                                    tbSales.IdNumber == Sales.IdNumber)
                                   select tbSales).Count();
                if (oldSalesRow == 0)
                {
                    if (Sales.CustomerName != null)
                    {
                        if (Sales.IdNumber != null)
                        {
                            if (Sales.CustomerCode != null)
                            {
                                myModels.Entry(Sales).State = System.Data.Entity.EntityState.Modified;
                                //保存数据库
                                myModels.SaveChanges();
                                strMsg = "success";
                            }
                            else
                            {
                                strMsg = "编号不能为空,请输入完整信息";
                            }
                        }
                        else
                        {
                            strMsg = "身份证不能为空,请输入完整信息";
                        }
                    }
                    else
                    {
                        strMsg = "客户名称不能为空,请输入完整信息";
                    }
                }
                else
                {
                    strMsg = "该客户信息已存在,不需要重复录入!";
                }
            }
            catch (Exception)
            {
                strMsg = "failed";
            }
            return(Json(strMsg, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="Sales"></param>
        /// <returns></returns>
        public ActionResult InsertSales(SYS_SalesCustomer Sales)
        {
            string strMsg = "failed";

            try
            {
                //判断销售客户表中是否已经存在新增的销售客户信息
                var SalesCount = (from tbSales in myModels.SYS_SalesCustomer
                                  where tbSales.SalesCustomerID == Sales.SalesCustomerID ||
                                  tbSales.IdNumber == Sales.IdNumber
                                  select tbSales).Count();
                if (SalesCount == 0)
                {
                    if (Sales.CustomerName != null)
                    {
                        if (Sales.IdNumber != null)
                        {
                            if (Sales.CustomerCode != null)
                            {
                                myModels.SYS_SalesCustomer.Add(Sales);
                                myModels.SaveChanges();
                                strMsg = "success";
                            }
                            else
                            {
                                strMsg = "编号不能为空,请输入完整信息";
                            }
                        }
                        else
                        {
                            strMsg = "身份证不能为空,请输入完整信息";
                        }
                    }
                    else
                    {
                        strMsg = "客户名称不能为空,请输入完整信息";
                    }
                }
                else
                {
                    strMsg = "该销售客户信息已经存在,不需要重复输入数据!";
                }
            }
            catch (Exception e)
            {
                strMsg = "failed";
            }
            return(Json(strMsg, JsonRequestBehavior.AllowGet));
        }