private void BindData() { if (ProductID != 0) { GroupProductModel model = bll.GetModel(ProductID); this.Title = model.ProductName + "-团购-鼎鼎商城"; Literal_ProductName.Text = model.ProductName; Image_Small.ImageUrl = GroupShoppingImageRule.GetImageUrl(model.MediumImage); Image_Big.ImageUrl = GroupShoppingImageRule.GetImageUrl(model.LargeImage); Literal_Count.Text = model.SuccedLine.ToString(); Literal_CurrentCount.Text = ""; Literal_GroupPrice.Text = model.GroupPrice.ToString("0.00"); Literal_MarketPrice.Text = model.MarketPrice.ToString("0.00"); Literal_Time.Text = ""; Literal_Brief.Text = model.Description; if (model.ProductType == (int)GroupShoppingProductType.解决方案) { Literal_Detail.Text = String.Format("<div class=\"box7\" runat=\"server\"><div class=\"title\">解决方案明细</div><div class=\"content\"><p class=\"description\">{0}</p></div></div>", model.Detail); Literal_Detail.Visible = true; } if (Session["group-product-apply"] != null) { TextBox_Message.Text = Session["group-product-apply"].ToString(); TextBox_Message.Focus(); } Repeater_ApplyList.DataSource = abll.GetList(ProductID); Repeater_ApplyList.DataBind(); } }
private void BindData() { DropDown_ProductType.DataSource = DataTableUtil.GetEnumKeyValue(typeof(GroupShoppingProductType)); DropDown_ProductType.DataTextField = "key"; DropDown_ProductType.DataValueField = "value"; DropDown_ProductType.DataBind(); if (GroupProductID != 0) { GroupProductModel model = bll.GetModel(GroupProductID); TextBox_ProductName.Text = model.ProductName; DropDown_ProductType.SelectedValue = model.ProductType.ToString(); TextBox_ProductCode.Text = model.ProductCode; TextBox_MarketPrice.Text = model.MarketPrice.ToString("0.00"); TextBox_GroupPrice.Text = model.GroupPrice.ToString("0.00"); TextBox_PrePaidPrice.Text = model.PrePaidPrice.ToString("0.00"); TextBox_Detail.Text = model.Detail; TextBox_Brief.Text = model.Description; TextBox_SuccedLine.Text = model.SuccedLine.ToString(); CheclBox_Recommend.Checked = model.IsRecommend; Image_ProductImage.ImageUrl = GroupShoppingImageRule.GetImageUrl(model.SmallImage); } }
public RepositoryResult <IEnumerable <ProductInterfaceModel> > GroupModifyProducts(int groupId, List <ProductInterfaceModel> ProductList) { try { if (groupId <= 0) { return(new RepositoryResult <IEnumerable <ProductInterfaceModel> >(HttpStatusCode.BadRequest)); } using (DataContext dbContext = DataContext.Create()) { var group = dbContext.GroupModels.Where(g => g.Id == groupId).SingleOrDefault(); if (group == null) { return(new RepositoryResult <IEnumerable <ProductInterfaceModel> >(HttpStatusCode.NotFound)); } dbContext.Database.ExecuteSqlCommand(RepositoryResource.IncrementResetGroupProduct); using (DbContextTransaction tx = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable)) { List <int> setProductList = ProductList.Select(m => m.Id).OrderBy(x => x).ToList(); IQueryable <GroupProductModel> groupProducts = dbContext.GroupProductModels.Where(x => x.GroupModelId == groupId).OrderBy(x => x.ProductModelId); List <int> productIdList = dbContext.ProductModels.Where(x => x.MakerModelId == group.MakerModelId).Select(x => x.Id).OrderBy(x => x).ToList <int>(); foreach (int item in productIdList) { GroupProductModel check = groupProducts.Where(x => x.ProductModelId == item).FirstOrDefault(); if (check == null && setProductList.Contains(item)) { check = new GroupProductModel(); check.GroupModelId = groupId; check.ProductModelId = item; dbContext.GroupProductModels.Add(check); } else if (check != null && setProductList.Contains(item) && check.Deleted == true) { check.Deleted = false; dbContext.Entry(check).State = EntityState.Modified; } else if (check != null && !setProductList.Contains(item) && check.Deleted == false) { check.Deleted = true; dbContext.Entry(check).State = EntityState.Modified; } } dbContext.SaveChanges(); tx.Commit(); } dbContext.Database.ExecuteSqlCommand(RepositoryResource.IncrementResetGroupProduct); return(new RepositoryResult <IEnumerable <ProductInterfaceModel> >(HttpStatusCode.NotFound, ProductList)); } } catch (Exception ex) { throw ex; } }
public IHttpActionResult SetProductList(int id, [FromBody] List <ProductApiModel> ProductList) { try { if (id <= 0) { return(BadRequest(Messages.ApiIllegalParameter)); } GroupModel group = dbContext.GroupModels.Where(g => g.Id == id).SingleOrDefault(); if (group == null) { return(BadRequest(Messages.ApiIllegalParameter)); } dbContext.Database.ExecuteSqlCommand(ContextResources.IncrementResetGroupProduct); using (DbContextTransaction tx = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable)) { List <int> setProductList = ProductList.Select(m => m.Id).OrderBy(x => x).ToList(); IQueryable <GroupProductModel> groupProducts = dbContext.GroupProductModels .Where(x => x.GroupModelId == id).OrderBy(x => x.ProductModelId); List <int> productIdList = dbContext.ProductModels.Where(x => x.MakerModelId == group.MakerModelId) .Select(x => x.Id).OrderBy(x => x).ToList <int>(); foreach (int item in productIdList) { GroupProductModel check = groupProducts.Where(x => x.ProductModelId == item).FirstOrDefault(); if (check == null && setProductList.Contains(item)) { check = new GroupProductModel(); check.GroupModelId = id; check.ProductModelId = item; dbContext.GroupProductModels.Add(check); } else if (check != null && setProductList.Contains(item) && check.Deleted == true) { check.Deleted = false; dbContext.Entry(check).State = EntityState.Modified; } else if (check != null && !setProductList.Contains(item) && check.Deleted == false) { check.Deleted = true; dbContext.Entry(check).State = EntityState.Modified; } } dbContext.SaveChanges(); tx.Commit(); } dbContext.Database.ExecuteSqlCommand(ContextResources.IncrementResetGroupProduct); return(Ok(ProductList)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static GroupProductModel GetImageUrl(GroupProductModel Product) { Product.SmallImage = config.UrlRoot + Product.SmallImage; Product.MediumImage = config.UrlRoot + Product.MediumImage; Product.LargeImage = config.UrlRoot + Product.LargeImage; return(Product); }
protected void Button_Add_Click(object sender, EventArgs e) { string ErrorMessage = String.Empty; if (String.IsNullOrEmpty(TextBox_ProductName.Text.Trim())) ErrorMessage += "产品名称不能为空\\n"; if (String.IsNullOrEmpty(TextBox_MarketPrice.Text.Trim()) || !PageValidate.IsDecimal(TextBox_MarketPrice.Text.Trim())) ErrorMessage += "市场价输入有误\\n"; if (String.IsNullOrEmpty(TextBox_GroupPrice.Text.Trim()) || !PageValidate.IsDecimal(TextBox_GroupPrice.Text.Trim())) ErrorMessage += "团购价输入有误\\n"; if (String.IsNullOrEmpty(TextBox_PrePaidPrice.Text.Trim()) || !PageValidate.IsDecimal(TextBox_PrePaidPrice.Text.Trim())) ErrorMessage += "预付金额输入有误\\n"; if (String.IsNullOrEmpty(TextBox_SuccedLine.Text.Trim()) || !PageValidate.IsNumber(TextBox_SuccedLine.Text.Trim())) ErrorMessage += "成团人数输入有误"; if (String.IsNullOrEmpty(TextBox_Brief.Text.Trim())) ErrorMessage += "产品简介不能为空\\n"; if (String.IsNullOrEmpty(FileUpload_Image.FileName.Trim())) ErrorMessage += "产品图片不能为空\\n"; if (!String.IsNullOrEmpty(ErrorMessage)) { MessageBox.Show(this, ErrorMessage); return; } int GroupProductID = CommDataHelper.GetNewSerialNum(AppType.GroupShopping); string[] FileNames = new string[3]; if (GroupShoppingImageRule.SaveImage(GroupProductID, FileUpload_Image.PostedFile, out FileNames)) { GroupProductModel model = new GroupProductModel(); model.ProductID = GroupProductID; model.ProductName = TextBox_ProductName.Text.Trim(); model.ProductType = Convert.ToInt32(DropDown_ProductType.SelectedValue); model.ProductCode = TextBox_ProductCode.Text.Trim(); model.MarketPrice = Convert.ToDecimal(TextBox_MarketPrice.Text.Trim()); model.GroupPrice = Convert.ToDecimal(TextBox_GroupPrice.Text.Trim()); model.PrePaidPrice = Convert.ToDecimal(TextBox_PrePaidPrice.Text.Trim()); model.SuccedLine = Convert.ToInt32(TextBox_SuccedLine.Text.Trim()); model.IsRecommend = CheclBox_Recommend.Checked; model.Detail = TextBox_Detail.Text.Trim(); model.Description = TextBox_Brief.Text; model.SmallImage = FileNames[0]; model.MediumImage = FileNames[1]; model.LargeImage = FileNames[2]; model.InsertTime = DateTime.Now; model.ChangeTime = DateTime.Now; model.Status = (int)GroupShoppingProductStatus.正在团购; new GroupProductBll().Add(model); Response.Redirect("List.aspx"); } else { MessageBox.Show(this, "图片上传失败,请检查后重新选择!"); return; } }
public GroupProductModel GetModel(int ProductID) { DbCommand Command = dbr.GetStoredProcCommand("UP_gsProduct_GetModel"); dbw.AddInParameter(Command, "@ProductID", DbType.Int32, ProductID); GroupProductModel model = null; DataTable dt = dbr.ExecuteDataSet(Command).Tables[0]; if (dt.Rows.Count > 0) { model = GetModel(dt.Rows[0]); } return(model); }
public void Update(GroupProductModel model) { DbCommand Command = dbw.GetStoredProcCommand("UP_gsProduct_Update"); dbw.AddInParameter(Command, "@ProductID", DbType.Int32, model.ProductID); dbw.AddInParameter(Command, "@ProductName", DbType.String, model.ProductName); dbw.AddInParameter(Command, "@ProductCode", DbType.String, model.ProductCode); dbw.AddInParameter(Command, "@MarketPrice", DbType.Decimal, model.MarketPrice); dbw.AddInParameter(Command, "@GroupPrice", DbType.Decimal, model.GroupPrice); dbw.AddInParameter(Command, "@PrePaidPrice", DbType.Decimal, model.PrePaidPrice); dbw.AddInParameter(Command, "@succedline", DbType.Int32, model.SuccedLine); dbw.AddInParameter(Command, "@SmallImage", DbType.String, model.SmallImage); dbw.AddInParameter(Command, "@MediumImage", DbType.String, model.MediumImage); dbw.AddInParameter(Command, "@LargeImage", DbType.String, model.LargeImage); dbw.AddInParameter(Command, "@Detail", DbType.String, model.Detail); dbw.AddInParameter(Command, "@Description", DbType.String, model.Description); dbw.AddInParameter(Command, "@InsertTime", DbType.DateTime, model.InsertTime); dbw.AddInParameter(Command, "@ChangeTime", DbType.DateTime, model.ChangeTime); dbw.AddInParameter(Command, "@Status", DbType.Int16, model.Status); dbw.AddInParameter(Command, "@ProductType", DbType.Int16, model.ProductType); dbw.AddInParameter(Command, "@isrecommend", DbType.Boolean, model.IsRecommend); dbw.ExecuteNonQuery(Command); }
private GroupProductModel GetModel(DataRow row) { GroupProductModel model = new GroupProductModel(); model.ProductID = Convert.ToInt32(row["ProductID"]); model.ProductName = Convert.ToString(row["ProductName"]); model.ProductCode = Convert.ToString(row["ProductCode"]); model.Description = Convert.ToString(row["Description"]); model.Detail = Convert.ToString(row["Detail"]); model.PrePaidPrice = Convert.ToDecimal(row["PrePaidPrice"]); model.GroupPrice = Convert.ToDecimal(row["GroupPrice"]); model.InsertTime = Convert.ToDateTime(row["InsertTime"]); model.ChangeTime = Convert.ToDateTime(row["ChangeTime"]); model.SmallImage = Convert.ToString(row["SmallImage"]); model.MediumImage = Convert.ToString(row["MediumImage"]); model.LargeImage = Convert.ToString(row["LargeImage"]); model.ProductType = Convert.ToInt16(row["ProductType"]); model.Status = Convert.ToInt16(row["Status"]); model.MarketPrice = Convert.ToDecimal(row["MarketPrice"]); model.SuccedLine = Convert.ToInt32(row["SuccedLine"]); model.IsRecommend = Convert.ToBoolean(row["IsRecommend"]); return(model); }
public void Update(GroupProductModel model) { dal.Update(model); }
public void Add(GroupProductModel model) { dal.Add(model); }
protected void Button_Edit_Click(object sender, EventArgs e) { string ErrorMessage = String.Empty; if (String.IsNullOrEmpty(TextBox_ProductName.Text.Trim())) { ErrorMessage += "产品名称不能为空\\n"; } if (String.IsNullOrEmpty(TextBox_MarketPrice.Text.Trim()) || !PageValidate.IsDecimal(TextBox_MarketPrice.Text.Trim())) { ErrorMessage += "市场价输入有误\\n"; } if (String.IsNullOrEmpty(TextBox_GroupPrice.Text.Trim()) || !PageValidate.IsDecimal(TextBox_GroupPrice.Text.Trim())) { ErrorMessage += "团购价输入有误\\n"; } if (String.IsNullOrEmpty(TextBox_PrePaidPrice.Text.Trim()) || !PageValidate.IsDecimal(TextBox_PrePaidPrice.Text.Trim())) { ErrorMessage += "预付金额输入有误\\n"; } if (String.IsNullOrEmpty(TextBox_SuccedLine.Text.Trim()) || !PageValidate.IsNumber(TextBox_SuccedLine.Text.Trim())) { ErrorMessage += "成团人数输入有误"; } if (String.IsNullOrEmpty(TextBox_Brief.Text.Trim())) { ErrorMessage += "产品简介不能为空\\n"; } if (!String.IsNullOrEmpty(ErrorMessage)) { MessageBox.Show(this, ErrorMessage); return; } GroupProductModel model = bll.GetModel(GroupProductID); model.ProductName = TextBox_ProductName.Text.Trim(); model.ProductType = Convert.ToInt32(DropDown_ProductType.SelectedValue); model.ProductCode = TextBox_ProductCode.Text.Trim(); model.MarketPrice = Convert.ToDecimal(TextBox_MarketPrice.Text.Trim()); model.GroupPrice = Convert.ToDecimal(TextBox_GroupPrice.Text.Trim()); model.PrePaidPrice = Convert.ToDecimal(TextBox_PrePaidPrice.Text.Trim()); model.SuccedLine = Convert.ToInt32(TextBox_SuccedLine.Text.Trim()); model.IsRecommend = CheclBox_Recommend.Checked; model.Detail = TextBox_Detail.Text.Trim(); model.Description = TextBox_Brief.Text; if (FileUpload_Image.FileName.Trim() != String.Empty && FileUpload_Image.PostedFile.ContentLength > 0) { string[] FileNames = new string[3]; if (GroupShoppingImageRule.SaveImage(GroupProductID, FileUpload_Image.PostedFile, out FileNames)) { model.SmallImage = FileNames[0]; model.MediumImage = FileNames[1]; model.LargeImage = FileNames[2]; } else { MessageBox.Show(this, "图片上传失败,请检查后重新选择!"); return; } } model.ChangeTime = DateTime.Now; bll.Update(model); Response.Redirect("List.aspx"); }
public async Task <Operate> AddOrUpdate(GroupProductModel model, string userName) { var result = new Operate(); try { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { //check duplicated group code var dupGroup = await _buyerGroupRepository.GetGroupByName(model.Code, model.Id); if (dupGroup != null) { result.Status = -2; result.Message = "Name is already taken"; return(result); } BuyerGroup buyerGroup; if (model.Id == 0) { buyerGroup = new BuyerGroup() { Code = model.Code, CreateBy = userName, CreateTime = DateTime.UtcNow }; } else { buyerGroup = await _buyerGroupRepository.GetById(model.Id); if (buyerGroup == null) { result.Status = -3; result.Message = "Buyer Group does not exist"; Logger.WriteErrorLog("BuyerGroupService", "AddOrUpdate", new Exception("Buyer Group does not exist")); return(result); } buyerGroup.Code = model.Code; buyerGroup.EditTime = DateTime.UtcNow; buyerGroup.EditBy = userName; } await _buyerGroupRepository.AddOrUpdate(buyerGroup); //update customer table's buyergroupId var customerIdList = new List <int>(); foreach (var customerItem in model.CustomerTempModelList) { customerIdList.Add(customerItem.Id); var customer = await _customerRepository.GetById(customerItem.Id); if (customer == null) { continue; } customer.BuyerGroupId = buyerGroup.Id; await _customerRepository.AddOrUpdate(customer); } var customerListByGroupPRoduct = await _customerRepository.GetByBuyerGroupId(buyerGroup.Id); foreach (var customer in customerListByGroupPRoduct) { if (customerIdList.IndexOf(customer.Id) < 0) { customer.BuyerGroupId = 0; await _customerRepository.AddOrUpdate(customer); } } //if group has been altered, set expire time now and insert new mapping relation var groupProduct = await _buyerGroupRepository.GetGroupProductByBuyerGroupId(buyerGroup.Id); if (groupProduct.Count != 0) { foreach (var item in groupProduct) { await _buyerGroupRepository.DeleteGroupProduct(item); } } foreach (var productItem in model.ProductTempModelList) { var groupProductNew = new GroupProduct() { Id = 0, BuyerGroupId = buyerGroup.Id, ProductId = productItem.ProductId, Price = productItem.Price }; await _buyerGroupRepository.AddOrUpdateGroupProduct(groupProductNew); } scope.Complete(); } } catch (Exception ex) { result.Status = -1; result.Message = ex.Message; Logger.WriteErrorLog("BuyerGroupService", "AddOrUpdate", ex); } return(result); }
public async Task <Operate> AddOrUpdate(GroupProductModel model) { var userName = User.Identity.Name; return(await _buyerGroupService.AddOrUpdate(model, userName)); }