public void Insert(Model.UserAddress model) { if (!list.Contains(model)) { list.Add(model); } }
private void OnSaveAddress() { if (profile == null) { profile = new CustomProfileCommon(); } if (profile.UserAddress.Count >= 5) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "当前地址数量已达上限(5个),若要继续添加新地址,请先删除部分收货地址。"); return; } Model.UserAddress model = new Model.UserAddress(); if (!OnCheckForm(ref model)) { return; } model.NumberID = Guid.NewGuid(); List <Model.UserAddress> list = profile.UserAddress.GetList(); foreach (Model.UserAddress item in list) { item.IsDefault = false; } profile.UserAddress.Insert(model); profile.Save(); BindAddress(); BindSelectAddress(); }
private void OnEditAddress() { string numberId = hNId.Value.Trim(); if (!string.IsNullOrEmpty(numberId)) { if (profile == null) { profile = new CustomProfileCommon(); } Model.UserAddress model = profile.UserAddress.GetModel(Guid.Parse(numberId)); if (!OnCheckForm(ref model)) { return; } if (model != null) { profile.UserAddress.Update(model); profile.Save(); BindAddress(); BindSelectAddress(); hOp.Value = "savaAddress"; } } }
private void OnCommit() { bool hasSucceed = false; if (profile == null) { profile = new CustomProfileCommon(); } if (!nId.Equals(Guid.Empty)) { List <Model.UserAddress> list = profile.UserAddress.GetList(); Model.UserAddress updateModel = list.Find(delegate(Model.UserAddress m) { return(m.NumberID == nId); }); if (updateModel != null) { if (!OnCheckForm(ref updateModel)) { return; } profile.UserAddress.Update(updateModel); hasSucceed = true; } } else { if (profile.UserAddress.Count >= 5) { WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "当前地址数量已达上限(5个),若要继续添加新地址,请先删除部分收货地址。", "操作错误", "error"); return; } List <Model.UserAddress> list = profile.UserAddress.GetList(); Model.UserAddress model = new Model.UserAddress(); if (!OnCheckForm(ref model)) { return; } Model.UserAddress model2 = list.Find(delegate(Model.UserAddress m) { return(m.Receiver == model.Receiver && m.ProvinceCity == model.ProvinceCity && m.Address == model.Address && m.Mobilephone == model.Mobilephone && m.Telephone == model.Telephone && m.Email == model.Email); }); if (model2 != null) { WebHelper.MessageBox.Messager(this.Page, lbtnPostBack, "已存在相同记录,请检查"); return; } model.NumberID = Guid.NewGuid(); profile.UserAddress.Insert(model); hasSucceed = true; } if (hasSucceed) { profile.Save(); WebHelper.MessageBox.Show(this.Page, lbtnPostBack, "操作成功", "ListAddress.aspx"); } }
public void Update(Model.UserAddress model) { int i = list.FindIndex(delegate(Model.UserAddress m) { return(m.NumberID == model.NumberID); }); if (i >= 0) { list.IndexOf(model, i); } }
/// <summary> /// 增加一条数据 /// </summary> public static int Add(Model.UserAddress model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into UserAddress("); strSql.Append("relName,mobile,tel,qq,weixin,zipcode,pid,cid,regionId,address,addressDetail,status,remark,addTime,addUser,infoType)"); strSql.Append(" values ("); strSql.Append("@relName,@mobile,@tel,@qq,@weixin,@zipcode,@pid,@cid,@regionId,@address,@addressDetail,@status,@remark,@addTime,@addUser,@infoType)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@relName", SqlDbType.VarChar, 50), new SqlParameter("@mobile", SqlDbType.VarChar, 50), new SqlParameter("@tel", SqlDbType.VarChar, 50), new SqlParameter("@qq", SqlDbType.VarChar, 50), new SqlParameter("@weixin", SqlDbType.VarChar, 50), new SqlParameter("@zipcode", SqlDbType.VarChar, 50), new SqlParameter("@pid", SqlDbType.Int, 4), new SqlParameter("@cid", SqlDbType.Int, 4), new SqlParameter("@regionId", SqlDbType.Int, 4), new SqlParameter("@address", SqlDbType.VarChar, 150), new SqlParameter("@addressDetail", SqlDbType.VarChar, 150), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@remark", SqlDbType.VarChar, 150), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@addUser", SqlDbType.Int, 4), new SqlParameter("@infoType", SqlDbType.Int, 4) }; parameters[0].Value = model.relName; parameters[1].Value = model.mobile; parameters[2].Value = model.tel; parameters[3].Value = model.qq; parameters[4].Value = model.weixin; parameters[5].Value = model.zipcode; parameters[6].Value = model.pid; parameters[7].Value = model.cid; parameters[8].Value = model.regionId; parameters[9].Value = model.address; parameters[10].Value = model.addressDetail; parameters[11].Value = model.status; parameters[12].Value = model.remark; parameters[13].Value = model.addTime; parameters[14].Value = model.addUser; parameters[15].Value = model.infoType; object obj = DBHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void OnChangeAddress() { string numberId = hNId.Value.Trim(); if (!string.IsNullOrEmpty(numberId)) { if (profile == null) { profile = new CustomProfileCommon(); } Model.UserAddress selectModel = profile.UserAddress.GetModel(Guid.Parse(numberId)); if (selectModel != null) { ltrHasAddress.Text = string.Format("<p>{3} {2} <br />{1} {0} </p>", selectModel.Address, selectModel.ProvinceCity.Replace("-", " "), selectModel.Mobilephone + " " + selectModel.Telephone, selectModel.Receiver); } } }
private void BindSelectAddress() { if (profile == null) { profile = new CustomProfileCommon(); } List <Model.UserAddress> list = profile.UserAddress.GetList(); if (list != null && list.Count > 0) { Model.UserAddress selectModel = list.Find(delegate(Model.UserAddress m) { return(m.IsDefault == true); }); if (selectModel == null) { selectModel = list.Find(delegate(Model.UserAddress m) { return(m.LastUpdatedDate == list.Max(mi => mi.LastUpdatedDate)); }); } ltrHasAddress.Text = string.Format("<p>{3} {2} <br />{1} {0} </p>", selectModel.Address, selectModel.ProvinceCity.Replace("-", " "), selectModel.Mobilephone + " " + selectModel.Telephone, selectModel.Receiver); hNId.Value = selectModel.NumberID.ToString(); } }
private void Bind() { if (!nId.Equals(Guid.Empty)) { if (profile == null) { profile = new CustomProfileCommon(); } Model.UserAddress model = profile.UserAddress.GetModel(nId); if (model != null) { txtReceiver.Value = model.Receiver; txtProvinceCity.Value = model.ProvinceCity; txtAddress.Value = model.Address; txtMobilephone.Value = model.Mobilephone; txtTelephone.Value = model.Telephone; txtEmail.Value = model.Email; } } }
private void OnEditGetAddress() { string numberId = hNId.Value.Trim(); if (!string.IsNullOrEmpty(numberId)) { if (profile == null) { profile = new CustomProfileCommon(); } Model.UserAddress model = profile.UserAddress.GetModel(Guid.Parse(numberId)); if (model != null) { txtReceiver.Value = model.Receiver; txtProvinceCity.Value = model.ProvinceCity; txtAddress.Value = model.Address; txtMobilephone.Value = model.Mobilephone; txtTelephone.Value = model.Telephone; txtEmail.Value = model.Email; hOp.Value = "editAddress"; } } }
/// <summary> /// 得到一个对象实体 /// </summary> public static Model.UserAddress GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,relName,mobile,tel,qq,weixin,zipcode,pid,cid,regionId,address,addressDetail,status,remark,addTime,addUser,infoType from UserAddress "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.UserAddress model = new Model.UserAddress(); DataSet ds = DBHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void OnCommit() { if (WebHelper.Common.GetUserId() != Guid.Empty) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请先登录再执行操作"); return; } string addressId = hNId.Value.Trim(); if (string.IsNullOrEmpty(addressId)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请选择收货人信息", "操作错误", "error"); return; } if (profile == null) { profile = new CustomProfileCommon(); } Model.UserAddress addressModel = profile.UserAddress.GetModel(Guid.Parse(addressId)); if (addressModel == null) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "不存在当前收货人信息记录,请检查", "操作错误", "error"); return; } string payOption = selectPay.InnerText.Trim(); if (string.IsNullOrEmpty(payOption)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请选择支付及配送方式", "操作错误", "error"); return; } int totalCount = profile.ShoppingCart.Count; decimal totalPrice = profile.ShoppingCart.TotalPrice; if (totalCount < 1) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "商品清单不存在任何商品,请检查", "操作错误", "error"); return; } string sProducts = ""; ICollection <Model.CartItemInfo> items = profile.ShoppingCart.CartItems; foreach (Model.CartItemInfo item in items) { sProducts += string.Format("{2},{1},{0}|", item.Subtotal, item.Quantity, item.ProductId); } sProducts = sProducts.Trim('|'); DateTime dtime = DateTime.Now; Model.OrderInfo model = new Model.OrderInfo(); model.OrderNum = WebHelper.CustomsHelper.CreateDateTimeString(); model.UserId = WebHelper.Common.GetUserId(); model.Receiver = addressModel.Receiver; model.ProviceCity = addressModel.ProvinceCity; model.Address = addressModel.Address; model.Mobilephone = addressModel.Mobilephone; model.Telephone = addressModel.Telephone; model.Email = addressModel.Email; model.Products = sProducts; model.TotalCount = totalCount; model.TotalPrice = totalPrice; model.PayOption = payOption; model.LastUpdatedDate = dtime; model.CreateDate = dtime; string errorMsg = ""; try { TransactionOptions options = new TransactionOptions(); options.IsolationLevel = IsolationLevel.ReadUncommitted; options.Timeout = TimeSpan.FromSeconds(90); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { if (bll == null) { bll = new BLL.OrderInfo(); } if (bll.Insert(model) > 0) { profile.ShoppingCart.Clear(); profile.Save(); } //提交事务 scope.Complete(); } Response.Redirect(string.Format("AddOrderSucceed.aspx?oN={0}", HttpUtility.UrlEncode(model.OrderNum)), true); } catch (Exception ex) { errorMsg = ex.Message; } if (!string.IsNullOrEmpty(errorMsg)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, errorMsg, "系统异常提醒"); return; } }
private bool OnCheckForm(ref Model.UserAddress model) { #region 获取输入并验证 string sReceiver = txtReceiver.Value.Trim(); if (string.IsNullOrEmpty(sReceiver)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请您填写收货人姓名", "操作错误", "error"); return(false); } string sProvinceCity = txtProvinceCity.Value.Trim(); if (string.IsNullOrEmpty(sProvinceCity)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请选择所在地区", "操作错误", "error"); return(false); } string[] pArr = sProvinceCity.Split('-'); if (pArr.Length != 3) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请正确选择所在地区中的省市区", "操作错误", "error"); return(false); } string sAddress = txtAddress.Value.Trim(); if (string.IsNullOrEmpty(sAddress)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请填写详细地址", "操作错误", "error"); return(false); } string sMobilephone = txtMobilephone.Value.Trim(); string sTelephone = txtTelephone.Value.Trim(); if (string.IsNullOrEmpty(sMobilephone) && string.IsNullOrEmpty(sTelephone)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "手机或固定电话至少填写一个", "操作错误", "error"); return(false); } Regex r = null; if (!string.IsNullOrEmpty(sMobilephone)) { r = new Regex(@"^1[3|4|5|8][0-9]\d{4,8}$"); if (!r.IsMatch(sMobilephone)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请输入正确的手机号码格式", "操作错误", "error"); return(false); } } if (!string.IsNullOrEmpty(sTelephone)) { r = new Regex(@"(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}"); if (!r.IsMatch(sTelephone)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请输入正确的电话号码格式", "操作错误", "error"); return(false); } } string sEmail = txtEmail.Value.Trim(); if (!string.IsNullOrEmpty(sEmail)) { r = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); if (!r.IsMatch(sEmail)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "请输入正确的电子邮箱格式", "操作错误", "error"); return(false); } } model.Receiver = sReceiver; model.ProvinceCity = sProvinceCity; model.Address = sAddress; model.Mobilephone = sMobilephone; model.Telephone = sTelephone; model.Email = sEmail; model.IsDefault = true; model.LastUpdatedDate = DateTime.Now; #endregion return(true); }
/// <summary> /// 得到一个对象实体 /// </summary> public static Model.UserAddress DataRowToModel(DataRow row) { Model.UserAddress model = new Model.UserAddress(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["relName"] != null) { model.relName = row["relName"].ToString(); } if (row["mobile"] != null) { model.mobile = row["mobile"].ToString(); } if (row["tel"] != null) { model.tel = row["tel"].ToString(); } if (row["qq"] != null) { model.qq = row["qq"].ToString(); } if (row["weixin"] != null) { model.weixin = row["weixin"].ToString(); } if (row["zipcode"] != null) { model.zipcode = row["zipcode"].ToString(); } if (row["pid"] != null && row["pid"].ToString() != "") { model.pid = int.Parse(row["pid"].ToString()); } if (row["cid"] != null && row["cid"].ToString() != "") { model.cid = int.Parse(row["cid"].ToString()); } if (row["regionId"] != null && row["regionId"].ToString() != "") { model.regionId = int.Parse(row["regionId"].ToString()); } if (row["address"] != null) { model.address = row["address"].ToString(); } if (row["addressDetail"] != null) { model.addressDetail = row["addressDetail"].ToString(); } if (row["status"] != null && row["status"].ToString() != "") { model.status = int.Parse(row["status"].ToString()); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } if (row["addTime"] != null && row["addTime"].ToString() != "") { model.addTime = DateTime.Parse(row["addTime"].ToString()); } if (row["addUser"] != null && row["addUser"].ToString() != "") { model.addUser = int.Parse(row["addUser"].ToString()); } if (row["infoType"] != null && row["infoType"].ToString() != "") { model.infoType = int.Parse(row["infoType"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(Model.UserAddress model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update UserAddress set "); strSql.Append("relName=@relName,"); strSql.Append("mobile=@mobile,"); strSql.Append("tel=@tel,"); strSql.Append("qq=@qq,"); strSql.Append("weixin=@weixin,"); strSql.Append("zipcode=@zipcode,"); strSql.Append("pid=@pid,"); strSql.Append("cid=@cid,"); strSql.Append("regionId=@regionId,"); strSql.Append("address=@address,"); strSql.Append("addressDetail=@addressDetail,"); strSql.Append("status=@status,"); strSql.Append("remark=@remark,"); strSql.Append("addTime=@addTime,"); strSql.Append("addUser=@addUser,"); strSql.Append("infoType=@infoType"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@relName", SqlDbType.VarChar, 50), new SqlParameter("@mobile", SqlDbType.VarChar, 50), new SqlParameter("@tel", SqlDbType.VarChar, 50), new SqlParameter("@qq", SqlDbType.VarChar, 50), new SqlParameter("@weixin", SqlDbType.VarChar, 50), new SqlParameter("@zipcode", SqlDbType.VarChar, 50), new SqlParameter("@pid", SqlDbType.Int, 4), new SqlParameter("@cid", SqlDbType.Int, 4), new SqlParameter("@regionId", SqlDbType.Int, 4), new SqlParameter("@address", SqlDbType.VarChar, 150), new SqlParameter("@addressDetail", SqlDbType.VarChar, 150), new SqlParameter("@status", SqlDbType.Int, 4), new SqlParameter("@remark", SqlDbType.VarChar, 150), new SqlParameter("@addTime", SqlDbType.DateTime), new SqlParameter("@addUser", SqlDbType.Int, 4), new SqlParameter("@infoType", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.relName; parameters[1].Value = model.mobile; parameters[2].Value = model.tel; parameters[3].Value = model.qq; parameters[4].Value = model.weixin; parameters[5].Value = model.zipcode; parameters[6].Value = model.pid; parameters[7].Value = model.cid; parameters[8].Value = model.regionId; parameters[9].Value = model.address; parameters[10].Value = model.addressDetail; parameters[11].Value = model.status; parameters[12].Value = model.remark; parameters[13].Value = model.addTime; parameters[14].Value = model.addUser; parameters[15].Value = model.infoType; parameters[16].Value = model.id; int rows = DBHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }