/// <summary> /// 映射数据 /// </summary> /// <param name="order"></param> /// <param name="logisticsInterface"></param> /// <returns></returns> public static T_MySql_Order CreateMap(Aorder order, string logisticsInterface) { try { var mySqlOrder = new T_MySql_Order(); mySqlOrder.OUTSYS_BILL_CODE = string.IsNullOrEmpty(order.mailNo) ? "" : order.mailNo; mySqlOrder.OUTSYS_ORDER_NO = string.IsNullOrEmpty(order.logisticID) ? "" : order.logisticID; mySqlOrder.ORDER_SOURCE = ENUM_ORDER_SOURCE.ALI.ToString(); mySqlOrder.MSG_TYPE = "JSON"; //mySqlOrder.CREATE_BY = ""; mySqlOrder.MSG_CONTENT = string.IsNullOrEmpty(logisticsInterface) ? "" : logisticsInterface; mySqlOrder.IS_SYNC_SUCCESS = 0; mySqlOrder.CREATE_TIME = DateTime.Now; mySqlOrder.CREATE_BY = mySqlOrder.ORDER_SOURCE; mySqlOrder.C1 = ""; mySqlOrder.C2 = ""; mySqlOrder.C3 = ""; mySqlOrder.REMARK = ""; return(mySqlOrder); } catch (Exception e) { var message = new StringBuilder(); message.Append("TAOBAO订单映射过程发生错误:" + logisticsInterface); message.Append(e.Message + e.StackTrace); return(null); } }
//Creates info on the submitted order table static void SubmitOrder(Aorder submittedOrder, List <Apizza> submittedPizzas) { var context = new PizzaBoxContext(); Console.WriteLine("Order #" + submittedOrder.OrderId + " $" + submittedOrder.Total); context.Aorders.Add(submittedOrder); context.SaveChanges(); //Takes each of the orders for the pizza and displays them and the price and moves them to the submitted order pizza foreach (var p in submittedPizzas) { var orderedPizzas = new AorderedPizza() { Id = (context.AorderedPizzas.Any(o => o.Id == 1))?context.AorderedPizzas.Max(o => o.Id) + 1: 1, OrderId = submittedOrder.OrderId, PizzaName = p.PizzaName, Topping1 = p.Topping1, Topping2 = p.Topping2, Topping3 = p.Topping3, Topping4 = p.Topping4, Topping5 = p.Topping5, Size = p.Size, Crust = p.Crust, Price = p.GetPizzaPrice() }; Console.WriteLine(" " + p.ToString()); context.AorderedPizzas.Add(orderedPizzas); context.SaveChanges(); } }
static void CreateOrder(Astore orderingStore, Acustomer orderingCustomer) { var context = new PizzaBoxContext(); int input = -1; List <Apizza> pizzas = new List <Apizza>(); var newOrder = new Aorder() { OrderId = (context.Aorders.Any(o => o.OrderId == 1))?context.Aorders.Max(o => o.OrderId) + 1: 1, CustomerId = orderingCustomer.Id, StoreId = orderingStore.Id, TimeOrdered = DateTime.Now }; Console.WriteLine("What Pizza Do you want in your order"); do { if (input != 2) { pizzas.Add(SelectPizza()); ModifyPizza(pizzas[pizzas.Count - 1]); } else { RemovePizza(pizzas); } Console.WriteLine("Order Total $: " + newOrder.TotalPrice(pizzas).Value); if (pizzas.Count >= maxPizzaCount || newOrder.TotalPrice(pizzas) > maxPizzaOrder) { input = 0; Console.WriteLine("You have reached the limit of your order"); } else { Console.WriteLine("Do you want another pizza. 0 for no 1 for yes 2 to remove pizza"); int.TryParse(Console.ReadLine(), out input); } }while(!(input == 0)); foreach (var p in pizzas) { Console.WriteLine(p.ToString()); } var totalPrice = 0m; foreach (var p in pizzas) { totalPrice += p.GetPizzaPrice(); } SubmitOrder(newOrder, pizzas); }
/// <summary> /// creates a new order to assign order details to /// Automatically assigns the time that the method gets the order /// </summary> /// <param name="custID"></param> /// <param name="storeID"></param> /// <param name="tot"></param> /// <returns></returns> public Aorder NewOrder(int custID, int storeID, decimal tot) { var order = new Aorder() { CustomerId = custID, StoreId = storeID, Total = tot, OrderTime = DateTime.Now, OrderId = ((context.Aorders.Any(o => o.OrderId == 1)) ? context.Aorders.Max(o => o.OrderId) + 1 : 1) }; context.Aorders.Add(order); context.SaveChanges(); return(order); }
/// <summary> /// Creates new details of an order using the price and the amoung /// </summary> /// <param name="orderNum"></param> /// <param name="itemNum"></param> /// <param name="amount"></param> /// <returns></returns> public decimal NewOrderDetail(int orderNum, int itemNum, int amount) { Aorder getorder = context.Aorders.FirstOrDefault(o => o.OrderId == orderNum); List <InventoryDetail> inventory = context.InventoryDetails.ToList(); inventory.Find(i => getorder.StoreId == i.StoreId && itemNum == i.ItemId).Amount -= amount; context.InventoryDetails.Update(inventory.Find(i => getorder.StoreId == i.StoreId && itemNum == i.ItemId)); context.SaveChanges(); AorderDetail newDetail = new AorderDetail() { Id = ((context.AorderDetails.Any(o => o.Id == 1)) ? context.AorderDetails.Max(o => o.Id) + 1 : 1), OrderId = orderNum, ItemId = itemNum, Total = Convert.ToDecimal(amount) }; context.AorderDetails.Add(newDetail); context.SaveChanges(); return(0.0m); }
public Aorder AddOrder(Aorder newOrder) { context.Aorders.Add(newOrder); return(newOrder); }
public Aorder AddOrder(Aorder newOrder) { orders.Add(newOrder); return(newOrder); }
//requesType为接口请求类型,提交/查询等 public static Aorder JsonToClass(string json) { Aorder order = new Aorder(); JObject j = JObject.Parse(json); List <JToken> baseinfo = j.Children().ToList(); List <JToken> sender = j["sender"].Children().ToList(); List <JToken> receiver = j["receiver"].Children().ToList(); string sendvalue = ""; string receivervalue = ""; string infovalue = ""; #region 赋值 #region 基础信息赋值 foreach (JProperty info in baseinfo) { infovalue = ""; // if (info.Name == "CustomerID" && info.Value.ToString() != "") //{ // infovalue = (string)info.Value; // if (infovalue.Length > 100) // { // infovalue = infovalue.Substring(0, 100); // } // CustomerID = infovalue; // continue; //} // if (info.Name == "subOrderID" && info.Value.ToString() != "") //{ // infovalue = (string)info.Value; // if (infovalue.Length > 100) // { // infovalue = infovalue.Substring(0, 100); // } // subOrderID = infovalue; // continue; //} if (info.Name == "businessNetworkNo" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 30) { infovalue = infovalue.Substring(0, 30); } order.businessNetworkNo = infovalue; continue; } else if (info.Name == "toNetworkNo" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 30) { infovalue = infovalue.Substring(0, 30); } order.toNetworkNo = infovalue; continue; } else if (info.Name == "gmtCommit" && info.Value.ToString() != "") { //转换阿里传递的时间戳 DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long TimeSta = long.Parse(info.Value + "0000"); TimeSpan toNow = new TimeSpan(TimeSta); order.gmtCommit = DateTime.Parse(dtStart.Add(toNow).ToString()); continue; } else if (info.Name == "gmtUpdated" && info.Value.ToString() != "") { //转换阿里传递的时间戳 DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long TimeSta = long.Parse(info.Value + "0000"); TimeSpan toNow = new TimeSpan(TimeSta); order.gmtUpdated = DateTime.Parse(dtStart.Add(toNow).ToString()); continue; } else if (info.Name == "transportPrice" && info.Value.ToString() != "") { order.transportPrice = (decimal)info.Value; continue; } else if (info.Name == "materialCost" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 2) { infovalue = infovalue.Substring(0, 2); } order.materialCost = infovalue; continue; } else if (info.Name == "materialCostPrice" && info.Value.ToString() != "") { order.materialCostPrice = (decimal)info.Value; continue; } else if (info.Name == "vistReceive" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 50) { infovalue = infovalue.Substring(0, 50); } order.vistReceive = infovalue; continue; } else if (info.Name == "vistReceivePrice" && info.Value.ToString() != "") { order.vistReceivePrice = (decimal)info.Value; continue; } else if (info.Name == "deliveryType" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 2) { infovalue = infovalue.Substring(0, 2); } order.deliveryType = infovalue; continue; } else if (info.Name == "deliveryPrice" && info.Value.ToString() != "") { order.deliveryPrice = (decimal)info.Value; continue; } else if (info.Name == "insuranceValue" && info.Value.ToString() != "") { order.insuranceValue = (decimal)info.Value; continue; } else if (info.Name == "insurancePrice" && info.Value.ToString() != "") { order.insurancePrice = (decimal)info.Value; continue; } else if (info.Name == "backSignBill" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 2) { infovalue = infovalue.Substring(0, 2); } order.backSignBill = infovalue; continue; } else if (info.Name == "backSignBillPrice" && info.Value.ToString() != "") { order.backSignBillPrice = (decimal)info.Value; continue; } else if (info.Name == "waitNotifySend" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 1) { infovalue = infovalue.Substring(0, 1); } order.waitNotifySend = infovalue; continue; } else if (info.Name == "waitNotifySendPrice" && info.Value.ToString() != "") { order.waitNotifySendPrice = (decimal)info.Value; continue; } else if (info.Name == "packageService" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 50) { infovalue = infovalue.Substring(0, 50); } order.packageService = infovalue; continue; } else if (info.Name == "packageServicePrice" && info.Value.ToString() != "") { order.packageServicePrice = (decimal)info.Value; continue; } else if (info.Name == "totalPrice" && info.Value.ToString() != "") { order.totalPrice = (decimal)info.Value; continue; } else if (info.Name == "payType" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 10) { infovalue = infovalue.Substring(0, 10); } order.payType = infovalue; continue; } else if (info.Name == "transportType" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 20) { infovalue = infovalue.Substring(0, 20); } order.transportType = infovalue; continue; } else if (info.Name == "codType" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 10) { infovalue = infovalue.Substring(0, 10); } order.codType = infovalue; continue; } else if (info.Name == "codPrice" && info.Value.ToString() != "") { order.codPrice = (decimal)info.Value; continue; } else if (info.Name == "otherPrice" && info.Value.ToString() != "") { order.otherPrice = (decimal)info.Value; continue; } else if (info.Name == "remark" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 1000) { infovalue = infovalue.Substring(0, 1000); } order.remark = infovalue; continue; } else if (info.Name == "logisticID" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 100) { infovalue = infovalue.Substring(0, 100); } order.logisticID = infovalue; continue; } else if (info.Name == "mailNo" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 100) { infovalue = infovalue.Substring(0, 100); } order.mailNo = infovalue; continue; } else if (info.Name == "weightRate" && info.Value.ToString() != "") { order.weightRate = (decimal)info.Value; continue; } else if (info.Name == "volumeRate" && info.Value.ToString() != "") { order.volumeRate = (decimal)info.Value; continue; } else if (info.Name == "leastExpenses" && info.Value.ToString() != "") { order.leastExpenses = Convert.ToDecimal(info.Value); continue; } //else if (info.Name == "waitewaitNotifySend" && info.Value.ToString() != "") //{ // waitewaitNotifySend = infovalue; // waitNotifySend = infovalue; // continue; //} //else if (info.Name == "waitewaitNotifySendPrice" && info.Value.ToString() != "") //{ // waitewaitNotifySendPrice = (decimal)info.Value; // waitNotifySendPrice = (decimal)info.Value; // continue; //} else if (info.Name == "smsNotify" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 1) { infovalue = infovalue.Substring(0, 1); } order.smsNotify = infovalue; continue; } else if (info.Name == "smsNotifyPrice" && info.Value.ToString() != "") { order.smsNotifyPrice = (decimal)info.Value; continue; } else if (info.Name == "fuelSurcharge" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 1) { infovalue = infovalue.Substring(0, 1); } order.fuelSurcharge = infovalue; continue; } else if (info.Name == "fuelSurchargePrice" && info.Value.ToString() != "") { order.fuelSurchargePrice = (decimal)info.Value; continue; } //else if (info.Name == "comments" && info.Value.ToString() != "") //{ // infovalue = (string)info.Value; // if (infovalue.Length > 100) // { // infovalue = infovalue.Substring(0, 100); // } // comments = infovalue; // continue; //} else if (info.Name == "totalWeight" && info.Value.ToString() != "") { order.totalWeight = (decimal)info.Value; continue; } else if (info.Name == "totalVolume" && info.Value.ToString() != "") { order.totalVolume = (decimal)info.Value; continue; } else if (info.Name == "totalNumber" && info.Value.ToString() != "") { order.totalNumber = (int)info.Value; continue; } else if (info.Name == "totalPrice" && info.Value.ToString() != "") { order.totalPrice = (decimal)info.Value; continue; } else if (info.Name == "weightRate" && info.Value.ToString() != "") { order.weightRate = (decimal)info.Value; continue; } else if (info.Name == "volumeRate" && info.Value.ToString() != "") { order.volumeRate = (decimal)info.Value; continue; } else if (info.Name == "promotion" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 200) { infovalue = infovalue.Substring(0, 200); } order.promotion = infovalue; continue; } else if (info.Name == "aliUID" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 100) { infovalue = infovalue.Substring(0, 100); } order.aliUID = infovalue; continue; } else if (info.Name == "memberType" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 30) { infovalue = infovalue.Substring(0, 30); } order.memberType = infovalue; continue; } else if (info.Name == "bizType" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 30) { infovalue = infovalue.Substring(0, 30); } order.bizType = infovalue; continue; } else if (info.Name == "cargoName" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 100) { infovalue = infovalue.Substring(0, 100); } order.cargoName = infovalue; continue; } else if (info.Name == "codValue" && info.Value.ToString() != "") { order.codValue = (decimal)info.Value; continue; } else if (info.Name == "logisticCompanyID" && info.Value.ToString() != "") { infovalue = (string)info.Value; if (infovalue.Length > 20) { infovalue = infovalue.Substring(0, 20); } order.logisticCompanyID = infovalue; continue; } //else if (info.Name == "serviceType" && info.Value.ToString() != "") //{ // infovalue = (string)info.Value; // if (infovalue.Length > 100) // { // infovalue = infovalue.Substring(0, 100); // } // serviceType = infovalue; // continue; //} } #endregion #region 发货人赋值 foreach (JProperty send in sender) { sendvalue = ""; if (send.Name == "companyName" && send.Value.ToString() != "") { sendvalue = (string)send.Value; if (sendvalue.Length > 100) { sendvalue = sendvalue.Substring(0, 100); } order.ScompanyName = sendvalue; } else if (send.Name == "name" && send.Value.ToString() != "") { sendvalue = (string)send.Value; if (sendvalue.Length > 100) { sendvalue = sendvalue.Substring(0, 100); } order.Sname = sendvalue; } else if (send.Name == "postCode" && send.Value.ToString() != "") { sendvalue = (string)send.Value; if (sendvalue.Length > 10) { sendvalue = sendvalue.Substring(0, 10); } order.SpostCode = sendvalue; } else if (send.Name == "mobile" && send.Value.ToString() != "" && send.Value.ToString().Length > 5) { sendvalue = (string)send.Value; if (sendvalue.Length > 50) { sendvalue = sendvalue.Substring(0, 50); } order.Smobile = sendvalue; } else if (send.Name == "phone" && send.Value.ToString() != "") { sendvalue = (string)send.Value; if (sendvalue.Length > 50) { sendvalue = sendvalue.Substring(0, 50); } order.Sphone = sendvalue; } else if (send.Name == "province" && send.Value.ToString() != "") { sendvalue = (string)send.Value; if (sendvalue.Length > 50) { sendvalue = sendvalue.Substring(0, 50); } order.Sprovince = sendvalue; } else if (send.Name == "city" && send.Value.ToString() != "") { sendvalue = (string)send.Value; if (sendvalue.Length > 50) { sendvalue = sendvalue.Substring(0, 50); } order.Scity = sendvalue; } else if (send.Name == "county" && send.Value.ToString() != "") { sendvalue = (string)send.Value; if (sendvalue.Length > 50) { sendvalue = sendvalue.Substring(0, 50); } order.Scounty = sendvalue; } else if (send.Name == "address" && send.Value.ToString() != "") { sendvalue = (string)send.Value; if (sendvalue.Length > 300) { sendvalue = sendvalue.Substring(0, 300); } order.Saddress = sendvalue; } } #endregion #region 收货人信息赋值 foreach (JProperty rec in receiver) { receivervalue = ""; if (rec.Name == "companyName" && rec.Value.ToString() != "") { receivervalue = (string)rec.Value; if (receivervalue.Length > 100) { receivervalue = receivervalue.Substring(0, 100); } order.RcompanyName = receivervalue; } else if (rec.Name == "name" && rec.Value.ToString() != "") { receivervalue = (string)rec.Value; if (receivervalue.Length > 100) { receivervalue = receivervalue.Substring(0, 100); } order.Rname = receivervalue; } else if (rec.Name == "postCode" && rec.Value.ToString() != "") { receivervalue = (string)rec.Value; if (receivervalue.Length > 10) { receivervalue = receivervalue.Substring(0, 10); } order.RpostCode = receivervalue; } else if (rec.Name == "mobile" && rec.Value != null && rec.Value.ToString().Length > 5) { receivervalue = (string)rec.Value; if (receivervalue.Length > 50) { receivervalue = receivervalue.Substring(0, 50); } order.Rmobile = receivervalue; } else if (rec.Name == "phone" && rec.Value.ToString() != "") { receivervalue = (string)rec.Value; if (receivervalue.Length > 50) { receivervalue = receivervalue.Substring(0, 50); } order.Rphone = receivervalue; } else if (rec.Name == "province" && rec.Value.ToString() != "") { receivervalue = (string)rec.Value; if (receivervalue.Length > 50) { receivervalue = receivervalue.Substring(0, 50); } order.Rprovince = receivervalue; } else if (rec.Name == "city" && rec.Value.ToString() != "") { receivervalue = (string)rec.Value; if (receivervalue.Length > 50) { receivervalue = receivervalue.Substring(0, 50); } order.Rcity = receivervalue; } else if (rec.Name == "county" && rec.Value.ToString() != "") { receivervalue = (string)rec.Value; if (receivervalue.Length > 50) { receivervalue = receivervalue.Substring(0, 50); } order.Rcounty = receivervalue; } else if (rec.Name == "address" && rec.Value.ToString() != "") { receivervalue = (string)rec.Value; if (receivervalue.Length > 50) { receivervalue = receivervalue.Substring(0, 50); } order.Raddress = receivervalue; } } #endregion #endregion return(order); }