public PromotionsAmountDiscountMgr(string connectionstring)
 {
     _mysqlDao = new MySqlDao(connectionstring);
     _padDao = new PromotionsAmountDiscountDao(connectionstring);
     _prodpromoDao = new ProdPromoDao(connectionstring);
     _proCateDao = new ProductCategoryDao(connectionstring);
     _prodCategSet = new ProductCategorySetDao(connectionstring);
     _proAllDao = new PromoAllDao(connectionstring);
     _usconDao = new UserConditionDao(connectionstring);
     _promoDisDao = new PromoDiscountDao(connectionstring);
     _promoMainDao = new PromotionsMaintainDao(connectionstring);
     _prodDao = new ProductDao(connectionstring);
     _vendorBrandDao = new VendorBrandDao(connectionstring);
     connStr = connectionstring;
 }
 /// <summary>
 /// 有參構造函數
 /// </summary>
 /// <param name="connectionstring">數據庫連接字符串</param>
 public PromotionsAmountGiftDao(string connectionstring)
 {
     _access = DBFactory.getDBAccess(DBType.MySql, connectionstring);
     this.connStr = connectionstring;
     _proCateDao = new ProductCategoryDao(connectionstring);
     _prodCategSetDao = new ProductCategorySetDao(connectionstring);
     _prodpromoDao = new ProdPromoDao(connectionstring);
     _proAllDao = new PromoAllDao(connectionstring);
     _usconDao = new UserConditionDao(connectionstring);
     _promoDisDao = new PromoDiscountDao(connectionstring);
     _serialDao = new SerialDao(connectionstring);
     _ptDao = new PromoTicketDao(connectionstring);
     _prodDao = new ProductDao(connectionstring);
     _promoMainDao = new PromotionsMaintainDao(connectionstring);
     _vendorBrandDao = new VendorBrandDao(connectionstring);
 }
 public HttpResponseBase GetProductByCategorySet()
 {
     string resultStr = "{success:false}";
     try
     {
         QueryVerifyCondition query = new QueryVerifyCondition();
         if (!string.IsNullOrEmpty(Request.Params["producateid"]))//活動類別編號
         {
             query.cate_id = Request.Params["producateid"];
         }
         if (!string.IsNullOrEmpty(Request.Params["key"]))//變動3支持商品編號批次搜索
         {
             query.product_name = Request.Params["key"].Replace(',', ',').Replace('|', ',').Replace(' ', ',');
         }
         //站台改成多個站台的site_id字符串 edit by shuangshuang0420j 20140925 13:40
         if (!string.IsNullOrEmpty(Request.Params["site_id"]))
         {
             query.site_ids = Request.Params["site_id"];
         }
         int totalCount = 0;
         query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
         query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");
         PromotionsMaintainDao pmDao = new PromotionsMaintainDao(connectionString);
         List<QueryandVerifyCustom> tempPros = pmDao.GetEventList(query, out totalCount);
         resultStr = "{succes:true,totalCount:" + totalCount + ",item:" + JsonConvert.SerializeObject(tempPros) + "}";
     }
     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 QueryProList()
        {
            string json = string.Empty;
            string _classid = String.Empty;
            PromotionsMaintainDao pmDao = new PromotionsMaintainDao(connectionString);
            try
            {
                QueryVerifyCondition query = new QueryVerifyCondition();
                #region 查询条件填充
                query.IsPage = true;
                query.Start = int.Parse(Request.Params["start"] ?? "0");
                query.Limit = int.Parse(Request.Params["limit"] ?? "25");
                if (!string.IsNullOrEmpty(Request.Params["ProCatid"]))//活動的category_id
                {
                    query.cate_id = Request.Form["ProCatid"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["key"]))//變動1支持商品編號的批次查詢
                {
                    query.product_name = Request.Params["key"].Replace(',', ',').Replace('|', ',').Replace(' ', ','); //在這裡product_id用,分割拼接的字符串用product_name 存放
                }

                if (!string.IsNullOrEmpty(Request.Params["site_id"]))//支持多站台查詢
                {
                    query.site_ids = Request.Params["site_id"].ToString();
                }

                if (!string.IsNullOrEmpty(Request.Params["comboFrontCage_hide"]))//支持類別查詢商品
                {
                    query.category_id = Convert.ToUInt32(Request.Params["comboFrontCage_hide"].ToString());
                }

                #endregion
                query.combination = 1;//只顯示單一商品
                int totalCount = 0;
                if (!string.IsNullOrEmpty(Request.Params["brand_id"]))//支持品牌查詢
                {
                    query.brand_id = uint.Parse(Request.Params["brand_id"]);
                }
                else
                {
                    if (!string.IsNullOrEmpty(Request.Params["class_id"]))//支持館別查詢
                    {
                        VendorBrandSetMgr vbsMgr = new VendorBrandSetMgr(connectionString);
                        VendorBrandSet vbs = new VendorBrandSet();
                        vbs.class_id = Convert.ToUInt32(Request.Params["class_id"]);
                        List<VendorBrandSet> vbsList = vbsMgr.Query(vbs);
                        foreach (VendorBrandSet item in vbsList)
                        {
                            query.brand_ids += item.brand_id + ",";
                        }
                        query.brand_ids = query.brand_ids.TrimEnd(',');
                    }
                }
                List<QueryandVerifyCustom> pros = pmDao.GetProList(query, out totalCount);
                json = "{succes:true,totalCount:" + totalCount + ",item:" + JsonConvert.SerializeObject(pros) + "}";
            }
            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 = "{succes:true,totalCount:0,item:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public int Update(PromotionsAmountFareQuery model, string oldEventId)
        {
            int i = 0;
            MySqlCommand mySqlCmd = new MySqlCommand();
            MySqlConnection mySqlConn = new MySqlConnection(connStr);
            StringBuilder sbExSql = new StringBuilder();
            try
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Closed)
                {
                    mySqlConn.Open();
                }
                mySqlCmd.Connection = mySqlConn;
                mySqlCmd.Transaction = mySqlConn.BeginTransaction();
                mySqlCmd.CommandType = System.Data.CommandType.Text;
                StringBuilder sqlf = new StringBuilder();

                mySqlCmd.CommandText = _prodPromoDao.DeleteProdProm(model.event_id);
                sbExSql.Append(mySqlCmd.CommandText);
                mySqlCmd.ExecuteNonQuery();//刪除ProdPromo

                mySqlCmd.CommandText = _promoAllDao.DelPromAll(model.event_id);
                sbExSql.Append(_promoAllDao.DelPromAll(mySqlCmd.CommandText));
                mySqlCmd.ExecuteNonQuery();//刪除PromAll

                if (model.allClass == 0)
                {
                    //刪除全館商品
                    ProductCategorySet qgSet = new ProductCategorySet();
                    qgSet.Category_Id = model.category_id;
                    qgSet.Product_Id = 999999;//全館商品刪除 id=999999
                    //根據category_id刪除product_category_set表數據
                    mySqlCmd.CommandText = _prodCateSetDao.DelProdCateSetByCPID(qgSet);
                    sbExSql.Append(mySqlCmd.CommandText);
                    mySqlCmd.ExecuteNonQuery();//刪除全館別商品999999

                    if (model.brand_id != 0)//當品牌不為空時講該品牌下的所有商品加入set表
                    {
                        sqlf.Append(_prodCateSetDao.DeleteProdCateSet(model.category_id));

                        mySqlCmd.CommandText = sqlf.ToString();
                        sbExSql.Append(mySqlCmd.CommandText);
                        mySqlCmd.ExecuteNonQuery();
                        sqlf.Clear();

                        QueryVerifyCondition query = new QueryVerifyCondition();//根據條件從product表中獲取符合條件的商品并添加到set和prodprom表中
                        query.brand_id = Convert.ToUInt32(model.brand_id);//品牌
                        query.site_ids = model.site;
                        query.combination = 1;
                        PromotionsMaintainDao _promoMainDao = new PromotionsMaintainDao(connStr);
                        query.IsPage = false;
                        int totalCount = 0;
                        List<QueryandVerifyCustom> qvcList = _promoMainDao.GetProList(query, out totalCount);

                        List<uint> categorysetProduct = new List<uint>();
                        foreach (QueryandVerifyCustom qvcItem in qvcList)
                        {
                            if (categorysetProduct.Contains(qvcItem.product_id))
                            {
                                continue;
                            }
                            categorysetProduct.Add(qvcItem.product_id);
                            ProductCategorySet pcsModel = new ProductCategorySet();
                            pcsModel.Product_Id = qvcItem.product_id;
                            pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                            pcsModel.Category_Id = model.category_id;
                            //刪除已有的 新增異動的
                            sqlf.Append(_prodCateSetDao.SaveProdCategorySet(pcsModel));

                        }
                    }
                    if (!string.IsNullOrEmpty(sqlf.ToString()))
                    {
                        mySqlCmd.CommandText = sqlf.ToString();
                        sbExSql.Append(mySqlCmd.CommandText);
                        mySqlCmd.ExecuteNonQuery();
                        sqlf.Clear();
                    }

                }
                else//全館時
                {
                    sqlf.Clear();
                    sqlf.AppendFormat(_prodCateSetDao.DeleteProdCateSet(model.category_id));


                    ProductCategorySet pcs = new ProductCategorySet();
                    pcs.Category_Id = model.category_id;
                    pcs.Product_Id = 999999;
                    pcs.Brand_Id = 0;
                    sqlf.Append(_prodCateSetDao.SaveProdCategorySet(pcs));
                    mySqlCmd.CommandText = sqlf.ToString();
                    sbExSql.Append(_promoAllDao.DeletePromAll(mySqlCmd.CommandText));
                    mySqlCmd.ExecuteNonQuery();

                }
                sqlf.Clear();
                PromoAll pamodel = new PromoAll();
                pamodel.event_id = model.event_id;
                pamodel.event_type = model.event_type;
                pamodel.category_id = Convert.ToInt32(model.category_id);
                pamodel.startTime = model.start;
                pamodel.end = model.end;
                pamodel.status = model.status;
                pamodel.kuser = model.kuser;
                pamodel.kdate = model.created;
                pamodel.muser = model.muser;
                pamodel.mdate = model.modified;
                pamodel.product_id = model.product_id;
                pamodel.class_id = model.class_id;
                pamodel.brand_id = model.brand_id;
                sqlf.AppendFormat(_promoAllDao.SavePromAll(pamodel));
                ProductCategoryDao _categoryDao = new ProductCategoryDao(connStr);
                ProductCategory pcmodel = _categoryDao.GetModelById(Convert.ToUInt32(model.category_id));
                pcmodel.category_id = Convert.ToUInt32(model.category_id);
                pcmodel.category_name = model.name;
                pcmodel.banner_image = model.banner_image;
                pcmodel.category_link_url = model.category_link_url;
                pcmodel.category_father_id = model.category_father_id;
                pcmodel.category_updatedate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(model.modified.ToString());
                pcmodel.category_display = Convert.ToUInt32(model.status);
                sqlf.AppendFormat(_cateDao.UpdateProdCate(pcmodel));
                PromotionsAmountReduce parModel = new PromotionsAmountReduce();
                parModel.id = model.id;
                parModel.name = model.name;
                parModel.delivery_store = model.delivery_store;
                parModel.group_id = model.group_id;
                parModel.type = model.type;
                parModel.amount = model.amount;
                parModel.quantity = model.quantity;
                parModel.start = model.start;
                parModel.end = model.end;
                parModel.updatetime = model.modified;
                parModel.created = model.created;
                parModel.active = model.active ? 1 : 0;
                parModel.status = model.status;
                sqlf.AppendFormat(_promAmountReduceDao.Update(parModel));
                mySqlCmd.CommandText = sqlf + UpdatePromoFare(model);
                i += mySqlCmd.ExecuteNonQuery();
                mySqlCmd.Transaction.Commit();
            }
            catch (Exception ex)
            {
                mySqlCmd.Transaction.Rollback();
                throw new Exception("PromotionsAmountFareDao-->Update-->sql:" + sbExSql.ToString() + ex.Message, ex);
            }
            finally
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
                {
                    mySqlConn.Close();
                }
            }
            return i;
        }
        /// <summary>
        /// 第二步保存和編輯數據  更新主表和product_category數據 處理product_category_set prod_promo prom_all prom_ticket
        /// </summary>
        /// <param name="model">query對象</param>
        /// <param name="oldeventid">原來的event_type</param>
        /// <returns>執行結果</returns>
        public int Update(PromotionsAmountGiftQuery model, string oldeventid)
        {
            //實例dao對象
            _ptDao = new PromoTicketDao(connStr);
            _proCateDao = new ProductCategoryDao(connStr);
            _prodCategSetDao = new ProductCategorySetDao(connStr);
            _prodpromoDao = new ProdPromoDao(connStr);

            int i = 0;
            //聲明鏈接數據庫
            MySqlCommand mySqlCmd = new MySqlCommand();
            MySqlConnection mySqlConn = new MySqlConnection(connStr);
            StringBuilder sbExSql = new StringBuilder();
            try
            {
                model.Replace4MySQL();
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Closed)
                {
                    mySqlConn.Open();
                }
                mySqlCmd.Connection = mySqlConn;
                //開啟事物
                mySqlCmd.Transaction = mySqlConn.BeginTransaction();
                mySqlCmd.CommandType = System.Data.CommandType.Text;
                StringBuilder Sql = new StringBuilder();


                mySqlCmd.CommandText = _prodpromoDao.DeleteProdProm(oldeventid);
                sbExSql.Append(mySqlCmd.CommandText);
                mySqlCmd.ExecuteNonQuery();//刪除ProdPromo

                mySqlCmd.CommandText = _proAllDao.DelPromAll(oldeventid);
                sbExSql.Append(mySqlCmd.CommandText);
                mySqlCmd.ExecuteNonQuery();//刪除PromAll


                //Sql.AppendFormat(_prodpromoDao.DeleteProdProm(model.event_id));
                //處理表product_category_set 和 prod_promo
                if (model.quanguan == 1)
                {
                    //根據category_id刪除product_category_set表數據
                    Sql.Clear();
                    Sql.AppendFormat(_prodCategSetDao.DeleteProdCateSet(model.category_id));
                    ////添加product_category_set數據
                    ProductCategorySet pcs = new ProductCategorySet();
                    pcs.Category_Id = model.category_id;
                    pcs.Product_Id = 999999;
                    pcs.Brand_Id = 0;
                    Sql.AppendFormat(_prodCategSetDao.SaveProdCategorySet(pcs));
                    mySqlCmd.CommandText = Sql.ToString();
                    sbExSql.Append(mySqlCmd.CommandText);
                    mySqlCmd.ExecuteNonQuery();//添加全館商品到PromAll
                    Sql.Clear();

                }
                else//非全館
                {
                    //刪除全館商品
                    ProductCategorySet qgSet = new ProductCategorySet();
                    qgSet.Category_Id = model.category_id;
                    qgSet.Product_Id = 999999;//全館商品刪除 id=999999
                    //根據category_id刪除product_category_set表數據
                    mySqlCmd.CommandText = _prodCategSetDao.DelProdCateSetByCPID(qgSet);
                    sbExSql.Append(mySqlCmd.CommandText);
                    mySqlCmd.ExecuteNonQuery();//刪除全館別商品999999

                    if (model.url_by == 1)//專區時 add by shuangshuang0420j 20150309 11:25 區分專區和非專區
                    {
                        //  Sql.Append(_prodpromoDao.DeleteProdProm(oldeventid));//修改前先刪除已有的數據
                        //選擇brand_id 的時候處理prod_promo  和product_category_set
                        if (model.brand_id != 0)//當品牌不為空時講該品牌下的所有商品加入set表
                        {

                            Sql.Append(_prodCategSetDao.DeleteProdCateSet(model.category_id));
                            mySqlCmd.CommandText = Sql.ToString();
                            sbExSql.Append(mySqlCmd.CommandText);
                            mySqlCmd.ExecuteNonQuery();
                            Sql.Clear();
                            QueryVerifyCondition query = new QueryVerifyCondition();
                            query.brand_id = Convert.ToUInt32(model.brand_id);
                            query.site_ids = model.site.ToString();
                            PromotionsMaintainDao _promoMainDao = new PromotionsMaintainDao(connStr);
                            int totalCount = 0;
                            List<QueryandVerifyCustom> qvcList = _promoMainDao.QueryByProSite(query, out totalCount, 0);

                            List<uint> categorysetProduct = new List<uint>();
                            foreach (QueryandVerifyCustom qvcItem in qvcList)
                            {
                                if (categorysetProduct.Contains(qvcItem.product_id))
                                {
                                    continue;
                                }
                                categorysetProduct.Add(qvcItem.product_id);
                                ProductCategorySet pcsModel = new ProductCategorySet();
                                pcsModel.Product_Id = qvcItem.product_id;
                                pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                pcsModel.Category_Id = model.category_id;
                                Sql.Append(_prodCategSetDao.SaveProdCategorySet(pcsModel));
                            }
                            if (!string.IsNullOrEmpty(Sql.ToString()))
                            {
                                mySqlCmd.CommandText = Sql.ToString();
                                sbExSql.Append(mySqlCmd.CommandText);
                                mySqlCmd.ExecuteNonQuery();
                                Sql.Clear();
                            }
                        }
                    }
                    else
                    { //非專區時
                        mySqlCmd.CommandText = _prodCategSetDao.DeleteProdCateSet(model.category_id);
                        sbExSql.Append(mySqlCmd.CommandText);
                        mySqlCmd.ExecuteNonQuery();
                        if (model.product_id != 0)
                        {
                            ProductCategorySet pcsModel = new ProductCategorySet();
                            pcsModel.Product_Id = Convert.ToUInt32(model.product_id);
                            pcsModel.Brand_Id = _prodDao.Query(new Product { Product_Id = pcsModel.Product_Id }).FirstOrDefault().Brand_Id;
                            pcsModel.Category_Id = model.category_id;
                            //Sql.Append(_prodCategSetDao.SaveProdCategorySet(pcsModel));
                            mySqlCmd.CommandText = _prodCategSetDao.SaveProdCategorySet(pcsModel);
                            sbExSql.Append(mySqlCmd.CommandText);
                            mySqlCmd.ExecuteNonQuery();//新增商品關係
                        }
                        else if (model.brand_id != 0)
                        {
                            QueryVerifyCondition query = new QueryVerifyCondition();
                            query.brand_id = Convert.ToUInt32(model.brand_id);
                            query.site_ids = model.site;
                            query.combination = 1;
                            int totalCount = 0;
                            List<QueryandVerifyCustom> qvcList = _promoMainDao.QueryByProSite(query, out totalCount, 0);
                            foreach (QueryandVerifyCustom qvcItem in qvcList)
                            {
                                ProductCategorySet pcsModel = new ProductCategorySet();
                                pcsModel.Product_Id = qvcItem.product_id;
                                pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                pcsModel.Category_Id = model.category_id;
                                // arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                                mySqlCmd.CommandText = _prodCategSetDao.SaveProdCategorySet(pcsModel);
                                sbExSql.Append(mySqlCmd.CommandText);
                                mySqlCmd.ExecuteNonQuery();//新增商品關係
                            }
                        }
                        else if (model.class_id != 0)
                        {
                            List<VendorBrand> brandIDs = _vendorBrandDao.GetClassBrandList(new VendorBrand { }, (uint)model.class_id);
                            foreach (VendorBrand item in brandIDs)
                            {
                                QueryVerifyCondition query = new QueryVerifyCondition();
                                query.brand_id = item.Brand_Id;
                                query.site_ids = model.site;
                                query.combination = 1;
                                int totalCount = 0;
                                List<QueryandVerifyCustom> qvcList = _promoMainDao.QueryByProSite(query, out totalCount, 0);
                                foreach (QueryandVerifyCustom qvcItem in qvcList)
                                {
                                    ProductCategorySet pcsModel = new ProductCategorySet();
                                    pcsModel.Product_Id = qvcItem.product_id;
                                    pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                    pcsModel.Category_Id = model.category_id;
                                    //arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                                    mySqlCmd.CommandText = _prodCategSetDao.SaveProdCategorySet(pcsModel);
                                    sbExSql.Append(mySqlCmd.CommandText);
                                    mySqlCmd.ExecuteNonQuery();//新增商品關係
                                }
                            }
                        }
                    }
                }
                //新增表promo_all數據
                //  Sql.AppendFormat(_proAllDao.DelPromAll(model.event_id));
                Sql.Clear();
                PromoAll pamodel = new PromoAll();
                pamodel.event_id = model.event_id;
                pamodel.product_id = model.product_id;
                pamodel.class_id = model.class_id;
                pamodel.brand_id = model.brand_id;
                pamodel.event_type = model.event_type;
                pamodel.category_id = Convert.ToInt32(model.category_id);
                pamodel.startTime = model.startdate;
                pamodel.end = model.enddate;
                pamodel.status = model.status;
                pamodel.kuser = model.kuser;
                pamodel.kdate = model.created;
                pamodel.muser = model.muser;
                pamodel.mdate = model.modified;
                Sql.AppendFormat(_proAllDao.SavePromAll(pamodel));
                //更新product_category表數據
                ProductCategory pcmodel = _proCateDao.GetModelById(Convert.ToUInt32(model.category_id));
                pcmodel.category_id = Convert.ToUInt32(model.category_id);
                pcmodel.banner_image = model.banner_image;
                pcmodel.category_link_url = model.category_link_url;
                pcmodel.category_display = Convert.ToUInt32(model.status);
                Sql.AppendFormat(_proCateDao.UpdateProdCate(pcmodel));

                //判斷送禮類型是否是機會,若是的話 修改編輯表promo_ticket
                if (model.gift_type == 2)
                { //新增數據到promo_ticket                   
                    if (model.ticket_id == 0)
                    {
                        PromoTicket pt = new PromoTicket();
                        pt.ticket_name = model.name;//機會name
                        pt.event_id = model.event_id;
                        pt.event_type = model.event_type;
                        pt.active_now = model.active_now;
                        pt.use_start = model.use_start;
                        pt.use_end = model.use_end;
                        pt.kuser = model.kuser;
                        pt.kdate = model.created;
                        pt.muser = model.muser;
                        pt.mdate = model.modified;
                        pt.valid_interval = model.valid_interval;
                        pt.status = model.status;
                        model.ticket_id = _ptDao.Save(pt);
                        model.ticket_name = pt.ticket_name;
                    }
                    //更新表數據
                    else
                    {
                        PromoTicket pt = _ptDao.Query(model.ticket_id);

                        pt.kuser = model.kuser;
                        pt.kdate = model.created;
                        pt.muser = model.muser;
                        pt.mdate = model.modified;

                        pt.ticket_name = model.ticket_name;//機會name
                        pt.event_id = model.event_id;
                        pt.event_type = model.event_type;
                        pt.active_now = model.active_now;
                        pt.use_start = model.use_start;
                        pt.use_end = model.use_end;
                        pt.valid_interval = model.valid_interval;
                        pt.status = model.status;

                        Sql.AppendFormat(_ptDao.UpdateSql(pt));
                    }
                }
                else if (model.ticket_id != 0)
                {
                    Sql.AppendFormat(_ptDao.DeleteSql(model.ticket_id));
                }


                if (model.gift_type == 3 || model.gift_type == 4)//當贈送購物金或抵用券時產生gift_id
                {
                    PromotionsAmountGiftCustom promGiftCustom = new PromotionsAmountGiftCustom();

                    promGiftCustom.product_id = 5669;
                    promGiftCustom.spec_type = 1;
                    promGiftCustom.spec_name = model.name;

                    promGiftCustom.Item_Alarm = 5;
                    promGiftCustom.Item_Stock = 9999;



                    mySqlCmd.CommandText = SaveProSpec(promGiftCustom);
                    uint specId = Convert.ToUInt32(mySqlCmd.ExecuteScalar());

                    promGiftCustom.Spec_Id_1 = specId;

                    mySqlCmd.CommandText = SaveProItem(promGiftCustom);

                    model.gift_id = Convert.ToInt32(mySqlCmd.ExecuteScalar());


                }

                //更新主表數據
                Sql.AppendFormat(UpdatePromoGift(model));
                mySqlCmd.CommandText = Sql.ToString();
                sbExSql.Append(mySqlCmd.CommandText);
                i += mySqlCmd.ExecuteNonQuery();
                mySqlCmd.Transaction.Commit();
            }
            catch (Exception ex)
            {//事物回滾
                mySqlCmd.Transaction.Rollback();
                throw new Exception("PromotionsAmountGiftDao-->Update-->" + ex.Message + sbExSql.ToString(), ex);
            }
            finally
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
                {
                    mySqlConn.Close();
                }
            }
            return i;
        }
        public HttpResponseBase DeletLessThen()
        {
            uint producateid = Convert.ToUInt32(Request.Params["producateid"]);
            //uint key_id = 0;
            string product_name = string.Empty;
            int types = 0;
            if (!string.IsNullOrEmpty(Request.Params["types"]))//變動3
            {
                types = int.Parse(Request.Params["types"]);
            }
            string site = "0";//站台改成多個站台的site_id字符串 edit by shuangshuang0420j 20140925 13:40
            if (!string.IsNullOrEmpty(Request.Params["websiteid"]))
            {
                site = Request.Params["websiteid"];
            }

            ProductCategorySetMgr _categorySetMgr = new ProductCategorySetMgr(mySqlConnectionString);
            List<ProductCategorySet> categoryList = _categorySetMgr.QueryMsg(new ProductCategorySetQuery { Category_Id = producateid });

            ProductMgr _prodMgr = new ProductMgr(mySqlConnectionString);
            int totalCount = 0;

            PromotionsMaintainDao pmDao = new PromotionsMaintainDao(mySqlConnectionString);
            string pricemaster_in = "";
            foreach (ProductCategorySet pcs in categoryList)
            {
                QueryVerifyCondition query = new QueryVerifyCondition();
                query.name_number = pcs.Product_Id.ToString();
                query.site_ids = site;
                if (!string.IsNullOrEmpty(product_name))
                {
                    query.product_name = product_name;
                }
                List<QueryandVerifyCustom> tempPros = pmDao.QueryByProSite(query, out totalCount, 0);
                if (1 <= tempPros.Count)
                {
                    pricemaster_in += tempPros[0].price_master_id + ",";
                }

            }
            pricemaster_in = pricemaster_in.TrimEnd(',');
            string jsonStr = String.Empty;
            try
            {
                PromoAdditionalPriceQuery model = new PromoAdditionalPriceQuery();

                _promoadditionproceMgr = new PromoAdditionalPriceMgr(mySqlConnectionString);
                model.id = Convert.ToInt32(Request.Params["rowid"].ToString());
                model.fixed_price = Convert.ToInt32(Request.Params["fixed_price"].ToString());
                model.price_master_in = pricemaster_in;
                if (string.IsNullOrEmpty(pricemaster_in))
                {
                    jsonStr = "{success:true,\"delcount\":\"" + 0 + "\" }";
                }
                else
                {
                    int result = _promoadditionproceMgr.DeletLessThen(model, types);
                    if (result > 0)
                    {
                        jsonStr = "{success:true,\"delcount\":\"" + 1 + "\" }";
                    }
                    else if (result == 0)
                    {
                        jsonStr = "{success:true,\"delcount\":\"" + 0 + "\" }";
                    }
                    else
                    {
                        jsonStr = "{success:false}";
                    }
                }

            }
            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);
                jsonStr = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }