/// <summary> /// 增加一条数据 /// </summary> public int Add(Bsam.Core.Model.Models.Model.sysUserInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into sysUserInfo("); strSql.Append("uLoginName,uLoginPWD,uRealName,uStatus,uRemark,uCreateTime,uUpdateTime,uLastErrTime,uErrorCount,name,sex,age,birth,addr,tdIsDelete)"); strSql.Append(" values ("); strSql.Append("@uLoginName,@uLoginPWD,@uRealName,@uStatus,@uRemark,@uCreateTime,@uUpdateTime,@uLastErrTime,@uErrorCount,@name,@sex,@age,@birth,@addr,@tdIsDelete)"); strSql.Append(";select LAST_INSERT_ROWID()"); SQLiteParameter[] parameters = { new SQLiteParameter("@uLoginName", DbType.String), new SQLiteParameter("@uLoginPWD", DbType.String), new SQLiteParameter("@uRealName", DbType.String), new SQLiteParameter("@uStatus", DbType.Int32, 8), new SQLiteParameter("@uRemark", DbType.String), new SQLiteParameter("@uCreateTime", DbType.DateTime), new SQLiteParameter("@uUpdateTime", DbType.DateTime), new SQLiteParameter("@uLastErrTime", DbType.DateTime), new SQLiteParameter("@uErrorCount", DbType.Int32, 8), new SQLiteParameter("@name", DbType.String), new SQLiteParameter("@sex", DbType.Int32, 8), new SQLiteParameter("@age", DbType.Int32, 8), new SQLiteParameter("@birth", DbType.DateTime), new SQLiteParameter("@addr", DbType.String), new SQLiteParameter("@tdIsDelete", DbType.bit, 1) }; parameters[0].Value = model.uLoginName; parameters[1].Value = model.uLoginPWD; parameters[2].Value = model.uRealName; parameters[3].Value = model.uStatus; parameters[4].Value = model.uRemark; parameters[5].Value = model.uCreateTime; parameters[6].Value = model.uUpdateTime; parameters[7].Value = model.uLastErrTime; parameters[8].Value = model.uErrorCount; parameters[9].Value = model.name; parameters[10].Value = model.sex; parameters[11].Value = model.age; parameters[12].Value = model.birth; parameters[13].Value = model.addr; parameters[14].Value = model.tdIsDelete; object obj = DbHelperSQLite.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void ShowInfo(int uID) { Bsam.Core.Model.Models.BLL.sysUserInfo bll = new Bsam.Core.Model.Models.BLL.sysUserInfo(); Bsam.Core.Model.Models.Model.sysUserInfo model = bll.GetModel(uID); this.lbluID.Text = model.uID.ToString(); this.lbluLoginName.Text = model.uLoginName; this.lbluLoginPWD.Text = model.uLoginPWD; this.lbluRealName.Text = model.uRealName; this.lbluStatus.Text = model.uStatus.ToString(); this.lbluRemark.Text = model.uRemark; this.lbluCreateTime.Text = model.uCreateTime.ToString(); this.lbluUpdateTime.Text = model.uUpdateTime.ToString(); this.lbluLastErrTime.Text = model.uLastErrTime.ToString(); this.lbluErrorCount.Text = model.uErrorCount.ToString(); this.lblname.Text = model.name; this.lblsex.Text = model.sex.ToString(); this.lblage.Text = model.age.ToString(); this.lblbirth.Text = model.birth.ToString(); this.lbladdr.Text = model.addr; this.lbltdIsDelete.Text = model.tdIsDelete?"是":"否"; }
private void ShowInfo(int uID) { Bsam.Core.Model.Models.BLL.sysUserInfo bll = new Bsam.Core.Model.Models.BLL.sysUserInfo(); Bsam.Core.Model.Models.Model.sysUserInfo model = bll.GetModel(uID); this.lbluID.Text = model.uID.ToString(); this.txtuLoginName.Text = model.uLoginName; this.txtuLoginPWD.Text = model.uLoginPWD; this.txtuRealName.Text = model.uRealName; this.txtuStatus.Text = model.uStatus.ToString(); this.txtuRemark.Text = model.uRemark; this.txtuCreateTime.Text = model.uCreateTime.ToString(); this.txtuUpdateTime.Text = model.uUpdateTime.ToString(); this.txtuLastErrTime.Text = model.uLastErrTime.ToString(); this.txtuErrorCount.Text = model.uErrorCount.ToString(); this.txtname.Text = model.name; this.txtsex.Text = model.sex.ToString(); this.txtage.Text = model.age.ToString(); this.txtbirth.Text = model.birth.ToString(); this.txtaddr.Text = model.addr; this.chktdIsDelete.Checked = model.tdIsDelete; }
/// <summary> /// 得到一个对象实体 /// </summary> public Bsam.Core.Model.Models.Model.sysUserInfo GetModel(int uID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select uID,uLoginName,uLoginPWD,uRealName,uStatus,uRemark,uCreateTime,uUpdateTime,uLastErrTime,uErrorCount,name,sex,age,birth,addr,tdIsDelete from sysUserInfo "); strSql.Append(" where uID=@uID"); SQLiteParameter[] parameters = { new SQLiteParameter("@uID", DbType.Int32, 4) }; parameters[0].Value = uID; Bsam.Core.Model.Models.Model.sysUserInfo model = new Bsam.Core.Model.Models.Model.sysUserInfo(); DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Bsam.Core.Model.Models.Model.sysUserInfo DataRowToModel(DataRow row) { Bsam.Core.Model.Models.Model.sysUserInfo model = new Bsam.Core.Model.Models.Model.sysUserInfo(); if (row != null) { if (row["uID"] != null && row["uID"].ToString() != "") { model.uID = int.Parse(row["uID"].ToString()); } if (row["uLoginName"] != null) { model.uLoginName = row["uLoginName"].ToString(); } if (row["uLoginPWD"] != null) { model.uLoginPWD = row["uLoginPWD"].ToString(); } if (row["uRealName"] != null) { model.uRealName = row["uRealName"].ToString(); } if (row["uStatus"] != null && row["uStatus"].ToString() != "") { model.uStatus = int.Parse(row["uStatus"].ToString()); } if (row["uRemark"] != null) { model.uRemark = row["uRemark"].ToString(); } if (row["uCreateTime"] != null && row["uCreateTime"].ToString() != "") { model.uCreateTime = DateTime.Parse(row["uCreateTime"].ToString()); } if (row["uUpdateTime"] != null && row["uUpdateTime"].ToString() != "") { model.uUpdateTime = DateTime.Parse(row["uUpdateTime"].ToString()); } if (row["uLastErrTime"] != null && row["uLastErrTime"].ToString() != "") { model.uLastErrTime = DateTime.Parse(row["uLastErrTime"].ToString()); } if (row["uErrorCount"] != null && row["uErrorCount"].ToString() != "") { model.uErrorCount = int.Parse(row["uErrorCount"].ToString()); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["sex"] != null && row["sex"].ToString() != "") { model.sex = int.Parse(row["sex"].ToString()); } if (row["age"] != null && row["age"].ToString() != "") { model.age = int.Parse(row["age"].ToString()); } if (row["birth"] != null && row["birth"].ToString() != "") { model.birth = DateTime.Parse(row["birth"].ToString()); } if (row["addr"] != null) { model.addr = row["addr"].ToString(); } if (row["tdIsDelete"] != null && row["tdIsDelete"].ToString() != "") { if ((row["tdIsDelete"].ToString() == "1") || (row["tdIsDelete"].ToString().ToLower() == "true")) { model.tdIsDelete = true; } else { model.tdIsDelete = false; } } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Bsam.Core.Model.Models.Model.sysUserInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update sysUserInfo set "); strSql.Append("uLoginName=@uLoginName,"); strSql.Append("uLoginPWD=@uLoginPWD,"); strSql.Append("uRealName=@uRealName,"); strSql.Append("uStatus=@uStatus,"); strSql.Append("uRemark=@uRemark,"); strSql.Append("uCreateTime=@uCreateTime,"); strSql.Append("uUpdateTime=@uUpdateTime,"); strSql.Append("uLastErrTime=@uLastErrTime,"); strSql.Append("uErrorCount=@uErrorCount,"); strSql.Append("name=@name,"); strSql.Append("sex=@sex,"); strSql.Append("age=@age,"); strSql.Append("birth=@birth,"); strSql.Append("addr=@addr,"); strSql.Append("tdIsDelete=@tdIsDelete"); strSql.Append(" where uID=@uID"); SQLiteParameter[] parameters = { new SQLiteParameter("@uLoginName", DbType.String), new SQLiteParameter("@uLoginPWD", DbType.String), new SQLiteParameter("@uRealName", DbType.String), new SQLiteParameter("@uStatus", DbType.Int32, 8), new SQLiteParameter("@uRemark", DbType.String), new SQLiteParameter("@uCreateTime", DbType.DateTime), new SQLiteParameter("@uUpdateTime", DbType.DateTime), new SQLiteParameter("@uLastErrTime", DbType.DateTime), new SQLiteParameter("@uErrorCount", DbType.Int32, 8), new SQLiteParameter("@name", DbType.String), new SQLiteParameter("@sex", DbType.Int32, 8), new SQLiteParameter("@age", DbType.Int32, 8), new SQLiteParameter("@birth", DbType.DateTime), new SQLiteParameter("@addr", DbType.String), new SQLiteParameter("@tdIsDelete", DbType.bit, 1), new SQLiteParameter("@uID", DbType.Int32, 8) }; parameters[0].Value = model.uLoginName; parameters[1].Value = model.uLoginPWD; parameters[2].Value = model.uRealName; parameters[3].Value = model.uStatus; parameters[4].Value = model.uRemark; parameters[5].Value = model.uCreateTime; parameters[6].Value = model.uUpdateTime; parameters[7].Value = model.uLastErrTime; parameters[8].Value = model.uErrorCount; parameters[9].Value = model.name; parameters[10].Value = model.sex; parameters[11].Value = model.age; parameters[12].Value = model.birth; parameters[13].Value = model.addr; parameters[14].Value = model.tdIsDelete; parameters[15].Value = model.uID; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtuLoginName.Text.Trim().Length == 0) { strErr += "uLoginName不能为空!\\n"; } if (this.txtuLoginPWD.Text.Trim().Length == 0) { strErr += "uLoginPWD不能为空!\\n"; } if (this.txtuRealName.Text.Trim().Length == 0) { strErr += "uRealName不能为空!\\n"; } if (!PageValidate.IsNumber(txtuStatus.Text)) { strErr += "uStatus格式错误!\\n"; } if (this.txtuRemark.Text.Trim().Length == 0) { strErr += "uRemark不能为空!\\n"; } if (!PageValidate.IsDateTime(txtuCreateTime.Text)) { strErr += "uCreateTime格式错误!\\n"; } if (!PageValidate.IsDateTime(txtuUpdateTime.Text)) { strErr += "uUpdateTime格式错误!\\n"; } if (!PageValidate.IsDateTime(txtuLastErrTime.Text)) { strErr += "uLastErrTime格式错误!\\n"; } if (!PageValidate.IsNumber(txtuErrorCount.Text)) { strErr += "uErrorCount格式错误!\\n"; } if (this.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (!PageValidate.IsNumber(txtsex.Text)) { strErr += "sex格式错误!\\n"; } if (!PageValidate.IsNumber(txtage.Text)) { strErr += "age格式错误!\\n"; } if (!PageValidate.IsDateTime(txtbirth.Text)) { strErr += "birth格式错误!\\n"; } if (this.txtaddr.Text.Trim().Length == 0) { strErr += "addr不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int uID = int.Parse(this.lbluID.Text); string uLoginName = this.txtuLoginName.Text; string uLoginPWD = this.txtuLoginPWD.Text; string uRealName = this.txtuRealName.Text; int uStatus = int.Parse(this.txtuStatus.Text); string uRemark = this.txtuRemark.Text; DateTime uCreateTime = DateTime.Parse(this.txtuCreateTime.Text); DateTime uUpdateTime = DateTime.Parse(this.txtuUpdateTime.Text); DateTime uLastErrTime = DateTime.Parse(this.txtuLastErrTime.Text); int uErrorCount = int.Parse(this.txtuErrorCount.Text); string name = this.txtname.Text; int sex = int.Parse(this.txtsex.Text); int age = int.Parse(this.txtage.Text); DateTime birth = DateTime.Parse(this.txtbirth.Text); string addr = this.txtaddr.Text; bool tdIsDelete = this.chktdIsDelete.Checked; Bsam.Core.Model.Models.Model.sysUserInfo model = new Bsam.Core.Model.Models.Model.sysUserInfo(); model.uID = uID; model.uLoginName = uLoginName; model.uLoginPWD = uLoginPWD; model.uRealName = uRealName; model.uStatus = uStatus; model.uRemark = uRemark; model.uCreateTime = uCreateTime; model.uUpdateTime = uUpdateTime; model.uLastErrTime = uLastErrTime; model.uErrorCount = uErrorCount; model.name = name; model.sex = sex; model.age = age; model.birth = birth; model.addr = addr; model.tdIsDelete = tdIsDelete; Bsam.Core.Model.Models.BLL.sysUserInfo bll = new Bsam.Core.Model.Models.BLL.sysUserInfo(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }