// 发送代购电子票 private void SendTickets() { SLS.Dal.Views.V_SchemesSendToCenter v_SchemesSendToCenter = new SLS.Dal.Views.V_SchemesSendToCenter(); //changed state = 1 to state = 0 for testing purposes // selects all scheme to be sent to provider //DataTable dt = v_SchemesSendToCenter.Open(ConnectionString, "distinct SchemeID, SiteID, UserType", "Buyed = 0 and (GetDate() between StartTime and EndTime) and Sends < 99 and HandleResult = 0 and State = 0 and LotteryID <> 29 and PrintOutType = 301", " UserType desc"); // changed to select all schemes from same lottery and issue to be sent to provider DataTable dt = v_SchemesSendToCenter.Open(ConnectionString, "distinct LotteryID, SiteID, IsuseName", "Buyed = 0 and QuashStatus = 0 and (GetDate() between StartTime and EndTime) and Sends < 99 and HandleResult = 0 and State = 1 and LotteryID <> 29 and PrintOutType = 301", ""); if (dt == null){ log.Write("发送代购票出错(SendTickets):读取方案错误。"); return; } //log.Write("SendTickets Started " + dt.Rows.Count); //SLS.Dal.Tables.T_SchemesSendToCenter t_SchemesSendToCenter = new SLS.Dal.Tables.T_SchemesSendToCenter(); // each ticket from a certain Issue that is waiting to be sent to provider, dt row # = # of issues waiting to be sent Stopwatch counter = new Stopwatch(); counter.Start(); for (int i = 0; i < dt.Rows.Count; i++) { DataTable dtSchemesSend = v_SchemesSendToCenter.Open(ConnectionString, "", "LotteryID =" + dt.Rows[i]["LotteryID"].ToString() + " and Buyed = 0 and QuashStatus = 0 and (GetDate() between StartTime and EndTime) and Sends < 99 and HandleResult = 0 and State = 1 and PrintOutType = 301", "SchemeID"); if (dtSchemesSend == null){ log.Write("发送代购票出错(SendTickets):读取错误。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); continue; } if (dtSchemesSend.Rows.Count < 1){ continue; } log.Write("SchemeSendToCenter LotteryID: " + dt.Rows[i]["LotteryID"].ToString() + " | Count: " + dtSchemesSend.Rows.Count.ToString()); int lotteryID = int.Parse(dt.Rows[i]["LotteryID"].ToString()); string issueName = dt.Rows[i]["IsuseName"].ToString(); string ticketXML = string.Empty; #region Process SchemeSendToCenter retrieved string idString = "("; foreach (DataRow drScheme in dtSchemesSend.Rows) { long schemeID = 0; string lottoNumber = null; string ticketSeq = null; int playTypeID = 0; string multiplier = null; double total = 0; try { schemeID = long.Parse(drScheme["SchemeID"].ToString()); lottoNumber = drScheme["Ticket"].ToString(); ticketSeq = string.Format("{0:D5}", long.Parse(drScheme["ID"].ToString()) % 100000); playTypeID = int.Parse(drScheme["PlayTypeID"].ToString()); multiplier = drScheme["Multiple"].ToString(); total = double.Parse(drScheme["Money"].ToString()); idString += drScheme["ID"].ToString() + ","; } catch(Exception e){ log.Write("parse data 出错(SendTickets drScheme)。方案ID:" + drScheme["SchemeID"].ToString() + " | M: " + e.Message + " >> " + e.Source); continue; } ticketXML += eTicketProvider.ConvertToTicketXML(ticketSeq, lotteryID, playTypeID, lottoNumber, multiplier, total); } idString = idString.Trim(',') + ")"; #endregion string orderNumber = DateTime.Now.ToString("yyyyMMddHHmmss") + issueName.Replace("-", "_").PadLeft(12, '0'); string RealityName = ConfigurationManager.AppSettings["eTicketUserName"]; string IDCardNumber = ConfigurationManager.AppSettings["eTicketIDNumber"]; string Mobile = ConfigurationManager.AppSettings["eTicketCellphone"]; string bodyXML = eTicketProvider.PrepareTicketsXML(orderNumber, IDCardNumber, Mobile, RealityName, lotteryID, issueName, ticketXML); string orderXML = eTicketProvider.GenerateOrderXML(bodyXML, orderNumber); log.Write("Order XML: " + orderXML); string ReceiveString = null; string ErrorCode = null; while (i > 0 && counter.ElapsedMilliseconds < 10000) System.Threading.Thread.Sleep(1000); try { ErrorCode = eTicketProvider.OrdereTicketSend(orderXML, out ReceiveString); counter.Reset(); counter.Start(); } catch(Exception ex){ log.Write("电子票-301 发送失败(SendTickets)。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString() + " | " + ex.Message); counter.Reset(); counter.Start(); continue; } //update sends on all Schemes from dtSchemesSend and set identifiers to order number if (MSSQL.ExecuteNonQuery(ConnectionString, "update v_SchemesSendToCenter set Sends = Sends + 1, Identifiers = '" + orderNumber + "' where ID in " + idString) < 0) { log.Write("更新票发送状态时出错(SendTickets)。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString() + " tickets: " + idString); } DataTable dtmp = new DataView(dtSchemesSend).ToTable(true, "SchemeID"); string schemeUpdate = "("; foreach (DataRow dr in dtmp.Rows) { schemeUpdate += dr["SchemeID"].ToString() + ","; } schemeUpdate = schemeUpdate.Trim().Trim(',') + ")"; if (MSSQL.ExecuteNonQuery(ConnectionString, "update T_Schemes set Identifiers = " + orderNumber + " where ID in " + schemeUpdate) < 0) { log.Write("更新 Scheme Identifiers error (SendTickets) - order # : " + orderNumber + ", Schemes : " + schemeUpdate); } if (MSSQL.ExecuteNonQuery(ConnectionString, "update T_SchemesSendToCenter set Identifiers = " + orderNumber + " where SchemeID in " + schemeUpdate) < 0) { log.Write("更新 T_SchemesSendToCenter Identifiers error (SendTickets) - order # : " + orderNumber + ", Schemes : " + schemeUpdate); } //log.Write("Ticket Sent"); #region Parse and proccess results if (ErrorCode == null){ log.Write("电子票-301 发送 Error (SendTickets)。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); continue; } log.Write("Response Recieved: " + ReceiveString); if (ErrorCode == "402") // IP restricted by provider, exit { log.Write("IP Restricted (SendTickets)。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); return; } // 109 - 10秒内禁止重复发单 if (ErrorCode == "109"){ i--; counter.Reset(); counter.Start(); System.Threading.Thread.Sleep(10000); continue; } // 重复发送的投注票 if (ErrorCode == "305"){ log.Write("重复发送的投注票(SendTickets):。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); continue; } int err = 0; if(!int.TryParse(ErrorCode, out err)) continue; if (err >= 100 && err <= 108) continue; // Agent ID is blocked if (ErrorCode == "112"){ log.Write("[Critical] Agent ID 被禁止(SendTickets):。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); return; } // received string is valid process, error code = 0 int ReturnValue = 0; string ReturnDescription = ""; // selects unique Schemes ID from dtSchemesSend DataTable dtUniqueScheme = new DataView(dtSchemesSend).ToTable(true, "SchemeID"); if (ErrorCode == "0") { // update each scheme when ticket errorcode = 0 foreach (DataRow drSch in dtUniqueScheme.Rows) { int Result = SLS.Dal.Procedures.P_SchemesSendToCenterHandleUniteAnte(ConnectionString, Shove._Convert.StrToLong(drSch["SchemeID"].ToString(), -1), DateTime.Now, true, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) { log.Write("对所发送的成功落地的代购票第一次处理出错(SendTickets):数据读写错误。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString() + "," + ReturnDescription); System.Threading.Thread.Sleep(1100); ReturnValue = 0; ReturnDescription = ""; Result = SLS.Dal.Procedures.P_SchemesSendToCenterHandleUniteAnte(ConnectionString, Shove._Convert.StrToLong(drSch["SchemeID"].ToString(), -1), DateTime.Now, true, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) log.Write("对所发送的成功落地的代购票第二次处理出错(SendTickets):数据读写错误。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString() + "," + ReturnDescription); } } log.Write("Response Proccessed - Ticket OK (" + orderNumber + ")"); continue; } int SiteID = Shove._Convert.StrToInt(dt.Rows[i]["SiteID"].ToString(), 1); if ("301 302 303 304 306 400 401".Split(' ').Contains(ErrorCode)) // need to cancel this scheme { foreach (DataRow dr in dtUniqueScheme.Rows) { int Result = SLS.Dal.Procedures.P_QuashScheme(ConnectionString, SiteID, Shove._Convert.StrToLong(dr["SchemeID"].ToString(), 0), true, false, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) log.Write("对所发送落地失败的代购票【作撤单】处理出错(SendTickets):数据读写错误。票号:" + dr["SchemeID"].ToString() + "," + ErrorCode + "," + ReturnDescription); } } #endregion } }
// 发送代购电子票 private void SendTickets() { SLS.Dal.Views.V_SchemesSendToCenter v_SchemesSendToCenter = new SLS.Dal.Views.V_SchemesSendToCenter(); //changed state = 1 to state = 0 for testing purposes // selects all scheme to be sent to provider //DataTable dt = v_SchemesSendToCenter.Open(ConnectionString, "distinct SchemeID, SiteID, UserType", "Buyed = 0 and (GetDate() between StartTime and EndTime) and Sends < 99 and HandleResult = 0 and State = 0 and LotteryID <> 29 and PrintOutType = 301", " UserType desc"); // changed to select all schemes from same lottery and issue to be sent to provider DataTable dt = v_SchemesSendToCenter.Open(ConnectionString, "distinct LotteryID, SiteID, IsuseName", "Buyed = 0 and QuashStatus = 0 and (GetDate() between StartTime and EndTime) and Sends < 99 and HandleResult = 0 and State = 1 and LotteryID <> 29 and PrintOutType = 301", ""); if (dt == null) { log.Write("发送代购票出错(SendTickets):读取方案错误。"); return; } //log.Write("SendTickets Started " + dt.Rows.Count); //SLS.Dal.Tables.T_SchemesSendToCenter t_SchemesSendToCenter = new SLS.Dal.Tables.T_SchemesSendToCenter(); // each ticket from a certain Issue that is waiting to be sent to provider, dt row # = # of issues waiting to be sent Stopwatch counter = new Stopwatch(); counter.Start(); for (int i = 0; i < dt.Rows.Count; i++) { DataTable dtSchemesSend = v_SchemesSendToCenter.Open(ConnectionString, "", "LotteryID =" + dt.Rows[i]["LotteryID"].ToString() + " and Buyed = 0 and QuashStatus = 0 and (GetDate() between StartTime and EndTime) and Sends < 99 and HandleResult = 0 and State = 1 and PrintOutType = 301", "SchemeID"); if (dtSchemesSend == null) { log.Write("发送代购票出错(SendTickets):读取错误。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); continue; } if (dtSchemesSend.Rows.Count < 1) { continue; } log.Write("SchemeSendToCenter LotteryID: " + dt.Rows[i]["LotteryID"].ToString() + " | Count: " + dtSchemesSend.Rows.Count.ToString()); int lotteryID = int.Parse(dt.Rows[i]["LotteryID"].ToString()); string issueName = dt.Rows[i]["IsuseName"].ToString(); string ticketXML = string.Empty; #region Process SchemeSendToCenter retrieved string idString = "("; foreach (DataRow drScheme in dtSchemesSend.Rows) { long schemeID = 0; string lottoNumber = null; string ticketSeq = null; int playTypeID = 0; string multiplier = null; double total = 0; try { schemeID = long.Parse(drScheme["SchemeID"].ToString()); lottoNumber = drScheme["Ticket"].ToString(); ticketSeq = string.Format("{0:D5}", long.Parse(drScheme["ID"].ToString()) % 100000); playTypeID = int.Parse(drScheme["PlayTypeID"].ToString()); multiplier = drScheme["Multiple"].ToString(); total = double.Parse(drScheme["Money"].ToString()); idString += drScheme["ID"].ToString() + ","; } catch (Exception e) { log.Write("parse data 出错(SendTickets drScheme)。方案ID:" + drScheme["SchemeID"].ToString() + " | M: " + e.Message + " >> " + e.Source); continue; } ticketXML += eTicketProvider.ConvertToTicketXML(ticketSeq, lotteryID, playTypeID, lottoNumber, multiplier, total); } idString = idString.Trim(',') + ")"; #endregion string orderNumber = DateTime.Now.ToString("yyyyMMddHHmmss") + issueName.Replace("-", "_").PadLeft(12, '0'); string RealityName = ConfigurationManager.AppSettings["eTicketUserName"]; string IDCardNumber = ConfigurationManager.AppSettings["eTicketIDNumber"]; string Mobile = ConfigurationManager.AppSettings["eTicketCellphone"]; string bodyXML = eTicketProvider.PrepareTicketsXML(orderNumber, IDCardNumber, Mobile, RealityName, lotteryID, issueName, ticketXML); string orderXML = eTicketProvider.GenerateOrderXML(bodyXML, orderNumber); log.Write("Order XML: " + orderXML); string ReceiveString = null; string ErrorCode = null; while (i > 0 && counter.ElapsedMilliseconds < 10000) { System.Threading.Thread.Sleep(1000); } try { ErrorCode = eTicketProvider.OrdereTicketSend(orderXML, out ReceiveString); counter.Reset(); counter.Start(); } catch (Exception ex) { log.Write("电子票-301 发送失败(SendTickets)。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString() + " | " + ex.Message); counter.Reset(); counter.Start(); continue; } //update sends on all Schemes from dtSchemesSend and set identifiers to order number if (MSSQL.ExecuteNonQuery(ConnectionString, "update v_SchemesSendToCenter set Sends = Sends + 1, Identifiers = '" + orderNumber + "' where ID in " + idString) < 0) { log.Write("更新票发送状态时出错(SendTickets)。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString() + " tickets: " + idString); } DataTable dtmp = new DataView(dtSchemesSend).ToTable(true, "SchemeID"); string schemeUpdate = "("; foreach (DataRow dr in dtmp.Rows) { schemeUpdate += dr["SchemeID"].ToString() + ","; } schemeUpdate = schemeUpdate.Trim().Trim(',') + ")"; if (MSSQL.ExecuteNonQuery(ConnectionString, "update T_Schemes set Identifiers = " + orderNumber + " where ID in " + schemeUpdate) < 0) { log.Write("更新 Scheme Identifiers error (SendTickets) - order # : " + orderNumber + ", Schemes : " + schemeUpdate); } if (MSSQL.ExecuteNonQuery(ConnectionString, "update T_SchemesSendToCenter set Identifiers = " + orderNumber + " where SchemeID in " + schemeUpdate) < 0) { log.Write("更新 T_SchemesSendToCenter Identifiers error (SendTickets) - order # : " + orderNumber + ", Schemes : " + schemeUpdate); } //log.Write("Ticket Sent"); #region Parse and proccess results if (ErrorCode == null) { log.Write("电子票-301 发送 Error (SendTickets)。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); continue; } log.Write("Response Recieved: " + ReceiveString); if (ErrorCode == "402") // IP restricted by provider, exit { log.Write("IP Restricted (SendTickets)。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); return; } // 109 - 10秒内禁止重复发单 if (ErrorCode == "109") { i--; counter.Reset(); counter.Start(); System.Threading.Thread.Sleep(10000); continue; } // 重复发送的投注票 if (ErrorCode == "305") { log.Write("重复发送的投注票(SendTickets):。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); continue; } int err = 0; if (!int.TryParse(ErrorCode, out err)) { continue; } if (err >= 100 && err <= 108) { continue; } // Agent ID is blocked if (ErrorCode == "112") { log.Write("[Critical] Agent ID 被禁止(SendTickets):。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString()); return; } // received string is valid process, error code = 0 int ReturnValue = 0; string ReturnDescription = ""; // selects unique Schemes ID from dtSchemesSend DataTable dtUniqueScheme = new DataView(dtSchemesSend).ToTable(true, "SchemeID"); if (ErrorCode == "0") { // update each scheme when ticket errorcode = 0 foreach (DataRow drSch in dtUniqueScheme.Rows) { int Result = SLS.Dal.Procedures.P_SchemesSendToCenterHandleUniteAnte(ConnectionString, Shove._Convert.StrToLong(drSch["SchemeID"].ToString(), -1), DateTime.Now, true, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) { log.Write("对所发送的成功落地的代购票第一次处理出错(SendTickets):数据读写错误。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString() + "," + ReturnDescription); System.Threading.Thread.Sleep(1100); ReturnValue = 0; ReturnDescription = ""; Result = SLS.Dal.Procedures.P_SchemesSendToCenterHandleUniteAnte(ConnectionString, Shove._Convert.StrToLong(drSch["SchemeID"].ToString(), -1), DateTime.Now, true, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) { log.Write("对所发送的成功落地的代购票第二次处理出错(SendTickets):数据读写错误。Issue: (" + dt.Rows[i]["LotteryID"].ToString() + ") " + dt.Rows[i]["IsuseName"].ToString() + "," + ReturnDescription); } } } log.Write("Response Proccessed - Ticket OK (" + orderNumber + ")"); continue; } int SiteID = Shove._Convert.StrToInt(dt.Rows[i]["SiteID"].ToString(), 1); if ("301 302 303 304 306 400 401".Split(' ').Contains(ErrorCode)) // need to cancel this scheme { foreach (DataRow dr in dtUniqueScheme.Rows) { int Result = SLS.Dal.Procedures.P_QuashScheme(ConnectionString, SiteID, Shove._Convert.StrToLong(dr["SchemeID"].ToString(), 0), true, false, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) { log.Write("对所发送落地失败的代购票【作撤单】处理出错(SendTickets):数据读写错误。票号:" + dr["SchemeID"].ToString() + "," + ErrorCode + "," + ReturnDescription); } } } #endregion } }
// 代购票查询 private void QueryTickets() { DataTable dt = new SLS.Dal.Views.V_SchemesSendToCenter().Open(ConnectionString, "distinct SchemeID", "(((Sends > 0) AND (Sends < 100)) or (sends = 3301) or (sends = 2148)) AND (HandleResult = 0) AND (IsOpened = 0) and LotteryID <> 29 and PrintOutType = 301", ""); if (dt == null){ log.Write("查询代购票出错(QueryTickets):读取未成功票错误。"); return; } if (dt.Rows.Count < 1){ return; } string lastOrder = null; string ReceiveString = null; string ErrorCode = null; DataTable dtSchemesSendToCenter = null; SLS.Dal.Tables.T_SchemesSendToCenter t_SchemesSendToCenter = new SLS.Dal.Tables.T_SchemesSendToCenter(); // process all schemes that is sent to provider for (int i = 0; i < dt.Rows.Count; i++) { dtSchemesSendToCenter = new SLS.Dal.Tables.T_SchemesSendToCenter().Open(ConnectionString, "top 1 *", "schemeid=" + dt.Rows[i]["SchemeID"].ToString() + " and (Sends > 0) AND (Sends < 100)", ""); if (dtSchemesSendToCenter == null){ continue; } if (dtSchemesSendToCenter.Rows.Count < 1){ continue; } string orderNumber = dtSchemesSendToCenter.Rows[0]["Identifiers"].ToString(); if (orderNumber == null || orderNumber == ""){ continue; } if (orderNumber != lastOrder) { try{ ErrorCode = eTicketProvider.CheckOrderStatus(orderNumber, out ReceiveString); } catch{ continue; } lastOrder = orderNumber; } if (ErrorCode == null) continue; if ("100 101 102 103 104 105 106 107 108 111 301 302 303 304 305 306 350 360 400 401".Split(' ').Contains(ErrorCode)) { t_SchemesSendToCenter.Sends.Value = ErrorCode + 100; t_SchemesSendToCenter.Update(ConnectionString, "SchemeID = " + dt.Rows[i]["SchemeID"].ToString()); continue; } if (ErrorCode == "112" || ErrorCode == "402"){ log.Write("IP / AgentID cannot be used, Code: " + ErrorCode); return; } if (ErrorCode != "0") continue; XmlDocument XmlDoc = new XmlDocument(); XmlNodeList orderNodes = null; XmlNodeList ticketNodes = null; string orderStatus = null; try { XmlDoc.Load(new StringReader(ReceiveString)); orderNodes = XmlDoc.GetElementsByTagName("order"); orderStatus = orderNodes[0].Attributes["status"].Value; ticketNodes = XmlDoc.GetElementsByTagName("ticket"); } catch { continue; } if (ticketNodes == null || ticketNodes.Count == 0){ continue; } if (orderStatus == "0"){ continue; } // Order is successful process all tickets at once if (orderStatus == "1") { int ReturnValue = 0; string ReturnDescription = ""; int Result = SLS.Dal.Procedures.P_SchemesSendToCenterHandleUniteAnte(ConnectionString, Shove._Convert.StrToLong(dt.Rows[i]["SchemeID"].ToString(), -1), DateTime.Now, true, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) { log.Write("对所查询到的电子票数据第一次处理出错(QueryTickets):数据读写错误。Scheme:" + dt.Rows[i]["SchemeID"].ToString() + "," + ReturnDescription); System.Threading.Thread.Sleep(1000); Result = SLS.Dal.Procedures.P_SchemesSendToCenterHandleUniteAnte(ConnectionString, Shove._Convert.StrToLong(dt.Rows[i]["SchemeID"].ToString(), -1), DateTime.Now, true, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)){ log.Write("对所查询到的电子票数据第二次处理出错(QueryTickets):数据读写错误。票号:" + dt.Rows[i]["SchemeID"].ToString() + "," + ReturnDescription); } } continue; } // order failed if (orderStatus == "3") { t_SchemesSendToCenter.Sends.Value = 999; t_SchemesSendToCenter.Update(ConnectionString, "SchemeID = " + dt.Rows[i]["SchemeID"].ToString()); continue; } // not done // parts of order failed, process individual tickets returned if (orderStatus == "2") { string ticketFailed = string.Empty; for (int k = 0; k < ticketNodes.Count; k++) { try { string ticketStatus = ticketNodes[k].Attributes["status"].Value; string ticketSeq = ticketNodes[k].Attributes["seq"].Value; if (ticketStatus.ToLower() == "N") { ticketFailed += ticketSeq + ","; } } catch { continue; } } ticketFailed = "(" + ticketFailed.Trim().Trim(',') + ")"; if (MSSQL.ExecuteNonQuery(ConnectionString, "update T_SchemesSendToCenter set Sends = 1000 where (SchemeID = " + dt.Rows[i]["SchemeID"].ToString() + ") AND ((ID % 100000) in " + ticketFailed + ") ") < 0) { log.Write("更新票Partially Failed(SendTickets)。方案ID:" + dt.Rows[i]["SchemeID"].ToString()); } } } }
// 代购票查询 private void QueryTickets() { DataTable dt = new SLS.Dal.Views.V_SchemesSendToCenter().Open(ConnectionString, "distinct SchemeID", "(((Sends > 0) AND (Sends < 100)) or (sends = 3301) or (sends = 2148)) AND (HandleResult = 0) AND (IsOpened = 0) and LotteryID <> 29 and PrintOutType = 301", ""); if (dt == null) { log.Write("查询代购票出错(QueryTickets):读取未成功票错误。"); return; } if (dt.Rows.Count < 1) { return; } string lastOrder = null; string ReceiveString = null; string ErrorCode = null; DataTable dtSchemesSendToCenter = null; SLS.Dal.Tables.T_SchemesSendToCenter t_SchemesSendToCenter = new SLS.Dal.Tables.T_SchemesSendToCenter(); // process all schemes that is sent to provider for (int i = 0; i < dt.Rows.Count; i++) { dtSchemesSendToCenter = new SLS.Dal.Tables.T_SchemesSendToCenter().Open(ConnectionString, "top 1 *", "schemeid=" + dt.Rows[i]["SchemeID"].ToString() + " and (Sends > 0) AND (Sends < 100)", ""); if (dtSchemesSendToCenter == null) { continue; } if (dtSchemesSendToCenter.Rows.Count < 1) { continue; } string orderNumber = dtSchemesSendToCenter.Rows[0]["Identifiers"].ToString(); if (orderNumber == null || orderNumber == "") { continue; } if (orderNumber != lastOrder) { try{ ErrorCode = eTicketProvider.CheckOrderStatus(orderNumber, out ReceiveString); } catch { continue; } lastOrder = orderNumber; } if (ErrorCode == null) { continue; } if ("100 101 102 103 104 105 106 107 108 111 301 302 303 304 305 306 350 360 400 401".Split(' ').Contains(ErrorCode)) { t_SchemesSendToCenter.Sends.Value = ErrorCode + 100; t_SchemesSendToCenter.Update(ConnectionString, "SchemeID = " + dt.Rows[i]["SchemeID"].ToString()); continue; } if (ErrorCode == "112" || ErrorCode == "402") { log.Write("IP / AgentID cannot be used, Code: " + ErrorCode); return; } if (ErrorCode != "0") { continue; } XmlDocument XmlDoc = new XmlDocument(); XmlNodeList orderNodes = null; XmlNodeList ticketNodes = null; string orderStatus = null; try { XmlDoc.Load(new StringReader(ReceiveString)); orderNodes = XmlDoc.GetElementsByTagName("order"); orderStatus = orderNodes[0].Attributes["status"].Value; ticketNodes = XmlDoc.GetElementsByTagName("ticket"); } catch { continue; } if (ticketNodes == null || ticketNodes.Count == 0) { continue; } if (orderStatus == "0") { continue; } // Order is successful process all tickets at once if (orderStatus == "1") { int ReturnValue = 0; string ReturnDescription = ""; int Result = SLS.Dal.Procedures.P_SchemesSendToCenterHandleUniteAnte(ConnectionString, Shove._Convert.StrToLong(dt.Rows[i]["SchemeID"].ToString(), -1), DateTime.Now, true, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) { log.Write("对所查询到的电子票数据第一次处理出错(QueryTickets):数据读写错误。Scheme:" + dt.Rows[i]["SchemeID"].ToString() + "," + ReturnDescription); System.Threading.Thread.Sleep(1000); Result = SLS.Dal.Procedures.P_SchemesSendToCenterHandleUniteAnte(ConnectionString, Shove._Convert.StrToLong(dt.Rows[i]["SchemeID"].ToString(), -1), DateTime.Now, true, ref ReturnValue, ref ReturnDescription); if ((Result < 0) || (ReturnValue < 0)) { log.Write("对所查询到的电子票数据第二次处理出错(QueryTickets):数据读写错误。票号:" + dt.Rows[i]["SchemeID"].ToString() + "," + ReturnDescription); } } continue; } // order failed if (orderStatus == "3") { t_SchemesSendToCenter.Sends.Value = 999; t_SchemesSendToCenter.Update(ConnectionString, "SchemeID = " + dt.Rows[i]["SchemeID"].ToString()); continue; } // not done // parts of order failed, process individual tickets returned if (orderStatus == "2") { string ticketFailed = string.Empty; for (int k = 0; k < ticketNodes.Count; k++) { try { string ticketStatus = ticketNodes[k].Attributes["status"].Value; string ticketSeq = ticketNodes[k].Attributes["seq"].Value; if (ticketStatus.ToLower() == "N") { ticketFailed += ticketSeq + ","; } } catch { continue; } } ticketFailed = "(" + ticketFailed.Trim().Trim(',') + ")"; if (MSSQL.ExecuteNonQuery(ConnectionString, "update T_SchemesSendToCenter set Sends = 1000 where (SchemeID = " + dt.Rows[i]["SchemeID"].ToString() + ") AND ((ID % 100000) in " + ticketFailed + ") ") < 0) { log.Write("更新票Partially Failed(SendTickets)。方案ID:" + dt.Rows[i]["SchemeID"].ToString()); } } } }