public DataOperation(List<Model.MigrationDataSet> mds, MainForm form) { this.mds = mds; this.connectionString = System.Configuration.ConfigurationSettings.AppSettings["MySqlConnectionString"]; prod = new Product(); pItem = new ProductItem(); pM = new PriceMaster(); iPrice = new ItemPrice(); categorySet = new ProductCategorySet(); pMap = new ProductMigrationMap(); _prodMgr = new ProductMgr(this.connectionString); _priceMgr = new PriceMasterMgr(this.connectionString); _prodItemMgr = new ProductItemMgr(this.connectionString); _itemPriceMgr = new ItemPriceMgr(this.connectionString); _vendorBrandMgr = new VendorBrandMgr(this.connectionString); _vendorMgr = new VendorMgr(this.connectionString); _pMap = new ProductMigrationMgr(this.connectionString); _productCategorySetMgr = new ProductCategorySetMgr(this.connectionString); _productNoticeSetMgr = new ProductNoticeSetMgr(this.connectionString); _productTagSetMgr = new ProductTagSetMgr(this.connectionString); _productPictureMgr = new ProductPictureMgr(this.connectionString); _proStatusHistoryMgr = new ProductStatusHistoryMgr(connectionString); _proSpecMgr = new ProductSpecMgr(connectionString); _siteMgr = new SiteMgr(connectionString); this.form = form; }
public HttpResponseBase IsSameChildVendor() { string result = string.Empty; try { List<ProductComboCustom> combos; if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { int parentId = int.Parse(Request.Params["ProductId"]); _combMgr = new ProductComboMgr(connectionString); combos = _combMgr.combQuery(new ProductComboCustom { Parent_Id = parentId }); } else { Caller _caller = (Session["caller"] as Caller); _combTempMgr = new ProductComboTempMgr(connectionString); ProductComboCustom query = new ProductComboCustom { Writer_Id = _caller.user_id }; //複製商品時 if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { query.Parent_Id = int.Parse(Request.Form["OldProductId"]); } combos = _combTempMgr.combQuery(query); } List<uint> brandIds = combos.GroupBy(m => m.brand_id).Select(m => m.Key).ToList(); if (brandIds.Count == 1) { result = "{success:true,same:true}"; } else { _vendorBrandMgr = new VendorBrandMgr(connectionString); List<uint> vendorIds = new List<uint>(); VendorBrand vendorBrand; foreach (var id in brandIds) { vendorBrand = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Id = id }); if (vendorBrand != null && !vendorIds.Contains(vendorBrand.Vendor_Id)) { vendorIds.Add(vendorBrand.Vendor_Id); } } result = "{success:true,same:" + (vendorIds.Count == 1).ToString().ToLower() + "}"; } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); result = "{success:true,same:false}"; } this.Response.Clear(); this.Response.Write(result); this.Response.End(); return this.Response; }
private string QueryHistory(int itemType) { StringBuilder html = new StringBuilder(); try { _historyBatchMgr = new HistoryBatchMgr(connectionString); List<HistoryBatch> batches = _historyBatchMgr.QueryToday(itemType); //edit by hufeng0813w 2014/06/13 batches.Sort(CompareToRowid);//進行一個排序 //end edit by hufeng0813w 2014/06/13 if (batches != null & batches.Count > 0) { html.Append("<html><head><style type=\"text/css\">table{text-align:center; font-size: 13px;border:1px solid #99bce8}caption{text-align:center;border:1px solid #99bce8;} td{border:1px solid #99bce8}.red{color:red;}.green{color:green;}.tstyle{width:250px;}</style></head><body>"); _tableHistoryMgr = new TableHistoryMgr(connectionString); _tableHistoryItemMgr = new TableHistoryItemMgr(connectionString); html.Append("<ul style=\"list-style:none\">"); string channelInfo = ""; int batchIndex = -1; foreach (var batch in batches) { //edit by hufeng0813w Reason:如果是商品對照異動通知 batchIndex++; if (itemType == 1) { channelInfo += "<b>" + batch.channel_name_full + "</b> (外站商品編號:" + batch.channel_detail_id + ")<br/>"; if (batchIndex == 0 || (batches[batchIndex].channel_detail_id == batches[batchIndex - 1].channel_detail_id && batches[batchIndex].channel_name_full == batches[batchIndex].channel_name_full && batches[batchIndex].kdate == batches[batchIndex - 1].kdate) || batchIndex < batches.Count - 1) { continue; } } List<TableHistory> histories = _tableHistoryMgr.Query(new TableHistory { batchno = batch.batchno.ToString() }); if (histories != null && histories.Count > 0) { Array tbls = histories.GroupBy(m => m.table_name).Select(m => m.Key).ToArray(); List<TableHistoryItem> items; uint productId = 0; #region 初始化 StringBuilder pro = new StringBuilder(); StringBuilder spec = new StringBuilder(); StringBuilder category = new StringBuilder(); StringBuilder item = new StringBuilder(); StringBuilder master = new StringBuilder(); StringBuilder price = new StringBuilder(); #endregion foreach (var tbl in tbls) { string tblName = tbl.ToString().ToLower(); bool isAdd = false; #region 針對不同表的處理 switch (tblName) { case "product": #region PRODUCT items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = batch.batchno.ToString(), table_name = tblName }); if (items != null && items.Count > 0) { StringBuilder column_1 = new StringBuilder("<tr><td>欄位名稱</td>"); StringBuilder column_2 = new StringBuilder("<tr><td>修改前</td>"); StringBuilder column_3 = new StringBuilder("<tr><td>修改後</td>"); Array cols = items.GroupBy(m => m.col_name).Select(m => m.Key).ToArray(); foreach (var col in cols) { var tmp = items.FindAll(m => m.col_name == col.ToString()); if (tmp.Count == 1 && string.IsNullOrEmpty(tmp.FirstOrDefault().old_value)) { continue; } else { tmp.Remove(tmp.Find(m => string.IsNullOrEmpty(m.old_value))); var first = tmp.FirstOrDefault(); var last = tmp.LastOrDefault(); if (first == last) { GetParamCon(last, true); } else { GetParamCon(first, true); } GetParamCon(last, false); column_1.AppendFormat("<td>{0}</td>", first.col_chsname); column_2.AppendFormat("<td class=\"red\">{0}</td>", first == last ? last.old_value : first.old_value); column_3.AppendFormat("<td class=\"green\">{0}</td>", last.col_value); isAdd = true; } } if (isAdd) { pro.AppendFormat("<table class=\"tstyle\">{0}</tr>{1}</tr>{2}</tr></table>", column_1, column_2, column_3); } if (productId == 0) { productId = uint.Parse(histories.Find(m => m.table_name == tblName).pk_value); } } #endregion break; case "product_spec": #region SPEC StringBuilder spec_1 = new StringBuilder("<tr><td>修改前</td>"); StringBuilder spec_2 = new StringBuilder("<tr><td>修改後</td>"); Array specIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray(); foreach (var id in specIds) { items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = batch.batchno.ToString(), table_name = tblName, pk_value = id.ToString() }); if (items.Count == 1 && string.IsNullOrEmpty(items.FirstOrDefault().old_value)) { continue; } else { items.Remove(items.Find(m => string.IsNullOrEmpty(m.old_value))); var first = items.FirstOrDefault(); var last = items.LastOrDefault(); spec_1.AppendFormat("<td class=\"red\">{0}</td>", first == last ? last.old_value : first.old_value); spec_2.AppendFormat("<td class=\"green\">{0}</td>", last.col_value); isAdd = true; } } if (isAdd) { spec.AppendFormat("<table class=\"tstyle\">{0}</tr>{1}</tr></table>", spec_1, spec_2); } if (productId == 0) { _productSpecMgr = new ProductSpecMgr(connectionString); ProductSpec pSpec = _productSpecMgr.Query(new ProductSpec { spec_id = uint.Parse(histories.Find(m => m.table_name == tblName).pk_value) }).FirstOrDefault(); if (pSpec != null) { productId = pSpec.product_id; } } #endregion break; case "product_category_set": #region CATEGORY if (productId == 0) { productId = uint.Parse(histories.Find(m => m.table_name.ToLower() == tblName).pk_value); } items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = batch.batchno.ToString(), table_name = tblName, pk_value = productId.ToString() }); if (items.Count > 0) { var first = items.FirstOrDefault(); var last = items.LastOrDefault(); category.Append("<table class=\"tstyle\"><tr><td>修改前</td><td>修改後</td></tr>"); category.AppendFormat("<tr><td class=\"red\">{0}</td>", first == last ? last.old_value : first.old_value); category.AppendFormat("<td class=\"green\">{0}</td></td></table>", last.col_value); } #endregion break; case "product_item": #region ITEM ProductItem pItem; _productItemMgr = new ProductItemMgr(connectionString); Array itemIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray(); foreach (var id in itemIds) { isAdd = false; pItem = _productItemMgr.Query(new ProductItem { Item_Id = uint.Parse(id.ToString()) }).FirstOrDefault(); if (pItem != null) { if (productId == 0) { productId = pItem.Product_Id; } string title = pItem.GetSpecName(); string top = "<div style=\"float:left\"><table class=\"tstyle\"><caption>" + title + "</caption><tr><td>欄位名稱</td><td>修改前</td><td>修改后</td></tr>"; string bottom = "</table></div>"; string strContent = "<tr><td>{0}</td><td class=\"red\">{1}</td><td class=\"green\">{2}</td></tr>"; string content = BuildContent(batch.batchno.ToString(), tblName, id.ToString(), strContent, ref isAdd); if (isAdd) { item.Append(top); item.Append(content); item.Append(bottom); } } } #endregion break; case "price_master": #region PRICE_MASTER PriceMaster pMaster; _priceMasterMgr = new PriceMasterMgr(connectionString); Array masterIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray(); foreach (var id in masterIds) { isAdd = false; pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = uint.Parse(id.ToString()) }).FirstOrDefault(); if (pMaster != null) { if (productId == 0) { productId = pMaster.product_id; } string siteName = QuerySiteName(pMaster.site_id.ToString()); string userLevel = QueryParaName(pMaster.user_level.ToString(), "UserLevel"); string userMail = pMaster.user_id == 0 ? "" : QueryMail(pMaster.user_id.ToString()); string childName = string.Empty; if (pMaster.child_id != 0 && pMaster.product_id != pMaster.child_id) { _productMgr = new ProductMgr(connectionString); Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(pMaster.child_id) }).FirstOrDefault(); if (tmpPro != null) { childName = tmpPro.Product_Name; } } string title = siteName + " + " + userLevel + (string.IsNullOrEmpty(userMail) ? "" : (" + " + userMail)) + (string.IsNullOrEmpty(childName) ? "<br/>" : "<br/>子商品: " + childName); if (!title.Contains("子商品")) { title += "<br/>"; } string top = "<div style=\"float:left\"><table class=\"tstyle\"><caption>" + title + "</caption><tr><td>欄位名稱</td><td>修改前</td><td>修改后</td></tr>"; string bottom = "</table></div>"; string strContent = "<tr><td>{0}</td><td class=\"red\">{1}</td><td class=\"green\">{2}</td></tr>"; string content = BuildContent(batch.batchno.ToString(), tblName, id.ToString(), strContent, ref isAdd); if (isAdd) { master.Append(top); master.Append(content); master.Append(bottom); } } } #endregion break; case "item_price": #region ITEM_PRICE ItemPriceCustom itemPrice; PriceMaster tmpMaster; _itemPriceMgr = new ItemPriceMgr(connectionString); _priceMasterMgr = new PriceMasterMgr(connectionString); Array priceIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray(); foreach (var id in priceIds) { isAdd = false; itemPrice = _itemPriceMgr.Query(new ItemPrice { item_price_id = uint.Parse(id.ToString()) }).FirstOrDefault(); if (itemPrice != null) { tmpMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = itemPrice.price_master_id }).FirstOrDefault(); if (tmpMaster != null) { if (productId == 0) { productId = tmpMaster.product_id; } string siteName = QuerySiteName(tmpMaster.site_id.ToString()); string userLevel = QueryParaName(tmpMaster.user_level.ToString(), "UserLevel"); string userMail = tmpMaster.user_id == 0 ? "" : QueryMail(tmpMaster.user_id.ToString()); string childName = string.Empty; if (tmpMaster.child_id != 0 && tmpMaster.product_id != tmpMaster.child_id) { _productMgr = new ProductMgr(connectionString); Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(tmpMaster.child_id) }).FirstOrDefault(); if (tmpPro != null) { childName = tmpPro.Product_Name; } } string strSpec = itemPrice.spec_name_1 + (string.IsNullOrEmpty(itemPrice.spec_name_2) ? "" : (" + " + itemPrice.spec_name_2)); string title = siteName + " + " + userLevel + (string.IsNullOrEmpty(userMail) ? "" : (" + " + userMail)) + (string.IsNullOrEmpty(childName) ? "<br/>" : "<br/>子商品: " + childName) + "<br/>" + strSpec; if (strSpec == "") { title += "<br/>"; } string top = "<div style=\"float:left\"><table class=\"tstyle\"><caption>" + title + "</caption><tr><td>欄位名稱</td><td>修改前</td><td>修改后</td></tr>"; string bottom = "</table></div>"; string strContent = "<tr><td>{0}</td><td class=\"red\">{1}</td><td class=\"green\">{2}</td></tr>"; string content = BuildContent(batch.batchno.ToString(), tblName, id.ToString(), strContent, ref isAdd); if (isAdd) { price.Append(top); price.Append(content); price.Append(bottom); } } } } #endregion break; default: break; } #endregion } #region 單批次拼接 StringBuilder batchHtml = new StringBuilder(); if (pro.Length > 0) { batchHtml.AppendFormat("<tr><td>商品信息</td><td>{0}</td></tr>", pro); } if (spec.Length > 0) { batchHtml.AppendFormat("<tr><td>規格信息</td><td>{0}</td></tr>", spec); } if (category.Length > 0) { batchHtml.AppendFormat("<tr><td>前臺分類信息</td><td>{0}</td></tr>", category); } if (item.Length > 0) { batchHtml.AppendFormat("<tr><td>商品細項信息</td><td>{0}</td></tr>", item); } if (master.Length > 0) { batchHtml.AppendFormat("<tr><td>站臺商品信息</td><td>{0}</td></tr>", master); } if (price.Length > 0) { batchHtml.AppendFormat("<tr><td>站臺價格信息</td><td>{0}</td></tr>", price); }; if (batchHtml.Length > 0) { _productMgr = new ProductMgr(connectionString); Product product = _productMgr.Query(new Product { Product_Id = productId }).FirstOrDefault(); if (product != null) { string brand = string.Empty; _vendorBrandMgr = new VendorBrandMgr(connectionString); VendorBrand vendorBrand = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Id = product.Brand_Id }); if (vendorBrand != null) { brand = vendorBrand.Brand_Name; } html.AppendFormat("<li><table><tr><td colspan='2'>商品編號:<b>{0}</b> 品牌:<b>{1}</b></td></tr>", productId, brand); html.AppendFormat("<tr><td colspan='2'><b>{0}</b> (修改人:{1}", product.Product_Name, batch.kuser); html.AppendFormat(",修改時間:{0})</td></tr>", batch.kdate.ToString("yyyy/MM/dd HH:mm:ss")); html.Append(batchHtml); if (itemType == 1) { html.AppendFormat("<tr><td colspan='2'>{0}</td></tr>", channelInfo); } html.Append("</table></li>"); } } #endregion } } html.Append("</ul>"); html.Append("</body></html>"); } } catch (Exception) { throw; } return html.ToString(); }
public void PrepareData(List<CombinationExcel> source) { if (source != null) { source.ForEach(m => m.Validate()); var parents = source.Where(m => m.combination.Trim() != "299" && string.IsNullOrEmpty(m.msg)); _productMgr = new ProductMgr(strConn); _productItemMgr = new ProductItemMgr(strConn); _vendorMgr = new VendorMgr(strConn); _vendorBrandMgr = new VendorBrandMgr(strConn); _siteMgr = new SiteMgr(strConn); _productMigrationMgr = new ProductMigrationMgr(strConn); _productComboMgr = new ProductComboMgr(strConn); _cateMgr = new ProductCategoryMgr(strConn); _productCategorySetMgr = new ProductCategorySetMgr(strConn); _productNoticeSetMgr = new ProductNoticeSetMgr(strConn); _productTagSetMgr = new ProductTagSetMgr(strConn); _productPictureMgr = new ProductPictureMgr(strConn); _productStatusHistoryMgr = new ProductStatusHistoryMgr(strConn); foreach (var parent in parents) { form.change(1); uint product_id = uint.Parse(parent.product_id); #region Product ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = parent.is_exist.ToUpper().Trim().Equals("OLD") ? parent.product_id : parent.temp_id }); if (prodMigra != null) { parent.msg = "此記錄暫時編號(temp_id)已經存在;"; continue; } Product newPro = parent.is_exist.ToUpper().Trim() == "OLD" ? _productMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault() : new Product(); if (newPro == null) { parent.msg = "商品不存在"; continue; } newPro.Product_Name = parent.product_name.Trim(); VendorBrand brand = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Name = parent.brand_name.Trim() }); if (brand == null) { parent.msg = "品牌不存在"; continue; } newPro.Brand_Id = brand.Brand_Id; switch (parent.combination.Trim()) { case "2": newPro.Combination = 2; break; case "3": newPro.Combination = 3; break; case "4": newPro.Combination = 4; break; default: break; } switch (parent.status.Trim().ToUpper()) { case "SAME": break; case "ON": newPro.Product_Status = 5; break; case "OFF": newPro.Product_Status = 6; break; case "NEW": newPro.Product_Status = 0; break; default: break; } newPro.Price_type = 1; newPro.Product_Spec = 0; newPro.Spec_Title_1 = string.Empty; newPro.Spec_Title_2 = string.Empty; newPro.Ignore_Stock = 0;// parent.ignore_stock.ToUpper().Trim() == "Y" ? 1 : 0; newPro.Shortage = 0;// parent.shortage.ToUpper().Trim() == "Y" ? 1 : 0; newPro.Cate_Id = parent.cate_id.Trim(); var vendor = _vendorMgr.GetSingle(new Vendor { vendor_id = brand.Vendor_Id }); if (vendor == null) { parent.msg = "供應商不存在"; continue; } newPro.user_id = vendor.product_manage; if (!string.IsNullOrEmpty(parent.service_fee)) { uint bag_check_money=0; uint.TryParse(parent.service_fee,out bag_check_money); newPro.Bag_Check_Money = bag_check_money; } #endregion bool result = true; ArrayList sqls = new ArrayList(); #region PriceMaster Site site = _siteMgr.Query(new Site { Site_Name = parent.site.Trim() }).FirstOrDefault(); if (site == null) { parent.msg = "價格檔站臺不存在"; result = false; break; } List<PriceMaster> priceMasters = new List<PriceMaster>(); //首先默認加入一筆吉甲地站臺 PriceMaster newPriceMaster = new PriceMaster { site_id = 1, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 }; newPriceMaster.product_name = newPro.Product_Name; newPriceMaster.price_status = 1; var item = _productItemMgr.Query(new ProductItem { Product_Id = newPro.Product_Id }).FirstOrDefault(); if (item == null) { parent.msg = "商品細項不存在"; continue; } #region 成本 int cost = 0; if (!string.IsNullOrEmpty(parent.cost)) { int.TryParse(parent.cost, out cost); } else { cost = Convert.ToInt32(item.Item_Cost); } newPriceMaster.cost = cost; #endregion #region 售價 int price = 0; if (!string.IsNullOrEmpty(parent.price)) { int.TryParse(parent.price, out price); } else { price = Convert.ToInt32(item.Item_Money); } newPriceMaster.price = price; #endregion newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money); newPriceMaster.event_start = item.Event_Product_Start; newPriceMaster.event_end = item.Event_Product_End; priceMasters.Add(newPriceMaster); if (site.Site_Id != 1) { //如果站臺不是吉甲地就把吉甲地站臺的價格狀態改為4(下架) priceMasters[0].price_status = 4; //再加入非吉甲地站臺 newPriceMaster = new PriceMaster { site_id = site.Site_Id, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 }; newPriceMaster.product_name = newPro.Product_Name; newPriceMaster.price_status = 1; #region 成本 cost = 0; if (!string.IsNullOrEmpty(parent.cost)) { int.TryParse(parent.cost, out cost); } else { cost = Convert.ToInt32(item.Item_Cost); } newPriceMaster.cost = cost; #endregion #region 售價 price = 0; if (!string.IsNullOrEmpty(parent.price)) { int.TryParse(parent.price, out price); } else { price = Convert.ToInt32(item.Item_Money); } newPriceMaster.price = price; #endregion newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money); newPriceMaster.event_start = item.Event_Product_Start; newPriceMaster.event_end = item.Event_Product_End; priceMasters.Add(newPriceMaster); } #region 其他站臺價格 var child = source.Where(m => m.combination.Trim() == "299" && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim() && string.IsNullOrEmpty(m.msg) && m.new_old.ToUpper().Trim() == "NEW" && m.formula.ToUpper().Trim().StartsWith("P")); if (child != null) { foreach (var c in child) { item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault(); if (item == null) { c.msg = "價格檔商品細項不存在"; result = false; break; } site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault(); if (site == null) { c.msg = "站臺不存在"; result = false; break; } if (priceMasters.Exists(m => m.site_id == site.Site_Id)) { c.msg = "站臺重複"; result = false; break; } newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 }; newPriceMaster.product_name = c.product_name.Trim(); newPriceMaster.site_id = site.Site_Id; newPriceMaster.price_status = 1; #region 成本 cost = 0; if (!string.IsNullOrEmpty(c.cost)) { int.TryParse(c.cost, out cost); } else { cost = Convert.ToInt32(item.Item_Cost); } newPriceMaster.cost = cost; #endregion #region 售價 price = 0; if (!string.IsNullOrEmpty(c.price)) { int.TryParse(c.price, out price); } else { price = Convert.ToInt32(item.Item_Money); } newPriceMaster.price = price; #endregion newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money); newPriceMaster.event_start = item.Event_Product_Start; newPriceMaster.event_end = item.Event_Product_End; priceMasters.Add(newPriceMaster); if (site.Site_Name.Trim().ToLower() == "chinatrust") { ArrayList category_set = CategorySet(c, brand.Brand_Id); if (category_set == null) { result = false; break; } else { sqls.AddRange(category_set); } } } if (!result) continue; } #endregion #endregion #region ProductCombo string[] strIds = parent.formula.IndexOf(",") != -1 ? parent.formula.Trim().Split(',') : new string[] { parent.formula.Trim() }; string[] nums = parent.number.IndexOf(",") != -1 ? parent.number.Trim().Split(',') : new string[] { parent.number.Trim() }; List<Product> children = new List<Product>(); ProductCombo tmp; for (int i = 0; i < strIds.Length; i++) { tmp = new ProductCombo(); if (parent.combination.Trim() != "2") { tmp.Buy_Limit = parent.buylimit.Trim().ToUpper() == "Y" ? 1 : 0; } else { tmp.S_Must_Buy = int.Parse(i >= nums.Length ? nums[nums.Length - 1] : nums[i]); } if (parent.combination.Trim() == "3")//為3任選時 數量為G_Must_Buy { tmp.G_Must_Buy = int.Parse(nums[0]); } switch (parent.new_old.Trim().ToUpper()) { case "NEW": var map = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] }); if (map == null) { parent.msg = "原料編號未找到對應"; break; } tmp.Child_Id = Convert.ToInt32(map.product_id); break; case "OLD": tmp.Child_Id = int.Parse(strIds[i]); break; case "BOTH": if (strIds[i].ToUpper().Trim().StartsWith("P")) { var tMap = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] }); if (tMap == null) { parent.msg = "原料編號未找到對應"; break; } tmp.Child_Id = Convert.ToInt32(tMap.product_id); } else { tmp.Child_Id = int.Parse(strIds[i]); } break; } if (tmp.Child_Id == 0) { result = false; break; } else { Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(tmp.Child_Id) }).FirstOrDefault(); if (tmpPro == null) { parent.msg = strIds[i] + "不存在"; result = false; break; } if (tmpPro.Product_Status == 0 || tmpPro.Product_Status ==1) { parent.msg = strIds[i] + "商品状态不為新增、申請審核"; result = false; break; } if (tmpPro.Combination != 0 && tmpPro.Combination != 1) { parent.msg = strIds[i] + "不是單一商品"; result = false; break; } switch (newPro.Product_Freight_Set) { case 1: case 3: if (tmpPro.Product_Freight_Set != 1 && tmpPro.Product_Freight_Set != 3) { parent.msg = strIds[i] + "运费模式与主商品不匹配"; result = false; } break; case 2: case 4: if (tmpPro.Product_Freight_Set != 2 && tmpPro.Product_Freight_Set != 4) { parent.msg = strIds[i] + "运费模式与主商品不匹配"; result = false; } break; case 5: case 6: if (tmpPro.Product_Freight_Set != 5 && tmpPro.Product_Freight_Set != 6) { parent.msg = strIds[i] + "运费模式与主商品不匹配"; result = false; } break; default: break; } if (!result) break; children.Add(tmpPro); } sqls.Add(_productComboMgr.Save(tmp)); } if (!result) continue; #endregion #region product_category_set if (!string.IsNullOrEmpty(parent.display)) { ArrayList category_set = CategorySet(parent, brand.Brand_Id); if (category_set == null) continue; else { foreach (var set in category_set) { if (!sqls.Contains(set)) { sqls.Add(set); } } } } else { sqls.Add(_productCategorySetMgr.SaveFromOtherPro(new ProductCategorySet { Product_Id = product_id })); } #endregion #region product_migration_map ProductMigrationMap pMap = new ProductMigrationMap(); if (parent.is_exist.ToUpper().Equals("OLD")) { pMap.temp_id = parent.product_id; } else if (parent.is_exist.ToUpper().Equals("NEW")) { pMap.temp_id = parent.temp_id; } sqls.Add(_productMigrationMgr.SaveNoPrid(pMap)); #endregion #region notice tag picture sqls.Add(_productNoticeSetMgr.SaveFromOtherPro(new ProductNoticeSet { product_id = product_id })); sqls.Add(_productTagSetMgr.SaveFromOtherPro(new ProductTagSet { product_id = product_id })); sqls.Add(_productPictureMgr.SaveFromOtherPro(new ProductPicture { product_id = Convert.ToInt32(product_id) })); sqls.Add(_productStatusHistoryMgr.SaveNoProductId(new ProductStatusHistory { type = 7, product_status = Convert.ToInt32(newPro.Product_Status) })); #endregion string str = string.Empty; if (_productMgr.ProductMigration(newPro, priceMasters, null, null, sqls, null)) { str = "匯入成功"; } else { str = "保存至數據庫失敗"; } parent.msg = str; source.FindAll(m => m.combination.Trim() == "299" && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim() && string.IsNullOrEmpty(m.msg) && m.new_old.ToUpper().Trim() == "NEW" && m.formula.ToUpper().Trim().StartsWith("P")).ForEach(m => m.msg = str); } #region 其他站臺價格 var pChild = source.Where(m => m.combination.Trim() == "299" && m.new_old.ToUpper().Trim() == "OLD" && string.IsNullOrEmpty(m.msg)); if (pChild != null) { ProductItem item; PriceMaster newPriceMaster; Site site; _priceMasterMgr = new PriceMasterMgr(strConn); foreach (var c in pChild) { ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = c.formula.Trim() }); if (prodMigra == null) { c.msg = "原料編號對照不存在"; continue; } item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault(); if (item == null) { c.msg = "價格檔商品細項不存在"; continue; } site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault(); if (site == null) { c.msg = "站臺不存在"; continue; } newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 }; newPriceMaster.product_name = c.product_name.Trim(); newPriceMaster.product_id = prodMigra.product_id; newPriceMaster.child_id = Convert.ToInt32(prodMigra.product_id); newPriceMaster.site_id = site.Site_Id; newPriceMaster.price_status = 1; #region 成本 int cost = 0; if (!string.IsNullOrEmpty(c.cost)) { int.TryParse(c.cost, out cost); } else { cost = Convert.ToInt32(item.Item_Cost); } newPriceMaster.cost = cost; #endregion #region 售價 int price = 0; if (!string.IsNullOrEmpty(c.price)) { int.TryParse(c.price, out price); } else { price = Convert.ToInt32(item.Item_Money); } newPriceMaster.price = price; #endregion newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money); newPriceMaster.event_start = item.Event_Product_Start; newPriceMaster.event_end = item.Event_Product_End; ArrayList category_set = new ArrayList(); if (site.Site_Name.Trim().ToLower() == "chinatrust") { Product pro= _productMgr.Query(new Product { Product_Id = item.Product_Id }).FirstOrDefault(); if (pro == null) { c.msg = "商品不存在"; continue; } #region 更新該站臺商品的 product_category_set bool result = true; System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex("^[0-9]*$"); string[] cateArray = c.display.Split(','); foreach (string strcate in cateArray) { if (!string.IsNullOrEmpty(strcate)) { if (regx.IsMatch(strcate)) { ProductCategory query = _cateMgr.QueryAll(new ProductCategory { category_id = uint.Parse(strcate) }).FirstOrDefault(); if (query == null || strcate.Equals("0")) { c.msg = "display:" + strcate + " 不存在;"; result = false; break; } else { ProductCategorySet category = new ProductCategorySet { Brand_Id = pro.Brand_Id, Category_Id = uint.Parse(strcate), Product_Id = prodMigra.product_id }; if (_productCategorySetMgr.Query(category).FirstOrDefault() == null) { category_set.Add(_productCategorySetMgr.Save(category)); } else { c.msg = "display:" + strcate + " 已存在;"; result = false; break; } } } else { c.msg = "display:" + strcate + " 格式不正確 "; result = false; break; } } } if (!result) continue; #endregion } string str = string.Empty; if (_priceMasterMgr.Save(newPriceMaster, null, category_set, ref str) > 0) { c.msg = "匯入成功"; } else { c.msg = string.IsNullOrEmpty(str) ? "保存至數據庫失敗" : str; } } } #endregion } }