protected void PupolateControls() { int userId = 0; if (Request.QueryString["userId"] != "" && Request.QueryString["userId"] != null) { userId = Int32.Parse(Request.QueryString["userId"]); } UserList.DataSource = UserAccess.GetAdminUserListById(userId); UserList.DataBind(); OAuthList.DataSource = OAuthAccess.GetAdminOAuthList(userId); OAuthList.DataBind(); UserCategoryList.DataSource = UserCategoryAccess.GetAdminUserCategoryList(userId); UserCategoryList.DataBind(); ZhuanTiList.DataSource = ZhuanTiAccess.GetAdminZhuanTiList(userId); ZhuanTiList.DataBind(); CardList.DataSource = CardAccess.GetAdminCardList(userId); CardList.DataBind(); List.DataSource = ItemAccess.GetAdminItemListByUserId(userId); List.DataBind(); }
//取类别ID protected int GetCategoryTypeId(string name, DataTable dt) { foreach (DataRow dr in dt.Rows) { if (name == dr["CategoryTypeName"].ToString()) { return(Int32.Parse(dr["CategoryTypeID"].ToString())); } } UserCategoryEntity userCat = new UserCategoryEntity(); userCat.CategoryTypeName = name; userCat.UserID = userId; userCat.CategoryTypeLive = 1; userCat.Synchronize = 1; int catTypeId = 0; bool success = UserCategoryAccess.InsertCategoryType(userCat, out catTypeId); if (!success) { throw new Exception(); } return(catTypeId); }
protected void Page_Load(object sender, EventArgs e) { userId = Int32.Parse(Session["UserID"].ToString()); zhuanTiId = Int32.Parse(Request.QueryString["ztid"]); catTypeList = UserCategoryAccess.GetCategoryTypeList(userId); itemTypeList = ItemAccess.GetItemListType(); if (!IsPostBack) { BindGrid(); this.CatTypeEmpIns.DataSource = catTypeList; this.CatTypeEmpIns.DataTextField = "CategoryTypeName"; this.CatTypeEmpIns.DataValueField = "CategoryTypeID"; this.CatTypeEmpIns.DataBind(); if (Request.Cookies["CatTypeID"] != null) { this.CatTypeEmpIns.SelectedValue = Request.Cookies["CatTypeID"].Value; } this.ItemTypeEmpIns.DataSource = itemTypeList; this.ItemTypeEmpIns.DataTextField = "ItemTypeName"; this.ItemTypeEmpIns.DataValueField = "ItemTypeValue"; this.ItemTypeEmpIns.DataBind(); if (Session["TodayDate"] != null) { string today = Session["TodayDate"].ToString(); this.ItemBuyDateEmpIns.Text = today; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int userId = Int32.Parse(Session["UserID"].ToString()); DataTable catTypeList = UserCategoryAccess.GetCategoryTypeList(userId); this.CatTypeList.DataSource = catTypeList; this.CatTypeList.DataBind(); this.CategoryTypeDown.DataSource = catTypeList; this.CategoryTypeDown.DataTextField = "CategoryTypeName"; this.CategoryTypeDown.DataValueField = "CategoryTypeID"; this.CategoryTypeDown.DataBind(); this.CategoryTypeDown.Items.Insert(0, new ListItem("请选择", "0")); this.ZhuanTiDown.DataSource = ZhuanTiAccess.GetZhuanTiList(userId); this.ZhuanTiDown.DataTextField = "ZhuanTiName"; this.ZhuanTiDown.DataValueField = "ZTID"; this.ZhuanTiDown.DataBind(); this.ZhuanTiDown.Items.Insert(0, new ListItem("请选择", "0")); this.ItemType.Attributes.Add("readonly", "readonly"); this.CategoryTypeDown.Attributes.Add("readonly", "readonly"); this.ItemBuyDate.Attributes.Add("readonly", "readonly"); //this.ItemBuyDate1.Attributes.Add("readonly", "readonly"); //this.ItemBuyDate2.Attributes.Add("readonly", "readonly"); if (Session["TodayDate"] != null) { string today = Session["TodayDate"].ToString(); string today2 = DateTime.Parse(today).AddMonths(11).ToString("yyyy-MM-dd"); this.ItemBuyDate.Text = today + " " + ItemHelper.GetWeekString(today, 0); this.ItemBuyDateHid.Value = today; this.ItemBuyDate1.Text = today; this.ItemBuyDate2.Text = today2; } //钱包 this.CardDown.DataSource = CardAccess.GetCardList(userId); this.CardDown.DataTextField = "CardName"; this.CardDown.DataValueField = "CardID"; this.CardDown.DataBind(); if (Request.Cookies["CardID"] != null) { string cardId = Request.Cookies["CardID"].Value; this.CardDown.SelectedValue = cardId; } } }
protected void Page_Load(object sender, EventArgs e) { userId = Int32.Parse(Session["UserID"].ToString()); catTypeList = UserCategoryAccess.GetCategoryTypeList(userId); itemTypeList = ItemAccess.GetItemListType(); cardList = CardAccess.GetCardList(userId); if (Request.QueryString["date"] != null && Request.QueryString["date"] != "") { if (!ValidHelper.CheckDate(Request.QueryString["date"])) { Session["TodayDate"] = DateTime.Now.ToString("yyyy-MM-dd"); } else { Session["TodayDate"] = Request.QueryString["date"]; } } today = Session["TodayDate"].ToString(); if (!IsPostBack) { BindGrid(); this.CatTypeEmpIns.DataSource = catTypeList; this.CatTypeEmpIns.DataTextField = "CategoryTypeName"; this.CatTypeEmpIns.DataValueField = "CategoryTypeID"; this.CatTypeEmpIns.DataBind(); if (Request.Cookies["CatTypeID"] != null) { this.CatTypeEmpIns.SelectedValue = Request.Cookies["CatTypeID"].Value; } this.ItemTypeEmpIns.DataSource = itemTypeList; this.ItemTypeEmpIns.DataTextField = "ItemTypeName"; this.ItemTypeEmpIns.DataValueField = "ItemTypeValue"; this.ItemTypeEmpIns.DataBind(); //钱包 this.CardEmpIns.DataSource = cardList; this.CardEmpIns.DataTextField = "CardName"; this.CardEmpIns.DataValueField = "CardID"; this.CardEmpIns.DataBind(); if (Request.Cookies["CardID"] != null) { this.CardEmpIns.SelectedValue = Request.Cookies["CardID"].Value; } } }
//添加类别操作 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 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 BindGrid() { double catRate = Double.Parse(Session["CategoryRate"].ToString()); DataTable dt = UserCategoryAccess.GetCategoryTypeList(userId); dt.Columns.Add("CategoryTypeRate", typeof(string)); foreach (DataRow dr in dt.Rows) { double catPrice = Double.Parse(dr["CategoryTypePrice"].ToString()); double[] denArr = GetDenArray(catPrice, catRate); if (catPrice > 0) { dr["CategoryTypeRate"] = denArr[0] + " ~ " + denArr[1]; } else { dr["CategoryTypeRate"] = "0"; } } this.CatTypeList.DataSource = dt; this.CatTypeList.DataBind(); }
//类别删除操作 protected void CatTypeList_RowDeleting(object sender, GridViewDeleteEventArgs e) { int catTypeId = Int32.Parse(CatTypeList.DataKeys[e.RowIndex].Value.ToString()); string catTypeName = ((Label)CatTypeList.Rows[e.RowIndex].FindControl("CatTypeNameLab")).Text; string catTypePrice = ((Label)CatTypeList.Rows[e.RowIndex].FindControl("CatTypePriceLab")).Text; UserCategoryEntity userCat = new UserCategoryEntity(); userCat.CategoryTypeID = catTypeId; userCat.CategoryTypeName = catTypeName; userCat.CategoryTypePrice = Double.Parse(catTypePrice); userCat.UserID = userId; userCat.CategoryTypeLive = 0; userCat.Synchronize = 1; bool success = UserCategoryAccess.CheckItemListByCatId(userId, catTypeId); if (!success) { success = UserCategoryAccess.DeleteCategoryType(userCat); if (success) { Utility.Alert(this, "删除成功。"); CatTypeList.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "删除失败!"); } } else { Utility.Alert(this, "不能删除已使用的类别!"); } }
//导出数据到App// protected void Button1_Click(object sender, EventArgs e) { int userId = Int32.Parse(Session["UserID"].ToString()); fileName = "aalife2.bak"; StringBuilder sb = new StringBuilder(); DataTable itemListTab = BackupAccess.BackupItemTableById(userId); if (itemListTab.Rows.Count > 0) { sb.AppendLine("DELETE FROM ItemTable;"); foreach (DataRow dr in itemListTab.Rows) { sb.AppendLine("INSERT INTO ItemTable (ItemType, ItemName, ItemPrice, ItemBuyDate, CategoryID, Recommend, Synchronize, RegionID, RegionType, ZhuanTiID, CardID) VALUES ('" + dr["ItemType"].ToString() + "', '" + dr["ItemName"].ToString() + "', '" + dr["ItemPrice"].ToString() + "', '" + String.Format("{0:yyyy-MM-dd}", dr["ItemBuyDate"]) + "', '" + dr["CategoryTypeID"].ToString() + "', '" + dr["Recommend"].ToString() + "', '0', '" + dr["RegionID"].ToString() + "', '" + dr["RegionType"].ToString() + "', '" + dr["ZhuanTiID"].ToString() + "', '" + dr["CardID"].ToString() + "');"); } sb.AppendLine(""); } DataTable catListTab = UserCategoryAccess.GetCategoryTypeList(userId); if (catListTab.Rows.Count > 0) { sb.AppendLine("DELETE FROM CategoryTable;"); foreach (DataRow dr in catListTab.Rows) { sb.AppendLine("INSERT INTO CategoryTable (CategoryID, CategoryName, CategoryPrice, CategoryRank, CategoryDisplay, CategoryLive) VALUES ('" + dr["CategoryTypeID"].ToString() + "', '" + dr["CategoryTypeName"].ToString() + "', '" + dr["CategoryTypePrice"].ToString() + "', '" + dr["CategoryTypeID"].ToString() + "', '1', '1');"); } sb.AppendLine(""); } DataTable zhuanTiTab = ZhuanTiAccess.GetZhuanTiList(userId); if (zhuanTiTab.Rows.Count > 0) { sb.AppendLine("DELETE FROM ZhuanTiTable;"); foreach (DataRow dr in zhuanTiTab.Rows) { sb.AppendLine("INSERT INTO ZhuanTiTable (ZTID, ZhuanTiName, ZhuanTiImage, ZhuanTiLive, Synchronize) VALUES ('" + dr["ZTID"].ToString() + "', '" + dr["ZhuanTiName"].ToString() + "', '" + dr["ZhuanTiImage"].ToString() + "', '" + dr["ZhuanTiLive"].ToString() + "', '0');"); } sb.AppendLine(""); } DataTable cardTab = CardAccess.GetCardList(userId); if (cardTab.Rows.Count > 0) { sb.AppendLine("DELETE FROM CardTable;"); foreach (DataRow dr in cardTab.Rows) { if (dr["CardID"].ToString() == "0") { continue; } sb.AppendLine("INSERT INTO CardTable (CDID, CardName, CardMoney, CardLive, Synchronize) VALUES ('" + dr["CardID"].ToString() + "', '" + dr["CardName"].ToString() + "', '" + dr["CardMoney"].ToString() + "', '" + dr["CardLive"].ToString() + "', '0');"); } } BackupAccess.WriteBackupFile(filePath + fileName, sb.ToString()); //Utility.Alert(this, "导出成功。"); DownBackFile(); }
//导入保存 protected int[] SaveExcel(DataTable dt) { int[] arr = new int[2]; all = UserAccess.ExportUserData(userId); catTypeList = UserCategoryAccess.GetCategoryTypeList(userId); string dbProviderName = WebConfiguration.DbProviderName; string dbConnectionString = WebConfiguration.DbConnectionString; DbProviderFactory factory = DbProviderFactories.GetFactory(dbProviderName); using (DbConnection conn = factory.CreateConnection()) { conn.ConnectionString = dbConnectionString; conn.Open(); DbTransaction tran = conn.BeginTransaction(); DbCommand comm = conn.CreateCommand(); comm.Connection = conn; comm.Transaction = tran; try { int n1 = 0; int n2 = 0; StringBuilder sb = new StringBuilder(); foreach (DataRow dr in dt.Rows) { string _itemType = GetItemTypeValue(dr["分类"].ToString()); string _itemName = dr["商品名称"].ToString(); int _catTypeId = GetCategoryTypeId(dr["商品类别"].ToString(), catTypeList); string _itemPrice = dr["商品价格"].ToString(); DateTime _itemBuyDate = DateTime.Parse(dr["购买日期"].ToString()); int _recommend = (dr["推荐否"].ToString() == "否" ? 0 : 1); ItemEntity item = new ItemEntity(); item.ItemType = _itemType; item.ItemName = _itemName; item.CategoryTypeID = _catTypeId; item.ItemPrice = (_itemPrice == "" ? 0 : Double.Parse(_itemPrice)); item.ItemBuyDate = _itemBuyDate; item.Recommend = _recommend; if (CheckRepeat(item, catTypeList)) { n2++; continue; } sb.AppendLine("INSERT INTO ItemTable(ItemType, ItemName, CategoryTypeID, ItemPrice, ItemBuyDate, UserID, Recommend) VALUES('" + item.ItemType + "','" + item.ItemName + "','" + item.CategoryTypeID + "','" + item.ItemPrice + "','" + item.ItemBuyDate.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss") + "','" + userId + "','" + item.Recommend + "');"); n1++; } arr[0] = n1; arr[1] = n2; if (sb.ToString() == "") { return(arr); } comm.CommandText = sb.ToString(); comm.ExecuteNonQuery(); tran.Commit(); } catch { tran.Rollback(); throw; } finally { conn.Close(); } } return(arr); }