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;
        }
        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;
        }