/// <summary> /// 更新一条数据 /// </summary> public bool Update(DNSABC.Model.DNSABC_UserPerson model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update DNSABC_UserPerson set "); strSql.Append("UserId=@UserId,"); strSql.Append("Name=@Name,"); strSql.Append("Position=@Position,"); strSql.Append("Mobil=@Mobil,"); strSql.Append("Tel=@Tel,"); strSql.Append("Qq=@Qq,"); strSql.Append("Email=@Email,"); strSql.Append("Remark=@Remark,"); strSql.Append("UpdateTime=@UpdateTime,"); strSql.Append("CreateTime=@CreateTime"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.VarChar, 50), new SqlParameter("@Position", SqlDbType.VarChar, 50), new SqlParameter("@Mobil", SqlDbType.VarChar, 20), new SqlParameter("@Tel", SqlDbType.VarChar, 20), new SqlParameter("@Qq", SqlDbType.Int, 4), new SqlParameter("@Email", SqlDbType.VarChar, 50), new SqlParameter("@Remark", SqlDbType.VarChar, 500), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.Name; parameters[2].Value = model.Position; parameters[3].Value = model.Mobil; parameters[4].Value = model.Tel; parameters[5].Value = model.Qq; parameters[6].Value = model.Email; parameters[7].Value = model.Remark; parameters[8].Value = model.UpdateTime; parameters[9].Value = model.CreateTime; parameters[10].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(int Id) { DNSABC.BLL.DNSABC_UserPerson bll = new DNSABC.BLL.DNSABC_UserPerson(); DNSABC.Model.DNSABC_UserPerson model = bll.GetModel(Id); this.lblId.Text = model.Id.ToString(); this.txtUserId.Text = model.UserId.ToString(); this.txtName.Text = model.Name; this.txtPosition.Text = model.Position; this.txtMobil.Text = model.Mobil; this.txtTel.Text = model.Tel; this.txtQq.Text = model.Qq.ToString(); this.txtEmail.Text = model.Email; this.txtRemark.Text = model.Remark; this.txtUpdateTime.Text = model.UpdateTime.ToString(); this.txtCreateTime.Text = model.CreateTime.ToString(); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DNSABC.Model.DNSABC_UserPerson model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into DNSABC_UserPerson("); strSql.Append("UserId,Name,Position,Mobil,Tel,Qq,Email,Remark,UpdateTime,CreateTime)"); strSql.Append(" values ("); strSql.Append("@UserId,@Name,@Position,@Mobil,@Tel,@Qq,@Email,@Remark,@UpdateTime,@CreateTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.VarChar, 50), new SqlParameter("@Position", SqlDbType.VarChar, 50), new SqlParameter("@Mobil", SqlDbType.VarChar, 20), new SqlParameter("@Tel", SqlDbType.VarChar, 20), new SqlParameter("@Qq", SqlDbType.Int, 4), new SqlParameter("@Email", SqlDbType.VarChar, 50), new SqlParameter("@Remark", SqlDbType.VarChar, 500), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@CreateTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserId; parameters[1].Value = model.Name; parameters[2].Value = model.Position; parameters[3].Value = model.Mobil; parameters[4].Value = model.Tel; parameters[5].Value = model.Qq; parameters[6].Value = model.Email; parameters[7].Value = model.Remark; parameters[8].Value = model.UpdateTime; parameters[9].Value = model.CreateTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public DNSABC.Model.DNSABC_UserPerson GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,UserId,Name,Position,Mobil,Tel,Qq,Email,Remark,UpdateTime,CreateTime from DNSABC_UserPerson "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; DNSABC.Model.DNSABC_UserPerson model = new DNSABC.Model.DNSABC_UserPerson(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"] != null && ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } if (ds.Tables[0].Rows[0]["UserId"] != null && ds.Tables[0].Rows[0]["UserId"].ToString() != "") { model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); } if (ds.Tables[0].Rows[0]["Name"] != null && ds.Tables[0].Rows[0]["Name"].ToString() != "") { model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); } if (ds.Tables[0].Rows[0]["Position"] != null && ds.Tables[0].Rows[0]["Position"].ToString() != "") { model.Position = ds.Tables[0].Rows[0]["Position"].ToString(); } if (ds.Tables[0].Rows[0]["Mobil"] != null && ds.Tables[0].Rows[0]["Mobil"].ToString() != "") { model.Mobil = ds.Tables[0].Rows[0]["Mobil"].ToString(); } if (ds.Tables[0].Rows[0]["Tel"] != null && ds.Tables[0].Rows[0]["Tel"].ToString() != "") { model.Tel = ds.Tables[0].Rows[0]["Tel"].ToString(); } if (ds.Tables[0].Rows[0]["Qq"] != null && ds.Tables[0].Rows[0]["Qq"].ToString() != "") { model.Qq = int.Parse(ds.Tables[0].Rows[0]["Qq"].ToString()); } if (ds.Tables[0].Rows[0]["Email"] != null && ds.Tables[0].Rows[0]["Email"].ToString() != "") { model.Email = ds.Tables[0].Rows[0]["Email"].ToString(); } if (ds.Tables[0].Rows[0]["Remark"] != null && ds.Tables[0].Rows[0]["Remark"].ToString() != "") { model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString(); } if (ds.Tables[0].Rows[0]["UpdateTime"] != null && ds.Tables[0].Rows[0]["UpdateTime"].ToString() != "") { model.UpdateTime = DateTime.Parse(ds.Tables[0].Rows[0]["UpdateTime"].ToString()); } if (ds.Tables[0].Rows[0]["CreateTime"] != null && ds.Tables[0].Rows[0]["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString()); } return(model); } else { return(null); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtUserId.Text)) { strErr += "用户ID格式错误!\\n"; } if (this.txtName.Text.Trim().Length == 0) { strErr += "姓名不能为空!\\n"; } if (this.txtPosition.Text.Trim().Length == 0) { strErr += "职位不能为空!\\n"; } if (this.txtMobil.Text.Trim().Length == 0) { strErr += "手机 必须要有联系人手机号码不能为空!\\n"; } if (this.txtTel.Text.Trim().Length == 0) { strErr += "电话不能为空!\\n"; } if (!PageValidate.IsNumber(txtQq.Text)) { strErr += "QQ号码格式错误!\\n"; } if (this.txtEmail.Text.Trim().Length == 0) { strErr += "邮箱不能为空!\\n"; } if (this.txtRemark.Text.Trim().Length == 0) { strErr += "备注不能为空!\\n"; } if (!PageValidate.IsDateTime(txtUpdateTime.Text)) { strErr += "更新时间格式错误!\\n"; } if (!PageValidate.IsDateTime(txtCreateTime.Text)) { strErr += "创建时间格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Id = int.Parse(this.lblId.Text); int UserId = int.Parse(this.txtUserId.Text); string Name = this.txtName.Text; string Position = this.txtPosition.Text; string Mobil = this.txtMobil.Text; string Tel = this.txtTel.Text; int Qq = int.Parse(this.txtQq.Text); string Email = this.txtEmail.Text; string Remark = this.txtRemark.Text; DateTime UpdateTime = DateTime.Parse(this.txtUpdateTime.Text); DateTime CreateTime = DateTime.Parse(this.txtCreateTime.Text); DNSABC.Model.DNSABC_UserPerson model = new DNSABC.Model.DNSABC_UserPerson(); model.Id = Id; model.UserId = UserId; model.Name = Name; model.Position = Position; model.Mobil = Mobil; model.Tel = Tel; model.Qq = Qq; model.Email = Email; model.Remark = Remark; model.UpdateTime = UpdateTime; model.CreateTime = CreateTime; DNSABC.BLL.DNSABC_UserPerson bll = new DNSABC.BLL.DNSABC_UserPerson(); bll.Update(model); ROYcms.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }