public HttpResponseBase GetCatagory() { List<ProductCategory> categoryList = new List<ProductCategory>(); List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>(); int categoryType = 2; //用來區別查詢所有節點還是查詢新館的節點 //edit by wwei0216w 2014/12/25 //從後臺獲取查詢所有節點還是查詢新館的節點 categoryType = Request["categoryType"] == null ? 2 : Convert.ToInt32(Request["categoryType"]); string resultStr = ""; try { _procateMgr = new ProductCategoryMgr(connectionString); categoryList = _procateMgr.QueryAll(new ProductCategory { }); cateList = getCate(categoryList, 0); List<ProductCategorySet> resultList = new List<ProductCategorySet>(); if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { _categorySetMgr = new ProductCategorySetMgr(connectionString); resultList = _categorySetMgr.Query(new ProductCategorySet { Product_Id = uint.Parse(Request.Params["ProductId"]) }); } else { Caller _caller = (Session["caller"] as Caller); ProductCategorySetTemp query = new ProductCategorySetTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE }; _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString); if (!string.IsNullOrEmpty(Request.Params["OldProductId"]))//edit by xiaohui 2014/09/24 { query.Product_Id = Request.Params["OldProductId"]; } resultList = (from c in _categoryTempSetMgr.Query(query) select new { Id = c.Id, Product_Id = c.Product_Id, Category_Id = c.Category_Id, Brand_Id = c.Brand_Id }).ToList().ConvertAll<ProductCategorySet>(m => new ProductCategorySet() { Id = m.Id, Product_Id = uint.Parse(m.Product_Id), Category_Id = m.Category_Id, Brand_Id = m.Brand_Id }); } GetCategoryList(categoryList, ref cateList, resultList); switch (categoryType) { case 0: resultStr = JsonConvert.SerializeObject(cateList); break; case 1: //等於754 cateList.FindAll(m => m.id == "2")[0].children.RemoveAll(m => m.id != "754");//移除新館節點 resultStr = JsonConvert.SerializeObject(cateList); break; case 2: cateList.FindAll(m => m.id == "2")[0].children.RemoveAll(m => m.id == "754");//移除新館節點 resultStr = JsonConvert.SerializeObject(cateList); break; } resultStr = resultStr.Replace("Checked", "checked"); } 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(resultStr); this.Response.End(); return this.Response; }
public HttpResponseBase tempCategoryAdd() { Caller _caller = (Session["caller"] as Caller); string resultStr = "{success:true}"; string tempStr = Request.Params["result"]; string cate_id = Request.Params["cate_id"]; string deStr = Request["oldresult"] == null ? "0" : Request["oldresult"]; List<ProductCategorySetTemp> saveTempList = new List<ProductCategorySetTemp>(); try { JavaScriptSerializer js = new JavaScriptSerializer(); List<ProductCategorySetCustom> cateCustomList = js.Deserialize<List<ProductCategorySetCustom>>(tempStr); if (string.IsNullOrEmpty(tempStr)) { cateCustomList = new List<ProductCategorySetCustom>(); } if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { #region 修改正式表 uint pid = uint.Parse(Request.Params["ProductId"]); _tableHistoryMgr = new TableHistoryMgr(connectionString); _categorySetMgr = new ProductCategorySetMgr(connectionString); _productMgr = new ProductMgr(connectionString); Product pro = new Product(); pro = _productMgr.Query(new Product { Product_Id = pid }).FirstOrDefault(); pro.Cate_Id = cate_id; _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; ArrayList sqls = new ArrayList(); sqls.Add(_categorySetMgr.Delete(new ProductCategorySet { Product_Id = pid })); sqls.Add(_productMgr.Update(pro)); foreach (ProductCategorySetCustom item in cateCustomList) { item.Product_Id = pid; item.Brand_Id = pro.Brand_Id; sqls.Add(_categorySetMgr.Save(item)); } if (!_tableHistoryMgr.SaveHistory<ProductCategorySetCustom>(cateCustomList, batch, sqls)) { resultStr = "{success:false}"; } #endregion } else { #region 修改臨時表 string product_id = "0"; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { product_id = Request.Form["OldProductId"]; } _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString); _productTempMgr = new ProductTempMgr(connectionString); if (string.IsNullOrEmpty(tempStr)) { bool result = _categoryTempSetMgr.Delete(new ProductCategorySetTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }, deStr); } else { ProductCategorySetTemp saveTemp; ProductTemp query = new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id.ToString() }; ProductTemp proTemp = _productTempMgr.GetProTemp(query); foreach (ProductCategorySetCustom item in cateCustomList) { saveTemp = new ProductCategorySetTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Product_Id = product_id; saveTemp.Category_Id = item.Category_Id; saveTemp.Brand_Id = proTemp.Brand_Id; saveTemp.Combo_Type = COMBO_TYPE; saveTempList.Add(saveTemp); } if (!_categoryTempSetMgr.Save(saveTempList)) { resultStr = "{success:false}"; } } if (!_productTempMgr.CategoryInfoUpdate(new ProductTemp { Writer_Id = _caller.user_id, Cate_Id = cate_id, Combo_Type = COMBO_TYPE, Product_Id = product_id.ToString() })) { resultStr = "{success:false}"; } #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); resultStr = "{success:false}"; } this.Response.Clear(); this.Response.Write(resultStr); this.Response.End(); return this.Response; }
public ActionResult tempCategoryAdd(int categoryType, int coboType = 1) { COMBO_TYPE = coboType; string resultStr = "{success:true}"; string oldresult = Request["oldresult"];//add by wwei0216w 2014/12/26 需要刪除的選中項 if (string.IsNullOrEmpty(oldresult)) { resultStr = "{success:false}"; return Content(resultStr); } try { Caller _caller = (Session["caller"] as Caller); string tempStr = ""; string cate_id = ""; if (!string.IsNullOrEmpty(Request.Params["result"])) { tempStr = Request.Params["result"]; } if (!string.IsNullOrEmpty(Request.Params["cate_id"])) { cate_id = Request.Params["cate_id"]; } List<ProductCategorySetTemp> saveTempList = new List<ProductCategorySetTemp>(); JavaScriptSerializer js = new JavaScriptSerializer(); List<ProductCategorySetCustom> cateCustomList = js.Deserialize<List<ProductCategorySetCustom>>(tempStr); string deStr = ""; //if (categoryType == 2)//新類別 //{ // if (cateCustomList.Count() <= 0) // { // resultStr = "{success:false,msg:'新類別必選'}"; // return Content(resultStr); // } //} #region 將要刪除的id 拼成 '1,2,3'這種形式 List<ProductCategorySetCustom> deleteCategorySet = js.Deserialize<List<ProductCategorySetCustom>>(oldresult); if (deleteCategorySet.Count() > 0) { foreach (var item in deleteCategorySet) { deStr += item.Category_Id + ","; } deStr = deStr.Remove(deStr.Length - 1); } #endregion if (string.IsNullOrEmpty(tempStr)) { cateCustomList = new List<ProductCategorySetCustom>(); } if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { #region 修改正式表 uint pid = uint.Parse(Request.Params["ProductId"]); _tableHistoryMgr = new TableHistoryMgr(connectionString); _categorySetMgr = new ProductCategorySetMgr(connectionString); _productMgr = new ProductMgr(connectionString); Product pro = new Product(); pro = _productMgr.Query(new Product { Product_Id = pid }).FirstOrDefault(); if (pro != null) { _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; ArrayList sqls = new ArrayList(); if (deStr != "") { sqls.Add(_categorySetMgr.Delete(new ProductCategorySet { Product_Id = pid }, deStr)); } if (categoryType == 1) { pro.Cate_Id = cate_id; } else if (categoryType == 2) //edit by wwei0216w 如果是新類別 就不進行報表修改 { pro.Prod_Classify = Convert.ToInt32(Request["prodClassify"]); //獲得對應館別ID _tableHistoryMgr.SaveHistory<Product>(pro, batch, null); } sqls.Add(_productMgr.Update(pro, _caller.user_id)); foreach (ProductCategorySetCustom item in cateCustomList) { item.Product_Id = pid; item.Brand_Id = pro.Brand_Id; sqls.Add(_categorySetMgr.Save(item)); } if (!_tableHistoryMgr.SaveHistory<ProductCategorySetCustom>(cateCustomList, batch, sqls)) { throw new Exception("there is no History be saved"); } //else //{ //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30 // if (pro.Combination == 1) // { // _productItemMgr = new ProductItemMgr(connectionString); // ProductItem pro_Item = new ProductItem() { Product_Id = pro.Product_Id, Export_flag = 2 }; // _productItemMgr.UpdateExportFlag(pro_Item); // } //} } else { throw new Exception("None Product has being found"); } #endregion } else { #region 修改臨時表 string product_id = "0"; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { product_id = Request.Form["OldProductId"]; } _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString); _productTempMgr = new ProductTempMgr(connectionString); bool result = _categoryTempSetMgr.Delete(new ProductCategorySetTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }, deStr); ProductTemp query = new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }; ProductTemp proTemp = _productTempMgr.GetProTemp(query); ProductCategorySetTemp saveTemp; if (proTemp == null) { resultStr = "{success:false}"; } else { foreach (ProductCategorySetCustom item in cateCustomList) { saveTemp = new ProductCategorySetTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Product_Id = product_id; saveTemp.Category_Id = item.Category_Id; saveTemp.Brand_Id = proTemp.Brand_Id; saveTemp.Combo_Type = COMBO_TYPE; saveTempList.Add(saveTemp); } if (!_categoryTempSetMgr.Save(saveTempList)) { resultStr = "{success:false}"; } } proTemp.Combo_Type = COMBO_TYPE; proTemp.Product_Id = product_id; if (categoryType == 1) { proTemp.Cate_Id = cate_id; } else if (categoryType == 2) //edit by wwei0216w 如果是新類別 就不進行報表修改 { proTemp.Prod_Classify = Convert.ToInt32(Request["prodClassify"]); //獲得對應館別ID } if (!_productTempMgr.CategoryInfoUpdate(proTemp)) { resultStr = "{success:false}"; } #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); resultStr = "{success:false}"; return Content(resultStr); } return Content(resultStr); ////this.Response.Clear(); ////this.Response.Write(resultStr); ////this.Response.End(); ////return this.Response; }
public HttpResponseBase tempCategoryAdd() { BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; int writd_Id = (int)vendorModel.vendor_id; string resultStr = "{success:true}"; string tempStr = Request.Params["result"]; string cate_id = Request.Params["cate_id"]; List<ProductCategorySetTemp> saveTempList = new List<ProductCategorySetTemp>(); try { JavaScriptSerializer js = new JavaScriptSerializer(); List<ProductCategorySetCustomTemp> cateCustomList = js.Deserialize<List<ProductCategorySetCustomTemp>>(tempStr); if (string.IsNullOrEmpty(tempStr)) { cateCustomList = new List<ProductCategorySetCustomTemp>(); } string vendor_pId = string.Empty; if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { vendor_pId = Request.Params["ProductId"]; //if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) //{ // vendor_pId = Request.Form["OldProductId"]; //} _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString); _productTempMgr = new ProductTempMgr(connectionString); if (string.IsNullOrEmpty(tempStr)) { bool result = _categoryTempSetMgr.DeleteByVendor(new ProductCategorySetTemp { Writer_Id = writd_Id, Combo_Type = COMBO_TYPE, Product_Id = vendor_pId }); } else { ProductCategorySetTemp saveTemp; ProductTemp query = new ProductTemp { Writer_Id = writd_Id, Combo_Type = COMBO_TYPE, Product_Id = vendor_pId }; ProductTemp proTemp = _productTempMgr.GetVendorProTemp(query); foreach (ProductCategorySetCustomTemp item in cateCustomList) { saveTemp = new ProductCategorySetTemp(); saveTemp.Writer_Id = writd_Id; saveTemp.Product_Id = vendor_pId; saveTemp.Category_Id = item.Category_Id; saveTemp.Brand_Id = proTemp.Brand_Id; saveTemp.Combo_Type = COMBO_TYPE; saveTempList.Add(saveTemp); } if (!_categoryTempSetMgr.SaveByVendor(saveTempList)) { resultStr = "{success:false}"; } } if (!_productTempMgr.CategoryInfoUpdateByVendor(new ProductTemp { Writer_Id = writd_Id, Cate_Id = cate_id, Combo_Type = COMBO_TYPE, Product_Id = vendor_pId })) { resultStr = "{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); resultStr = "{success:false}"; } this.Response.Clear(); this.Response.Write(resultStr); this.Response.End(); return this.Response; }
public HttpResponseBase GetCatagory(string id = "true") { List<ProductCategory> categoryList = new List<ProductCategory>(); List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>(); string resultStr = ""; BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; try { _procateMgr = new ProductCategoryMgr(connectionString); categoryList = _procateMgr.QueryAll(new ProductCategory { }); cateList = getCate(categoryList, "5"); List<ProductCategorySetTemp> TempresultList = new List<ProductCategorySetTemp>(); List<ProductCategorySet> resultList = new List<ProductCategorySet>(); ProductCategorySetTemp query = new ProductCategorySetTemp(); if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { uint product_id = 0; if (uint.TryParse(Request.Params["ProductId"], out product_id)) //正式表數據 { _categorySetMgr = new ProductCategorySetMgr(connectionString); resultList = _categorySetMgr.Query(new ProductCategorySet { Product_Id = uint.Parse(Request.Params["ProductId"]) }); TempresultList = null; } else { resultList = null; query.Product_Id = Request.Params["ProductId"]; _productTempMgr = new ProductTempMgr(connectionString); ProductTemp productT = _productTempMgr.GetProTempByVendor(new ProductTemp { Product_Id = Request.Params["ProductId"] }).FirstOrDefault(); if (productT != null) { query.Combo_Type = productT.Combo_Type; } else { query.Combo_Type = COMBO_TYPE; } query.Writer_Id = (int)vendorModel.vendor_id; _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString); TempresultList = (from c in _categoryTempSetMgr.QueryByVendor(query) select new { Id = c.Id, Product_Id = c.Product_Id, Category_Id = c.Category_Id, Brand_Id = c.Brand_Id }).ToList().ConvertAll<ProductCategorySetTemp>(m => new ProductCategorySetTemp { Id = m.Id, Product_Id = m.Product_Id, Category_Id = m.Category_Id, Brand_Id = m.Brand_Id }); } } //調試resultlist是否為空 GetCategoryList(categoryList, ref cateList, TempresultList, resultList); List<ProductCategoryCustom> cateListResult = new List<ProductCategoryCustom>(); cateListResult = getCate(categoryList, "0"); cateListResult[0].children = getCate(categoryList, cateListResult[0].id.ToString()); int cateLen = cateListResult[0].children.Count; int i = 0; while (cateLen > 0) { if (cateListResult[0].children[i].id == "5") { i++; } else { cateListResult[0].children.Remove(cateListResult[0].children[i]); } cateLen--; } cateListResult[0].children[0].children = cateList; resultStr = JsonConvert.SerializeObject(cateListResult); resultStr = resultStr.Replace("Checked", "checked"); } 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(resultStr); this.Response.End(); return this.Response; }
public HttpResponseBase GetCatagory() { List<ProductCategory> categoryList = new List<ProductCategory>(); List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>(); string resultStr = ""; try { _procateMgr = new ProductCategoryMgr(connectionString); categoryList = _procateMgr.QueryAll(new ProductCategory { }); cateList = getCate(categoryList, "5"); List<ProductCategorySetTemp> TempresultList = new List<ProductCategorySetTemp>(); List<ProductCategorySet> resultList = new List<ProductCategorySet>(); string Ven_product_id = string.Empty; if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { Ven_product_id = Request.Params["ProductId"]; } //if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) //{ // Ven_product_id = Request.Form["OldProductId"]; //} BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; int writd_Id = Convert.ToInt32(vendorModel.vendor_id); ProductCategorySetTemp query = new ProductCategorySetTemp { Writer_Id = writd_Id, Combo_Type = COMBO_TYPE, Product_Id = Ven_product_id }; _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString); TempresultList = (from c in _categoryTempSetMgr.QueryByVendor(query) select new { Id = c.Id, Product_Id = c.Product_Id, Category_Id = c.Category_Id, Brand_Id = c.Brand_Id }).ToList().ConvertAll<ProductCategorySetTemp>(m => new ProductCategorySetTemp() { Id = m.Id, Product_Id = m.Product_Id, Category_Id = m.Category_Id, Brand_Id = m.Brand_Id }); GetCategoryList(categoryList, ref cateList, TempresultList, resultList); List<ProductCategoryCustom> cateListResult = new List<ProductCategoryCustom>(); cateListResult = getCate(categoryList, "0"); cateListResult[0].children = getCate(categoryList, cateListResult[0].id.ToString()); int cateLen = cateListResult[0].children.Count; int i = 0; while (cateLen > 0) { if (cateListResult[0].children[i].id.ToString() == "5") { i++; } else { cateListResult[0].children.Remove(cateListResult[0].children[i]); } cateLen--; } cateListResult[0].children[0].children = cateList; resultStr = JsonConvert.SerializeObject(cateListResult); resultStr = resultStr.Replace("Checked", "checked"); } 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(resultStr); this.Response.End(); return this.Response; }