/// <summary> /// 添加订单 /// </summary> /// <param name="OrderData"></param> /// <returns></returns> public int AddOrders(PlaceOrder OrderData) { Order order = new Order(); //var query = (from c in HouseAppEntities.Order // orderby c.UserID descending // select c); //u1.UserID = query.First<User>().UserID + 1; //order.OrderID ; order.CreaterID = OrderData.CreaterID ; order.CreateDateTime = DateTime.Now; order.ProductName = OrderData.ProductName; order.ProductWeight = OrderData.ProductWeight; order.Remarks = OrderData.Remarks; order.SenderName = OrderData.SenderName; order.SenderPhone = OrderData.SenderPhone; order.SenderAddress = OrderData.SenderAddress; order.ReceiverName = OrderData.ReceiverName; order.ReceiverPhone = OrderData.ReceiverPhone; order.ReceiverAddress = OrderData.ReceiverAddress; order.State = 0; //刚下单,状态为"0" order.PointX = OrderData.PointX; order.PointY = OrderData.PointY; order.PointX2 = OrderData.PointX2; order.PointY2 = OrderData.PointY2; order.Street = OrderData.Street; HouseAppEntities.Order.Add(order); int effect = -1; effect = HouseAppEntities.SaveChanges(); return effect; }
protected void Button1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(TextBox11.Text) || String.IsNullOrEmpty(TextBox13.Text) || String.IsNullOrEmpty(TextBox6.Text) || String.IsNullOrEmpty(TextBox8.Text) || String.IsNullOrEmpty(TextBox14.Text) || String.IsNullOrEmpty(TextBox7.Text) || String.IsNullOrEmpty(TextBox9.Text) || String.IsNullOrEmpty(TextBox15.Text)) { this.Page.RegisterStartupScript(" ", "<script>alert(' 请填写完整信息 '); </script> "); } else { JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); Services.Entity.PlaceOrder placeOrder = new Services.Entity.PlaceOrder(); //placeOrder.OrderID placeOrder.CreaterID = userID; //placeOrder.CreateDateTime = DateTime.Now; placeOrder.ProductName = TextBox11.Text; placeOrder.ProductWeight = DropDownList1.Text; placeOrder.Remarks = TextBox13.Text; placeOrder.SenderName = TextBox6.Text; placeOrder.SenderPhone = TextBox8.Text; placeOrder.SenderAddress = TextBox14.Text; placeOrder.ReceiverName = TextBox7.Text; placeOrder.ReceiverPhone = TextBox9.Text; placeOrder.ReceiverAddress = TextBox15.Text; placeOrder.PointX = ViewState["pointX1"].ToString(); placeOrder.PointY = ViewState["pointY1"].ToString(); placeOrder.PointX2 = ViewState["pointX2"].ToString(); placeOrder.PointY2 = ViewState["pointY2"].ToString(); placeOrder.Street = ViewState["Street"].ToString(); //执行序列化 part:1 string jsonstr = jsonSerializer.Serialize(placeOrder); //调用服务 RunServiceSoapClient testService = new RunServiceSoapClient(); //接受json格式的字符串,反序列化 WebPages.RunServiceReference.MySoapHeader soapHeader = new WebPages.RunServiceReference.MySoapHeader(); soapHeader.UserName = uName; soapHeader.Password = ps; string result = testService.UserPlaceOrder(soapHeader, jsonstr); if (result != "0") { FieldInfo[] infos = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance); for (int i = 0; i < infos.Length; i++) { if (infos[i].FieldType == typeof(TextBox)) { ((TextBox)infos[i].GetValue(this)).Text = ""; } } this.Page.RegisterStartupScript(" ", "<script>alert(' 下单成功 '); </script> "); } else { this.Page.RegisterStartupScript(" ", "<script>alert(' 下单失败 '); </script> "); } } }