/// <summary>
        /// 发送奖期查询后续业务逻辑
        /// </summary>
        /// <param name="returnMsg"></param>
        private void OnSendSuccess(string returnMsg)
        {
            var xdoc = XDocument.Parse(returnMsg);
            var q    = xdoc.Descendants("issue").FirstOrDefault();

            if (q == null)
            {
                throw new Common.ElectronicException("XML数据分析错误,未找到节点【issue】");
            }
            var attrs = q.Attributes().ToDictionary(t => t.Name.LocalName);

            #region db logic
            var t_Isuses = new SLS.Dal.Tables.T_Isuses();

            string lotoid    = null;
            string issue     = null;
            string starttime = null;
            string endtime   = null;
            string bonuscode = null;
            string status    = null;
            int    LotteryID = 0;
            string IssueName = null;
            string WinNumber = null;

            var sunlotto = new SLS.Common.EtSunLotto();

            try{
                lotoid    = attrs[SunlotXmlDefin.LotoId].Value;
                issue     = attrs[SunlotXmlDefin.Issue].Value;
                starttime = attrs[SunlotXmlDefin.StartTime].Value;
                endtime   = attrs[SunlotXmlDefin.EndTime].Value;
                status    = attrs[SunlotXmlDefin.Status].Value;
                LotteryID = sunlotto.GetSystemLotteryID(lotoid);
                IssueName = sunlotto.ConvertIntoSystemIssue(lotoid, issue);
            }
            catch (Exception e) {
                base.WriteLog("奖期查询/通知属性分析错误 : " + e.Message);
            }


            //如果包含开奖结果
            if (attrs.ContainsKey(SunlotXmlDefin.BonusCode))
            {
                bonuscode = attrs[SunlotXmlDefin.BonusCode].Value;
                WinNumber = sunlotto.ConverToSystemLottoNum(lotoid, bonuscode);
            }
            if ((LotteryID < 1) || (String.IsNullOrEmpty(issue)))
            {
                base.WriteLog(lotoid + " : 期号 " + issue + " 错误");
            }

            long IssueID = 0;
            //新增奖期
            if (t_Isuses.GetCount("LotteryID = " + LotteryID.ToString() + " and [Name] = '" + Shove._Web.Utility.FilteSqlInfusion(IssueName) + "'") < 1)
            {
                DateTime _StartTime = DateTime.Now;
                DateTime _EndTime   = DateTime.Now;

                try {
                    _StartTime = DateTime.ParseExact(starttime, "yyyyMMddhhmmss", System.Globalization.CultureInfo.CurrentCulture);
                    _EndTime   = DateTime.ParseExact(endtime, "yyyyMMddhhmmss", System.Globalization.CultureInfo.CurrentCulture);
                }
                catch {
                    base.WriteLog(LotteryID.ToString() + " : 期号 " + IssueID.ToString() + " 时间错误");
                }
                string ReturnDescription = "";
                //新增奖期
                if (SLS.Dal.Procedures.P_IsuseAdd(ConnectString, LotteryID, IssueName, _StartTime, _EndTime, "", ref IssueID, ref ReturnDescription) < 0)
                {
                    base.WriteLog(LotteryID.ToString() + " : 期号 " + IssueID.ToString() + " 新增错误");
                }

                if (IssueID < 0)
                {
                    base.WriteLog(LotteryID.ToString() + " : 期号 " + IssueID.ToString() + " 错误");
                }
            }

            var dtIssue = t_Isuses.Open(ConnectString
                                        , "ID, State, WinLotteryNumber"
                                        , "LotteryID = " + LotteryID.ToString() + " and [Name] = '" + Shove._Web.Utility.FilteSqlInfusion(IssueName) + "' and LotteryID  in (select id from T_Lotteries where PrintOutType = 301)"
                                        , "");

            if ((dtIssue == null) || (dtIssue.Rows.Count < 1))
            {
                //todo
            }

            if (status == IssueState.Drawing)
            {
                int    ReturnValue      = -1;
                string ReturnDescprtion = "";

                int Result = SLS.Dal.Procedures.P_ElectronTicketAgentSchemeQuash(ConnectString, Shove._Convert.StrToLong(dtIssue.Rows[0]["ID"].ToString(), 0), ref ReturnValue, ref ReturnDescprtion);
                if (Result < 0)
                {
                    //new Log("ElectronTicket\\SunLotto").Write("电子票方案撤单错误_P_ElectronTicketAgentSchemeQuash : " + IssueID.ToString());
                    base.WriteLog("电子票方案撤单错误_P_ElectronTicketAgentSchemeQuash : " + IssueID.ToString());
                }
            }
            else if (status == IssueState.Open)
            {
            }

            bool isHasUpdate = false;

            if (dtIssue.Rows[0]["State"].ToString() != status)
            {
                isHasUpdate = true;
            }

            if (isHasUpdate)
            {
                int    ReturnValue      = -1;
                string ReturnDescprtion = "";

                int Result = SLS.Dal.Procedures.P_IsuseUpdate(ConnectString
                                                              , LotteryID
                                                              , Shove._Web.Utility.FilteSqlInfusion(IssueName)
                                                              , Shove._Convert.StrToShort(status, 1)
                                                              , Shove._Convert.StrToDateTime(starttime, DateTime.Now.ToString())
                                                              , Shove._Convert.StrToDateTime(endtime, DateTime.Now.ToString())
                                                              , DateTime.Now
                                                              , WinNumber
                                                              , ref ReturnValue
                                                              , ref ReturnDescprtion);

                if (Result < 0)
                {
                    base.WriteLog("电子票更新期号P_IsuseEdit。");
                }

                if (ReturnValue < 0)
                {
                    base.WriteLog(ReturnDescprtion);
                }
            }
            #endregion
        }
Beispiel #2
0
        /// <summary>
        /// 发送奖期查询后续业务逻辑
        /// </summary>
        /// <param name="returnMsg"></param>
        private void OnSendSuccess(string returnMsg)
        {
            var xdoc = XDocument.Parse(returnMsg);
            var q = xdoc.Descendants("issue").FirstOrDefault();
            if (q == null)
                throw new Common.ElectronicException("XML数据分析错误,未找到节点【issue】");
            var attrs = q.Attributes().ToDictionary(t => t.Name.LocalName);

            #region db logic
            var t_Isuses = new SLS.Dal.Tables.T_Isuses();

            string lotoid = null; 
            string issue = null; 
            string starttime = null; 
            string endtime = null;
            string bonuscode = null;
            string status = null; 
            int LotteryID = 0;
            string IssueName = null;
            string WinNumber = null;

            var sunlotto = new SLS.Common.EtSunLotto();

            try{
                lotoid = attrs[SunlotXmlDefin.LotoId].Value;
                issue = attrs[SunlotXmlDefin.Issue].Value;
                starttime = attrs[SunlotXmlDefin.StartTime].Value;
                endtime = attrs[SunlotXmlDefin.EndTime].Value;
                status = attrs[SunlotXmlDefin.Status].Value;
                LotteryID = sunlotto.GetSystemLotteryID(lotoid);
                IssueName = sunlotto.ConvertIntoSystemIssue(lotoid, issue);
            }
            catch (Exception e){                    
                base.WriteLog("奖期查询/通知属性分析错误 : " + e.Message); 
            }
            

            //如果包含开奖结果
            if (attrs.ContainsKey(SunlotXmlDefin.BonusCode))
            {
                bonuscode = attrs[SunlotXmlDefin.BonusCode].Value;
                WinNumber = sunlotto.ConverToSystemLottoNum(lotoid, bonuscode);
            }
            if ((LotteryID < 1) || (String.IsNullOrEmpty(issue)))
            {
                base.WriteLog(lotoid + " : 期号 " + issue + " 错误");                      
            }

            long IssueID = 0;
            //新增奖期
            if (t_Isuses.GetCount("LotteryID = " + LotteryID.ToString() + " and [Name] = '" + Shove._Web.Utility.FilteSqlInfusion(IssueName) + "'") < 1)
            {
                DateTime _StartTime = DateTime.Now;
                DateTime _EndTime = DateTime.Now;

                try {
                    _StartTime = DateTime.ParseExact(starttime, "yyyyMMddhhmmss", System.Globalization.CultureInfo.CurrentCulture);
                    _EndTime = DateTime.ParseExact(endtime, "yyyyMMddhhmmss", System.Globalization.CultureInfo.CurrentCulture);
                }
                catch {
                    base.WriteLog(LotteryID.ToString() + " : 期号 " + IssueID.ToString() + " 时间错误");
                }
                string ReturnDescription = "";
                //新增奖期
                if (SLS.Dal.Procedures.P_IsuseAdd(ConnectString, LotteryID, IssueName, _StartTime, _EndTime, "", ref IssueID, ref ReturnDescription) < 0)
                    base.WriteLog(LotteryID.ToString() + " : 期号 " + IssueID.ToString() + " 新增错误");

                if (IssueID < 0)                    
                    base.WriteLog(LotteryID.ToString() + " : 期号 " + IssueID.ToString() + " 错误");
            }

            var dtIssue = t_Isuses.Open(ConnectString
                ,"ID, State, WinLotteryNumber"
                , "LotteryID = " + LotteryID.ToString() + " and [Name] = '" + Shove._Web.Utility.FilteSqlInfusion(IssueName) + "' and LotteryID  in (select id from T_Lotteries where PrintOutType = 301)"
                , "");

            if ((dtIssue == null) || (dtIssue.Rows.Count < 1)) {
                //todo 
            }
            
            if (status == IssueState.Drawing) {
                int ReturnValue = -1;
                string ReturnDescprtion = "";

                int Result = SLS.Dal.Procedures.P_ElectronTicketAgentSchemeQuash(ConnectString, Shove._Convert.StrToLong(dtIssue.Rows[0]["ID"].ToString(), 0), ref ReturnValue, ref ReturnDescprtion);
                if (Result < 0)
                {
                    //new Log("ElectronTicket\\SunLotto").Write("电子票方案撤单错误_P_ElectronTicketAgentSchemeQuash : " + IssueID.ToString());
                    base.WriteLog("电子票方案撤单错误_P_ElectronTicketAgentSchemeQuash : " + IssueID.ToString());
                }
            }
            else if (status == IssueState.Open) { 
            }

            bool isHasUpdate = false;

            if (dtIssue.Rows[0]["State"].ToString() != status)
                isHasUpdate = true;

            if (isHasUpdate) {
                int ReturnValue = -1;
                string ReturnDescprtion = "";

                int Result = SLS.Dal.Procedures.P_IsuseUpdate(ConnectString
                    , LotteryID
                    , Shove._Web.Utility.FilteSqlInfusion(IssueName)
                    , Shove._Convert.StrToShort(status, 1)
                    , Shove._Convert.StrToDateTime(starttime, DateTime.Now.ToString())
                    , Shove._Convert.StrToDateTime(endtime, DateTime.Now.ToString())
                    , DateTime.Now
                    , WinNumber
                    , ref ReturnValue
                    , ref ReturnDescprtion);

                if (Result < 0)
                    base.WriteLog("电子票更新期号P_IsuseEdit。");    

                if (ReturnValue < 0)
                    base.WriteLog(ReturnDescprtion);
            }  
            #endregion
        }
Beispiel #3
0
        private void ExecForOpen_StepOne(string winXml, int lotteryId, string issueNo, string winNumber, double[] winMoneyList, out long _issueId)
        {
            //根据彩种ID和期号查询当期的自增ID
            var dtIssue = new SLS.Dal.Tables.T_Isuses().Open(ConnectString
                                                             , "*"
                                                             , string.Format(" LotteryID={0} AND Name='{1}' ", lotteryId, issueNo)
                                                             , "");

            if (dtIssue == null)
            {
                throw new SLS.Common.ElectronicException("数据库读写错误");
            }
            if (dtIssue.Rows.Count == 0)
            {
                throw new SLS.Common.ElectronicException(string.Format("未查询到当前期次,彩种:{0},期次号:{1}", lotteryId, issueNo));
            }

            var issueId = dtIssue.Rows[0]["ID"].ToString();

            _issueId = long.Parse(issueId);
            var dtIsuseBonuses = new SLS.Dal.Tables.T_IsuseBonuses().Open(ConnectString
                                                                          , ""
                                                                          , "IsuseID = " + issueId
                                                                          , "");

            if (dtIsuseBonuses == null)
            {
                throw new SLS.Common.ElectronicException("数据库读写错误");
            }

            if (dtIsuseBonuses.Rows.Count < 1)
            {
                int    ReturnValue       = -1;
                string ReturnDescription = "";


                int Result = SLS.Dal.Procedures.P_IsuseBonusesAdd(ConnectString
                                                                  , Shove._Convert.StrToLong(issueId, 0)
                                                                  , 1 //todo : 是否需要修改为自动开奖特殊用户ID
                                                                  , winXml
                                                                  , ref ReturnValue
                                                                  , ref ReturnDescription);

                if (Result < 0)
                {
                    throw new SLS.Common.ElectronicException("数据库读写错误");
                }

                if (ReturnValue < 0)
                {
                    throw new SLS.Common.ElectronicException(ReturnDescription);
                }
            }
            //取出需要开奖的投注记录
            var dt = new SLS.Dal.Tables.T_Schemes().Open(ConnectString
                                                         , "* "
                                                         , "IsuseID = " + Shove._Web.Utility.FilteSqlInfusion(issueId) + " and isOpened = 0 and Buyed = 1"
                                                         , "[ID]");

            if (dt == null)
            {
                throw new SLS.Common.ElectronicException("数据库读写错误");
            }

            StringBuilder sb            = new StringBuilder();
            string        NoWinSchemeID = "";

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string LotteryNumber     = dt.Rows[i]["LotteryNumber"].ToString();
                string Description       = "";
                double WinMoneyNoWithTax = 0;
                double WinMoney          = 0;

                try
                {
                    WinMoney = new SLS.Lottery()[lotteryId].ComputeWin(LotteryNumber
                                                                       , winNumber
                                                                       , ref Description
                                                                       , ref WinMoneyNoWithTax
                                                                       , int.Parse(dt.Rows[i]["PlayTypeID"].ToString())
                                                                       , winMoneyList);
                }
                catch
                {
                    WinMoney = 0;
                    base.WriteLog("方案 ID:" + dt.Rows[i]["ID"].ToString() + " 算奖出现错误!");
                }

                if (WinMoney == 0)
                {
                    NoWinSchemeID += dt.Rows[i]["ID"].ToString() + ",";

                    continue;
                }

                sb.Append("update T_Schemes set EditWinMoney = ").Append(WinMoney * Shove._Convert.StrToInt(dt.Rows[i]["Multiple"].ToString(), 1))
                .Append(", EditWinMoneyNoWithTax = ").Append(WinMoneyNoWithTax * Shove._Convert.StrToInt(dt.Rows[i]["Multiple"].ToString(), 1))
                .Append(", WinDescription = '").Append(Description).Append("'")
                .Append(" where [ID] = ").AppendLine(dt.Rows[i]["ID"].ToString());
            }

            if (!string.IsNullOrEmpty(sb.ToString()))
            {
                Shove.Database.MSSQL.ExecuteNonQuery(ConnectString, sb.ToString(), new Shove.Database.MSSQL.Parameter[0]);
            }

            if (NoWinSchemeID.EndsWith(","))
            {
                NoWinSchemeID = NoWinSchemeID.Substring(0, NoWinSchemeID.Length - 1);
            }

            if (!string.IsNullOrEmpty(NoWinSchemeID))
            {
                StringBuilder sb1 = new StringBuilder();

                sb1.Append("update T_Schemes set EditWinMoney = 0")
                .Append(", EditWinMoneyNoWithTax = 0, isOpened = 1 , OpenOperatorID=" + 1)      //todo : 是否替换userid
                .Append(", WinDescription = ''")
                .Append(" where [ID] in (" + NoWinSchemeID + ")");

                Shove.Database.MSSQL.ExecuteNonQuery(ConnectString, sb1.ToString(), new Shove.Database.MSSQL.Parameter[0]);
            }

            if (dt.Rows.Count == 0)
            {
                return;
            }
            //执行第三步,派奖逻辑
            ExecForOpen_StepThree(issueNo, lotteryId, winNumber, winMoneyList, _issueId);
        }
Beispiel #4
0
        private void ExecForOpen_StepOne(string winXml,int lotteryId,string issueNo,string winNumber,double[] winMoneyList,out long _issueId)
        { 
            //根据彩种ID和期号查询当期的自增ID
            var dtIssue = new SLS.Dal.Tables.T_Isuses().Open(ConnectString
                                                                , "*"
                                                                , string.Format(" LotteryID={0} AND Name='{1}' ",lotteryId,issueNo)
                                                                , "");
            if (dtIssue == null)
                throw new SLS.Common.ElectronicException("数据库读写错误");
            if (dtIssue.Rows.Count == 0)
                throw new SLS.Common.ElectronicException(string.Format("未查询到当前期次,彩种:{0},期次号:{1}",lotteryId,issueNo));

            var issueId = dtIssue.Rows[0]["ID"].ToString();
            _issueId = long.Parse(issueId);
            var dtIsuseBonuses = new SLS.Dal.Tables.T_IsuseBonuses().Open(ConnectString
                                     , ""
                                     , "IsuseID = " + issueId
                                     , "");

            if (dtIsuseBonuses == null)
                throw new SLS.Common.ElectronicException("数据库读写错误");

            if (dtIsuseBonuses.Rows.Count < 1)
            {
                int ReturnValue = -1;
                string ReturnDescription = "";


                int Result = SLS.Dal.Procedures.P_IsuseBonusesAdd(ConnectString
                                , Shove._Convert.StrToLong(issueId, 0)
                                , 1 //todo : 是否需要修改为自动开奖特殊用户ID
                                , winXml
                                , ref ReturnValue
                                , ref ReturnDescription);

                if (Result < 0)
                    throw new SLS.Common.ElectronicException("数据库读写错误");

                if (ReturnValue < 0)
                    throw new SLS.Common.ElectronicException(ReturnDescription);
            }
            //取出需要开奖的投注记录
            var dt = new SLS.Dal.Tables.T_Schemes().Open(ConnectString
                        , "* "
                        , "IsuseID = " + Shove._Web.Utility.FilteSqlInfusion(issueId) + " and isOpened = 0 and Buyed = 1"
                        , "[ID]");

            if (dt == null)
                throw new SLS.Common.ElectronicException("数据库读写错误");

            StringBuilder sb = new StringBuilder();
            string NoWinSchemeID = "";

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string LotteryNumber = dt.Rows[i]["LotteryNumber"].ToString();
                string Description = "";
                double WinMoneyNoWithTax = 0;
                double WinMoney = 0;

                try
                {
                    WinMoney = new SLS.Lottery()[lotteryId].ComputeWin(LotteryNumber
                                                                , winNumber
                                                                , ref Description
                                                                , ref WinMoneyNoWithTax
                                                                , int.Parse(dt.Rows[i]["PlayTypeID"].ToString())
                                                                , winMoneyList);
                }
                catch
                {
                    WinMoney = 0;
                    base.WriteLog("方案 ID:" + dt.Rows[i]["ID"].ToString() + " 算奖出现错误!");                    
                }

                if (WinMoney == 0)
                {
                    NoWinSchemeID += dt.Rows[i]["ID"].ToString()  + ",";

                    continue;
                }

                sb.Append("update T_Schemes set EditWinMoney = ").Append(WinMoney * Shove._Convert.StrToInt(dt.Rows[i]["Multiple"].ToString(), 1))
                    .Append(", EditWinMoneyNoWithTax = ").Append(WinMoneyNoWithTax * Shove._Convert.StrToInt(dt.Rows[i]["Multiple"].ToString(), 1))
                    .Append(", WinDescription = '").Append(Description).Append("'")
                    .Append(" where [ID] = ").AppendLine(dt.Rows[i]["ID"].ToString());
            }

            if(!string.IsNullOrEmpty(sb.ToString()))
                Shove.Database.MSSQL.ExecuteNonQuery(ConnectString,sb.ToString(), new Shove.Database.MSSQL.Parameter[0]);

            if (NoWinSchemeID.EndsWith(","))
            {
                NoWinSchemeID = NoWinSchemeID.Substring(0, NoWinSchemeID.Length - 1);
            }

            if (!string.IsNullOrEmpty(NoWinSchemeID))
            {
                StringBuilder sb1 = new StringBuilder();

                sb1.Append("update T_Schemes set EditWinMoney = 0")
                    .Append(", EditWinMoneyNoWithTax = 0, isOpened = 1 , OpenOperatorID=" + 1)  //todo : 是否替换userid
                    .Append(", WinDescription = ''")
                    .Append(" where [ID] in (" + NoWinSchemeID + ")");

                Shove.Database.MSSQL.ExecuteNonQuery(ConnectString,sb1.ToString(), new Shove.Database.MSSQL.Parameter[0]);
            }

            if (dt.Rows.Count == 0)
                return;
            //执行第三步,派奖逻辑
            ExecForOpen_StepThree(issueNo, lotteryId, winNumber, winMoneyList,_issueId);
        }
Beispiel #5
0
        // 查询奖期状态
        private void QueryIsuseState()
        {
            // 查询的几组条件说明:
            //  1 有效期内未开奖、未开启的
            //  2 已截止未开奖的 (2 days ago = 2280 minutes)
            DataTable dt = new SLS.Dal.Views.V_Isuses().Open(ConnectionString, "[ID], LotteryID, [Name], [EndTime]", "((isOpened = 0 and (Getdate() between StartTime and EndTime) and State = 0) or (isOpened = 0 and DATEDIFF(MINUTE, Getdate(), EndTime) > -2280 AND GETDATE() > EndTime and State < 6)) and PrintOutType = 301", "EndTime");
           
            if (dt == null)
            {
                //msg.Send("期号状态查询错误(QueryIsuseState)。");
                issLog.Write("期号状态查询错误(QueryIsuseState)。");
                return;
            }

            if (dt.Rows.Count < 1)
            {
                return;
            }
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (i % 100 == 99)
                {
                    System.Threading.Thread.Sleep(1000);
                }

                #region 查询奖期 一次1期
                // inquery xml here
                int lottoID = 0;
                if (!int.TryParse(dt.Rows[i]["LotteryID"].ToString(), out lottoID))
                    continue;
                string ReceiveString = null;
                string ErrorCode = null;
                try
                {   // post to provider and wait for response
                    ErrorCode = eTicketProvider.GetLotteryInfo(lottoID, dt.Rows[i]["Name"].ToString(), out ReceiveString);
                }
                catch{
                    continue;
                }
                string logString = string.Empty;
                if(string.IsNullOrEmpty(ConfigurationManager.AppSettings["LogAll"]) || ConfigurationManager.AppSettings["LogAll"].Equals("true"))
                {
                    XmlDocument xdLog = new XmlDocument();
                    xdLog.LoadXml(ReceiveString);
                    XmlNodeList xNode = xdLog.GetElementsByTagName("body");
                    if (xNode != null && xNode.Count > 0)
                        logString = xNode[0].OuterXml;
                    else
                        logString = ReceiveString;
                }
                issLog.Write("期号: (" + lottoID.ToString() + ") " + dt.Rows[i]["Name"].ToString() + " | " + logString);
                #endregion
                if (ErrorCode == null || ReceiveString == null)
                    continue;
                if (ErrorCode != "0")
                    continue;

                #region 处理结果

                XmlDocument XmlDoc = new XmlDocument();
                XmlNodeList nodesIssue = null;

                try
                {
                    XmlDoc.Load(new StringReader(ReceiveString));
                    nodesIssue = XmlDoc.GetElementsByTagName("issue");
                }
                catch{
                    continue;
                }

                if (nodesIssue == null || nodesIssue.Count < 1)
                    continue;

                SLS.Dal.Tables.T_Isuses t_Isuses = new SLS.Dal.Tables.T_Isuses();
                string lotoid = null;
                string issue = null;
                string Status = null;
                string lottoNum = null;
                int LotteryID = 0;
                string IssueName = null;

                if (nodesIssue[0].Attributes.Count < 1){
                    continue;
                }
                try
                {
                    lotoid = nodesIssue[0].Attributes["lotoid"].Value;
                    issue = nodesIssue[0].Attributes["issue"].Value;
                    Status = nodesIssue[0].Attributes["status"].Value;
                    if (nodesIssue[0].Attributes["bonuscode"] != null)
                        lottoNum = nodesIssue[0].Attributes["bonuscode"].Value;
                    LotteryID = eTicketProvider.GetSystemLotteryID(lotoid);
                    IssueName = eTicketProvider.ConvertIntoSystemIssue(lotoid, issue);
                }
                catch { continue; }
                if ((LotteryID == 0)) { continue; }
                
                DataTable dtIsuse = t_Isuses.Open(ConnectionString, "ID, State, WinLotteryNumber", "LotteryID = " + LotteryID.ToString() + " and [Name] = '" + IssueName + "'", "");
                if ((dtIsuse == null) || (dtIsuse.Rows.Count != 1)){ continue; }

                bool isHasUpdate = false;
                // 奖期状态:0 未开启 1 开始 2 暂停 3 截止 4 期结 5 返奖 6 返奖结束
                // Sun : 0 未开启 1 已开新期 2 暂停 3 截止投注 4 摇出奖号 5 兑奖中 6 结期兑奖
                if (dtIsuse.Rows[0]["State"].ToString() != Status)
                {
                    t_Isuses.State.Value = Status;
                    t_Isuses.StateUpdateTime.Value = DateTime.Now;
                    isHasUpdate = true;
                }
                string WinNumber = null;
                if (lottoNum != null)
                    WinNumber = eTicketProvider.ConverToSystemLottoNum(lotoid, lottoNum);

                if (!String.IsNullOrEmpty(WinNumber) && (dtIsuse.Rows[0]["WinLotteryNumber"].ToString() != WinNumber))
                {
                    t_Isuses.WinLotteryNumber.Value = WinNumber;
                    isHasUpdate = true;

                    if (LotteryID == SLS.Lottery.SHSSL.ID)
                    {
                        DataTable dtWinTypes = new SLS.Dal.Tables.T_WinTypes().Open(ConnectionString, "", "LotteryID =" + LotteryID.ToString(), "");
                        double[] WinMoneyList = new double[dtWinTypes.Rows.Count * 2];
                        for (int k = 0; k < dtWinTypes.Rows.Count; k++)
                        {
                            WinMoneyList[k * 2] = Shove._Convert.StrToDouble(dtWinTypes.Rows[k]["DefaultMoney"].ToString(), 1);
                            WinMoneyList[k * 2 + 1] = Shove._Convert.StrToDouble(dtWinTypes.Rows[k]["DefaultMoneyNoWithTax"].ToString(), 1);
                        }

                        DataTable dtChaseTaskDetails = new SLS.Dal.Tables.T_ChaseTaskDetails().Open(ConnectionString, "", "IsuseID=" + dtIsuse.Rows[0]["ID"].ToString() + " and SchemeID IS NOT NULL", "");
                        for (int k = 0; k < dtChaseTaskDetails.Rows.Count; k++)
                        {
                            string LotteryNumber = dtChaseTaskDetails.Rows[k]["LotteryNumber"].ToString();
                            string Description = "";
                            double WinMoneyNoWithTax = 0;
                            double WinMoney = new SLS.Lottery()[LotteryID].ComputeWin(LotteryNumber, WinNumber, ref Description, ref WinMoneyNoWithTax, int.Parse(dtChaseTaskDetails.Rows[k]["PlayTypeID"].ToString()), WinMoneyList);

                            if (WinMoney < 1){
                                continue;
                            }
                            int ReturnValue = 0;
                            string ReturnDescprtion = "";
                            if (SLS.Dal.Procedures.P_ChaseTaskStopWhenWin(ConnectionString, Shove._Convert.StrToLong(dtChaseTaskDetails.Rows[k]["SiteID"].ToString(), 1), Shove._Convert.StrToLong(dtChaseTaskDetails.Rows[k]["SchemeID"].ToString(), 0), WinMoney, ref ReturnValue, ref ReturnDescprtion) < 0)
                            {
                                log.Write("(QueryIsuseState)电子票撤销追号错误 P_ChaseTaskStopWhenWin。");
                            }
                        }
                    }
                }
                
                if (isHasUpdate){
                    t_Isuses.Update(ConnectionString, "LotteryID = " + LotteryID.ToString() + " and [Name] = '" + IssueName + "'");
                }
                #endregion
            }
        }
Beispiel #6
0
        // 查询奖期状态
        private void QueryIsuseState()
        {
            // 查询的几组条件说明:
            //  1 有效期内未开奖、未开启的
            //  2 已截止未开奖的 (2 days ago = 2280 minutes)
            DataTable dt = new SLS.Dal.Views.V_Isuses().Open(ConnectionString, "[ID], LotteryID, [Name], [EndTime]", "((isOpened = 0 and (Getdate() between StartTime and EndTime) and State = 0) or (isOpened = 0 and DATEDIFF(MINUTE, Getdate(), EndTime) > -2280 AND GETDATE() > EndTime and State < 6)) and PrintOutType = 301", "EndTime");

            if (dt == null)
            {
                //msg.Send("期号状态查询错误(QueryIsuseState)。");
                issLog.Write("期号状态查询错误(QueryIsuseState)。");
                return;
            }

            if (dt.Rows.Count < 1)
            {
                return;
            }
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (i % 100 == 99)
                {
                    System.Threading.Thread.Sleep(1000);
                }

                #region 查询奖期 一次1期
                // inquery xml here
                int lottoID = 0;
                if (!int.TryParse(dt.Rows[i]["LotteryID"].ToString(), out lottoID))
                {
                    continue;
                }
                string ReceiveString = null;
                string ErrorCode     = null;
                try
                {   // post to provider and wait for response
                    ErrorCode = eTicketProvider.GetLotteryInfo(lottoID, dt.Rows[i]["Name"].ToString(), out ReceiveString);
                }
                catch {
                    continue;
                }
                string logString = string.Empty;
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["LogAll"]) || ConfigurationManager.AppSettings["LogAll"].Equals("true"))
                {
                    XmlDocument xdLog = new XmlDocument();
                    xdLog.LoadXml(ReceiveString);
                    XmlNodeList xNode = xdLog.GetElementsByTagName("body");
                    if (xNode != null && xNode.Count > 0)
                    {
                        logString = xNode[0].OuterXml;
                    }
                    else
                    {
                        logString = ReceiveString;
                    }
                }
                issLog.Write("期号: (" + lottoID.ToString() + ") " + dt.Rows[i]["Name"].ToString() + " | " + logString);
                #endregion
                if (ErrorCode == null || ReceiveString == null)
                {
                    continue;
                }
                if (ErrorCode != "0")
                {
                    continue;
                }

                #region 处理结果

                XmlDocument XmlDoc     = new XmlDocument();
                XmlNodeList nodesIssue = null;

                try
                {
                    XmlDoc.Load(new StringReader(ReceiveString));
                    nodesIssue = XmlDoc.GetElementsByTagName("issue");
                }
                catch {
                    continue;
                }

                if (nodesIssue == null || nodesIssue.Count < 1)
                {
                    continue;
                }

                SLS.Dal.Tables.T_Isuses t_Isuses = new SLS.Dal.Tables.T_Isuses();
                string lotoid    = null;
                string issue     = null;
                string Status    = null;
                string lottoNum  = null;
                int    LotteryID = 0;
                string IssueName = null;

                if (nodesIssue[0].Attributes.Count < 1)
                {
                    continue;
                }
                try
                {
                    lotoid = nodesIssue[0].Attributes["lotoid"].Value;
                    issue  = nodesIssue[0].Attributes["issue"].Value;
                    Status = nodesIssue[0].Attributes["status"].Value;
                    if (nodesIssue[0].Attributes["bonuscode"] != null)
                    {
                        lottoNum = nodesIssue[0].Attributes["bonuscode"].Value;
                    }
                    LotteryID = eTicketProvider.GetSystemLotteryID(lotoid);
                    IssueName = eTicketProvider.ConvertIntoSystemIssue(lotoid, issue);
                }
                catch { continue; }
                if ((LotteryID == 0))
                {
                    continue;
                }

                DataTable dtIsuse = t_Isuses.Open(ConnectionString, "ID, State, WinLotteryNumber", "LotteryID = " + LotteryID.ToString() + " and [Name] = '" + IssueName + "'", "");
                if ((dtIsuse == null) || (dtIsuse.Rows.Count != 1))
                {
                    continue;
                }

                bool isHasUpdate = false;
                // 奖期状态:0 未开启 1 开始 2 暂停 3 截止 4 期结 5 返奖 6 返奖结束
                // Sun : 0 未开启 1 已开新期 2 暂停 3 截止投注 4 摇出奖号 5 兑奖中 6 结期兑奖
                if (dtIsuse.Rows[0]["State"].ToString() != Status)
                {
                    t_Isuses.State.Value           = Status;
                    t_Isuses.StateUpdateTime.Value = DateTime.Now;
                    isHasUpdate = true;
                }
                string WinNumber = null;
                if (lottoNum != null)
                {
                    WinNumber = eTicketProvider.ConverToSystemLottoNum(lotoid, lottoNum);
                }

                if (!String.IsNullOrEmpty(WinNumber) && (dtIsuse.Rows[0]["WinLotteryNumber"].ToString() != WinNumber))
                {
                    t_Isuses.WinLotteryNumber.Value = WinNumber;
                    isHasUpdate = true;

                    if (LotteryID == SLS.Lottery.SHSSL.ID)
                    {
                        DataTable dtWinTypes   = new SLS.Dal.Tables.T_WinTypes().Open(ConnectionString, "", "LotteryID =" + LotteryID.ToString(), "");
                        double[]  WinMoneyList = new double[dtWinTypes.Rows.Count * 2];
                        for (int k = 0; k < dtWinTypes.Rows.Count; k++)
                        {
                            WinMoneyList[k * 2]     = Shove._Convert.StrToDouble(dtWinTypes.Rows[k]["DefaultMoney"].ToString(), 1);
                            WinMoneyList[k * 2 + 1] = Shove._Convert.StrToDouble(dtWinTypes.Rows[k]["DefaultMoneyNoWithTax"].ToString(), 1);
                        }

                        DataTable dtChaseTaskDetails = new SLS.Dal.Tables.T_ChaseTaskDetails().Open(ConnectionString, "", "IsuseID=" + dtIsuse.Rows[0]["ID"].ToString() + " and SchemeID IS NOT NULL", "");
                        for (int k = 0; k < dtChaseTaskDetails.Rows.Count; k++)
                        {
                            string LotteryNumber     = dtChaseTaskDetails.Rows[k]["LotteryNumber"].ToString();
                            string Description       = "";
                            double WinMoneyNoWithTax = 0;
                            double WinMoney          = new SLS.Lottery()[LotteryID].ComputeWin(LotteryNumber, WinNumber, ref Description, ref WinMoneyNoWithTax, int.Parse(dtChaseTaskDetails.Rows[k]["PlayTypeID"].ToString()), WinMoneyList);

                            if (WinMoney < 1)
                            {
                                continue;
                            }
                            int    ReturnValue      = 0;
                            string ReturnDescprtion = "";
                            if (SLS.Dal.Procedures.P_ChaseTaskStopWhenWin(ConnectionString, Shove._Convert.StrToLong(dtChaseTaskDetails.Rows[k]["SiteID"].ToString(), 1), Shove._Convert.StrToLong(dtChaseTaskDetails.Rows[k]["SchemeID"].ToString(), 0), WinMoney, ref ReturnValue, ref ReturnDescprtion) < 0)
                            {
                                log.Write("(QueryIsuseState)电子票撤销追号错误 P_ChaseTaskStopWhenWin。");
                            }
                        }
                    }
                }

                if (isHasUpdate)
                {
                    t_Isuses.Update(ConnectionString, "LotteryID = " + LotteryID.ToString() + " and [Name] = '" + IssueName + "'");
                }
                #endregion
            }
        }