public DataOperation(List<Model.MigrationDataSet> mds, MainForm form) { this.mds = mds; this.connectionString = System.Configuration.ConfigurationSettings.AppSettings["MySqlConnectionString"]; prod = new Product(); pItem = new ProductItem(); pM = new PriceMaster(); iPrice = new ItemPrice(); categorySet = new ProductCategorySet(); pMap = new ProductMigrationMap(); _prodMgr = new ProductMgr(this.connectionString); _priceMgr = new PriceMasterMgr(this.connectionString); _prodItemMgr = new ProductItemMgr(this.connectionString); _itemPriceMgr = new ItemPriceMgr(this.connectionString); _vendorBrandMgr = new VendorBrandMgr(this.connectionString); _vendorMgr = new VendorMgr(this.connectionString); _pMap = new ProductMigrationMgr(this.connectionString); _productCategorySetMgr = new ProductCategorySetMgr(this.connectionString); _productNoticeSetMgr = new ProductNoticeSetMgr(this.connectionString); _productTagSetMgr = new ProductTagSetMgr(this.connectionString); _productPictureMgr = new ProductPictureMgr(this.connectionString); _proStatusHistoryMgr = new ProductStatusHistoryMgr(connectionString); _proSpecMgr = new ProductSpecMgr(connectionString); _siteMgr = new SiteMgr(connectionString); this.form = form; }
public HttpResponseBase productPictrueTempSave() { string json = "{success:true}"; ProductTemp pTemp = new ProductTemp(); _productTempMgr = new ProductTempMgr(connectionString); _specTempMgr = new ProductSpecTempMgr(connectionString); _productPicMgr = new ProductPictureMgr(connectionString); _specMgr = new ProductSpecMgr(connectionString); if (string.IsNullOrEmpty(Request.Params["product_id"])) { if (!string.IsNullOrEmpty(Request.Params["image_InsertValue"])) pTemp.Product_Image = Request.Params["image_InsertValue"]; if (!string.IsNullOrEmpty(Request.Params["image_MobileValue"])) pTemp.Mobile_Image = Request.Params["image_MobileValue"];//如果手機說明圖有值,將值賦予Moibile_Image edit by wwei0216w 2015/3/18 if (!string.IsNullOrEmpty(Request.Params["productMedia"])) pTemp.product_media = Request.Params["productMedia"]; if (!string.IsNullOrEmpty(Request.Params["specify_Product_alt"])) pTemp.Product_alt = Request.Params["specify_Product_alt"];//add by wwei0216w 2015/4/9 pTemp.Writer_Id = (Session["caller"] as Caller).user_id; pTemp.Combo_Type = COMBO_TYPE; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { pTemp.Product_Id = Request.Form["OldProductId"]; } ProductSpecTemp pSpec = new ProductSpecTemp(); List<ProductSpecTemp> pSpecList = new List<ProductSpecTemp>(); if (!string.IsNullOrEmpty(Request.Params["spec_InsertValue"])) { string[] Values = Request.Form["spec_InsertValue"].ToString().Split(';'); for (int i = 0; i < Values.Length - 1; i++) { pSpec = new ProductSpecTemp(); pSpec.Writer_Id = (Session["caller"] as Caller).user_id; pSpec.product_id = pTemp.Product_Id; string[] perValue = Values[i].Split(','); if (!string.IsNullOrEmpty(perValue[0])) { pSpec.spec_image = perValue[0]; }; if (!string.IsNullOrEmpty(perValue[1])) { pSpec.spec_id = uint.Parse(perValue[1]); }; if (!string.IsNullOrEmpty(perValue[2])) { pSpec.spec_sort = uint.Parse(perValue[2]); }; if (!string.IsNullOrEmpty(perValue[3])) { pSpec.spec_status = uint.Parse(perValue[3]); }; pSpecList.Add(pSpec); } } List<ProductPictureTemp> picList = new List<ProductPictureTemp>(); _pPicTempMgr = new ProductPictureTempImplMgr(connectionString); ProductPictureTemp pPic = new ProductPictureTemp(); if (!string.IsNullOrEmpty(Request.Params["picture_InsertValue"])) { string[] Values = Request.Form["picture_InsertValue"].ToString().Split(';'); for (int i = 0; i < Values.Length - 1; i++) { pPic = new ProductPictureTemp(); string[] perValue = Values[i].Split(','); pPic.combo_type = COMBO_TYPE; pPic.writer_Id = (Session["caller"] as Caller).user_id; pPic.product_id = pTemp.Product_Id; if (!string.IsNullOrEmpty(perValue[0])) { pPic.image_filename = perValue[0]; }; if (!string.IsNullOrEmpty(perValue[1])) { pPic.image_sort = uint.Parse(perValue[1]); }; if (!string.IsNullOrEmpty(perValue[2])) { pPic.image_state = uint.Parse(perValue[2]); }; picList.Add(pPic); } } //關於手機APP的代碼部份 List<ProductPictureTemp> picAppList = new List<ProductPictureTemp>(); //IProductPictureTempImplAppMgr ppt = new ProductPictureAppTempImplMgr(connectionString); ProductPictureTemp pa = new ProductPictureTemp(); if (!string.IsNullOrEmpty(Request.Params["mobilePic_InsertValue"])) { string[] Values = Request.Form["mobilePic_InsertValue"].ToString().Split(';'); for (int i = 0; i < Values.Length - 1; i++) { pa = new ProductPictureTemp(); string[] AppValue = Values[i].Split(','); pa.combo_type = COMBO_TYPE; pa.writer_Id = (Session["caller"] as Caller).user_id; pa.product_id = pTemp.Product_Id; if (!string.IsNullOrEmpty(AppValue[0])) { pa.image_filename = AppValue[0]; }; if (!string.IsNullOrEmpty(AppValue[1])) { pa.image_sort = uint.Parse(AppValue[1]); }; if (!string.IsNullOrEmpty(AppValue[2])) { pa.image_state = uint.Parse(AppValue[2]); }; picAppList.Add(pa); } } try { int type = 1;//1:商品說明圖,2:手機App說明圖 int writer_id = (Session["caller"] as Caller).user_id; //保存至productTemp if (pTemp.Product_Image != "" || pTemp.product_media != "" || pTemp.Mobile_Image != "" || pTemp.Product_alt != "") { _productTempMgr.ProductTempUpdate(pTemp, "pic"); } //保存規格圖 _specTempMgr.Update(pSpecList, "image"); //保存說明圖 string oldProductId = "0"; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { oldProductId = Request.Form["OldProductId"]; } _pPicTempMgr.Save(picList, new ProductPictureTemp() { writer_Id = writer_id, combo_type = COMBO_TYPE, product_id = oldProductId }, type);// edit by wangwei0216w 註釋掉_pPicTempMgr.Save 以解決複製后不能讀取圖片路勁到數據庫 type = 2; _pPicTempMgr.Save(picAppList, new ProductPictureTemp() { writer_Id = writer_id, combo_type = COMBO_TYPE, product_id = oldProductId }, type); } 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.EDIT_FAIL + "\"}"; } } else//更新正式表 { Product p = new Product(); uint productId = uint.Parse(Request.Params["product_id"]); if (!string.IsNullOrEmpty(Request.Params["image_InsertValue"])) p.Product_Image = Request.Params["image_InsertValue"];//如果商品說明圖有值,將值賦予Product_Image if (!string.IsNullOrEmpty(Request.Params["image_MobileValue"])) p.Mobile_Image = Request.Params["image_MobileValue"];//如果手機說明圖有值,將值賦予Moibile_Image edit by wwei0216w 2015/3/18 if (!string.IsNullOrEmpty(Request.Params["productMedia"])) p.product_media = Request.Params["productMedia"]; if (!string.IsNullOrEmpty(Request.Params["specify_Product_alt"])) p.Product_alt = Request.Params["specify_Product_alt"];//add by wwei0216w 2015/4/9 p.Product_Id = productId; _productMgr = new ProductMgr(connectionString); ProductSpec pSpec = new ProductSpec(); List<ProductSpec> pSpecList = new List<ProductSpec>(); if (!string.IsNullOrEmpty(Request.Params["spec_InsertValue"])) { string[] Values = Request.Form["spec_InsertValue"].ToString().Split(';'); for (int i = 0; i < Values.Length - 1; i++) { pSpec = new ProductSpec(); pSpec.product_id = productId; string[] perValue = Values[i].Split(','); if (!string.IsNullOrEmpty(perValue[0])) { pSpec.spec_image = perValue[0]; }; if (!string.IsNullOrEmpty(perValue[1])) { pSpec.spec_id = uint.Parse(perValue[1]); }; if (!string.IsNullOrEmpty(perValue[2])) { pSpec.spec_sort = uint.Parse(perValue[2]); }; if (!string.IsNullOrEmpty(perValue[3])) { pSpec.spec_status = uint.Parse(perValue[3]); }; pSpecList.Add(pSpec); } } List<ProductPicture> picList = new List<ProductPicture>(); _productPicMgr = new ProductPictureMgr(connectionString); ProductPicture pPic = new ProductPicture(); if (!string.IsNullOrEmpty(Request.Params["picture_InsertValue"])) { string[] Values = Request.Form["picture_InsertValue"].ToString().Split(';'); for (int i = 0; i < Values.Length - 1; i++) { pPic = new ProductPicture(); string[] perValue = Values[i].Split(','); pPic.product_id = int.Parse(Request.Params["product_id"]); if (!string.IsNullOrEmpty(perValue[0])) { pPic.image_filename = perValue[0]; }; if (!string.IsNullOrEmpty(perValue[1])) { pPic.image_sort = uint.Parse(perValue[1]); }; if (!string.IsNullOrEmpty(perValue[2])) { pPic.image_state = uint.Parse(perValue[2]); }; picList.Add(pPic); } } //手機app圖檔 List<ProductPicture> appList = new List<ProductPicture>(); _productPicMgr = new ProductPictureMgr(connectionString); ProductPicture apppPic = new ProductPicture(); if (!string.IsNullOrEmpty(Request.Params["mobilePic_InsertValue"])) { string[] Values = Request.Form["mobilePic_InsertValue"].ToString().Split(';'); for (int i = 0; i < Values.Length - 1; i++) { apppPic = new ProductPicture(); string[] perValue = Values[i].Split(','); apppPic.product_id = int.Parse(Request.Params["product_id"]); if (!string.IsNullOrEmpty(perValue[0])) { apppPic.image_filename = perValue[0]; }; if (!string.IsNullOrEmpty(perValue[1])) { apppPic.image_sort = uint.Parse(perValue[1]); }; if (!string.IsNullOrEmpty(perValue[2])) { apppPic.image_state = uint.Parse(perValue[2]); }; appList.Add(apppPic); } } try { _productMgr.Update_Product_Spec_Picture(p, pSpecList, picList, appList); json = "{success:true,msg:\"" + Resources.Product.SAVE_SUCCESS + "\"}"; } 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:true,msg:\"" + Resources.Product.SAVE_FAIL + "\"}"; } } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase DeletePic() { string json = "{success:true,msg:\"" + Resources.Product.DELETE_SUCCESS + "\"}"; string deleteType = Request.Params["type"]; int apporexplain = Convert.ToInt32(Request["apporexplain"]);//判斷是從前臺的APP傳來還是從explain傳來 ProductSpecTemp psTemp = new ProductSpecTemp(); ProductSpec pSpec = new ProductSpec(); List<ProductSpecTemp> psList = new List<ProductSpecTemp>(); _specTempMgr = new ProductSpecTempMgr(connectionString); _specMgr = new ProductSpecMgr(connectionString); string[] record = Request.Params["rec"].Split(','); string fileName = record[0].Split('/')[imgNameIdx]; SetPath(apporexplain); if (deleteType == "desc") { string imageName = imgLocalPath + descPath + GetDetailFolder(fileName) + fileName; string imageName400 = imgLocalPath + desc400Path + GetDetailFolder(fileName) + fileName; DeletePicFile(imageName); DeletePicFile(imageName400); } if (string.IsNullOrEmpty(Request.Params["product_id"])) { psTemp.Writer_Id = (Session["caller"] as Caller).user_id; try { _specTempMgr.Update(psList, "image"); } 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:true,msg:\"" + Resources.Product.DELETE_SPEC_FAIL + "\"}"; } } else { pSpec.product_id = uint.Parse(Request.Params["product_id"]); try { _specMgr.UpdateSingle(pSpec); } 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:true,msg:\"" + Resources.Product.DELETE_SPEC_FAIL + "\"}"; } } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public string QuerySpecPic() { _specTempMgr = new ProductSpecTempMgr(connectionString); _specMgr = new ProductSpecMgr(connectionString); string json = string.Empty; if (string.IsNullOrEmpty(Request.Params["product_id"])) { //查找臨時表記錄 ProductSpecTemp psTemp = new ProductSpecTemp(); psTemp.Writer_Id = (Session["caller"] as Caller).user_id; psTemp.spec_type = 1; //string str = "{success:true,items:"+JsonConvert.+"}"; List<ProductSpecTemp> results = _specTempMgr.Query(psTemp); //JsonConvert.SerializeObject(); foreach (var item in results) { if (item.spec_image != "") { item.spec_image = imgServerPath + specPath + GetDetailFolder(item.spec_image) + item.spec_image; } } json = "{success:true,items:" + JsonConvert.SerializeObject(results) + "}"; json = json.Replace("spec_image", "img"); } else { //查找正式表 ProductSpec pSpec = new ProductSpec(); pSpec.product_id = uint.Parse(Request.Params["product_id"]); pSpec.spec_type = 1; List<ProductSpec> spList = _specMgr.Query(pSpec); foreach (var item in spList) { if (item.spec_image != "") { item.spec_image = imgServerPath + specPath + GetDetailFolder(item.spec_image) + item.spec_image; } } json = "{success:true,items:" + JsonConvert.SerializeObject(spList) + "}"; json = json.Replace("spec_image", "img"); } return json; }
public HttpResponseBase DeletePic() { string json = "{success:true,msg:\"" + Resources.Product.DELETE_SUCCESS + "\",path:\"" + default50Path + "\"}"; try { string deleteType = Request.Params["type"]; int apporexplain = Convert.ToInt32(Request["apporexplain"]);//判斷是從前臺的APP傳來還是從explain傳來 ProductSpecTemp psTemp = new ProductSpecTemp(); ProductSpec pSpec = new ProductSpec(); List<ProductSpecTemp> psList = new List<ProductSpecTemp>(); List<ProductSpec> pspList = new List<ProductSpec>(); _specTempMgr = new ProductSpecTempMgr(connectionString); _specMgr = new ProductSpecMgr(connectionString); string[] records = Request.Params["rec"].Split('|'); foreach (var item in records) { string[] record = item.Split(','); if (record[0].Split('/').Length == defaultImgLength) //默认图片无法删除 { json = "{success:false,msg:\"" + Resources.Product.DEFAULT_CANNOT_DELETE + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } string fileName = record[0].Split('/')[imgNameIdx]; if (deleteType == "spec") { psTemp.spec_image = string.Empty; psTemp.spec_id = uint.Parse(record[1]); psTemp.spec_sort = uint.Parse(record[2]); psTemp.spec_status = uint.Parse(record[3]); pSpec.spec_image = string.Empty; pSpec.spec_id = uint.Parse(record[1]); pSpec.spec_sort = uint.Parse(record[2]); pSpec.spec_status = uint.Parse(record[3]); psList.Add(psTemp); pspList.Add(pSpec); string imageName = imgLocalPath + specPath + GetDetailFolder(fileName) + fileName; string image100 = imgLocalPath + spec100Path + GetDetailFolder(fileName) + fileName; string image280 = imgLocalPath + spec280Path + GetDetailFolder(fileName) + fileName; //刪除服務器上對應的圖片 DeletePicFile(imageName); DeletePicFile(image100); DeletePicFile(image280); } else if (deleteType == "desc") { SetPath(apporexplain); string imageName = imgLocalPath + descPath + GetDetailFolder(fileName) + fileName; string imageName400 = imgLocalPath + desc400Path + GetDetailFolder(fileName) + fileName; DeletePicFile(imageName); DeletePicFile(imageName400); } } //string[] record = Request.Params["rec"].Split(','); //if (record[0].Split('/').Length == defaultImgLength) //默认图片无法删除 //{ // json = "{success:false,msg:\"" + Resources.Product.DEFAULT_CANNOT_DELETE + "\"}"; // this.Response.Clear(); // this.Response.Write(json); // this.Response.End(); // return this.Response; //} //string fileName = record[0].Split('/')[imgNameIdx]; //if (deleteType == "spec") //{ // psTemp.spec_image = string.Empty; // psTemp.spec_id = uint.Parse(record[1]); // psTemp.spec_sort = uint.Parse(record[2]); // psTemp.spec_status = uint.Parse(record[3]); // pSpec.spec_image = string.Empty; // pSpec.spec_id = uint.Parse(record[1]); // pSpec.spec_sort = uint.Parse(record[2]); // pSpec.spec_status = uint.Parse(record[3]); // psList.Add(psTemp); // string imageName = imgLocalPath + specPath + GetDetailFolder(fileName) + fileName; // string image100 = imgLocalPath + spec100Path + GetDetailFolder(fileName) + fileName; // string image280 = imgLocalPath + spec280Path + GetDetailFolder(fileName) + fileName; // //刪除服務器上對應的圖片 // DeletePicFile(imageName); // DeletePicFile(image100); // DeletePicFile(image280); //} //else if (deleteType == "desc") //{ // //if (apporexplain == 1) // //{ // SetPath(apporexplain); // string imageName = imgLocalPath + descPath + GetDetailFolder(fileName) + fileName; // string imageName400 = imgLocalPath + desc400Path + GetDetailFolder(fileName) + fileName; // DeletePicFile(imageName); // DeletePicFile(imageName400); // //} // //else if(apporexplain == 2) // //{ // // string imageName = imgLocalPath + descMobilePath + GetDetailFolder(fileName) + fileName; // // string imageName400 = imgLocalPath + desc400MobilePath + GetDetailFolder(fileName) + fileName; // // DeletePicFile(imageName); // // DeletePicFile(imageName400); // //} //} if (string.IsNullOrEmpty(Request.Params["product_id"])) { psTemp.Writer_Id = (Session["caller"] as Caller).user_id; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { psTemp.product_id = Request.Form["OldProductId"]; } _specTempMgr.Update(psList, "image"); } else { uint productId = uint.Parse(Request.Params["product_id"]); foreach (var item in pspList) { item.product_id = productId; _specMgr.UpdateSingle(item); } //pSpec.product_id = uint.Parse(Request.Params["product_id"]); //_specMgr.UpdateSingle(pSpec); } } 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:true,msg:\"" + Resources.Product.DELETE_SPEC_FAIL + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase spec2TempQuery() { string resultStr = "{success:false}"; Caller _caller = (Session["caller"] as Caller); try { if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { //product_spec uint pid = uint.Parse(Request.Form["ProductId"]); _specMgr = new ProductSpecMgr(connectionString); resultStr = "{success:true,data:" + JsonConvert.SerializeObject(_specMgr.Query(new ProductSpec { product_id = pid, spec_type = 2 })) + "}"; } else { //product_spec_temp _specTempMgr = new ProductSpecTempMgr(connectionString); ProductSpecTemp query = new ProductSpecTemp { Writer_Id = _caller.user_id, spec_type = 2 }; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { query.product_id = Request.Form["OldProductId"]; } resultStr = "{success:true,data:" + JsonConvert.SerializeObject(_specTempMgr.Query(query)) + "}"; } } 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 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 ActionResult upLoadImg() { try { HttpPostedFileBase file = Request.Files["Filedata"]; int type = Request["appOrexplain"] == null ? 0 : Convert.ToInt32(Request["appOrexplain"]); string nameType = Request.Params["nameType"]; // 將 nametype 提前 使其判斷傳入的圖片是否為商品主圖 edit by zhuoqin0830w 2015/01/29 int prodCheck = file.FileName.LastIndexOf("prod_"); // 將 proCheck 提前 使其判斷批量上傳的圖片中是否存在商品主圖 edit by zhuoqin0830w 2015/01/30 if (nameType == "spec") { type = 5; } if (prodCheck == 0 && type == 0) //批量上傳時type才會 ==0,其他單獨上傳時是不需要根據prod處理圖片的 { type = 3; } int mobileCheck = file.FileName.LastIndexOf("mobile_");//批量上傳時type才會 ==0,其他單獨上傳時是不需要根據prod處理圖片的 if (mobileCheck == 0 && type == 0) { type = 4; } string path = Server.MapPath(xmlPath); siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = null; //判斷 批量上傳 或 單個上傳 的圖片是否為 商品主圖 或 手機商品圖 edit by zhuoqin0830w 2015/03/24 switch (nameType) { //如果 nameType == prod 則表示 是 單個上傳 商品主圖 case "prod": maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max"); break; //如果 nameType == mobile 則表示 是 單個上傳 手機商品圖 case "mobile": maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max"); break; //如果 nameType == null 則表示 是 批量上傳 case null: //如果 prodCheck == 0 則表示 是 批量上傳 中包含 商品主圖 if (prodCheck == 0) { maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max"); } //如果 mobileCheck == 0 則表示 是 批量上傳 中包含 手機商品圖 else if (mobileCheck == 0) { maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max"); } else { maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); } break; default: maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); break; } string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; if ((nameType == "mobile" && type == 4) || (mobileCheck == 0 && type == 4)) //add by wwei0216w 2015/4/1 添加原因:手機圖片要放在640*640路徑下 { prodPath = prodMobile640; } string localProdPath = imgLocalPath + prodPath; //string localProd50Path = imgLocalPath + prod50Path; //string localProd150Path = imgLocalPath + prod150Path; //string localProd280Path = imgLocalPath + prod280Path; string localSpecPath = imgLocalPath + specPath; //string localSpec100Path = imgLocalPath + spec100Path; //string localSpec280Path = imgLocalPath + spec280Path; string[] Mappath = new string[2]; FileManagement fileLoad = new FileManagement(); string fileName = string.Empty; string fileExtention = string.Empty; ViewBag.spec_id = -1; if (nameType != null) { fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower(); } else { #region 批次上傳圖片操作 //此處由批次上傳進入. //判斷文件名格式是否正確 ViewBag.moreFileOneTime = true; //int prodCheck = file.FileName.LastIndexOf("prod_"); int specCheck = file.FileName.LastIndexOf("spec_"); int descCheck = file.FileName.LastIndexOf("desc_"); int appCheck = file.FileName.LastIndexOf("app_"); string errorMsg = "ERROR/"; if (prodCheck == -1 && specCheck == -1 && descCheck == -1 && appCheck == -1 && mobileCheck == -1) { errorMsg += "[" + file.FileName + "] "; errorMsg += Resources.Product.FILE_NAME_ERROR; ViewBag.fileName = errorMsg; return View("~/Views/Product/upLoad.cshtml"); } else { nameType = file.FileName.Split('_')[0]; if (nameType == "app") { type = 2; } else if (nameType == "desc") { type = 1; } else if (nameType == "spec") { type = 5; } fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')); } if (specCheck == 0) { Caller _caller = (Session["caller"] as Caller); string spec = file.FileName.Split('_')[1].Split('.')[0]; bool checkStatus = true; if (!string.IsNullOrEmpty(Request.Params["product_id"].Split(';')[0].ToString())) { //product_spec uint pid = uint.Parse(Request.Params["product_id"].Split(';')[0].ToString()); _specMgr = new ProductSpecMgr(connectionString); List<ProductSpec> pSpecList = _specMgr.Query(new ProductSpec { product_id = pid, spec_type = 1 }); foreach (var item in pSpecList) { if (item.spec_name == spec) { checkStatus = false; ViewBag.spec_id = item.spec_id; } } } else { //product_spec_temp _specTempMgr = new ProductSpecTempMgr(connectionString); List<ProductSpecTemp> pSpecTempList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, spec_type = 1 }); foreach (var item in pSpecTempList) { if (item.spec_name == spec) { checkStatus = false; ViewBag.spec_id = item.spec_id; } } } if (checkStatus)//表示沒有要上傳圖片規格相同的規格一 { errorMsg += "[" + file.FileName + "] " + Resources.Product.SPEC_NOT_FIND; ViewBag.fileName = errorMsg; return View("~/Views/Product/upLoad.cshtml"); } } #endregion } SetPath(type);//設定圖片路徑 string localDescPath = imgLocalPath + descPath; //string localDesc400Path = imgLocalPath + desc400Path; string returnName = imgServerPath; bool result = false; string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string firstFolder = NewFileName.Substring(0, 2) + "/"; string secondFolder = NewFileName.Substring(2, 2) + "/"; string ServerPath = string.Empty; if (nameType == "spec") { Mappath[0] = firstFolder; Mappath[1] = secondFolder; CreateFolder(localSpecPath, Mappath); //CreateFolder(localSpec100Path, Mappath); //CreateFolder(localSpec280Path, Mappath); localSpecPath += firstFolder + secondFolder; //localSpec100Path += firstFolder + secondFolder; //localSpec280Path += firstFolder + secondFolder; specPath += firstFolder + secondFolder; returnName += specPath + NewFileName + fileExtention; //localSpec100Path += NewFileName + fileExtention; //localSpec280Path += NewFileName + fileExtention; NewFileName = localSpecPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + specPath); } else if (nameType == "desc" || nameType == "app") { Mappath[0] = firstFolder; Mappath[1] = secondFolder; CreateFolder(localDescPath, Mappath); //CreateFolder(localDesc400Path, Mappath); localDescPath += firstFolder + secondFolder; //localDesc400Path += firstFolder + secondFolder; descPath += firstFolder + secondFolder; //localDesc400Path += NewFileName + fileExtention; returnName += descPath + NewFileName + fileExtention; NewFileName = localDescPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + descPath); } else { Mappath[0] = firstFolder; Mappath[1] = secondFolder; //Data:2014/06/26 //author:Castle //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!! CreateFolder(localProdPath, Mappath); //CreateFolder(localProd50Path, Mappath); //CreateFolder(localProd150Path, Mappath); //CreateFolder(localProd280Path, Mappath); localProdPath += firstFolder + secondFolder; //localProd50Path += firstFolder + secondFolder; //localProd150Path += firstFolder + secondFolder; //localProd280Path += firstFolder + secondFolder; prodPath += firstFolder + secondFolder; //localProd50Path += NewFileName + fileExtention; //localProd150Path += NewFileName + fileExtention; //localProd280Path += NewFileName + fileExtention; returnName += prodPath + NewFileName + fileExtention; NewFileName = localProdPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + prodPath); } string ErrorMsg = string.Empty; Resource.CoreMessage = new CoreResource("Product"); //上傳圖片 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); #region // //上傳對應大小圖片 //压缩图片至其它规格 //Data:2014/06/26 //author:Castle //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!! //if (result) //{ // FTP ftp = null; // string newFileName = NewFileName.Substring(NewFileName.LastIndexOf("/")); // GigadeService.TransImageClient transImg = new GigadeService.TransImageClient(); // if (nameType == "spec") // { // string sourceImgPath = Server.MapPath(imgLocalServerPath + specPath + NewFileName.Substring(NewFileName.LastIndexOf("/"))); // ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder), newFileName, 100, 100, admin_userName.Value, admin_passwd.Value); // if (string.IsNullOrWhiteSpace(ErrorMsg)) // { // file.SaveAs(Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder + newFileName)); // ftp = new FTP(localSpec100Path, ftpuser, ftppwd); // ftp.UploadFile(Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder + newFileName)); // } // if (!Directory.Exists(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder))) // Directory.CreateDirectory(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder)); // ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder), newFileName, 280, 280, admin_userName.Value, admin_passwd.Value); // if (string.IsNullOrWhiteSpace(ErrorMsg)) // { // file.SaveAs(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder + newFileName)); // ftp = new FTP(localSpec100Path, ftpuser, ftppwd); // ftp.UploadFile(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder + newFileName)); // } // } // else if (nameType == "desc") // { // string sourceImgPath = Server.MapPath(imgLocalServerPath + descPath + NewFileName.Substring(NewFileName.LastIndexOf("/"))); // ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder), newFileName, 400, 400, admin_userName.Value, admin_passwd.Value); // if (string.IsNullOrWhiteSpace(ErrorMsg)) // { // file.SaveAs(Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder + newFileName)); // ftp = new FTP(localSpec100Path, ftpuser, ftppwd); // ftp.UploadFile(Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder + newFileName)); // } // } // else // { // //string sourceImgPath = Server.MapPath(imgLocalServerPath + prodPath + NewFileName.Substring(NewFileName.LastIndexOf("/"))); // //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder), newFileName, 50, 50, admin_userName.Value, admin_passwd.Value); // //if (string.IsNullOrWhiteSpace(ErrorMsg)) // //{ // // file.SaveAs(Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder + newFileName)); // // ftp = new FTP(localProd50Path, ftpuser, ftppwd); // // ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder + newFileName)); // //} // //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder), newFileName, 150, 150, admin_userName.Value, admin_passwd.Value); // //if (string.IsNullOrWhiteSpace(ErrorMsg)) // //{ // // file.SaveAs(Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder + newFileName)); // // ftp = new FTP(localProd150Path, ftpuser, ftppwd); // // ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder + newFileName)); // //} // ////if (!Directory.Exists(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder))) // //// Directory.CreateDirectory(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder)); // ////ImageClass iC280 = new ImageClass(sourceImgPath); // //////iC280.ImageMagick(sourceImgPath, Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + NewFileName.Substring(NewFileName.LastIndexOf("/"))), 280, 280, ref error); // ////iC150.MakeThumbnail(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + NewFileName.Substring(NewFileName.LastIndexOf("/"))), 280, 280, ref error); // //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder), newFileName, 280, 280, admin_userName.Value, admin_passwd.Value); // //if (string.IsNullOrWhiteSpace(ErrorMsg)) // //{ // // file.SaveAs(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + newFileName)); // // ftp = new FTP(localProd280Path, ftpuser, ftppwd); // // ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + newFileName)); // //} // } //} #endregion if (string.IsNullOrEmpty(ErrorMsg)) { ViewBag.fileName = returnName; ViewBag.Type = type; //獲取文件長度 add by zhuoqin0830w 2015/01/29 string[] strFile = file.FileName.Split('_'); //判斷文件名的長度是否大於 1 如果大於 1 則再次進行判斷是否為數字 如果不是則進行強制轉換 int image_sort = 0; int.TryParse(strFile.Length > 1 ? strFile[1] : "0", out image_sort); ViewBag.image_sort = image_sort; } else { // 判斷 批量上傳中 是否存在 商品圖 或 手機商品圖 edit by zhuoqin0830w 2015/03/24 if (prodCheck == 0 || mobileCheck == 0) { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; } else { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; } Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = "ERROR/" + ErrorMsg; logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } } 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 View("~/Views/Product/upLoad.cshtml"); }
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(); }
/// <summary> /// 多表更新 /// </summary> /// <param name="p">product表</param> /// <param name="pIList">ProductSpec表</param> /// <param name="pSList">ProductPicture</param> /// <returns></returns> public bool Update_Product_Spec_Picture(Product p, List<ProductSpec> pSList, List<ProductPicture> pPList, List<ProductPicture> appList = null) { ArrayList sqlList = new ArrayList(); _productSpecMgr = new ProductSpecMgr(connectionStr); List<Product> pList = _productDao.Query(p); pList[0].Product_Image = p.Product_Image; pList[0].product_media = p.product_media; pList[0].Mobile_Image = p.Mobile_Image; // edit by wwei0216w 2015/3/18 添加關於Mobile的修改 pList[0].Product_alt = p.Product_alt; if (p.Product_Image != "" || p.product_media != "" || p.Mobile_Image != "" || p.Product_alt != "")// edit by wwei0216w 2015/3/18 添加關於Mobile的修改 { sqlList.Add(_productDao.Update(pList[0])); } //ProductSpec表 foreach (var item in pSList) { //查詢product_item表 ProductSpec spec = _productSpecMgr.query(int.Parse(item.spec_id.ToString())); spec.spec_image = item.spec_image; spec.spec_sort = item.spec_sort; spec.spec_status = item.spec_status; sqlList.Add(_productSpecMgr.Update(spec)); } //ProductPicture表 sqlList.Add(_productPicDao.Delete(int.Parse(p.Product_Id.ToString()))); foreach (var item in pPList) { sqlList.Add(_productPicDao.Save(item)); } sqlList.Add(_productPicDao.Delete(int.Parse(p.Product_Id.ToString()), 2)); //1:商品說明表 2:手機app圖檔表 foreach (var item in appList) { sqlList.Add(_productPicDao.Save(item, 2)); } MySqlDao mySqlDao = new MySqlDao(connectionStr); return mySqlDao.ExcuteSqls(sqlList); }
public string QuerySpecPic() { BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];//獲取當前登入的供應商 string serverSpecPath = imgServerPath + specPath; string serverSpec100Path = imgServerPath + spec100Path; string serverSpec280Path = imgServerPath + spec280Path; _specTempMgr = new ProductSpecTempMgr(connectionString); _specMgr = new ProductSpecMgr(connectionString); string json = string.Empty; ProductSpecTemp psTemp = new ProductSpecTemp(); psTemp.Writer_Id = (int)vendorModel.vendor_id; psTemp.spec_type = 1; if (!string.IsNullOrEmpty(Request.Params["product_id"])) { psTemp.product_id = Request.Params["product_id"]; } uint pid = 0; if (uint.TryParse(Request.Params["product_id"], out pid)) { #region 正式表 ProductSpec pSpec = new ProductSpec(); pSpec.spec_type = 1; pSpec.product_id = Convert.ToUInt32(Request.Params["product_id"]); List<ProductSpec> spList = _specMgr.Query(pSpec); foreach (var item in spList) { if (item.spec_image != "") { item.spec_image = serverSpecPath + GetDetailFolder(item.spec_image) + item.spec_image; } else { item.spec_image = imgServerPath + "/product/nopic_50.jpg"; } } json = "{success:true,items:" + JsonConvert.SerializeObject(spList) + "}"; json = json.Replace("spec_image", "img"); #endregion } else { #region 供應商 臨時表 List<ProductSpecTemp> results = _specTempMgr.VendorQuery(psTemp); //JsonConvert.SerializeObject(); foreach (var item in results) { if (item.spec_image != "") { item.spec_image = serverSpecPath + GetDetailFolder(item.spec_image) + item.spec_image; } else { item.spec_image = imgServerPath + "/product/nopic_50.jpg"; } } json = "{success:true,items:" + JsonConvert.SerializeObject(results) + "}"; json = json.Replace("spec_image", "img"); #endregion } return json; }
public HttpResponseBase DeletePic() { string json = "{success:true,msg:\"" + Resources.VendorProduct.DELETE_SUCCESS + "\",path:\"" + default50Path + "\"}"; string deleteType = Request.Params["type"]; ProductSpecTemp psTemp = new ProductSpecTemp(); ProductSpec pSpec = new ProductSpec(); List<ProductSpecTemp> psList = new List<ProductSpecTemp>(); _specTempMgr = new ProductSpecTempMgr(connectionString); _specMgr = new ProductSpecMgr(connectionString); BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];//獲取當前登入的供應商 string[] record = Request.Params["rec"].Split(','); if (record[0].Split('/').Length == defaultImgLength) //默认图片无法删除 { json = "{success:false,msg:\"" + Resources.VendorProduct.DEFAULT_CANNOT_DELETE + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } string fileName = record[0].Split('/')[imgNameIdx]; if (deleteType == "spec") { psTemp.spec_image = string.Empty; psTemp.spec_id = uint.Parse(record[1]); psTemp.spec_sort = uint.Parse(record[2]); psTemp.spec_status = uint.Parse(record[3]); pSpec.spec_image = string.Empty; pSpec.spec_id = uint.Parse(record[1]); pSpec.spec_sort = uint.Parse(record[2]); pSpec.spec_status = uint.Parse(record[3]); psList.Add(psTemp); string imageName = imgLocalPath + specPath + GetDetailFolder(fileName) + fileName; string image100 = imgLocalPath + spec100Path + GetDetailFolder(fileName) + fileName; string image280 = imgLocalPath + spec280Path + GetDetailFolder(fileName) + fileName; //刪除服務器上對應的圖片 DeletePicFile(imageName); DeletePicFile(image100); DeletePicFile(image280); } else if (deleteType == "desc") { string imageName = imgLocalPath + descPath + GetDetailFolder(fileName) + fileName; string imageName400 = imgLocalPath + desc400Path + GetDetailFolder(fileName) + fileName; DeletePicFile(imageName); DeletePicFile(imageName400); } psTemp.Writer_Id = (int)vendorModel.vendor_id; if (!string.IsNullOrEmpty(Request.Params["product_id"])) { psTemp.product_id = Request.Params["product_id"]; } //if (!string.IsNullOrEmpty(Request.Params["OldProductId"])) //{ // psTemp.product_id = Request.Params["OldProductId"]; //} try { _specTempMgr.Update(psList, "image"); } 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.VendorProduct.DELETE_SPEC_FAIL + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase spec2TempQuery() { string resultStr = "{success:false}"; try { BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; int writerID = (int)vendorModel.vendor_id; uint pid = 0; if (!string.IsNullOrEmpty(Request.Form["ProductId"])) { if (uint.TryParse(Request.Form["ProductId"].ToString(), out pid)) { //product_spec pid = uint.Parse(Request.Form["ProductId"]); _specMgr = new ProductSpecMgr(connectionString); resultStr = "{success:true,data:" + JsonConvert.SerializeObject(_specMgr.Query(new ProductSpec { product_id = pid, spec_type = 2 })) + "}"; } else { //product_spec_temp _specTempMgr = new ProductSpecTempMgr(connectionString); ProductSpecTemp query = new ProductSpecTemp { Writer_Id = writerID, spec_type = 2 }; query.product_id = Request.Form["ProductId"].ToString(); resultStr = "{success:true,data:" + JsonConvert.SerializeObject(_specTempMgr.VendorQuery(query)) + "}"; } } } 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 string QuerySpecPic() { _specTempMgr = new ProductSpecTempMgr(connectionString); _specMgr = new ProductSpecMgr(connectionString); string json = string.Empty; BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; //查找臨時表記錄 ProductSpecTemp psTemp = new ProductSpecTemp(); psTemp.Writer_Id = Convert.ToInt32(vendorModel.vendor_id); psTemp.spec_type = 1; //string str = "{success:true,items:"+JsonConvert.+"}"; List<ProductSpecTemp> results = _specTempMgr.Query(psTemp); //JsonConvert.SerializeObject(); foreach (var item in results) { if (item.spec_image != "") { item.spec_image = imgServerPath + specPath + GetDetailFolder(item.spec_image) + item.spec_image; } } json = "{success:true,items:" + JsonConvert.SerializeObject(results) + "}"; json = json.Replace("spec_image", "img"); return json; }
public HttpResponseBase productPictrueTempSave() { string json = "{success:true}"; ProductTemp pTemp = new ProductTemp(); _productTempMgr = new ProductTempMgr(connectionString); _specTempMgr = new ProductSpecTempMgr(connectionString); _productPicMgr = new ProductPictureMgr(connectionString); BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"]; int writd_Id = Convert.ToInt32(vendorModel.vendor_id); _specMgr = new ProductSpecMgr(connectionString); if (!string.IsNullOrEmpty(Request.Params["image_InsertValue"])) pTemp.Product_Image = Request.Params["image_InsertValue"]; if (!string.IsNullOrEmpty(Request.Params["productMedia"])) pTemp.product_media = Request.Params["productMedia"]; if (!string.IsNullOrEmpty(Request.Params["product_id"])) { pTemp.Product_Id = Request.Params["product_id"].ToString(); } pTemp.Writer_Id = writd_Id; pTemp.Combo_Type = COMBO_TYPE; ProductSpecTemp pSpec = new ProductSpecTemp(); List<ProductSpecTemp> pSpecList = new List<ProductSpecTemp>(); if (!string.IsNullOrEmpty(Request.Params["spec_InsertValue"])) { string[] Values = Request.Form["spec_InsertValue"].ToString().Split(';'); for (int i = 0; i < Values.Length - 1; i++) { pSpec = new ProductSpecTemp(); pSpec.Writer_Id = writd_Id; string[] perValue = Values[i].Split(','); if (!string.IsNullOrEmpty(perValue[0])) { pSpec.spec_image = perValue[0]; }; if (!string.IsNullOrEmpty(perValue[1])) { pSpec.spec_id = uint.Parse(perValue[1]); }; if (!string.IsNullOrEmpty(perValue[2])) { pSpec.spec_sort = uint.Parse(perValue[2]); }; if (!string.IsNullOrEmpty(perValue[3])) { pSpec.spec_status = uint.Parse(perValue[3]); }; pSpecList.Add(pSpec); } } List<ProductPictureTemp> picList = new List<ProductPictureTemp>(); _pPicTempMgr = new ProductPictureTempImplMgr(connectionString); ProductPictureTemp pPic = new ProductPictureTemp(); if (!string.IsNullOrEmpty(Request.Params["picture_InsertValue"])) { string[] Values = Request.Form["picture_InsertValue"].ToString().Split(';'); for (int i = 0; i < Values.Length - 1; i++) { pPic = new ProductPictureTemp(); string[] perValue = Values[i].Split(','); pPic.combo_type = COMBO_TYPE; pPic.writer_Id = writd_Id; pPic.image_createdate = Convert.ToInt32(CommonFunction.GetPHPTime()); pPic.product_id = pTemp.Product_Id; if (!string.IsNullOrEmpty(perValue[0])) { pPic.image_filename = perValue[0]; }; if (!string.IsNullOrEmpty(perValue[1])) { pPic.image_sort = uint.Parse(perValue[1]); }; if (!string.IsNullOrEmpty(perValue[2])) { pPic.image_state = uint.Parse(perValue[2]); }; picList.Add(pPic); } } try { //保存至productTemp if (pTemp.Product_Image != "" || pTemp.product_media != "") { _productTempMgr.ProductTempUpdateByVendor(pTemp, "pic"); } //保存規格圖 _specTempMgr.Update(pSpecList, "image"); //保存說明圖 //int oldProductId = 0; //if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) //{ // oldProductId = int.Parse(Request.Form["OldProductId"]); //} ProductPictureTemp proPictureTemp = new ProductPictureTemp { writer_Id = pTemp.Writer_Id, combo_type = pTemp.Combo_Type, product_id = pTemp.Product_Id }; _pPicTempMgr.Save(picList, proPictureTemp); //_pPicTempMgr.Save(picList, new ProductPictureTemp() { writer_Id = writer_id, combo_type = COMBO_TYPE, product_id = oldProductId }); edite by wangwei0216w 註釋掉_pPicTempMgr.Save 以解決複製后不能讀取圖片路勁到數據庫 json = "{success:true,msg:\"" + Resources.VendorProduct.SAVE_SUCCESS + "\"}"; } 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.VendorProduct.EDIT_FAIL + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public string QuerySpecPic() { string serverSpecPath = imgServerPath + specPath; string serverSpec100Path = imgServerPath + spec100Path; string serverSpec280Path = imgServerPath + spec280Path; _specTempMgr = new ProductSpecTempMgr(connectionString); _specMgr = new ProductSpecMgr(connectionString); string json = string.Empty; ProductSpecTemp psTemp = new ProductSpecTemp(); psTemp.spec_type = 1; if (!string.IsNullOrEmpty(Request.Params["product_id"])) { psTemp.product_id = Request.Params["product_id"]; } List<ProductSpecTemp> results = _specTempMgr.VendorQuery(psTemp); //JsonConvert.SerializeObject(); foreach (var item in results) { if (item.spec_image != "") { item.spec_image = serverSpecPath + GetDetailFolder(item.spec_image) + item.spec_image; } else { item.spec_image = imgServerPath + "/product/nopic_50.jpg"; } } json = "{success:true,items:" + JsonConvert.SerializeObject(results) + "}"; json = json.Replace("spec_image", "img"); return json; }