private void update(HttpContext context) { model = bll.GetModel(context.Request["LoginName"].ToString());//根据loginname(用户名)得到实体并且赋到model里面 if (context.Request["CustomerName"].ToString() != null) { model.CustomerName = context.Request["CustomerName"].ToString(); } if (context.Request["Sex"].ToString() != null) { model.Sex = context.Request["Sex"].ToString(); } if (context.Request["PhoneNum"].ToString() != null) { model.PhoneNum = context.Request["PhoneNum"].ToString(); } if (context.Request["Email"].ToString() != null) { model.Email = context.Request["Email"].ToString(); } if (bll.Update(model)) { context.Response.Write("{\"Result\":\"1\"}"); } else { context.Response.Write("{\"Result\":\"0\"}"); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(CarSpirits.Model.Customer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Customer set "); strSql.Append("CustomerID=@CustomerID,"); strSql.Append("CustomerName=@CustomerName,"); strSql.Append("LoginName=@LoginName,"); strSql.Append("LoginPwd=@LoginPwd,"); strSql.Append("Sex=@Sex,"); strSql.Append("PhoneNum=@PhoneNum,"); strSql.Append("Email=@Email,"); strSql.Append("Remark=@Remark,"); strSql.Append("CreateDate=@CreateDate"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@CustomerID", SqlDbType.NVarChar, 50), new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50), new SqlParameter("@LoginName", SqlDbType.NVarChar, 100), new SqlParameter("@LoginPwd", SqlDbType.NVarChar, 100), new SqlParameter("@Sex", SqlDbType.NVarChar, 20), new SqlParameter("@PhoneNum", SqlDbType.NVarChar, 50), new SqlParameter("@Email", SqlDbType.NVarChar, 50), new SqlParameter("@Remark", SqlDbType.NVarChar, 255), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.CustomerID; parameters[1].Value = model.CustomerName; parameters[2].Value = model.LoginName; parameters[3].Value = model.LoginPwd; parameters[4].Value = model.Sex; parameters[5].Value = model.PhoneNum; parameters[6].Value = model.Email; parameters[7].Value = model.Remark; parameters[8].Value = model.CreateDate; parameters[9].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void getpwd(HttpContext context) { if (bll.Exists(context.Request["LoginName"].ToString(), context.Request["PhoneNum"].ToString(), context.Request["Email"].ToString())) { model = bll.GetModel(context.Request["LoginName"].ToString()); model.LoginPwd = context.Request["LoginPwd"].ToString(); bll.Update(model); context.Response.Write("{\"Result\":\"1\",\"LoginPwd\":\"" + model.LoginPwd + "\"}"); } else { context.Response.Write("{\"Result\":\"0\"}"); } }
private void updatepwd(HttpContext context) { model = bll.GetModel(context.Request["LoginName"].ToString());//根据loginname得到实体并且赋到model里面 model.LoginPwd = context.Request["LoginPwd"].ToString(); if (bll.Update(model)) { context.Response.Write("{\"Result\":\"1\"}"); } else { context.Response.Write("{\"Result\":\"0\"}"); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CarSpirits.Model.Customer DataRowToModel(DataRow row) { CarSpirits.Model.Customer model = new CarSpirits.Model.Customer(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["CustomerID"] != null) { model.CustomerID = row["CustomerID"].ToString(); } if (row["CustomerName"] != null) { model.CustomerName = row["CustomerName"].ToString(); } if (row["LoginName"] != null) { model.LoginName = row["LoginName"].ToString(); } if (row["LoginPwd"] != null) { model.LoginPwd = row["LoginPwd"].ToString(); } if (row["Sex"] != null) { model.Sex = row["Sex"].ToString(); } if (row["PhoneNum"] != null) { model.PhoneNum = row["PhoneNum"].ToString(); } if (row["Email"] != null) { model.Email = row["Email"].ToString(); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } if (row["CreateDate"] != null && row["CreateDate"].ToString() != "") { model.CreateDate = DateTime.Parse(row["CreateDate"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(CarSpirits.Model.Customer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Customer("); strSql.Append("CustomerID,CustomerName,LoginName,LoginPwd,Sex,PhoneNum,Email,Remark)"); strSql.Append(" values ("); strSql.Append("@CustomerID,@CustomerName,@LoginName,@LoginPwd,@Sex,@PhoneNum,@Email,@Remark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CustomerID", SqlDbType.NVarChar, 50), new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50), new SqlParameter("@LoginName", SqlDbType.NVarChar, 100), new SqlParameter("@LoginPwd", SqlDbType.NVarChar, 100), new SqlParameter("@Sex", SqlDbType.NVarChar, 20), new SqlParameter("@PhoneNum", SqlDbType.NVarChar, 50), new SqlParameter("@Email", SqlDbType.NVarChar, 50), new SqlParameter("@Remark", SqlDbType.NVarChar, 255), new SqlParameter("@CreateDate", SqlDbType.DateTime) }; parameters[0].Value = model.CustomerID; parameters[1].Value = model.CustomerName; parameters[2].Value = model.LoginName; parameters[3].Value = model.LoginPwd; parameters[4].Value = model.Sex; parameters[5].Value = model.PhoneNum; parameters[6].Value = model.Email; parameters[7].Value = model.Remark; parameters[8].Value = model.CreateDate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 取得数据 /// </summary> /// <param name="id"></param> /// <returns></returns> private CarSpirits.Model.Customer GetData(int id) { CarSpirits.Model.Customer model = new CarSpirits.Model.Customer(); if (id > 0) { model = bll.GetModel(id); } else { } model.CustomerID = System.Guid.NewGuid().ToString(); model.CustomerName = Request.Form["ipt_customername"] != "" ? Request.Form["ipt_customername"] : ""; model.LoginName = Request.Form["ipt_loginname"] != "" ? Request.Form["ipt_loginname"] : ""; model.LoginPwd = Request.Form["ipt_loginpwd"] != "" ? Request.Form["ipt_loginpwd"] : ""; model.Sex = Request.Form["ipt_sex"] != "" ? Request.Form["ipt_sex"] : ""; model.PhoneNum = Request.Form["ipt_phonenum"] != "" ? Request.Form["ipt_phonenum"] : ""; model.Email = Request.Form["ipt_email"] != "" ? Request.Form["ipt_email"] : ""; model.Remark = Request.Form["ipt_remark"] != "" ? Request.Form["ipt_remark"] : ""; return(model); }
public CarSpirits.Model.Customer GetModel(string LoginName) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,CustomerID,CustomerName,LoginName,LoginPwd,Sex,PhoneNum,Email,Remark,CreateDate from Customer "); strSql.Append(" where LoginName=@LoginName "); SqlParameter[] parameters = { new SqlParameter("@LoginName", SqlDbType.NVarChar, 100) }; parameters[0].Value = LoginName; CarSpirits.Model.Customer model = new CarSpirits.Model.Customer(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 添加或修改数据 /// </summary> private void UpdateData() { int id = Request.Form["id"] != "" ? Convert.ToInt32(Request.Form["id"]) : 0; CarSpirits.Model.Customer model = GetData(id); string writeMsg = "操作失败!"; if (model != null) { if (id < 1) { if (bll.Add(model) > 0) { writeMsg = "增加成功!"; } else { writeMsg = "增加失败!"; } } else { if (bll.Update(model)) { writeMsg = "更新成功!"; } else { writeMsg = "更新失败!"; } } } Response.Clear(); Response.Write(writeMsg); Response.End(); }