protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtYear.Text)) { strErr += "Year格式错误!\\n"; } if (!PageValidate.IsDateTime(txtStartDate.Text)) { strErr += "StartDate格式错误!\\n"; } if (!PageValidate.IsDateTime(txtEndDate.Text)) { strErr += "EndDate格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Year = int.Parse(this.txtYear.Text); DateTime StartDate = DateTime.Parse(this.txtStartDate.Text); DateTime EndDate = DateTime.Parse(this.txtEndDate.Text); WebDemo.Model.WebDemo.HeatingCycle model = new WebDemo.Model.WebDemo.HeatingCycle(); model.Year = Year; model.StartDate = StartDate; model.EndDate = EndDate; WebDemo.BLL.WebDemo.HeatingCycle bll = new WebDemo.BLL.WebDemo.HeatingCycle(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.HeatingCycle model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update HeatingCycle set "); strSql.Append("Year=@Year,"); strSql.Append("StartDate=@StartDate,"); strSql.Append("EndDate=@EndDate"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@Year", SqlDbType.Int, 4), new SqlParameter("@StartDate", SqlDbType.DateTime), new SqlParameter("@EndDate", SqlDbType.DateTime), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.Year; parameters[1].Value = model.StartDate; parameters[2].Value = model.EndDate; parameters[3].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.HeatingCycle model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into HeatingCycle("); strSql.Append("Year,StartDate,EndDate)"); strSql.Append(" values ("); strSql.Append("@Year,@StartDate,@EndDate)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Year", SqlDbType.Int, 4), new SqlParameter("@StartDate", SqlDbType.DateTime), new SqlParameter("@EndDate", SqlDbType.DateTime) }; parameters[0].Value = model.Year; parameters[1].Value = model.StartDate; parameters[2].Value = model.EndDate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void ShowInfo(int ID) { WebDemo.BLL.WebDemo.HeatingCycle bll = new WebDemo.BLL.WebDemo.HeatingCycle(); WebDemo.Model.WebDemo.HeatingCycle model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.txtYear.Text = model.Year.ToString(); this.txtStartDate.Text = model.StartDate.ToString(); this.txtEndDate.Text = model.EndDate.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.HeatingCycle DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.HeatingCycle model = new WebDemo.Model.WebDemo.HeatingCycle(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["Year"] != null && row["Year"].ToString() != "") { model.Year = int.Parse(row["Year"].ToString()); } if (row["StartDate"] != null && row["StartDate"].ToString() != "") { model.StartDate = DateTime.Parse(row["StartDate"].ToString()); } if (row["EndDate"] != null && row["EndDate"].ToString() != "") { model.EndDate = DateTime.Parse(row["EndDate"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.HeatingCycle GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Year,StartDate,EndDate from HeatingCycle "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; WebDemo.Model.WebDemo.HeatingCycle model = new WebDemo.Model.WebDemo.HeatingCycle(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }