private void createBrandModelList() { List <BrandView> brandViews = new List <BrandView>(); DataTable dtBrandsSupplierID = Helper.LoadSql("SELECT dbo.Brand.id FROM dbo.Supplier_Brand INNER JOIN " + "dbo.Brand ON dbo.Supplier_Brand.brandID = dbo.Brand.id " + "WHERE(dbo.Supplier_Brand.supplierID = " + cmbSupplier.SelectedValue + ")"); // SupplierID foreach (DataRow brandRow in dtBrandsSupplierID.Rows) { int brandID = int.Parse(brandRow["id"].ToString()); DataRow dr1 = (DataRow)(from myRow in ds.Tables["Brand"].AsEnumerable() where myRow.Field <int>("id") == brandID select myRow).FirstOrDefault(); BrandView brandView1 = new BrandView(); brandView1.id = int.Parse(dr1["id"].ToString()); brandView1.name = dr1["name"].ToString(); brandView1.fullName = dr1["fullName"].ToString(); brandView1.brandProductTypeID = int.Parse(dr1["brandProductTypeID"].ToString()); brandView1.brandProductTypeName = dr1["brandProductTypeName"].ToString(); brandView1.defaultSizeSetID = Helper.IntParse(dr1["defaultSizeSetID"].ToString()); brandView1.sizeSetName = dr1["sizeSetName"].ToString(); brandView1.isRequiredColor = int.Parse(dr1["isRequiredColor"].ToString()); brandView1.isRequireSize = int.Parse(dr1["isRequireSize"].ToString()); brandView1.modelCodes = new List <BaseTable>(); foreach (DataRow dr2 in dr1.GetChildRows(brandsmodelsRelation)) { BaseTable model1 = new BaseTable(); model1.id = (int)dr2["id"]; model1.name = dr2["code"].ToString(); brandView1.modelCodes.Add(model1); } brandViews.Add(brandView1); } bsBrandView.DataSource = brandViews; }
// GET: Brands/Create public ActionResult Create() { Sidebar(); var model = new BrandView(); return(View(model)); }
/// <summary> /// Thread body /// </summary> /// <param name="state"></param> private void StartWork(object state) { BrandView brandView = state as BrandView; brand savedBrand = null; brand theBrand = new brand(); brandView.Merge(theBrand, editMode); AutoResetEvent nextOneAutoResetEvent = new AutoResetEvent(false); EventHandler <save_BrandCompletedEventArgs> h1 = (s, e) => { // TODO: handle error from server side savedBrand = e.Result; nextOneAutoResetEvent.Set(); }; Globals.WSClient.save_BrandCompleted += h1; Globals.WSClient.save_BrandAsync(theBrand); nextOneAutoResetEvent.WaitOne(); Globals.WSClient.save_BrandCompleted -= h1; // Check return result. If failure, savedCategory will be null if (savedBrand != null) { this.Dispatcher.BeginInvoke(delegate() { brandView.Restore(new BrandView(savedBrand)); }); } else { // Show error message ShopproHelper.ShowMessageWindow(this, "Error", "Fail to save this entry.", false); // Back to readonly mode this.Dispatcher.BeginInvoke(delegate() { // Restore cached UI data brandView.CancelEdit(); this.brandDataForm.CancelEdit(); }); } // No unsaved item this.editMode = DataFormMode.ReadOnly; // Hide busy indicator ShopproHelper.HideBusyIndicator(this); // Go to original page if necessary if (this.ContentPageCtx.GotoAddNewPage) { ShopproHelper.GoToContentPage(this, PageEnum.BrandListPage); } }
public ActionResult Edit(BrandView brand) { if (ModelState.IsValid) { var t = db.Brand.FirstOrDefault(s => s.ID == brand.ID); t.ID = brand.ID; t.Name = brand.Name; t.Image = string.Join(",", brand.Image.Images); t.Sort = brand.Sort; t.Explain = brand.Explain; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
public BrandView ReturnOneBrand(int id) { Brand b1 = db.Brands.Find(id); if (b1 == null) { return(new BrandView()); } BrandView b = new BrandView(); b.BrandId = b1.BrandId; b.BrandName = b1.BrandName; b.CountryOfOrigin = b1.CountryOfOrigin; return(b); }
public ActionResult Create(BrandView brand) { if (ModelState.IsValid) { var model = new Brand { Name = brand.Name, Image = string.Join(",", brand.Image.Images), Sort = brand.Sort, Explain = brand.Explain }; db.Brand.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
// GET: Brands/Edit/5 public ActionResult Edit(int?id) { Sidebar(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Brand model = db.Brand.Find(id); var models = new BrandView { ID = model.ID, Name = model.Name, Sort = model.Sort, Explain = model.Explain }; models.Image.Images = model.Image?.Split(',') ?? new string[0]; if (models == null) { return(HttpNotFound()); } return(View(models)); }
/// <summary> /// 查询品牌 /// </summary> /// <param name="search">查询条件</param> /// <returns>品牌数据集合</returns> public List <BrandView> QueryBrand(SearchCondition search) { List <BrandView> result = new List <BrandView>(); MySqlConnection connection = Connection.GetConnection(); MySqlCommand cmd = new MySqlCommand(); StringBuilder sql = new StringBuilder(); sql.Append("SELECT Id,Name,Logo FROM Himall_Brands WHERE Id IN (SELECT DISTINCT BrandId FROM Himall_Products _p "); sql.Append("WHERE _p.IsDeleted=0 AND _p.AuditStatus=2 AND _p.SaleStatus=1 "); #region 店铺过滤 if (search.shopId > 0) { sql.Append(" AND _p.ShopId=@ShopId "); cmd.Parameters.AddWithValue("@ShopId", search.shopId); } #endregion #region 品牌过滤 if (search.BrandId > 0) { sql.Append(" AND _p.BrandId=@BrandId "); cmd.Parameters.AddWithValue("@BrandId", search.BrandId); } #endregion #region 分类过滤 if (search.CategoryId > 0) { if (search.shopId > 0) { sql.Append(" AND _p.Id IN (SELECT DISTINCT ProductId FROM Himall_ProductShopCategories WHERE ShopCategoryId = @ShopCategoryId)"); cmd.Parameters.AddWithValue("@ShopCategoryId", search.ShopCategoryId); } else { sql.AppendFormat("AND _p.CategoryId IN (SELECT Id FROM Himall_Categories WHERE CONCAT('|',Path,'|') LIKE '%|{0}|%')", search.CategoryId); } } #endregion #region 属性过滤 if (search.AttrIds.Count > 0) { string sqlAttrWhere = string.Empty; for (int i = 0; i < search.AttrIds.Count; i++) { if (search.AttrIds[i].Contains("_")) { string attrId = search.AttrIds[i].Split(new char[] { '_' })[0]; string valId = search.AttrIds[i].Split(new char[] { '_' })[1]; sqlAttrWhere += string.Format("(AttributeId=@AttrId{0} AND ValueId=@ValId{0}) OR", i.ToString()); cmd.Parameters.AddWithValue(string.Format("@AttrId{0}", i.ToString()), attrId); cmd.Parameters.AddWithValue(string.Format("@ValId{0}", i.ToString()), valId); } } if (!string.IsNullOrEmpty(sqlAttrWhere)) { sqlAttrWhere = sqlAttrWhere.Substring(0, sqlAttrWhere.Length - 3); sql.AppendFormat(" AND _p.Id IN (SELECT DISTINCT ProductId FROM Himall_ProductAttributes WHERE {0}) ", sqlAttrWhere); } } #endregion #region 价格区间 if (search.StartPrice > 0) { sql.Append(" AND _p.MinSalePrice>=@StartPrice "); cmd.Parameters.AddWithValue("@StartPrice", search.StartPrice); } if (search.EndPrice > 0 && search.EndPrice >= search.StartPrice) { sql.Append(" AND _p.MinSalePrice <= @EndPrice "); cmd.Parameters.AddWithValue("@EndPrice", search.EndPrice); } #endregion #region 关键词处理 if (!string.IsNullOrEmpty(search.Keyword)) { //分隔关键词 List <string> words = new List <string>(); List <string> ws = _segment.DoSegment(search.Keyword); foreach (string s in ws) { if (!words.Contains(s)) { words.Add(s); } } if (search.Ex_Keyword != null && !string.IsNullOrEmpty(search.Ex_Keyword.Trim()) && search.Ex_Keyword.Trim().Length <= 5) { words.Add(search.Ex_Keyword.Trim()); } else { if (!string.IsNullOrEmpty(search.Ex_Keyword)) { ws = _segment.DoSegment(search.Ex_Keyword); foreach (string s in ws) { if (!words.Contains(s)) { words.Add(s); } } } } //分词搜索 if (words.Count > 0) { MySqlCommand IdCmd = new MySqlCommand(); string sqlWhere = "SELECT Id FROM Himall_Products WHERE ProductName=@ProductName UNION ALL SELECT a.ProductId FROM Himall_ProductWords a INNER JOIN Himall_SegmentWords b ON a.WordId=b.Id WHERE b.Word IN (SELECT WORD FROM ({0}) AS _WordTable) OR MATCH(b.Word) AGAINST(@WordList IN BOOLEAN MODE)"; string wordList = string.Empty; string wordInList = string.Empty; string IdList = string.Empty; for (int i = 0; i < words.Count; i++) { wordList += words[i] + "*,"; wordInList += string.Format("SELECT @word{0} AS WORD {1} ", i.ToString(), (i == words.Count - 1 ? string.Empty : " UNION ALL ")); IdCmd.Parameters.AddWithValue(string.Format("@word{0}", i.ToString()), words[i]); } IdCmd.Parameters.AddWithValue("@WordList", wordList.TrimEnd(new char[] { ',' })); IdCmd.Parameters.AddWithValue("@ProductName", search.Keyword.Trim()); IdCmd.CommandText = string.Format(sqlWhere, wordInList); IdCmd.Connection = connection; if (IdCmd.Connection.State != ConnectionState.Open) { connection.Open(); } MySqlDataReader IdReader = IdCmd.ExecuteReader(); while (IdReader.Read()) { IdList += IdReader["Id"].ToString() + ","; } IdReader.Dispose(); sql.AppendFormat(" AND _p.Id IN ({0})", string.IsNullOrEmpty(IdList) ? "0" : IdList.TrimEnd(new char[] { ',' })); } } #endregion sql.Append(")"); cmd.Connection = connection; if (cmd.Connection.State != ConnectionState.Open) { connection.Open(); } cmd.CommandText = sql.ToString(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { BrandView temp = new BrandView(); temp.Id = long.Parse(reader["Id"].ToString()); temp.Name = reader["Name"].ToString(); temp.Logo = reader["Logo"].ToString(); result.Add(temp); } reader.Dispose(); connection.Close(); connection.Dispose(); return(result); }
protected internal override Brand toObject(BrandView v) => new BrandViewFactory().Create(v);