/// <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 }
// 查询奖期状态 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 } }
/// <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 }
// 查询奖期状态 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 } }