public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtHostId.Text)) { strErr += "HostId格式错误!\\n"; } if (!PageValidate.IsNumber(txtFuncType.Text)) { strErr += "FuncType格式错误!\\n"; } if (!PageValidate.IsDateTime(txtReadTime.Text)) { strErr += "ReadTime格式错误!\\n"; } if (!PageValidate.IsNumber(txtState.Text)) { strErr += "State格式错误!\\n"; } if (this.txtDescripion.Text.Trim().Length == 0) { strErr += "Descripion不能为空!\\n"; } if (this.txtRemark.Text.Trim().Length == 0) { strErr += "Remark不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int ID = int.Parse(this.lblID.Text); int HostId = int.Parse(this.txtHostId.Text); int FuncType = int.Parse(this.txtFuncType.Text); DateTime ReadTime = DateTime.Parse(this.txtReadTime.Text); int State = int.Parse(this.txtState.Text); string Descripion = this.txtDescripion.Text; string Remark = this.txtRemark.Text; WebDemo.Model.WebDemo.HostStateLog model = new WebDemo.Model.WebDemo.HostStateLog(); model.ID = ID; model.HostId = HostId; model.FuncType = FuncType; model.ReadTime = ReadTime; model.State = State; model.Descripion = Descripion; model.Remark = Remark; WebDemo.BLL.WebDemo.HostStateLog bll = new WebDemo.BLL.WebDemo.HostStateLog(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(int ID) { WebDemo.BLL.WebDemo.HostStateLog bll = new WebDemo.BLL.WebDemo.HostStateLog(); WebDemo.Model.WebDemo.HostStateLog model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.lblHostId.Text = model.HostId.ToString(); this.lblFuncType.Text = model.FuncType.ToString(); this.lblReadTime.Text = model.ReadTime.ToString(); this.lblState.Text = model.State.ToString(); this.lblDescripion.Text = model.Descripion; this.lblRemark.Text = model.Remark; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.HostStateLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update HostStateLog set "); strSql.Append("HostId=@HostId,"); strSql.Append("FuncType=@FuncType,"); strSql.Append("ReadTime=@ReadTime,"); strSql.Append("State=@State,"); strSql.Append("Descripion=@Descripion,"); strSql.Append("Remark=@Remark"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@HostId", SqlDbType.Int, 4), new SqlParameter("@FuncType", SqlDbType.Int, 4), new SqlParameter("@ReadTime", SqlDbType.DateTime), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@Descripion", SqlDbType.VarChar, 200), new SqlParameter("@Remark", SqlDbType.VarChar, 200), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.HostId; parameters[1].Value = model.FuncType; parameters[2].Value = model.ReadTime; parameters[3].Value = model.State; parameters[4].Value = model.Descripion; parameters[5].Value = model.Remark; parameters[6].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebDemo.Model.WebDemo.HostStateLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into HostStateLog("); strSql.Append("HostId,FuncType,ReadTime,State,Descripion,Remark)"); strSql.Append(" values ("); strSql.Append("@HostId,@FuncType,@ReadTime,@State,@Descripion,@Remark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@HostId", SqlDbType.Int, 4), new SqlParameter("@FuncType", SqlDbType.Int, 4), new SqlParameter("@ReadTime", SqlDbType.DateTime), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@Descripion", SqlDbType.VarChar, 200), new SqlParameter("@Remark", SqlDbType.VarChar, 200) }; parameters[0].Value = model.HostId; parameters[1].Value = model.FuncType; parameters[2].Value = model.ReadTime; parameters[3].Value = model.State; parameters[4].Value = model.Descripion; parameters[5].Value = model.Remark; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.HostStateLog DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.HostStateLog model = new WebDemo.Model.WebDemo.HostStateLog(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["HostId"] != null && row["HostId"].ToString() != "") { model.HostId = int.Parse(row["HostId"].ToString()); } if (row["FuncType"] != null && row["FuncType"].ToString() != "") { model.FuncType = int.Parse(row["FuncType"].ToString()); } if (row["ReadTime"] != null && row["ReadTime"].ToString() != "") { model.ReadTime = DateTime.Parse(row["ReadTime"].ToString()); } if (row["State"] != null && row["State"].ToString() != "") { model.State = int.Parse(row["State"].ToString()); } if (row["Descripion"] != null) { model.Descripion = row["Descripion"].ToString(); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.HostStateLog GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,HostId,FuncType,ReadTime,State,Descripion,Remark from HostStateLog "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; WebDemo.Model.WebDemo.HostStateLog model = new WebDemo.Model.WebDemo.HostStateLog(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }