//修改资料 protected void SubmitButton_Click(object sender, EventArgs e) { string userNickName = this.UserNickName.Text.Trim(); this.Label3.Text = ""; string userEmail = this.UserEmail.Text.Trim(); if (userEmail != "") { if (!ValidHelper.CheckEmail(userEmail)) { this.Label3.Text = "邮箱格式填写错误!"; return; } } string userPhone = this.UserPhone.Text.Trim(); if (userPhone != "") { if (!ValidHelper.CheckPhone(userPhone)) { this.Label6.Text = "手机号码填写错误!"; return; } } string userWorkDay = this.UserWorkDay.SelectedValue; string categoryRate = this.CategoryRate.Text.Trim(); if (!ValidHelper.CheckDouble(categoryRate)) { Utility.Alert(this, "预算率填写错误!"); return; } UserEntity user = UserAccess.GetUserById(userId); user.UserNickName = userNickName; user.UserEmail = userEmail; user.UserPhone = userPhone; user.UserWorkDay = userWorkDay; user.CategoryRate = Double.Parse(categoryRate); user.Synchronize = 1; bool success = UserAccess.UpdateUser(user); if (success) { Session["UserNickName"] = user.UserNickName; Session["UserWorkDay"] = user.UserWorkDay; Session["CategoryRate"] = user.CategoryRate; Utility.Alert(this, "修改成功。", "UserAdmin.aspx"); } else { Utility.Alert(this, "修改失败!"); } }
//快速添加消费 protected void LinkButton1_Click(object sender, EventArgs e) { string itemName = this.ItemNameEmpIns.Text.Trim(); string itemType = this.ItemTypeEmpIns.SelectedValue; int catTypeId = Convert.ToInt32(this.CatTypeEmpIns.SelectedValue); string itemPrice = this.ItemPriceEmpIns.Text.Trim(); DateTime itemBuyDate = Convert.ToDateTime(this.ItemBuyDateEmpIns.Text.Trim() + " " + DateTime.Now.ToString("HH:mm:ss")); int cardId = Convert.ToInt32(this.CardEmpIns.SelectedValue); if (itemName == "") { Utility.Alert(this, "商品名称未填写!"); return; } Response.Cookies["CatTypeID"].Value = catTypeId.ToString(); Response.Cookies["CatTypeID"].Expires = DateTime.MaxValue; Response.Cookies["CardID"].Value = cardId.ToString(); Response.Cookies["CardID"].Expires = DateTime.MaxValue; if (!ValidHelper.CheckDouble(itemPrice)) { Utility.Alert(this, "商品价格填写错误!"); return; } ItemInfo item = new ItemInfo(); item.ItemType = itemType; item.ItemName = itemName; item.CategoryTypeID = catTypeId; item.ItemPrice = Convert.ToDecimal(itemPrice); item.ItemBuyDate = itemBuyDate; item.UserID = userId; item.RegionID = 0; item.RegionType = ""; item.Synchronize = 1; item.ZhuanTiID = ztId; item.ModifyDate = DateTime.Now; item.CardID = cardId; bool success = item_bll.InsertItem(item); if (success) { Session["TodayDate"] = itemBuyDate.ToString("yyyy-MM-dd"); this.ItemNameEmpIns.Text = ""; this.ItemPriceEmpIns.Text = ""; List.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "添加失败!"); return; } }
//保存方法 protected int SaveItem() { string itemName = this.ItemNameEmpIns.Text.Trim(); if (itemName == "") { Utility.Alert(this, "商品名称未填写!"); return(2); } string itemType = this.ItemTypeEmpIns.SelectedValue; int catTypeId = Int32.Parse(this.CatTypeEmpIns.SelectedValue); Response.Cookies["CatTypeID"].Value = catTypeId.ToString(); Response.Cookies["CatTypeID"].Expires = DateTime.MaxValue; string itemPrice = this.ItemPriceEmpIns.Text.Trim(); if (!ValidHelper.CheckDouble(itemPrice)) { Utility.Alert(this, "商品价格填写错误!"); return(2); } DateTime itemBuyDate = DateTime.Parse(today + " " + DateTime.Now.ToString("HH:mm:ss")); int cardId = Int32.Parse(this.CardEmpIns.SelectedValue); Response.Cookies["CardID"].Value = cardId.ToString(); Response.Cookies["CardID"].Expires = DateTime.MaxValue; ItemEntity item = new ItemEntity(); item.ItemType = itemType; item.ItemName = itemName; item.CategoryTypeID = catTypeId; item.ItemPrice = Double.Parse(itemPrice); item.ItemBuyDate = itemBuyDate; item.UserID = userId; item.RegionID = 0; item.RegionType = ""; item.Synchronize = 1; item.CardID = cardId; bool success = ItemAccess.InsertItem(item, 1); if (success) { Session["TodayDate"] = itemBuyDate.ToString("yyyy-MM-dd"); return(1); } else { return(0); } }
//添加钱包操作 protected void Button1_Click(object sender, EventArgs e) { string cardName = this.CardNameEmpIns.Text.Trim(); string cardMoney = this.CardMoneyEmpIns.Text.Trim(); if (cardName == "") { Utility.Alert(this, "钱包名称未填写!"); return; } if (cardMoney != "") { if (!ValidHelper.CheckDouble(cardMoney)) { Utility.Alert(this, "余额填写错误!"); return; } } else { cardMoney = "0"; } CardInfo card = bll.GetCardByCardName(userId, cardName); card.CardName = cardName; card.MoneyStart = Convert.ToDecimal(cardMoney); card.UserID = userId; card.CardLive = 1; card.Synchronize = 1; card.CDID = bll.GetMaxCardId(userId); card.ModifyDate = DateTime.Now; if (card.CardID > 0 || cardName == "我的钱包") { Utility.Alert(this, "钱包已存在,不能重复添加!"); return; } bool success = bll.InsertCard(card); if (success) { Utility.Alert(this, "添加成功。", "UserCardAdmin.aspx"); } else { Utility.Alert(this, "添加失败!"); } }
//类别更新操作 protected void CardList_RowUpdating(object sender, GridViewUpdateEventArgs e) { int cardId = Int32.Parse(CardList.DataKeys[e.RowIndex].Value.ToString()); TextBox cardNameBox = (TextBox)CardList.Rows[e.RowIndex].FindControl("CardNameBox"); string cardName = cardNameBox.Text.Trim(); if (cardName == "") { Utility.Alert(this, "名称未填写!"); return; } TextBox cardMoneyBox = (TextBox)CardList.Rows[e.RowIndex].FindControl("CardMoneyBox"); string cardMoney = cardMoneyBox.Text.Trim(); if (!ValidHelper.CheckDouble(cardMoney)) { Utility.Alert(this, "余额填写错误!"); return; } bool success = false; if (cardId == 0) { success = UserAccess.UpdateUserMoneyNew(userId, Double.Parse(cardMoney)); } else { CardEntity card = new CardEntity(); card.CardID = cardId; card.CardName = cardName; card.CardMoney = Double.Parse(cardMoney); card.UserID = userId; card.CardLive = 1; card.Synchronize = 1; success = CardAccess.UpdateCard(card); } if (success) { Utility.Alert(this, "更新成功。"); CardList.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "更新失败!"); } }
//检查内容 private bool CheckSave() { string itemType = this.ItemTypeHid.Value; int catTypeId = Convert.ToInt32(this.CategoryTypeDown.SelectedValue); string itemName = this.ItemName.Text.Trim(); string itemPrice = this.ItemPrice.Text.Trim(); if (itemType == "") { Utility.Alert(this, "消费分类填写错误!"); return(false); } if (catTypeId == 0) { Utility.Alert(this, "商品类别填写错误!"); return(false); } if (itemName == "") { Utility.Alert(this, "商品名称填写错误!"); return(false); } if (!ValidHelper.CheckDouble(itemPrice)) { Utility.Alert(this, "商品价格填写错误!"); return(false); } if (this.RegionID.Checked) { if (!ValidHelper.CheckDate(this.ItemBuyDate1.Text.Trim()) || !ValidHelper.CheckDate(this.ItemBuyDate2.Text.Trim())) { Utility.Alert(this, "购买日期填写错误!"); return(false); } } else { if (!ValidHelper.CheckDate(this.ItemBuyDateHid.Value)) { Utility.Alert(this, "购买日期填写错误!"); return(false); } } return(true); }
//添加类别操作 protected void Button1_Click(object sender, EventArgs e) { string catTypeName = this.CatTypeNameEmpIns.Text.Trim(); if (catTypeName == "") { Utility.Alert(this, "类别名称未填写!"); return; } string catTypePrice = this.CatTypePriceEmpIns.Text.Trim(); if (catTypePrice != "") { if (!ValidHelper.CheckDouble(catTypePrice)) { Utility.Alert(this, "类别预算填写错误!"); return; } } else { catTypePrice = "0"; } UserCategoryEntity userCat = new UserCategoryEntity(); userCat.CategoryTypeName = catTypeName; userCat.CategoryTypePrice = Double.Parse(catTypePrice); userCat.UserID = userId; userCat.CategoryTypeLive = 1; userCat.Synchronize = 1; int catTypeId = 0; bool success = UserCategoryAccess.InsertCategoryType(userCat, out catTypeId); if (success) { Utility.Alert(this, "添加成功。", "UserCategoryAdmin.aspx"); } else { Utility.Alert(this, "添加失败!"); } }
//添加类别操作 protected void Button1_Click(object sender, EventArgs e) { string cardName = this.CardNameEmpIns.Text.Trim(); if (cardName == "") { Utility.Alert(this, "名称未填写!"); return; } string cardMoney = this.CardMoneyEmpIns.Text.Trim(); if (cardMoney != "") { if (!ValidHelper.CheckDouble(cardMoney)) { Utility.Alert(this, "余额填写错误!"); return; } } else { cardMoney = "0"; } CardEntity card = new CardEntity(); card.CardName = cardName; card.CardMoney = Double.Parse(cardMoney); card.UserID = userId; card.CardLive = 1; card.Synchronize = 1; bool success = CardAccess.InsertCard(card); if (success) { Utility.Alert(this, "添加成功。", "UserCardAdmin.aspx"); } else { Utility.Alert(this, "添加失败!"); } }
//类别更新操作 protected void CatTypeList_RowUpdating(object sender, GridViewUpdateEventArgs e) { int catTypeId = Int32.Parse(CatTypeList.DataKeys[e.RowIndex].Value.ToString()); TextBox catTypeNameBox = (TextBox)CatTypeList.Rows[e.RowIndex].FindControl("CatTypeNameBox"); string catTypeName = catTypeNameBox.Text.Trim(); if (catTypeName == "") { Utility.Alert(this, "类别名称未填写!"); return; } TextBox catTypePriceBox = (TextBox)CatTypeList.Rows[e.RowIndex].FindControl("CatTypePriceBox"); string catTypePrice = catTypePriceBox.Text.Trim(); if (!ValidHelper.CheckDouble(catTypePrice)) { Utility.Alert(this, "类别预算填写错误!"); return; } UserCategoryEntity userCat = new UserCategoryEntity(); userCat.CategoryTypeID = catTypeId; userCat.CategoryTypeName = catTypeName; userCat.CategoryTypePrice = Double.Parse(catTypePrice); userCat.UserID = userId; userCat.CategoryTypeLive = 1; userCat.Synchronize = 1; bool success = UserCategoryAccess.UpdateCategoryType(userCat); if (success) { Utility.Alert(this, "更新成功。"); CatTypeList.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "更新失败!"); } }
//钱包更新操作 protected void CardList_RowUpdating(object sender, GridViewUpdateEventArgs e) { int cardId = Convert.ToInt32(CardList.DataKeys[e.RowIndex].Value); string cardName = ((TextBox)CardList.Rows[e.RowIndex].FindControl("CardNameBox")).Text.Trim(); string cardNameHid = ((HiddenField)CardList.Rows[e.RowIndex].FindControl("CardNameHid")).Value; string cardMoneyBox = ((TextBox)CardList.Rows[e.RowIndex].FindControl("CardMoneyBox")).Text.Trim(); decimal cardMoneyHid = Convert.ToDecimal(((HiddenField)CardList.Rows[e.RowIndex].FindControl("CardMoneyHid")).Value); decimal moneyStartHid = Convert.ToDecimal(((HiddenField)CardList.Rows[e.RowIndex].FindControl("MoneyStartHid")).Value); decimal cardBalanceHid = Convert.ToDecimal(((HiddenField)CardList.Rows[e.RowIndex].FindControl("CardBalanceHid")).Value); if (cardName == "") { Utility.Alert(this, "钱包名称未填写!"); return; } if (!ValidHelper.CheckDouble(cardMoneyBox)) { Utility.Alert(this, "余额填写错误!"); return; } decimal cardMoney = 0m; if (moneyStartHid == 0) { cardMoney = Convert.ToDecimal(cardMoneyBox) - cardBalanceHid; } else { cardMoney = Convert.ToDecimal(cardMoneyBox) + moneyStartHid - cardBalanceHid; } bool IsUpdate = Session["IsUpdate"].ToString() == "1"; if (!IsUpdate) { cardMoney = Convert.ToDecimal(cardMoneyBox); } bool success = false; if (cardId == 0) { UserInfo user = user_bll.GetUserByUserId(userId); if (!IsUpdate) { user.UserMoney = cardMoney; } if (IsUpdate) { user.MoneyStart = cardMoney; } user.ModifyDate = DateTime.Now; user.Synchronize = 1; success = user_bll.UpdateUser(user); } else { CardInfo card = new CardInfo(); if (cardName != cardNameHid) { card = bll.GetCardByCardName(userId, cardName); if (card.CardID > 0) { Utility.Alert(this, "钱包已存在,不能重复添加!"); return; } } card.CDID = cardId; card.CardName = cardName; if (!IsUpdate) { card.CardMoney = cardMoney; } if (IsUpdate) { card.MoneyStart = cardMoney; } card.UserID = userId; card.CardLive = 1; card.Synchronize = 1; card.ModifyDate = DateTime.Now; success = bll.UpdateCard(card); } if (success) { CacheHelper.RemoveCache(string.Format("cardtype_{0}", userId)); Utility.Alert(this, "更新成功。"); CardList.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "更新失败!"); } }
//转账 protected void SubmitButtom_Click(object sender, EventArgs e) { int cardId = Convert.ToInt32(this.CardIDEditHid.Value); int toCardId = Convert.ToInt32(this.CardDownEdit.SelectedValue); string cardMoney = this.CardMoneyEdit.Text.Trim(); string cardDate = this.CardDateEdit.Text; string cardNote = this.CardNoteEdit.Text; if (!ValidHelper.CheckDouble(cardMoney)) { Utility.Alert(this, "金额填写错误!"); return; } if (cardId == toCardId) { Utility.Alert(this, "不允许转给相同钱包!"); return; } using (TransactionScope ts = new TransactionScope()) { CardInfo card = new CardInfo(); UserInfo user = user_bll.GetUserByUserId(userId); decimal newMoney = Convert.ToDecimal(cardMoney); if (cardId == 0) { if (user.IsUpdate == 1) { user.MoneyStart = user.MoneyStart - newMoney; } else { user.UserMoney = user.UserMoney - newMoney; } user.ModifyDate = DateTime.Now; user.Synchronize = 1; user_bll.UpdateUser(user); } else { card = bll.GetCardByCardId(userId, cardId); if (user.IsUpdate == 1) { card.MoneyStart = card.MoneyStart - newMoney; } else { card.CardMoney = card.CardMoney - newMoney; } card.ModifyDate = DateTime.Now; card.Synchronize = 1; bll.UpdateCard(card); } if (toCardId == 0) { if (user.IsUpdate == 1) { user.MoneyStart = user.MoneyStart + newMoney; } else { user.UserMoney = user.UserMoney + newMoney; } user.ModifyDate = DateTime.Now; user.Synchronize = 1; user_bll.UpdateUser(user); } else { card = bll.GetCardByCardId(userId, toCardId); if (user.IsUpdate == 1) { card.MoneyStart = card.MoneyStart + newMoney; } else { card.CardMoney = card.CardMoney + newMoney; } card.ModifyDate = DateTime.Now; card.Synchronize = 1; bll.UpdateCard(card); } ZhuanZhangInfo zhuan = new ZhuanZhangInfo(); zhuan.ZhuanZhangFrom = cardId; zhuan.ZhuanZhangTo = toCardId; zhuan.ZhuanZhangDate = Convert.ToDateTime(cardDate); zhuan.ZhuanZhangMoney = Convert.ToDecimal(cardMoney); zhuan.ZhuanZhangLive = 1; zhuan.Synchronize = 1; zhuan.ModifyDate = DateTime.Now; zhuan.UserID = userId; zhuan.ZZID = zhuan_bll.GetMaxZhuanZhangId(userId); zhuan.ZhuanZhangNote = cardNote; bool success = zhuan_bll.InsertZhuanZhang(zhuan); if (!success) { Utility.Alert(this, "保存转账记录失败!"); } ts.Complete(); } Response.Redirect("UserCardAdmin.aspx"); }
protected int SaveItem() { string itemType = this.ItemTypeHid.Value; if (itemType == "") { Utility.Alert(this, "消费分类填写错误!"); return(2); } int catTypeId = Int32.Parse(this.CategoryTypeDown.SelectedValue); if (catTypeId == 0) { Utility.Alert(this, "商品类别填写错误!"); return(2); } Response.Cookies["CatTypeID"].Value = catTypeId.ToString(); Response.Cookies["CatTypeID"].Expires = DateTime.MaxValue; string itemName = this.ItemName.Text.Trim(); if (itemName == "") { Utility.Alert(this, "商品名称填写错误!"); return(2); } int userId = Int32.Parse(Session["UserID"].ToString()); string itemPrice = this.ItemPrice.Text.Trim(); if (!ValidHelper.CheckDouble(itemPrice)) { Utility.Alert(this, "商品价格填写错误!"); return(2); } int zhuanTiId = Int32.Parse(this.ZhuanTiDown.SelectedValue); int cardId = Int32.Parse(this.CardDown.SelectedValue); Response.Cookies["CardID"].Value = cardId.ToString(); Response.Cookies["CardID"].Expires = DateTime.MaxValue; DateTime itemBuyDate = DateTime.Now; DateTime itemBuyDate1 = DateTime.Now; DateTime itemBuyDate2 = DateTime.Now; int monthRegion = 0; int regionId = 0; string regionType = ""; if (this.RegionID.Checked) { if (!ValidHelper.CheckDate(this.ItemBuyDate1.Text.Trim()) || !ValidHelper.CheckDate(this.ItemBuyDate2.Text.Trim())) { Utility.Alert(this, "购买日期填写错误!"); return(2); } else { itemBuyDate1 = DateTime.Parse(this.ItemBuyDate1.Text.Trim() + " " + DateTime.Now.ToString("HH:mm:ss")); itemBuyDate2 = DateTime.Parse(this.ItemBuyDate2.Text.Trim() + " " + DateTime.Now.ToString("HH:mm:ss")); } regionType = this.RegionTypeHid.Value; itemBuyDate = itemBuyDate1; regionId = Int32.Parse(ItemAccess.GetItemListMaxRegionId(userId)); monthRegion = ItemHelper.GetMonthRegion(itemBuyDate1, itemBuyDate2, regionType); //判断区间最大天数 int maxRegion = 0; string regionStr = ""; switch (regionType) { case "d": case "b": maxRegion = 92; regionStr = "应小于3个月。"; break; case "w": maxRegion = (int)Math.Floor((double)92 / 7); regionStr = "应小于3个月。"; break; case "m": maxRegion = 36; regionStr = "应小于3年。"; break; case "y": maxRegion = 15; regionStr = "应小于15年。"; break; } if (monthRegion <= 0 || monthRegion >= maxRegion) { Utility.Alert(this, "区间日期设置不合理!" + regionStr); return(2); } } else { if (!ValidHelper.CheckDate(this.ItemBuyDateHid.Value)) { Utility.Alert(this, "购买日期填写错误!"); return(2); } else { itemBuyDate = DateTime.Parse(this.ItemBuyDateHid.Value + " " + DateTime.Now.ToString("HH:mm:ss")); itemBuyDate1 = itemBuyDate; } } ItemEntity item = new ItemEntity(); item.ItemType = itemType; item.ItemName = itemName; item.CategoryTypeID = catTypeId; item.ItemPrice = Double.Parse(itemPrice); item.UserID = userId; item.RegionID = regionId; item.RegionType = regionType; item.Synchronize = 1; item.ZhuanTiID = zhuanTiId; item.CardID = cardId; bool success = false; for (int i = 0; i <= monthRegion; i++) { switch (regionType) { case "d": itemBuyDate = itemBuyDate1.AddDays(i); break; case "w": itemBuyDate = itemBuyDate1.AddDays(i * 7); break; case "m": itemBuyDate = itemBuyDate1.AddMonths(i); break; case "y": itemBuyDate = itemBuyDate1.AddYears(i); break; case "b": DateTime curDate = itemBuyDate1.AddDays(i); if (ItemHelper.GetWorkDayFinal(curDate, Session["UserWorkDay"].ToString())) { itemBuyDate = curDate; } else { continue; } break; } item.ItemBuyDate = itemBuyDate; success = ItemAccess.InsertItem(item, 1); } if (success) { Session["TodayDate"] = itemBuyDate1.ToString("yyyy-MM-dd"); return(1); } else { return(0); } }