/// <summary>
 /// 刪除
 /// </summary>
 /// <param name="proDelSetTemp"></param>
 /// <returns>sql字符串</returns>
 public string Delete(ProductDeliverySetTemp proDelSetTemp)
 {
     string strSql= string.Format(@"set sql_safe_updates=0;delete from product_delivery_set_temp
         where writer_id={0} and combo_type={1} and product_id={2};set sql_safe_updates=1;",
         proDelSetTemp.Writer_Id,proDelSetTemp.Combo_Type,proDelSetTemp.Product_id);
     return strSql;
 }
 public string SaveFromProDeliverySet(ProductDeliverySetTemp proDelSetTemp)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("insert into product_delivery_set_temp(writer_id,product_id,freight_big_area,freight_type,combo_type) ");
     strSql.AppendFormat(" select {0} as writer_id,product_id,freight_big_area,freight_type,{1} as combo_type from product_delivery_set ",proDelSetTemp.Writer_Id,proDelSetTemp.Combo_Type);
     strSql.AppendFormat(" where product_id = {0}", proDelSetTemp.Product_id);
     return strSql.ToString();
 }
Ejemplo n.º 3
0
        public int TempMove2Pro(int writerId, int combo_type, string product_Id)
        {
            ArrayList sqls = new ArrayList();
            int product_id = 0;
            ProductTempMgr proTempMgr = new ProductTempMgr("");
            ProductTemp proTemp = new ProductTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_Id = product_Id, Create_Channel = 1 };//1:後台管理者(manage_user) edit by xiagnwang0413w 2014/08/09
            string movePro = proTempMgr.MoveProduct(proTemp);
            sqls.Add(proTempMgr.Delete(proTemp));

            /*********start*********/
            //將ProductDeliverySetTemp表數據導入正式表 edit by xiangwang0413w 2014/11/06
            IProductDeliverySetTempImplMgr _proDelSetTemp = new ProductDeliverySetTempMgr("");
            var proDelSetTemp = new ProductDeliverySetTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_id = int.Parse(product_Id) };
            sqls.Add(_proDelSetTemp.MoveProductDeliverySet(proDelSetTemp));
            sqls.Add(_proDelSetTemp.Delete(proDelSetTemp));
            /*******end***********/

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

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

            ProductPictureTempImplMgr proPicTempMgr = new ProductPictureTempImplMgr("");
            ProductPictureTemp proPictureTemp = new ProductPictureTemp { writer_Id = writerId, combo_type = combo_type, product_id = product_Id };
            sqls.Add(proPicTempMgr.MoveToProductPicture(proPictureTemp, 1));//更新說明圖表
            sqls.Add(proPicTempMgr.MoveToProductPicture(proPictureTemp, 2));//更新APP圖表
            sqls.Add(proPicTempMgr.Delete(proPictureTemp, 1));//刪除說明圖臨時表
            sqls.Add(proPicTempMgr.Delete(proPictureTemp, 2)); //刪除app臨時表 add by wwei0216w 2014/11/11

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

            ProductStatusHistoryMgr proStatusHistoryMgr = new ProductStatusHistoryMgr("");
            sqls.Add(proStatusHistoryMgr.SaveNoProductId(new ProductStatusHistory { product_status = 0, user_id = Convert.ToUInt32(writerId), type = 5 }));

            ItemPriceTempMgr itemTempPriceMgr = new ItemPriceTempMgr("");
            sqls.Add(itemTempPriceMgr.Delete(product_Id, combo_type, writerId));

            PriceMasterTempMgr priceMasterTempMgr = new PriceMasterTempMgr("");
            PriceMasterTemp priceMasterTemp = new PriceMasterTemp { writer_Id = writerId, product_id = product_Id, combo_type = combo_type };
            sqls.Add(priceMasterTempMgr.Delete(priceMasterTemp));

            //判斷是單一商品還是組合商品
            if (combo_type == 1)
            {//單一商品
                IProductItemImplDao piDao = new ProductItemDao(connectionStr);
                ProductItemTempMgr proItemTempMgr = new ProductItemTempMgr("");
                ProductItemTemp proItemTemp = new ProductItemTemp { Writer_Id = writerId, Product_Id = product_Id };
                string selItem = proItemTempMgr.QuerySql(proItemTemp);
                string moveItem = proItemTempMgr.MoveProductItem(proItemTemp);
                sqls.Add(proItemTempMgr.DeleteSql(proItemTemp));

                /*************start*課程相關*****************/
                //CourseDetailItem
                ICourseDetailItemTempImplMgr _cdItemMgr = new CourseDetailItemTempMgr("");
                string moveCourDetaItem = _cdItemMgr.MoveCourseDetailItem(writerId);
                sqls.Add(_cdItemMgr.DeleteSql(writerId));

                //CourseProduct
                ICourseProductTempImplMgr _courProdTempMgr = new CourseProductTempMgr("");
                var courProdTemp = new CourseProductTemp { Writer_Id = writerId, Product_Id = uint.Parse(product_Id) };
                string moveCourProd = _courProdTempMgr.MoveCourseProduct(courProdTemp);
                sqls.Add(_courProdTempMgr.DeleteSql(courProdTemp));
                /*************end**********************************/



                ProductSpecTempMgr proSpecTempMgr = new ProductSpecTempMgr("");
                ProductSpecTemp proSpecTemp = new ProductSpecTemp { Writer_Id = writerId, product_id = product_Id };
                sqls.Add(proSpecTempMgr.TempMoveSpec(proSpecTemp));
                sqls.Add(proSpecTempMgr.TempDelete(proSpecTemp));



                string priceMaster = priceMasterTempMgr.Move2PriceMaster(priceMasterTemp);

                ItemPriceMgr itemPriceMgr = new ItemPriceMgr("");
                string itemPrice = itemPriceMgr.SaveFromItem(writerId, product_Id);

                product_id = _productDao.TempMove2Pro(movePro, moveCourProd, moveItem, moveCourDetaItem, selItem, priceMaster, itemPrice, sqls);
                //把商品推薦屬性臨時表中的數據moveto商品推薦屬性表中,然後刪除商品推薦臨時表 通過product_id指定商品推薦屬性對應的商品
                #region 推薦商品屬性插入recommended_product_attribute表中做記錄
                if (_rProductAttribute.ExsitInTemp(writerId, int.Parse(product_Id), combo_type) > 0)//判斷臨時表中是否存在 product_Id為傳入的productId
                {
                    DataTable _dt = _rProductAttribute.GetTempList(writerId, int.Parse(product_Id), combo_type);
                    RecommendedProductAttribute rPA = new RecommendedProductAttribute();
                    rPA.product_id = Convert.ToUInt32(product_id);
                    rPA.time_start = 0;
                    rPA.time_end = 0;
                    rPA.expend_day = Convert.ToUInt32(_dt.Rows[0]["expend_day"]);
                    rPA.months = _dt.Rows[0]["months"].ToString();
                    rPA.combo_type = 1;
                    if (_rProductAttribute.GetMsgByProductId(product_id) > 0)//如果大於0,表示推薦表中存在數據
                    {
                        if (_rProductAttribute.Update(rPA) > 0)
                        {
                            _rProductAttribute.DeleteTemp(writerId, int.Parse(product_Id), combo_type);//刪除臨時表中的數據
                        }
                    }
                    else
                    {
                        if (_rProductAttribute.Save(rPA) > 0)
                        {
                            _rProductAttribute.DeleteTemp(writerId, int.Parse(product_Id), combo_type);//刪除臨時表中的數據
                        }
                    }
                }
                #endregion
                if (product_id > 0)
                {
                    piDao.UpdateErpId(product_id.ToString());
                }
                return product_id;
            }
            else
            {//組合商品
                ProductComboTempMgr pcTempMgr = new ProductComboTempMgr("");
                ProductComboTemp proComboTemp = new ProductComboTemp { Writer_Id = writerId, Parent_Id = product_Id };
                sqls.Add(pcTempMgr.TempMoveCombo(proComboTemp));
                sqls.Add(pcTempMgr.TempDelete(proComboTemp));
                string selPrice = priceMasterTempMgr.SelectChild(priceMasterTemp);
                string priceMaster = priceMasterTempMgr.Move2PriceMasterByMasterId();
                ItemPriceTempMgr itemPriceTempMgr = new ItemPriceTempMgr("");
                string itemPrice = itemPriceTempMgr.Move2ItemPrice();
                sqls.Add(itemPriceTempMgr.Delete(product_Id, combo_type, writerId));
                product_id = _productDao.TempMove2Pro(movePro, "", "", "", selPrice, priceMaster, itemPrice, sqls);
                //把商品推薦屬性臨時表中的數據moveto商品推薦屬性表中,然後刪除商品推薦臨時表 通過product_id指定商品推薦屬性對應的商品
                #region 推薦商品屬性插入recommended_product_attribute表中做記錄
                if (_rProductAttribute.ExsitInTemp(writerId, int.Parse(product_Id), combo_type) > 0)//判斷臨時表中是否存在 product_Id為傳入的productId
                {
                    DataTable _dt = _rProductAttribute.GetTempList(writerId, int.Parse(product_Id), combo_type);
                    RecommendedProductAttribute rPA = new RecommendedProductAttribute();
                    rPA.product_id = Convert.ToUInt32(product_id);
                    rPA.time_start = 0;
                    rPA.time_end = 0;
                    rPA.expend_day = Convert.ToUInt32(_dt.Rows[0]["expend_day"]);
                    rPA.months = _dt.Rows[0]["months"].ToString();
                    rPA.combo_type = 2;
                    if (_rProductAttribute.GetMsgByProductId(product_id) > 0)//如果大於0,表示推薦表中存在數據
                    {
                        if (_rProductAttribute.Update(rPA) > 0)
                        {
                            _rProductAttribute.DeleteTemp(writerId, int.Parse(product_Id), combo_type);//刪除臨時表中的數據
                        }
                    }
                    else
                    {
                        if (_rProductAttribute.Save(rPA) > 0)
                        {
                            _rProductAttribute.DeleteTemp(writerId, int.Parse(product_Id), combo_type);//刪除臨時表中的數據
                        }
                    }
                }
                return product_id;
                #endregion
            }
        }
 /// <summary>
 /// 查詢符合條件的ProductDeliverySet集合
 /// </summary>
 /// <param name="pds">查詢的條件</param>
 /// <returns>符合條件的集合</returns>
 public List<ProductDeliverySetTemp> QueryByProductId(ProductDeliverySetTemp query) 
 {
     string sqlStr = string.Format("SELECT product_id,freight_big_area,freight_type FROM product_delivery_set_temp where product_id ={0} and combo_type={1} and writer_id={2}",
         query.Product_id,query.Combo_Type, query.Writer_Id);
   return _dbAccess.getDataTableForObj<ProductDeliverySetTemp>(sqlStr);
 }