private void ShowInfo(int Id) { Maticsoft.BLL.News bll = new Maticsoft.BLL.News(); Maticsoft.Model.News model = bll.GetModel(Id); this.lblName.Text = model.Name; BLL.NewsType BLLNewsType = new BLL.NewsType(); Model.NewsType ModelNewsType = BLLNewsType.GetModel((int)model.Fk_NewsType_Id); this.lblContents.Text = model.Contents; BLL.Users BLLUsers = new BLL.Users(); Model.Users ModelUsers = BLLUsers.GetModel((int)model.Fk_Users_Id); this.lblFk_Users_Id.Text = ModelUsers.Name; this.lblAddTime.Text = model.AddTime.ToString(); if (Session["LoginUser"] == null) { lblUser.Text = "匿名"; } else { BLL.Users bllleaveuser = new BLL.Users(); Model.Users modelleaveuser = bllleaveuser.GetModel((int)Session["LoginUser"]); lblUser.Text = modelleaveuser.TrueName; } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsDateTime(txtAddTime.Text)) { strErr += "发布时间格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Id = int.Parse(this.lblId.Text); String Name = this.txtName.Text; int Fk_NewsType_Id = int.Parse(this.ddlFk_NewsType_Id.SelectedValue); String Contents = this.txtContents.Text; int Fk_Users_Id = int.Parse(this.ddlFk_Users_Id.SelectedValue); DateTime AddTime = DateTime.Parse(this.txtAddTime.Text); Maticsoft.Model.News model = new Maticsoft.Model.News(); model.Id = Id; model.Name = Name; model.Fk_NewsType_Id = Fk_NewsType_Id; model.Contents = Contents; model.Fk_Users_Id = Fk_Users_Id; model.AddTime = AddTime; Maticsoft.BLL.News bll = new Maticsoft.BLL.News(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.News model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into News("); strSql.Append("Name,Fk_NewsType_Id,Contents,Fk_Users_Id,AddTime)"); strSql.Append(" values ("); strSql.Append("@Name,@Fk_NewsType_Id,@Contents,@Fk_Users_Id,@AddTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.VarChar, 100), new SqlParameter("@Fk_NewsType_Id", SqlDbType.Int, 4), new SqlParameter("@Contents", SqlDbType.VarChar, -1), new SqlParameter("@Fk_Users_Id", SqlDbType.Int, 4), new SqlParameter("@AddTime", SqlDbType.DateTime) }; parameters[0].Value = model.Name; parameters[1].Value = model.Fk_NewsType_Id; parameters[2].Value = model.Contents; parameters[3].Value = model.Fk_Users_Id; parameters[4].Value = model.AddTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.News DataRowToModel(DataRow row) { Maticsoft.Model.News model = new Maticsoft.Model.News(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Fk_NewsType_Id"] != null && row["Fk_NewsType_Id"].ToString() != "") { model.Fk_NewsType_Id = int.Parse(row["Fk_NewsType_Id"].ToString()); } if (row["Contents"] != null) { model.Contents = row["Contents"].ToString(); } if (row["Fk_Users_Id"] != null && row["Fk_Users_Id"].ToString() != "") { model.Fk_Users_Id = int.Parse(row["Fk_Users_Id"].ToString()); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.News DataRowToModel(DataRow row) { Maticsoft.Model.News model = new Maticsoft.Model.News(); 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["Content"] != null) { model.Content = row["Content"].ToString(); } if (row["Time"] != null && row["Time"].ToString() != "") { model.Time = DateTime.Parse(row["Time"].ToString()); } if (row["Attachment"] != null) { model.Attachment = row["Attachment"].ToString(); } if (row["GroupID"] != null && row["GroupID"].ToString() != "") { model.GroupID = int.Parse(row["GroupID"].ToString()); } if (row["IsOpen"] != null && row["IsOpen"].ToString() != "") { if ((row["IsOpen"].ToString() == "1") || (row["IsOpen"].ToString().ToLower() == "true")) { model.IsOpen = true; } else { model.IsOpen = false; } } if (row["Click"] != null && row["Click"].ToString() != "") { model.Click = int.Parse(row["Click"].ToString()); } if (row["No"] != null && row["No"].ToString() != "") { model.No = int.Parse(row["No"].ToString()); } if (row["Mark"] != null && row["Mark"].ToString() != "") { model.Mark = int.Parse(row["Mark"].ToString()); } if (row["S1"] != null) { model.S1 = row["S1"].ToString(); } } return(model); }
private void ShowInfo(int Id) { Maticsoft.BLL.News bll = new Maticsoft.BLL.News(); Maticsoft.Model.News model = bll.GetModel(Id); this.lblId.Text = model.Id.ToString(); this.txtName.Text = model.Name; this.ddlFk_NewsType_Id.SelectedValue = model.Fk_NewsType_Id.ToString(); this.txtContents.Text = model.Contents; this.ddlFk_Users_Id.SelectedValue = model.Fk_Users_Id.ToString(); this.txtAddTime.Text = model.AddTime.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.News model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update News set "); strSql.Append("Title=@Title,"); strSql.Append("Content=@Content,"); strSql.Append("Time=@Time,"); strSql.Append("Attachment=@Attachment,"); strSql.Append("GroupID=@GroupID,"); strSql.Append("IsOpen=@IsOpen,"); strSql.Append("Click=@Click,"); strSql.Append("Mark=@Mark,"); strSql.Append("S1=@S1"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Content", SqlDbType.NVarChar, -1), new SqlParameter("@Time", SqlDbType.DateTime), new SqlParameter("@Attachment", SqlDbType.NVarChar, 100), new SqlParameter("@GroupID", SqlDbType.Int, 4), new SqlParameter("@IsOpen", SqlDbType.Bit, 1), new SqlParameter("@Click", SqlDbType.Int, 4), new SqlParameter("@Mark", SqlDbType.Int, 4), new SqlParameter("@S1", SqlDbType.NVarChar, 50), new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@No", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.Content; parameters[2].Value = model.Time; parameters[3].Value = model.Attachment; parameters[4].Value = model.GroupID; parameters[5].Value = model.IsOpen; parameters[6].Value = model.Click; parameters[7].Value = model.Mark; parameters[8].Value = model.S1; parameters[9].Value = model.ID; parameters[10].Value = model.No; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(int Id) { Maticsoft.BLL.News bll = new Maticsoft.BLL.News(); Maticsoft.Model.News model = bll.GetModel(Id); this.lblId.Text = model.Id.ToString(); this.lblName.Text = model.Name; BLL.NewsType BLLNewsType = new BLL.NewsType(); Model.NewsType ModelNewsType = BLLNewsType.GetModel((int)model.Fk_NewsType_Id); this.lblFk_NewsType_Id.Text = ModelNewsType.Name; this.lblContents.Text = model.Contents; BLL.Users BLLUsers = new BLL.Users(); Model.Users ModelUsers = BLLUsers.GetModel((int)model.Fk_Users_Id); this.lblFk_Users_Id.Text = ModelUsers.Name; this.lblAddTime.Text = model.AddTime.ToString(); }
private void ShowInfo(int ID) { Maticsoft.BLL.News bll = new Maticsoft.BLL.News(); Maticsoft.Model.News model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.lblTitle.Text = model.Title; this.lblContent.Text = model.Content; this.lblTime.Text = model.Time.ToString(); this.lblAttachment.Text = model.Attachment; this.lblGroupID.Text = model.GroupID.ToString(); this.lblIsOpen.Text = model.IsOpen?"是":"否"; this.lblClick.Text = model.Click.ToString(); this.lblNo.Text = model.No.ToString(); this.lblMark.Text = model.Mark.ToString(); this.lblS1.Text = model.S1; }
private void ShowInfo(int ID) { Maticsoft.BLL.News bll = new Maticsoft.BLL.News(); Maticsoft.Model.News model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.txtTitle.Text = model.Title; this.txtContent.Text = model.Content; this.txtTime.Text = model.Time.ToString(); this.txtAttachment.Text = model.Attachment; this.txtGroupID.Text = model.GroupID.ToString(); this.chkIsOpen.Checked = model.IsOpen; this.txtClick.Text = model.Click.ToString(); this.lblNo.Text = model.No.ToString(); this.txtMark.Text = model.Mark.ToString(); this.txtS1.Text = model.S1; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.News model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into News("); strSql.Append("Title,Content,Time,Attachment,GroupID,IsOpen,Click,No,Mark,S1)"); strSql.Append(" values ("); strSql.Append("@Title,@Content,@Time,@Attachment,@GroupID,@IsOpen,@Click,@No,@Mark,@S1)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Content", SqlDbType.NVarChar, -1), new SqlParameter("@Time", SqlDbType.DateTime), new SqlParameter("@Attachment", SqlDbType.NVarChar, 100), new SqlParameter("@GroupID", SqlDbType.Int, 4), new SqlParameter("@IsOpen", SqlDbType.Bit, 1), new SqlParameter("@Click", SqlDbType.Int, 4), new SqlParameter("@No", SqlDbType.Int, 4), new SqlParameter("@Mark", SqlDbType.Int, 4), new SqlParameter("@S1", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Title; parameters[1].Value = model.Content; parameters[2].Value = model.Time; parameters[3].Value = model.Attachment; parameters[4].Value = model.GroupID; parameters[5].Value = model.IsOpen; parameters[6].Value = model.Click; parameters[7].Value = model.No; parameters[8].Value = model.Mark; parameters[9].Value = model.S1; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.News model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update News set "); strSql.Append("Name=@Name,"); strSql.Append("Fk_NewsType_Id=@Fk_NewsType_Id,"); strSql.Append("Contents=@Contents,"); strSql.Append("Fk_Users_Id=@Fk_Users_Id,"); strSql.Append("AddTime=@AddTime"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.VarChar, 100), new SqlParameter("@Fk_NewsType_Id", SqlDbType.Int, 4), new SqlParameter("@Contents", SqlDbType.VarChar, -1), new SqlParameter("@Fk_Users_Id", SqlDbType.Int, 4), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.Name; parameters[1].Value = model.Fk_NewsType_Id; parameters[2].Value = model.Contents; parameters[3].Value = model.Fk_Users_Id; parameters[4].Value = model.AddTime; parameters[5].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.News GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Name,Fk_NewsType_Id,Contents,Fk_Users_Id,AddTime from News "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Maticsoft.Model.News model = new Maticsoft.Model.News(); 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 Maticsoft.Model.News GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Title,Content,Time,Attachment,GroupID,IsOpen,Click,No,Mark,S1 from News "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Maticsoft.Model.News model = new Maticsoft.Model.News(); 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 (this.txtTitle.Text.Trim().Length == 0) { strErr += "标题不能为空!\\n"; } if (this.txtContent.Text.Trim().Length == 0) { strErr += "内容不能为空!\\n"; } if (!PageValidate.IsDateTime(txtTime.Text)) { strErr += "发布时间格式错误!\\n"; } if (this.txtAttachment.Text.Trim().Length == 0) { strErr += "附件不能为空!\\n"; } if (!PageValidate.IsNumber(txtGroupID.Text)) { strErr += "分组格式错误!\\n"; } if (!PageValidate.IsNumber(txtClick.Text)) { strErr += "点击数格式错误!\\n"; } if (!PageValidate.IsNumber(txtMark.Text)) { strErr += "Mark格式错误!\\n"; } if (this.txtS1.Text.Trim().Length == 0) { strErr += "S1不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int ID = int.Parse(this.lblID.Text); string Title = this.txtTitle.Text; string Content = this.txtContent.Text; DateTime Time = DateTime.Parse(this.txtTime.Text); string Attachment = this.txtAttachment.Text; int GroupID = int.Parse(this.txtGroupID.Text); bool IsOpen = this.chkIsOpen.Checked; int Click = int.Parse(this.txtClick.Text); int No = int.Parse(this.lblNo.Text); int Mark = int.Parse(this.txtMark.Text); string S1 = this.txtS1.Text; Maticsoft.Model.News model = new Maticsoft.Model.News(); model.ID = ID; model.Title = Title; model.Content = Content; model.Time = Time; model.Attachment = Attachment; model.GroupID = GroupID; model.IsOpen = IsOpen; model.Click = Click; model.No = No; model.Mark = Mark; model.S1 = S1; Maticsoft.BLL.News bll = new Maticsoft.BLL.News(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }