protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtTitle.Text.Trim().Length == 0) { strErr += "组名不能为空!\\n"; } if (this.txtAtlas.Text.Trim().Length == 0) { strErr += "Atlas不能为空!\\n"; } if (!PageValidate.IsDateTime(txtTime.Text)) { strErr += "Time格式错误!\\n"; } if (this.txtInfo.Text.Trim().Length == 0) { strErr += "Info不能为空!\\n"; } if (this.txtNo.Text.Trim().Length == 0) { strErr += "No不能为空!\\n"; } if (!PageValidate.IsNumber(txtMark.Text)) { strErr += "Mark格式错误!\\n"; } if (!PageValidate.IsNumber(txtClick.Text)) { strErr += "Click格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string Title = this.txtTitle.Text; string Atlas = this.txtAtlas.Text; DateTime Time = DateTime.Parse(this.txtTime.Text); string Info = this.txtInfo.Text; string No = this.txtNo.Text; int Mark = int.Parse(this.txtMark.Text); int Click = int.Parse(this.txtClick.Text); Maticsoft.Model.NewsGroup model = new Maticsoft.Model.NewsGroup(); model.Title = Title; model.Atlas = Atlas; model.Time = Time; model.Info = Info; model.No = No; model.Mark = Mark; model.Click = Click; Maticsoft.BLL.NewsGroup bll = new Maticsoft.BLL.NewsGroup(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
private void ShowInfo(int ID) { Maticsoft.BLL.NewsGroup bll = new Maticsoft.BLL.NewsGroup(); Maticsoft.Model.NewsGroup model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.lblTitle.Text = model.Title; this.lblAtlas.Text = model.Atlas; this.lblTime.Text = model.Time.ToString(); this.lblInfo.Text = model.Info; this.lblNo.Text = model.No; this.lblMark.Text = model.Mark.ToString(); this.lblClick.Text = model.Click.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.NewsGroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update NewsGroup set "); strSql.Append("Title=@Title,"); strSql.Append("Atlas=@Atlas,"); strSql.Append("Time=@Time,"); strSql.Append("Info=@Info,"); strSql.Append("Mark=@Mark,"); strSql.Append("Click=@Click"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Atlas", SqlDbType.NVarChar, 50), new SqlParameter("@Time", SqlDbType.DateTime), new SqlParameter("@Info", SqlDbType.NVarChar, -1), new SqlParameter("@Mark", SqlDbType.Int, 4), new SqlParameter("@Click", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@No", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Title; parameters[1].Value = model.Atlas; parameters[2].Value = model.Time; parameters[3].Value = model.Info; parameters[4].Value = model.Mark; parameters[5].Value = model.Click; parameters[6].Value = model.ID; parameters[7].Value = model.No; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.NewsGroup DataRowToModel(DataRow row) { Maticsoft.Model.NewsGroup model = new Maticsoft.Model.NewsGroup(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["Title"] != null) { model.Title = row["Title"].ToString(); } if (row["Atlas"] != null) { model.Atlas = row["Atlas"].ToString(); } if (row["Time"] != null && row["Time"].ToString() != "") { model.Time = DateTime.Parse(row["Time"].ToString()); } if (row["Info"] != null) { model.Info = row["Info"].ToString(); } if (row["No"] != null) { model.No = row["No"].ToString(); } if (row["Mark"] != null && row["Mark"].ToString() != "") { model.Mark = int.Parse(row["Mark"].ToString()); } if (row["Click"] != null && row["Click"].ToString() != "") { model.Click = int.Parse(row["Click"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.NewsGroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into NewsGroup("); strSql.Append("Title,Atlas,Time,Info,No,Mark,Click)"); strSql.Append(" values ("); strSql.Append("@Title,@Atlas,@Time,@Info,@No,@Mark,@Click)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Atlas", SqlDbType.NVarChar, 50), new SqlParameter("@Time", SqlDbType.DateTime), new SqlParameter("@Info", SqlDbType.NVarChar, -1), new SqlParameter("@No", SqlDbType.NVarChar, 50), new SqlParameter("@Mark", SqlDbType.Int, 4), new SqlParameter("@Click", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.Atlas; parameters[2].Value = model.Time; parameters[3].Value = model.Info; parameters[4].Value = model.No; parameters[5].Value = model.Mark; parameters[6].Value = model.Click; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.NewsGroup GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Title,Atlas,Time,Info,No,Mark,Click from NewsGroup "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Maticsoft.Model.NewsGroup model = new Maticsoft.Model.NewsGroup(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }