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(); }
//删除操作 protected void List_RowDeleting(object sender, GridViewDeleteEventArgs e) { int zhuanTiId = Int32.Parse(List.DataKeys[e.RowIndex].Value.ToString()); ZhuanTiEntity zhuanTi = ZhuanTiAccess.GetZhuanTiListById(zhuanTiId, userId); zhuanTi.ZhuanTiLive = 0; zhuanTi.Synchronize = 1; bool success = ZhuanTiAccess.DeleteZhuanTi(zhuanTiId, userId); if (success) { success = ZhuanTiAccess.UpdateZhuanTi(zhuanTi); if (success) { Utility.Alert(this, "删除成功。"); List.EditIndex = -1; BindGrid(); } } else { Utility.Alert(this, "删除失败!"); } }
//添加操作 protected void Button1_Click(object sender, EventArgs e) { string zhuanTiImage = ""; if (this.ZhuanTiImageIns.HasFile) { string imageExt = ImageHelper.GetImageExt(this.ZhuanTiImageIns.FileName); if (imageExt != ".jpg" && imageExt != ".png" && imageExt != ".bmp" && imageExt != ".gif") { Utility.Alert(this, "图片文件格式不支持!"); return; } zhuanTiImage = "zt_" + userId + "_" + Utility.GetRandomNumber(1000, 9999) + imageExt; string imagePath = Server.MapPath("/Images/ZhuanTi/") + zhuanTiImage; try { this.ZhuanTiImageIns.SaveAs(imagePath); ImageHelper.SaveImage(imagePath, 200, 200); } catch { Utility.Alert(this, "专题图片上传失败!"); return; } } else { Utility.Alert(this, "专题图片未选择!"); return; } string zhuanTiName = this.ZhuanTiNameIns.Text.Trim(); if (zhuanTiName == "") { Utility.Alert(this, "专题名称未填写!"); return; } ZhuanTiEntity zhuanTi = new ZhuanTiEntity(); zhuanTi.ZhuanTiName = zhuanTiName; zhuanTi.ZhuanTiImage = zhuanTiImage; zhuanTi.ZhuanTiLive = 1; zhuanTi.Synchronize = 1; zhuanTi.UserID = userId; bool success = ZhuanTiAccess.InsertZhuanTi(zhuanTi); if (success) { Utility.Alert(this, "添加成功。", "UserZhuanTi.aspx"); } else { Utility.Alert(this, "添加失败!"); } }
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 BindGrid() { DataTable dt = ZhuanTiAccess.GetZhuanTiListDetail(zhuanTiId, userId); List.DataSource = dt; List.DataBind(); ZhuanTiEntity zhuanTi = ZhuanTiAccess.GetZhuanTiListById(zhuanTiId, userId); this.ZhuanTiDate.Text = zhuanTi.ZhuanTiDate; this.ZhuanTiShouRu.Text = zhuanTi.ZhuanTiShouRu.ToString("0.0##"); this.ZhuanTiZhiChu.Text = zhuanTi.ZhuanTiZhiChu.ToString("0.0##"); }
protected void BindGrid() { DataTable dt = ItemAccess.GetItemList(today, userId); List.DataSource = dt; List.DataBind(); 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")); double shouruPrice = 0; double zhichuPrice = 0; double shouruPriceMonth = 0; double zhichuPriceMonth = 0; double shouruPriceYear = 0; double zhichuPriceYear = 0; DataTable total = ItemAccess.GetItemListShouZhi(today, userId, out shouruPrice, out zhichuPrice, out shouruPriceMonth, out zhichuPriceMonth, out shouruPriceYear, out zhichuPriceYear); this.Label2.Text = shouruPrice.ToString("0.0##"); this.Label4.Text = zhichuPrice.ToString("0.0##"); this.Label1.Text = shouruPriceMonth.ToString("0.0##"); this.Label3.Text = zhichuPriceMonth.ToString("0.0##"); this.Label11.Text = shouruPriceYear.ToString("0.0##"); this.Label12.Text = zhichuPriceYear.ToString("0.0##"); double jiechuPrice = 0; double huanruPrice = 0; double jieruPrice = 0; double huanchuPrice = 0; DataTable jiehuan = ItemAccess.GetItemListJieHuan(today, userId, out jiechuPrice, out huanruPrice, out jieruPrice, out huanchuPrice); this.Label5.Text = jiechuPrice.ToString("0.##"); this.Label6.Text = huanruPrice.ToString("0.##"); this.Label7.Text = jieruPrice.ToString("0.##"); this.Label8.Text = huanchuPrice.ToString("0.##"); this.Label9.Text = (jiechuPrice - huanruPrice).ToString("0.##"); this.Label10.Text = (jieruPrice - huanchuPrice).ToString("0.##"); }
//导出数据到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 void List_RowUpdating(object sender, GridViewUpdateEventArgs e) { int zhuanTiId = Int32.Parse(List.DataKeys[e.RowIndex].Value.ToString()); string zhuanTiImage = ((HiddenField)List.Rows[e.RowIndex].FindControl("ZhuanTiImageHid")).Value; FileUpload zhuanTiImageUpload = (FileUpload)List.Rows[e.RowIndex].FindControl("ZhuanTiImageUpload"); if (zhuanTiImageUpload.HasFile) { string imageExt = ImageHelper.GetImageExt(zhuanTiImageUpload.FileName); string imageName = ImageHelper.GetImageName(zhuanTiImage); if (imageExt != ".jpg" && imageExt != ".png" && imageExt != ".bmp" && imageExt != ".gif") { Utility.Alert(this, "图片文件格式不支持!"); return; } if (imageName == "none") { imageName = "zt_" + userId + "_" + Utility.GetRandomNumber(1000, 9999); } zhuanTiImage = imageName + imageExt; string imagePath = Server.MapPath("/Images/ZhuanTi/") + zhuanTiImage; try { zhuanTiImageUpload.SaveAs(imagePath); ImageHelper.SaveImage(imagePath, 200, 200); } catch { Utility.Alert(this, "专题图片上传失败!"); return; } } TextBox zhuanTiNameBox = (TextBox)List.Rows[e.RowIndex].FindControl("ZhuanTiNameBox"); string zhuanTiName = zhuanTiNameBox.Text.Trim(); if (zhuanTiName == "") { Utility.Alert(this, "专题名称未填写!"); return; } ZhuanTiEntity zhuanTi = ZhuanTiAccess.GetZhuanTiListById(zhuanTiId, userId); zhuanTi.ZhuanTiImage = zhuanTiImage; zhuanTi.ZhuanTiName = zhuanTiName; zhuanTi.UserID = userId; bool success = ZhuanTiAccess.UpdateZhuanTi(zhuanTi); if (success) { Utility.Alert(this, "更新成功。"); List.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "更新失败!"); } }
protected void BindGrid() { this.List.DataSource = ZhuanTiAccess.GetZhuanTiList(userId); this.List.DataBind(); }