Example #1
0
        /// <summary>
        /// 調用儲存過程為price_master 裱中的name添加前後綴
        /// </summary>
        /// <param name="days">過期天數(超多少天的前後綴自動刪除)</param>
        /// <returns>受影響的行數</returns>
        public int ResetExtendName(Caller callId, uint product_id = 0)
        {
            try
            {
                IPriceMasterImplMgr pmMgr = new PriceMasterMgr(connectionStr);
                MySqlDao _mySqlDao = new MySqlDao(connectionStr);
                ArrayList sqlList = new ArrayList();
                string msg = string.Empty;
                List<ProdNameExtendCustom> list = new List<ProdNameExtendCustom>();
                if (product_id != 0)
                {
                    list = peDao.GetPastProductById(product_id);
                }
                else
                {
                    list = peDao.GetPastProduct();
                }
                foreach (var pM in list)
                {
                    //pM.Product_Name = pM.Product_Name.Replace(PriceMaster.L_HKH + pM.Product_Prefix + PriceMaster.R_HKH, "")//替換掉priceMaster中product_name的前綴
                    //.Replace(PriceMaster.L_HKH + pM.Product_Suffix + PriceMaster.R_HKH, "");//替換掉priceMaster中product_name的後綴
                    bool tempFlag = true;
                    int index = 0;///定義index防止錯誤導致下面的while無限循環
                    while(tempFlag)///循環刪除前後綴
                    {
                        index ++;
                        pM.Product_Name = ClearPreSuName(pM.Product_Name, PriceMaster.L_HKH.ToString(), PriceMaster.R_HKH.ToString());
                        if (pM.Product_Name.IndexOf(PriceMaster.L_HKH.ToString()) == -1 && pM.Product_Name.IndexOf(PriceMaster.R_HKH.ToString()) == -1||index>10)
                        {
                            tempFlag = false;
                        }
                    }
                    PriceMaster p = new PriceMaster();
                    p.price_master_id = pM.Price_Master_Id;
                    p.product_name = pM.Product_Name;
                    sqlList.Add(pmMgr.UpdateName(p)); //將去掉前後綴的名稱update到price_master表
                    pM.Flag = 3;//過期
                    pM.Event_End = pM.Event_End;
                    pM.Event_Start = pM.Event_Start;
                }

                if (_mySqlDao.ExcuteSqls(sqlList))
                {
                    peDao.Update(list.Select(p => (ProdNameExtend)p).ToList());
                }
                if (msg == "")
                {
                    int days = 30;//過期多少天刪除
                    return peDao.DeleteExtendName(days);
                }
                else
                {
                    return -1;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("ProdNameExtendMgr-->ResetExtendName-->" + ex.Message, ex);
            }
        }
        public ActionResult QueryProdname(ProdNameExtendCustom pron, bool isOverdue)
        {
            string ids = Request["Ids"];
            try
            {
                int state = 0;//判斷是否需要重新查詢的依據
                _prodnameExtendMgr = new ProdNameExtendMgr(connectionString);
                IPriceMasterImplMgr pmMgr = new PriceMasterMgr(connectionString);
                MySqlDao _mySqlDao = new MySqlDao(connectionString);
                ArrayList sqlList = new ArrayList();
                List<ProdNameExtendCustom> list = _prodnameExtendMgr.Query(pron, ids);//根據條件查詢商品信息
                //判斷過期商品 和 審核商品 中是否存在錯誤數據  edit by zhuoqin0830w  2015/05/07
                List<ProdNameExtendCustom> listDelete = list.FindAll(m => m.Flag == 3 || m.Flag == 1); //查詢過程中,為防止未去掉前後綴,卻到期的商品,進行一次遍歷,去掉前後綴 edit by wwei 0216w 2014/12/22
                //獲取 前一天 時間的時間戳  edit by zhuoqin0830w  2015/05/07
                long time = CommonFunction.GetPHPTime(Convert.ToString(DateTime.Now)) - 86400;
                foreach (ProdNameExtendCustom pec in listDelete)
                {
                    pec.Product_Name = pec.Product_Name.Replace(PriceMaster.L_HKH + pec.Product_Prefix + PriceMaster.R_HKH, "").Replace(PriceMaster.L_HKH + pec.Product_Suffix + PriceMaster.R_HKH, "");
                    PriceMaster p = new PriceMaster();
                    p.price_master_id = pec.Price_Master_Id;
                    p.product_name = pec.Product_Name;
                    switch (pec.Flag)
                    {
                        case 1://審核商品
                            //判斷結束時間 是否 小於 前一天 時間的時間戳  edit by zhuoqin0830w  2015/05/07
                            if (pec.Event_End <= time)
                            {
                                sqlList.Add(pmMgr.UpdateName(p));
                                state = 1;//如果審核商品中結束時間小於前一天的時間,則賦值為1;
                                _mySqlDao.ExcuteSqls(sqlList);
                                break;
                            }
                            break;
                        case 3://過期商品
                            //如果在過期的商品名稱中能找到前綴後綴~則調用刪除前後綴的方法
                            if ((pec.Product_Name.Contains(PriceMaster.L_HKH + pec.Product_Prefix + PriceMaster.R_HKH) || pec.Product_Name.Contains(PriceMaster.L_HKH + pec.Product_Suffix + PriceMaster.R_HKH)))
                            {
                                _prodnameExtendMgr.ResetExtendName(new Caller());
                                state = 1;//如果有過期商品包含前後綴,則賦值為1;
                                break;
                            }
                            break;
                    }
                }
                if (state == 1)
                {
                    list = _prodnameExtendMgr.Query(pron, ids);//替換掉之前包含前後綴的商品名稱
                }

                for (int i = 0; i < list.Count; i++)
                {
                    list[i].Key_Id = i;
                }//add by wwei0216w 2014/12/30 為key_id賦值

                if (isOverdue)//查詢過期
                {
                    list.RemoveAll(p => p.Flag != 3);
                }
                else //查詢未過期
                {
                    list.RemoveAll(p => p.Flag == 3);
                }
                return Json(new { item = list });
            }
            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);
            }
            return Json(new List<ProdNameExtendCustom>());
        }