public static void AutoHotelPlaning()
        {
            DateTime dtBegin = new DateTime();
            dtBegin = System.DateTime.Now;

            AutoHotelPlanEntity _autohotelplanEntity = new AutoHotelPlanEntity();
            CommonEntity _commonEntity = new CommonEntity();
            _autohotelplanEntity.LogMessages = new HotelVp.Common.Logger.LogMessage();
            _autohotelplanEntity.LogMessages.Userid = "JOB System";
            _autohotelplanEntity.LogMessages.Username = "******";
            _autohotelplanEntity.AutoHotelPlanDBEntity = new List<AutoHotelPlanDBEntity>();
            AutoHotelPlanDBEntity appcontentDBEntity = new AutoHotelPlanDBEntity();
            _autohotelplanEntity.AutoHotelPlanDBEntity.Add(appcontentDBEntity);
            Console.WriteLine("酒店销售计划JOB自动运行开始");
            int iCount = AutoSelect(_autohotelplanEntity);
            Console.WriteLine("酒店销售计划JOB自动运行 执行记录数:" + iCount.ToString());
            //Console.WriteLine("发送邮件开始");
            //bool bResult = SendMailExpress(dsResult);
            //string strResult = "失败";
            //if (bResult)
            //{
            //    strResult = "成功";
            //}
            //else
            //{
            //    Thread.Sleep(5000);
            //}

            //Console.WriteLine("发送邮件结束 结果:" + strResult);

            DateTime dtEnd = new DateTime();
            dtEnd = System.DateTime.Now;

            Console.WriteLine(dtEnd - dtBegin);
        }
        private static string ApplySalesRoomService(DataRow drRow, string Type)
        {
            AutoHotelPlanEntity _autohotelplanEntity = new AutoHotelPlanEntity();
            _autohotelplanEntity.LogMessages = new HotelVp.Common.Logger.LogMessage();
            _autohotelplanEntity.LogMessages.Userid = "JOB System";
            _autohotelplanEntity.LogMessages.Username = drRow["Create_User"].ToString().Trim();
            _autohotelplanEntity.AutoHotelPlanDBEntity = new List<AutoHotelPlanDBEntity>();
            AutoHotelPlanDBEntity appcontentDBEntity = new AutoHotelPlanDBEntity();

            appcontentDBEntity.HotelID = drRow["HOTEL_ID"].ToString().Trim();
            appcontentDBEntity.PriceCode = drRow["RATE_CODE"].ToString().Trim();
            appcontentDBEntity.RoomCode = drRow["ROOM_TYPE_CODE"].ToString().Trim();
            appcontentDBEntity.RoomName = drRow["ROOM_TYPE_NAME"].ToString().Trim();
            appcontentDBEntity.StartDTime = drRow["StartDtime"].ToString().Trim();
            appcontentDBEntity.EndDTime = drRow["EndDtime"].ToString().Trim();
            appcontentDBEntity.EffHour = drRow["EFFECT_HOUR"].ToString().Trim();
            appcontentDBEntity.WeekList = drRow["Week_List"].ToString().Trim();
            appcontentDBEntity.Note1 = drRow["GUAID"].ToString().Trim();
            appcontentDBEntity.Note2 = drRow["CXLID"].ToString().Trim();
            appcontentDBEntity.OnePrice = drRow["ONE_PRICE"].ToString().Trim();
            appcontentDBEntity.TwoPrice = drRow["TWO_PRICE"].ToString().Trim();
            appcontentDBEntity.ThreePrice = drRow["THREE_PRICE"].ToString().Trim();
            appcontentDBEntity.FourPrice = drRow["FOUR_PRICE"].ToString().Trim();
            appcontentDBEntity.BedPrice = drRow["ATTN_PRICE"].ToString().Trim();
            appcontentDBEntity.BreakfastNum = drRow["BREAKFAST_NUM"].ToString().Trim();
            appcontentDBEntity.BreakPrice = drRow["EACH_BREAKFAST_PRICE"].ToString().Trim();
            appcontentDBEntity.IsNetwork = drRow["IS_NETWORK"].ToString().Trim();
            appcontentDBEntity.Offsetval = drRow["OFFSETVAL"].ToString().Trim();
            appcontentDBEntity.Offsetunit = drRow["OFFSETUNIT"].ToString().Trim();
            appcontentDBEntity.RoomStatus = drRow["STATUS"].ToString().Trim();
            appcontentDBEntity.RoomCount = drRow["ROOM_NUM"].ToString().Trim();
            appcontentDBEntity.IsReserve = drRow["IS_RESERVE"].ToString().Trim();
            appcontentDBEntity.UpdateUser = drRow["Create_User"].ToString().Trim();
            appcontentDBEntity.TypeID = Type;

            _autohotelplanEntity.AutoHotelPlanDBEntity.Add(appcontentDBEntity);
            _autohotelplanEntity = AutoHotelPlanSA.ApplySalesPlan(_autohotelplanEntity);

            return _autohotelplanEntity.ErrorMSG;
        }
        private static int AutoSelect(AutoHotelPlanEntity autogotelplanEntity)
        {
            int iMaxLenth = String.IsNullOrEmpty(ConfigurationManager.AppSettings["MaxLength"]) ? 200 : int.Parse(ConfigurationManager.AppSettings["MaxLength"].ToString());
            DataSet dsResult = new DataSet();
            dsResult = AutoHotelPlanDA.AutoListSelect(autogotelplanEntity);
            int iCount = 0;
            string PlanID=string.Empty;
            string Status=string.Empty;
            string Action=string.Empty;
            string Result=string.Empty;
            string Username = string.Empty;
            //string strToDay = DateTime.Now.ToShortDateString();
            //int strToWeek = (int)DateTime.Now.DayOfWeek + 1;
            //string strDayTemp = string.Empty;
            string strWeekTemp = string.Empty;
            string strTypeNm = string.Empty;
            string strTypeTime = string.Empty;
            string ChkResult = string.Empty;

            ArrayList alHotelList = new ArrayList();
            Hashtable htErrList = new Hashtable();
            Hashtable htErr = new Hashtable();

            foreach (DataRow drRow in dsResult.Tables[0].Rows)
            {
                if (!"0".Equals(drRow["Type"].ToString().Trim()))
                {
                    ChkResult = CheckApplySalesRoomService(drRow, drRow["Type"].ToString().Trim());
                    if (!String.IsNullOrEmpty(ChkResult))
                    {
                        htErrList.Add(drRow["HPID"].ToString().Trim(), ChkResult);
                    }
                    else
                    {
                        alHotelList.Add(drRow);
                    }
                }
                else
                {
                    alHotelList.Add(drRow);
                }

                iCount = iCount + 1;
                if (iCount == iMaxLenth)
                {
                    htErr = ApplySalesRoomServiceList(alHotelList);
                    foreach (System.Collections.DictionaryEntry item in htErr)
                    {
                        if (!htErrList.ContainsKey(item.Key.ToString()))
                        {
                            htErrList.Add(item.Key.ToString(), item.Value.ToString());
                        }
                    }
                    iCount = 0;
                }
            }

            if (iCount > 0)
            {
                htErr = ApplySalesRoomServiceList(alHotelList);
                foreach (System.Collections.DictionaryEntry item in htErr)
                {
                    if (!htErrList.ContainsKey(item.Key.ToString()))
                    {
                        htErrList.Add(item.Key.ToString(), item.Value.ToString());
                    }
                }
            }

            foreach (DataRow drRow in dsResult.Tables[0].Rows)
            {
                if ("0".Equals(drRow["Type"].ToString().Trim()))
                {
                    strTypeNm = "立即保存";
                    strTypeTime = drRow["Plan_DTime"].ToString().Trim();
                    PlanID = drRow["HPID"].ToString().Trim();
                    Status = "2";
                    Action = "1";
                    //Result = ApplySalesRoomService(drRow, drRow["Type"].ToString().Trim());
                    Result = htErrList[drRow["HPID"].ToString().Trim()].ToString();
                    Username = drRow["Create_User"].ToString().Trim();
                    AutoHotelPlanDA.UpdateSalesPlanEventStatus(PlanID, Status, Action, Result, Username);
                    AutoHotelPlanDA.UpdateSalesPlanEventJobStatus(drRow["JID"].ToString().Trim(), Action, Result, Username);
                    iCount = iCount + 1;
                }
                else if ("1".Equals(drRow["Type"].ToString().Trim()))
                {
                    strTypeNm = "定时保存";
                    strTypeTime = drRow["Plan_DTime"].ToString().Trim();
                    PlanID = drRow["HPID"].ToString().Trim();
                    Status = "2";
                    Action = "1";
                    //Result = ApplySalesRoomService(drRow, drRow["Type"].ToString().Trim());
                    Result = htErrList[drRow["HPID"].ToString().Trim()].ToString();
                    Username = drRow["Create_User"].ToString().Trim();
                    AutoHotelPlanDA.UpdateSalesPlanEventStatus(PlanID, Status, Action, Result, Username);
                    AutoHotelPlanDA.UpdateSalesPlanEventJobStatus(drRow["JID"].ToString().Trim(), Action, Result, Username);
                    iCount = iCount + 1;
                }
                else if ("2".Equals(drRow["Type"].ToString().Trim()))
                {
                    strTypeNm = "每日自动更新";
                    strTypeTime = drRow["PlanTime"].ToString().Trim();
                    //strDayTemp = drRow["EndDtime"].ToString().Trim();
                    strWeekTemp = drRow["Week_List"].ToString().Trim();

                    Status = (DateTime.Parse(drRow["JPDTime"].ToString().Trim()) == DateTime.Parse(drRow["PlanPlanEnd"].ToString().Trim() + " " + drRow["PlanTime"].ToString().Trim())) ? "2" : "1";
                    PlanID = drRow["HPID"].ToString().Trim();

                    //Console.WriteLine("Action:" + drRow["Action"].ToString().Trim());
                    //Console.WriteLine("HPID:" + drRow["HPID"].ToString().Trim());
                    //Console.WriteLine(htErrList[drRow["HPID"].ToString().Trim()].ToString());

                    Action = ChkNumerVal(drRow["Action"].ToString().Trim()).ToString();
                    //Result = ApplySalesRoomService(drRow, drRow["Type"].ToString().Trim());
                    Result = htErrList[drRow["HPID"].ToString().Trim()].ToString();
                    Username = drRow["Create_User"].ToString().Trim();
                    AutoHotelPlanDA.UpdateSalesPlanEventStatus(PlanID, Status, Action, Result, Username);
                    AutoHotelPlanDA.UpdateSalesPlanEventJobStatus(drRow["JID"].ToString().Trim(), "1", Result, Username);
                    iCount = iCount + 1;
                }

                CommonEntity _commonEntity = new CommonEntity();
                _commonEntity.LogMessages = autogotelplanEntity.LogMessages;
                _commonEntity.CommonDBEntity = new List<CommonDBEntity>();
                CommonDBEntity commonDBEntity = new CommonDBEntity();

                commonDBEntity.Event_Type = "酒店销售计划-JOB";
                commonDBEntity.Event_ID = drRow["HPID"].ToString().Trim();
                string conTent = "销售计划 运行一次 - 计划ID:{0} 更新方式:{1} 定时执行时间:{2} 定时开始日期:{3} 定时结束日期:{4} 星期详情:{5} 修改时间:{6} 修改人:{7}";
                conTent = string.Format(conTent, drRow["HPID"].ToString().Trim(), strTypeNm, strTypeTime, drRow["StartDtime"].ToString().Trim(), drRow["EndDtime"].ToString().Trim(), strWeekTemp, drRow["Update_Time"].ToString().Trim(), drRow["Update_User"].ToString().Trim());
                commonDBEntity.Event_Content = conTent;
                commonDBEntity.Event_Result = Result;
                _commonEntity.CommonDBEntity.Add(commonDBEntity);
                CommonBP.InsertEventHistory(_commonEntity);
            }
            return dsResult.Tables[0].Rows.Count;
        }
        private static Hashtable ApplySalesRoomServiceList(ArrayList alHotelList)
        {
            AutoHotelPlanEntity _autohotelplanEntity = new AutoHotelPlanEntity();
            _autohotelplanEntity.LogMessages = new HotelVp.Common.Logger.LogMessage();
            _autohotelplanEntity.LogMessages.Userid = "JOB System";
            _autohotelplanEntity.LogMessages.Username = "******";
            _autohotelplanEntity.AutoHotelPlanDBEntity = new List<AutoHotelPlanDBEntity>();

            for (int i = 0; i < alHotelList.Count; i++)
            {
                DataRow drRow = (DataRow)alHotelList[i];
                AutoHotelPlanDBEntity appcontentDBEntity = new AutoHotelPlanDBEntity();
                appcontentDBEntity.HotelID = drRow["HOTEL_ID"].ToString().Trim();
                appcontentDBEntity.PriceCode = drRow["RATE_CODE"].ToString().Trim();
                appcontentDBEntity.RoomCode = drRow["ROOM_TYPE_CODE"].ToString().Trim();
                appcontentDBEntity.RoomName = drRow["ROOM_TYPE_NAME"].ToString().Trim();
                appcontentDBEntity.StartDTime = drRow["StartDtime"].ToString().Trim();
                appcontentDBEntity.EndDTime = drRow["EndDtime"].ToString().Trim();
                appcontentDBEntity.EffHour = drRow["EFFECT_HOUR"].ToString().Trim();
                appcontentDBEntity.WeekList = drRow["Week_List"].ToString().Trim();
                appcontentDBEntity.Note1 = drRow["GUAID"].ToString().Trim();
                appcontentDBEntity.Note2 = drRow["CXLID"].ToString().Trim();
                appcontentDBEntity.OnePrice = drRow["ONE_PRICE"].ToString().Trim();
                appcontentDBEntity.TwoPrice = drRow["TWO_PRICE"].ToString().Trim();
                appcontentDBEntity.ThreePrice = drRow["THREE_PRICE"].ToString().Trim();
                appcontentDBEntity.FourPrice = drRow["FOUR_PRICE"].ToString().Trim();
                appcontentDBEntity.BedPrice = drRow["ATTN_PRICE"].ToString().Trim();
                appcontentDBEntity.NetPrice = drRow["NET_PRICE"].ToString().Trim();
                appcontentDBEntity.BreakfastNum = drRow["BREAKFAST_NUM"].ToString().Trim();
                appcontentDBEntity.BreakPrice = drRow["EACH_BREAKFAST_PRICE"].ToString().Trim();
                appcontentDBEntity.IsNetwork = drRow["IS_NETWORK"].ToString().Trim();
                appcontentDBEntity.Offsetval = drRow["OFFSETVAL"].ToString().Trim();
                appcontentDBEntity.Offsetunit = drRow["OFFSETUNIT"].ToString().Trim();
                appcontentDBEntity.RoomStatus = drRow["STATUS"].ToString().Trim();
                appcontentDBEntity.RoomCount = drRow["ROOM_NUM"].ToString().Trim();
                appcontentDBEntity.IsReserve = drRow["IS_RESERVE"].ToString().Trim();
                appcontentDBEntity.UpdateUser = drRow["Create_User"].ToString().Trim();
                appcontentDBEntity.TypeID = drRow["Type"].ToString().Trim();
                appcontentDBEntity.HPID = drRow["HPID"].ToString().Trim();
                appcontentDBEntity.Supplier = drRow["SOURCE"].ToString().Trim();
                _autohotelplanEntity.AutoHotelPlanDBEntity.Add(appcontentDBEntity);
            }

            Hashtable htResult = new Hashtable();
            htResult = AutoHotelPlanSA.ApplySalesPlanList(_autohotelplanEntity);
            return htResult;
        }
        private static int AutoSelect(AutoHotelPlanEntity autogotelplanEntity)
        {
            DataSet dsResult = new DataSet();
            dsResult = AutoHotelPlanDA.AutoListSelect(autogotelplanEntity);
            int iCount = 0;
            string PlanID=string.Empty;
            string Status=string.Empty;
            string Action=string.Empty;
            string Result=string.Empty;
            string Username = string.Empty;
            //string strToDay = DateTime.Now.ToShortDateString();
            //int strToWeek = (int)DateTime.Now.DayOfWeek + 1;
            //string strDayTemp = string.Empty;
            string strWeekTemp = string.Empty;
            string strTypeNm = string.Empty;
            string strTypeTime = string.Empty;
            foreach (DataRow drRow in dsResult.Tables[0].Rows)
            {
                if ("0".Equals(drRow["Type"].ToString().Trim()))
                {
                    strTypeNm = "立即保存";
                    strTypeTime = drRow["Plan_DTime"].ToString().Trim();
                    PlanID = drRow["HPID"].ToString().Trim();
                    Status = "2";
                    Action = "1";
                    Result = ApplySalesRoomService(drRow, drRow["Type"].ToString().Trim());
                    Username = drRow["Create_User"].ToString().Trim();
                    AutoHotelPlanDA.UpdateSalesPlanEventStatus(PlanID, Status, Action, Result, Username);
                    AutoHotelPlanDA.UpdateSalesPlanEventJobStatus(drRow["JID"].ToString().Trim(), Action, Result, Username);
                    iCount = iCount + 1;
                }
                else if ("1".Equals(drRow["Type"].ToString().Trim()))
                {
                    strTypeNm = "定时保存";
                    strTypeTime = drRow["Plan_DTime"].ToString().Trim();
                    PlanID = drRow["HPID"].ToString().Trim();
                    Status = "2";
                    Action = "1";
                    Result = ApplySalesRoomService(drRow, drRow["Type"].ToString().Trim());
                    Username = drRow["Create_User"].ToString().Trim();
                    AutoHotelPlanDA.UpdateSalesPlanEventStatus(PlanID, Status, Action, Result, Username);
                    AutoHotelPlanDA.UpdateSalesPlanEventJobStatus(drRow["JID"].ToString().Trim(), Action, Result, Username);
                    iCount = iCount + 1;
                }
                else if ("2".Equals(drRow["Type"].ToString().Trim()))
                {
                    strTypeNm = "每日自动更新";
                    strTypeTime = drRow["PlanTime"].ToString().Trim();
                    //strDayTemp = drRow["EndDtime"].ToString().Trim();
                    strWeekTemp = drRow["Week_List"].ToString().Trim();

                    Status = (DateTime.Parse(drRow["JPDTime"].ToString().Trim()) == DateTime.Parse(drRow["PlanPlanEnd"].ToString().Trim() + " " + drRow["PlanTime"].ToString().Trim())) ? "2" : "1";
                    PlanID = drRow["HPID"].ToString().Trim();
                    Action = ChkNumerVal(drRow["Action"].ToString().Trim()).ToString();
                    Result = ApplySalesRoomService(drRow, drRow["Type"].ToString().Trim());
                    Username = drRow["Create_User"].ToString().Trim();
                    AutoHotelPlanDA.UpdateSalesPlanEventStatus(PlanID, Status, Action, Result, Username);
                    AutoHotelPlanDA.UpdateSalesPlanEventJobStatus(drRow["JID"].ToString().Trim(), "1", Result, Username);
                    iCount = iCount + 1;
                }

                CommonEntity _commonEntity = new CommonEntity();
                _commonEntity.LogMessages = autogotelplanEntity.LogMessages;
                _commonEntity.CommonDBEntity = new List<CommonDBEntity>();
                CommonDBEntity commonDBEntity = new CommonDBEntity();

                commonDBEntity.Event_Type = "酒店销售计划-JOB";
                commonDBEntity.Event_ID = drRow["HPID"].ToString().Trim();
                string conTent = "销售计划 运行一次 - 计划ID:{0} 更新方式:{1} 定时执行时间:{2} 定时开始日期:{3} 定时结束日期:{4} 星期详情:{5} 修改时间:{6} 修改人:{7}";
                conTent = string.Format(conTent, drRow["HPID"].ToString().Trim(), strTypeNm, strTypeTime, drRow["StartDtime"].ToString().Trim(), drRow["EndDtime"].ToString().Trim(), strWeekTemp, drRow["Update_Time"].ToString().Trim(), drRow["Update_User"].ToString().Trim());
                commonDBEntity.Event_Content = conTent;
                commonDBEntity.Event_Result = Result;
                _commonEntity.CommonDBEntity.Add(commonDBEntity);
                CommonBP.InsertEventHistory(_commonEntity);
            }
            return iCount;
        }
 public static DataSet AutoListSelect(AutoHotelPlanEntity autohotelplanEntity)
 {
     AutoHotelPlanDBEntity dbParm = (autohotelplanEntity.AutoHotelPlanDBEntity.Count > 0) ? autohotelplanEntity.AutoHotelPlanDBEntity[0] : new AutoHotelPlanDBEntity();
     DataCommand cmd = DataCommandManager.GetDataCommand("AutoListSelect");
     return cmd.ExecuteDataSet(); ;
 }