protected void dvGroupPurchase_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { if (e.NewValues["Name"] == null) { throw new Exception("请输入团购名称"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["Name"].ToString()); } if (e.NewValues["Description"] == null) { throw new Exception("请输入团购描述"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["Description"].ToString()); } if (e.NewValues["RequiredNumber"] == null) { throw new Exception("请输入团购人数"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["RequiredNumber"].ToString()); } if (e.NewValues["GroupPrice"] == null) { throw new Exception("请输入团购价格"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["GroupPrice"].ToString()); } if (e.NewValues["StartDate"] == null) { throw new Exception("请输入团购开始日期"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["StartDate"].ToString()); } if (e.NewValues["EndDate"] == null) { throw new Exception("请输入团购结束日期"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["EndDate"].ToString()); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { this.gvGroupPurchaseList.PageSize = Config.ProductListPageSize; //如果指定了商品ID,则显示指定商品下的所有团购列表信息 if (!string.IsNullOrEmpty(Request.QueryString["ProductID"])) { string productID = Request.QueryString["ProductID"]; UtilityHelper.AntiSQLInjection(productID); string strWhere = string.Format("ProductID = {0}", productID); this.odsGroupPurchaseList.SelectParameters["strWhere"].DefaultValue = strWhere; this.gvGroupPurchaseList.DataBind(); } //从商品管理页面跳转来,新增团购 if (Request.QueryString["Action"] == "add" && !string.IsNullOrEmpty(Request.QueryString["ProductID"])) { UtilityHelper.AntiSQLInjection(Request.QueryString["ProductID"]); int productID; if (int.TryParse(Request.QueryString["ProductID"], out productID)) { Fruit product = Fruit.FindFruitByID(productID); if (product != null) { //设置DetailsView插入模式 this.dvGroupPurchase.ChangeMode(DetailsViewMode.Insert); this.dvGroupPurchase.AutoGenerateInsertButton = true; HiddenField hfProductID = this.dvGroupPurchase.FindControl("hfProductID") as HiddenField; Label lblProductName = this.dvGroupPurchase.FindControl("lblProductName") as Label; //团购所属的商品信息 hfProductID.Value = product.ID.ToString(); lblProductName.Text = string.Format("【{0}】{1}", product.Category.CategoryName, product.FruitName); } else { throw new Exception("没有此商品"); } } else { throw new Exception("没有指定商品ID"); } } } }
protected void btnSearch_Click(object sender, EventArgs e) { string strWhere = string.Empty, tableName = string.Empty; List <string> listWhere = new List <string>(); try { //查询条件:团购名称 if (!string.IsNullOrEmpty(this.txtGroupPurchaseName.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtGroupPurchaseName.Text); listWhere.Add(string.Format("Name like '%{0}%'", this.txtGroupPurchaseName.Text.Trim())); this.txtGroupPurchaseName.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtGroupPurchaseName.Style.Clear(); } //查询条件:团购活动ID if (!string.IsNullOrEmpty(this.txtGroupEventID.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtGroupEventID.Text); listWhere.Add(string.Format("Id in (select GroupID from GroupPurchaseEvent where Id = {0})", this.txtGroupEventID.Text.Trim())); this.txtGroupEventID.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtGroupEventID.Style.Clear(); } strWhere = string.Join <string>(" and ", listWhere); this.gvGroupPurchaseList.PageIndex = 0; this.odsGroupPurchaseList.SelectParameters["strWhere"].DefaultValue = strWhere; this.gvGroupPurchaseList.DataBind(); this.dvGroupPurchase.Visible = false; } catch (Exception ex) { ScriptManager.RegisterStartupScript(Page, this.GetType(), "jsWarn", string.Format("alert('{0}');", ex.Message), true); } }
protected void dvGroupPurchase_ItemInserting(object sender, DetailsViewInsertEventArgs e) { //DetailView会把所有绑定字段的键值放入e.Values集合,非绑定字段则不会自动处理,需要手工处理。 try { Fruit fruit = new Fruit(); fruit.ID = int.Parse(e.Values["ProductID"].ToString()); e.Values.Remove("ProductID"); e.Values.Add("Product", fruit); if (e.Values["Name"] == null) { throw new Exception("请输入团购名称"); } else { UtilityHelper.AntiSQLInjection(e.Values["Name"].ToString()); } if (e.Values["Description"] == null) { throw new Exception("请输入团购描述"); } else { UtilityHelper.AntiSQLInjection(e.Values["Description"].ToString()); } if (e.Values["RequiredNumber"] == null) { throw new Exception("请输入团购人数"); } else { UtilityHelper.AntiSQLInjection(e.Values["RequiredNumber"].ToString()); } if (e.Values["GroupPrice"] == null) { throw new Exception("请输入团购价格"); } else { UtilityHelper.AntiSQLInjection(e.Values["GroupPrice"].ToString()); } if (e.Values["StartDate"] == null) { throw new Exception("请输入团购开始日期"); } else { UtilityHelper.AntiSQLInjection(e.Values["StartDate"].ToString()); } if (e.Values["EndDate"] == null) { throw new Exception("请输入团购结束日期"); } else { UtilityHelper.AntiSQLInjection(e.Values["EndDate"].ToString()); } } catch (Exception ex) { this.lblErrMsg.Text = ex.Message; e.Cancel = true; } }
protected void btnSearch_Click(object sender, EventArgs e) { string strWhere = string.Empty, tableName = string.Empty; List <string> listWhere = new List <string>(); try { //查询条件:商品类别 if (this.ddlCategory.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlCategory.SelectedValue); listWhere.Add(string.Format("CategoryID = {0}", this.ddlCategory.SelectedValue)); this.ddlCategory.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlCategory.Style.Clear(); } //查询条件:是否缺货 if (this.ddlOutOfStock.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlOutOfStock.SelectedValue); listWhere.Add(string.Format("(InventoryQty <> -1 and InventoryQty <= {0})", Config.ProductInventoryWarn)); this.ddlOutOfStock.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlOutOfStock.Style.Clear(); } //查询条件:是否置顶 if (this.ddlIsSticky.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlIsSticky.SelectedValue); listWhere.Add(string.Format("IsSticky = {0}", this.ddlIsSticky.SelectedValue)); this.ddlIsSticky.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlIsSticky.Style.Clear(); } //查询条件:是否上架 if (this.ddlIsOnSale.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlIsOnSale.SelectedValue); listWhere.Add(string.Format("ProductOnSale = {0}", this.ddlIsOnSale.SelectedValue)); this.ddlIsOnSale.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlIsOnSale.Style.Clear(); } //查询条件:商品名称 if (!string.IsNullOrEmpty(this.txtProdName.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtProdName.Text); listWhere.Add(string.Format("ProductName like '%{0}%'", this.txtProdName.Text.Trim())); this.txtProdName.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtProdName.Style.Clear(); } strWhere = string.Join <string>(" and ", listWhere); this.gvFruitList.PageIndex = 0; this.odsFruitList.SelectParameters["strWhere"].DefaultValue = strWhere; this.gvFruitList.DataBind(); } catch (Exception ex) { ScriptManager.RegisterStartupScript(Page, this.GetType(), "jsWarn", string.Format("alert('{0}');", ex.Message), true); } }
protected void Page_Load(object sender, EventArgs e) { int prodID; try { if (string.IsNullOrEmpty(Request.QueryString["ProdID"])) { throw new Exception("缺少商品参数ProdID"); } UtilityHelper.AntiSQLInjection(Request.QueryString["ProdID"]); prodID = int.Parse(Request.QueryString["ProdID"]); Fruit fruit = Fruit.FindFruitByID(prodID); if (fruit != null) { fruit.FruitImgList.ForEach(fi => { if (fi.MainImg) { this.imgMainImg.ImageUrl = "~/images/" + fi.ImgName; this.imgMainImg.AlternateText = fi.ImgDesc; this.imgMainImg.CssClass = "img-responsive"; } else { //this.divSlides.InnerHtml += string.Format("<div><img u=\"image\" src=\"images/{0}\" alt=\"{1}:{2}\" /></div>", fi.ImgName, fruit.FruitName, fruit.FruitDesc); } }); this.lblProdName.Text = fruit.FruitName; if (fruit.IsSticky) { this.lblStickyProd.Text = "<i class=\"fa fa-thumbs-up fa-lg\"></i>掌柜推荐"; } else { this.lblStickyProd.Visible = false; } if (fruit.ID == Fruit.FindTopSelling(DateTime.Now)) { this.lblTopSelling.Text = "<i class=\"fa fa-trophy fa-lg\"></i>本月爆款"; } else { this.lblTopSelling.Visible = false; } this.lblProdDesc.Text = fruit.FruitDesc; this.lblProdPrice.Text = fruit.FruitPrice.ToString(); this.lblProdUnit.Text = "元/" + fruit.FruitUnit; this.lblSalesVolume.Text = "累计销量:" + Fruit.SalesVolume(prodID).ToString(); if (fruit.InventoryQty == 0) { this.btnAddToCart.Disabled = true; this.btnLaunchGroupEvent.Disabled = true; this.lblProdState.Text = "商品已售罄,我们正在补货ing..."; } if (fruit.ActiveGroupPurchase == null) { this.btnLaunchGroupEvent.Visible = false; this.btnAddToCart.InnerHtml = "<i class='fa fa-cart-plus fa-lg fa-fw'></i> 加入购物车"; } else { this.btnLaunchGroupEvent.Visible = true; this.btnLaunchGroupEvent.InnerHtml = string.Format("<i class='fa fa-group fa-lg fa-fw'></i> 团购价:{0}元/{1} {2}人团", fruit.ActiveGroupPurchase.GroupPrice, fruit.FruitUnit, fruit.ActiveGroupPurchase.RequiredNumber); this.btnAddToCart.InnerHtml = "<i class='fa fa-cart-plus fa-lg fa-fw'></i> 单独购买"; } HtmlImage hiDetailImg; fruit.FruitImgList.ForEach(fi => { if (fi.DetailImg) { hiDetailImg = new HtmlImage(); hiDetailImg.Src = "~/images/" + fi.ImgName; hiDetailImg.Alt = fi.ImgDesc; hiDetailImg.Attributes["class"] = "img-responsive"; this.divDetailImg.Controls.Add(hiDetailImg); } }); //生成商品信息JS对象,用于前端JS操作 JsonConvert.DefaultSettings = new Func <JsonSerializerSettings>(() => { JsonSerializerSettings jSetting = new JsonSerializerSettings(); jSetting.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat; jSetting.DateFormatString = "yyyy-MM-dd HH:mm:ss"; jSetting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; return(jSetting); }); string jProd = JsonConvert.SerializeObject(fruit); ScriptManager.RegisterStartupScript(Page, this.GetType(), "jProdInfo", string.Format("var prod={0};", jProd), true); //搜狐畅言所需的页面文章ID,参考:http://changyan.kuaizhan.com/help/f-source-id.html this.SOHUCS.Attributes["sid"] = Request.Url.GetHashCode().ToString(); } else { Response.Write("<script>alert('商品已下架:(');history.back();</script>"); } } catch (Exception ex) { Log.Error(this.GetType().ToString(), ex.Message); throw ex; } }
protected void dvFruit_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { try { //当前的DetailView控件对象和当前记录主键值 DetailsView dvFruit = sender as DetailsView; int fruitID = int.Parse(dvFruit.DataKey.Value.ToString()); if (e.NewValues["FruitName"] == null) { throw new Exception("请输入商品名称"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["FruitName"].ToString()); } DropDownList ddlCategory = dvFruit.FindControl("ddlCategoryEdit") as DropDownList; if (ddlCategory.SelectedIndex == 0) { throw new Exception("请选择商品类别"); } else { UtilityHelper.AntiSQLInjection(ddlCategory.SelectedValue); } if (e.NewValues["FruitPrice"] == null) { throw new Exception("请输入商品价格"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["FruitPrice"].ToString()); } if (e.NewValues["FruitUnit"] == null) { throw new Exception("请输入商品单位"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["FruitUnit"].ToString()); } if (e.NewValues["FruitDesc"] == null) { throw new Exception("请输入商品描述"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["FruitDesc"].ToString()); } if (e.NewValues["InventoryQty"] == null) { throw new Exception("请输入商品库存数量"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["InventoryQty"].ToString()); } if (e.NewValues["OnSale"] == null) { throw new Exception("请输入是否上架"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["OnSale"].ToString()); } if (e.NewValues["IsSticky"] == null) { throw new Exception("请输入是否置顶"); } else { UtilityHelper.AntiSQLInjection(e.NewValues["IsSticky"].ToString()); } if (e.NewValues["Priority"] == null) { e.NewValues["Priority"] = 0; } else { UtilityHelper.AntiSQLInjection(e.NewValues["Priority"].ToString()); } //获取商品类别信息,添加入e.Values集合 Category category = new Category(); category.ID = int.Parse(ddlCategory.SelectedValue); e.NewValues.Add("Category", category); List <FruitImg> fruitImgList = new List <FruitImg>(); FruitImg fruitImg; //处理原有的图片:在DetailsView嵌套的Repeater中查找所有的子控件,并新建FruitImg对象,添加到集合中 Repeater rpFruitImgList = dvFruit.FindControl("rpFruitImgList") as Repeater; for (int i = 0; i < rpFruitImgList.Items.Count; i++) { HiddenField hfImgID = rpFruitImgList.Items[i].FindControl("hfImgID") as HiddenField; HiddenField hfImgSeqX = rpFruitImgList.Items[i].FindControl("hfImgSeqX") as HiddenField; HiddenField hfImgSeqY = rpFruitImgList.Items[i].FindControl("hfImgSeqY") as HiddenField; HyperLink hlOriginalImg = rpFruitImgList.Items[i].FindControl("hlOriginalImg") as HyperLink; RadioButton rbMainImg = rpFruitImgList.Items[i].FindControl("rbMainImg") as RadioButton; CheckBox cbDetailImg = rpFruitImgList.Items[i].FindControl("cbDetailImg") as CheckBox; TextBox txtImgDescEditOriginal = rpFruitImgList.Items[i].FindControl("txtImgDescEditOriginal") as TextBox; fruitImg = new FruitImg(); fruitImgList.Add(fruitImg); fruitImg.ImgID = int.Parse(hfImgID.Value); fruitImg.ImgName = hlOriginalImg.Text; fruitImg.ImgDesc = txtImgDescEditOriginal.Text.Trim(); fruitImg.MainImg = rbMainImg.Checked; fruitImg.DetailImg = cbDetailImg.Checked; int imgSeqX, imgSeqY; if (!int.TryParse(hfImgSeqX.Value, out imgSeqX)) { imgSeqX = 0; } if (!int.TryParse(hfImgSeqY.Value, out imgSeqY)) { imgSeqY = 0; } fruitImg.ImgSeqX = imgSeqX; fruitImg.ImgSeqY = imgSeqY; } //把FruitImgList对象附加到DetailView控件的e.NewValues键值对中,留待数据源控件odsFruit调用Fruit对象的update方法一起更新 e.NewValues.Add("FruitImgList", fruitImgList); //处理新上传的图片:把新上传的图片信息先行入库,并保存到服务器磁盘 HttpFileCollection imgFiles = Request.Files; if (imgFiles.Count != 0) { //存放新上传的图片 List <FruitImg> newFruitImgList = new List <FruitImg>(); FruitImg newFruitImg; int gridItemCount = GRID_COL / GRID_ITEM_WIDTH, currentIndex = fruitImgList.Count; for (int i = 0; i < imgFiles.Count; i++) { HttpPostedFile imgFile = imgFiles[i]; if (imgFile.ContentLength == 0) { continue; } string fileName, fileExtension; fileName = System.IO.Path.GetFileName(imgFile.FileName); fileExtension = System.IO.Path.GetExtension(fileName); //处理图片备注 string strImgDesc; if (i == 0) { TextBox txtImgDesc = dvFruit.FindControl("txtImgDescEdit") as TextBox; strImgDesc = txtImgDesc.Text; } else { string txtImgDescID = "dvFruit$txtImgDescEdit" + (i + 1); strImgDesc = Request.Form[txtImgDescID].ToString(); } if (Regex.IsMatch(fileExtension, string.Format("({0})", Config.AllowedUploadFileExt), RegexOptions.IgnoreCase)) { newFruitImg = new FruitImg(); newFruitImgList.Add(newFruitImg); newFruitImg.ImgName = fileName; newFruitImg.ImgDesc = strImgDesc; newFruitImg.MainImg = false; newFruitImg.DetailImg = false; //根据上传图片的序列号计算其gridstack的X/Y坐标值 newFruitImg.ImgSeqX = (currentIndex - currentIndex / gridItemCount * gridItemCount) * GRID_ITEM_WIDTH; newFruitImg.ImgSeqY = currentIndex / gridItemCount * GRID_ITEM_HEIGHT; currentIndex++; //保存新图片文件 imgFile.SaveAs(Request.MapPath("~/images/") + fileName); } } if (newFruitImgList.Count > 0) { //新图片信息入库 Fruit.AddFruitImg(fruitID, newFruitImgList); } } } catch (Exception ex) { this.lblErrMsg.Text = ex.Message; e.Cancel = true; this.gvFruitList.DataBind(); } }
protected void dvFruit_ItemInserting(object sender, DetailsViewInsertEventArgs e) { //DetailView会把所有绑定字段的键值放入e.Values集合,非绑定字段则不会自动处理,需要手工处理。 try { if (e.Values["FruitName"] == null) { throw new Exception("请输入商品名称"); } else { UtilityHelper.AntiSQLInjection(e.Values["FruitName"].ToString()); } DropDownList ddlCategoryInsert = ((DetailsView)sender).FindControl("ddlCategoryInsert") as DropDownList; if (ddlCategoryInsert.SelectedIndex == 0) { throw new Exception("请选择商品类别"); } else { UtilityHelper.AntiSQLInjection(ddlCategoryInsert.SelectedValue); } if (e.Values["FruitPrice"] == null) { throw new Exception("请输入商品价格"); } else { UtilityHelper.AntiSQLInjection(e.Values["FruitPrice"].ToString()); } if (e.Values["FruitUnit"] == null) { throw new Exception("请输入商品单位"); } else { UtilityHelper.AntiSQLInjection(e.Values["FruitUnit"].ToString()); } if (e.Values["FruitDesc"] == null) { throw new Exception("请输入商品描述"); } else { UtilityHelper.AntiSQLInjection(e.Values["FruitDesc"].ToString()); } //默认上架 if (e.Values["OnSale"] == null) { e.Values["OnSale"] = true; } else { UtilityHelper.AntiSQLInjection(e.Values["OnSale"].ToString()); } //默认不置顶 if (e.Values["IsSticky"] == null) { e.Values["IsSticky"] = false; } else { UtilityHelper.AntiSQLInjection(e.Values["IsSticky"].ToString()); } //默认优先级0 if (e.Values["Priority"] == null) { e.Values["Priority"] = 0; } else { UtilityHelper.AntiSQLInjection(e.Values["Priority"].ToString()); } //获取商品库存数量,默认为不限量 if (e.Values["InventoryQty"] == null) { e.Values["InventoryQty"] = -1; } else { UtilityHelper.AntiSQLInjection(e.Values["InventoryQty"].ToString()); } //获取商品类别信息,添加入e.Values集合 Category category = new Category(); category.ID = int.Parse(ddlCategoryInsert.SelectedValue); e.Values.Add("Category", category); HttpFileCollection imgFiles = Request.Files; if (imgFiles.Count != 0) { List <FruitImg> fruitImgList = new List <FruitImg>(); FruitImg fruitImg; //根据gridstack.js网格数、网格项宽度参数计算每行的网格项数量,用于后续计算每个网格项的X/Y坐标值 int gridItemCount = GRID_COL / GRID_ITEM_WIDTH, currentIndex; //遍历文件上传框 for (int i = 0; i < imgFiles.Count; i++) { HttpPostedFile imgFile = imgFiles[i]; if (imgFile.ContentLength == 0) { continue; } string fileName, fileExtension; fileName = System.IO.Path.GetFileName(imgFile.FileName); fileExtension = System.IO.Path.GetExtension(fileName); //处理图片备注 string strImgDesc; if (i == 0) { TextBox txtImgDesc = ((DetailsView)sender).FindControl("txtImgDescInsert") as TextBox; strImgDesc = txtImgDesc.Text; } else { string txtImgDescID = "dvFruit$txtImgDescInsert" + (i + 1); strImgDesc = Request.Form[txtImgDescID].ToString(); } if (Regex.IsMatch(fileExtension, string.Format("({0})", Config.AllowedUploadFileExt), RegexOptions.IgnoreCase)) { fruitImg = new FruitImg(); fruitImgList.Add(fruitImg); fruitImg.ImgName = fileName; fruitImg.ImgDesc = strImgDesc; fruitImg.DetailImg = false; //根据上传图片的序列号计算其gridstack的X/Y坐标值 currentIndex = (fruitImgList.Count - 1); fruitImg.ImgSeqX = (currentIndex - currentIndex / gridItemCount * gridItemCount) * GRID_ITEM_WIDTH; fruitImg.ImgSeqY = currentIndex / gridItemCount * GRID_ITEM_HEIGHT; //保存新图片文件 imgFile.SaveAs(Request.MapPath("~/images/") + fileName); } } if (fruitImgList.Count > 0) { //默认新上传的第一个是主图 fruitImgList[0].MainImg = true; //把需要上传的图片信息加入DetailView控件的e.Values集合中,留待数据源控件odsFruit调用Fruit对象的insert方法一起插入 e.Values.Add("FruitImgList", fruitImgList); } } else { throw new Exception("请选择商品图片"); } } catch (Exception ex) { this.lblErrMsg.Text = ex.Message; e.Cancel = true; this.gvFruitList.DataBind(); } }
protected void btnSearch_Click(object sender, EventArgs e) { string strWhere = string.Empty, strTableName = string.Empty; List <string> listWhere = new List <string>(); bool isJoinMembership = false, isJoinUsers = false; try { //查询条件:是否在线 if (this.ddlIsOnline.SelectedIndex == 0) { this.ddlIsOnline.Style.Clear(); } else { if (this.ddlIsOnline.SelectedValue == "1") { UtilityHelper.AntiSQLInjection(this.ddlIsOnline.SelectedValue); listWhere.Add(string.Format("DATEADD(mi,-{0},GETDATE())<=aspnet_Users.LastActivityDate", Membership.UserIsOnlineTimeWindow + 480)); this.ddlIsOnline.Style.Add("background-color", CRITERIA_BG_COLOR.Name); isJoinUsers = true; } else { UtilityHelper.AntiSQLInjection(this.ddlIsOnline.SelectedValue); listWhere.Add(string.Format("DATEADD(mi,-{0},GETDATE())>aspnet_Users.LastActivityDate", Membership.UserIsOnlineTimeWindow + 480)); this.ddlIsOnline.Style.Add("background-color", CRITERIA_BG_COLOR.Name); isJoinUsers = true; } } //查询条件:是否订阅微信公众号 if (this.ddlIsSubscribe.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlIsSubscribe.SelectedValue); listWhere.Add(string.Format("WeChatUsers.IsSubscribe = {0}", this.ddlIsSubscribe.SelectedValue)); this.ddlIsSubscribe.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlIsSubscribe.Style.Clear(); } //查询条件:性别 if (this.ddlSex.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlSex.SelectedValue); listWhere.Add(string.Format("WeChatUsers.Sex = {0}", this.ddlSex.SelectedValue)); this.ddlSex.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlSex.Style.Clear(); } //查询条件:是否允许登录 if (this.ddlIsApproved.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlIsApproved.SelectedValue); listWhere.Add(string.Format("aspnet_Membership.IsApproved = {0}", this.ddlIsApproved.SelectedValue)); this.ddlIsApproved.Style.Add("background-color", CRITERIA_BG_COLOR.Name); isJoinMembership = true; } else { this.ddlIsApproved.Style.Clear(); } //查询条件:微信昵称 if (!string.IsNullOrEmpty(this.txtNickName.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtNickName.Text); listWhere.Add(string.Format("WeChatUsers.NickName like '%{0}%'", this.txtNickName.Text.Trim())); this.txtNickName.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtNickName.Style.Clear(); } //查询条件:国家 if (!string.IsNullOrEmpty(this.txtCountry.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtCountry.Text); listWhere.Add(string.Format("WeChatUsers.Country like '%{0}%'", this.txtCountry.Text.Trim())); this.txtCountry.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtCountry.Style.Clear(); } //查询条件:省份 if (!string.IsNullOrEmpty(this.txtProvince.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtProvince.Text); listWhere.Add(string.Format("WeChatUsers.Province like '%{0}%'", this.txtProvince.Text.Trim())); this.txtProvince.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtProvince.Style.Clear(); } //查询条件:城市 if (!string.IsNullOrEmpty(this.txtCity.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtCountry.Text); listWhere.Add(string.Format("WeChatUsers.City like '%{0}%'", this.txtCity.Text.Trim())); this.txtCity.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtCity.Style.Clear(); } //查询条件:开始注册日期 if (!string.IsNullOrEmpty(this.txtStartCreationDate.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtStartCreationDate.Text); listWhere.Add(string.Format("CONVERT(varchar(8), aspnet_Membership.CreateDate, 112) >= '{0}'", this.txtStartCreationDate.Text.Trim().Replace("-", ""))); this.txtStartCreationDate.Style.Add("background-color", CRITERIA_BG_COLOR.Name); isJoinMembership = true; } else { this.txtStartCreationDate.Style.Clear(); } //查询条件:结束注册日期 if (!string.IsNullOrEmpty(this.txtEndCreationDate.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtEndCreationDate.Text); listWhere.Add(string.Format("CONVERT(varchar(8), aspnet_Membership.CreateDate, 112) <= '{0}'", this.txtEndCreationDate.Text.Trim().Replace("-", ""))); this.txtEndCreationDate.Style.Add("background-color", CRITERIA_BG_COLOR.Name); isJoinMembership = true; } else { this.txtEndCreationDate.Style.Clear(); } //查询条件:开始活跃时间 if (!string.IsNullOrEmpty(this.txtStartLastActivityDate.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtStartLastActivityDate.Text); listWhere.Add(string.Format("CONVERT(varchar(8), DATEADD(hh,8,aspnet_Users.LastActivityDate), 112) >= '{0}'", this.txtStartLastActivityDate.Text.Trim().Replace("-", ""))); this.txtStartLastActivityDate.Style.Add("background-color", CRITERIA_BG_COLOR.Name); isJoinUsers = true; } else { this.txtStartLastActivityDate.Style.Clear(); } //查询条件:结束活跃时间 if (!string.IsNullOrEmpty(this.txtEndLastActivityDate.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtEndLastActivityDate.Text); listWhere.Add(string.Format("CONVERT(varchar(8), DATEADD(hh,8,aspnet_Users.LastActivityDate), 112) <= '{0}'", this.txtEndLastActivityDate.Text.Trim().Replace("-", ""))); this.txtEndLastActivityDate.Style.Add("background-color", CRITERIA_BG_COLOR.Name); isJoinUsers = true; } else { this.txtEndLastActivityDate.Style.Clear(); } strWhere = string.Join <string>(" and ", listWhere); this.odsUserList.SelectParameters["strWhere"].DefaultValue = strWhere; //根据查询涉及表做关联 strTableName = "WeChatUsers"; if (isJoinMembership) { strTableName += " left join aspnet_Membership on WeChatUsers.UserId = aspnet_Membership.UserId"; } if (isJoinUsers) { strTableName += " left join aspnet_Users on WeChatUsers.UserId = aspnet_Users.UserId"; } this.odsUserList.SelectParameters["tableName"].DefaultValue = strTableName; this.gvUserList.PageIndex = 0; this.gvUserList.DataBind(); } catch (Exception ex) { ScriptManager.RegisterStartupScript(Page, this.GetType(), "jsWarn", string.Format("alert('{0}');", ex.Message), true); } }
protected void btnSearch_Click(object sender, EventArgs e) { string strWhere = string.Empty, tableName = string.Empty; List <string> listWhere = new List <string>(); try { //查询条件:支付方式 if (this.ddlPaymentTerm.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlPaymentTerm.SelectedValue); listWhere.Add(string.Format("PaymentTerm = {0}", this.ddlPaymentTerm.SelectedValue)); this.ddlPaymentTerm.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlPaymentTerm.Style.Clear(); } //查询条件:支付状态 if (this.ddlTradeState.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlTradeState.SelectedValue); listWhere.Add(string.Format("TradeState = {0}", this.ddlTradeState.SelectedValue)); this.ddlTradeState.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlTradeState.Style.Clear(); } //查询条件:发货状态 if (this.ddlIsDelivery.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlIsDelivery.SelectedValue); listWhere.Add(string.Format("IsDelivered = {0}", this.ddlIsDelivery.SelectedValue)); this.ddlIsDelivery.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlIsDelivery.Style.Clear(); } //查询条件:签收状态 if (this.ddlIsAccept.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlIsAccept.SelectedValue); listWhere.Add(string.Format("IsAccept = {0}", this.ddlIsAccept.SelectedValue)); this.ddlIsAccept.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlIsAccept.Style.Clear(); } //查询条件:撤单状态 if (this.ddlIsCancel.SelectedIndex != 0) { UtilityHelper.AntiSQLInjection(this.ddlIsCancel.SelectedValue); listWhere.Add(string.Format("IsCancel = {0}", this.ddlIsCancel.SelectedValue)); this.ddlIsCancel.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.ddlIsCancel.Style.Clear(); } //查询条件:收货人姓名 if (!string.IsNullOrEmpty(this.txtReceiverName.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtReceiverName.Text); listWhere.Add(string.Format("DeliverName like '%{0}%'", this.txtReceiverName.Text.Trim())); this.txtReceiverName.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtReceiverName.Style.Clear(); } //查询条件:收货人电话 if (!string.IsNullOrEmpty(this.txtReceiverPhone.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtReceiverPhone.Text); listWhere.Add(string.Format("DeliverPhone like '%{0}%'", this.txtReceiverPhone.Text.Trim())); this.txtReceiverPhone.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtReceiverPhone.Style.Clear(); } //查询条件:订单ID if (!string.IsNullOrEmpty(this.txtOrderID.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtOrderID.Text); listWhere.Add(string.Format("OrderID like '%{0}%'", this.txtOrderID.Text.Trim())); this.txtOrderID.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtOrderID.Style.Clear(); } //查询条件:团购活动ID if (!string.IsNullOrEmpty(this.txtGroupEventID.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtGroupEventID.Text); listWhere.Add(string.Format("Id in (select PoID from OrderDetail where GroupEventID = {0})", this.txtGroupEventID.Text.Trim())); this.txtGroupEventID.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtGroupEventID.Style.Clear(); } //查询条件:订单商品详情 if (!string.IsNullOrEmpty(this.txtOrderDetail.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtOrderDetail.Text); listWhere.Add(string.Format("Id in (select PoID from OrderDetail where OrderProductName like '%{0}%')", this.txtOrderDetail.Text.Trim())); this.txtOrderDetail.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtOrderDetail.Style.Clear(); } //查询条件:微信支付交易号 if (!string.IsNullOrEmpty(this.txtTransactionID.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtTransactionID.Text); listWhere.Add(string.Format("TransactionID like '%{0}%'", this.txtTransactionID.Text.Trim())); this.txtTransactionID.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtTransactionID.Style.Clear(); } //查询条件:支付宝交易号 if (!string.IsNullOrEmpty(this.txtTradeNo.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtTradeNo.Text); listWhere.Add(string.Format("AP_TradeNo like '%{0}%'", this.txtTradeNo.Text.Trim())); this.txtTransactionID.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtTradeNo.Style.Clear(); } //查询条件:订单开始日期 if (!string.IsNullOrEmpty(this.txtStartOrderDate.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtStartOrderDate.Text); listWhere.Add(string.Format("CONVERT(varchar(8), OrderDate, 112) >= '{0}'", this.txtStartOrderDate.Text.Trim().Replace("-", ""))); this.txtStartOrderDate.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtStartOrderDate.Style.Clear(); } //查询条件:订单结束日期 if (!string.IsNullOrEmpty(this.txtEndOrderDate.Text.Trim())) { UtilityHelper.AntiSQLInjection(this.txtEndOrderDate.Text); listWhere.Add(string.Format("CONVERT(varchar(8), OrderDate, 112) <= '{0}'", this.txtEndOrderDate.Text.Trim().Replace("-", ""))); this.txtEndOrderDate.Style.Add("background-color", CRITERIA_BG_COLOR.Name); } else { this.txtEndOrderDate.Style.Clear(); } strWhere = string.Join <string>(" and ", listWhere); this.gvOrderList.PageIndex = 0; this.odsOrderList.SelectParameters["strWhere"].DefaultValue = strWhere; this.gvOrderList.DataBind(); } catch (Exception ex) { ScriptManager.RegisterStartupScript(Page, this.GetType(), "jsWarn", string.Format("alert('{0}');", ex.Message), true); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { string openID, agentOpenID, groupEventID, strWhere = string.Empty; if (Request.QueryString["OpenID"] != null) { UtilityHelper.AntiSQLInjection(Request.QueryString["OpenID"]); openID = Request.QueryString["OpenID"]; strWhere = string.Format("OpenID='{0}'", openID); } if (Request.QueryString["AgentOpenID"] != null) { UtilityHelper.AntiSQLInjection(Request.QueryString["AgentOpenID"]); agentOpenID = Request.QueryString["AgentOpenID"]; strWhere = string.Format("AgentOpenID='{0}'", agentOpenID); } if (Request.QueryString["GroupEventID"] != null) { UtilityHelper.AntiSQLInjection(Request.QueryString["GroupEventID"]); groupEventID = Request.QueryString["GroupEventID"]; this.txtGroupEventID.Text = groupEventID; this.txtGroupEventID.Style.Add("background-color", CRITERIA_BG_COLOR.Name); strWhere = string.Format("Id in (select PoID from OrderDetail where GroupEventID = {0})", groupEventID); } this.odsOrderList.TypeName = "ProductOrder"; this.odsOrderList.EnablePaging = true; this.odsOrderList.SelectParameters.Add("strWhere", DbType.String, strWhere); this.odsOrderList.SelectParameters.Add("strOrder", DbType.String, string.Empty); this.odsOrderList.SelectParameters[this.odsOrderList.SelectParameters.Add("totalRows", DbType.Int32, "0")].Direction = ParameterDirection.Output; this.odsOrderList.SelectParameters[this.odsOrderList.SelectParameters.Add("payingOrderCount", DbType.Int32, "0")].Direction = ParameterDirection.Output; this.odsOrderList.SelectParameters[this.odsOrderList.SelectParameters.Add("deliveringOrderCount", DbType.Int32, "0")].Direction = ParameterDirection.Output; this.odsOrderList.SelectParameters[this.odsOrderList.SelectParameters.Add("acceptingOrderCount", DbType.Int32, "0")].Direction = ParameterDirection.Output; this.odsOrderList.SelectParameters[this.odsOrderList.SelectParameters.Add("cancelledOrderCount", DbType.Int32, "0")].Direction = ParameterDirection.Output; this.odsOrderList.SelectParameters[this.odsOrderList.SelectParameters.Add("totalOrderPrice", DbType.Decimal, "0")].Direction = ParameterDirection.Output; this.gvOrderList.AllowPaging = true; this.gvOrderList.AllowCustomPaging = true; this.gvOrderList.PageIndex = 0; this.gvOrderList.PageSize = Config.OrderListPageSize; this.ddlPaymentTerm.Items.Add(new ListItem("微信支付", ((int)PaymentTerm.WECHAT).ToString())); this.ddlPaymentTerm.Items.Add(new ListItem("支付宝", ((int)PaymentTerm.ALIPAY).ToString())); this.ddlPaymentTerm.Items.Add(new ListItem("货到付款", ((int)PaymentTerm.CASH).ToString())); this.ddlTradeState.Items.Add(new ListItem("===微信支付状态===", "-1")); this.ddlTradeState.Items.Add(new ListItem("支付成功", ((int)TradeState.SUCCESS).ToString())); this.ddlTradeState.Items.Add(new ListItem("转入退款", ((int)TradeState.REFUND).ToString())); this.ddlTradeState.Items.Add(new ListItem("未支付", ((int)TradeState.NOTPAY).ToString())); this.ddlTradeState.Items.Add(new ListItem("已关闭", ((int)TradeState.CLOSED).ToString())); this.ddlTradeState.Items.Add(new ListItem("已撤销(刷卡支付)", ((int)TradeState.REVOKED).ToString())); this.ddlTradeState.Items.Add(new ListItem("用户支付中", ((int)TradeState.USERPAYING).ToString())); this.ddlTradeState.Items.Add(new ListItem("支付失败", ((int)TradeState.PAYERROR).ToString())); this.ddlTradeState.Items.Add(new ListItem("===支付宝状态===", "-1")); this.ddlTradeState.Items.Add(new ListItem("等待买家付款", ((int)TradeState.AP_WAIT_BUYER_PAY).ToString())); this.ddlTradeState.Items.Add(new ListItem("等待卖家收款", ((int)TradeState.AP_TRADE_PENDING).ToString())); this.ddlTradeState.Items.Add(new ListItem("交易成功", ((int)TradeState.AP_TRADE_SUCCESS).ToString())); this.ddlTradeState.Items.Add(new ListItem("交易成功且结束", ((int)TradeState.AP_TRADE_FINISHED).ToString())); this.ddlTradeState.Items.Add(new ListItem("未支付已关闭", ((int)TradeState.AP_TRADE_CLOSED).ToString())); this.ddlTradeState.Items.Add(new ListItem("===货到付款状态===", "-1")); this.ddlTradeState.Items.Add(new ListItem("已付现金", ((int)TradeState.CASHPAID).ToString())); this.ddlTradeState.Items.Add(new ListItem("未付现金", ((int)TradeState.CASHNOTPAID).ToString())); this.txtDeliveryName.Text = Config.DeliveryName; this.txtDeliveryPhone.Text = Config.DeliveryPhone; } catch (Exception ex) { Response.Write(string.Format("<script>alert('{0}');history.back();</script>", ex.Message)); Response.End(); } } }