/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool Update(AusMoney model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update DepartMoney set "); strSql.Append(" username=@username,amount=@amount"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@username", SqlDbType.VarChar, 20), new SqlParameter("@amount", SqlDbType.Money, 8), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.username; parameters[1].Value = model.amount; parameters[2].Value = model.id; int result = DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (result >= 1) { return(true); } else { return(false); } }
/// <summary> /// 根据项目名称,年份和人员得到实体 /// </summary> /// <param name="itemname">项目名称</param> /// <param name="username">人员</param> /// <returns></returns> public static AusMoney GetModelbyname(string itemname, string username, int years) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from DepartMoney"); strSql.Append(" where itemname=@itemname"); strSql.Append(" and username=@username"); strSql.Append(" and years=@years"); SqlParameter[] parameters = { new SqlParameter("@itemname", SqlDbType.VarChar, 20), new SqlParameter("@username", SqlDbType.VarChar, 20), new SqlParameter("@years", SqlDbType.Int, 4) }; parameters[0].Value = itemname; parameters[1].Value = username; parameters[2].Value = years; AusMoney model = new AusMoney(); DataTable dt = DBHelper.GetDataSet(strSql.ToString(), parameters); if (dt.Rows.Count > 0) { model.id = Convert.ToInt32(dt.Rows[0]["ID"]); model.itemname = Convert.ToString(dt.Rows[0]["itemname"]); model.username = Convert.ToString(dt.Rows[0]["username"]); model.amount = Convert.IsDBNull(dt.Rows[0]["amount"]) ? 0.0 : Convert.ToDouble(dt.Rows[0]["amount"]); model.haspay = Convert.IsDBNull(dt.Rows[0]["haspay"]) ? 0.0 : Convert.ToDouble(dt.Rows[0]["haspay"]); model.year = Convert.ToInt32(dt.Rows[0]["years"]); } return(model); }
/// <summary> /// 增加一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool Add(AusMoney model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into DepartMoney("); strSql.Append("itemname,username,amount,years)"); strSql.Append(" values ("); strSql.Append("@itemname,@username,@amount,@years)"); SqlParameter[] parameters = { new SqlParameter("@itemname", SqlDbType.VarChar, 20), new SqlParameter("@username", SqlDbType.VarChar, 20), new SqlParameter("@amount", SqlDbType.Money, 8), new SqlParameter("@years", SqlDbType.Int, 4) }; parameters[0].Value = model.itemname; parameters[1].Value = model.username; parameters[2].Value = model.amount; parameters[3].Value = model.year; int result = DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (result >= 1) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象的实体 /// </summary> /// <param name="id"></param> /// <returns></returns> public static AusMoney GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from DepartMoney "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; AusMoney model = new AusMoney(); DataTable ds = DBHelper.GetDataSet(strSql.ToString(), parameters); if (ds.Rows.Count > 0) { model.id = Convert.ToInt32(ds.Rows[0]["ID"]); model.itemname = Convert.ToString(ds.Rows[0]["itemname"]); model.username = Convert.ToString(ds.Rows[0]["username"]); model.amount = Convert.IsDBNull(ds.Rows[0]["amount"]) ? 0.0 : Convert.ToDouble(ds.Rows[0]["amount"]); model.haspay = Convert.IsDBNull(ds.Rows[0]["haspay"]) ? 0.0 : Convert.ToDouble(ds.Rows[0]["haspay"]); model.year = Convert.ToInt32(ds.Rows[0]["years"]); } return(model); }
/// <summary> /// 加载当前数据 /// </summary> private void LoadNowMoney() { int id = Convert.ToInt32(Request.QueryString["id"]); string itemname = Request.QueryString["itemname"]; AusMoney ausmoney = AusMoneyManager.GetModel(id); this.person.SelectedValue = ausmoney.username; this.txtmoney.Text = ausmoney.amount.ToString(); this.person.Enabled = false; }
/// <summary> /// 更新数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ibtnUpdate_Click(object sender, ImageClickEventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); string itemname = Request.QueryString["itemname"]; AusMoney ausmoney = AusMoneyManager.GetModel(id); double haspay = ausmoney.haspay; if (Convert.ToDouble(this.txtmoney.Text.Trim()) < haspay) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "error", "<script>alert('更新失败,该人员在该项目下的总预算不能小于已支付的预算')</script>", false); } if (this.txtmoney.Text != "") { //bool has = AusMoneyManager.Exists(itemname, this.person.SelectedValue); //if (has) //{ // Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "error", "<script>alert('更新失败,该人员在该项目下已存在预算')</script>", false); //} //else //{ //ausmoney.username = this.person.SelectedValue; ausmoney.amount = Convert.ToDouble(this.txtmoney.Text.Trim()); bool count = AusMoneyManager.Update(ausmoney); if (count) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "success", "<script>alert('更新成功');window.location='DepartMoneyList.aspx?itemname=" + itemname + "';</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('更新失败')</script>", false); } //} } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "alert('请检查人员和金额是否已经填写');", true); } }
/// <summary> /// 更新以支付的金额 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool UpdateMoney(AusMoney model) { string str = "update DepartMoney set haspay=@haspay where id=@id"; SqlParameter[] parameters = { new SqlParameter("@haspay", SqlDbType.Money, 8), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.haspay; parameters[1].Value = model.id; int result = DBHelper.ExecuteCommand(str, parameters); if (result >= 1) { return(true); } else { return(false); } }
/// <summary> /// 添加数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ibtnAdd_Click(object sender, ImageClickEventArgs e) { string itemname = Request.QueryString["itemname"]; string username = this.person.SelectedValue; int year = DateTime.Now.Year; if (this.person.SelectedIndex != 0 && this.txtmoney.Text != "") { if (AusMoneyManager.Exists(itemname, username, year)) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "error", "<script>alert('添加失败,该人员在该项目下已存在预算')</script>", false); } else { AusMoney ausmoney = new AusMoney(); ausmoney.itemname = itemname; ausmoney.username = username; ausmoney.amount = double.Parse(this.txtmoney.Text.Trim()); ausmoney.year = year; bool count = AusMoneyManager.Add(ausmoney); if (count) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "success", "<script>alert('添加成功');window.location='DepartMoneyList.aspx?itemname=" + itemname + "';</script>", false); } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "add", "<script>alert('添加失败')</script>", false); } } } else { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "alert('请检查人员和金额是否已经填写');", true); } }
/// <summary> /// 更新已支付金额 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool UpdateMoney(AusMoney model) { return(AusMoneyService.UpdateMoney(model)); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool Add(AusMoney model) { return(AusMoneyService.Add(model)); }