private void ShowInfo(int feedbackID) { UFB.BLL.FeedbackManager bll = new UFB.BLL.FeedbackManager(); UFB.Model.Feedback model = bll.GetModel(feedbackID); this.lblfeedbackID.Text = model.feedbackID.ToString(); this.txtUserID.Text = model.UserID.ToString(); this.txtfeedbackTime.Text = model.feedbackTime.ToString(); this.txtcategory.Text = model.category; this.txtInfo.Text = model.Info; this.txtcontact.Text = model.contact; this.txtimage.Text = model.image; this.txtisInvalid.Text = model.isInvalid; this.txtsolutionState.Text = model.solutionState; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(UFB.Model.Feedback model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Feedback set "); strSql.Append("UserID=@UserID,"); strSql.Append("feedbackTime=@feedbackTime,"); strSql.Append("category=@category,"); strSql.Append("Info=@Info,"); strSql.Append("contact=@contact,"); strSql.Append("image=@image,"); strSql.Append("isInvalid=@isInvalid,"); strSql.Append("solutionState=@solutionState"); strSql.Append(" where feedbackID=@feedbackID"); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@feedbackTime", SqlDbType.SmallDateTime), new SqlParameter("@category", SqlDbType.VarChar, 64), new SqlParameter("@Info", SqlDbType.VarChar, 128), new SqlParameter("@contact", SqlDbType.VarChar, 64), new SqlParameter("@image", SqlDbType.VarChar, 64), new SqlParameter("@isInvalid", SqlDbType.VarChar, 16), new SqlParameter("@solutionState", SqlDbType.VarChar, 16), new SqlParameter("@feedbackID", SqlDbType.Int, 4) }; parameters[0].Value = model.UserID; parameters[1].Value = model.feedbackTime; parameters[2].Value = model.category; parameters[3].Value = model.Info; parameters[4].Value = model.contact; parameters[5].Value = model.image; parameters[6].Value = model.isInvalid; parameters[7].Value = model.solutionState; parameters[8].Value = model.feedbackID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public UFB.Model.Feedback DataRowToModel(DataRow row) { UFB.Model.Feedback model = new UFB.Model.Feedback(); if (row != null) { if (row["feedbackID"] != null && row["feedbackID"].ToString() != "") { model.feedbackID = int.Parse(row["feedbackID"].ToString()); } if (row["UserID"] != null && row["UserID"].ToString() != "") { model.UserID = int.Parse(row["UserID"].ToString()); } if (row["feedbackTime"] != null && row["feedbackTime"].ToString() != "") { model.feedbackTime = DateTime.Parse(row["feedbackTime"].ToString()); } if (row["category"] != null) { model.category = row["category"].ToString(); } if (row["Info"] != null) { model.Info = row["Info"].ToString(); } if (row["contact"] != null) { model.contact = row["contact"].ToString(); } if (row["image"] != null) { model.image = row["image"].ToString(); } if (row["isInvalid"] != null) { model.isInvalid = row["isInvalid"].ToString(); } if (row["solutionState"] != null) { model.solutionState = row["solutionState"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(UFB.Model.Feedback model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Feedback("); strSql.Append("UserID,feedbackTime,category,Info,contact,image,isInvalid,solutionState)"); strSql.Append(" values ("); strSql.Append("@UserID,@feedbackTime,@category,@Info,@contact,@image,@isInvalid,@solutionState)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@feedbackTime", SqlDbType.SmallDateTime), new SqlParameter("@category", SqlDbType.VarChar, 64), new SqlParameter("@Info", SqlDbType.VarChar, 128), new SqlParameter("@contact", SqlDbType.VarChar, 64), new SqlParameter("@image", SqlDbType.VarChar, 64), new SqlParameter("@isInvalid", SqlDbType.VarChar, 16), new SqlParameter("@solutionState", SqlDbType.VarChar, 16) }; parameters[0].Value = model.UserID; parameters[1].Value = model.feedbackTime; parameters[2].Value = model.category; parameters[3].Value = model.Info; parameters[4].Value = model.contact; parameters[5].Value = model.image; parameters[6].Value = model.isInvalid; parameters[7].Value = model.solutionState; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public UFB.Model.Feedback GetModel(int feedbackID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 feedbackID,UserID,feedbackTime,category,Info,contact,image,isInvalid,solutionState from Feedback "); strSql.Append(" where feedbackID=@feedbackID"); SqlParameter[] parameters = { new SqlParameter("@feedbackID", SqlDbType.Int, 4) }; parameters[0].Value = feedbackID; UFB.Model.Feedback model = new UFB.Model.Feedback(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtUserID.Text)) { strErr += "UserID格式错误!\\n"; } if (!PageValidate.IsDateTime(txtfeedbackTime.Text)) { strErr += "feedbackTime格式错误!\\n"; } if (this.txtcategory.Text.Trim().Length == 0) { strErr += "category不能为空!\\n"; } if (this.txtInfo.Text.Trim().Length == 0) { strErr += "Info不能为空!\\n"; } if (this.txtcontact.Text.Trim().Length == 0) { strErr += "contact不能为空!\\n"; } if (this.txtimage.Text.Trim().Length == 0) { strErr += "image不能为空!\\n"; } if (this.txtisInvalid.Text.Trim().Length == 0) { strErr += "isInvalid不能为空!\\n"; } if (this.txtsolutionState.Text.Trim().Length == 0) { strErr += "solutionState不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int feedbackID = int.Parse(this.lblfeedbackID.Text); int UserID = int.Parse(this.txtUserID.Text); DateTime feedbackTime = DateTime.Parse(this.txtfeedbackTime.Text); string category = this.txtcategory.Text; string Info = this.txtInfo.Text; string contact = this.txtcontact.Text; string image = this.txtimage.Text; string isInvalid = this.txtisInvalid.Text; string solutionState = this.txtsolutionState.Text; UFB.Model.Feedback model = new UFB.Model.Feedback(); model.feedbackID = feedbackID; model.UserID = UserID; model.feedbackTime = feedbackTime; model.category = category; model.Info = Info; model.contact = contact; model.image = image; model.isInvalid = isInvalid; model.solutionState = solutionState; UFB.BLL.FeedbackManager bll = new UFB.BLL.FeedbackManager(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }