예제 #1
0
        public HttpResponseBase tempCategoryAdd()
        {

            Caller _caller = (Session["caller"] as Caller);
            string resultStr = "{success:true}";
            string tempStr = Request.Params["result"];
            string cate_id = Request.Params["cate_id"];
            string deStr = Request["oldresult"] == null ? "0" : Request["oldresult"];

            List<ProductCategorySetTemp> saveTempList = new List<ProductCategorySetTemp>();
            try
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                List<ProductCategorySetCustom> cateCustomList = js.Deserialize<List<ProductCategorySetCustom>>(tempStr);
                if (string.IsNullOrEmpty(tempStr))
                {
                    cateCustomList = new List<ProductCategorySetCustom>();
                }


                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    #region 修改正式表
                    uint pid = uint.Parse(Request.Params["ProductId"]);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _categorySetMgr = new ProductCategorySetMgr(connectionString);
                    _productMgr = new ProductMgr(connectionString);

                    Product pro = new Product();
                    pro = _productMgr.Query(new Product { Product_Id = pid }).FirstOrDefault();
                    pro.Cate_Id = cate_id;

                    _functionMgr = new FunctionMgr(connectionString);
                    string function = Request.Params["function"] ?? "";
                    Function fun = _functionMgr.QueryFunction(function, "/ProductCombo");
                    int functionid = fun == null ? 0 : fun.RowId;
                    HistoryBatch batch = new HistoryBatch { functionid = functionid };
                    batch.batchno = Request.Params["batch"] ?? "";
                    batch.kuser = (Session["caller"] as Caller).user_email;

                    ArrayList sqls = new ArrayList();
                    sqls.Add(_categorySetMgr.Delete(new ProductCategorySet { Product_Id = pid }));
                    sqls.Add(_productMgr.Update(pro));
                    foreach (ProductCategorySetCustom item in cateCustomList)
                    {
                        item.Product_Id = pid;
                        item.Brand_Id = pro.Brand_Id;
                        sqls.Add(_categorySetMgr.Save(item));
                    }

                    if (!_tableHistoryMgr.SaveHistory<ProductCategorySetCustom>(cateCustomList, batch, sqls))
                    {
                        resultStr = "{success:false}";
                    }
                    #endregion
                }
                else
                {
                    #region 修改臨時表

                    string product_id = "0";
                    if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                    {
                        product_id = Request.Form["OldProductId"];
                    }
                    _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString);
                    _productTempMgr = new ProductTempMgr(connectionString);
                    if (string.IsNullOrEmpty(tempStr))
                    {
                        bool result = _categoryTempSetMgr.Delete(new ProductCategorySetTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }, deStr);
                    }
                    else
                    {
                        ProductCategorySetTemp saveTemp;
                        ProductTemp query = new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id.ToString() };
                        ProductTemp proTemp = _productTempMgr.GetProTemp(query);
                        foreach (ProductCategorySetCustom item in cateCustomList)
                        {
                            saveTemp = new ProductCategorySetTemp();
                            saveTemp.Writer_Id = _caller.user_id;
                            saveTemp.Product_Id = product_id;
                            saveTemp.Category_Id = item.Category_Id;
                            saveTemp.Brand_Id = proTemp.Brand_Id;
                            saveTemp.Combo_Type = COMBO_TYPE;
                            saveTempList.Add(saveTemp);
                        }

                        if (!_categoryTempSetMgr.Save(saveTempList))
                        {
                            resultStr = "{success:false}";
                        }
                    }

                    if (!_productTempMgr.CategoryInfoUpdate(new ProductTemp { Writer_Id = _caller.user_id, Cate_Id = cate_id, Combo_Type = COMBO_TYPE, Product_Id = product_id.ToString() }))
                    {
                        resultStr = "{success:false}";
                    }

                    #endregion
                }

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                resultStr = "{success:false}";
            }

            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }
예제 #2
0
        public ActionResult tempCategoryAdd(int categoryType, int coboType = 1)
        {
            COMBO_TYPE = coboType;
            string resultStr = "{success:true}";
            string oldresult = Request["oldresult"];//add by wwei0216w 2014/12/26 需要刪除的選中項

            if (string.IsNullOrEmpty(oldresult))
            {
                resultStr = "{success:false}";
                return Content(resultStr);
            }
            try
            {
                Caller _caller = (Session["caller"] as Caller);
                string tempStr = "";
                string cate_id = "";
                if (!string.IsNullOrEmpty(Request.Params["result"]))
                {
                    tempStr = Request.Params["result"];
                }

                if (!string.IsNullOrEmpty(Request.Params["cate_id"]))
                {
                    cate_id = Request.Params["cate_id"];
                }

                List<ProductCategorySetTemp> saveTempList = new List<ProductCategorySetTemp>();

                JavaScriptSerializer js = new JavaScriptSerializer();
                List<ProductCategorySetCustom> cateCustomList = js.Deserialize<List<ProductCategorySetCustom>>(tempStr);
                string deStr = "";
                //if (categoryType == 2)//新類別
                //{


                //    if (cateCustomList.Count() <= 0)
                //    {
                //        resultStr = "{success:false,msg:'新類別必選'}";
                //        return Content(resultStr);
                //    }
                //}

                #region 將要刪除的id 拼成 '1,2,3'這種形式
                List<ProductCategorySetCustom> deleteCategorySet = js.Deserialize<List<ProductCategorySetCustom>>(oldresult);

                if (deleteCategorySet.Count() > 0)
                {
                    foreach (var item in deleteCategorySet)
                    {
                        deStr += item.Category_Id + ",";
                    }
                    deStr = deStr.Remove(deStr.Length - 1);
                }
                #endregion



                if (string.IsNullOrEmpty(tempStr))
                {
                    cateCustomList = new List<ProductCategorySetCustom>();
                }


                if (!string.IsNullOrEmpty(Request.Params["ProductId"]))
                {
                    #region 修改正式表
                    uint pid = uint.Parse(Request.Params["ProductId"]);
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _categorySetMgr = new ProductCategorySetMgr(connectionString);
                    _productMgr = new ProductMgr(connectionString);


                    Product pro = new Product();
                    pro = _productMgr.Query(new Product { Product_Id = pid }).FirstOrDefault();
                    if (pro != null)
                    {
                        _functionMgr = new FunctionMgr(connectionString);
                        string function = Request.Params["function"] ?? "";
                        Function fun = _functionMgr.QueryFunction(function, "/Product/ProductSave");
                        int functionid = fun == null ? 0 : fun.RowId;
                        HistoryBatch batch = new HistoryBatch { functionid = functionid };
                        batch.batchno = Request.Params["batch"] ?? "";
                        batch.kuser = (Session["caller"] as Caller).user_email;



                        ArrayList sqls = new ArrayList();
                        if (deStr != "")
                        {
                            sqls.Add(_categorySetMgr.Delete(new ProductCategorySet { Product_Id = pid }, deStr));
                        }
                        if (categoryType == 1)
                        {
                            pro.Cate_Id = cate_id;
                        }
                        else if (categoryType == 2)  //edit by wwei0216w 如果是新類別 就不進行報表修改
                        {
                            pro.Prod_Classify = Convert.ToInt32(Request["prodClassify"]); //獲得對應館別ID
                            _tableHistoryMgr.SaveHistory<Product>(pro, batch, null);
                        }

                        sqls.Add(_productMgr.Update(pro, _caller.user_id));
                        foreach (ProductCategorySetCustom item in cateCustomList)
                        {
                            item.Product_Id = pid;
                            item.Brand_Id = pro.Brand_Id;
                            sqls.Add(_categorySetMgr.Save(item));
                        }

                        if (!_tableHistoryMgr.SaveHistory<ProductCategorySetCustom>(cateCustomList, batch, sqls))
                        {

                            throw new Exception("there is no History be saved");
                        }
                        //else
                        //{ //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30
                        //    if (pro.Combination == 1)
                        //    {
                        //        _productItemMgr = new ProductItemMgr(connectionString);
                        //        ProductItem pro_Item = new ProductItem() { Product_Id = pro.Product_Id, Export_flag = 2 };
                        //        _productItemMgr.UpdateExportFlag(pro_Item);
                        //    }
                        //}
                    }
                    else
                    {
                        throw new Exception("None Product has being found");
                    }
                    #endregion
                }
                else
                {
                    #region 修改臨時表
                    string product_id = "0";
                    if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                    {
                        product_id = Request.Form["OldProductId"];
                    }
                    _categoryTempSetMgr = new ProductCategorySetTempMgr(connectionString);
                    _productTempMgr = new ProductTempMgr(connectionString);

                    bool result = _categoryTempSetMgr.Delete(new ProductCategorySetTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }, deStr);

                    ProductTemp query = new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id };
                    ProductTemp proTemp = _productTempMgr.GetProTemp(query);
                    ProductCategorySetTemp saveTemp;

                    if (proTemp == null)
                    {
                        resultStr = "{success:false}";
                    }
                    else
                    {
                        foreach (ProductCategorySetCustom item in cateCustomList)
                        {
                            saveTemp = new ProductCategorySetTemp();
                            saveTemp.Writer_Id = _caller.user_id;
                            saveTemp.Product_Id = product_id;
                            saveTemp.Category_Id = item.Category_Id;
                            saveTemp.Brand_Id = proTemp.Brand_Id;
                            saveTemp.Combo_Type = COMBO_TYPE;
                            saveTempList.Add(saveTemp);
                        }

                        if (!_categoryTempSetMgr.Save(saveTempList))
                        {
                            resultStr = "{success:false}";
                        }
                    }

                    proTemp.Combo_Type = COMBO_TYPE;
                    proTemp.Product_Id = product_id;
                    if (categoryType == 1)
                    {
                        proTemp.Cate_Id = cate_id;
                    }
                    else if (categoryType == 2)  //edit by wwei0216w 如果是新類別 就不進行報表修改
                    {
                        proTemp.Prod_Classify = Convert.ToInt32(Request["prodClassify"]); //獲得對應館別ID
                    }

                    if (!_productTempMgr.CategoryInfoUpdate(proTemp))
                    {
                        resultStr = "{success:false}";
                    }

                    #endregion
                }

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                resultStr = "{success:false}";
                return Content(resultStr);
            }

            return Content(resultStr);
            ////this.Response.Clear();
            ////this.Response.Write(resultStr);
            ////this.Response.End();
            ////return this.Response;
        }