//添加类别操作 protected void Button1_Click(object sender, EventArgs e) { string catTypeName = this.CatTypeNameEmpIns.Text.Trim(); string catTypePrice = this.CatTypePriceEmpIns.Text.Trim(); if (catTypeName == "") { Utility.Alert(this, "类别名称未填写!"); return; } if (catTypePrice != "") { if (!ValidHelper.CheckNumber(catTypePrice)) { Utility.Alert(this, "类别预算填写错误!"); return; } } else { catTypePrice = "0"; } UserCategoryInfo category = bll.GetUserCategoryByName(userId, catTypeName); category.CategoryTypeID = bll.GetMaxCategoryTypeId(userId); category.CategoryTypeName = catTypeName; category.CategoryTypePrice = Convert.ToInt32(catTypePrice); category.UserID = userId; category.CategoryTypeLive = 1; category.Synchronize = 1; category.ModifyDate = DateTime.Now; if (category.UserCategoryID > 0) { Utility.Alert(this, "类别已存在,不能重复添加!"); return; } bool success = bll.InsertUserCategory(category); if (success) { Utility.Alert(this, "添加成功。", "UserCategoryAdmin.aspx"); } else { Utility.Alert(this, "添加失败!"); } }
protected void Page_Load(object sender, EventArgs e) { userId = Convert.ToInt32(Session["UserID"]); today = Convert.ToDateTime(Session["TodayDate"]); if (Request.QueryString["catTypeId"] != null && Request.QueryString["catTypeId"] != "") { if (!ValidHelper.CheckNumber(Request.QueryString["catTypeId"])) { Response.Redirect("FenLeiZongJi.aspx"); } else { catTypeId = Convert.ToInt32(Request.QueryString["catTypeId"]); } } if (!IsPostBack) { PopulateControls(); } }
//修改资料 protected void SubmitButton_Click(object sender, EventArgs e) { string userNickName = this.UserNickName.Text.Trim(); string userEmail = this.UserEmail.Text.Trim(); string userPhone = this.UserPhone.Text.Trim(); string userWorkDay = this.UserWorkDay.SelectedValue; string categoryRate = this.CategoryRate.Text.Trim(); this.Label3.Text = ""; if (userEmail != "") { if (!ValidHelper.CheckEmail(userEmail)) { this.Label3.Text = "邮箱格式填写错误!"; return; } } if (userPhone != "") { if (!ValidHelper.CheckPhone(userPhone)) { this.Label6.Text = "手机号码填写错误!"; return; } } if (!ValidHelper.CheckNumber(categoryRate)) { Utility.Alert(this, "预算率填写错误!"); return; } int rateValue = Convert.ToInt32(categoryRate); if (rateValue > 100) { Utility.Alert(this, "预算率不能大于100!"); return; } user.UserNickName = userNickName; user.UserEmail = userEmail; user.UserPhone = userPhone; user.UserWorkDay = userWorkDay; user.CategoryRate = rateValue; user.Synchronize = 1; user.ModifyDate = DateTime.Now; bool success = bll.UpdateUser(user); if (success) { Session["UserNickName"] = user.UserNickName; Session["UserWorkDay"] = user.UserWorkDay; Session["CategoryRate"] = user.CategoryRate; Utility.Alert(this, "修改成功。", "UserAdmin.aspx#info"); } else { Utility.Alert(this, "修改失败!"); } }
//类别更新操作 protected void CatTypeList_RowUpdating(object sender, GridViewUpdateEventArgs e) { int catTypeId = Convert.ToInt32(CatTypeList.DataKeys[e.RowIndex].Value); string catTypeName = ((TextBox)CatTypeList.Rows[e.RowIndex].FindControl("CatTypeNameBox")).Text.Trim(); string catTypeNameHid = ((HiddenField)CatTypeList.Rows[e.RowIndex].FindControl("CatTypeNameHid")).Value; string catTypePrice = ((TextBox)CatTypeList.Rows[e.RowIndex].FindControl("CatTypePriceBox")).Text.Trim(); if (catTypeName == "") { Utility.Alert(this, "类别名称未填写!"); return; } if (catTypePrice != "") { if (!ValidHelper.CheckNumber(catTypePrice)) { Utility.Alert(this, "类别预算填写错误!"); return; } } else { catTypePrice = "0"; } bool success = false; UserCategoryInfo category = new UserCategoryInfo(); if (catTypeName != catTypeNameHid) { category = bll.GetUserCategoryByName(userId, catTypeName); if (category.CategoryTypeID > 0) { Utility.Alert(this, "类别已存在,不能重复添加!"); return; } } category.CategoryTypeID = catTypeId; category.CategoryTypeName = catTypeName; category.CategoryTypePrice = Convert.ToInt32(catTypePrice); category.UserID = userId; category.CategoryTypeLive = 1; category.Synchronize = 1; category.ModifyDate = DateTime.Now; using (TransactionScope ts = new TransactionScope()) { success = bll.DeleteUserCategory(userId, catTypeId); success = bll.InsertUserCategory(category); ts.Complete(); } if (success) { CacheHelper.RemoveCache(string.Format("cattype_{0}", userId)); Utility.Alert(this, "更新成功。"); CatTypeList.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "更新失败!"); } }