protected string ShowHref(object id) { string result = string.Empty; int _id = 0; int.TryParse(id.ToString(), out _id); if (_id > 0) { var bargain = BargainBLL.ReadBargain(_id); if (bargain.Id > 0 && bargain.StartDate > DateTime.Now) {//未开始 result = "<a href = \"BargainAdd.aspx?ID=" + id + "\" class=\"ig-colink\">修改</a> "; result += "<a href = \"Bargain.aspx?ID=" + id + "&Action=Delete\" class=\"ig-colink\" onclick=\"javascript: return(window.confirm('确定要删除吗'))\">删除</a> "; } if (bargain.Id > 0 && bargain.StartDate <= DateTime.Now && bargain.EndDate >= DateTime.Now) {//进行中 result = "<a href = \"BargainAdd.aspx?ID=" + id + "\" class=\"ig-colink\">查看</a> "; result += " <a onclick = \"SelectRecording(" + id + ");\" class=\"ig-colink\">砍价记录</a> "; //有效的活动可以关闭 if (bargain.Status != 0) { result += "<a href = \"Bargain.aspx?ID=" + id + "&Action=ShutDown\" class=\"ig-colink\" onclick=\"javascript:return(window.confirm('确定要关闭吗,关闭后不可恢复'))\">关闭</a> "; } } if (bargain.Id > 0 && bargain.EndDate < DateTime.Now) {// 已结束 result = "<a href = \"BargainAdd.aspx?ID=" + id + "\" class=\"ig-colink\">查看</a> "; result += " <a onclick = \"SelectRecording(" + id + ");\" class=\"ig-colink\">砍价记录</a> "; result += "<a href = \"Bargain.aspx?ID=" + id + "&Action=Delete\" class=\"ig-colink\" onclick=\"javascript:return(window.confirm('确定要删除吗'))\">删除</a> "; } // // } return(result); }
/// <summary> /// 页面加载方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckAdminPower("ReadRecording", PowerCheckType.Single); //var bargain = BargainOrderBLL.ReadBargainOrder(RequestHelper.GetQueryString<int>("ID")); bargain = BargainBLL.ReadBargain(RequestHelper.GetQueryString <int>("ID")); var BargainDetailList = BargainDetailsBLL.ReadByBargainId(bargain.Id); foreach (var item in BargainDetailList) { var product = ProductBLL.Read(item.ProductID); if (product.Id > 0 && product.IsDelete == 0) { BargainDetail.Items.Add(new ListItem(product.Name, item.Id.ToString())); } } BargainDetail.Items.Insert(0, new ListItem { Text = "请选择", Value = "" }); //BargainDetail.SelectedIndexChanged += new System.EventHandler(BargainDetail_SelectedIndexChanged); if (!string.IsNullOrEmpty(BargainDetail.SelectedValue)) { foreach (var item in BargainOrderBLL.SearchBargainOrderList(new BargainOrderSearch() { BargainDetailsId = int.Parse(BargainDetail.SelectedValue) })) { var user = UserBLL.Read(item.UserId); user.UserName = System.Web.HttpUtility.UrlDecode(user.UserName, System.Text.Encoding.UTF8); BargainOrder.Items.Add(new ListItem(user.UserName, item.Id.ToString())); } } BargainOrder.Items.Insert(0, new ListItem { Text = "请选择", Value = "" }); #region MyRegion var bargainDetails = BargainDetailsBLL.ReadByBargainId(bargain.Id); foreach (var bdt in bargainDetails) { var bargain_orders = BargainOrderBLL.SearchBargainOrderList(new BargainOrderSearch { BargainDetailsId = bdt.Id }); b_orderids = b_orderids.Concat(bargain_orders.Select(k => k.Id)).ToList(); } #endregion BindData(); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //默认开始时间是当前 结束时间2天后 StartDate.Text = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd hh:mm:ss"); EndDate.Text = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd hh:mm:ss"); var id = RequestHelper.GetQueryString <int>("ID"); string Action = RequestHelper.GetQueryString <string>("Action"); if (Action == "Delete") { Delete(); } if (id > 0) { CheckAdminPower("ReadBargain", PowerCheckType.Single); var bargain = BargainBLL.ReadBargain(id); Name.Text = bargain.Name; StartDate.Text = bargain.StartDate.ToString("yyyy-MM-dd hh:mm:ss"); EndDate.Text = bargain.EndDate.ToString("yyyy-MM-dd hh:mm:ss"); //if (bargain.LimitCount == int.MaxValue) //{ // //Unlimited.Checked = true; //} //else //{ // LimitCount.Text = bargain.LimitCount.ToString(); //} LimitCount.Text = bargain.LimitCount.ToString(); NumberPeople.Text = bargain.NumberPeople.ToString(); SuccessRate.Text = bargain.SuccessRate.ToString(); Status = bargain.Status; DetailList = BargainDetailsBLL.ReadByBargainId(bargain.Id); if (bargain.Id > 0 && bargain.EndDate < DateTime.Now) { SubmitButton.Visible = false; enableUpdate = false; } if (bargain.Id > 0 && bargain.EndDate >= DateTime.Now && bargain.StartDate <= DateTime.Now) { SubmitButton.Visible = false; enableUpdate = false; } } } }
private void Delete() { int id = RequestHelper.GetQueryString <int>("ID"); if (id > 0) { var bargain = BargainBLL.ReadBargain(id); if (bargain.Id > 0 && bargain.EndDate >= DateTime.Now && bargain.StartDate <= DateTime.Now) { ScriptHelper.Alert("活动进行中,不能删除"); } else { BargainDetailsBLL.Delete(id); } } }
/// <summary> /// 关闭 /// </summary> private void ShutDown() { int id = RequestHelper.GetQueryString <int>("ID"); if (id > 0) { var bargain = BargainBLL.ReadBargain(id); if (bargain.Id > 0 && bargain.Status != 0) { #region 关闭 事务:将未支付成功的砍价全部置为“砍价失败”,原“活动已取消,砍价失败” BargainBLL.ChangeBargainStatus(id, (int)Bargain_Status.ShutDown); #endregion //Dictionary<string, object> dict = new Dictionary<string, object>(); //dict.Add("[Status]", 0); //BargainBLL.UpdatePart("[Bargain]", dict, id); } else { ScriptHelper.Alert("操作不合法"); } } }
/// <summary> /// 检查砍价订单状态 /// </summary> /// <param name="bargainOrderId"></param> /// <returns></returns> private void CheckStatus(int bargainOrderId) { //new TxtLog(Server.MapPath("/apilog/")).Write("-----bargainOrderId:"+ bargainOrderId+"----"); var bargainOrder = BargainOrderBLL.ReadBargainOrder(bargainOrderId); //new TxtLog(Server.MapPath("/apilog/")).Write("-----BargainOrderType:" + bargainOrder.Status + "----"); if (bargainOrder.Id > 0 && bargainOrder.Status == (int)BargainOrderType.进行中) { var bargainDetail = BargainDetailsBLL.ReadBargainDetails(bargainOrder.BargainDetailsId); var bargain = BargainBLL.ReadBargain(bargainDetail.BargainId); if (DateTime.Now >= bargain.EndDate) {//已经结束,砍价失败 bargainOrder.Status = (int)BargainOrderType.价失败; BargainOrderBLL.UpdateBargainOrder(bargainOrder); } var product = ProductBLL.Read(bargainDetail.ProductID); if (product.MarketPrice - bargainOrder.BargainPrice == bargainDetail.ReservePrice && bargainOrder.Status != (int)BargainOrderType.价成功) { bargainOrder.Status = (int)BargainOrderType.价成功; //BargainOrderBLL.UpdateBargainOrder(bargainOrder); if (BargainOrderBLL.UpdateBargainOrder(bargainOrder)) { //发送砍价成功模板消息 //SendBargainMessage(bargainOrder); //new TxtLog(Server.MapPath("/apilog/")).Write("-----发送砍价成功模板消息:End----"); } } else if (DateTime.Now >= bargain.EndDate && bargainOrder.Status != (int)BargainOrderType.价失败) { bargainOrder.Status = (int)BargainOrderType.价失败; BargainOrderBLL.UpdateBargainOrder(bargainOrder); } else {//进行中 } } }
protected void SubmitButton_Click(object sender, EventArgs e) { var ID = RequestHelper.GetQueryString <int>("ID"); var bargain = BargainBLL.ReadBargain(ID); if (bargain.Id > 0 && bargain.EndDate < DateTime.Now) { ScriptHelper.Alert("活动已结束,不能编辑"); } if (bargain.Id > 0 && bargain.EndDate >= DateTime.Now && bargain.StartDate <= DateTime.Now) { ScriptHelper.Alert("活动进行中,不能编辑"); } bargain.Name = Name.Text; bargain.StartDate = DateTime.Parse(StartDate.Text); bargain.EndDate = DateTime.Parse(EndDate.Text); if (bargain.StartDate >= bargain.EndDate) { ScriptHelper.Alert("结束时间不能小于开始时间"); } //if (!Unlimited.Checked && string.IsNullOrEmpty(LimitCount.Text)) //{ // ScriptHelper.Alert("请填写助力限制次数"); //} //bargain.LimitCount = Unlimited.Checked ? int.MaxValue : int.Parse(LimitCount.Text); if (string.IsNullOrEmpty(LimitCount.Text)) { ScriptHelper.Alert("请填写助力限制次数"); } bargain.LimitCount = int.Parse(LimitCount.Text); bargain.NumberPeople = int.Parse(NumberPeople.Text); //bargain.SuccessRate = int.Parse(SuccessRate.Text); //砍价成功率默认100% bargain.SuccessRate = 100; //记录改变前的状态 int original_Status = bargain.Status; bargain.Status = RequestHelper.GetForm <int>("ctl00$ContentPlaceHolder$Status") <= 0 ? 0 : 1; string alertMessage = string.Empty; try { #region 参加活动的商品 //原始 List <BargainDetailsInfo> original_b_details = BargainDetailsBLL.ReadByBargainId(bargain.Id); //待新增、修改 List <BargainDetailsInfo> B_Details = new List <BargainDetailsInfo>(); var Ids = Array.ConvertAll(RequestHelper.GetForm <string>("Id").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(int.Parse(s)); }); var Product_Id = Array.ConvertAll(RequestHelper.GetForm <string>("Product_Id").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(int.Parse(s)); }); var BargainId = Array.ConvertAll(RequestHelper.GetForm <string>("BargainId").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(int.Parse(s)); }); var Product_Name = RequestHelper.GetForm <string>("Product_Name").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //var Product_OriginalPrice = RequestHelper.GetForm<string>("Product_OriginalPrice"); var product_OriginalPrice = Array.ConvertAll(RequestHelper.GetForm <string>("product_OriginalPrice").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => decimal.Parse(k)); var Product_ReservePrice = Array.ConvertAll(RequestHelper.GetForm <string>("Product_ReservePrice").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(decimal.Parse(s)); }); var Stock = Array.ConvertAll(RequestHelper.GetForm <string>("Stock").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(int.Parse(s)); }); var Sort = Array.ConvertAll(RequestHelper.GetForm <string>("Sort").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(int.Parse(s)); }); //是否在售 var Product_IsSale = string.IsNullOrWhiteSpace(RequestHelper.GetForm <string>("Product_IsSale")) ? null : Array.ConvertAll(RequestHelper.GetForm <string>("Product_IsSale").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(int.Parse(s)); }); //是否删除 var Product_IsDelete = string.IsNullOrWhiteSpace(RequestHelper.GetForm <string>("Product_IsDelete")) ? null : Array.ConvertAll(RequestHelper.GetForm <string>("Product_IsDelete").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(int.Parse(s)); }); //商品表编号 var Product_Real_Id = string.IsNullOrWhiteSpace(RequestHelper.GetForm <string>("Product_Real_Id")) ? null : Array.ConvertAll(RequestHelper.GetForm <string>("Product_Real_Id").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), delegate(string s) { return(int.Parse(s)); }); //正在参加砍价的商品 var _bargainProducts = BargainDetailsBLL.ReadBargainProducts(); for (int i = 0; i < Product_Id.Length; i++) { //添加:Product_Id[i]>0 //修改:Product_Id[i] > 0 && Product_Real_Id[i]==Product_Id[i] 商品表必须存在此商品 if ((Ids[i] <= 0 && Product_Id[i] > 0) || (Ids[i] > 0 && Product_Id[i] > 0 && Product_Real_Id != null && Product_Real_Id[i] == Product_Id[i])) { #region 是否下架或删除 if (Product_IsSale != null && Product_IsSale.Length > i) { if (Product_IsSale[i] != 1) { alertMessage = "商品:【" + Product_Name[i] + "】已下架,不能添加"; } } if (Product_IsDelete != null && Product_IsDelete.Length > i) { if (Product_IsDelete[i] != 0) { alertMessage = "商品:【" + Product_Name[i] + "】已删除,不能添加"; } } #endregion #region 一商品同时只能参加1个砍价活动 if (_bargainProducts.Any(k => k.ProductID == Product_Id[i]) && Ids[i] <= 0) { alertMessage = "商品:【" + Product_Name[i] + "】正在参与砍价活动,不得重复添加"; } #endregion if (string.IsNullOrEmpty(alertMessage)) { //判断商品底价不得超过原价 if (product_OriginalPrice[i] <= Product_ReservePrice[i]) { alertMessage = "商品底价必须小于原价"; //ScriptHelper.Alert("商品:【"+Product_Name[i]+"】底价必须大于【"+(product_OriginalPrice[i] - product_OriginalPrice[i] * bargain.SuccessRate/100) +"】"); //return; } B_Details.Add(new BargainDetailsInfo() { Id = Ids[i], ProductID = Product_Id[i], ReservePrice = Product_ReservePrice[i], Sort = Sort[i], Stock = Stock[i], BargainId = BargainId[i], ProductName = Product_Name[i], ShareImage1 = (original_b_details.FirstOrDefault(k => k.Id == Ids[i]) ?? new BargainDetailsInfo()).ShareImage1 }); } } } #endregion if (string.IsNullOrEmpty(alertMessage)) { alertMessage = ShopLanguage.ReadLanguage("AddOK"); if (ID <= 0) { CheckAdminPower("AddBargain", PowerCheckType.Single); int id = BargainBLL.AddBargain(bargain); B_Details.ForEach(item => { item.BargainId = id; item.ShareImage1 = CreateBargainShareImage(item.ReservePrice, item.ProductID); BargainDetailsBLL.AddBargainDetails(item); }); AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("Bargain"), id); } else { CheckAdminPower("UpdateBargain", PowerCheckType.Single); BargainBLL.UpdateBargain(bargain); #region 修改时关闭活动,则将未支付成功的砍价全部置为“砍价失败”,原“活动已取消,砍价失败” if (original_Status == (int)Bargain_Status.OnGoing && bargain.Status == (int)Bargain_Status.ShutDown) { //异步 关闭 ShutDownBargain(bargain.Id); } #endregion B_Details.ForEach(item => { item.BargainId = bargain.Id; item.ShareImage1 = CreateBargainShareImage(item.ReservePrice, item.ProductID, item.ShareImage1); if (item.Id > 0) { BargainDetailsBLL.UpdateBargainDetails(item); } else { BargainDetailsBLL.AddBargainDetails(item); } }); AdminLogBLL.Add(ShopLanguage.ReadLanguage("UpdateRecord"), ShopLanguage.ReadLanguage("Bargain"), bargain.Id); alertMessage = ShopLanguage.ReadLanguage("UpdateOK"); } } } catch (Exception ex) { new TxtLog(Server.MapPath("/apilog/")).Write("-----bargainadd error:" + ex); ScriptHelper.Alert("商品底价、库存、排序号 填写不规范,请检查"); } if (alertMessage == ShopLanguage.ReadLanguage("AddOK") || alertMessage == ShopLanguage.ReadLanguage("UpdateOK")) { ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl); } else { ScriptHelper.Alert(alertMessage); } }