Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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
            {
                BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
                int writerID = (int)vendorModel.vendor_id;

                string specType = Request.Params["specType"];
                string spec1Name = Request.Params["spec1Name"];
                string spec1Result = Request.Params["spec1Result"];
                string spec2Name = Request.Params["spec2Name"];
                string spec2Result = Request.Params["spec2Result"];

                _specTempMgr = new ProductSpecTempMgr(connectionString);
                _productTempMgr = new ProductTempMgr(connectionString);
                _productItemTempMgr = new ProductItemTempMgr(connectionString);
                _serialMgr = new SerialMgr(connectionString);
                #region 臨時表修改
                string proId = string.Empty;
                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    proId = Request.Params["ProductId"].ToString();

                }
                if (!string.IsNullOrEmpty(proId))
                {
                    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)
                        {
                            item.Writer_Id = writerID;// item.Writer_Id = _caller.user_id;
                            item.product_id = proId;
                            item.spec_type = 1;
                            item.spec_image = "";
                            specAllList.Add(item);
                        }

                        if (specType.Equals("2"))
                        {

                            spec2List = jss.Deserialize<List<ProductSpecTemp>>(spec2Result);

                            foreach (ProductSpecTemp item in spec2List)
                            {
                                item.Writer_Id = writerID;// item.Writer_Id = _caller.user_id;
                                item.product_id = proId;
                                item.spec_type = 2;
                                item.spec_image = "";
                                specAllList.Add(item);
                            }
                        }

                        List<ProductSpecTemp> tempList = _specTempMgr.VendorQuery(new ProductSpecTemp { Writer_Id = writerID, product_id = proId });

                        if (tempList == null || tempList.Count() <= 0)
                        {
                            #region 保存

                            specAllList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString()));

                            bool saveSpecResult = _specTempMgr.SaveByVendor(specAllList);

                            if (saveSpecResult)
                            {
                                _productItemTempMgr.DeleteByVendor(new ProductItemTemp { Writer_Id = writerID, Product_Id = proId });
                                #region 保存ProductItemTemp

                                List<ProductSpecTemp> specAllResultList = _specTempMgr.VendorQuery(new ProductSpecTemp { Writer_Id = writerID, product_id = proId });
                                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 = writerID;
                                        itemTemp.Product_Id = proId;
                                        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 = writerID;
                                            itemTemp.Product_Id = proId;
                                            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);
                                        }
                                    }
                                }

                                bool saveItemResult = _productItemTempMgr.SaveByVendor(saveItemList);

                                if (!saveItemResult)
                                {
                                    result = false;
                                }

                                #endregion

                            }
                            else
                            {
                                result = false;
                            }
                            #endregion
                        }
                        else
                        {
                            #region 更新

                            string strSpecInit = Request.Params["specInit"];

                            string[] specs = strSpecInit.Trim().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.VendorQuery(new ProductSpecTemp { Writer_Id = writerID, product_id = proId });
                                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 = writerID;
                                            saveTemp.Spec_Id_1 = item.spec_id;
                                            saveTemp.Product_Id = proId;
                                            saveTemp.Item_Stock = 10;
                                            saveTemp.Item_Alarm = 1;
                                            saveItemList.Add(saveTemp);
                                        }
                                        else
                                        {
                                            ProductItemTemp saveTemp = new ProductItemTemp();
                                            saveTemp.Writer_Id = writerID;
                                            saveTemp.Spec_Id_2 = item.spec_id;
                                            saveTemp.Product_Id = proId;
                                            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 = writerID;
                                                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 = proId;
                                                saveItemList.Add(saveTemp);
                                            }

                                            foreach (ProductSpecTemp item1 in addList.Where(p => p.spec_type == 2).ToList())
                                            {
                                                ProductItemTemp saveTemp = new ProductItemTemp();
                                                saveTemp.Writer_Id = writerID;
                                                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 = proId;
                                                saveItemList.Add(saveTemp);
                                            }
                                        }
                                        else
                                        {
                                            foreach (ProductSpecTemp item2 in spec1ResultList)
                                            {
                                                ProductItemTemp saveTemp = new ProductItemTemp();
                                                saveTemp.Writer_Id = writerID;
                                                saveTemp.Spec_Id_1 = item2.spec_id;
                                                saveTemp.Spec_Id_2 = item.spec_id;
                                                saveTemp.Product_Id = proId;
                                                saveTemp.Item_Stock = 10;
                                                saveTemp.Item_Alarm = 1;
                                                saveItemList.Add(saveTemp);
                                            }

                                        }
                                    }
                                }
                                _specTempMgr.SaveByVendor(addList);
                                _productItemTempMgr.SaveByVendor(saveItemList);

                            }

                            if (specs.Length > 0 && !string.IsNullOrEmpty(strSpecInit.Trim()))
                            {
                                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 = writerID, Product_Id = proId };
                                        uint spectype = _specTempMgr.VendorQuery(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), product_id = proId })[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.DeleteByVendor(delTemp))
                                        {
                                            result = false;
                                        }
                                        if (!_specTempMgr.DeleteByVendor(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), Writer_Id = writerID, product_id = proId }))
                                        {
                                            result = false;
                                        }
                                        DeletePicOnServer(false, true, false, uint.Parse(initSpecId), Convert.ToString(proId));
                                    }

                                }
                                if (!_specTempMgr.Update(updateList, "spec"))
                                {
                                    result = false;
                                }
                            }

                            #endregion
                        }

                        #region 更新ProductTemp

                        ProductTemp proTemp = new ProductTemp();
                        proTemp.Writer_Id = writerID;
                        proTemp.Product_Spec = uint.Parse(specType);
                        proTemp.Spec_Title_1 = spec1Name;
                        proTemp.Spec_Title_2 = spec2Name;
                        proTemp.Combo_Type = COMBO_TYPE;
                        proTemp.Product_Id = proId;
                        bool saveProductResult = _productTempMgr.vendorSpecInfoSave(proTemp) > 0 ? true : false;
                        if (!saveProductResult)
                        {
                            result = false;
                        }
                        #endregion

                        #endregion
                    }
                    else
                    {
                        #region 無規格

                        ProductTemp query = _productTempMgr.GetVendorProTemp(new ProductTemp { Writer_Id = writerID, Combo_Type = COMBO_TYPE, Product_Id = proId });
                        //如果原數據有規格
                        if (query.Product_Spec != 0)
                        {
                            //刪除服務器上對應的圖片
                            DeletePicOnServer(false, true, false, 0, proId);

                            _productItemTempMgr.DeleteByVendor(new ProductItemTemp { Writer_Id = writerID, Product_Id = proId });

                            _specTempMgr.DeleteByVendor(new ProductSpecTemp { Writer_Id = writerID, product_id = proId });


                            _productTempMgr.vendorSpecInfoSave(new ProductTemp { Product_Spec = 0, Spec_Title_1 = "", Spec_Title_2 = "", Writer_Id = writerID, Combo_Type = COMBO_TYPE, Product_Id = proId });


                            List<ProductItemTemp> saveList = new List<ProductItemTemp>();
                            saveList.Add(new ProductItemTemp { Writer_Id = writerID, Product_Id = proId, Item_Stock = 10, Item_Alarm = 1 });
                            _productItemTempMgr.SaveByVendor(saveList);
                        }
                        else
                        {
                            List<ProductItemTemp> itemQuery = _productItemTempMgr.QueryByVendor(new ProductItemTemp { Writer_Id = writerID, Product_Id = proId });
                            if (itemQuery.Count() <= 0)
                            {
                                List<ProductItemTemp> saveList = new List<ProductItemTemp>();
                                saveList.Add(new ProductItemTemp { Writer_Id = writerID, Product_Id = proId, Item_Stock = 10, Item_Alarm = 1 });
                                _productItemTempMgr.SaveByVendor(saveList);
                            }
                        }


                        #endregion
                    }
                }
                else
                {
                    result = false;
                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", "VendorProductCountroller.cs", "specTempSave()", Resources.VendorProduct.NOTFOUNTKEY);
                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    log.Error(logMessage);
                    resultStr = "{success:false}";
                }
                #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}";
            }

            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
Esempio n. 4
0
        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");
        }
        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 HttpResponseBase spec2TempQuery()
 {
     string resultStr = "{success:false}";
     try
     {   //product_spec_temp
         _specTempMgr = new ProductSpecTempMgr(connectionString);
         ProductSpecTemp query = new ProductSpecTemp { spec_type = 2 };
         if (!string.IsNullOrEmpty(Request.Form["ProductId"]))
         {
             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 HttpResponseBase productPictrueTempSave()
        {
            string json = "{success:true}";
            BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
            int writerID = (int)vendorModel.vendor_id;
            ProductTemp pTemp = new ProductTemp();
            _productTempMgr = new ProductTempMgr(connectionString);
            _specTempMgr = new ProductSpecTempMgr(connectionString);
            pTemp.Writer_Id = writerID;
            pTemp.Combo_Type = COMBO_TYPE;
            if (!string.IsNullOrEmpty(Request.Params["product_id"]))
            {
                pTemp.Product_Id = Request.Params["product_id"];
            }
            //if (!string.IsNullOrEmpty(Request.Params["OldProductId"]))
            //{
            //    pTemp.Product_Id = Request.Params["OldProductId"];
            //}
            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"];

            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 = writerID;
                    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 = writerID;
                    pPic.product_id = pTemp.Product_Id;
                    pPic.image_createdate = Convert.ToInt32(CommonFunction.GetPHPTime());
                    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
            {
                // int writer_id = writerID; // (Session["caller"] as Caller).user_id;
                //保存至productTemp
                if (pTemp.Product_Image != "" || pTemp.product_media != "")
                {
                    _productTempMgr.ProductTempUpdateByVendor(pTemp, "pic");
                }
                //保存規格圖
                _specTempMgr.Update(pSpecList, "image");
                //保存說明圖
                ProductPictureTemp proPictureTemp = new ProductPictureTemp { writer_Id = writerID, combo_type = COMBO_TYPE, product_id = pTemp.Product_Id };
                _pPicTempMgr.Save(picList, proPictureTemp);
                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.SAVE_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 specTempDelete()
        {
            string resultStr = "{success:true}";
            _specTempMgr = new ProductSpecTempMgr(connectionString);
            _productItemTempMgr = new ProductItemTempMgr(connectionString);
            _productTempMgr = new ProductTempMgr(connectionString);

            try
            {
                BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
                int writerID = (int)vendorModel.vendor_id;

                ProductSpecTemp proSpecTemp = new ProductSpecTemp { Writer_Id = writerID };
                if (!string.IsNullOrEmpty(Request.Form["ProductId"]))
                {
                    proSpecTemp.product_id = Request.Form["ProductId"].ToString();
                }
                //if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                //{
                //    proSpecTemp.product_id = Request.Form["OldProductId"].ToString();
                //}
                DeletePicOnServer(false, true, false, 0, proSpecTemp.product_id);
                _specTempMgr.DeleteByVendor(proSpecTemp);
                _productItemTempMgr.DeleteByVendor(new ProductItemTemp { Writer_Id = writerID, Product_Id = proSpecTemp.product_id });

                //更新ProductTemp規格為無規格
                ProductTemp proTemp = new ProductTemp { Product_Spec = 0, Spec_Title_1 = "", Spec_Title_2 = "", Writer_Id = writerID, Combo_Type = COMBO_TYPE };
                proTemp.Product_Id = proSpecTemp.product_id;
                bool saveProductResult = _productTempMgr.vendorSpecInfoSave(proTemp) > 0 ? true : false;


                if (!saveProductResult)
                {
                    resultStr = "{success:false}";
                }
            }
            catch (Exception ex)
            {
                resultStr = "{success: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);
            }


            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
        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;
        }
        /// <summary>
        /// 從product_temp product_spec_temp 和product_picture中獲取圖片路徑 刪除服務器上面的圖片
        /// </summary>
        /// <param name="prod">是否獲取product_temp圖片路徑數據</param>
        /// <param name="spec">是否獲取product_spec_temp圖片路徑數據</param>
        /// <param name="desc">是否獲取product_picture_temp圖片路徑數據</param>
        /// <param name="product_id">商品id</param>
        public void DeletePicOnServer(bool prod, bool spec, bool desc, string product_id)
        {
            BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
            int write_Id = Convert.ToInt32(vendorModel.vendor_id);

            _productTempMgr = new ProductTempMgr(connectionString);
            _specTempMgr = new ProductSpecTempMgr(connectionString);
            _pPicTempMgr = new ProductPictureTempImplMgr(connectionString);
            ArrayList ImgList = new ArrayList();

            ProductSpecTemp pSpec = new ProductSpecTemp();
            pSpec.Writer_Id = write_Id;
            pSpec.product_id = product_id;
            pSpec.spec_type = 1;

            //刪除對應的圖片
            //商品圖
            if (prod)
            {
                ProductTemp query = new ProductTemp { Writer_Id = write_Id, Combo_Type = COMBO_TYPE, Product_Id = product_id, Create_Channel = 2 };
                string fileName = _productTempMgr.GetProTempByVendor(query).FirstOrDefault().Product_Image;
                if (!string.IsNullOrEmpty(fileName))
                {
                    ImgList.Add(imgLocalPath + prodPath + GetDetailFolder(fileName) + fileName);
                    ImgList.Add(imgLocalPath + prod50Path + GetDetailFolder(fileName) + fileName);
                    ImgList.Add(imgLocalPath + prod150Path + GetDetailFolder(fileName) + fileName);
                    ImgList.Add(imgLocalPath + prod280Path + GetDetailFolder(fileName) + fileName);
                }

            }
            //規格圖
            if (spec)
            {
                List<ProductSpecTemp> pSList = _specTempMgr.Query(pSpec);
                foreach (var item in pSList)
                {
                    if (item.spec_image != "")
                    {
                        ImgList.Add(imgLocalPath + specPath + GetDetailFolder(item.spec_image) + item.spec_image);
                        ImgList.Add(imgLocalPath + spec100Path + GetDetailFolder(item.spec_image) + item.spec_image);
                        ImgList.Add(imgLocalPath + spec280Path + GetDetailFolder(item.spec_image) + item.spec_image);
                    }
                }
            }
            //商品說明圖
            if (desc)
            {
                ProductPictureTemp query = new ProductPictureTemp { writer_Id = write_Id, combo_type = COMBO_TYPE, product_id = product_id };
                List<ProductPictureTemp> pPList = _pPicTempMgr.Query(query);
                foreach (var item in pPList)
                {
                    ImgList.Add(imgLocalPath + descPath + GetDetailFolder(item.image_filename) + item.image_filename);
                    ImgList.Add(imgLocalPath + desc400Path + GetDetailFolder(item.image_filename) + item.image_filename);
                }
            }

            foreach (string item in ImgList)
            {
                //刪除服務器上對應的圖片
                if (System.IO.File.Exists(item))
                {
                    System.IO.File.Delete(item);
                }
            }
        }
        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;
        }
Esempio n. 14
0
        public HttpResponseBase specTempDelete()
        {
            string resultStr = "{success:true}";
            _specTempMgr = new ProductSpecTempMgr(connectionString);
            _productItemTempMgr = new ProductItemTempMgr(connectionString);
            _productTempMgr = new ProductTempMgr(connectionString);
            Caller _caller = (Session["caller"] as Caller);
            try
            {

                ProductSpecTemp proSpecTemp = new ProductSpecTemp { Writer_Id = _caller.user_id };

                if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                {
                    proSpecTemp.product_id = Request.Form["OldProductId"];
                }
                DeletePicOnServer(false, true, false, 0, proSpecTemp.product_id);
                _specTempMgr.Delete(proSpecTemp);
                _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = proSpecTemp.product_id });

                //刪除CourseDetailItemTemp hxw 2015/03/11
                ICourseDetailItemTempImplMgr _courDetaItemTempMgr = new CourseDetailItemTempMgr(connectionString);
                _courDetaItemTempMgr.Delete(_caller.user_id);

                //更新Product規格為無規格
                ProductTemp proTemp = new ProductTemp { Product_Spec = 0, Spec_Title_1 = "", Spec_Title_2 = "", Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE };
                proTemp.Product_Id = proSpecTemp.product_id;
                bool saveProductResult = _productTempMgr.SpecInfoSave(proTemp);


                if (!saveProductResult)
                {
                    resultStr = "{success:false}";
                }
            }
            catch (Exception ex)
            {
                resultStr = "{success: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);
            }


            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
        public ActionResult upLoadImg()
        {
            BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];//獲取當前登入的供應商
            int writerID = (int)vendorModel.vendor_id;

            string path = Server.MapPath(xmlPath);
            siteConfigMgr = new SiteConfigMgr(path);
            ViewBag.moreFileOneTime = false;
            SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format");
            SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue");
            SiteConfig maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
            SiteConfig admin_userName = siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
            SiteConfig admin_passwd = siteConfigMgr.GetConfigByName("ADMIN_PASSWD");

            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;

            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 localDescPath = imgLocalPath + descPath;
            //string localDesc400Path = imgLocalPath + desc400Path;
            string[] Mappath = new string[2];

            FileManagement fileLoad = new FileManagement();

            HttpPostedFileBase file = Request.Files["Filedata"];
            string nameType = Request.Params["nameType"];
            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_");
                string errorMsg = "ERROR/";
                if (prodCheck == -1 && specCheck == -1 && descCheck == -1)
                {
                    errorMsg += "[" + file.FileName + "] ";
                    errorMsg += Resources.VendorProduct.FILE_NAME_ERROR;

                    ViewBag.fileName = errorMsg;
                    return View("~/Views/VendorProduct/upLoad.cshtml");
                }
                else
                {
                    nameType = file.FileName.Split('_')[0];
                    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);
                    ProductSpecTemp proSpecTemp = new ProductSpecTemp();
                    string spec = file.FileName.Split('_')[1].Split('.')[0];
                    bool checkStatus = true;
                    if (!string.IsNullOrEmpty(Request.Params["product_id"].Split(';')[0].ToString()))
                    {
                        //product_spec
                        proSpecTemp.product_id = Request.Params["product_id"].Split(';')[0].ToString();
                    }
                    //product_spec_temp
                    _specTempMgr = new ProductSpecTempMgr(connectionString);

                    List<ProductSpecTemp> pSpecTempList = _specTempMgr.VendorQuery(new ProductSpecTemp { Writer_Id = writerID, 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.VendorProduct.SPEC_NOT_FIND;
                        ViewBag.fileName = errorMsg;
                        return View("~/Views/VendorProduct/upLoad.cshtml");
                    }
                }
                #endregion
            }

            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")
            {

                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("VendorProduct");
            try
            {
                //上傳圖片

                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                //上傳對應大小圖片
                //压缩图片至其它规格
            }
            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);
            }
            if (string.IsNullOrEmpty(ErrorMsg))
            {
                ViewBag.fileName = returnName;
            }
            else
            {
                ViewBag.fileName = "ERROR/" + ErrorMsg;
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = "ERROR/" + ErrorMsg;
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);

            }
            return View("~/Views/VendorProduct/upLoad.cshtml");
        }
Esempio n. 16
0
        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 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;
        }
Esempio n. 18
0
        public void DeletePicOnServer(bool prod, bool spec, bool desc, string product_id, int type = 1)
        {
            int writerId = (Session["caller"] as Caller).user_id;
            _productTempMgr = new ProductTempMgr(connectionString);
            _specTempMgr = new ProductSpecTempMgr(connectionString);
            _pPicTempMgr = new ProductPictureTempImplMgr(connectionString);
            ArrayList ImgList = new ArrayList();
            ProductSpecTemp pSpec = new ProductSpecTemp();
            pSpec.Writer_Id = writerId;
            pSpec.spec_type = 1;
            //刪除對應的圖片
            //商品圖
            if (prod)
            {
                ProductTemp query = new ProductTemp { Writer_Id = writerId, Combo_Type = COMBO_TYPE, Product_Id = product_id.ToString() };
                string fileName = _productTempMgr.GetProTemp(query).Product_Image;
                if (!string.IsNullOrEmpty(fileName))
                {
                    ImgList.Add(imgLocalPath + prodPath + GetDetailFolder(fileName) + fileName);
                    ImgList.Add(imgLocalPath + prod50Path + GetDetailFolder(fileName) + fileName);
                    ImgList.Add(imgLocalPath + prod150Path + GetDetailFolder(fileName) + fileName);
                    ImgList.Add(imgLocalPath + prod280Path + GetDetailFolder(fileName) + fileName);
                }

            }
            //規格圖
            if (spec)
            {
                List<ProductSpecTemp> pSList = _specTempMgr.Query(pSpec);
                foreach (var item in pSList)
                {
                    if (item.spec_image != "")
                    {
                        ImgList.Add(imgLocalPath + specPath + GetDetailFolder(item.spec_image) + item.spec_image);
                        ImgList.Add(imgLocalPath + spec100Path + GetDetailFolder(item.spec_image) + item.spec_image);
                        ImgList.Add(imgLocalPath + spec280Path + GetDetailFolder(item.spec_image) + item.spec_image);
                    }
                }
            }
            //商品說明圖
            if (desc)
            {
                ProductPictureTemp query = new ProductPictureTemp { writer_Id = writerId, combo_type = COMBO_TYPE, product_id = product_id };
                List<ProductPictureTemp> pPList = _pPicTempMgr.Query(query);
                SetPath(type);
                foreach (var item in pPList)
                {
                    ImgList.Add(imgLocalPath + descPath + GetDetailFolder(item.image_filename) + item.image_filename);
                    ImgList.Add(imgLocalPath + desc400Path + GetDetailFolder(item.image_filename) + item.image_filename);
                }
            }

            foreach (string item in ImgList)
            {
                //刪除服務器上對應的圖片
                if (System.IO.File.Exists(item))
                {
                    System.IO.File.Delete(item);
                }
            }
        }
        /// <summary>
        /// 刪除服務器上的圖片
        /// </summary>
        /// <param name="prod">商品圖是否刪除</param>
        /// <param name="spec">規格圖是否是否刪除</param>
        /// <param name="desc">說明圖是否刪除</param>
        /// <param name="spec_id">規格id</param>
        /// <param name="product_id">商品id</param>
        public void DeletePicOnServer(bool prod, bool spec, bool desc, uint spec_id, string product_id)
        {
            try
            {
                BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
                int writerId = (int)vendorModel.vendor_id;
                _productTempMgr = new ProductTempMgr(connectionString);
                _specTempMgr = new ProductSpecTempMgr(connectionString);
                _pPicTempMgr = new ProductPictureTempImplMgr(connectionString);
                ArrayList ImgList = new ArrayList();


                //刪除對應的圖片
                //商品圖
                if (prod)
                {
                    ProductTemp query = new ProductTemp { Writer_Id = writerId, Combo_Type = COMBO_TYPE, Create_Channel = 2, Product_Id = product_id };
                    string fileName = _productTempMgr.GetProTempByVendor(query).FirstOrDefault().Product_Image;
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        ImgList.Add(imgLocalPath + prodPath + GetDetailFolder(fileName) + fileName);
                        ImgList.Add(imgLocalPath + prod50Path + GetDetailFolder(fileName) + fileName);
                        ImgList.Add(imgLocalPath + prod150Path + GetDetailFolder(fileName) + fileName);
                        ImgList.Add(imgLocalPath + prod280Path + GetDetailFolder(fileName) + fileName);
                    }

                }
                //規格圖
                if (spec)
                {
                    ProductSpecTemp pSpec = new ProductSpecTemp();
                    pSpec.Writer_Id = writerId;
                    pSpec.spec_type = 1;
                    if (spec_id != 0)
                    {
                        pSpec.spec_id = spec_id;
                    }
                    if (!string.IsNullOrEmpty(product_id))
                    {
                        pSpec.product_id = product_id;
                    }
                    List<ProductSpecTemp> pSList = _specTempMgr.VendorQuery(pSpec);
                    foreach (var item in pSList)
                    {
                        if (item.spec_image != "")
                        {
                            ImgList.Add(imgLocalPath + specPath + GetDetailFolder(item.spec_image) + item.spec_image);
                            ImgList.Add(imgLocalPath + spec100Path + GetDetailFolder(item.spec_image) + item.spec_image);
                            ImgList.Add(imgLocalPath + spec280Path + GetDetailFolder(item.spec_image) + item.spec_image);
                        }
                    }
                }
                //商品說明圖
                if (desc)
                {
                    ProductPictureTemp query = new ProductPictureTemp { writer_Id = writerId, combo_type = COMBO_TYPE, product_id = product_id };
                    List<ProductPictureTemp> pPList = _pPicTempMgr.VendorQuery(query);
                    foreach (var item in pPList)
                    {
                        ImgList.Add(imgLocalPath + descPath + GetDetailFolder(item.image_filename) + item.image_filename);
                        ImgList.Add(imgLocalPath + desc400Path + GetDetailFolder(item.image_filename) + item.image_filename);
                    }
                }

                foreach (string item in ImgList)
                {
                    //刪除服務器上對應的圖片
                    if (System.IO.File.Exists(item))
                    {
                        System.IO.File.Delete(item);
                    }
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }
        }
Esempio n. 20
0
        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 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;
 }