protected void btnSubmit_Click(object sender, EventArgs e) { using (var conn = new SqlConnection(DataAccess.ConnectString)) { conn.Open(); var trans = conn.BeginTransaction(); try { var m = repo.Single <Member>(Mid); // Update Member Information #region Get Member Nation & Region var _nation = ddlNation.SelectedValue; if (!string.IsNullOrEmpty(_nation)) { if (_nation.Equals("中国")) { m.Nation = _nation; if (!string.IsNullOrEmpty(tbRegion1.Text.Trim())) { if (!string.IsNullOrEmpty(tbRegion2.Text.Trim())) { m.Region = $"{tbRegion1.Text.Trim()}|{tbRegion2.Text.Trim()}"; } else { m.Region = tbRegion1.Text.Trim(); } } else { m.Region = string.Empty; } } else if (!string.IsNullOrEmpty(tbNation.Text.Trim())) { m.Nation = tbNation.Text.Trim(); m.Region = string.Empty; } else { m.Nation = _nation; m.Region = string.Empty; } } else { m.Nation = string.Empty; m.Region = string.Empty; } #endregion if (!string.IsNullOrEmpty(tbIDCardNo.Text.Trim())) { m.IDCardNo = tbIDCardNo.Text.Trim(); } else { throw new Exception("请填写会员身份证号码"); } if (!string.IsNullOrEmpty(tbPassportNo.Text.Trim())) { m.PassportNo = tbPassportNo.Text.Trim(); } else { throw new Exception("请填写会员护照编号"); } if (!string.IsNullOrEmpty(tbPassportName.Text.Trim())) { m.PassportName = tbPassportName.Text.Trim(); } else { throw new Exception("请填写会员护照姓名"); } if (!string.IsNullOrEmpty(tbMobile.Text.Trim())) { m.Mobile = tbMobile.Text.Trim(); } else { throw new Exception("请填写会员手机"); } if (!string.IsNullOrEmpty(tbQQ.Text.Trim())) { m.QQ = tbQQ.Text.Trim(); } else { throw new Exception("请填写会员QQ"); } if (!string.IsNullOrEmpty(tbEmail.Text.Trim())) { m.Email = tbEmail.Text.Trim(); } else { throw new Exception("请填写会员邮箱"); } //m.MemberType = MemberType.Match; repo.Update(m); // New Order var o = new Order(); var _newID = int.MinValue; if (OrderID > 0) { o = repo.Single <Order>(OrderID); } o.Mobile = m.Mobile; o.UpdateTime = DateTime.Now; o.Description = tbOrderDescription.Text.Trim(); o.OrderType = OrderBaseType.Travel; if (OrderID > 0) { repo.Update(o, trans); // used by setting OrderItem foreign key _newID = OrderID; } else { o.MemberID = m.ID; o.MemberName = m.Name; o.Address = m.Address; o.Payment = string.Empty; o.Price = 0; o.Sale = null; o.Deposit = null; o.Status = OrderStatusType.Draft; o.Rate = 0; o.CreateTime = DateTime.Now; o.IsActive = true; o.Remark = string.Empty; //Get the Order ID after Insert new one object _key = null; repo.Insert(o, out _key, trans); _newID = Convert.ToInt32(_key); } //Remove Order Item of this Order if (OrderID > 0 && o.ID.Equals(OrderID)) { var count = repo.Query <OrderItem>(x => x.OrderID == OrderID).Delete(trans); } //New Order Items //Product pETPL = Product.Cache.Load("iETPL"); var pETPA = Product.Cache.Load("iETPA"); if (pETPA == null) { throw new Exception("无观赛信息,请联系管理员"); } // Get Partner Information to Serialize Json if (cbPartner.Checked) { var oiPartner = new OrdrItmTravelPartner(); var pa = new Partner(); if (!string.IsNullOrEmpty(tbPartnerName.Text.Trim())) { pa.Name = tbPartnerName.Text.Trim(); } else { throw new Exception("请填写同伴姓名"); } if (!string.IsNullOrEmpty(ddlPartnerRelation.SelectedValue)) { pa.Relation = int.Parse(ddlPartnerRelation.SelectedValue); } else { throw new Exception("请选择同伴关系"); } if (!string.IsNullOrEmpty(rblPartnerGender.SelectedValue)) { pa.Gender = bool.Parse(rblPartnerGender.SelectedValue); } else { pa.Gender = true; } if (!string.IsNullOrEmpty(tbPartnerIDCardNo.Text.Trim())) { pa.IDCardNo = tbPartnerIDCardNo.Text.Trim(); } else { throw new Exception("请填写同伴身份证"); } if (!string.IsNullOrEmpty(tbPartnerPassportNo.Text.Trim())) { pa.PassportNo = tbPartnerPassportNo.Text.Trim(); } else { throw new Exception("请填写同伴护照号码"); } if (!string.IsNullOrEmpty(tbPartnerPassportName.Text.Trim())) { pa.PassportName = tbPartnerPassportName.Text.Trim(); } else { throw new Exception("请填写同伴护照姓名"); } oiPartner.Partner = pa; oiPartner.OrderID = _newID; oiPartner.Size = string.Empty; oiPartner.Quantity = 1; oiPartner.Sale = null; oiPartner.Place(m, pETPA, trans); } // Generate OrderItemTravelPlan var oiPlan = new OrdrItmTravelPlanLondon(); // Genernate Travel Date if (!string.IsNullOrEmpty(tbFromDate.Text.Trim()) && !string.IsNullOrEmpty(tbToDate.Text.Trim())) { oiPlan.TravelFromDate = DateTime.Parse(tbFromDate.Text.Trim()); oiPlan.TravelToDate = DateTime.Parse(tbToDate.Text.Trim()); } else { throw new Exception("请填写推荐出行时间"); } // Generate Travel Option //string _strTravelOption = string.Empty; var listTravelOption = new List <string>(); for (var i = 0; i < cblTravelOption.Items.Count; i++) { if (cblTravelOption.Items[i].Selected) { listTravelOption.Add(cblTravelOption.Items[i].Value); } } oiPlan.TravelOption = listTravelOption.Count > 0 ? listTravelOption.ToArray() : null; oiPlan.OrderID = _newID; oiPlan.Quantity = 1; oiPlan.Sale = null; oiPlan.Place(m, trans); trans.Commit(); ClientScript.RegisterClientScriptBlock(typeof(string), "succeed", string.Format("alert('订单({0})保存成功');window.location.href = 'ServerOrderView.ashx?OrderID={0}'", _newID), true); } catch (Exception ex) { trans.Rollback(); ClientScript.RegisterClientScriptBlock(typeof(string), "failed", $"alert('{ex.Message}')", true); } //conn.Close(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { using (SqlConnection conn = new SqlConnection(DataAccess.ConnectString)) { conn.Open(); SqlTransaction trans = conn.BeginTransaction(); try { Member m = repo.Single <Member>(this.MID); // Update Member Information #region Get Member Nation & Region string _nation = ddlNation.SelectedValue; if (!string.IsNullOrEmpty(_nation)) { if (_nation.Equals("中国")) { m.Nation = _nation; if (!string.IsNullOrEmpty(tbRegion1.Text.Trim())) { if (!string.IsNullOrEmpty(tbRegion2.Text.Trim())) { m.Region = string.Format("{0}|{1}", tbRegion1.Text.Trim(), tbRegion2.Text.Trim()); } else { m.Region = tbRegion1.Text.Trim(); } } else { m.Region = string.Empty; } } else if (!string.IsNullOrEmpty(tbNation.Text.Trim())) { m.Nation = tbNation.Text.Trim(); m.Region = string.Empty; } else { m.Nation = _nation; m.Region = string.Empty; } } else { m.Nation = string.Empty; m.Region = string.Empty; } #endregion if (!string.IsNullOrEmpty(tbIDCardNo.Text.Trim())) { m.IDCardNo = tbIDCardNo.Text.Trim(); } else { throw new Exception("请填写会员身份证号码"); } if (!string.IsNullOrEmpty(tbPassportNo.Text.Trim())) { m.PassportNo = tbPassportNo.Text.Trim(); } else { throw new Exception("请填写会员护照编号"); } if (!string.IsNullOrEmpty(tbPassportName.Text.Trim())) { m.PassportName = tbPassportName.Text.Trim(); } else { throw new Exception("请填写会员护照姓名"); } if (!string.IsNullOrEmpty(tbMobile.Text.Trim())) { m.Mobile = tbMobile.Text.Trim(); } else { throw new Exception("请填写会员手机"); } if (!string.IsNullOrEmpty(tbQQ.Text.Trim())) { m.QQ = tbQQ.Text.Trim(); } else { throw new Exception("请填写会员QQ"); } if (!string.IsNullOrEmpty(tbEmail.Text.Trim())) { m.Email = tbEmail.Text.Trim(); } else { throw new Exception("请填写会员邮箱"); } m.MemberType = MemberType.Match; repo.Update(m); // New Order Order o = new Order(); int _newID = int.MinValue; if (OrderID > 0) { o = repo.Single <Order>(OrderID); } o.Mobile = m.Mobile; o.UpdateTime = DateTime.Now; o.Description = tbOrderDescription.Text.Trim(); o.OrderType = OrderBaseType.Travel; if (OrderID > 0) { repo.Update(o, trans); // used by setting OrderItem foreign key _newID = OrderID; } else { o.MemberID = m.ID; o.MemberName = m.Name; o.Address = m.Address; o.Payment = string.Empty; o.Price = 0; o.Sale = null; o.Deposit = null; o.Status = OrderStatusType.Draft; o.Rate = 0; o.CreateTime = DateTime.Now; o.IsActive = true; o.Remark = string.Empty; //Get the Order ID after Insert new one object _key = null; repo.Insert <Order>(o, out _key, trans); _newID = Convert.ToInt32(_key); } //Remove Order Item of this Order if (OrderID > 0 && o.ID.Equals(OrderID)) { int _count = 0; repo.Delete <OrderItem>(x => x.OrderID.Equals(OrderID), out _count, trans); } //New Order Items //Product pTravelPlan = Product.Cache.Load("2015ATPL"); Product pTravelPartner = Product.Cache.Load("2015ATPA"); if (pTravelPartner == null) { throw new Exception("无观赛信息,请联系管理员"); } // Get Partner Information to Serialize Json if (cbPartner.Checked) { OrdrItmTravelPartner oiPartner = new OrdrItmTravelPartner(); Partner pa = new Partner(); if (!string.IsNullOrEmpty(tbPartnerName.Text.Trim())) { pa.Name = tbPartnerName.Text.Trim(); } else { throw new Exception("请填写同伴姓名"); } if (!string.IsNullOrEmpty(ddlPartnerRelation.SelectedValue)) { pa.Relation = int.Parse(ddlPartnerRelation.SelectedValue); } else { throw new Exception("请选择同伴关系"); } if (!string.IsNullOrEmpty(rblPartnerGender.SelectedValue)) { pa.Gender = bool.Parse(rblPartnerGender.SelectedValue); } else { pa.Gender = true; } if (!string.IsNullOrEmpty(tbPartnerIDCardNo.Text.Trim())) { pa.IDCardNo = tbPartnerIDCardNo.Text.Trim(); } else { throw new Exception("请填写同伴身份证"); } if (!string.IsNullOrEmpty(tbPartnerPassportNo.Text.Trim())) { pa.PassportNo = tbPartnerPassportNo.Text.Trim(); } else { throw new Exception("请填写同伴护照号码"); } if (!string.IsNullOrEmpty(tbPartnerPassportName.Text.Trim())) { pa.PassportName = tbPartnerPassportName.Text.Trim(); } else { throw new Exception("请填写同伴护照姓名"); } oiPartner.Partner = pa; oiPartner.OrderID = _newID; oiPartner.Size = string.Empty; oiPartner.Quantity = 1; oiPartner.Sale = null; oiPartner.Place(m, pTravelPartner, trans); } // Generate OrderItemTravelPlan OrdrItmTravelPlan2015AsiaTrophy oiPlan = new OrdrItmTravelPlan2015AsiaTrophy(); // Get the value of IsTicket bool _isTicket; if (!string.IsNullOrEmpty(rblIsTicketOnly.SelectedValue)) { _isTicket = rblIsTicketOnly.SelectedValue.Equals("Tour", StringComparison.OrdinalIgnoreCase) ? false : true; } else { throw new Exception("请填写报名方式"); } // Generate Travel Option TravelOption to = new TravelOption(); if (cbMatch1.Checked && cbMatch2.Checked) { to.MatchOption = MatchOption.All; } else if (cbMatch1.Checked && !cbMatch2.Checked) { to.MatchOption = MatchOption.First; } else if (!cbMatch1.Checked && cbMatch2.Checked) { to.MatchOption = MatchOption.Second; } else { throw new Exception("请选择观赛的场次"); } to.IsVisa = cblTravelOption.Items.FindByValue("VISA").Selected; to.IsFlight = cblTravelOption.Items.FindByValue("FLIGHT").Selected; to.IsHotel = cblTravelOption.Items.FindByValue("HOTEL").Selected; to.IsTraining = cblTravelOption.Items.FindByValue("TRAINING").Selected; to.IsParty = cblTravelOption.Items.FindByValue("PARTY").Selected; to.IsSingapore = cblTravelOption.Items.FindByValue("SINGAPORE").Selected; oiPlan.IsTicketOnly = _isTicket; oiPlan.TravelOption = to; oiPlan.OrderID = _newID; oiPlan.Quantity = 1; oiPlan.Sale = null; oiPlan.Place(m, trans); trans.Commit(); ClientScript.RegisterClientScriptBlock(typeof(string), "succeed", string.Format("alert('订单({0})保存成功');window.location.href = 'ServerOrderView.ashx?OrderID={0}'", _newID.ToString()), true); } catch (Exception ex) { trans.Rollback(); ClientScript.RegisterClientScriptBlock(typeof(string), "failed", string.Format("alert('{0}')", ex.Message.ToString()), true); } //conn.Close(); } }