示例#1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string backouts = context.Request["params"];

            TmsReturnModel         returnModel    = new TmsReturnModel();
            StockOutDetailsService service        = new StockOutDetailsService();
            DispatchCenterService  centerService  = new DispatchCenterService();
            StockInDetailsService  stockInDetails = new StockInDetailsService();

            try
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    tmsModel outs = JsonConvert.DeserializeObject <tmsModel>(backouts);
                    if (outs.stockOutDetailsList != null)
                    {
                        foreach (LHStockOutDetails items in outs.stockOutDetailsList)
                        {
                            LHStockOutDetails details = service.Where(p => p.KeyId == items.KeyId && p.FId == items.FId).FirstOrDefault();

                            if (details != null)
                            {
                                details.FRecycleQty = items.FRecycleQty;
                                details.FReturnQty  = items.FReturnQty;

                                details.FDevice = items.FDevice;

                                details.FDeviceValue = string.IsNullOrEmpty(items.FDeviceValue.ToString()) ? 0 : Convert.ToDecimal(items.FDeviceValue);

                                details.FInTemperature = string.IsNullOrEmpty(items.FInTemperature.ToString()) //
                                    ? 0 : Convert.ToDecimal(items.FInTemperature.ToString());
                                details.FInPressure = string.IsNullOrEmpty(items.FInPressure.ToString())       //
                                    ? 0 : Convert.ToDecimal(items.FInPressure.ToString());

                                details.FOutTemperature = string.IsNullOrEmpty(items.FOutTemperature.ToString()) //
                                    ? 0 : Convert.ToDecimal(items.FOutTemperature.ToString());
                                details.FOutPressure = string.IsNullOrEmpty(items.FOutPressure.ToString())       //
                                    ? 0 : Convert.ToDecimal(items.FOutPressure.ToString());

                                details.FPayTemperature = string.IsNullOrEmpty(items.FPayTemperature.ToString()) //
                                    ? 0 : Convert.ToDecimal(items.FPayTemperature.ToString());
                                details.FPayPressure = string.IsNullOrEmpty(items.FPayPressure.ToString())       //
                                    ? 0 : Convert.ToDecimal(items.FPayPressure.ToString());

                                details.FReceiveTemperature = string.IsNullOrEmpty(items.FReceiveTemperature.ToString()) //
                                                    ? 0 : Convert.ToDecimal(items.FReceiveTemperature.ToString());
                                details.FReceivePressure = string.IsNullOrEmpty(items.FReceivePressure.ToString())       //
                                    ? 0 : Convert.ToDecimal(items.FReceivePressure.ToString());

                                //数量计算
                                LHStockOut StockOut = new StockOutService().Where(p => p.KeyId == items.KeyId).FirstOrDefault();
                                string     FCode    = StockOut.FCode;
                                //计算公式
                                LHTubePrice v1 = new TubePriceService().Where(p => p.FBill == "销售" &&//
                                                                              p.FCode == FCode &&//
                                                                              p.FItemCode == details.FItemCode).FirstOrDefault();

                                if (v1 != null)
                                {
                                    //< font color = "red" >$W1:进厂温度、$W2:出厂温度、$W3: 交付温度、$W4: 接收温度、$V: 水容积 </ font >< br />
                                    //< font color = "red" >$Y1:进厂压力、$Y2:出厂压力、$Y3: 交付压力、$Y4: 接收压力 </ font >< br />

                                    string inW = Convert.ToDecimal(details.FInTemperature).ToString(CultureInfo.InvariantCulture);
                                    string inY = Convert.ToDecimal(details.FInPressure).ToString(CultureInfo.InvariantCulture);

                                    string outW = Convert.ToDecimal(details.FOutTemperature).ToString(CultureInfo.InvariantCulture);
                                    string outY = Convert.ToDecimal(details.FOutPressure).ToString(CultureInfo.InvariantCulture);;

                                    string payW = Convert.ToDecimal(details.FPayTemperature).ToString(CultureInfo.InvariantCulture);
                                    string payY = Convert.ToDecimal(details.FPayPressure).ToString(CultureInfo.InvariantCulture);

                                    string recW = Convert.ToDecimal(details.FReceiveTemperature).ToString(CultureInfo.InvariantCulture);
                                    string recY = Convert.ToDecimal(details.FReceivePressure).ToString(CultureInfo.InvariantCulture);

                                    //水溶积
                                    string v = Convert.ToDecimal(details.FDeviceValue).ToString(CultureInfo.InvariantCulture);

                                    //数量
                                    string s1 = v1.FFormula.Replace("$W1", inW) //
                                                .Replace("$W2", outW)
                                                .Replace("$W3", payW)           //
                                                .Replace("$W4", recW)           //
                                                .Replace("$Y1", inY)            //
                                                .Replace("$Y2", outY)           //
                                                .Replace("$Y3", payY)           //
                                                .Replace("$Y4", recY)           //
                                                .Replace("$V", v);

                                    //数量
                                    details.FQty = Convert.ToDecimal(FormulaCalculator.Eval(s1));
                                    //金额
                                    details.FAmount = details.FQty * details.FPrice;
                                }


                                service.SaveChanges();
                            }
                        }
                    }
                    if (outs.dispatchCenterList != null)
                    {
                        foreach (LHDispatchCenter item in outs.dispatchCenterList)
                        {
                            LHDispatchCenter lH = centerService.Where(p => p.KeyId == item.KeyId & p.FAuditFlag == 0).FirstOrDefault();
                            if (lH != null)
                            {
                                lH.FDriver     = item.FDriver;
                                lH.FSupercargo = item.FSupercargo;
                                lH.FMileage    = item.FMileage;
                            }

                            centerService.SaveChanges();
                        }
                    }
                    trans.Complete();
                }

                returnModel.code = "200";
                returnModel.msg  = "成功";
            }
            catch (Exception ex)
            {
                returnModel.code = "500";
                returnModel.msg  = "失败";
                returnModel.msg  = ex.Message;
            }



            context.Response.Write(JsonConvert.SerializeObject(returnModel));
        }
示例#2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            bool isSucceed = false;

            try
            {
                switch (Actions)
                {
                case WebAction.Add:
                    isSucceed = SubmintAdd();
                    break;

                case WebAction.Edit:
                    isSucceed = SubmintEdit();
                    break;
                }

                tmsModel t = new tmsModel();
                try
                {
                    IQueryable <LHDispatchCenter> center = DispatchCenterService.Where(p => p.KeyId == lblKeyId.Text);
                    if (center.Count() > 0)
                    {
                        t.dispatchCenterList = center.ToList();
                    }
                    IQueryable <LHStockOut> iP = new StockOutService().Where(p => p.FDispatchNum == lblKeyId.Text);
                    t.stockOutList        = iP.ToList <LHStockOut>();
                    t.stockOutDetailsList = new List <LHStockOutDetails>();
                    foreach (LHStockOut item in iP)
                    {
                        IQueryable <LHStockOutDetails> li = new StockOutDetailsService().Where(p => p.KeyId == item.KeyId);
                        foreach (LHStockOutDetails outDetails in li)
                        {
                            t.stockOutDetailsList.Add(outDetails);
                        }
                    }
                    IQueryable <LHPassCard> lHPasses = PassCardService.Where(p => p.FDispatchNum == lblKeyId.Text);
                    if (lHPasses != null)
                    {
                        t.passCardList = lHPasses.ToList();
                    }

                    t.passCardDetailsList = new List <LHPassCardDetails>();
                    foreach (LHPassCard item in t.passCardList)
                    {
                        IQueryable <LHPassCardDetails> cardDetails = new PassCardDetailsService().Where(p => p.KeyId == item.KeyId);
                        foreach (LHPassCardDetails details in cardDetails)
                        {
                            t.passCardDetailsList.Add(details);
                        }
                    }

                    IQueryable <LHStockIn> skin = new StockInService().Where(p => p.FDispatchNum == lblKeyId.Text);
                    if (skin != null && skin.Count() > 0)
                    {
                        t.stockInList        = skin.ToList();
                        t.stockInDetailsList = new List <LHStockInDetails>();
                        foreach (LHStockIn item in skin)
                        {
                            IQueryable <LHStockInDetails> inDetails = new StockInDetailsService().Where(p => p.KeyId == item.KeyId);
                            foreach (LHStockInDetails inDetail in inDetails)
                            {
                                t.stockInDetailsList.Add(inDetail);
                            }
                        }
                    }
                    new HttpRequest().httpRequest(t, "open/dbo/dboData");
                }
                catch (Exception)
                {
                }
            }
            catch (DbEntityValidationException ex)
            {
                string msg = string.Empty;
                List <ICollection <DbValidationError> > errors = (from u in ex.EntityValidationErrors select u.ValidationErrors).ToList();
                foreach (ICollection <DbValidationError> item in errors)
                {
                    msg += item.FirstOrDefault().ErrorMessage;
                }
                isSucceed = false;
            }
            finally
            {
                if (isSucceed)
                {
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    Alert.Show("提交失败!", MessageBoxIcon.Error);
                }
            }
        }
示例#3
0
        public void httpRequest(tmsModel t, string uri)
        {
            string result = "";

            string details = "";
            string message = "";

            try
            {
                if (t.stockOutDetailsList != null)
                {
                    foreach (LHStockOutDetails item in t.stockOutDetailsList)
                    {
                        details += item.FId + "---" + item.FItemCode + ",";
                    }
                }
                if (t.stockOutList != null && t.stockOutList.Count > 0)
                {
                    message += ",发货单:" + t.stockOutList[0].KeyId;
                }
                if (t.stockOutDetailsList != null)
                {
                    message += ",发货单详细单号:" + details;
                }
                if (t.passCardList != null && t.passCardList.Count > 0)
                {
                    message += ",销售单:" + t.passCardList[0].KeyId;
                }
                if (t.passCardDetailsList != null)
                {
                    string sdetails = "";
                    foreach (LHPassCardDetails item in t.passCardDetailsList)
                    {
                        sdetails += item.FId + "---" + item.FItemCode + ",";
                    }
                    message += ",销售单详细单号:" + sdetails;
                }
                if (t.DispatchDetailsList != null && t.DispatchDetailsList.Count > 0)
                {
                    message += ",调度单:" + t.dispatchCenterList[0].KeyId;
                }
                LogUtil.InfoLog(message);
                string     url = System.Configuration.ConfigurationManager.AppSettings["ineterface"];
                WebRequest req = HttpWebRequest.Create(url + uri + "?appkey=e50f9e48d3234807a20ffd3653fafa7b") as WebRequest;
                req.Method = "post";
                string json = "params=" + JsonConvert.SerializeObject(t);
                byte[] bt   = Encoding.UTF8.GetBytes(json);
                req.ContentLength = bt.Length;
                req.ContentType   = "application/x-www-form-urlencoded";
                Stream st = req.GetRequestStream();
                st.Write(bt, 0, bt.Length);

                HttpWebResponse response = (HttpWebResponse)req.GetResponse();
                Stream          stream   = response.GetResponseStream();
                StreamReader    red      = new StreamReader(stream);
                result = red.ReadToEnd();
                TmsReturnModel model = JsonConvert.DeserializeObject <TmsReturnModel>(result);


                if (model.code != "200")
                {
                    message += ",同步失败,状态码:" + model.code + ",信息:" + model.msg;
                    LogUtil.InfoLog(message);
                }
            }
            catch (System.Exception ex)
            {
                details  = "";
                message += "错误:";
                if (t.stockOutDetailsList != null)
                {
                    foreach (LHStockOutDetails item in t.stockOutDetailsList)
                    {
                        details += item.FId + "---" + item.FItemCode + ",";
                    }
                }
                if (t.stockOutList != null && t.stockOutList.Count > 0)
                {
                    message += ",发货单:" + t.stockOutList[0].KeyId;
                }
                if (t.stockOutDetailsList != null)
                {
                    message += ",发货单详细单号:" + details;
                }
                if (t.passCardList != null && t.passCardList.Count > 0)
                {
                    message += ",销售单:" + t.passCardList[0].KeyId;
                }
                if (t.passCardDetailsList != null)
                {
                    string sdetails = "";
                    foreach (LHPassCardDetails item in t.passCardDetailsList)
                    {
                        sdetails += item.FId + "---" + item.FItemCode + ",";
                    }
                    message += ",销售单详细单号:" + sdetails;
                }
                if (t.DispatchDetailsList != null && t.DispatchDetailsList.Count > 0)
                {
                    message += ",调度单:" + t.dispatchCenterList[0].KeyId;
                }
                message += ",错误信息:" + ex.Message;
                message += ",错误堆栈:" + ex.StackTrace;
                LogUtil.InfoLog(message);
            }
        }