private void ShowInfo(int _id) { BLL.distribution bll = new BLL.distribution(); Model.distribution model = bll.GetModel(_id); txtTitle.Text = model.title; rblType.SelectedValue = model.type.ToString(); rblIsLock.SelectedValue = model.is_lock.ToString(); txtSortId.Text = model.sort_id.ToString(); txtAmount.Text = model.amount.ToString(); txtRemark.Text = model.remark; }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.distribution GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,title,remark,type,amount,sort_id,is_lock from dt_distribution "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.distribution model = new Model.distribution(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "") { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (ds.Tables[0].Rows[0]["remark"] != null && ds.Tables[0].Rows[0]["remark"].ToString() != "") { model.remark = ds.Tables[0].Rows[0]["remark"].ToString(); } if (ds.Tables[0].Rows[0]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "") { model.type = int.Parse(ds.Tables[0].Rows[0]["type"].ToString()); } if (ds.Tables[0].Rows[0]["amount"] != null && ds.Tables[0].Rows[0]["amount"].ToString() != "") { model.amount = decimal.Parse(ds.Tables[0].Rows[0]["amount"].ToString()); } if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } if (ds.Tables[0].Rows[0]["is_lock"] != null && ds.Tables[0].Rows[0]["is_lock"].ToString() != "") { model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString()); } return(model); } else { return(null); } }
private bool DoAdd() { bool result = true; Model.distribution model = new Model.distribution(); BLL.distribution bll = new BLL.distribution(); model.title = txtTitle.Text.Trim(); model.type = int.Parse(rblType.SelectedValue); model.is_lock = int.Parse(rblIsLock.SelectedValue); model.sort_id = int.Parse(txtSortId.Text.Trim()); model.amount = decimal.Parse(txtAmount.Text.Trim()); model.remark = txtRemark.Text; if (bll.Add(model) < 1) { result = false; } return result; }
private bool DoAdd() { bool result = true; Model.distribution model = new Model.distribution(); BLL.distribution bll = new BLL.distribution(); model.title = txtTitle.Text.Trim(); model.type = int.Parse(rblType.SelectedValue); model.is_lock = int.Parse(rblIsLock.SelectedValue); model.sort_id = int.Parse(txtSortId.Text.Trim()); model.amount = decimal.Parse(txtAmount.Text.Trim()); model.remark = txtRemark.Text; if (bll.Add(model) < 1) { result = false; } return(result); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.distribution model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dt_distribution set "); strSql.Append("title=@title,"); strSql.Append("remark=@remark,"); strSql.Append("type=@type,"); strSql.Append("amount=@amount,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("is_lock=@is_lock"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@remark", SqlDbType.NText), new SqlParameter("@type", SqlDbType.TinyInt, 1), new SqlParameter("@amount", SqlDbType.Decimal, 5), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.title; parameters[1].Value = model.remark; parameters[2].Value = model.type; parameters[3].Value = model.amount; parameters[4].Value = model.sort_id; parameters[5].Value = model.is_lock; 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(Model.distribution model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dt_distribution("); strSql.Append("title,remark,type,amount,sort_id,is_lock)"); strSql.Append(" values ("); strSql.Append("@title,@remark,@type,@amount,@sort_id,@is_lock)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@remark", SqlDbType.NText), new SqlParameter("@type", SqlDbType.TinyInt, 1), new SqlParameter("@amount", SqlDbType.Decimal, 5), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@is_lock", SqlDbType.TinyInt, 1) }; parameters[0].Value = model.title; parameters[1].Value = model.remark; parameters[2].Value = model.type; parameters[3].Value = model.amount; parameters[4].Value = model.sort_id; parameters[5].Value = model.is_lock; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public Model.distribution GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,title,remark,type,amount,sort_id,is_lock from dt_distribution "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Model.distribution model = new Model.distribution(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "") { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (ds.Tables[0].Rows[0]["remark"] != null && ds.Tables[0].Rows[0]["remark"].ToString() != "") { model.remark = ds.Tables[0].Rows[0]["remark"].ToString(); } if (ds.Tables[0].Rows[0]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "") { model.type = int.Parse(ds.Tables[0].Rows[0]["type"].ToString()); } if (ds.Tables[0].Rows[0]["amount"] != null && ds.Tables[0].Rows[0]["amount"].ToString() != "") { model.amount = decimal.Parse(ds.Tables[0].Rows[0]["amount"].ToString()); } if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "") { model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString()); } if (ds.Tables[0].Rows[0]["is_lock"] != null && ds.Tables[0].Rows[0]["is_lock"].ToString() != "") { model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString()); } return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.distribution model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.distribution model) { return(dal.Add(model)); }