Beispiel #1
0
        public bool ProcessKickBack(short command_Renamed, string userCode, ref Sale sale, out ErrorMessage errorMessage)
        {
            //  var tender = new Tender();
            bool result   = true;
            var  kickback = new XML(_policyManager);
            var  store    = _policyManager.LoadStoreInfo();

            float timeIN      = 0;
            short TimeOut     = 0;
            bool  GotResponse = false;
            short Answer;
            var   KBComm = new Comm();

            object[] CapValue = new object[3];
            var      tender   = _tenderManager.GetAllTender(sale.Sale_Num, sale.TillNumber, "Sale", userCode, false,
                                                            "", out errorMessage);

            //   command 0 - GetPointStatus Request
            //   command 1 - FinalizeRewards Request - only from Exact Change button
            //   command 2 - Check Balance
            if (command_Renamed < 0 | command_Renamed > 2)
            {
                errorMessage.StatusCode           = HttpStatusCode.BadGateway;
                errorMessage.MessageStyle.Message = "Invalid loyalty card";
                return(false);
            }

            KBComm            = new Comm(); //'' KickBackComm
            KBComm.CommData  += KBComm_CommData;
            KBComm.CommError += KBComm_CommError;



            Comm.KBComm = KBComm;

            var xml      = new XML(_policyManager);
            var saleLine = new Sale_Line();
            var s        = new Sale();


            //  var sale = _saleManager.GetCurrentSale();
            var offSet = _policyManager.LoadStoreInfo().OffSet;

            // Write to log is done by KickBackXML class, POS only displays messages for the cashier

            if (!_xmlManager.Initialize("", "", "", (sale.Sale_Num).ToString(), System.Convert.ToString(store.Code), "", ref xml))
            {
                // Display the same error message on the screen because for cashier doesn't matter
                // if the connection cannot be made or the XML cannot be created.
                // But KickBackXML class writes the error in the log for debugging purposes

                _resourceManager.CreateMessage(offSet, 11, 42, null, MessageType.Exclamation);//Cannot communicate with Loyalty Server
                errorMessage.MessageStyle.Message = "Invalid loyalty card";
                errorMessage.StatusCode           = HttpStatusCode.NotAcceptable;
                return(false);
            }
            else
            {
                kickback.Sale = this.saleObj;

                if (!(tender == null))
                {
                    kickback.Tenders = tender;
                }
            }

            if (command_Renamed == 0 | command_Renamed == 2)
            {
                var a = xml.PosSequenceID;

                // if (!_xmlManager.FormatFinalizeRewardsRequestXML(sale.Customer.PointCardNum, System.Convert.ToString(sale.Customer.PointCardSwipe == "2" ? "SWIPE" : "MANUAL"), (sale.Customer.Points_Redeemed).ToString(), (sale.Sale_Totals.Gross).ToString(), "", "", "", System.Convert.ToString(store.Code), System.Convert.ToString(userCode), System.Convert.ToString(sale.TillNumber), "", "", "", "",ref xml,ref sale))
                if (!_xmlManager.FormatGetPointStatusRequestXML(sale.Customer.PointCardNum, System.Convert.ToString(sale.Customer.PointCardSwipe == "2" ? "SWIPE" : "MANUAL"), ref xml))
                {
                    // Display the same error massage on the screen because for cashier doesn't matter
                    // if the connection cannot be made or the XML cannot be created.
                    // But write the correct reason in the log for debugging purposes

                    _resourceManager.CreateMessage(offSet, 11, 42, null, MessageType.Information); //Cannot communicate to Loyalty TPS

                    return(false);
                }
                var sam1 = xml;
            }


            else if (command_Renamed == 1) // send finalize rewards only from Exact_Change Button
            {
                var points = (sale.Customer.Points_Redeemed == 0) ? 0 : (sale.Customer.Points_Redeemed / ExchangeRate);
                if (!_xmlManager.FormatFinalizeRewardsRequestXML(sale.Customer.PointCardNum, System.Convert.ToString(sale.Customer.PointCardSwipe == "2" ? "SWIPE" : "MANUAL"), points.ToString(), (sale.Sale_Totals.Gross).ToString(), "", "", "", System.Convert.ToString(store.Code), System.Convert.ToString(userCode), System.Convert.ToString(sale.TillNumber), "", "", "", "", ref xml, ref sale))
                // if (!_xmlManager.FormatFinalizeRewardsRequestXML(sale.Customer.PointCardNum, "SWIPE", (sale.Customer.Points_Redeemed * 100).ToString(), (sale.Sale_Totals.Gross).ToString(), "", "", "", System.Convert.ToString(store.Code), System.Convert.ToString(userCode), System.Convert.ToString(sale.TillNumber), "", "", "", "", ref xml, ref sale))
                {
                    //shiny end
                    // Display the same error massage on the screen because for cashier doesn't matter
                    // if the connection cannot be made or the XML cannot be created.
                    // But write the correct reason in the log for debugging purposes
                    //Chaps_Main.DisplayMessage(this, (short)42, MsgBoxStyle.Information, null, (byte)0); //Cannot communicate to Loyalty TPS
                    //shiny sept 14, 2009 - changed to use the common function, so apperstophe fix can do in one place
                    //             dbMaster.Execute "INSERT INTO KickBackQueue VALUES ('" & KickBack.GetRequestXMLstring & "')"
                    // modGlobalFunctions.InsertTo_KickBackQueue(Variables.KickBack.GetRequestXMLstring);
                    InsertTo_KickBackQueue(xml.GetRequestXMLstring);
                    //shiny end - sept14, 2009
                    return(false);
                }
            }


            KickBackBuffer = ""; //clear the response buffer

            Thread.Sleep(500);
            var timeout = _policyManager.KICKBACK_TMT;

            KickBackBuffer = socket.Connect(xml.GetRequestXMLstring, _policyManager.KICKBACK_IP, (short)Conversion.Val(_policyManager.KICKBACK_PRT), (short)Conversion.Val(timeout), out errorMessage);



            if (KickBackBuffer == "failed")
            {
                WriteTokickBackLogFile(" Cannot Send to Server: " + xml.GetRequestXMLstring);
                if (command_Renamed == 1)
                {
                    InsertTo_KickBackQueue(xml.GetRequestXMLstring);
                }
                return(false);
            }

            WriteTokickBackLogFile(" Connected to KickBack Server: " + $"{_policyManager.KICKBACK_IP}:{_policyManager.KICKBACK_PRT}");
            string kickBackTrimmedResponse = KickBackBuffer.Replace("\0", string.Empty);

            WriteTokickBackLogFile(" Received from Kickback Server:: " + kickBackTrimmedResponse.TrimEnd());
            var    sam3    = xml;
            string RespStr = "";

            Byte[] buff = new Byte[1000];

            GotResponse = false;

            TimeOut = System.Convert.ToInt16(_policyManager.KICKBACK_TMT);
            timeIN  = (float)DateAndTime.Timer;
            //    Debug.Print TimeOut & " " & timeIN
            while (!(DateAndTime.Timer - timeIN > TimeOut))
            {
                //        Debug.Print Timer
                System.Windows.Forms.Application.DoEvents();
                if (!string.IsNullOrEmpty(KickBackBuffer))
                {
                    GotResponse = true;
                    break;
                }
                if (DateAndTime.Timer < timeIN)
                {
                    timeIN = (float)DateAndTime.Timer;
                }
            }


            if (!GotResponse)
            {
                WriteTokickBackLogFile("No response from Loyalty Server.");
                if (command_Renamed == 1)
                {
                    InsertTo_KickBackQueue(xml.GetRequestXMLstring);
                }
                MessageType temp_VbStyle2 = (int)MessageType.Critical + MessageType.OkOnly;
                _resourceManager.CreateMessage(offSet, 11, 42, null, temp_VbStyle2);

                return(false);
            }
            _xmlManager.AnalyseKickBackResponse(KickBackBuffer, ref xml);

            if (command_Renamed == 0 | command_Renamed == 2)
            {
                //Analyze the response
                // Modified on Apr 03, 2009 to use two flags for invalid and non registered cards
                // If the card is not valid processing should continue without any KickBack redemtion or acumulation
                // If the card is not registered processing should continue with accumulation but without redemption
                if (!xml.GetLoyaltyIDValid)
                {
                    //Invalid Loyalty Card
                    _resourceManager.CreateMessage(offSet, 11, 45, null, MessageType.OkOnly);
                    // was 1145
                    sale.Customer.PointCardNum         = "";
                    sale.Customer.PointCardPhone       = "";
                    sale.Customer.PointCardSwipe       = "";
                    sale.Customer.Points_ExchangeRate  = 0;
                    sale.Customer.Points_Redeemed      = 0;
                    sale.Customer.PointsAwarded        = 0;
                    sale.Customer.PointCard_Registered = false;

                    errorMessage = new ErrorMessage();
                    errorMessage.MessageStyle = new MessageStyle
                    {
                        Message = "Invalid loyalty card"
                    };
                    errorMessage.StatusCode = HttpStatusCode.NotAcceptable;
                    result = false;
                }
                else if (command_Renamed == 0)
                {
                    if (xml.LoyaltyIDRegistered)
                    {
                        var allowredeem = sale.Customer.PointsCard_AllowRedemption;
                        var balance     = xml.Sale.Customer.Balance_Points;
                        //var saleline = sale.Sale_Lines;
                        //var saletotal = sale.Sale_Totals;
                        //var gross = sale.Sale_Totals.Gross;
                        //var till = sale.TillNumber;
                        //var cardno = sale.Customer.PointCardNum;
                        //var salenum = sale.Sale_Num;
                        //var entrymethod = sale.Customer.PointCardSwipe;
                        //var selectedCustomer = sale.Customer;
                        // sale = xml.Sale;
                        sale.Customer.PointCard_Registered = true;
                        // sale.Sale_Totals = saletotal;
                        // sale.Sale_Num = salenum;
                        // sale.TillNumber = till;
                        // sale.Sale_Lines = saleline;
                        //sale.Customer = selectedCustomer;
                        sale.Customer.PointsCard_AllowRedemption = allowredeem;
                        //sale.Customer.PointCardNum = cardno;
                        //sale.Customer.PointCardSwipe = entrymethod;
                        sale.Customer.Balance_Points = xml.Sale.Customer.Balance_Points;
                        result = true;
                    }
                    else
                    {
                        _resourceManager.CreateMessage(offSet, 11, 46, null, MessageType.OkOnly);

                        sale.Customer.PointCard_Registered = false;
                        sale.Customer.Points_Redeemed      = 0;
                    }
                }
                sale.Customer.Balance_Points = xml.Sale.Customer.Balance_Points;
                ExchangeRate = sale.Customer.Points_ExchangeRate = xml.Sale.Customer.Points_ExchangeRate;
                WriteUDPData(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + "Inside processkickback 483 cardno value" + sale.Customer.PointCardNum);
            }
            var a10 = xml;

            CacheManager.AddCurrentSaleForTill(sale.TillNumber, sale.Sale_Num, sale);
            // _commManager.EndClass();

            //if (((string.IsNullOrEmpty(sale.Customer.CustomerCardNum) && string.IsNullOrEmpty(sale.Customer.PointCardNum))
            //    || (string.IsNullOrEmpty(sale.Customer.CustomerCardNum) && string.IsNullOrEmpty(sale.Customer.PointCardPhone)))
            //    && (string.IsNullOrEmpty(sale.Customer.PointCardNum) && string.IsNullOrEmpty(sale.Customer.LoyaltyCard)))
            //{
            //    errorMessage = new ErrorMessage();
            //    errorMessage.MessageStyle = new MessageStyle
            //    {
            //        Message = "Invalid loyalty card"

            //    };
            //    errorMessage.StatusCode = HttpStatusCode.NotAcceptable;
            //    result = false;
            //}

            //if (sale.Customer.Balance_Points == 0)
            //{
            //    errorMessage = new ErrorMessage();
            //    errorMessage.MessageStyle = new MessageStyle
            //    {
            //        Message = "Invalid loyalty card"

            //    };
            //    errorMessage.StatusCode = HttpStatusCode.NotAcceptable;
            //    result = false;
            //}
            return(result);
        }
Beispiel #2
0
        // Nov 27, 2008: Nicolette modified this function to initialize the connection to
        // KickBack in one function and to check the time out inside this class instead of the POS
        // April 15, 2010: Svetlana added system to make this class completely generic
        //Public Function Initialize(ByVal strHostIP As String, _
        //ByVal intHostPort As Integer) As Boolean
        public bool Initialize(string strHostIP, short intHostPort, short System_Renamed)
        {
            bool    returnValue    = false;
            dynamic Policy_Renamed = default(dynamic);

            int   nError  = 0;
            float timeIN  = 0;
            byte  TimeOut = 0;

            HostIP   = strHostIP;
            HostPort = intHostPort;

            swTCP               = new SocketWrench();
            swTCP.OnConnect    += new EventHandler(swTCP_OnConnect);
            swTCP.OnDisconnect += new EventHandler(swTCP_OnDisconnect);
            swTCP.OnError      += new SocketWrench.OnErrorEventHandler(swTCP_OnError);
            swTCP.OnRead       += new EventHandler(swTCP_OnRead);

            swTCP.AutoResolve = false;
            swTCP.Blocking    = false;
            swTCP.Secure      = false;
            // TODO: Updated call of the socket wrench for the new dll. - Ipsit_33
            // Refer: https://sockettools.com/webhelp/dotnet/dotnet/htmlhelp/SocketTools.SocketWrench.Initialize_overload_1.html
            nError = Convert.ToInt32(swTCP.Initialize(CSTOOLS4_LICENSE_KEY));
            if (nError != 0)
            {
                returnValue = false;
                WriteToLog("Failed to initialize SocketWrench control");
                return(returnValue);
            }

            // TODO: Updated call of the socket wrench for the new dll. - Ipsit_34
            if (swTCP.Status == SocketWrench.SocketStatus.statusDisconnect ||
                swTCP.Status == SocketWrench.SocketStatus.statusUnused)
            {
                nError = Convert.ToInt32(swTCP.Connect(HostIP, HostPort, SocketWrench.SocketProtocol.socketStream, TimeOut));

                if (nError != 0)
                {
                    returnValue = false;

                    WriteToLog("Connect method returned an error in Comm class. Cannot connect to " + HostIP + ":" + Convert.ToString(HostPort));
                    return(returnValue);
                }

                //
                commSystem = System_Renamed;

                if (commSystem == 1)
                {
                    TimeOut = Convert.ToByte(Policy_Renamed.FUELONLY_TMT);
                }
                else
                {
                    TimeOut = (byte)5; //default timeout
                }

                timeIN = (float)DateAndTime.Timer;
                while (true)
                {
                    System.Windows.Forms.Application.DoEvents();
                    // since this function is used not only by Kickback
                    //If (Timer - timeIN > Policy.KICKBACK_TMT) Or boolIsConnected Then
                    if ((DateAndTime.Timer - timeIN > TimeOut) || boolIsConnected)
                    {
                        break;
                    }
                }
            }
            if (boolIsConnected)
            {
                if (commSystem == 1)
                {
                    WriteToLog("Connected to FuelOnly Server " + HostIP + ":" + Convert.ToString(HostPort));
                }
                if (commSystem == 2)
                {
                    carwashSeqNum = (byte)1;
                    WriteToLog("Connected to the Carwash Server" + HostIP + ":" + Convert.ToString(HostPort));
                }
            }
            else
            {
                WriteToLog("Cannot connect to " + HostIP + ":" + Convert.ToString(HostPort));
            }
            returnValue = boolIsConnected;

            return(returnValue);
        }