/// <summary> /// 点击确定按钮执行的方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { Maticsoft.BLL.supervision_Info supervision = new Maticsoft.BLL.supervision_Info(); Maticsoft.Model.supervision_Info supervision_Info = supervision.GetModel(InfoID); if (supervision_Info == null) { supervision_Info = new Maticsoft.Model.supervision_Info(); } //获取客户端通过Post方式传递过来的值的(需要更改) supervision_Info.I_FindDate = (DateTime)Common.sink(this.I_FindDate.UniqueID, MethodType.Post, 255, 0, DataType.Dat); supervision_Info.I_Type = Convert.ToInt32(this.I_Type.SelectedValue); supervision_Info.I_Content = (string)Common.sink(this.I_Content.UniqueID, MethodType.Post, 0, 0, DataType.Str); supervision_Info.I_ReportDate = (DateTime)Common.sink(this.I_ReportDate.UniqueID, MethodType.Post, 0, 0, DataType.Dat); supervision_Info.I_ReportUserID = Convert.ToInt32(this.I_ReportUserID.Value); switch (CMD) { case "New": CMD_Txt = "增加"; //如果是增加操作,就调用Add方法 supervision.Add(supervision_Info); break; case "Edit": CMD_Txt = "修改"; //如果是修改操作,就调用Update方法 supervision.Update(supervision_Info); break; } All_Title_Txt = CMD_Txt + App_Txt; //以下方法的第4个参数需要更改 EventMessage.MessageBox(1, "操作成功", string.Format("{1}ID({0})成功!", InfoID, All_Title_Txt), Icon_Type.OK, Common.GetHomeBaseUrl("default.aspx")); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.supervision_Info DataRowToModel(DataRow row) { Maticsoft.Model.supervision_Info model=new Maticsoft.Model.supervision_Info(); if (row != null) { if(row["InfoID"]!=null && row["InfoID"].ToString()!="") { model.InfoID=int.Parse(row["InfoID"].ToString()); } if(row["I_FindDate"]!=null && row["I_FindDate"].ToString()!="") { model.I_FindDate=DateTime.Parse(row["I_FindDate"].ToString()); } if(row["I_Type"]!=null && row["I_Type"].ToString()!="") { model.I_Type=int.Parse(row["I_Type"].ToString()); } if(row["I_Content"]!=null) { model.I_Content=row["I_Content"].ToString(); } if(row["I_ReportDate"]!=null && row["I_ReportDate"].ToString()!="") { model.I_ReportDate=DateTime.Parse(row["I_ReportDate"].ToString()); } if(row["I_ReportUserID"]!=null && row["I_ReportUserID"].ToString()!="") { model.I_ReportUserID=int.Parse(row["I_ReportUserID"].ToString()); } } return model; }
/// <summary> /// 初始化 /// </summary> private void OnStart() { if (CMD == "New") { HiddenDisp(); } else if (CMD == "Edit") { HeadMenuButtonItem bi2 = new HeadMenuButtonItem(); bi2.ButtonPopedom = PopedomType.Delete; bi2.ButtonName = "信息"; //需要改 bi2.ButtonUrlType = UrlType.JavaScript; bi2.ButtonUrl = string.Format("DelData('?CMD=Delete&InfoID={0}')", InfoID); HeadMenuWebControls1.ButtonList.Add(bi2); HiddenDisp(); InputData(); } else if (CMD == "Delete") { //这是操作数据库的核心代码,工作原理是:首先要明确现在所操作的模块对应着数据库中的哪张表,然后创建这个表所对应的的逻辑处理层(bll)对象,如这里操作的表是supervision_Info,则要新建所对应的Maticsoft.BLL.supervision_Info对象 Maticsoft.BLL.supervision_Info bll = new Maticsoft.BLL.supervision_Info(); //这是数据库实体类对象(简单来说就对应着这个表的一条记录),因为这里操作的表是supervision_Info,则对应的model是Maticsoft.Model.supervision_Info,然后通过上一行new的bll对象去执行数据库操作(这里使用的方法是GetModel,当然还有其他的方法,根据需要使用不同的方法),返回对应实体类对象 Maticsoft.Model.supervision_Info model = bll.GetModel(InfoID); //bll执行删除操作,参数是这个实体类的ID值 bll.Delete(model.InfoID); //以下方法的第4、5个参数需要更改 EventMessage.MessageBox(1, "操作成功", string.Format("{1}ID({0})成功!", InfoID, "删除信息"), Icon_Type.OK, Common.GetHomeBaseUrl("default.aspx")); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.supervision_Info model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into supervision_Info("); strSql.Append("I_FindDate,I_Type,I_Content,I_ReportDate,I_ReportUserID)"); strSql.Append(" values ("); strSql.Append("@I_FindDate,@I_Type,@I_Content,@I_ReportDate,@I_ReportUserID)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@I_FindDate", SqlDbType.DateTime), new SqlParameter("@I_Type", SqlDbType.TinyInt,1), new SqlParameter("@I_Content", SqlDbType.Text), new SqlParameter("@I_ReportDate", SqlDbType.DateTime), new SqlParameter("@I_ReportUserID", SqlDbType.Int, 4) }; parameters[0].Value = model.I_FindDate; parameters[1].Value = model.I_Type; parameters[2].Value = model.I_Content; parameters[3].Value = model.I_ReportDate; parameters[4].Value = model.I_ReportUserID; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.supervision_Info DataRowToModel(DataRow row) { Maticsoft.Model.supervision_Info model = new Maticsoft.Model.supervision_Info(); if (row != null) { if (row["InfoID"] != null && row["InfoID"].ToString() != "") { model.InfoID = int.Parse(row["InfoID"].ToString()); } if (row["I_FindDate"] != null && row["I_FindDate"].ToString() != "") { model.I_FindDate = DateTime.Parse(row["I_FindDate"].ToString()); } if (row["I_Type"] != null && row["I_Type"].ToString() != "") { model.I_Type = int.Parse(row["I_Type"].ToString()); } if (row["I_Content"] != null) { model.I_Content = row["I_Content"].ToString(); } if (row["I_ReportDate"] != null && row["I_ReportDate"].ToString() != "") { model.I_ReportDate = DateTime.Parse(row["I_ReportDate"].ToString()); } if (row["I_ReportUserID"] != null && row["I_ReportUserID"].ToString() != "") { model.I_ReportUserID = int.Parse(row["I_ReportUserID"].ToString()); } } return(model); }
/// <summary> /// 点击确定按钮执行的方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click(object sender, EventArgs e) { Maticsoft.BLL.supervision_Info supervision = new Maticsoft.BLL.supervision_Info(); Maticsoft.Model.supervision_Info supervision_Info = supervision.GetModel(InfoID); if (supervision_Info == null) { supervision_Info = new Maticsoft.Model.supervision_Info(); } //获取客户端通过Post方式传递过来的值的(需要更改) supervision_Info.I_FindDate = (DateTime)Common.sink(this.I_FindDate.UniqueID, MethodType.Post, 255, 0, DataType.Dat); supervision_Info.I_Type = Convert.ToInt32(this.I_Type.SelectedValue); supervision_Info.I_Content = (string)Common.sink(this.I_Content.UniqueID, MethodType.Post, 0, 0, DataType.Str); supervision_Info.I_ReportDate = (DateTime)Common.sink(this.I_ReportDate.UniqueID, MethodType.Post, 0, 0, DataType.Dat); supervision_Info.I_ReportUserID = Convert.ToInt32(this.I_ReportUserID.Value); switch (CMD) { case "New": CMD_Txt = "增加"; //如果是增加操作,就调用Add方法 supervision.Add(supervision_Info); break; case "Edit": CMD_Txt = "修改"; //如果是修改操作,就调用Update方法 supervision.Update(supervision_Info); break; } All_Title_Txt = CMD_Txt + App_Txt; //以下方法的第4个参数需要更改 EventMessage.MessageBox(1, "操作成功", string.Format("{1}ID({0})成功!", InfoID, All_Title_Txt), Icon_Type.OK, Common.GetHomeBaseUrl("default.aspx")); }
private void ShowInfo(int InfoID) { Maticsoft.BLL.supervision_Info bll = new Maticsoft.BLL.supervision_Info(); Maticsoft.Model.supervision_Info model = bll.GetModel(InfoID); this.lblInfoID.Text = model.InfoID.ToString(); this.txtI_FindDate.Text = model.I_FindDate.ToString(); this.txtI_Type.Text = model.I_Type.ToString(); this.txtI_Content.Text = model.I_Content; this.txtI_ReportDate.Text = model.I_ReportDate.ToString(); this.txtI_ReportUserID.Text = model.I_ReportUserID.ToString(); }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsDateTime(txtI_FindDate.Text)) { strErr += "发现时间格式错误!\\n"; } if (!PageValidate.IsNumber(txtI_Type.Text)) { strErr += "信息类别格式错误!\\n"; } if (this.txtI_Content.Text.Trim().Length == 0) { strErr += "信息内容不能为空!\\n"; } if (!PageValidate.IsDateTime(txtI_ReportDate.Text)) { strErr += "报告时间格式错误!\\n"; } if (!PageValidate.IsNumber(txtI_ReportUserID.Text)) { strErr += "报告人格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int InfoID = int.Parse(this.lblInfoID.Text); DateTime I_FindDate = DateTime.Parse(this.txtI_FindDate.Text); int I_Type = int.Parse(this.txtI_Type.Text); string I_Content = this.txtI_Content.Text; DateTime I_ReportDate = DateTime.Parse(this.txtI_ReportDate.Text); int I_ReportUserID = int.Parse(this.txtI_ReportUserID.Text); Maticsoft.Model.supervision_Info model = new Maticsoft.Model.supervision_Info(); model.InfoID = InfoID; model.I_FindDate = I_FindDate; model.I_Type = I_Type; model.I_Content = I_Content; model.I_ReportDate = I_ReportDate; model.I_ReportUserID = I_ReportUserID; Maticsoft.BLL.supervision_Info bll = new Maticsoft.BLL.supervision_Info(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
public void btnSave_Click(object sender, EventArgs e) { string strErr=""; if(!PageValidate.IsDateTime(txtI_FindDate.Text)) { strErr+="发现时间格式错误!\\n"; } if(!PageValidate.IsNumber(txtI_Type.Text)) { strErr+="信息类别格式错误!\\n"; } if(this.txtI_Content.Text.Trim().Length==0) { strErr+="信息内容不能为空!\\n"; } if(!PageValidate.IsDateTime(txtI_ReportDate.Text)) { strErr+="报告时间格式错误!\\n"; } if(!PageValidate.IsNumber(txtI_ReportUserID.Text)) { strErr+="报告人格式错误!\\n"; } if(strErr!="") { MessageBox.Show(this,strErr); return; } int InfoID=int.Parse(this.lblInfoID.Text); DateTime I_FindDate=DateTime.Parse(this.txtI_FindDate.Text); int I_Type=int.Parse(this.txtI_Type.Text); string I_Content=this.txtI_Content.Text; DateTime I_ReportDate=DateTime.Parse(this.txtI_ReportDate.Text); int I_ReportUserID=int.Parse(this.txtI_ReportUserID.Text); Maticsoft.Model.supervision_Info model=new Maticsoft.Model.supervision_Info(); model.InfoID=InfoID; model.I_FindDate=I_FindDate; model.I_Type=I_Type; model.I_Content=I_Content; model.I_ReportDate=I_ReportDate; model.I_ReportUserID=I_ReportUserID; Maticsoft.BLL.supervision_Info bll=new Maticsoft.BLL.supervision_Info(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功!","list.aspx"); }
/// <summary> /// 在编辑的时候将对应的值绑定到Label上 /// </summary> private void InputData() { //这两句和73、75作用一样 Maticsoft.BLL.supervision_Info bll = new Maticsoft.BLL.supervision_Info(); Maticsoft.Model.supervision_Info model = bll.GetModel(InfoID); //以下几行需要更改 this.I_FindDate.Text = this.I_FindDate_Txt.Text = model.I_FindDate.ToShortDateString(); this.I_Type.SelectedValue = model.I_Type + ""; this.I_Type_Txt.Text = getSuperisionNameByType(model.I_Type); this.I_Content.Text = this.I_Content_Txt.Text = model.I_Content; this.I_ReportDate.Text = this.I_ReportDate.Text = model.I_ReportDate.ToShortDateString(); Maticsoft.BLL.sys_User user_bll = new Maticsoft.BLL.sys_User(); Maticsoft.Model.sys_User user_model = user_bll.GetModel(model.I_ReportUserID); this.I_ReportUserID.Value = user_model.UserID + ""; this.I_ReportUserID_TextBox.Text = user_model.U_CName; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.supervision_Info model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update supervision_Info set "); strSql.Append("I_FindDate=@I_FindDate,"); strSql.Append("I_Type=@I_Type,"); strSql.Append("I_Content=@I_Content,"); strSql.Append("I_ReportDate=@I_ReportDate,"); strSql.Append("I_ReportUserID=@I_ReportUserID"); strSql.Append(" where InfoID=@InfoID"); SqlParameter[] parameters = { new SqlParameter("@I_FindDate", SqlDbType.DateTime), new SqlParameter("@I_Type", SqlDbType.TinyInt, 1), new SqlParameter("@I_Content", SqlDbType.Text), new SqlParameter("@I_ReportDate", SqlDbType.DateTime), new SqlParameter("@I_ReportUserID", SqlDbType.Int, 4), new SqlParameter("@InfoID", SqlDbType.Int, 4) }; parameters[0].Value = model.I_FindDate; parameters[1].Value = model.I_Type; parameters[2].Value = model.I_Content; parameters[3].Value = model.I_ReportDate; parameters[4].Value = model.I_ReportUserID; parameters[5].Value = model.InfoID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.supervision_Info GetModel(int InfoID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 InfoID,I_FindDate,I_Type,I_Content,I_ReportDate,I_ReportUserID from supervision_Info "); strSql.Append(" where InfoID=@InfoID"); SqlParameter[] parameters = { new SqlParameter("@InfoID", SqlDbType.Int, 4) }; parameters[0].Value = InfoID; Maticsoft.Model.supervision_Info model = new Maticsoft.Model.supervision_Info(); 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.supervision_Info GetModel(int InfoID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 InfoID,I_FindDate,I_Type,I_Content,I_ReportDate,I_ReportUserID from supervision_Info "); strSql.Append(" where InfoID=@InfoID"); SqlParameter[] parameters = { new SqlParameter("@InfoID", SqlDbType.Int,4) }; parameters[0].Value = InfoID; Maticsoft.Model.supervision_Info model=new Maticsoft.Model.supervision_Info(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }