Example #1
0
        // 生成采购计划单
        public string Create_Polist(string plJson, string plcJson)
        {
            string msg = "success";

            using (kw_m01Context kw_m01 = new kw_m01Context())
            {
                var polist  = JsonConvert.DeserializeObject <M_POLIST>(plJson);
                var polists = JsonConvert.DeserializeObject <List <M_POLISTC> >(plcJson);
                var db      = polist.CMTMAN;

                var ccode = kw_m01.p_getmaxcode3("204", "1", db, DateTime.Now.Date).First();
                polist.CCODE = ccode;
                for (var i = 0; i < polists.Count; i++)
                {
                    polists[i].CCODE = ccode;
                }

                kw_m01.M_POLIST.Add(polist);
                kw_m01.M_POLISTC.AddRange(polists);
                kw_m01.SaveChanges();
                kw_m01.sp_ins_erp_polist(db, ccode);
            }

            return(msg);
        }
Example #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);
        }