Exemple #1
0
        // 代购票查询
        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());
                    }
                }
            }
        }
Exemple #2
0
        // 代购票查询
        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());
                    }
                }
            }
        }