示例#1
0
        // 提交订单到erp 减库存
        public JsonResult CMT(string ccode, string db, string ccustid)
        {
            var jsonResult = new JsonResult();

            jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            jsonResult.Data = 4;

            using (kw_m01Context kw_m01 = new kw_m01Context())
            {
                var corder = kw_m01.M_CORDER.Find(ccode, db);
                if (corder.CMTFLAG == "1")
                {
                    jsonResult.Data = 5;
                    return(jsonResult);
                }

                // 转到erp
                kw_m01.p_ins_custid_no(db, ccustid);
                kw_m01.sp_ins_erp_corder(db, ccode);

                // 让订单处于已提交状态
                corder.CMTFLAG = "1";
                kw_m01.M_CORDER.AddOrUpdate(corder);

                var cordercs = from c in kw_m01.M_CORDERC
                               where c.cquotid == db &&
                               c.CCODE == ccode
                               select c;

                var date = DateTime.Now;

                foreach (var corderc in cordercs)
                {
                    // 每个项的库存异动
                    M_StoreChange storeChange = new M_StoreChange();
                    storeChange.db         = db;
                    storeChange.ccode      = ccode;
                    storeChange.iorder     = corderc.IORDER;
                    storeChange.cmteid     = corderc.CMTEID;
                    storeChange.changeFlag = -1;
                    storeChange.quantity   = corderc.DQTY;
                    storeChange.changeDate = date.Date;
                    kw_m01.M_StoreChange.Add(storeChange);

                    // 每个项的库存更改kw
                    var store = kw_m01.gb_Store.Find(corderc.CMTEID);
                    store.Inventory -= corderc.DQTY;
                    kw_m01.gb_Store.AddOrUpdate(store);
                }

                // 保存数据库更改
                kw_m01.SaveChanges();

                jsonResult.Data = "success";
            }

            return(jsonResult);
        }
示例#2
0
        // 添加订单
        public JsonResult AddOrder(string customerJson, string corderJson, string cordercsJson, string flag)
        {
            var jsonResult = new JsonResult();

            jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;


            // 反序列化 单头单身
            JavaScriptSerializer js = new JavaScriptSerializer();
            var customer            = js.Deserialize <M_CUSTOMER>(customerJson);
            var corder   = js.Deserialize <M_CORDER>(corderJson);
            var cordercs = js.Deserialize <List <M_CORDERC> >(cordercsJson);

            Debug.Assert(customer != null, "customer 为null!");
            Debug.Assert(corder != null, "corder 为null!");


            // 访问数据库
            using (kw_m01Context kw_m01 = new kw_m01Context())
            {
                // 获取客户号 填入customer&corder
                var custmResult = kw_m01.p_cre_custid_no(customer.cdeareaid, customer.CCLASSID, customer.cconmante).ToList();
                Debug.Assert(custmResult.First() != null && custmResult.First() != "", "客户ID获取失败");
                customer.CCUSTID = custmResult.First();
                corder.CCUSTID   = customer.CCUSTID;


                // 获取单号 填入customer&corder
                var orderResult = kw_m01.p_getmaxcode3("305", "1", corder.cpathid, DateTime.Now.Date).ToList();
                Debug.Assert(orderResult.First() != null && orderResult.First() != "", "订单ID获取失败");
                corder.CCODE     = orderResult.First();
                customer.CREMARK = corder.CCODE;
                for (var i = 0; i < cordercs.Count; i++)
                {
                    cordercs[i].CCODE = corder.CCODE;
                }


                // 操作数据库
                try
                {
                    kw_m01.M_CUSTOMER.AddOrUpdate(customer);
                    kw_m01.M_CORDER.Add(corder);
                    if (cordercs.Count != 0)
                    {
                        kw_m01.M_CORDERC.AddRange(cordercs);
                    }
                    kw_m01.SaveChanges();


                    if (flag == "1")
                    {
                        kw_m01.p_ins_custid_no(customer.cdeareaid, customer.CCUSTID);
                        kw_m01.sp_ins_erp_corder(corder.cpathid, corder.CCODE);
                        corder.CMTFLAG = "1";
                        kw_m01.M_CORDER.AddOrUpdate(corder);
                        kw_m01.SaveChanges();
                    }
                    jsonResult.Data = "success";
                }
                catch (Exception ex)
                {
                    string o = "";
                    new SaveError(ex, o, o, o, o, o, "区域:" + corder.cpathid, "订单号:" + corder.CCODE);
                    jsonResult.Data = 3;
                }
            }
            return(jsonResult);
        }
示例#3
0
        // 保存订单
        public JsonResult SaveOrder(string customerJson, string corderJson, string cordercsJson, string flag)
        {
            var jsonResult = new JsonResult();

            jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            // 反序列化 单头单身
            JavaScriptSerializer js = new JavaScriptSerializer();
            var customer            = js.Deserialize <M_CUSTOMER>(customerJson);
            var corder   = js.Deserialize <M_CORDER>(corderJson);
            var cordercs = js.Deserialize <List <M_CORDERC> >(cordercsJson);

            Debug.Assert(customer != null, "customer 为null!");
            Debug.Assert(corder != null, "corder 为null!");


            // 访问数据库
            //TransactionScope scope = new TransactionScope()
            using (kw_m01Context kw_m01 = new kw_m01Context())
            {
                var dels = from s in kw_m01.M_CORDERC
                           where s.CCODE == corder.CCODE &&
                           s.cquotid == corder.cpathid
                           select s;

                // 操作数据库
                kw_m01.M_CORDER.AddOrUpdate(corder);
                kw_m01.M_CUSTOMER.AddOrUpdate(customer);
                kw_m01.M_CORDERC.RemoveRange(dels);

                if (cordercs.Count != 0)
                {
                    kw_m01.M_CORDERC.AddRange(cordercs);
                }

                if (flag == "1")
                {
                    var erp_order = kw_m01.v_corder.Find(corder.cpathid, corder.CCODE);
                    if (erp_order.CMTFLAG == "0")
                    {
                        try
                        {
                            kw_m01.SaveChanges();
                            kw_m01.sp_erp_corder(1, corder.cpathid, corder.CCODE, o, o, o, o, o, o, o, o);
                            kw_m01.p_ins_custid_no(customer.cdeareaid, customer.CCUSTID);
                            kw_m01.sp_ins_erp_corder(corder.cpathid, corder.CCODE);
                            jsonResult.Data = "success";
                        }
                        catch (Exception ex)
                        {
                            new SaveError(ex, o, o, o, o, o, "db:" + corder.cpathid, "客户订单号:" + corder.CCODE);
                        }
                    }
                }
                else
                {
                    var tempOrder = kw_m01.M_CORDER.Find(corder.CCODE, corder.cpathid);

                    if (tempOrder.CMTFLAG == "0")
                    {
                        kw_m01.SaveChanges();
                        jsonResult.Data = "success";
                    }
                }
            }
            return(jsonResult);
        }