/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.DBBackup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update DBBackup set "); strSql.Append("BackupTime=@BackupTime,"); strSql.Append("BackupName=@BackupName,"); strSql.Append("Path=@Path,"); strSql.Append("Remark=@Remark"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@BackupTime", SqlDbType.DateTime), new SqlParameter("@BackupName", SqlDbType.VarChar, 50), new SqlParameter("@Path", SqlDbType.VarChar, 150), new SqlParameter("@Remark", SqlDbType.VarChar, 500), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.BackupTime; parameters[1].Value = model.BackupName; parameters[2].Value = model.Path; parameters[3].Value = model.Remark; parameters[4].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.DBBackup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into DBBackup("); strSql.Append("BackupTime,BackupName,Path,Remark)"); strSql.Append(" values ("); strSql.Append("@BackupTime,@BackupName,@Path,@Remark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@BackupTime", SqlDbType.DateTime), new SqlParameter("@BackupName", SqlDbType.VarChar, 50), new SqlParameter("@Path", SqlDbType.VarChar, 150), new SqlParameter("@Remark", SqlDbType.VarChar, 500) }; parameters[0].Value = model.BackupTime; parameters[1].Value = model.BackupName; parameters[2].Value = model.Path; parameters[3].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.DBBackup DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.DBBackup model = new WebDemo.Model.WebDemo.DBBackup(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["BackupTime"] != null && row["BackupTime"].ToString() != "") { model.BackupTime = DateTime.Parse(row["BackupTime"].ToString()); } if (row["BackupName"] != null) { model.BackupName = row["BackupName"].ToString(); } if (row["Path"] != null) { model.Path = row["Path"].ToString(); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } } return(model); }
private void ShowInfo(int ID) { WebDemo.BLL.WebDemo.DBBackup bll = new WebDemo.BLL.WebDemo.DBBackup(); WebDemo.Model.WebDemo.DBBackup model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.txtBackupTime.Text = model.BackupTime.ToString(); this.txtBackupName.Text = model.BackupName; this.txtPath.Text = model.Path; this.txtRemark.Text = model.Remark; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsDateTime(txtBackupTime.Text)) { strErr += "BackupTime格式错误!\\n"; } if (this.txtBackupName.Text.Trim().Length == 0) { strErr += "BackupName不能为空!\\n"; } if (this.txtPath.Text.Trim().Length == 0) { strErr += "Path不能为空!\\n"; } if (this.txtRemark.Text.Trim().Length == 0) { strErr += "备注不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int ID = int.Parse(this.lblID.Text); DateTime BackupTime = DateTime.Parse(this.txtBackupTime.Text); string BackupName = this.txtBackupName.Text; string Path = this.txtPath.Text; string Remark = this.txtRemark.Text; WebDemo.Model.WebDemo.DBBackup model = new WebDemo.Model.WebDemo.DBBackup(); model.ID = ID; model.BackupTime = BackupTime; model.BackupName = BackupName; model.Path = Path; model.Remark = Remark; WebDemo.BLL.WebDemo.DBBackup bll = new WebDemo.BLL.WebDemo.DBBackup(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.DBBackup GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,BackupTime,BackupName,Path,Remark from DBBackup "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; WebDemo.Model.WebDemo.DBBackup model = new WebDemo.Model.WebDemo.DBBackup(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }