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 ProductItemMapExcelMgr(string connectionString) { _productItemMapMgr = new ProductItemMapMgr(connectionString); _productItemMapDao = new ProductItemMapDao(connectionString); _productItemMgr = new ProductItemMgr(connectionString); _productItemDao = new ProductItemDao(connectionString); _callerMgr = new CallerMgr(connectionString); _priceMasterMgr = new PriceMasterMgr(connectionString); _access = DBAccess.DBFactory.getDBAccess(DBType.MySql, connectionString); }
//根據upcid獲取item_id public HttpResponseBase GetItemidByUpcid() { string json = string.Empty; _IiupcMgr = new IupcMgr(mySqlConnectionString); _iproductitemMgr = new ProductItemMgr(mySqlConnectionString); Iupc m = new Iupc(); DataTable dt = new DataTable(); bool isUpc = true; try { //獲取條碼 if (!string.IsNullOrEmpty(Request.Params["upc_id"])) { m.upc_id = Request.Params["upc_id"].ToString().Trim(); //6位整數時先判斷輸入的是否為item_id Regex reg = new Regex("^\\d{6}$"); if (reg.IsMatch(m.upc_id)) { ProductItemQuery query = new ProductItemQuery(); query.Item_Id = Convert.ToUInt32(m.upc_id); List<ProductItemQuery> store = _iproductitemMgr.GetProductItemByID(query); if (store.Count == 0) { isUpc = true; } else if (store.Count > 1) { isUpc = true; } else { json = "{success:true,msg:1,itemid:" + query.Item_Id + "}"; isUpc = false; } } if (isUpc) { dt = _IiupcMgr.upcid(m); if (dt.Rows.Count == 0) { json = "{success:false,msg:0}"; } else if (dt.Rows.Count > 1) { json = "{success:false,msg:2}"; } else { json = "{success:true,msg:1,itemid:" + dt.Rows[0]["item_id"].ToString() + "}"; } } } } 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); json = "{success:false}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 商品點擊信息列表 /// </summary> /// <returns></returns> public HttpResponseBase BrowseDataList() { string json = string.Empty; DataTable dtBrowseData = new DataTable(); int totalCount = 0; BrowseDataQuery query = new BrowseDataQuery(); string type=Request.Params["type"]; string searchContent = Request.Params["searchContent"]; if (!string.IsNullOrEmpty(type)) { query.type = Convert.ToInt32(type); } if (!string.IsNullOrEmpty(searchContent)) { query.SearchCondition = searchContent; } if (!string.IsNullOrEmpty(Request.Params["true"])) { if (Request.Params["true"] == "true") { query.isSecret = true; } else { query.isSecret = false; } } if (!string.IsNullOrEmpty(Request.Params["searchType"])) { query.SearchType = Convert.ToInt32(Request.Params["searchType"]); } query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25"); _IBrowseDataMgr = new BrowseDataMgr(mySqlConnectionString); _IProductItemMgr=new ProductItemMgr(mySqlConnectionString); _IOrderMasterMgr = new OrderMasterMgr(mySqlConnectionString); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; try { dtBrowseData = _IBrowseDataMgr.GetBrowseDataList(query, out totalCount); if (dtBrowseData.Rows.Count>0) { dtBrowseData.Columns.Add("buyCount"); for (int i = 0; i < dtBrowseData.Rows.Count; i++) { string user_id = dtBrowseData.Rows[i]["user_id"].ToString(); string product_id = dtBrowseData.Rows[i]["product_id"].ToString(); string item_id = string.Empty; if (query.isSecret) { dtBrowseData.Rows[i]["user_name"] = dtBrowseData.Rows[i]["user_name"].ToString().Substring(0, 1) + "**"; } List<ProductItem> listProductItem = _IProductItemMgr.GetProductItemByID(Convert.ToInt32(product_id)); if (listProductItem.Count > 0) { item_id = listProductItem[0].Item_Id.ToString(); } OrderMasterQuery orderMasterQuery = new OrderMasterQuery { User_Id = Convert.ToUInt32(dtBrowseData.Rows[i]["user_id"]), Item_Id = Convert.ToInt32(item_id) }; dtBrowseData.Rows[i]["buyCount"] = _IOrderMasterMgr.GetBuyCount(orderMasterQuery); } json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(dtBrowseData, Formatting.Indented, timeConverter) + "}"; } else { json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(dtBrowseData, Formatting.Indented, timeConverter) + "}"; //json = "{success:false,msg:0}"; } } 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); json = "{success:false,msg:0}"; } this.Response.Clear(); this.Response.Write(json); 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 } }
public string ComboPriceSave() { string json = "{success:true}"; if (!PriceMaster.CheckProdName(Request.Form["product_name"])) { return "{success:false,msg:'" + Resources.Product.FORBIDDEN_CHARACTER + "'}"; } ProductTemp pTemp = new ProductTemp(); List<PriceMasterTemp> pMasterListT = new List<PriceMasterTemp>(); List<PriceMaster> pMasterList = new List<PriceMaster>(); List<List<ItemPrice>> ItemPList = new List<List<ItemPrice>>(); PriceMasterTemp pMasterTemp = new PriceMasterTemp(); if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { pTemp.Product_Id = Request.Form["OldProductId"]; pMasterTemp.product_id = Request.Form["OldProductId"]; } string paramValue = Request.Params["paramValue"]; #region 參數 int writer_id = (Session["caller"] as Caller).user_id; string product_name = PriceMaster.Product_Name_FM(Request.Params["product_name"]); string price_type = Request.Params["price_type"]; string product_price_list = Request.Params["product_price_list"]; string default_bonus_percent = Request.Params["default_bonus_percent"]; string price = Request.Params["price"]; string cost = Request.Params["cost"]; string max_price = Request.Params["max_price"]; string bonus_percent = Request.Params["bonus_percent"]; string event_price = Request.Params["event_price"]; string event_cost = Request.Params["event_cost"]; string max_event_price = Request.Params["max_event_price"]; string event_start = Request.Params["event_start"]; string event_end = Request.Params["event_end"]; string site_id = Request.Params["site_id"]; string user_level = Request.Params["user_level"]; string user_mail = Request.Params["user_mail"]; string bag_check_money = Request.Params["bag_check_money"] == "" ? "0" : Request.Params["bag_check_money"]; string accumulated_bonus = Request.Params["accumulated_bonus"]; string bonus_percent_start = Request.Params["bonus_percent_start"]; string bonus_percent_end = Request.Params["bonus_percent_end"]; string same_price = Request.Params["same_price"]; string show_listprice = Request.Params["show_listprice"]; string valid_start = Request.Params["valid_start"]; string valid_end = Request.Params["valid_end"]; #endregion List<MakePriceCustom> PriceStore = new List<MakePriceCustom>(); if (price_type == "2")//各自定價 { JavaScriptSerializer jss = new JavaScriptSerializer(); string priceStr = Request.Params["priceStr"]; PriceStore = jss.Deserialize<List<MakePriceCustom>>(priceStr); } if (!string.IsNullOrEmpty(Request.Params["product_id"])) { #region 正式表操作 List<PriceMaster> pMList = new List<PriceMaster>(); //插入price_master _priceMasterMgr = new PriceMasterMgr(connectionString); _priceMasterTsMgr = new PriceMasterTsMgr(connectionString); PriceMaster pMaster = new PriceMaster(); //查詢price_master if (!string.IsNullOrEmpty(Request.Params["price_master_id"])) { pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = uint.Parse(Request.Params["price_master_id"]) }).FirstOrDefault(); } pMaster.product_id = uint.Parse(Request.Params["product_id"]); pMaster.child_id = int.Parse(Request.Params["product_id"]); pMaster.site_id = uint.Parse(site_id); uint userId = 0; if (!string.IsNullOrEmpty(Request.Form["user_mail"])) { _usersMgr = new UsersMgr(connectionString); System.Data.DataTable dt_User = _usersMgr.Query(Request.Form["user_mail"]); if (dt_User != null && dt_User.Rows.Count > 0) { userId = Convert.ToUInt32(dt_User.Rows[0]["user_id"]); } } if (userId != 0) { pMaster.user_id = userId; } if (user_level != "") { pMaster.user_level = uint.Parse(user_level); } pMaster.product_name = product_name; pMaster.bonus_percent = float.Parse(bonus_percent); pMaster.cost = int.Parse(cost); pMaster.price = int.Parse(price); pMaster.max_price = int.Parse(max_price); pMaster.max_event_price = int.Parse(max_event_price); pMaster.default_bonus_percent = float.Parse(default_bonus_percent); pMaster.event_price = int.Parse(event_price); pMaster.event_cost = int.Parse(event_cost); pMaster.same_price = int.Parse(same_price); pMaster.price_status = 2;//申請審核 pMaster.accumulated_bonus = uint.Parse(accumulated_bonus); #region 時間 活動時間 if (event_start != "") { pMaster.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(event_start)); } if (event_end != "") { pMaster.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(event_end)); } if (bonus_percent_start != "") { pMaster.bonus_percent_start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_start)); } if (bonus_percent_end != "") { pMaster.bonus_percent_end = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_end)); } if (!string.IsNullOrEmpty(valid_start)) { pMaster.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start)); } if (!string.IsNullOrEmpty(valid_end)) { pMaster.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end)); } #endregion _functionMgr = new FunctionMgr(connectionString); string function = Request.Params["function"] ?? ""; Function fun = _functionMgr.QueryFunction(function, "/ProductCombo"); int functionid = fun == null ? 0 : fun.RowId; HistoryBatch batch = new HistoryBatch { functionid = functionid }; batch.batchno = Request.Params["batch"] ?? ""; batch.kuser = (Session["caller"] as Caller).user_email; List<ItemPrice> update = new List<ItemPrice>(); if (price_type == "2") //各自定價 { CreateList(PriceStore, pMaster, null, same_price, ItemPList, pMasterListT, pMasterList, update); } pMasterList.Add(pMaster); try { //價格修改 申請審核 PriceUpdateApply priceUpdateApply = new PriceUpdateApply(); priceUpdateApply.apply_user = Convert.ToUInt32((Session["caller"] as Caller).user_id); //價格審核記錄 PriceUpdateApplyHistory applyHistroy = new PriceUpdateApplyHistory(); applyHistroy.user_id = Convert.ToInt32(priceUpdateApply.apply_user); applyHistroy.price_status = 1; //applyHistroy.type = 3; applyHistroy.type = 1;//edit by wwei0216w 所作操作為 1:申請審核的操作 _priceUpdateApplyMgr = new PriceUpdateApplyMgr(connectionString); _priceUpdateApplyHistoryMgr = new PriceUpdateApplyHistoryMgr(connectionString); _tableHistoryMgr = new TableHistoryMgr(connectionString); ArrayList excuteSql = new ArrayList(); if (!string.IsNullOrEmpty(Request.Params["price_master_id"])) { #region 修改 priceUpdateApply.price_master_id = pMaster.price_master_id; PriceMaster priceMster = _priceMasterMgr.QueryPMaster(new PriceMaster() { site_id = uint.Parse(site_id), user_level = uint.Parse(user_level == "" ? "0" : user_level), user_id = userId, product_id = uint.Parse(Request.Params["product_id"]), price_master_id = uint.Parse(Request.Params["price_master_id"]) }); //更新price_master if (priceMster != null) { json = "{success:true,msg:'" + Resources.Product.SITE_EXIST + "'}"; } else { int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply); if (apply_id != -1) { bool flag = false; foreach (var item in pMasterList) { item.apply_id = (uint)apply_id; excuteSql = new ArrayList(); if (item == pMaster) { pMaster.apply_id = Convert.ToUInt32(apply_id); applyHistroy.apply_id = apply_id; excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); } //excuteSql.Add(_priceMasterMgr.Update(item)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(item));//edit by xiangwang0413w 2014/07/16 將數據更新到pirce_master_ts表 flag = _tableHistoryMgr.SaveHistory<PriceMaster>(item, batch, excuteSql); } if (flag) { //更新item_price //_itemPriceMgr = new ItemPriceMgr(""); _itemPriceTsMgr = new ItemPriceTsMgr(connectionString); foreach (var iPrice in update) { iPrice.apply_id = (uint)apply_id; excuteSql = new ArrayList(); //excuteSql.Add(_itemPriceMgr.Update(iPrice)); excuteSql.Add(_itemPriceTsMgr.UpdateTs(iPrice));//edit by xiangwang0413w 2014/07/17 將數據更新到pirce_master_ts表 if (!_tableHistoryMgr.SaveHistory<ItemPrice>(iPrice, batch, excuteSql)) { json = "{success:true,msg:'" + Resources.Product.EDIT_FAIL + "'}"; } } json = "{success:true,msg:'" + Resources.Product.EDIT_SUCCESS + "'}"; } else { json = "{success:true,msg:'" + Resources.Product.EDIT_FAIL + "'}"; } } else { json = "{success:true,msg:'" + Resources.Product.EDIT_FAIL + "'}"; } } #endregion } else { #region 新增 string msg = string.Empty; int status = 0; List<ItemPrice> iprice = (ItemPList == null || ItemPList.Count == 0) ? null : ItemPList[pMasterList.IndexOf(pMaster)]; int priceMasterId = _priceMasterMgr.Save(pMaster, iprice, null, ref msg); if (priceMasterId != -1) { priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId); int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply); if (apply_id != -1) { pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); pMaster.apply_id = Convert.ToUInt32(apply_id); excuteSql.Add(_priceMasterMgr.Update(pMaster)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(pMaster)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核 foreach (var item in pMasterList.FindAll(m => m.product_id != m.child_id)) { iprice = (ItemPList == null || ItemPList.Count == 0) ? null : ItemPList[pMasterList.IndexOf(item)]; priceMasterId = _priceMasterMgr.Save(item, iprice, null, ref msg); pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); if (priceMasterId != -1) { priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId); pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); pMaster.apply_id = Convert.ToUInt32(apply_id); excuteSql.Add(_priceMasterMgr.Update(pMaster)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(pMaster)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核 } else { status = 2; } } } else { status = 3; } } else { status = 3; } excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); _tableHistoryMgr = new TableHistoryMgr(connectionString); if (_tableHistoryMgr.SaveHistory<PriceMaster>(pMaster, batch, excuteSql)) { status = 1; } else { status = 2; } //foreach (var item in pMasterList) //{ // List<ItemPrice> iprice = (ItemPList == null || ItemPList.Count == 0) ? null : ItemPList[pMasterList.IndexOf(item)]; // int priceMasterId = _priceMasterMgr.Save(item, iprice, null, ref msg); // if (apply_id != -1) // { // pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); // } // if (priceMasterId != -1) // { // if (item != pMaster) { status = 1; continue; } // priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId); // int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply); // if (apply_id != -1) // { // pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); // pMaster.apply_id = Convert.ToUInt32(apply_id); // applyHistroy.apply_id = apply_id; // excuteSql.Add(_priceMasterMgr.Update(pMaster)); // excuteSql.Add(_priceMasterTsMgr.UpdateTs(pMaster)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核 // excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); // _tableHistoryMgr = new TableHistoryMgr(connectionString); // if (_tableHistoryMgr.SaveHistory<PriceMaster>(pMaster, batch, excuteSql)) // { // status = 1; // } // else { status = 2; } // } // else { status = 2; } // } // else { status = 3; } //} if (status == 1) { json = "{success:true,msg:'" + Resources.Product.ADD_SUCCESS + "'}"; } else if (status == 2) { json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } else { json = "{success:false,msg:'" + msg + "'}"; } #endregion } } 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); json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } #endregion } else { #region 新增至臨時表 try { _productTempMgr = new ProductTempMgr(connectionString); _pMasterTempMgr = new PriceMasterTempMgr(connectionString); //product_temp pTemp.Product_Price_List = uint.Parse(product_price_list); pTemp.Writer_Id = writer_id; pTemp.Combo_Type = COMBO_TYPE; pTemp.Price_type = int.Parse(price_type); pTemp.Bag_Check_Money = uint.Parse(bag_check_money); pTemp.show_listprice = uint.Parse(show_listprice); pTemp.Bonus_Percent = float.Parse(bonus_percent); pTemp.Default_Bonus_Percent = float.Parse(default_bonus_percent); //Price_Master pMasterTemp.product_name = product_name; ; pMasterTemp.default_bonus_percent = float.Parse(default_bonus_percent); pMasterTemp.writer_Id = writer_id; pMasterTemp.combo_type = COMBO_TYPE; //默認站臺1:吉甲地,(按統一價格比例拆分)會員等級1:普通會員 pMasterTemp.site_id = 1; pMasterTemp.user_level = 1; pMasterTemp.same_price = int.Parse(same_price); pMasterTemp.accumulated_bonus = uint.Parse(accumulated_bonus); pMasterTemp.bonus_percent = float.Parse(bonus_percent); pMasterTemp.price = int.Parse(price); pMasterTemp.cost = int.Parse(cost); pMasterTemp.max_price = int.Parse(max_price); pMasterTemp.max_event_price = int.Parse(max_event_price); pMasterTemp.event_price = int.Parse(event_price); pMasterTemp.event_cost = int.Parse(event_cost); #region 時間 活動時間 if (event_start != "") { pMasterTemp.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(event_start)); } if (event_end != "") { pMasterTemp.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(event_end)); } if (bonus_percent_start != "") { pMasterTemp.bonus_percent_start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_start)); pTemp.Bonus_Percent_Start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_start)); } if (bonus_percent_end != "") { pMasterTemp.bonus_percent_end = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_end)); pTemp.Bonus_Percent_End = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_end)); } if (!string.IsNullOrEmpty(valid_start)) { pMasterTemp.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start)); } if (!string.IsNullOrEmpty(valid_end)) { pMasterTemp.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end)); } #endregion pMasterTemp.price_status = 1; _productItemMgr = new ProductItemMgr(connectionString); string oldProductId = "0"; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { oldProductId = Request.Form["OldProductId"]; } List<ItemPrice> update = new List<ItemPrice>(); if (price_type == "2") { _combTempMgr = new ProductComboTempMgr(connectionString); List<ProductComboCustom> combResultList = _combTempMgr.priceComboQuery(new ProductComboCustom { Writer_Id = writer_id, Parent_Id = int.Parse(oldProductId.ToString()) }); bool match = true; if (combResultList.Count() > 0) { int countBySearchPile = combResultList.GroupBy(m => m.Pile_Id).Count(); //庫中原有價格數據 int countByStorePile = PriceStore.GroupBy(m => m.Pile_Id).Count(); //頁面store數據 //判斷群組數量是否相同 if (countBySearchPile == countByStorePile) { for (int i = 1; i <= countBySearchPile; i++) { //組合類型為固定或任選時pile_id為0; var tempSearch = combResultList.Where(m => m.Pile_Id == (combResultList[0].Pile_Id == 0 ? 0 : i)).ToList().GroupBy(m => m.Child_Id).ToList(); var tempPrice = PriceStore.Where(m => m.Pile_Id == (combResultList[0].Pile_Id == 0 ? 0 : i)).ToList().GroupBy(m => m.Child_Id).ToList(); //判斷當前組中子商品的數量是否相同 if (tempSearch.Count() == tempPrice.Count()) { foreach (var item in tempPrice) { if (tempSearch.Where(m => m.Key == item.Key.ToString()).ToList().Count() <= 0)//edit 2014/09/24 { match = false; break; } } } else { match = false; break; } } } else { match = false; } } else { match = false; } if (!match) { _combTempMgr = new ProductComboTempMgr(connectionString); _combTempMgr.comboPriceDelete(new ProductComboTemp { Writer_Id = writer_id, Combo_Type = COMBO_TYPE, Parent_Id = oldProductId }); PriceStore.ForEach(rec => rec.price_master_id = 0); } CreateList(PriceStore, null, pMasterTemp, same_price, ItemPList, pMasterListT, pMasterList, update); } pMasterListT.Add(pMasterTemp); //如果原價格為複製價格,則需刪除原複製價格並將child_id設為oldProductId if (oldProductId != "0") { pMasterListT.ForEach(m => { if (m.child_id == "0") { m.child_id = oldProductId; } }); } //查詢 PriceMasterProductCustom queryReust = _pMasterTempMgr.Query(new PriceMasterTemp() { writer_Id = writer_id, child_id = oldProductId, product_id = oldProductId, combo_type = COMBO_TYPE }); //檢查價格類型是否有變動,如果有則刪除原有價格數據 if (queryReust != null) { if (!price_type.Equals(queryReust.price_type.ToString())) { _combTempMgr = new ProductComboTempMgr(connectionString); _combTempMgr.comboPriceDelete(new ProductComboTemp { Writer_Id = writer_id, Combo_Type = COMBO_TYPE, Parent_Id = oldProductId.ToString() }); queryReust = null; } } if (queryReust == null)//插入 { if (price_type == "1") { _pMasterTempMgr.Save(pMasterListT, null, null); } else { _pMasterTempMgr.Save(pMasterListT, ItemPList, null); } } else//更新 { if (price_type == "1") { _pMasterTempMgr.Update(pMasterListT, null); } else { _pMasterTempMgr.Update(pMasterListT, update); } } _productTempMgr.PriceBonusInfoSave(pTemp); } 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); json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } #endregion } return json; }
public string QueryStock() { string json = string.Empty; if (string.IsNullOrEmpty(Request.Params["product_id"])) { //查找臨時表是否有記錄 _productItemTempMgr = new ProductItemTempMgr(connectionString); int writeId = (Session["caller"] as Caller).user_id; ProductItemTemp query = new ProductItemTemp { Writer_Id = writeId }; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { query.Product_Id = Request.Form["OldProductId"]; } json = _productItemTempMgr.QueryStock(query); } else { //從正式表讀取數據 _productItemMgr = new ProductItemMgr(connectionString); ProductItem pItem = new ProductItem(); pItem.Product_Id = uint.Parse(Request.Params["product_id"]); _productItemMgr.Query(pItem); json = _productItemMgr.QueryStock(pItem); } return json; }
//RF直接庫調 public HttpResponseBase RFKT() { string json = string.Empty; IialgQuery q = new IialgQuery(); uint id = 0; DateTime dt = new DateTime(); int sun = 0; _proditemMgr = new ProductItemMgr(mySqlConnectionString); ProductItem Proitems = new ProductItem(); try { if (uint.TryParse(Request.Params["item_id"].ToString(), out id)) {//商品id q.item_id = id; Proitems.Item_Id = id; } if (DateTime.TryParse(Request.Params["made_date"].ToString(), out dt)) {//商品製造日期 q.made_dt = dt; } if (int.TryParse(Request.Params["prod_qty"].ToString(), out sun)) {//商品原有數量 q.qty_o = sun; } if (int.TryParse(Request.Params["pnum"].ToString(), out sun)) {//商品撿貨數量 q.pnum = sun; } if (!string.IsNullOrEmpty(Request.Params["loc_id"].ToString())) {//商品撿貨數量 q.loc_id = Request.Params["loc_id"]; } if (!string.IsNullOrEmpty(Request.Params["order_id"])) { q.order_id = Request.Params["order_id"]; } q.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; //進行庫調 _iagMgr = new IialgMgr(mySqlConnectionString); Caller call = new Caller(); call = (System.Web.HttpContext.Current.Session["caller"] as Caller); string path = "/WareHouse/KutiaoAddorReduce"; if (q.loc_id == "YY999999") { json = "{success:false}"; } else { Proitems.Item_Stock = q.pnum - q.qty_o; int result = _iagMgr.addIialgIstock(q); if (result == 2) { json = "{success:true,msg:2}"; } if (result == 100) { _proditemMgr.UpdateItemStock(Proitems, path, call); json = "{success:true,msg:100}"; } } } 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); json = "{success:false}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
// 更新表Iinvd庫存鎖的狀態 public JsonResult UpdateIinvdActive() { string jsonStr = string.Empty; try { _iinvd = new IinvdMgr(mySqlConnectionString); Iinvd nvd = new Iinvd(); IialgQuery q = new IialgQuery(); _iagMgr = new IialgMgr(mySqlConnectionString); int id = Convert.ToInt32(Request.Params["id"]); string active = Request.Params["active"]; string lock_id = Request.Params["lock_id"]; if (!string.IsNullOrEmpty(Request.Params["po_id"].ToString())) { q.po_id = Request.Params["po_id"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["remarks"].ToString())) { q.remarks = Request.Params["remarks"].ToString(); } if (active == "H") { nvd.ista_id = "A"; nvd.qity_id = 0; } else if (active == "A") { nvd.qity_id = Convert.ToInt32(lock_id); nvd.ista_id = "H"; } nvd.row_id = id; nvd.change_user = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString()); nvd.change_dtim = DateTime.Now; if (_iinvd.UpdateIinvdLock(nvd, q) > 0) { //加鎖成功往iialg插入一條數據;解鎖不需要記錄 if (active == "A") { Iinvd store = _iinvd.GetIinvd(nvd).FirstOrDefault(); q.loc_id = store.plas_loc_id; q.item_id = store.item_id; q.iarc_id = "KS"; q.qty_o = store.prod_qty; q.type = 1; q.adj_qty = -store.prod_qty; q.create_dtim = DateTime.Now; q.create_user = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString()); q.made_dt = store.made_date; q.cde_dt = store.cde_dt; if (_iagMgr.insertiialg(q) > 0) { Caller call = new Caller(); call = (System.Web.HttpContext.Current.Session["caller"] as Caller); ProductItem proitem = new ProductItem(); _proditemMgr = new ProductItemMgr(mySqlConnectionString); int item_stock = store.prod_qty; proitem.Item_Stock = -item_stock; proitem.Item_Id = store.item_id; string path = "/WareHouse/KutiaoAddorReduce"; _proditemMgr.UpdateItemStock(proitem, path, call); return Json(new { success = "true" }); } else { return Json(new { success = "false" }); } } else { Iinvd store = _iinvd.GetIinvd(nvd).FirstOrDefault(); q.loc_id = store.plas_loc_id; q.item_id = store.item_id; q.iarc_id = "KS"; q.qty_o = 0; q.type = 1; q.adj_qty = store.prod_qty; q.create_dtim = DateTime.Now; q.create_user = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString()); q.made_dt = store.made_date; q.cde_dt = store.cde_dt; if (_iagMgr.insertiialg(q) > 0) { Caller call = new Caller(); call = (System.Web.HttpContext.Current.Session["caller"] as Caller); ProductItem proitem = new ProductItem(); _proditemMgr = new ProductItemMgr(mySqlConnectionString); int item_stock = store.prod_qty; proitem.Item_Stock = item_stock; proitem.Item_Id = store.item_id; string path = "/WareHouse/KutiaoAddorReduce"; _proditemMgr.UpdateItemStock(proitem, path, call); return Json(new { success = "true" }); } else { return Json(new { success = "false" }); } } } else { return Json(new { success = "false" }); } } 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); return Json(new { success = "false" }); } }
public HttpResponseBase InsertIinvd() { string jsonStr = String.Empty; Int64 aaa = 0; //無用變數 uint p = 0; //無用變數 try { Iinvd m = new Iinvd(); IialgQuery ia = new IialgQuery(); Iupc iu = new Iupc(); ProductItem proitem = new ProductItem(); Caller call = new Caller(); IstockChangeQuery stock = new IstockChangeQuery(); call = (System.Web.HttpContext.Current.Session["caller"] as Caller); string path = ""; _iinvd = new IinvdMgr(mySqlConnectionString); _iagMgr = new IialgMgr(mySqlConnectionString); _IiupcMgr = new IupcMgr(mySqlConnectionString); #region 獲取數據往 if (Int64.TryParse(Request.Params["item_id"].ToString(), out aaa)) { if (uint.TryParse(Request.Params["item_id"].ToString(), out p)) { m.item_id = uint.Parse(Request.Params["item_id"].ToString()); } if (Request.Params["item_id"].ToString().Length > 6) { m.item_id = uint.Parse(_iinvd.Getprodubybar(Request.Params["item_id"].ToString()).Rows[0]["item_id"].ToString()); } } else { if (Request.Params["item_id"].ToString().Length > 6) { m.item_id = uint.Parse(_iinvd.Getprodubybar(Request.Params["item_id"].ToString()).Rows[0]["item_id"].ToString()); } } m.dc_id = 1; m.whse_id = 1; m.prod_qty = Int32.Parse(Request.Params["prod_qty"].ToString());//數量 DateTime today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")); DateTime dtime; if (DateTime.TryParse(Request.Params["startTime"].ToString(), out dtime)) {//用戶填寫創建時間算出有效日期 DateTime start = DateTime.Parse(Request.Params["startTime"].ToString()); m.made_date = start; if (uint.TryParse(Request.Params["cde_dt_incr"].ToString(), out p)) { m.cde_dt = start.AddDays(Int32.Parse(Request.Params["cde_dt_incr"].ToString())); } else { m.cde_dt = DateTime.Now; } } else { if (DateTime.TryParse(Request.Params["cde_dt"].ToString(), out dtime)) {//用戶填寫有效日期算出製造日期 m.cde_dt = DateTime.Parse(Request.Params["cde_dt"].ToString());//有效時間 if (uint.TryParse(Request.Params["cde_dt_incr"].ToString(), out p)) { m.made_date = m.cde_dt.AddDays(-Int32.Parse(Request.Params["cde_dt_incr"].ToString())); } else { m.made_date = today; } } else { m.cde_dt = today; m.made_date = today; } } m.cde_dt = DateTime.Parse(m.cde_dt.ToShortDateString()); m.made_date = DateTime.Parse(m.made_date.ToShortDateString()); m.plas_loc_id = Request.Params["plas_loc_id"].ToString().ToUpper();//上架料位 string loc_id = Request.Params["loc_id"].ToString().ToUpper(); m.change_dtim = DateTime.Now;//編輯時間 m.receipt_dtim = DateTime.Now;//收貨時間 m.create_user = (Session["caller"] as Caller).user_id; #endregion #region 獲取數據添加打iialg ia.loc_id = m.plas_loc_id.ToString().ToUpper(); ia.item_id = m.item_id; stock.sc_trans_type = 0; if (!string.IsNullOrEmpty(Request.Params["iarc_id"].ToString())) { ia.iarc_id = Request.Params["iarc_id"].ToString(); } else { ia.iarc_id = "PC"; stock.sc_trans_type = 1;//收貨上架 } //if (ia.iarc_id == "DR" || ia.iarc_id == "KR") //{ // type = 2;//RF理貨 //} ia.create_dtim = DateTime.Now; ia.create_user = m.create_user; ia.doc_no = "P" + DateTime.Now.ToString("yyyyMMddHHmmss"); if (!string.IsNullOrEmpty(Request.Params["doc_num"])) { ia.doc_no = Request.Params["doc_num"]; stock.sc_trans_id = ia.doc_no;//交易單號 } if (!string.IsNullOrEmpty(Request.Params["Po_num"])) { ia.po_id = Request.Params["Po_num"]; stock.sc_cd_id = ia.po_id;//前置單號 } if (!string.IsNullOrEmpty(Request.Params["remark"])) { ia.remarks = Request.Params["remark"]; stock.sc_note = ia.remarks;//備註 } ia.made_dt = m.made_date; ia.cde_dt = m.cde_dt; #endregion #region 獲取店內條碼-=添加條碼 if (!string.IsNullOrEmpty(Request.Params["vendor_id"].ToString())) { iu.upc_id = CommonFunction.GetUpc(m.item_id.ToString(), Request.Params["vendor_id"].ToString(), m.cde_dt.ToString("yyMMdd")); } iu.item_id = m.item_id; iu.upc_type_flg = "2";//店內碼 iu.create_user = m.create_user; string result = _IiupcMgr.IsExist(iu);//是否有重複的條碼 if (result == "0") { if (_IiupcMgr.Insert(iu) < 1) { jsonStr = "{success:true,msg:2}"; } } #endregion #region 新增/編輯 #region 庫存調整的時候,商品庫存也要調整 _proditemMgr = new ProductItemMgr(mySqlConnectionString); int item_stock = m.prod_qty; proitem.Item_Stock = item_stock; proitem.Item_Id = m.item_id; #endregion if (_iinvd.IsUpd(m, stock) > 0) {//編輯 ia.qty_o = _iinvd.Selnum(m); ia.adj_qty = m.prod_qty; m.prod_qty = ia.qty_o + m.prod_qty; if (m.prod_qty >= 0) { if (_iinvd.Upd(m) > 0) { if (Request.Params["iialg"].ToString() == "Y") {// if (ia.iarc_id != "PC" && ia.iarc_id != "NE")//------------庫存調整的時候商品庫存也更改,收貨上架的時候不更改,RF理貨的時候也是不更改 { path = "/WareHouse/KutiaoAddorReduce"; _proditemMgr.UpdateItemStock(proitem, path, call); } if (_iagMgr.insertiialg(ia) > 0) { jsonStr = "{success:true,msg:0}";//更新成功 } else { jsonStr = "{success:false,msg:1}";//更新失敗 } } else { jsonStr = "{success:true,msg:0}";//更新成功 } } else { jsonStr = "{success:false,msg:1}";//更新失敗 } } else { jsonStr = "{success:false,msg:1}";//庫存為負數 } } else {//新增 m.ista_id = "A"; m.create_dtim = DateTime.Now; //創建時間 if (_iinvd.Insert(m) > 0) { _IlocMgr = new IlocMgr(mySqlConnectionString); Iloc loc = new BLL.gigade.Model.Iloc(); loc.change_user = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString()); loc.change_dtim = DateTime.Now; loc.loc_id = m.plas_loc_id.ToString().ToUpper(); if (loc_id.Trim() != m.plas_loc_id.Trim())//判斷如果是主料位不需要進行多餘的操作 { if (_IlocMgr.SetIlocUsed(loc) > 0) { if (Request.Params["iialg"].ToString() == "Y") { if (ia.iarc_id != "PC" && ia.iarc_id != "NE")//------------庫存調整的時候商品庫存也更改,收貨上架的時候不更改,RF理貨的時候也是不更改 { path = "/WareHouse/KutiaoAddorReduce"; _proditemMgr.UpdateItemStock(proitem, path, call); } ia.qty_o = 0; ia.adj_qty = m.prod_qty; if (_iagMgr.insertiialg(ia) > 0) { jsonStr = "{success:true,msg:0}";//更新成功 } else { jsonStr = "{success:false,msg:1}";//更新失敗 } } else { jsonStr = "{success:true,msg:0}";//新增成功 } } else { jsonStr = "{success:false,msg:1}";//新增失敗 } } else { if (Request.Params["iialg"].ToString() == "Y") { if (ia.iarc_id != "PC" && ia.iarc_id != "NE")//------------庫存調整的時候商品庫存也更改,收貨上架的時候不更改,RF理貨的時候也是不更改 { path = "/WareHouse/KutiaoAddorReduce"; _proditemMgr.UpdateItemStock(proitem, path, call); } ia.qty_o = 0; ia.adj_qty = m.prod_qty; if (_iagMgr.insertiialg(ia) > 0) { jsonStr = "{success:true,msg:0}";//更新成功 } else { jsonStr = "{success:false,msg:1}";//更新失敗 } } else { jsonStr = "{success:true,msg:0}";//新增成功 } } } else { jsonStr = "{success:false,msg:1}"; } } #endregion } 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); jsonStr = "{success:false}"; } this.Response.Clear(); this.Response.Write(jsonStr.ToString()); this.Response.End(); return this.Response; }
public string QueryStock() { BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; string json = string.Empty; int writerID = (int)vendorModel.vendor_id; uint pid = 0; try { ProductItemTemp query = new ProductItemTemp(); if (!string.IsNullOrEmpty(Request.Params["product_id"])) { if (uint.TryParse(Request.Params["product_id"].ToString(), out pid)) {//查詢商品列表中正式表的詳細資料 _productItemMgr = new ProductItemMgr(connectionString); ProductItem pItem = new ProductItem(); pItem.Product_Id = uint.Parse(Request.Params["product_id"]); _productItemMgr.Query(pItem); json = _productItemMgr.QueryStock(pItem); } else { query.Product_Id = Request.Params["product_id"].ToString(); query.Writer_Id = writerID; //查找臨時表是否有記錄 _productItemTempMgr = new ProductItemTempMgr(connectionString); json = _productItemTempMgr.QueryStockByVendor(query); } } else { json = "{success:false,msg:'" + Resources.VendorProduct.NOTFOUNTKEY + "'}"; } } 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); json = "{success:false,msg:'" + ex.Message + "'}"; } return json; }
public HttpResponseBase GetProItems() { string json = string.Empty; uint productID = 0; try { BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; int writerID = (int)vendorModel.vendor_id; if (!string.IsNullOrEmpty(Request.Form["ProductId"])) { if (uint.TryParse(Request.Form["ProductId"].ToString(), out productID)) {//商品列表中正式表商品的詳細資料 //product_item _productItemMgr = new ProductItemMgr(connectionString); List<ProductItem> proItem = _productItemMgr.QueryPrice(new ProductItem { Product_Id = Convert.ToUInt32(Request.Form["ProductId"]) }); json = JsonConvert.SerializeObject(proItem); } else { //product_item ProductItemTemp query = new ProductItemTemp(); query.Product_Id = Request.Form["ProductId"].ToString(); query.Writer_Id = writerID; _productItemTempMgr = new ProductItemTempMgr(connectionString); List<ProductItemTemp> proItemTemp = _productItemTempMgr.QueryByVendor(query); json = JsonConvert.SerializeObject(proItemTemp); } } } 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); } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase specTempSave() { string resultStr = "{success:true}"; bool result = true; try { Caller _caller = (Session["caller"] as Caller); string specType = Request.Params["specType"]; string spec1Name = Request.Params["spec1Name"]; string spec1Result = Request.Params["spec1Result"]; string spec2Name = ""; string spec2Result; _specMgr = new ProductSpecMgr(connectionString); _specTempMgr = new ProductSpecTempMgr(connectionString); _productTempMgr = new ProductTempMgr(connectionString); _productItemMgr = new ProductItemMgr(connectionString); _productItemTempMgr = new ProductItemTempMgr(connectionString); _serialMgr = new SerialMgr(connectionString); if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { uint proId = uint.Parse(Request.Params["ProductId"]); _functionMgr = new FunctionMgr(connectionString); string function = Request.Params["function"] ?? ""; Function fun = _functionMgr.QueryFunction(function, "/Product/ProductSave"); int functionid = fun == null ? 0 : fun.RowId; HistoryBatch batch = new HistoryBatch { functionid = functionid }; batch.batchno = Request.Params["batch"] ?? ""; batch.kuser = (Session["caller"] as Caller).user_email; #region 正式表修改 List<ProductSpec> spec1List = null; List<ProductSpec> spec2List = null; List<ProductSpec> specUpdateList = new List<ProductSpec>(); List<ProductSpec> specAddList = new List<ProductSpec>(); JavaScriptSerializer jss = new JavaScriptSerializer(); spec1List = jss.Deserialize<List<ProductSpec>>(spec1Result); if (spec1List != null) { //規格一處理 spec1List.ForEach(m => { m.product_id = proId; m.spec_type = 1; if (m.spec_id != 0) { specUpdateList.Add(m); } else { specAddList.Add(m); } }); } //規格二處理 if (specType.Equals("2")) { spec2Name = Request.Params["spec2Name"]; spec2Result = Request.Params["spec2Result"]; spec2List = jss.Deserialize<List<ProductSpec>>(spec2Result); spec2List.ForEach(m => { m.product_id = proId; m.spec_type = 2; if (m.spec_id != 0) { specUpdateList.Add(m); } else { specAddList.Add(m); } }); } Product proModel = new Product(); _productMgr = new ProductMgr(connectionString); _tableHistoryMgr = new TableHistoryMgr(connectionString); proModel = _productMgr.Query(new Product { Product_Id = proId }).FirstOrDefault(); proModel.Spec_Title_1 = spec1Name; proModel.Spec_Title_2 = spec2Name; if (specUpdateList.Count() > 0) { for (int i = 0, j = specUpdateList.Count(); i < j; i++) { ArrayList sqls = new ArrayList(); sqls.Add(_specMgr.Update(specUpdateList[i])); if (i == 0) { sqls.Add(_productMgr.Update(proModel)); } if (!_tableHistoryMgr.SaveHistory<ProductSpec>(specUpdateList[i], batch, sqls)) { result = false; } } } if (specAddList.Count() > 0) { List<ProductItem> saveItemList = new List<ProductItem>(); List<ProductSpec> spec1ExistList = spec1List.Where(m => m.spec_id != 0).ToList(); //規格一中原本就存在的規格 specAddList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString())); ProductItem saveTemp; List<PriceMaster> list_price = new List<PriceMaster>(); PriceMasterMgr pm = new PriceMasterMgr(connectionString); list_price = pm.GetPriceMasterInfoByID2(proId.ToString());//獲取同一個ID下其他產品的價格信息 PriceMaster _p = list_price.FirstOrDefault();//add by wangwei0216w 2014/9/19 獲取同一個ID下其他產品的信息 //List<ProductItem> pro_list = new List<ProductItem>(); //ProductItemMgr pig = new ProductItemMgr(connectionString); //pro_list = pig.GetProductItemByID(Convert.ToInt32(proId)); //ProductItem _product = pro_list.FirstOrDefault();//獲取同一個ID下其他產品的信息 foreach (var m in specAddList) { if (specType.Equals("1")) { if (m.spec_type == 1) { saveTemp = new ProductItem(); if (_p.same_price == 1) //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格 { //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost); //saveTemp.Item_Money = Convert.ToUInt32(_p.price); } else { resultStr = "{success:true,Msg:true}"; } saveTemp.Spec_Id_1 = m.spec_id; saveTemp.Product_Id = proId; // saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } else { saveTemp = new ProductItem(); if (_p.same_price == 1) //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格 { //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost); //saveTemp.Item_Money = Convert.ToUInt32(_p.price); } else { resultStr = "{success:true,Msg:true}"; } saveTemp.Spec_Id_2 = m.spec_id; saveTemp.Product_Id = proId; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } } else { if (m.spec_type == 1) { foreach (ProductSpec item in spec2List) { saveTemp = new ProductItem(); if (_p.same_price == 1) //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格 { //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost); //saveTemp.Item_Money = Convert.ToUInt32(_p.price); } else { resultStr = "{success:true,Msg:true}"; } saveTemp.Spec_Id_1 = m.spec_id; saveTemp.Spec_Id_2 = item.spec_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveTemp.Product_Id = proId; saveItemList.Add(saveTemp); } } else { foreach (ProductSpec item2 in spec1ExistList) { saveTemp = new ProductItem(); if (_p.same_price == 1) //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格 { //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost); //saveTemp.Item_Money = Convert.ToUInt32(_p.price); } else { resultStr = "{success:true,Msg:true}"; } saveTemp.Spec_Id_1 = item2.spec_id; saveTemp.Spec_Id_2 = m.spec_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveTemp.Product_Id = proId; saveItemList.Add(saveTemp); } } } } _specMgr.Save(specAddList); _productItemMgr.Save(saveItemList); ProductItem pro; if (proModel.Product_Status != 0) //add by wangwei0216w 2014/9/18 作用:將Export_flag的值設置為1 { pro = new ProductItem() { Product_Id = proModel.Product_Id, Export_flag = 1 }; _productItemMgr.UpdateExportFlag(pro); } if (result) //如果之前保存規格,插入臨時表登操作有誤,則不執行插入itemprice的操作 { List<ProductItem> item_list = _productItemMgr.GetProductNewItem_ID(Convert.ToInt32(proModel.Product_Id)); //得到product_item的新增ID ItemPrice i = new ItemPrice(); ItemPriceMgr ipm = new ItemPriceMgr(connectionString); ArrayList liststr = new ArrayList(); foreach (PriceMaster p in list_price) { foreach (ProductItem pi in item_list) { if (p.same_price == 1) { i.price_master_id = p.price_master_id; i.item_id = pi.Item_Id; i.item_money = Convert.ToUInt32(p.price); i.item_cost = Convert.ToUInt32(p.cost); i.event_cost = Convert.ToUInt32(p.event_cost); i.event_money = Convert.ToUInt32(p.event_price); } else { i.price_master_id = p.price_master_id; i.item_id = pi.Item_Id; i.item_money = 0; i.item_cost = 0; i.event_money = 0; i.event_cost = 0; resultStr = "{success:true,Msg:true}"; } liststr.Add(ipm.Save(i)); } } ipm.AddItemPricBySpec(liststr, connectionString); } } //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30 //if (proModel.Combination == 1) //{ // _productItemMgr = new ProductItemMgr(connectionString); // ProductItem pro_Item = new ProductItem() { Product_Id = proModel.Product_Id, Export_flag = 2 }; // _productItemMgr.UpdateExportFlag(pro_Item); //} #endregion } else { #region 臨時表修改 _productTempMgr = new ProductTempMgr(connectionString); //add by xiangwang 2014.09.26 可修改庫存預設值為99 string product_id = "0"; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { product_id = Request.Form["OldProductId"]; } //add by xiangwang 2014.09.26 可修改庫存預設值為99 ProductTemp query = _productTempMgr.GetProTemp(new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }); if (!specType.Equals("0") && !string.IsNullOrEmpty(specType)) { #region 有規格 List<ProductSpecTemp> spec1List; List<ProductSpecTemp> spec2List; List<ProductSpecTemp> specAllList = new List<ProductSpecTemp>(); JavaScriptSerializer jss = new JavaScriptSerializer(); spec1List = jss.Deserialize<List<ProductSpecTemp>>(spec1Result); foreach (ProductSpecTemp item in spec1List) { // specid = _serialMgr.NextSerial(18); //item.spec_id = uint.Parse(specid.ToString()); item.Writer_Id = _caller.user_id; item.product_id = product_id; item.spec_type = 1; item.spec_image = ""; specAllList.Add(item); } if (specType.Equals("2")) { spec2Name = Request.Params["spec2Name"]; spec2Result = Request.Params["spec2Result"]; spec2List = jss.Deserialize<List<ProductSpecTemp>>(spec2Result); foreach (ProductSpecTemp item in spec2List) { // specid = _serialMgr.NextSerial(18); //item.spec_id = uint.Parse(specid.ToString()); item.Writer_Id = _caller.user_id; item.product_id = product_id; item.spec_type = 2; item.spec_image = ""; specAllList.Add(item); } } List<ProductSpecTemp> tempList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id }); if (tempList == null || tempList.Count() <= 0) { #region 保存 specAllList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString())); bool saveSpecResult = _specTempMgr.Save(specAllList); if (saveSpecResult) { _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id }); #region 保存ProductItemTemp List<ProductSpecTemp> specAllResultList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id }); List<ProductSpecTemp> spec1ResultList = specAllResultList.Where(m => m.spec_type == 1).ToList(); List<ProductSpecTemp> spec2ResultList = specAllResultList.Where(m => m.spec_type == 2).ToList(); List<ProductItemTemp> saveItemList = new List<ProductItemTemp>(); if (specType.Equals("1")) { foreach (ProductSpecTemp specTemp1 in spec1ResultList) { ProductItemTemp itemTemp = new ProductItemTemp(); itemTemp.Writer_Id = _caller.user_id; itemTemp.Product_Id = product_id; itemTemp.Spec_Id_1 = specTemp1.spec_id; //itemTemp.Item_Stock = 10; itemTemp.Item_Alarm = 1; saveItemList.Add(itemTemp); } } else if (specType.Equals("2")) { foreach (ProductSpecTemp specTemp1 in spec1ResultList) { foreach (ProductSpecTemp specTemp2 in spec2ResultList) { ProductItemTemp itemTemp = new ProductItemTemp(); itemTemp.Writer_Id = _caller.user_id; itemTemp.Product_Id = product_id; itemTemp.Spec_Id_1 = specTemp1.spec_id; itemTemp.Spec_Id_2 = specTemp2.spec_id; //itemTemp.Item_Stock = 10; itemTemp.Item_Alarm = 1; itemTemp.Item_Code = ""; itemTemp.Barcode = ""; saveItemList.Add(itemTemp); } } } //add by xiangwang 2014.09.26 可修改庫存預設值為99 //saveItemList.ForEach(m => m.SetDefaultItemStock(query)); bool saveItemResult = _productItemTempMgr.Save(saveItemList); if (!saveItemResult) { result = false; } #endregion } else { result = false; } #endregion } else { #region 更新 string strSpecInit = Request.Params["specInit"]; string[] specs = strSpecInit.Split(','); List<ProductSpecTemp> addList = specAllList.Where(p => p.spec_id == 0).ToList(); if (addList.Count() > 0) { addList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString())); List<ProductSpecTemp> specAllResultList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id }); List<ProductSpecTemp> spec1ResultList = specAllResultList.Where(m => m.spec_type == 1).ToList(); List<ProductSpecTemp> spec2ResultList = specAllResultList.Where(m => m.spec_type == 2).ToList(); List<ProductItemTemp> saveItemList = new List<ProductItemTemp>(); foreach (ProductSpecTemp item in addList) { if (specType.Equals("1")) { if (item.spec_type == 1) { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_1 = item.spec_id; saveTemp.Product_Id = product_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } else { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_2 = item.spec_id; saveTemp.Product_Id = product_id; // saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } } else { if (item.spec_type == 1) { foreach (ProductSpecTemp item1 in spec2ResultList) { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_1 = item.spec_id; saveTemp.Spec_Id_2 = item1.spec_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveTemp.Product_Id = product_id; saveItemList.Add(saveTemp); } foreach (ProductSpecTemp item1 in addList.Where(p => p.spec_type == 2).ToList()) { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_1 = item.spec_id; saveTemp.Spec_Id_2 = item1.spec_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveTemp.Product_Id = product_id; saveItemList.Add(saveTemp); } } else { foreach (ProductSpecTemp item2 in spec1ResultList) { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_1 = item2.spec_id; saveTemp.Spec_Id_2 = item.spec_id; saveTemp.Product_Id = product_id; // saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } } } } _specTempMgr.Save(addList); //add by xiangwang 2014.09.26 可修改庫存預設值為99 //saveItemList.ForEach(m => m.SetDefaultItemStock(query)); _productItemTempMgr.Save(saveItemList); } if (specs.Length > 0) { List<ProductSpecTemp> updateList = new List<ProductSpecTemp>(); foreach (string initSpecId in specs) { ProductSpecTemp nowItem = specAllList.Where(p => p.spec_id == uint.Parse(initSpecId)).FirstOrDefault(); if (nowItem != null) { updateList.Add(nowItem); } else { ProductItemTemp delTemp = new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id }; uint spectype = _specTempMgr.Query(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), product_id = product_id })[0].spec_type; if (spectype == 1) { delTemp.Spec_Id_1 = uint.Parse(initSpecId); } else if (spectype == 2) { delTemp.Spec_Id_2 = uint.Parse(initSpecId); } if (!_productItemTempMgr.Delete(delTemp)) { result = false; } if (!_specTempMgr.Delete(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), Writer_Id = _caller.user_id, product_id = product_id })) { result = false; } DeletePicOnServer(false, true, false, uint.Parse(initSpecId), product_id); } } if (!_specTempMgr.Update(updateList, "spec")) { result = false; } } #endregion } #region 更新Product ProductTemp proTemp = new ProductTemp(); proTemp.Writer_Id = _caller.user_id; proTemp.Product_Spec = uint.Parse(specType); proTemp.Spec_Title_1 = spec1Name; proTemp.Spec_Title_2 = spec2Name; proTemp.Combo_Type = COMBO_TYPE; proTemp.Product_Id = product_id; bool saveProductResult = _productTempMgr.SpecInfoSave(proTemp); if (!saveProductResult) { result = false; } #endregion #endregion } else { #region 無規格 List<ProductItemTemp> saveList = new List<ProductItemTemp>(); //如果原數據有規格 if (query.Product_Spec != 0) { //刪除服務器上對應的圖片 DeletePicOnServer(false, true, false, 0, product_id); _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id }); _specTempMgr.Delete(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id }); _productTempMgr.SpecInfoSave(new ProductTemp { Product_Spec = 0, Spec_Title_1 = "", Spec_Title_2 = "", Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }); saveList = new List<ProductItemTemp>(); saveList.Add(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id/*, Item_Stock = 10*/, Item_Alarm = 1 }); } else { List<ProductItemTemp> itemQuery = _productItemTempMgr.Query(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id }); if (itemQuery.Count() <= 0) { saveList = new List<ProductItemTemp>(); saveList.Add(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id, /*Item_Stock = 10,*/ Item_Alarm = 1 }); // _productItemTempMgr.Save(saveList); } } //add by xiangwang 2014.09.26 可修改庫存預設值為99 //saveList.ForEach(m => m.SetDefaultItemStock(query)); _productItemTempMgr.Save(saveList); #endregion } #endregion #region 調度或自出商品,商品庫存預設為99 var proditemTemp = new ProductItemTemp { Product_Id = product_id, Writer_Id = _caller.user_id }; proditemTemp.SetDefaultItemStock(query); _productItemTempMgr.UpdateItemStock(proditemTemp); #endregion } } catch (Exception ex) { result = false; 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); } if (!result) { resultStr = "{success:false,Msg:false}"; } this.Response.Clear(); this.Response.Write(resultStr); this.Response.End(); return this.Response; }
public HttpResponseBase KutiaoAddorReduce() { string jsonStr = String.Empty; _iinvd = new IinvdMgr(mySqlConnectionString); _iagMgr = new IialgMgr(mySqlConnectionString); Iinvd invd = new Iinvd(); iialg iag = new iialg(); IstockChange Icg = new IstockChange(); ProductItem Proitems = new ProductItem(); int results = 0; try { invd.row_id = Convert.ToInt32(Request.Params["row_id"]);//行號碼 int resultcount = 0; int kucuncount = Convert.ToInt32(Request.Params["benginnumber"]);//庫存數量 int tiaozhengcount = Convert.ToInt32(Request.Params["changenumber"]); int kucuntype = Convert.ToInt32(Request.Params["kutiaotype"]); if (!string.IsNullOrEmpty(Request.Params["item_id"]))//商品細項編號 { Icg.item_id = Convert.ToUInt32(Request.Params["item_id"]); Proitems.Item_Id = Icg.item_id; } int oldsumcount = _iinvd.GetProqtyByItemid(Convert.ToInt32(Icg.item_id));//總庫存 string iarc_id = ""; if (!string.IsNullOrEmpty(Request.Params["iarcid"])) { iarc_id = Request.Params["iarcid"];//庫調原因 } #region 庫存調整的時候,商品庫存也要調整 _proditemMgr = new ProductItemMgr(mySqlConnectionString); int item_stock = 0; #endregion if (kucuntype == 1)//表示選擇了加 { resultcount = kucuncount + tiaozhengcount; item_stock = tiaozhengcount; } else//表示選擇了減號 { resultcount = kucuncount - tiaozhengcount; item_stock = -tiaozhengcount; } Proitems.Item_Stock = item_stock; invd.prod_qty = resultcount;//此時為更改后的庫存 invd.change_dtim = DateTime.Now; invd.change_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; Icg.sc_trans_type = 2; Icg.sc_num_old = oldsumcount; Icg.sc_time = DateTime.Now; Icg.sc_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; if (!string.IsNullOrEmpty(Request.Params["po_id"])) { Icg.sc_cd_id = Request.Params["po_id"];//採購單編號 } if (!string.IsNullOrEmpty(Request.Params["doc_no"])) { Icg.sc_trans_id = Request.Params["doc_no"];//庫調單號 } if (!string.IsNullOrEmpty(Request.Params["remarks"])) { Icg.sc_note = Request.Params["remarks"];//備註 } _istockMgr = new IstockChangeMgr(mySqlConnectionString); int j = _iinvd.kucunTiaozheng(invd); //更改iloc表中的狀態並且在iialg表中插入數據 string path = "/WareHouse/KutiaoAddorReduce"; Caller call = new Caller(); call = (System.Web.HttpContext.Current.Session["caller"] as Caller); int k = 0; if (iarc_id == "NE" || iarc_id == "RF")//庫存調整-不改動前台庫存 { k = 1; } else { k = _proditemMgr.UpdateItemStock(Proitems, path, call); } int newsumcount = _iinvd.GetProqtyByItemid(Convert.ToInt32(Icg.item_id));//總庫存 Icg.sc_num_chg = newsumcount - oldsumcount; Icg.sc_num_new = newsumcount; Icg.sc_istock_why = 2; if (oldsumcount != newsumcount) { results = _istockMgr.insert(Icg); } else { results = 1; } if (j > 0 && results > 0 && k > 0) { jsonStr = "{success:true}"; } else { jsonStr = "{success:false}"; } } 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); jsonStr = "{success:false}"; } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }
public HttpResponseBase GetProItems() { string json = string.Empty; try { if (!string.IsNullOrEmpty(Request.Form["ProductId"]) && !string.IsNullOrEmpty(Request.Form["SiteId"])) { //item_price } else if (!string.IsNullOrEmpty(Request.Form["ProductId"])) { //product_item _productItemMgr = new ProductItemMgr(connectionString); List<ProductItem> proItem = _productItemMgr.QueryPrice(new ProductItem { Product_Id = Convert.ToUInt32(Request.Form["ProductId"]) }); json = JsonConvert.SerializeObject(proItem); } else { //product_item_temp int writerId = (Session["caller"] as Caller).user_id; ProductItemTemp query = new ProductItemTemp { Writer_Id = writerId }; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { query.Product_Id = Request.Form["OldProductId"]; } _productItemTempMgr = new ProductItemTempMgr(connectionString); List<ProductItemTemp> proItemTemp = _productItemTempMgr.Query(query); json = JsonConvert.SerializeObject(proItemTemp); } } 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); } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase verifyApply() { List<QueryandVerifyCustom> resultList = new List<QueryandVerifyCustom>(); string result = "{success:false}"; bool resl = true; try { string prodcutIdStr = Request.Params["prodcutIdStr"]; string[] productIds = prodcutIdStr.Split(','); string method = Request.Params["method"]; Caller _caller = (Session["caller"] as Caller); _prodMgr = new ProductMgr(connectionString); _applyMgr = new ProductStatusApplyMgr(connectionString); _statusHistoryMgr = new ProductStatusHistoryMgr(connectionString); _tableHistoryMgr = new TableHistoryMgr(connectionString); _functionMgr = new FunctionMgr(connectionString); string function = Request.Params["function"] ?? ""; Function fun = _functionMgr.QueryFunction(function, "/ProductList") ?? _functionMgr.QueryFunction(function, "/ProductList/ReplaceVerify"); int functionid = fun == null ? 0 : fun.RowId; HistoryBatch batch = new HistoryBatch { functionid = functionid, kuser = (Session["caller"] as Caller).user_email }; string batchNo = CommonFunction.GetPHPTime().ToString() + "_" + (Session["caller"] as Caller).user_id + "_"; string msg = ""; foreach (string item in productIds.Distinct()) { ArrayList sqls = new ArrayList(); Product update = _prodMgr.Query(new Product { Product_Id = uint.Parse(item) }).FirstOrDefault(); //選擇自動上架時間時更改商品上架時間為選定時間 if (method.Equals("3")) { update.Product_Start = uint.Parse(BLL.gigade.Common.CommonFunction.GetPHPTime(Request.Params["product_start"]).ToString()); method = "1"; } //若當前商品狀態不是新建商品或下架,則跳過申請 if (update.Product_Status != 0 && update.Product_Status != 6 && update.Product_Status!=7) { break; } //判斷商品是否失格 則 直接取消申請 add by zhuoqin0830w 20105/07/01 if (update.off_grade == 1) { msg += "【" + update.Product_Id + "】商品是失格商品,不可申請審核!</br>"; break; } ProductStatusApply apply = new ProductStatusApply(); apply.product_id = uint.Parse(item); apply.prev_status = update.Product_Status; apply.online_mode = uint.Parse(method); sqls.Add(_applyMgr.Save(apply)); ProductStatusHistory history = new ProductStatusHistory(); history.product_id = uint.Parse(item); history.user_id = uint.Parse(_caller.user_id.ToString()); history.type = 1; //操作類型 ??????????????????? history.product_status = 1; //操作後狀態 //edit by zhuoqin0830w 2015/06/30 添加備註欄位 history.remark = Request.Form["Remark"]; sqls.Add(_statusHistoryMgr.Save(history)); batch.batchno = batchNo + update.Product_Id; update.Product_Status = 1; //狀態 -> 申請審核 sqls.Add(_prodMgr.Update(update, _caller.user_id)); if (!_tableHistoryMgr.SaveHistory<Product>(update, batch, sqls)) { resl = false; } //若當前商品為單一商品並且商品狀態為新建商品,則將product_item.export_flag改為1 if (resl && update.Combination == 1 && apply.prev_status == 0) { _productItemMgr = new ProductItemMgr(connectionString); ProductItem proItem = new ProductItem() { Product_Id = update.Product_Id, Export_flag = 1 }; _productItemMgr.UpdateExportFlag(proItem); } } result = "{success:" + resl.ToString().ToLower() + ",'msg':'" + msg + "'}"; } 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); } Response.Clear(); Response.Write(result); Response.End(); return this.Response; }
public HttpResponseBase StockSave() { ProductItemTemp piTemp = new ProductItemTemp(); _productItemMgr = new ProductItemMgr(connectionString); ProductItem pItem = new ProductItem(); string[] Value = Request.Params["ig_sh_InsertValue"].Split(','); string json = "{success:true}"; _productItemTempMgr = new ProductItemTempMgr(connectionString); int writeId = (Session["caller"] as Caller).user_id; _tableHistoryMgr = new TableHistoryMgr(connectionString); List<ProductItemTemp> piTempList = new List<ProductItemTemp>(); List<ProductItem> pItemList = new List<ProductItem>(); //edit by wwei0216w 2015/6/11 修改原因:之前代碼在判斷時會做出誤判,因為spilt用(,)進行分割,導致字符串中本來是用(,)時,也被分割 if (!string.IsNullOrEmpty(Request.Form["InsertValue"])) { List<ProductItem> list = JsonConvert.DeserializeObject<List<ProductItem>>(Request.Form["InsertValue"].ToString()); foreach (var p_item in list) { piTemp = new ProductItemTemp(); pItem = new ProductItem(); piTemp.Writer_Id = writeId; if (!string.IsNullOrEmpty(p_item.Item_Id.ToString())) { piTemp.Item_Id = p_item.Item_Id; pItem.Item_Id = p_item.Item_Id; }; if (Request.Params["product_id"] != "") { pItem.Product_Id = uint.Parse(Request.Params["product_id"]); pItem = _productItemMgr.Query(pItem)[0]; } if (!string.IsNullOrEmpty(p_item.Spec_Id_1.ToString())) { piTemp.Spec_Id_1 = p_item.Spec_Id_1; pItem.Spec_Id_1 = p_item.Spec_Id_1; }; if (!string.IsNullOrEmpty(p_item.Spec_Id_2.ToString())) { piTemp.Spec_Id_2 = p_item.Spec_Id_2; pItem.Spec_Id_2 = p_item.Spec_Id_2; }; if (!string.IsNullOrEmpty(p_item.Item_Stock.ToString())) { piTemp.Item_Stock = p_item.Item_Stock; pItem.Item_Stock = p_item.Item_Stock; }; if (!string.IsNullOrEmpty(p_item.Item_Alarm.ToString())) { piTemp.Item_Alarm = p_item.Item_Alarm; pItem.Item_Alarm = p_item.Item_Alarm; }; if (!string.IsNullOrEmpty(p_item.Barcode.ToString())) { piTemp.Barcode = p_item.Barcode; pItem.Barcode = p_item.Barcode; }; if (!string.IsNullOrEmpty(p_item.Item_Code.ToString())) { piTemp.Item_Code = p_item.Item_Code; pItem.Item_Code = p_item.Item_Code; } if (!string.IsNullOrEmpty(p_item.Erp_Id.ToString())) { piTemp.Erp_Id = p_item.Erp_Id; pItem.Erp_Id = p_item.Erp_Id; } // add by zhuoqin0830w 2014/02/05 增加備註 if (!string.IsNullOrEmpty(p_item.Remark.ToString())) { piTemp.Remark = p_item.Remark; pItem.Remark = p_item.Remark; } // add by zhuoqin0830w 2014/03/20 增加運達天數 if (!string.IsNullOrEmpty(p_item.Arrive_Days.ToString())) { piTemp.Arrive_Days = p_item.Arrive_Days; pItem.Arrive_Days = p_item.Arrive_Days; } piTempList.Add(piTemp); pItemList.Add(pItem); } //string[] Values = Request.Form["InsertValue"].ToString().Split(';'); //for (int i = 0; i < Values.Length - 1; i++) //{ // piTemp = new ProductItemTemp(); // pItem = new ProductItem(); // piTemp.Writer_Id = writeId; // string[] perValue = Values[i].Split(','); // //查詢product_item數據 // if (!string.IsNullOrEmpty(perValue[5])) { piTemp.Item_Id = uint.Parse(perValue[5]); pItem.Item_Id = uint.Parse(perValue[5]); }; // if (Request.Params["product_id"] != "") // { // pItem.Product_Id = uint.Parse(Request.Params["product_id"]); // pItem = _productItemMgr.Query(pItem)[0]; // } // if (!string.IsNullOrEmpty(perValue[0])) { piTemp.Spec_Id_1 = uint.Parse(perValue[0]); pItem.Spec_Id_1 = uint.Parse(perValue[0]); }; // if (!string.IsNullOrEmpty(perValue[1])) { piTemp.Spec_Id_2 = uint.Parse(perValue[1]); pItem.Spec_Id_2 = uint.Parse(perValue[1]); }; // if (!string.IsNullOrEmpty(perValue[2])) { piTemp.Item_Stock = int.Parse(perValue[2]); pItem.Item_Stock = int.Parse(perValue[2]); }; // if (!string.IsNullOrEmpty(perValue[3])) { piTemp.Item_Alarm = uint.Parse(perValue[3]); pItem.Item_Alarm = uint.Parse(perValue[3]); }; // if (!string.IsNullOrEmpty(perValue[4])) { piTemp.Barcode = perValue[4]; pItem.Barcode = perValue[4]; }; // if (!string.IsNullOrEmpty(perValue[6])) { piTemp.Item_Code = perValue[6]; pItem.Item_Code = perValue[6]; } // if (!string.IsNullOrEmpty(perValue[7])) { piTemp.Erp_Id = perValue[7]; pItem.Erp_Id = perValue[7]; } // // add by zhuoqin0830w 2014/02/05 增加備註 // if (!string.IsNullOrEmpty(perValue[8])) { piTemp.Remark = perValue[8]; pItem.Remark = perValue[8]; } // // add by zhuoqin0830w 2014/03/20 增加運達天數 // if (!string.IsNullOrEmpty(perValue[9])) { piTemp.Arrive_Days = int.Parse(perValue[9]); pItem.Arrive_Days = int.Parse(perValue[9]); } // piTempList.Add(piTemp); // pItemList.Add(pItem); //} } //判斷單一商品是新增還是修改 if (!string.IsNullOrEmpty(Request.Params["product_id"])) {//修改單一商品時執行 Product p = new Product(); _functionMgr = new FunctionMgr(connectionString); string function = Request.Params["function"] ?? ""; Function fun = _functionMgr.QueryFunction(function, "/Product/ProductSave"); int functionid = fun == null ? 0 : fun.RowId; HistoryBatch batch = new HistoryBatch { functionid = functionid }; batch.batchno = Request.Params["batch"] ?? ""; batch.kuser = (Session["caller"] as Caller).user_email; //更新product _productMgr = new ProductMgr(connectionString); Product Query = new Product(); //查詢product表。 Query.Product_Id = uint.Parse(Request.Params["product_id"]); p = _productMgr.Query(Query)[0]; p.Shortage = int.Parse(Value[1]); p.Ignore_Stock = int.Parse(Value[0]); p.outofstock_days_stopselling=int.Parse(Value[2]); json = "{success:true,msg:'" + Resources.Product.SAVE_SUCCESS + "'}"; try { foreach (var item in pItemList) { ArrayList arrList = new ArrayList(); arrList.Add(_productItemMgr.Update(item)); _tableHistoryMgr.SaveHistory<ProductItem>(item, batch, arrList); } ArrayList proList = new ArrayList(); proList.Add(_productMgr.Update(p)); _tableHistoryMgr.SaveHistory<Product>(p, batch, proList); //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30 //if (p.Combination == 1) //{ // _productItemMgr = new ProductItemMgr(connectionString); // ProductItem pro_Item = new ProductItem() { Product_Id = p.Product_Id, Export_flag = 2 }; // _productItemMgr.UpdateExportFlag(pro_Item); //} } 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); json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } } else {//新增單一商品時 try { //更新product_temp _productTempMgr = new ProductTempMgr(connectionString); ProductTemp pTemp = new ProductTemp(); pTemp.Ignore_Stock = int.Parse(Value[0]); pTemp.Shortage = int.Parse(Value[1]); pTemp.outofstock_days_stopselling = int.Parse(Value[2]); pTemp.Writer_Id = writeId; pTemp.Combo_Type = COMBO_TYPE; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { pTemp.Product_Id = Request.Form["OldProductId"]; } _productTempMgr.ProductTempUpdate(pTemp, "stock"); piTempList.ForEach(m => { m.Product_Id = pTemp.Product_Id; }); _productItemTempMgr.UpdateStockAlarm(piTempList); } 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); json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public StringBuilder GetStockMessageFromFile(string fileName, ref DataTable _dtSucess, ref DataTable _dtFail, ref DataTable _dtIgnore, ref DataTable _dtErrorTable) { StringBuilder sbErrContent = new StringBuilder(); DataTable dt = null; try { dt = ExcelHelperXhf.ImportExcel2003toDt(fileName); } catch (Exception) { try { dt = ExcelHelperXhf.ImportExcel2007toDt(fileName); } catch (Exception) { DataRow rows = _dtErrorTable.NewRow(); rows[0] = fileName; rows[1] = "這個格式的Excel格式未知,不能讀取"; _dtErrorTable.Rows.Add(rows); sbErrContent.AppendLine(fileName + "這個格式的Excel格式未知,不能讀取"); //Console.WriteLine("這個格式的Excel格式未知,不能讀取"); } } _productItemMgr = new ProductItemMgr(mySqlConnectionString); foreach (DataRow r in dt.Rows) { ProductItemQuery model = new ProductItemQuery(); model.Erp_Id = r["品號"].ToString(); model.item_stock = Convert.ToInt32(r["可用量"].ToString()); //查詢atm數量 int atmNumber = _productItemMgr.GetATMStock(model);/*ATM的數量*/ int useNumber = Convert.ToInt32(model.item_stock) - atmNumber; //int olditem_stock = Convert.ToInt32(model.item_stock); model.item_stock = useNumber; try { List<ProductItemQuery> ItemList = new List<ProductItemQuery>(); ItemList = _productItemMgr.GetProdItemByERp(model); if (ItemList.Count > 0 && ItemList[0].product_id != 0) { if (atmNumber > 0) {//扣除ATM的 #region MyRegion if (model.item_stock == ItemList[0].item_stock) { DataRow rows = _dtSucess.NewRow(); rows[0] = ItemList[0].product_id; rows[1] = ItemList[0].item_id; rows[2] = model.Erp_Id; rows[3] = ItemList[0].product_name; rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; rows[5] = string.Format(" {0} ", model.item_stock); _dtSucess.Rows.Add(rows); sbErrContent.AppendLine(string.Format("erp_id為{0}的商品庫存變為{1}", model.Erp_Id, model.item_stock)); } else { if (_productItemMgr.UpdateStockAsErpId(model) > 0) { DataRow rows = _dtSucess.NewRow(); rows[0] = ItemList[0].product_id; rows[1] = ItemList[0].item_id; rows[2] = model.Erp_Id; rows[3] = ItemList[0].product_name; rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; rows[5] = string.Format(" {0}扣除ATM庫存為{1} ", model.item_stock + atmNumber, model.item_stock); _dtSucess.Rows.Add(rows); sbErrContent.AppendLine(string.Format("erp_id為{0}的商品扣除ATM庫存{1}", model.Erp_Id, atmNumber)); } else { DataRow rows = _dtFail.NewRow(); rows[0] = ItemList[0].product_id; rows[1] = ItemList[0].item_id; rows[2] = model.Erp_Id; rows[3] = ItemList[0].product_name; rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; rows[5] = string.Format(" 由{0}更新為{1}失敗! ", ItemList[0].item_stock, model.item_stock); _dtFail.Rows.Add(rows); sbErrContent.AppendLine(string.Format("erp_id為{0}的更新失敗", model.Erp_Id)); } } #endregion } else {//不扣除ATM的,可能需要更新,可能不需要更新 #region MyRegion if (ItemList[0].item_stock == model.item_stock)//不需要更新的 { DataRow rows = _dtSucess.NewRow(); rows[0] = ItemList[0].product_id; rows[1] = ItemList[0].item_id; rows[2] = model.Erp_Id; rows[3] = ItemList[0].product_name; rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; rows[5] = string.Format(" {0} ", model.item_stock); _dtSucess.Rows.Add(rows); sbErrContent.AppendLine(string.Format("erp_id為{0}的商品庫存變為{1}", model.Erp_Id, model.item_stock)); } else //需要更新的 { if (_productItemMgr.UpdateStockAsErpId(model) > 0) { DataRow rows = _dtSucess.NewRow(); rows[0] = ItemList[0].product_id; rows[1] = ItemList[0].item_id; rows[2] = model.Erp_Id; rows[3] = ItemList[0].product_name; rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; rows[5] = string.Format(" 由{0}更新為{1}成功! ", ItemList[0].item_stock, model.item_stock); _dtSucess.Rows.Add(rows); sbErrContent.AppendLine(string.Format("erp_id為{0}的商品庫存變為{1}", model.Erp_Id, model.item_stock)); } else { DataRow rows = _dtFail.NewRow(); rows[0] = ItemList[0].product_id; rows[1] = ItemList[0].item_id; rows[2] = model.Erp_Id; rows[3] = ItemList[0].product_name; rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; rows[5] = string.Format(" 由{0}更新為{1}失敗! ", ItemList[0].item_stock, model.item_stock); _dtFail.Rows.Add(rows); sbErrContent.AppendLine(string.Format("erp_id為{0}的更新失敗", model.Erp_Id)); } } #endregion } //if (_productItemMgr.UpdateStockAsErpId(model) > 0) //{//更新成功的 // if (atmNumber > 0) // {//扣除ATM的 // DataRow rows = _dtSucess.NewRow(); // rows[0] = ItemList[0].product_id; // rows[1] = ItemList[0].item_id; // rows[2] = model.Erp_Id; // rows[3] = ItemList[0].product_name; // rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; // rows[5] = string.Format(" {0}扣除ATM庫存為{1} ", model.item_stock + atmNumber, model.item_stock); // _dtSucess.Rows.Add(rows); // sbErrContent.AppendLine(string.Format("erp_id為{0}的商品扣除ATM庫存{1}", model.Erp_Id, atmNumber)); // } // else // { // DataRow rows = _dtSucess.NewRow(); // rows[0] = ItemList[0].product_id; // rows[1] = ItemList[0].item_id; // rows[2] = model.Erp_Id; // rows[3] = ItemList[0].product_name; // rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; // rows[5] = string.Format(" 由{0}更新為{1}成功! ", ItemList[0].item_stock, model.item_stock); // _dtSucess.Rows.Add(rows); // sbErrContent.AppendLine(string.Format("erp_id為{0}的商品庫存變為{1}", model.Erp_Id, model.item_stock)); // } //} //else //{//更新失敗的 // DataRow rows = _dtFail.NewRow(); // rows[0] = ItemList[0].product_id; // rows[1] = ItemList[0].item_id; // rows[2] = model.Erp_Id; // rows[3] = ItemList[0].product_name; // rows[4] = ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2; // rows[5] = string.Format(" 由{0}更新為{1}失敗! ", ItemList[0].item_stock, model.item_stock); // _dtFail.Rows.Add(rows); // sbErrContent.AppendLine(string.Format("erp_id為{0}的更新失敗", model.Erp_Id)); //} } else { DataRow rows = _dtIgnore.NewRow(); rows[0] = model.Erp_Id; _dtIgnore.Rows.Add(rows); sbErrContent.AppendLine(string.Format("erp_id為{0}的跳過", model.Erp_Id)); } } catch (Exception ex) { throw new Exception("CheckOrderAmount-->GetStockMessageFromFile-->" + ex.Message); } } return sbErrContent; }
public void CreateList(List<MakePriceCustom> PriceStore, PriceMaster pMaster, PriceMasterTemp pMasterTemp, string same_price, List<List<ItemPrice>> ItemPList, List<PriceMasterTemp> pMasterListT, List<PriceMaster> pMasterList, List<ItemPrice> update) { _productItemMgr = new ProductItemMgr(connectionString); if (PriceStore.Count > 0) { //先遍歷群組 var piles = PriceStore.GroupBy(rec => rec.Pile_Id).ToList(); piles.ForEach(rec => { if (same_price == "1") { //循環grid的每一行 rec.ToList().ForEach(row => { //生成price_master if (pMasterTemp != null) { PriceMasterTemp pmT = pMasterTemp.Clone() as PriceMasterTemp; pmT.product_name = row.Product_Name; pmT.child_id = row.Child_Id.ToString(); pmT.price = int.Parse(row.item_money.ToString()); pmT.max_price = int.Parse(row.item_money.ToString()); //edit by xinglu0624w reason 子商品需要给 max_price 值 pmT.max_event_price = 0; pmT.cost = int.Parse(row.item_cost.ToString()); pmT.event_price = int.Parse(row.event_money.ToString()); pmT.event_cost = int.Parse(row.event_cost.ToString()); pmT.valid_start = pMasterTemp.valid_start; pmT.valid_end = pMasterTemp.valid_end; pMasterListT.Add(pmT); } else { PriceMaster priceMa = pMaster.Clone() as PriceMaster; priceMa.product_name = row.Product_Name; priceMa.child_id = int.Parse(row.Child_Id.ToString()); priceMa.price = int.Parse(row.item_money.ToString()); priceMa.max_price = int.Parse(row.item_money.ToString()); priceMa.max_event_price = 0; priceMa.cost = int.Parse(row.item_cost.ToString()); priceMa.event_price = int.Parse(row.event_money.ToString()); priceMa.event_cost = int.Parse(row.event_cost.ToString()); priceMa.price_master_id = row.price_master_id; pMasterList.Add(priceMa); } if (row.price_master_id == 0)//新增 { //生成item_price List<ProductItem> piList = _productItemMgr.Query(new ProductItem { Product_Id = row.Child_Id }); List<ItemPrice> iList = new List<ItemPrice>(); piList.ForEach(item => { ItemPrice iP = new ItemPrice(); iP.item_id = item.Item_Id; iP.item_money = row.item_money; iP.item_cost = row.item_cost; iP.event_money = row.event_money; iP.event_cost = row.event_cost; iList.Add(iP); }); ItemPList.Add(iList); } else //更新 { ItemPrice ip = new ItemPrice(); ip.item_price_id = row.item_price_id; ip.price_master_id = row.price_master_id; ip.item_money = row.item_money; ip.item_cost = row.item_cost; ip.event_money = row.event_money; ip.event_cost = row.event_cost; update.Add(ip); } }); } else //處理各自定價-規格不同價 { var children = rec.GroupBy(c => c.Child_Id).ToList(); children.ForEach(c => { List<ItemPrice> differentPrice = new List<ItemPrice>(); //生成price_mater var rowData = (from ci in c where ci.Child_Id == c.Key select new { ci.Product_Name, ci.price_master_id }).ToList().First(); if (pMasterTemp != null) { PriceMasterTemp pmT = pMasterTemp.Clone() as PriceMasterTemp; pmT.product_name = rowData.Product_Name; pmT.child_id = c.Key.ToString(); pmT.price = int.Parse(c.FirstOrDefault().item_money.ToString()); pmT.max_price = int.Parse(c.FirstOrDefault().item_money.ToString()); //edit by hufeng0813w 2014/06/16 Reason:規格不同價時子商品也需要cost,event_cost,event_money pmT.max_event_price = int.Parse(c.FirstOrDefault().event_money.ToString()); pmT.cost = int.Parse(c.FirstOrDefault().item_cost.ToString()); pmT.event_price = int.Parse(c.FirstOrDefault().event_money.ToString()); pmT.event_cost = int.Parse(c.FirstOrDefault().event_cost.ToString()); //edit by hufeng0813w 2014/06/16 pMasterListT.Add(pmT); } else { PriceMaster priceMa = pMaster.Clone() as PriceMaster; priceMa.price_master_id = uint.Parse(rowData.price_master_id.ToString()); priceMa.product_name = rowData.Product_Name; priceMa.child_id = int.Parse(c.Key.ToString()); priceMa.price = int.Parse(c.FirstOrDefault().item_money.ToString()); priceMa.max_price = int.Parse(c.FirstOrDefault().item_money.ToString()); //edit by hufeng0813w 2014/06/16 Reason:規格不同價時子商品也需要cost,event_cost,event_money priceMa.max_event_price = int.Parse(c.FirstOrDefault().event_money.ToString()); priceMa.cost = int.Parse(c.FirstOrDefault().item_cost.ToString()); priceMa.event_price = int.Parse(c.FirstOrDefault().event_money.ToString()); priceMa.event_cost = int.Parse(c.FirstOrDefault().event_cost.ToString()); //edit by hufeng0813w 2014/06/16 pMasterList.Add(priceMa); } c.ToList().ForEach(row => { //生成item_price ItemPrice iP = new ItemPrice(); iP.item_id = row.item_id; iP.item_money = row.item_money; iP.item_cost = row.item_cost; iP.event_money = row.event_money; iP.event_cost = row.event_cost; iP.item_price_id = row.item_price_id; iP.price_master_id = row.price_master_id; differentPrice.Add(iP); update.Add(iP); }); ItemPList.Add(differentPrice); }); } }); } //為保證ItemPList.Count=pMasterListT.Count ItemPList.Add(null); }
public HttpResponseBase QueryLastModifyRecord() { string result = string.Empty; try { if (!string.IsNullOrEmpty(Request.Form["Product_Id"])) { StringBuilder html = new StringBuilder(); int productId = Convert.ToInt32(Request.Form["Product_Id"]); bool isPro = (Request.Form["Type"] ?? "") == "product"; _tableHistoryMgr = new TableHistoryMgr(connectionString); _tableHistoryItemMgr = new TableHistoryItemMgr(connectionString); TableHistory query = new TableHistory { pk_value = productId.ToString() }; if (isPro) { query.table_name = "product"; } TableHistory lastRec = _tableHistoryMgr.QueryLastModifyByProductId(query); if (lastRec != null) { List<TableHistory> histories = _tableHistoryMgr.Query(new TableHistory { batchno = lastRec.batchno }); if (histories != null && histories.Count > 0) { List<string> tbls = histories.GroupBy(m => m.table_name).Select(m => m.Key).ToList(); uint site = 0, level = 0, userid = 0; string[] priceTable = { "price_master", "item_price" }; if (isPro) { tbls.RemoveAll(m => priceTable.Contains(m)); } else { uint.TryParse(Request.Form["Site_id"], out site); uint.TryParse(Request.Form["User_Level"], out level); uint.TryParse(Request.Form["User_id"], out userid); tbls.RemoveAll(m => !priceTable.Contains(m)); } List<TableHistoryItem> items; #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(); NotificationController notification = new NotificationController(); #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 = lastRec.batchno, table_name = tblName }); if (items != null && items.Count > 0) { StringBuilder column_1 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">欄位名稱</td>"); StringBuilder column_2 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">修改前</td>"); StringBuilder column_3 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">修改後</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) { notification.GetParamCon(last, true); } else { notification.GetParamCon(first, true); } notification.GetParamCon(last, false); column_1.AppendFormat("<td style=\"border:1px solid #99bce8;\">{0}</td>", first.col_chsname); column_2.AppendFormat("<td style=\"border:1px solid #99bce8;color:Red;\">{0}</td>", first == last ? last.old_value : first.old_value);//class=\"red\" column_3.AppendFormat("<td style=\"border:1px solid #99bce8;color:green;\">{0}</td>", last.col_value);//class=\"green\" isAdd = true; } } if (isAdd) { pro.AppendFormat("<table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\">{0}</tr>{1}</tr>{2}</tr></table>", column_1, column_2, column_3);//class=\"tbptstyle\" } } #endregion break; case "product_spec": #region SPEC StringBuilder spec_1 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">修改前</td>"); StringBuilder spec_2 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">修改後</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 = lastRec.batchno, 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\" style=\"border:1px solid #99bce8;color:Red;\">{0}</td>", first == last ? last.old_value : first.old_value); spec_2.AppendFormat("<td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{0}</td>", last.col_value); isAdd = true; } } if (isAdd) { spec.AppendFormat("<table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\">{0}</tr>{1}</tr></table>", spec_1, spec_2);//class=\"tbptstyle\" } #endregion break; case "product_category_set": #region CATEGORY items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = lastRec.batchno, table_name = tblName, pk_value = productId.ToString() }); if (items.Count > 0) { var first = items.FirstOrDefault(); var last = items.LastOrDefault(); category.Append("<table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\"><tr><td style=\"border:1px solid #99bce8;\">修改前</td><td style=\"border:1px solid #99bce8;\">修改後</td></tr>");// class=\"tbptstyle\" category.AppendFormat("<tr><td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{0}</td>", first == last ? last.old_value : first.old_value); category.AppendFormat("<td class=\"green\" style=\"border:1px solid #99bce8;color: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) { string title = pItem.GetSpecName(); string top = "<div style=\"float:left\"><table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\"><caption style=\"text-align:center;border:1px solid #99bce8;\">" + title + "</caption><tr><td style=\"border:1px solid #99bce8;\">欄位名稱</td><td style=\"border:1px solid #99bce8;\">修改前</td><td style=\"border:1px solid #99bce8;\">修改后</td></tr>";//class=\"tbstyle\" string bottom = "</table></div>"; string strContent = "<tr><td style=\"border:1px solid #99bce8;\">{0}</td><td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{1}</td><td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{2}</td></tr>"; string content = notification.BuildContent(lastRec.batchno, 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; _pMaster = 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 = _pMaster.Query(new PriceMaster { price_master_id = uint.Parse(id.ToString()) }).FirstOrDefault(); if (pMaster != null && pMaster.site_id == site && pMaster.user_level == level && pMaster.user_id == userid) { string siteName = notification.QuerySiteName(pMaster.site_id.ToString()); string userLevel = notification.QueryParaName(pMaster.user_level.ToString(), "UserLevel"); string userMail = pMaster.user_id == 0 ? "" : notification.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 style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\"><caption style=\"text-align:center;border:1px solid #99bce8;\">" + title + "</caption><tr><td style=\"border:1px solid #99bce8;\">欄位名稱</td><td style=\"border:1px solid #99bce8;\">修改前</td><td style=\"border:1px solid #99bce8;\">修改后</td></tr>";// class=\"tbstyle\" string bottom = "</table></div>"; string strContent = "<tr><td style=\"border:1px solid #99bce8;\">{0}</td><td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{1}</td><td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{2}</td></tr>"; string content = notification.BuildContent(lastRec.batchno, 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); _pMaster = 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 = _pMaster.Query(new PriceMaster { price_master_id = itemPrice.price_master_id }).FirstOrDefault(); if (tmpMaster != null && tmpMaster.site_id == site && tmpMaster.user_level == level && tmpMaster.user_id == userid) { string siteName = notification.QuerySiteName(tmpMaster.site_id.ToString()); string userLevel = notification.QueryParaName(tmpMaster.user_level.ToString(), "UserLevel"); string userMail = tmpMaster.user_id == 0 ? "" : notification.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 style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\"><caption style=\"text-align:center;border:1px solid #99bce8;\">" + title + "</caption><tr><td style=\"border:1px solid #99bce8;\">欄位名稱</td><td style=\"border:1px solid #99bce8;\">修改前</td><td style=\"border:1px solid #99bce8;\">修改后</td></tr>";//class=\"tbstyle\" string bottom = "</table></div>"; string strContent = "<tr><td style=\"border:1px solid #99bce8;\">{0}</td><td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{1}</td><td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{2}</td></tr>"; string content = notification.BuildContent(lastRec.batchno, 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 style=\"border:1px solid #99bce8;\">商品信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", pro); } if (spec.Length > 0) { batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">規格信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", spec); } if (category.Length > 0) { batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">前臺分類信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", category); } if (item.Length > 0) { batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">商品細項信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", item); } if (master.Length > 0) { batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">站臺商品信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", master); } if (price.Length > 0) { batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">站臺價格信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", price); }; if (batchHtml.Length > 0) { _productMgr = new ProductMgr(connectionString); Product product = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(productId) }).FirstOrDefault(); if (product != null) { string brand = string.Empty; vbMgr = new VendorBrandMgr(connectionString); VendorBrand vendorBrand = vbMgr.GetProductBrand(new VendorBrand { Brand_Id = product.Brand_Id }); if (vendorBrand != null) { brand = vendorBrand.Brand_Name; } _historyBatchMgr = new HistoryBatchMgr(connectionString); HistoryBatch batch = _historyBatchMgr.Query(new HistoryBatch { batchno = lastRec.batchno }); html.Append("<html><head><style type=\"text/css\">table{ font-size: 13px;border:1px solid #99bce8}td{border:1px solid #99bce8} .tbstyle{width:180px;text-align:center;} .red{color:Red;}.green{color:green;} caption{text-align:center;border:1px solid #99bce8}</style></head><body>"); html.AppendFormat("<table style=\"font-size: 13px;border:1px solid #99bce8;\"><tr><td colspan='2' style=\"border:1px solid #99bce8;\">商品編號:<b>{0}</b> 品牌:<b>{1}</b></td></tr>", productId, brand); html.AppendFormat("<tr><td colspan='2' style=\"border:1px solid #99bce8;\"><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); html.Append("</table>"); html.Append("</body></html>"); } } #endregion } result = "{success:true,html:'" + HttpUtility.HtmlEncode(html.ToString()) + "'}"; } else { result = "{success:true,html:''}"; } } } 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,html:''}"; } this.Response.Clear(); this.Response.Write(result); this.Response.End(); return this.Response; }
public string QueryItemStock() { string json = string.Empty; _productItemMgr = new ProductItemMgr(connectionString); if (!string.IsNullOrEmpty(Request.Params["product_id"])) { try { List<StockDataCustom> stockCustomList = _productItemMgr.QueryItemStock(int.Parse(Request.Params["product_id"]), int.Parse(Request.Params["pile_id"])); json = "{items:" + JsonConvert.SerializeObject(stockCustomList) + "}"; } 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); json = "[]"; } } return json; }
public HttpResponseBase OrderInfoQueryByGigade() { string jsonStr = "{success:false}"; uint pid = 0; uint spec1 = 0; uint spec2 = 0; UInt32.TryParse(Request.Params["pid"] ?? "0", out pid); IProductImplMgr _proMgr = new ProductMgr(connectionString); ProductCombo pcombo = new ProductCombo(); if (pid != 0) { long time = BLL.gigade.Common.CommonFunction.GetPHPTime(Request.Params["combOrderDate"]);//獲取頁面上的訂單日期 edit by zhuoqin0830w 2015/11/17 Product prod = _proMgr.Query(new Product { Product_Id = pid }).FirstOrDefault(); if (prod != null) { //判断商品是否上架 long ltime = BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); bool upFlag = prod.Product_Status == 5 && ltime >= prod.Product_Start && ltime <= prod.Product_End;//判斷商品是否上架 if (Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd" || upFlag)//edit by xiangwang0413w 內部訂單輸入不進行商品是否上架判斷 { if (prod.Combination == 3) { #region 無規格任選 try { bool hasSpec = false; //查詢子商品信息 _prodCombMgr = new ProductComboMgr(connectionString); _proItemMgr = new ProductItemMgr(connectionString); _priceMasterMgr = new PriceMasterMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(pid.ToString()) }); //組合商品信息 OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = pid }, 1, 0, 1); // add by wwei0216w 2015/2/10 將之前的0,1,1改成 1,0,1 因為參數不對查詢不出結果 orderAdd.childCount = prodComList.Count(); jsonStr = "{success:true"; double comboPrice = 0.0; //組合商品的價格 =sum( 子商品價格 * 子商品必選數量(s_must_buy); double comboCost = 0.0; //組合商品的成本 double comboEventCost = 0.0; //組合商品的活動成本 add by zhuoqin0830w 2015/11/09 int childSum = 0; //必選商品的必購數量之和 int minStock = 0; int stockIndex = 0; List<OrderAddCustom> orderAddList = new List<OrderAddCustom>(); //存放必選商品集 //此循環是計算子商品的庫存,總價(供按比例拆分時計算子商品的價格使用)等其它信息 for (int i = 0, j = prodComList.Count(); i < j; i++) { ProductComboCustom item = prodComList[i]; uint c_product_id = uint.Parse(item.Child_Id.ToString()); Product pResult = _proMgr.Query(new Product { Product_Id = c_product_id }).FirstOrDefault(); //判斷子商品是否有規格 if (pResult.Product_Spec > 0) { hasSpec = true; break; } //補貨中停止販售 1:是 0:否 if (pResult.Shortage == 1) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } OrderAddCustom oc = new OrderAddCustom(); ProductItem pItemResult = _proItemMgr.Query(new ProductItem { Product_Id = c_product_id }).FirstOrDefault(); if (pItemResult != null) { oc.Item_Id = pItemResult.Item_Id; oc.Item_Stock = pItemResult.Item_Stock; oc.s_must_buy = item.S_Must_Buy; oc.parent_id = int.Parse(pid.ToString()); oc.ignore_stock = pResult.Ignore_Stock; //計算必先商品之最小庫存 if (item.S_Must_Buy > 0) { oc.Product_Id = c_product_id; childSum += item.S_Must_Buy; if (stockIndex == 0) { minStock = int.Parse((pItemResult.Item_Stock / item.S_Must_Buy).ToString()); } else { int curStock = int.Parse((pItemResult.Item_Stock / item.S_Must_Buy).ToString()); if (curStock < minStock) { minStock = curStock; } } stockIndex++; } } PriceMaster pm = null; if (prod.Price_type == 1) //按比例拆分 { pm = _priceMasterMgr.QueryPriceMaster(new PriceMaster { site_id = 1, child_id = 0, user_level = 1, user_id = 0, product_id = c_product_id }); } else if (prod.Price_type == 2) //各自定價 { pm = _priceMasterMgr.QueryPriceMaster(new PriceMaster { site_id = 1, child_id = int.Parse(c_product_id.ToString()), user_level = 1, user_id = 0, product_id = pid }); } if (pm != null) { //計算Item的價格 ItemPriceCustom ipResult = new ItemPriceCustom(); IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); ipResult = iPMgr.Query(new ItemPrice { item_id = pItemResult.Item_Id, price_master_id = pm.price_master_id }).FirstOrDefault(); oc.product_name = pm.product_name; oc.price_master_id = pm.price_master_id; oc.Item_Money = ipResult.item_money; oc.product_cost = ipResult.item_money; oc.original_price = int.Parse(ipResult.item_money.ToString()); oc.Item_Cost = ipResult.item_cost; //計算必選商品之總價 if (item.S_Must_Buy > 0) { comboPrice += int.Parse((ipResult.item_money * item.S_Must_Buy).ToString()); comboCost += int.Parse((ipResult.item_cost * item.S_Must_Buy).ToString()); } orderAddList.Add(oc); } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } //將計算的最小庫存價賦值給組合商品 orderAdd.stock = minStock; //各自定價時將組合商品的定價賦值給組合商品 if (prod.Price_type == 2) { orderAdd.product_cost = int.Parse(comboPrice.ToString()); } //如果子商品含有規格則提示 if (hasSpec) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_NO_SPEC + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } jsonStr += ",child:["; string priceScales = "";//單一商品價格所占比例 string costScalses = ""; //單一商品成本所占比例 var rightList = orderAddList.Where(rec => rec.s_must_buy > 0).ToList(); var totalPrice = orderAdd.product_cost; //組合商品的定價 var totalCost = orderAdd.cost; //組合商品的成本 foreach (var item in rightList) { //如果組合商品的價格類型為 按比例拆分 則需重新為必選子商品定價 if (prod.Price_type == 1) { //if (comboCost != 0) if (comboPrice != 0) { //new logic 计算按比例拆分之比例 double priceScale = double.Parse((item.Item_Money * item.s_must_buy / comboPrice).ToString()); //double costScale = double.Parse((item.Item_Cost * item.s_must_buy / comboCost).ToString()); priceScales += priceScale + ","; //costScalses += costScale + ","; int afterPrice = Convert.ToInt16(Math.Round(totalPrice * priceScale / item.s_must_buy)); //int afterCost = Convert.ToInt16(Math.Round(totalCost * costScale / item.s_must_buy)); comboPrice -= Convert.ToInt16(item.Item_Money * item.s_must_buy); //comboCost -= Convert.ToInt16(item.Item_Cost * item.s_must_buy); totalPrice -= afterPrice * item.s_must_buy; //totalCost -= afterCost * item.s_must_buy; item.product_cost = uint.Parse(afterPrice.ToString()); //item.Item_Cost = uint.Parse(afterCost.ToString()); } else { priceScales += "0"; //costScalses += "0"; item.product_cost = 0; } } jsonStr += JsonConvert.SerializeObject(item); } //jsonStr = jsonStr.Substring(0, jsonStr.Length - 1); jsonStr = jsonStr.Replace("}{", "},{"); jsonStr += "],data:["; //拼接組合商品 s_must_buy:當前任選中必選商品的記錄數 jsonStr += "{product_id:'" + orderAdd.product_id + "',product_name:'" + orderAdd.product_name + "',Item_Cost:'" + orderAdd.cost + "',product_cost:'" + orderAdd.product_cost + "',item_id:0"; jsonStr += ",child_scale:'" + priceScales + "',child_cost_scale:'" + costScalses + "',stock:'" + minStock + "',g_must_buy:'" + prodComList[0].G_Must_Buy + "',s_must_buy:" + rightList.Count() + ""; jsonStr += ",combination:" + orderAdd.child + ",buy_limit:" + prodComList[0].Buy_Limit + ",child:" + orderAdd.child + ",childCount:" + orderAdd.childCount + ",childSum:" + childSum + ",price_type:" + orderAdd.price_type + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}]}"; } 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); } #endregion } else if (prod.Combination == 2) { #region 固定組合 try { OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = pid }, 1, 0, 1); jsonStr = "{success:true"; //查詢子商品信息 _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(pid.ToString()) }); IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString); IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString); foreach (var item in prodComList) { Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }).FirstOrDefault(); //補貨中停止販售 1:是 0:否 if (pResult.Shortage == 1) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } jsonStr += ",child:["; double totalPrice = 0; double totalCost = 0; double totalEventCost = 0; //add by zhuoqin0830w 2015/11/09 double totalEventPrice = 0;//add by zhuoqin0830w 2015/11/17 string priceScales = "";//單一商品價格所占比例 string costScales = ""; //單一商品成本所占比例 string eventcostScales = "";//單一商品活動成本所占比例 add by zhuoqin0830w 2015/11/09 string eventpriceScales = "";//單一商品活動價所占比例 add by zhuoqin0830w 2015/11/17 int minStock = 0; if (prod.Price_type == 1) { #region 按比例拆分 //計算子商品的總價 List<ProductItem> price_data_right_list = new List<ProductItem>(); foreach (var item in prodComList) { bool findState = false; List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }); List<ProductItem> pItemList = _proItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Child_Id.ToString()) }); //在item_price中查找對應item_id的商品規格價格 IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(item.Child_Id.ToString()), user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0 }); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { //add by zhuoqin0830w 2015/11/06 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本 if (time > pM.event_end) { pM.event_cost = 0; pM.event_price = 0; } //遍歷此商品所有item_id,找出第一筆在item_price中的item_id返回,若無,則此組合商品不能加入訂單 foreach (ProductItem items in pItemList) { ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(items.Item_Id.ToString()), price_master_id = pM.price_master_id }); if (ipList.Count == 1) { if (pM.same_price == 1) { totalPrice += pM.price * item.S_Must_Buy; totalCost += pM.cost * item.S_Must_Buy; totalEventCost += pM.event_cost * item.S_Must_Buy;//add by zhuoqin0830w 2015/11/09 totalEventPrice += pM.event_price * item.S_Must_Buy;//add by zhuoqin0830w 2015/11/17 } else { totalPrice += ipList[0].item_money * item.S_Must_Buy; totalCost += ipList[0].item_cost * item.S_Must_Buy; totalEventCost += ipList[0].event_cost * item.S_Must_Buy;//add by zhuoqin0830w 2015/11/09 totalEventPrice += ipList[0].event_money * item.S_Must_Buy;//add by zhuoqin0830w 2015/11/17 } price_data_right_list.Add(items); findState = true; break; } } if (!findState) { //在item_price中未查出對應價格 this.Response.Clear(); this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_PRICE_NULL + "'}"); this.Response.End(); return this.Response; } } else { //price_master表中沒有相對應的站台價格 add by zhuoqin0830w 2015/11/16 jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } int index = 0; int comboPrice = orderAdd.product_cost; //組合商品的定價 int comboCost = orderAdd.cost; int comboEventCost = 0; int comboEventPrice = 0; //add by zhuoqin0830w 2015/11/06 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本 if (orderAdd != null) { if (time > orderAdd.event_start && time < orderAdd.event_end) { comboEventCost = orderAdd.event_cost; comboEventPrice = orderAdd.event_price; } else { orderAdd.event_cost = 0; orderAdd.event_price = 0; } } for (int i = 0; i < prodComList.Count; i++) { index++; OrderAddCustom oc = new OrderAddCustom(); oc.Product_Id = uint.Parse(prodComList[i].Child_Id.ToString()); oc.parent_id = prodComList[i].Parent_Id; //讀取product_name IPriceMasterImplMgr pMgr = new PriceMasterMgr(connectionString); PriceMaster pm = pMgr.QueryPriceMaster(new PriceMaster { site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0, user_level = 1, user_id = 0, product_id = oc.Product_Id }); if (pm != null) { oc.product_name = pm.product_name; } oc.s_must_buy = prodComList[i].S_Must_Buy; if (price_data_right_list.Count != 0) { if (index == 1) { //最小庫存為組合下子商品的最小庫存/該子商品必購數量(如果必購數量為0則按1計算) minStock = int.Parse((price_data_right_list[i].Item_Stock / (prodComList[i].S_Must_Buy == 0 ? 1 : prodComList[i].S_Must_Buy)).ToString()); } Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(prodComList[i].Child_Id.ToString()) }).FirstOrDefault(); //有規格 oc.Spec_Name_1 = price_data_right_list[i].Spec_Name_1; oc.Spec_Name_2 = price_data_right_list[i].Spec_Name_2; oc.Item_Stock = price_data_right_list[i].Item_Stock; oc.Item_Id = price_data_right_list[i].Item_Id; int curStock = int.Parse((oc.Item_Stock / (prodComList[i].S_Must_Buy == 0 ? 1 : prodComList[i].S_Must_Buy)).ToString()); if (curStock < minStock) { minStock = curStock; } oc.Spec_Id_1 = price_data_right_list[i].Spec_Id_1; oc.Spec_Id_2 = price_data_right_list[i].Spec_Id_2; oc.ignore_stock = pResult.Ignore_Stock; //在item_price中查找對應item_id的商品規格價格 IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(price_data_right_list[i].Product_Id.ToString()), user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0 }); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { double singlePrice = 0; double singleCost = 0; double singleEventCost = 0;//add by zhuoqin0830w 2015/11/09 double singleEventPrice = 0;//add by zhuoqin0830w 2015/11/17 if (pM.same_price == 1) { oc.original_price = pM.price; oc.Item_Cost = uint.Parse(pM.cost.ToString()); oc.Event_Item_Cost = uint.Parse(pm.event_cost.ToString());//add by zhuoqin0830w 2015/11/09 oc.Event_Item_Money = uint.Parse(pm.event_price.ToString());//add by zhuoqin0830w 2015/11/17 singlePrice = pM.price * oc.s_must_buy; singleCost = pM.cost * oc.s_must_buy; singleEventCost = pM.event_cost * oc.s_must_buy;//add by zhuoqin0830w 2015/11/09 singleEventPrice = pM.event_price * oc.s_must_buy;//add by zhuoqin0830w 2015/11/17 } else { ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(price_data_right_list[i].Item_Id.ToString()), price_master_id = pM.price_master_id }); if (ipList.Count == 1) { oc.original_price = int.Parse(ipList[0].item_money.ToString()); oc.Item_Cost = ipList[0].item_cost; oc.Event_Item_Cost = ipList[0].event_cost;//add by zhuoqin0830w 2015/11/09 oc.Event_Item_Money = ipList[0].event_money;//add by zhuoqin0830w 2015/11/17 singlePrice = ipList[0].item_money * oc.s_must_buy; singleCost = ipList[0].item_cost * oc.s_must_buy; singleEventCost = ipList[0].event_cost * oc.s_must_buy;//add by zhuoqin0830w 2015/11/09 singleEventPrice = ipList[0].event_money * oc.s_must_buy;//add by zhuoqin0830w 2015/11/17 } } if (totalPrice == 0) { priceScales += "0"; costScales += "0"; eventcostScales += "0";//add by zhuoqin0830w 2015/11/09 eventpriceScales += "0";//add by zhuoqin0830w 2015/11/09 oc.product_cost = 0; } else { //new logic 算比例 double priceScale = double.Parse((singlePrice / totalPrice).ToString()); double costScale = double.Parse((singleCost / totalCost).ToString()); //add by zhuoqin0830w 2015/11/09 添加活動成本的比例 double eventcostScale = 0; if (totalEventCost != 0) { eventcostScale = double.Parse((singleEventCost / totalEventCost).ToString()); } else { eventcostScale = priceScale;// 如果 活動成本的比例為0 則表示沒有活動成本則按照價格的比例進行計算 } double eventpriceScale = 0; if (totalEventPrice != 0) { eventpriceScale = double.Parse((singleEventPrice / totalEventPrice).ToString()); } else { eventpriceScale = priceScale;// 如果 活動價的比例為0 則表示沒有活動成本則按照價格的比例進行計算 } priceScales += priceScale + ","; costScales += costScale + ","; eventcostScales += eventcostScale + ",";//add by zhuoqin0830w 2015/11/09 eventpriceScales += eventpriceScale + ",";//add by zhuoqin0830w 2015/11/17 var afterprice = Convert.ToInt16(Math.Round(comboPrice * priceScale / oc.s_must_buy)); var aftercost = Convert.ToInt16(Math.Round(comboCost * costScale / oc.s_must_buy)); var aftereventcost = Convert.ToInt16(Math.Round(comboEventCost * eventcostScale / oc.s_must_buy));//add by zhuoqin0830w 2015/11/09 var aftereventprice = Convert.ToInt16(Math.Round(comboEventPrice * eventpriceScale / oc.s_must_buy));//add by zhuoqin0830w 2015/11/17 comboPrice -= afterprice * oc.s_must_buy; comboCost -= aftercost * oc.s_must_buy; comboEventCost -= aftereventcost * oc.s_must_buy;//add by zhuoqin0830w 2015/11/09 comboEventPrice -= aftereventprice * oc.s_must_buy;//add by zhuoqin0830w 2015/11/17 totalPrice -= singlePrice; totalCost -= singleCost; totalEventCost -= singleEventCost;//add by zhuoqin0830w 2015/11/09 totalEventPrice -= singleEventPrice;//add by zhuoqin0830w 2015/11/17 oc.product_cost = uint.Parse(afterprice.ToString()); oc.Item_Cost = uint.Parse(aftercost.ToString()); oc.Event_Item_Cost = uint.Parse(aftereventcost.ToString());//add by zhuoqin0830w 2015/11/09 oc.Event_Item_Money = uint.Parse(aftereventprice.ToString());//add by zhuoqin0830w 2015/11/17 } } } jsonStr += JsonConvert.SerializeObject(oc) + ","; } #endregion } else { #region 各自定價 orderAdd.product_cost = 0; foreach (var item in prodComList) { Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }).FirstOrDefault(); OrderAddCustom oc = new OrderAddCustom(); oc.price_type = prod.Price_type; oc.parent_id = item.Parent_Id; oc.Product_Id = uint.Parse(item.Child_Id.ToString()); List<ProductItem> pItemList = _proItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Child_Id.ToString()) }); if (prodComList.IndexOf(item) == 0) { minStock = int.Parse((pItemList[0].Item_Stock / (item.S_Must_Buy == 0 ? 1 : item.S_Must_Buy)).ToString()); //最小庫存為組合下子商品的最小庫存/該子商品必購數量(如果必購數量為0則按1計算) } PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = pid, user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = Int32.Parse(item.Child_Id) //add by wangwei02016w 2014/9/24 }); ItemPriceCustom ip = new ItemPriceCustom(); IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); if (pM != null) { oc.product_name = pM.product_name; oc.price_master_id = pM.price_master_id; ip = iPMgr.Query(new ItemPrice { item_id = uint.Parse(pItemList[0].Item_Id.ToString()), price_master_id = pM.price_master_id }).First(); oc.Spec_Name_1 = pItemList[0].Spec_Name_1; oc.Spec_Name_2 = pItemList[0].Spec_Name_2; oc.Item_Stock = pItemList[0].Item_Stock; oc.Spec_Id_1 = pItemList[0].Spec_Id_1; oc.Spec_Id_2 = pItemList[0].Spec_Id_2; oc.ignore_stock = pResult.Ignore_Stock; int curStock = int.Parse((pItemList[0].Item_Stock / (item.S_Must_Buy == 0 ? 1 : item.S_Must_Buy)).ToString()); if (curStock < minStock) { minStock = curStock; } oc.Item_Id = pItemList[0].Item_Id; oc.product_cost = ip.item_money; oc.original_price = int.Parse(ip.item_money.ToString()); orderAdd.product_cost += Convert.ToInt32(oc.product_cost * item.S_Must_Buy); } oc.s_must_buy = item.S_Must_Buy; jsonStr += JsonConvert.SerializeObject(oc) + ","; } #endregion } jsonStr = jsonStr.Substring(0, jsonStr.Length - 1) + "]"; jsonStr += ",data:["; //拼接組合商品 cost為組合商品之成本,product_cost為組合商品之售價 jsonStr += "{product_id:'" + orderAdd.product_id + "',product_name:'" + orderAdd.product_name + "',Item_Cost:'" + orderAdd.cost + "',product_cost:'" + orderAdd.product_cost + "',item_id:0" + ",Event_Item_Cost:" + orderAdd.event_cost + ",Event_Item_Money:" + orderAdd.event_price; jsonStr += ",s_must_buy:'" + prodComList.Count + "',child_scale:'" + priceScales + "',child_cost_scale:'" + costScales + "',child_event_cost_scale:'" + eventcostScales + "',stock:'" + minStock + "',g_must_buy:'" + prodComList.Count + "',child:" + orderAdd.child + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}"; jsonStr += "]}"; } 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); } #endregion } else { #region 單一商品 // 判斷 輸入的商品是否是單一商品 並且是 內部訂單輸入 如果是 則彈出提示框 add by zhuoqin0830w 2015/07/10 if (Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd") { if (prod.Combination == 1 && Convert.ToInt32(Request.Params["pid"].Length) != 6 && Request.Params["parent_id"] == "") { this.Response.Clear(); this.Response.Write("{success:false,msg:'單一商品必須輸入六碼編號!'}"); this.Response.End(); return this.Response; } } IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString); Product p = new Product(); p.Product_Id = pid; ProductItem pItem = new ProductItem(); pItem.Product_Id = pid; UInt32.TryParse(Request.Params["spec1"] ?? "0", out spec1); UInt32.TryParse(Request.Params["spec2"] ?? "0", out spec2); pItem.Spec_Id_1 = spec1; pItem.Spec_Id_2 = spec2; try { List<OrderAddCustom> oalist = new List<OrderAddCustom>(); OrderAddCustom oc = new OrderAddCustom(); List<Product> pList = _proMgr.Query(p); List<ProductItem> pItemList = _proItemMgr.Query(pItem); if (pList.Count() <= 0 || pItemList.Count() <= 0) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}";//商品不存在 this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } //補貨中停止販售 1:是 0:否 if (pList[0].Shortage == 1) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}";//補貨中不能販賣 this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } int parent_id = 0; int price_type = 0; uint c_combination = 0; int c_buy_limit = 0; //組合商品子商品查詢 if (!string.IsNullOrEmpty(Request.Params["parent_id"])) { parent_id = int.Parse(Request.Params["parent_id"]); //查詢組合商品的價格類型 Product parentResult = _proMgr.Query(new Product { Product_Id = uint.Parse(parent_id.ToString()) }).FirstOrDefault(); if (parentResult != null) { price_type = parentResult.Price_type; c_combination = parentResult.Combination; } oc.price_type = price_type; //找出該商品在組合商品中的必購數量 _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = parent_id, Child_Id = pid.ToString() });//add by wangwei02016w 2014/9/24 if (prodComList.Count == 1) { oc.s_must_buy = prodComList[0].S_Must_Buy; c_buy_limit = prodComList[0].Buy_Limit; } } //在item_price中查找對應item_id的商品規格價格 IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString); IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = null; if (price_type == 2) //各自定價時取價格 { pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(parent_id.ToString()), user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = int.Parse(pList[0].Product_Id.ToString()) }); } else { pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = pList[0].Product_Id, user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0 }); } if (pM != null) { oc.price_master_id = pM.price_master_id; List<ItemPriceCustom> ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(pItemList[0].Item_Id.ToString()), price_master_id = pM.price_master_id }); oc.Product_Id = pList[0].Product_Id; oc.product_name = pList[0].Product_Name; oc.Spec_Id_1 = pItemList[0].Spec_Id_1; oc.Spec_Id_2 = pItemList[0].Spec_Id_2; oc.Item_Id = pItemList[0].Item_Id; oc.Item_Stock = pItemList[0].Item_Stock; if (ipList.Count() > 0) { //edit by zhuoqin0830w 2015/11/16 將售價和活動售價的邏輯改為與成本和活動成本的邏輯一樣 eric說需要修改 if (pM.same_price == 1) { oc.Item_Cost = uint.Parse(pM.cost.ToString());//成本 oc.Item_Money = uint.Parse(pM.price.ToString());//定價 } else { oc.Item_Cost = ipList[0].item_cost; oc.Item_Money = ipList[0].item_money; } //add by zhuoqin0830w 2015/11/06 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本 if (time > pM.event_start && time < pM.event_end) { oc.Event_Item_Cost = uint.Parse(pM.event_cost.ToString()); //add by zhuoqin0830w 2015/11/16 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動售價為 0 如果沒有過期則顯示活動售價 oc.Event_Item_Money = uint.Parse(pM.event_price.ToString()); } else { oc.Event_Item_Cost = 0; oc.Event_Item_Money = 0; } } else { this.Response.Clear(); this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SINGLE_SPEC_PRICE_WRONG + "'}"); this.Response.End(); return this.Response; } IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString); List<ProductSpec> specList1 = _specMgr.query(Int32.Parse(pItemList[0].Product_Id.ToString()), "spec_id_1"); List<ProductSpec> specList2 = _specMgr.query(Int32.Parse(pItemList[0].Product_Id.ToString()), "spec_id_2"); oc.specList1 = specList1; oc.specList2 = specList2; oalist.Add(oc); StringBuilder stb = new StringBuilder(); stb.Append("["); stb.Append("{product_id:" + oc.Product_Id + ",price_type:" + oc.price_type + ",child:" + c_combination + ",buy_limit:" + c_buy_limit + ",item_id:" + oc.Item_Id + ",product_name:'" + oc.product_name + "',"); //添加 活動成本 金額顯示 ",Event_Item_Cost:" + pM.event_cost zhuoqin0830w 2015/04/30 添加活動售價 ",Event_Item_Money:" + oc.Event_Item_Money zhuoqin0830w 2015/11/16 stb.Append("product_cost:" + oc.Item_Money + ",Event_Item_Money:" + oc.Event_Item_Money + ",Item_Cost:" + oc.Item_Cost + ",Event_Item_Cost:" + pM.event_cost + ",stock:" + oc.Item_Stock + ",s_must_buy:" + oc.s_must_buy + ",Spec_Name_1:'" + pItemList[0].Spec_Name_1 + "',Spec_Name_2:'" + pItemList[0].Spec_Name_2 + "',spec1:" + pItemList[0].Spec_Id_1 + ",spec2:" + pItemList[0].Spec_Id_2 + ",price_master_id:" + oc.price_master_id + ",ignore_stock:" + pList[0].Ignore_Stock + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}"); stb.Append("]"); jsonStr = "{success:true,data:" + stb.ToString() + "}"; } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}"; } } 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); } #endregion } } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_DOWN + "'}"; } } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}"; } } else { jsonStr = "[{success:true,data:{product_id:''}}]"; } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }