Example #1
0
        public bool CopyProduct(int writerId, int combo_type, string product_Id)
        {
            try
            {
                if (DeleteTemp(writerId, combo_type, product_Id)) 
                {
                    ArrayList sqls = new ArrayList();
                    var prodTemp = new ProductTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_Id = product_Id, Create_Channel = 1 };
                    sqls.Add(SaveFromPro(prodTemp));

                    //add by xiangwang0413w 2014/11/06
                    ProductDeliverySetTempMgr proDelSetTempMgr = new ProductDeliverySetTempMgr("");
                    sqls.Add(proDelSetTempMgr.SaveFromProDeliverySet(new ProductDeliverySetTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_id = int.Parse(product_Id) }));

                    ProductNoticeSetTempMgr proNoticeSetTempMgr = new ProductNoticeSetTempMgr("");
                    sqls.Add(proNoticeSetTempMgr.SaveFromProNotice(new ProductNoticeSetTemp { Writer_Id = writerId, Combo_Type = combo_type, product_id = product_Id }));

                    ProductTagSetTempMgr proTagSetTempMgr = new ProductTagSetTempMgr("");
                    sqls.Add(proTagSetTempMgr.SaveFromTag(new ProductTagSetTemp { Writer_Id = writerId, Combo_Type = combo_type, product_id = product_Id }));

                    ProductPictureTempImplMgr proPicTempMgr = new ProductPictureTempImplMgr("");
                    sqls.Add(proPicTempMgr.SaveFromProPicture(new ProductPictureTemp { writer_Id = writerId, combo_type = combo_type, product_id = product_Id },1));//複製商品說明圖
                    sqls.Add(proPicTempMgr.SaveFromProPicture(new ProductPictureTemp { writer_Id = writerId, combo_type = combo_type, product_id = product_Id }, 2));//複製手機app圖

                    ProductCategorySetTempMgr proCateSetTempMgr = new ProductCategorySetTempMgr("");
                    sqls.Add(proCateSetTempMgr.SaveFromCategorySet(new ProductCategorySetTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_Id = product_Id }));

                    PriceMasterTempMgr priceMasterTempMgr = new PriceMasterTempMgr("");

                    ArrayList specs = new ArrayList();
                    if (combo_type == 1)//單一商品
                    {
                        sqls.Add(priceMasterTempMgr.SaveFromPriceMaster(new PriceMasterTemp { writer_Id = writerId, product_id = product_Id, combo_type = combo_type }));
                        //add by dongya 2015/08/25 添加信息到商品推薦臨時表  用來複製商品 
                        RecommendedProductAttributeMgr recommendAttributeMgr = new RecommendedProductAttributeMgr("");
                        sqls.Add(recommendAttributeMgr.SaveRecommendedProductAttributSet(new RecommendedRroductAttributeTemp{write_id = writerId, product_id = UInt32.Parse(product_Id),combo_type=combo_type}));
                        ProductItemTempMgr proItemTempMgr = new ProductItemTempMgr("");
                        var prodItemTemp = new ProductItemTemp { Writer_Id = writerId, Product_Id = product_Id };

                        sqls.Add(proItemTempMgr.SaveFromProItem(prodItemTemp));

                        ProductSpecMgr proSpecMgr = new ProductSpecMgr(connStr);
                        List<ProductSpec> proSpecs = proSpecMgr.Query(new ProductSpec { product_id = uint.Parse(product_Id) });
                        if (proSpecs != null)
                        {
                            ProductSpecTempMgr proSpecTempMgr = new ProductSpecTempMgr("");
                            StringBuilder str;
                            foreach (var item in proSpecs)
                            {
                                sqls.Add(proSpecTempMgr.SaveFromSpec(new ProductSpecTemp { Writer_Id = writerId, product_id = product_Id, spec_id = item.spec_id }));

                                str = new StringBuilder();
                                str.Append(proSpecTempMgr.UpdateCopySpecId(new ProductSpecTemp { Writer_Id = writerId, product_id = product_Id, spec_id = item.spec_id }));
                                str.Append(proItemTempMgr.UpdateCopySpecId(new ProductItemTemp { Writer_Id = writerId, Product_Id = product_Id, Spec_Id_1 = item.spec_id, Spec_Id_2 = item.spec_id }));
                                specs.Add(str.ToString());
                            }
                        }
                        return _pTempDao.CopyProduct(sqls, specs, null, null, null);
                    }
                    else
                    {
                        PriceMasterMgr priceMasterMgr = new PriceMasterMgr("");
                        string selMaster = priceMasterMgr.SelectChild(new PriceMaster { product_id = uint.Parse(product_Id) });

                        string moveMaster = priceMasterTempMgr.SaveFromPriceMasterByMasterId(new PriceMasterTemp { combo_type = combo_type, writer_Id = writerId });

                        ItemPriceTempMgr itemPriceTempMgr = new ItemPriceTempMgr("");
                        string movePrice = itemPriceTempMgr.SaveFromItemPriceByMasterId();

                        //add by dongya 2015/08/25 添加信息到商品推薦臨時表  用來複製商品 
                        RecommendedProductAttributeMgr recommendAttributeMgr = new RecommendedProductAttributeMgr("");
                        sqls.Add(recommendAttributeMgr.SaveRecommendedProductAttributSet(new RecommendedRroductAttributeTemp { write_id = writerId, product_id = UInt32.Parse(product_Id),combo_type=combo_type }));
                        ProductComboTempMgr proComboTempMgr = new ProductComboTempMgr("");
                        sqls.Add(proComboTempMgr.SaveFromCombo(new ProductComboTemp { Writer_Id = writerId, Parent_Id = product_Id }));

                        return _pTempDao.CopyProduct(sqls, specs, selMaster, moveMaster, movePrice);
                    }
                }
                return false;
            }
            catch (Exception ex)
            {
                throw new Exception("ProductTempMgr.CopyProduct-->" + ex.Message, ex);
            }
        }