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;
        }
Ejemplo n.º 2
0
        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;
        }