/// <summary> /// 增加一条数据 /// </summary> public int Add(WebDemo.Model.WebDemo.MultiUser model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MultiUser("); strSql.Append("UserCode,UserName,DeptID,CardId,CardSector,CardSn,Mark,Sex,Phone,PaperType,PaperNo,uAccount,OpenTime,ValidDate,LastMoney,TotalMoney,ReMark)"); strSql.Append(" values ("); strSql.Append("@UserCode,@UserName,@DeptID,@CardId,@CardSector,@CardSn,@Mark,@Sex,@Phone,@PaperType,@PaperNo,@uAccount,@OpenTime,@ValidDate,@LastMoney,@TotalMoney,@ReMark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserCode", SqlDbType.VarChar, 50), new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@DeptID", SqlDbType.VarChar, 50), new SqlParameter("@CardId", SqlDbType.Int, 4), new SqlParameter("@CardSector", SqlDbType.Int, 4), new SqlParameter("@CardSn", SqlDbType.VarChar, 8), new SqlParameter("@Mark", SqlDbType.Int, 4), new SqlParameter("@Sex", SqlDbType.VarChar, 20), new SqlParameter("@Phone", SqlDbType.VarChar, 50), new SqlParameter("@PaperType", SqlDbType.Int, 4), new SqlParameter("@PaperNo", SqlDbType.VarChar, 50), new SqlParameter("@uAccount", SqlDbType.VarChar, 50), new SqlParameter("@OpenTime", SqlDbType.DateTime), new SqlParameter("@ValidDate", SqlDbType.DateTime), new SqlParameter("@LastMoney", SqlDbType.Decimal, 9), new SqlParameter("@TotalMoney", SqlDbType.Decimal, 9), new SqlParameter("@ReMark", SqlDbType.VarChar, 50) }; parameters[0].Value = model.UserCode; parameters[1].Value = model.UserName; parameters[2].Value = model.DeptID; parameters[3].Value = model.CardId; parameters[4].Value = model.CardSector; parameters[5].Value = model.CardSn; parameters[6].Value = model.Mark; parameters[7].Value = model.Sex; parameters[8].Value = model.Phone; parameters[9].Value = model.PaperType; parameters[10].Value = model.PaperNo; parameters[11].Value = model.uAccount; parameters[12].Value = model.OpenTime; parameters[13].Value = model.ValidDate; parameters[14].Value = model.LastMoney; parameters[15].Value = model.TotalMoney; parameters[16].Value = model.ReMark; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void ShowInfo(int MultiUserID) { WebDemo.BLL.WebDemo.MultiUser bll = new WebDemo.BLL.WebDemo.MultiUser(); WebDemo.Model.WebDemo.MultiUser model = bll.GetModel(MultiUserID); this.lblMultiUserID.Text = model.MultiUserID.ToString(); this.txtUserCode.Text = model.UserCode; this.txtUserName.Text = model.UserName; this.txtDeptID.Text = model.DeptID; this.txtCardId.Text = model.CardId.ToString(); this.txtCardSector.Text = model.CardSector.ToString(); this.txtCardSn.Text = model.CardSn; this.txtMark.Text = model.Mark.ToString(); this.txtSex.Text = model.Sex; this.txtPhone.Text = model.Phone; this.txtPaperType.Text = model.PaperType.ToString(); this.txtPaperNo.Text = model.PaperNo; this.txtuAccount.Text = model.uAccount; this.txtOpenTime.Text = model.OpenTime.ToString(); this.txtValidDate.Text = model.ValidDate.ToString(); this.txtLastMoney.Text = model.LastMoney.ToString(); this.txtTotalMoney.Text = model.TotalMoney.ToString(); this.txtReMark.Text = model.ReMark; }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MultiUser GetModel(int MultiUserID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 MultiUserID,UserCode,UserName,DeptID,CardId,CardSector,CardSn,Mark,Sex,Phone,PaperType,PaperNo,uAccount,OpenTime,ValidDate,LastMoney,TotalMoney,ReMark from MultiUser "); strSql.Append(" where MultiUserID=@MultiUserID"); SqlParameter[] parameters = { new SqlParameter("@MultiUserID", SqlDbType.Int, 4) }; parameters[0].Value = MultiUserID; WebDemo.Model.WebDemo.MultiUser model = new WebDemo.Model.WebDemo.MultiUser(); 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> public WebDemo.Model.WebDemo.MultiUser DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.MultiUser model = new WebDemo.Model.WebDemo.MultiUser(); if (row != null) { if (row["MultiUserID"] != null && row["MultiUserID"].ToString() != "") { model.MultiUserID = int.Parse(row["MultiUserID"].ToString()); } if (row["UserCode"] != null) { model.UserCode = row["UserCode"].ToString(); } if (row["UserName"] != null) { model.UserName = row["UserName"].ToString(); } if (row["DeptID"] != null) { model.DeptID = row["DeptID"].ToString(); } if (row["CardId"] != null && row["CardId"].ToString() != "") { model.CardId = int.Parse(row["CardId"].ToString()); } if (row["CardSector"] != null && row["CardSector"].ToString() != "") { model.CardSector = int.Parse(row["CardSector"].ToString()); } if (row["CardSn"] != null) { model.CardSn = row["CardSn"].ToString(); } if (row["Mark"] != null && row["Mark"].ToString() != "") { model.Mark = int.Parse(row["Mark"].ToString()); } if (row["Sex"] != null) { model.Sex = row["Sex"].ToString(); } if (row["Phone"] != null) { model.Phone = row["Phone"].ToString(); } if (row["PaperType"] != null && row["PaperType"].ToString() != "") { model.PaperType = int.Parse(row["PaperType"].ToString()); } if (row["PaperNo"] != null) { model.PaperNo = row["PaperNo"].ToString(); } if (row["uAccount"] != null) { model.uAccount = row["uAccount"].ToString(); } if (row["OpenTime"] != null && row["OpenTime"].ToString() != "") { model.OpenTime = DateTime.Parse(row["OpenTime"].ToString()); } if (row["ValidDate"] != null && row["ValidDate"].ToString() != "") { model.ValidDate = DateTime.Parse(row["ValidDate"].ToString()); } if (row["LastMoney"] != null && row["LastMoney"].ToString() != "") { model.LastMoney = decimal.Parse(row["LastMoney"].ToString()); } if (row["TotalMoney"] != null && row["TotalMoney"].ToString() != "") { model.TotalMoney = decimal.Parse(row["TotalMoney"].ToString()); } if (row["ReMark"] != null) { model.ReMark = row["ReMark"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.MultiUser model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MultiUser set "); strSql.Append("UserCode=@UserCode,"); strSql.Append("UserName=@UserName,"); strSql.Append("DeptID=@DeptID,"); strSql.Append("CardId=@CardId,"); strSql.Append("CardSector=@CardSector,"); strSql.Append("CardSn=@CardSn,"); strSql.Append("Mark=@Mark,"); strSql.Append("Sex=@Sex,"); strSql.Append("Phone=@Phone,"); strSql.Append("PaperType=@PaperType,"); strSql.Append("PaperNo=@PaperNo,"); strSql.Append("uAccount=@uAccount,"); strSql.Append("OpenTime=@OpenTime,"); strSql.Append("ValidDate=@ValidDate,"); strSql.Append("LastMoney=@LastMoney,"); strSql.Append("TotalMoney=@TotalMoney,"); strSql.Append("ReMark=@ReMark"); strSql.Append(" where MultiUserID=@MultiUserID"); SqlParameter[] parameters = { new SqlParameter("@UserCode", SqlDbType.VarChar, 50), new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@DeptID", SqlDbType.VarChar, 50), new SqlParameter("@CardId", SqlDbType.Int, 4), new SqlParameter("@CardSector", SqlDbType.Int, 4), new SqlParameter("@CardSn", SqlDbType.VarChar, 8), new SqlParameter("@Mark", SqlDbType.Int, 4), new SqlParameter("@Sex", SqlDbType.VarChar, 20), new SqlParameter("@Phone", SqlDbType.VarChar, 50), new SqlParameter("@PaperType", SqlDbType.Int, 4), new SqlParameter("@PaperNo", SqlDbType.VarChar, 50), new SqlParameter("@uAccount", SqlDbType.VarChar, 50), new SqlParameter("@OpenTime", SqlDbType.DateTime), new SqlParameter("@ValidDate", SqlDbType.DateTime), new SqlParameter("@LastMoney", SqlDbType.Decimal, 9), new SqlParameter("@TotalMoney", SqlDbType.Decimal, 9), new SqlParameter("@ReMark", SqlDbType.VarChar, 50), new SqlParameter("@MultiUserID", SqlDbType.Int, 4) }; parameters[0].Value = model.UserCode; parameters[1].Value = model.UserName; parameters[2].Value = model.DeptID; parameters[3].Value = model.CardId; parameters[4].Value = model.CardSector; parameters[5].Value = model.CardSn; parameters[6].Value = model.Mark; parameters[7].Value = model.Sex; parameters[8].Value = model.Phone; parameters[9].Value = model.PaperType; parameters[10].Value = model.PaperNo; parameters[11].Value = model.uAccount; parameters[12].Value = model.OpenTime; parameters[13].Value = model.ValidDate; parameters[14].Value = model.LastMoney; parameters[15].Value = model.TotalMoney; parameters[16].Value = model.ReMark; parameters[17].Value = model.MultiUserID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtUserCode.Text.Trim().Length == 0) { strErr += "UserCode不能为空!\\n"; } if (this.txtUserName.Text.Trim().Length == 0) { strErr += "UserName不能为空!\\n"; } if (this.txtDeptID.Text.Trim().Length == 0) { strErr += "DeptID不能为空!\\n"; } if (!PageValidate.IsNumber(txtCardId.Text)) { strErr += "CardId格式错误!\\n"; } if (!PageValidate.IsNumber(txtCardSector.Text)) { strErr += "CardSector格式错误!\\n"; } if (this.txtCardSn.Text.Trim().Length == 0) { strErr += "CardSn不能为空!\\n"; } if (!PageValidate.IsNumber(txtMark.Text)) { strErr += "Mark格式错误!\\n"; } if (this.txtSex.Text.Trim().Length == 0) { strErr += "Sex不能为空!\\n"; } if (this.txtPhone.Text.Trim().Length == 0) { strErr += "Phone不能为空!\\n"; } if (!PageValidate.IsNumber(txtPaperType.Text)) { strErr += "PaperType格式错误!\\n"; } if (this.txtPaperNo.Text.Trim().Length == 0) { strErr += "PaperNo不能为空!\\n"; } if (this.txtuAccount.Text.Trim().Length == 0) { strErr += "uAccount不能为空!\\n"; } if (!PageValidate.IsDateTime(txtOpenTime.Text)) { strErr += "OpenTime格式错误!\\n"; } if (!PageValidate.IsDateTime(txtValidDate.Text)) { strErr += "ValidDate格式错误!\\n"; } if (!PageValidate.IsDecimal(txtLastMoney.Text)) { strErr += "LastMoney格式错误!\\n"; } if (!PageValidate.IsDecimal(txtTotalMoney.Text)) { strErr += "TotalMoney格式错误!\\n"; } if (this.txtReMark.Text.Trim().Length == 0) { strErr += "ReMark不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string UserCode = this.txtUserCode.Text; string UserName = this.txtUserName.Text; string DeptID = this.txtDeptID.Text; int CardId = int.Parse(this.txtCardId.Text); int CardSector = int.Parse(this.txtCardSector.Text); string CardSn = this.txtCardSn.Text; int Mark = int.Parse(this.txtMark.Text); string Sex = this.txtSex.Text; string Phone = this.txtPhone.Text; int PaperType = int.Parse(this.txtPaperType.Text); string PaperNo = this.txtPaperNo.Text; string uAccount = this.txtuAccount.Text; DateTime OpenTime = DateTime.Parse(this.txtOpenTime.Text); DateTime ValidDate = DateTime.Parse(this.txtValidDate.Text); decimal LastMoney = decimal.Parse(this.txtLastMoney.Text); decimal TotalMoney = decimal.Parse(this.txtTotalMoney.Text); string ReMark = this.txtReMark.Text; WebDemo.Model.WebDemo.MultiUser model = new WebDemo.Model.WebDemo.MultiUser(); model.UserCode = UserCode; model.UserName = UserName; model.DeptID = DeptID; model.CardId = CardId; model.CardSector = CardSector; model.CardSn = CardSn; model.Mark = Mark; model.Sex = Sex; model.Phone = Phone; model.PaperType = PaperType; model.PaperNo = PaperNo; model.uAccount = uAccount; model.OpenTime = OpenTime; model.ValidDate = ValidDate; model.LastMoney = LastMoney; model.TotalMoney = TotalMoney; model.ReMark = ReMark; WebDemo.BLL.WebDemo.MultiUser bll = new WebDemo.BLL.WebDemo.MultiUser(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }