Example #1
0
        private void SaveManualHandpay()
        {
            if (cmbBarPositions.SelectedIndex <= 0)
            {
                return;
            }
            Window Owner;
            double amount       = 0;
            int    Auth_User_ID = 0;

            try
            {
                CAuthorize objAuthorize = null;

                if (txtBox != null && txtBox.Text.Length > 0)
                {
                    // Issue fix for ->set cultureinfo='en-US',  currencyculture='it-IT'
                    double.TryParse(txtBox.Text.ToString(), NumberStyles.Currency, new CultureInfo(ExtensionMethods.CurrentCurrenyCulture), out amount);
                }
                Auth_User_ID = Security.SecurityHelper.CurrentUser.User_No;
                if (Settings.Client != null && Settings.Client.ToLower() == "winchells" &&
                    Settings.MaxHandPayAuthRequired &&
                    txtBox != null &&
                    (amount > Settings.HandpayPayoutCustomer_Max))
                {
                    objAuthorize = new CAuthorize("CashdeskOperator.Authorize.cs.MaxHandpay");
                    Auth_User_ID = Security.SecurityHelper.CurrentUser.User_No;
                    if (!Security.SecurityHelper.HasAccess("CashdeskOperator.Authorize.cs.MaxHandpay"))
                    {
                        objAuthorize.ShowDialogEx(this);
                        if (!objAuthorize.IsAuthorized)
                        {
                            IsProcessed = true;
                            return;
                        }
                        else
                        {
                            Auth_User_ID = handpay.GetUserID(objAuthorize.User.SecurityUserID);
                        }
                    }
                    else
                    {
                        objAuthorize.IsAuthorized = true;
                    }
                }

                if (Settings.RegulatoryEnabled == true && Settings.RegulatoryType == "AAMS")
                {
                    if (txtBox != null)
                    {
                        Custid           = 0;
                        ProcessCancelled = false;
                        if (amount >= Settings.HandpayPayoutCustomer_Min && amount <= Settings.HandpayPayoutCustomer_Max)
                        {
                            oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                            oCustomerDetails.delCustomerUpdated   += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            Owner = Window.GetWindow(this);
                            oCustomerDetails.ShowDialogEx(this);
                        }
                        else if (amount >= Settings.HandpayPayoutCustomer_BankAccNo)
                        {
                            oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails(true);
                            oCustomerDetails.delCustomerUpdated   += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            Owner = Window.GetWindow(this);
                            oCustomerDetails.ShowDialogEx(this);
                        }
                        else if (amount >= Settings.HandpayPayoutCustomer_Max && amount <= Settings.HandpayPayoutCustomer_BankAccNo)
                        {
                            oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                            oCustomerDetails.delCustomerUpdated   += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            Owner = Window.GetWindow(this);
                            oCustomerDetails.ShowDialogEx(this);
                        }
                    }

                    if (ProcessCancelled) // if the process cancelled from the customer then  back to the handpay screen
                    {
                        return;
                    }
                }

                List <AssetNumberResult> lstasset = handpay.GetAssetNumber((cmbBarPositions.SelectedItem as BarPositions).Installation_No);

                string Asset = lstasset[0].Stock_No;

                treasury = new Treasury {
                    InstallationNumber = (cmbBarPositions.SelectedItem as BarPositions).Installation_No
                };

                if (optHandpay.IsChecked == true)
                {
                    treasury.TreasuryType = "AttendantPay Credit";
                }
                else if (optJackpot.IsChecked == true)
                {
                    treasury.TreasuryType = "AttendantPay Jackpot";
                }
                else
                {
                    treasury.TreasuryType = "PROGRESSIVE";
                }
                treasury.TreasuryAmount     = amount;
                treasury.ActualTreasuryDate = DateTime.Now;

                // treasury.UserID = Security.SecurityHelper.CurrentUser.User_No;
                treasury.UserID = Auth_User_ID;


                treasury.Authorized_Date = DateTime.MinValue.DBMinValue();
                if (objAuthorize != null && objAuthorize.IsAuthorized)
                {
                    treasury.AuthorizedUser_No = Auth_User_ID;
                    treasury.Authorized_Date   = DateTime.Now;

                    //Audit for authorization
                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {
                        AuditModuleName    = ModuleName.ManualAttendantPay,
                        Audit_Screen_Name  = "PositionDetails|ManualAttendantPay",
                        Audit_Desc         = "Manual AttendantPay Type-" + treasury.TreasuryType,
                        AuditOperationType = OperationType.ADD,
                        Audit_Field        = "AuthorizedUser_No",
                        Audit_New_Vl       = Auth_User_ID.ToString(),
                        Audit_Slot         = Asset
                    });
                }

                treasury.CustomerID = Custid; // add the customer to the treasury if amt between 1000 & 4000 or >5000

                Treasury_No = handpay.ProcessHandPay(treasury, 0);


                IsProcessed = true;
                if (Treasury_No > 0)
                {
                    DateTime dtTreasury = (DateTime)handpay.GetTreasuryDateTime(Treasury_No);

                    TextBlock_11.Text = "#" + (cmbBarPositions.SelectedItem as BarPositions).Bar_Pos_Name + dtTreasury.ToString("ddMMyyyyHHmmss");
                    txtAmount.Text    = Convert.ToDecimal((treasury.TreasuryAmount)).GetUniversalCurrencyFormat();
                    #region GCD
                    if (Settings.IsGloryCDEnabled && Settings.CashDispenserEnabled)
                    {
                        LoadingWindow ld = new LoadingWindow(Window.GetWindow(this), ModuleName.ManualAttendantPay, Treasury_No.ToString(), (cmbBarPositions.SelectedItem as BarPositions).Bar_Pos_Name, Convert.ToInt32(treasury.TreasuryAmount * 100));
                        ld.Topmost = true;
                        ld.ShowDialogEx(this);
                        Result res = ld.Result;
                        if (res.IsSuccess && (Treasury_No > 0))
                        {
                            LogManager.WriteLog(string.Format("Cash Dispensed Successfully - Treasury Amount: {0:0.00}", treasury.TreasuryAmount), LogManager.enumLogLevel.Info);
                            LogManager.WriteLog("Export Manual AttendantPay Details to Enterprise", LogManager.enumLogLevel.Info);
                            handpay.ExportHandPay(Treasury_No);

                            BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);

                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {
                                AuditModuleName    = ModuleName.AttendantPay,
                                Audit_Screen_Name  = "PositionDetails|AttendantPay|Manual HandPay",
                                Audit_Desc         = "Manual HandPay Succeed",
                                AuditOperationType = OperationType.ADD,
                                Audit_Old_Vl       = "Ticket_ExceptionID:0 (Manual Handpay); TreasuryNo:" + Treasury_No + ";",
                            });
                        }
                        else
                        {
                            BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);
                            LogManager.WriteLog(string.Format("Unable to Dispense Cash - Treasury Amount: {0:0.00}", treasury.TreasuryAmount), LogManager.enumLogLevel.Info);
                            LogManager.WriteLog("Rollback Manual HandPay Process", LogManager.enumLogLevel.Info);
                            handpay.RollbackHandPay(0, Treasury_No);
                            MessageBox.ShowBox("MessageID117", BMC_Icon.Error);
                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {
                                AuditModuleName    = ModuleName.AttendantPay,
                                Audit_Screen_Name  = "PositionDetails|AttendantPay",
                                Audit_Desc         = treasury.TreasuryType + " processing was not completed.",
                                AuditOperationType = OperationType.ADD,
                                Audit_Slot         = Asset
                            });
                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {
                                AuditModuleName    = ModuleName.AttendantPay,
                                Audit_Screen_Name  = "PositionDetails|AttendantPay|Manual HandPay Process Failed",
                                Audit_Desc         = "Rollback HandPay Process Voucher due to cash dispenser error",
                                AuditOperationType = OperationType.MODIFY,
                                Audit_Old_Vl       = "Ticket_ExceptionID:0 (Manual Handpay); TreasuryNo:" + Treasury_No + ";"
                            });
                        }
                    }
                    else
                    {
                        this.ProcessCashDispense("Manual AttendantPay Type", treasury.TreasuryType, Convert.ToDecimal(amount));
                        MessageBox.ShowBox("MessageID116", BMC_Icon.Information);
                    }
                    #endregion

                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {
                        AuditModuleName    = ModuleName.ManualAttendantPay,
                        Audit_Screen_Name  = "PositionDetails|ManualAttendantPay",
                        Audit_Desc         = "Manual AttendantPay Type-" + treasury.TreasuryType,
                        AuditOperationType = OperationType.ADD,
                        Audit_Field        = "Amount",
                        Audit_New_Vl       = String.Format("{0:0.00}", treasury.TreasuryAmount),
                        Audit_Slot         = Asset
                    });

                    if (txtBox != null)
                    {
                        //txtBox.Text = "0.00";

                        txtBox.Text = this.DefaultAmount();
                        ucValueCalcComp.s_UnformattedText = "";
                    }

                    if (objAuthorize != null && objAuthorize.User != null)
                    {
                        (oCommonUtilities.CreateInstance()).PrintCommonReceipt(false, treasury.TreasuryType, Treasury_No.ToString(), objAuthorize.User);
                    }
                    else
                    {
                        (oCommonUtilities.CreateInstance()).PrintCommonReceipt(false, treasury.TreasuryType, Treasury_No.ToString());
                    }
                    if (((bool)optJackpot.IsChecked) || ((bool)optProgressive.IsChecked))// || ((bool)optHandpay.IsChecked))
                    {
                        treasury.Asset = Asset;
                        //string installationType = installationPathkey.GetValue("InstallationType").ToString();

                        //if (installationType.ToUpper().Equals("EXCHANGECLIENT"))
                        //{
                        //    if (Settings.SendPT10FromClient)
                        //        PostHandpayEvent(treasury);
                        //}
                        //else
                        PostHandpayEvent(treasury);
                    }
                }
                else
                {
                    if (optHandpay.IsChecked == true)
                    {
                        MessageBox.ShowBox("MessageID119", BMC_Icon.Error);
                    }
                    else if (optJackpot.IsChecked == true)
                    {
                        MessageBox.ShowBox("MessageID1191", BMC_Icon.Error);
                    }
                    else
                    {
                        MessageBox.ShowBox("MessageID1192", BMC_Icon.Error);
                    }


                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {
                        AuditModuleName   = ModuleName.ManualAttendantPay,
                        Audit_Screen_Name = "PositionDetails|ManualAttendantPay",

                        Audit_Desc         = "Manual AttendantPay Type-" + treasury.TreasuryType + " processing was not completed.",
                        AuditOperationType = OperationType.ADD,
                        Audit_Slot         = Asset
                    });
                }
            }
            catch (Exception Ex)
            {
                ExceptionManager.Publish(Ex);
                MessageBox.ShowBox("MessageID119", BMC_Icon.Error);

                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                {
                    AuditModuleName    = ModuleName.ManualAttendantPay,
                    Audit_Screen_Name  = "PositionDetails|ManualAttendantPay",
                    Audit_Desc         = "Manual AttendantPay Type-" + treasury.TreasuryType + " processing was not completed.",
                    AuditOperationType = OperationType.ADD,
                    Audit_Slot         = Asset
                });
            }
        }
Example #2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            bool isValid = false;
            RTOnlineTicketDetail objTicketDetail = null;

            double redeemTicketAmount = 0;

            bool IsCashDispenseError = false;

            try
            {
                if (isScannerFired) //check done not to fire the verify event twice while verifying a ticket using scanner
                {
                    isScannerFired = false;
                    return;
                }
                ClearAll(true);
                TextBlock_11.Text   = string.Empty;
                txtAmount.Text      = string.Empty;
                btnVerify.IsEnabled = false;
                if ((sender is System.Windows.Controls.TextBox))
                {
                    isScannerFired = true;
                }
                else
                {
                    isScannerFired = false;
                }

                if (this.ucValueCalc.txtDisplay.Text.Trim().Length > 0)
                {
                    if (this.ucValueCalc.txtDisplay.Text.Trim().Length < 4)
                    {
                        MessageBox.ShowBox("MessageID403", BMC_Icon.Error);
                        this.txtStatus.Visibility        = Visibility.Hidden;
                        this.ucValueCalc.txtDisplay.Text = String.Empty;
                        return;
                    }

                    IRedeemOnlineTicket objCashDeskOper = RedeemOnlineTicketBusinessObject.CreateInstance();
                    objTicketDetail = new RTOnlineTicketDetail();

                    objTicketDetail.ClientSiteCode  = Settings.SiteCode;
                    objTicketDetail.TicketString    = this.ucValueCalc.txtDisplay.Text.Trim();
                    objTicketDetail.HostSiteCode    = objTicketDetail.TicketString.Substring(0, 4);
                    objTicketDetail.RedeemedMachine = System.Environment.MachineName;

                    objTicketDetail = objCashDeskOper.GetRedeemTicketAmount(objTicketDetail);

                    if (objTicketDetail.TicketStatusCode == -990) //TIS Error (If any)
                    {
                        MessageBox.ShowBox(objTicketDetail.TicketErrorMessage, BMC_Icon.Error, true);
                        disptimerRedeem.Stop();
                        this.txtStatus.Visibility = Visibility.Hidden;
                        return;
                    }

                    if (objTicketDetail.TicketStatusCode == -234) //Exception Occured
                    {
                        MessageBox.ShowBox("MessageID425", BMC_Icon.Error);
                        disptimerRedeem.Stop();
                        this.txtStatus.Visibility = Visibility.Hidden;
                        return;
                    }

                    if (objTicketDetail.TicketStatusCode == -99) //Included for Cross Ticketing
                    {
                        MessageBox.ShowBox("MessageID403", BMC_Icon.Error);
                        disptimerRedeem.Stop();
                        this.txtStatus.Visibility        = Visibility.Hidden;
                        this.ucValueCalc.txtDisplay.Text = String.Empty;
                        return;
                    }



                    if (objTicketDetail.TicketStatusCode == 250)     //Any/specific player card required for TIS
                    {
                        bool ValidCard       = false;
                        int  PlayerCardClose = 0;



                        if (objTicketDetail.CardRequired == 2)
                        {
                            PlayerCardValidation objPlayerCardValidation = new PlayerCardValidation(objTicketDetail.CardRequired);
                            objPlayerCardValidation.ShowDialogEx(this);
                            ValidCard       = objPlayerCardValidation.valid;
                            PlayerCardClose = objPlayerCardValidation.Close;

                            if (PlayerCardClose == 1)
                            {
                                this.ucValueCalc.txtDisplay.Text = String.Empty;
                                this.ucValueCalc.txtDisplay.Focus();
                                return;
                            }

                            else if (!ValidCard)
                            {
                                MessageBox.ShowBox("PlayerCardRedeem6", BMC_Icon.Error);
                                this.ucValueCalc.txtDisplay.Text = String.Empty;
                                this.ucValueCalc.txtDisplay.Focus();
                                return;
                            }
                        }
                        else if (objTicketDetail.CardRequired == 1)
                        {
                            PlayerCardValidation objPlayerCardValidation = new PlayerCardValidation(objTicketDetail.CardRequired, objTicketDetail.PlayerCardNumber);
                            objPlayerCardValidation.ShowDialogEx(this);
                            ValidCard       = objPlayerCardValidation.valid;
                            PlayerCardClose = objPlayerCardValidation.Close;
                            if (PlayerCardClose == 1)
                            {
                                this.ucValueCalc.txtDisplay.Text = String.Empty;
                                this.ucValueCalc.txtDisplay.Focus();
                                return;
                            }
                            else if (!ValidCard)
                            {
                                MessageBox.ShowBox("PlayerCardRedeem6", BMC_Icon.Error);
                                this.ucValueCalc.txtDisplay.Text = String.Empty;
                                this.ucValueCalc.txtDisplay.Focus();
                                return;
                            }
                        }

                        objTicketDetail.TicketStatusCode = 0;
                    }


                    int ticketAmount = Convert.ToInt32(objTicketDetail.RedeemedAmount);

                    redeemTicketAmount = ticketAmount / 100;

                    objTicketDetail.CustomerId = Custid;

                    this.txtStatus.Visibility = Visibility.Visible;
                    this.txtStatus.Text       = "VALIDATING.";
                    disptimerRedeem.IsEnabled = true;
                    disptimerRedeem.Start();


                    //if ((objCashDeskOper.CheckSDGTicket(objTicketDetail.TicketString) == 0) && (Settings.RedeemConfirm))
                    if (objTicketDetail.TicketStatusCode == 0 && (Settings.RedeemConfirm))
                    {
                        disptimerRedeem.Stop();
                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                        {
                            _diagResult = MessageBox.ShowBox("MessageID225", BMC_Icon.Question, BMC_Button.YesNo);
                        }
                        else
                        {
                            _diagResult = System.Windows.Forms.DialogResult.Yes;
                        }
                        if (_diagResult == System.Windows.Forms.DialogResult.Yes)
                        {
                            #region ITALY CODE COMMENTED
                            //if (Settings.RegulatoryEnabled == true && Settings.RegulatoryType == "AAMS")
                            //{
                            //    ProcessCancelled = false;
                            //    if (ticketStatus == 0)
                            //    {
                            //        if (redeemTicketAmount >= Settings.RedeemTicketCustomer_Min && redeemTicketAmount <= Settings.RedeemTicketCustomer_Max)
                            //        {
                            //            customerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                            //            customerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            //            customerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            //            Owner = Window.GetWindow(this);
                            //            customerDetails.ShowDialog();
                            //        }
                            //        else if (redeemTicketAmount >= Settings.RedeemTicketCustomer_BankAcctNo)
                            //        {
                            //            customerDetails = new BMC.Presentation.POS.Views.CustomerDetails(true);
                            //            customerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            //            customerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            //            Owner = Window.GetWindow(this);
                            //            customerDetails.ShowDialog();
                            //        }

                            //        if (ProcessCancelled)
                            //        {
                            //            MessageBox.ShowBox("MessageID299", BMC_Icon.Information);
                            //            this.ucValueCalc.txtDisplay.Text = string.Empty;
                            //            return;
                            //        }
                            //    }
                            //}
                            #endregion

                            objTicketDetail = objCashDeskOper.RedeemOnlineTicket(objTicketDetail);
                            isValid         = objTicketDetail.ValidTicket;
                        }
                        else
                        {
                            disptimerRedeem.Start();
                            this.txtStatus.Visibility = Visibility.Hidden;
                            return;
                        }
                        disptimerRedeem.Start();
                    }
                    //else if ((objCashDeskOper.CheckSDGTicket(objTicketDetail.TicketString) == -3) && (Settings.RedeemConfirm)
                    else if (objTicketDetail.TicketStatusCode == -3 && (Settings.RedeemConfirm) && Settings.RedeemExpiredTicket)
                    {
                        disptimerRedeem.Stop();

                        CAuthorize objAuthorize = null;
                        //Manoj 26th Aug 2010. CR383384
                        //RedeemExpiredTicket functionality has been implmented for Winchells.
                        //So, in settings RedeemExpiredTicket will be True for Winchells, for rest it will be False.
                        //So we dont need the following if condition.
                        //if (Settings.Client != null && Settings.Client.ToLower() == "winchells")
                        //{
                        objAuthorize      = new CAuthorize("CashdeskOperator.Authorize.cs.ReedemExpiredTicket");
                        objAuthorize.User = Security.SecurityHelper.CurrentUser;
                        string Cur_User_Name = Security.SecurityHelper.CurrentUser.Last_Name + ", " + Security.SecurityHelper.CurrentUser.First_Name;
                        objTicketDetail.RedeemedUser = Cur_User_Name;

                        if (!Security.SecurityHelper.HasAccess("CashdeskOperator.Authorize.cs.ReedemExpiredTicket"))
                        {
                            objAuthorize.ShowDialogEx(this);

                            string Auth_User_Name = objAuthorize.User.UserName;
                            if (objAuthorize.User.Last_Name != null && objAuthorize.User.First_Name != null)
                            {
                                Auth_User_Name = objAuthorize.User.Last_Name + ", " + objAuthorize.User.First_Name;
                            }
                            else
                            {
                                Auth_User_Name = objAuthorize.User.UserName;
                            }

                            objTicketDetail.RedeemedUser = Auth_User_Name;

                            if (!objAuthorize.IsAuthorized)
                            {
                                ClearAll(false);
                                return;
                            }
                        }
                        else
                        {
                            objAuthorize.IsAuthorized = true;
                        }
                        //}

                        if (objAuthorize != null && objAuthorize.IsAuthorized)
                        {
                            objTicketDetail.AuthorizedUser_No = objAuthorize.User.SecurityUserID;
                            objTicketDetail.Authorized_Date   = DateTime.Now;

                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {
                                AuditModuleName    = ModuleName.Voucher,
                                Audit_Screen_Name  = "Vouchers|RedeemVoucher",
                                Audit_Desc         = "Voucher Number-" + objTicketDetail.TicketString,
                                AuditOperationType = OperationType.MODIFY,
                                Audit_Field        = "AuthorizedUser_No",
                                Audit_New_Vl       = Security.SecurityHelper.CurrentUser.SecurityUserID.ToString()
                            });
                        }
                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                        {
                            _diagResult = MessageBox.ShowBox("MessageID225", BMC_Icon.Question, BMC_Button.YesNo);
                        }
                        else
                        {
                            _diagResult = System.Windows.Forms.DialogResult.Yes;
                        }
                        if (_diagResult == System.Windows.Forms.DialogResult.Yes)
                        {
                            #region ITALY CODE COMMENTED
                            //if (Settings.RegulatoryEnabled == true && Settings.RegulatoryType == "AAMS")
                            //{
                            //    ProcessCancelled = false;
                            //    if (ticketStatus == 0)
                            //    {
                            //        if (redeemTicketAmount >= Settings.RedeemTicketCustomer_Min && redeemTicketAmount <= Settings.RedeemTicketCustomer_Max)
                            //        {
                            //            customerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                            //            customerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            //            customerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            //            Owner = Window.GetWindow(this);
                            //            customerDetails.ShowDialog();
                            //        }
                            //        else if (redeemTicketAmount >= Settings.RedeemTicketCustomer_BankAcctNo)
                            //        {
                            //            customerDetails = new BMC.Presentation.POS.Views.CustomerDetails(true);
                            //            customerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            //            customerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            //            Owner = Window.GetWindow(this);
                            //            customerDetails.ShowDialog();
                            //        }

                            //        if (ProcessCancelled)
                            //        {
                            //            MessageBox.ShowBox("MessageID299", BMC_Icon.Information);
                            //            this.ucValueCalc.txtDisplay.Text = string.Empty;
                            //            return;
                            //        }
                            //    }
                            //}

                            #endregion
                            objTicketDetail = objCashDeskOper.RedeemOnlineTicket(objTicketDetail);
                            isValid         = objTicketDetail.ValidTicket;
                        }
                        else
                        {
                            disptimerRedeem.Start();
                            this.txtStatus.Visibility = Visibility.Hidden;
                            return;
                        }
                        disptimerRedeem.Start();
                    }
                    else
                    {
                        objTicketDetail = objCashDeskOper.RedeemOnlineTicket(objTicketDetail);
                        isValid         = objTicketDetail.ValidTicket;
                    }

                    if (objTicketDetail.TicketStatus == "MessageID210")
                    {
                        objTicketDetail.TicketStatus = Application.Current.FindResource(objTicketDetail.TicketStatus).ToString() +
                                                       "(" + CommonUtilities.GetCurrency(Convert.ToDouble(objTicketDetail.TicketValue / 100)) + ")";
                    }
                    else
                    {
                        objTicketDetail.TicketStatus = Application.Current.FindResource(objTicketDetail.TicketStatus).ToString();
                    }

                    IsCashDispenseError = true;
                    if (isValid && objTicketDetail.RedeemedMachine != null && objTicketDetail.RedeemedMachine != string.Empty)
                    {
                        try
                        {
                            //DateTime PrintDate;
                            //string strbar_pos = objCashDeskOper.GetTicketPrintDevice(objTicketDetail.TicketString, out PrintDate);
                            DateTime PrintDate  = DateTime.Now;
                            string   strbar_pos = objCashDeskOper.GetTicketPrintDevice(objTicketDetail.TicketString, out PrintDate);
                            //TextBlock_11.Text = "#" + strbar_pos + PrintDate.ToString().Replace("/", "").Replace(":", "").Replace("AM", "0").Replace("PM", "1").Replace(" ", "");
                            //TextBlock_11.Text = "#" + objTicketDetail.PrintedDevice + objTicketDetail.PrintedDate.ToString().Replace("/", "").Replace(":", "").Replace("AM", "0").Replace("PM", "1").Replace(" ", "");
                            if (objTicketDetail.RedeemedDate == null || objTicketDetail.RedeemedDate.ToString().Trim().Equals(string.Empty))
                            {
                                TextBlock_11.Text = string.Empty;
                            }
                            else
                            {
                                TextBlock_11.Text = "#" + strbar_pos + objTicketDetail.RedeemedDate.ToString("ddMMyyyyHHmmss");
                            }

                            txtAmount.Text = objTicketDetail.RedeemedAmount.GetUniversalCurrencyFormat();
                            if (!objTicketDetail.TicketStatus.Trim().ToUpper().Equals("ALREADY CLAIMED"))
                            {
                                #region GCD
                                if (Settings.IsGloryCDEnabled && Settings.CashDispenserEnabled)
                                {
                                    LogManager.WriteLog(string.Format("Process Redeem Voucher: {2} for Bar Postion: {0} - Amount: {1} in cents", strbar_pos, ticketAmount, objTicketDetail.TicketString), LogManager.enumLogLevel.Info);

                                    //implement Cash Dispenser
                                    LogManager.WriteLog(string.Format("Amount: {0:0.00} Sending to Cash Dispenser ", ticketAmount), LogManager.enumLogLevel.Info);
                                    LoadingWindow ld = new LoadingWindow(Window.GetWindow(this), ModuleName.Voucher, TextBlock_11.Text, strbar_pos, ticketAmount);
                                    ld.Topmost = true;
                                    ld.ShowDialogEx(this);
                                    Result res = ld.Result;
                                    if (!res.IsSuccess)
                                    {
                                        IsCashDispenseError = false;
                                        this.txtStatus.Text = res.error.Message;
                                        LogManager.WriteLog(string.Format("Unable to Dispense Cash - Amount: {0}", ticketAmount), LogManager.enumLogLevel.Info);
                                        LogManager.WriteLog("Rollback Redeem Voucher Process", LogManager.enumLogLevel.Info);
                                        AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                        {
                                            AuditModuleName    = ModuleName.Voucher,
                                            Audit_Screen_Name  = "Vouchers|RedeemVoucher",
                                            Audit_Desc         = "Rollback redeem voucher:" + objTicketDetail.TicketString + " due to cash dispenser error",
                                            AuditOperationType = OperationType.MODIFY,
                                            Audit_Old_Vl       = "iPayDeviceid:" + objTicketDetail.RedeemedDevice + ";dtPaid:" + objTicketDetail.RedeemedDate.GetUniversalDateTimeFormat() + ";Customerid:" + objTicketDetail.CustomerId.ToString()
                                        });
                                        objCashDeskOper.RollbackRedeemTicket(objTicketDetail.TicketString);
                                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                                        {
                                            BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);
                                        }
                                    }
                                    else
                                    {
                                        LogManager.WriteLog(string.Format("Cash Dispensed Successfully - Amount: {0}", ticketAmount), LogManager.enumLogLevel.Info);

                                        IsCashDispenseError = true;
                                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                                        {
                                            BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);
                                        }
                                    }
                                }
                                #endregion
                            }
                        }
                        catch (Exception Ex)
                        {
                            LogManager.WriteLog("Error showing Voucher Info :" + Ex.Message, LogManager.enumLogLevel.Error);
                        }
                    }

                    if (objTicketDetail.ShowOfflineTicketScreen)
                    {
                        int result;

                        if (objTicketDetail.HostSiteCode == Settings.SiteCode) // Offline Tickets redemption is valid only for local site code
                        {
                            result = objCashDeskOper.CheckSDGOfflineTicket(objTicketDetail.TicketString);
                        }
                        else
                        {
                            result = -14;
                        }

                        if (result == -14)// Site Code Mismatch
                        {
                            this.txtStatus.Visibility = Visibility.Visible;
                            this.txtStatus.Text       = Application.Current.FindResource("MessageID312") as string;
                            this.txtStatus.Background = System.Windows.Media.Brushes.Red;
                            return;
                        }
                        else
                        {
                            frmRedeemOffline = new BMC.Presentation.POS.Views.CRedeemOfflineTicket();
                            frmRedeemOffline.TicketNumber = ucValueCalc.txtDisplay.Text.Trim();
                            frmRedeemOffline.ShowDialogEx(this);
                            if (frmRedeemOffline.IsSuccessfull)
                            {
                                this.ucValueCalc.txtDisplay.Text = frmRedeemOffline.TicketNumber;
                                button_Click(sender, e);
                            }
                            else
                            {
                                this.ucValueCalc.txtDisplay.Text = string.Empty;
                                this.txtStatus.Clear();
                            }
                        }
                    }
                    else
                    {
                        if (Settings.IsGloryCDEnabled && (!IsCashDispenseError))
                        {
                            disptimerRedeem.Stop();
                            this.txtStatus.Visibility = Visibility.Visible;
                            this.txtStatus.Background = System.Windows.Media.Brushes.Red;
                            TextBlock_11.Text         = string.Empty;
                            txtAmount.Text            = string.Empty;
                            System.Threading.Thread.Sleep(100);
                            //System.Threading.Thread.CurrentThread
                            disptimerRedeem.Start();
                        }
                        else
                        {
                            this.txtStatus.Text = objTicketDetail.TicketStatus;
                            //"(" + CommonUtilities.GetCurrency(Convert.ToDouble(TicketDetail.TicketValue / 100)) + ")";
                            if (Application.Current.FindResource("MessageID219").ToString() == objTicketDetail.TicketStatus)
                            {
                                bisTicketExpired = true;
                            }
                            this.txtWarning.Text = objTicketDetail.TicketWarning;
                            if (!objTicketDetail.ValidTicket)
                            {
                                this.txtStatus.Background = System.Windows.Media.Brushes.Red;

                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {
                                    AuditModuleName    = ModuleName.Voucher,
                                    Audit_Screen_Name  = "Vouchers|RedeemVoucher",
                                    Audit_Desc         = "Invalid Voucher Redemption Attempt",
                                    AuditOperationType = OperationType.MODIFY,
                                    Audit_Field        = "Voucher Number",
                                    Audit_New_Vl       = objTicketDetail.TicketString
                                });
                            }
                            else
                            {
                                this.txtStatus.Background = System.Windows.Media.Brushes.White;

                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {
                                    AuditModuleName    = ModuleName.Voucher,
                                    Audit_Screen_Name  = "Vouchers|RedeemVoucher",
                                    Audit_Desc         = "Voucher Number-" + objTicketDetail.TicketString,
                                    AuditOperationType = OperationType.ADD,
                                    Audit_Field        = "Voucher Status",
                                    Audit_New_Vl       = objTicketDetail.TicketStatus
                                });

                                //Cross Ticketing- Insert Local Record
                                if (!string.IsNullOrEmpty(objTicketDetail.VoucherXMLData))
                                {
                                    objTicketDetail.RedeemedUser = Security.SecurityHelper.CurrentUser.UserName;
                                    objCashDeskOper.ImportVoucherDetails(objTicketDetail);
                                }

                                if (objTicketDetail.TicketStatus.Contains(Application.Current.FindResource("MessageID210").ToString()))
                                {
                                    //disptimerRedeem.Stop();

                                    Action act = new Action(() =>
                                    {
                                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                                        {
                                            if (IsCashDispenseError)
                                            {
                                                if (Settings.IsGloryCDEnabled)
                                                {
                                                    disptimerRedeem.Stop();
                                                    this.txtStatus.Visibility = Visibility.Visible;
                                                }
                                                else
                                                {
                                                    this.ClearAll(false);
                                                }
                                                MessageBox.ShowBox("MessageID377", BMC_Icon.Information);
                                            }
                                        }
                                        else
                                        {
                                            this.txtStatus.Text       = Application.Current.FindResource("MessageID377").ToString();
                                            txtAmount.Text            = Convert.ToDecimal(objTicketDetail.TicketValue / 100).GetUniversalCurrencyFormat();
                                            bisTicketExpired          = false;
                                            this.txtStatus.Background = System.Windows.Media.Brushes.GreenYellow;
                                        }
                                        if (!Settings.IsGloryCDEnabled)
                                        {
                                            this.dispenserStatus.LoadItemsAysnc();
                                        }
                                    });

                                    if (!Settings.IsGloryCDEnabled)
                                    {
                                        _worker.Dispense("Voucher Number", objTicketDetail.TicketString, objTicketDetail.RedeemedAmount, act);
                                    }
                                    else
                                    {
                                        act();
                                        disptimerRedeem.Start();
                                    }
                                }
                            }
                            if (objTicketDetail.EnableTickerPrintDetails)
                            {
                                this.gridRedeemedTicket.Visibility = Visibility.Visible;
                                this.txtPrintedMachine.Text        = objTicketDetail.RedeemedMachine;
                                this.txtClaimedDevice.Text         = objTicketDetail.RedeemedDevice;
                                this.txtTickAmount.Text            = objTicketDetail.RedeemedAmount.GetUniversalCurrencyFormatWithSymbol();
                                this.txtClaimedDate.Text           = objTicketDetail.RedeemedDate.GetUniversalDateTimeFormat();
                            }
                            else
                            {
                                this.gridRedeemedTicket.Visibility = Visibility.Hidden;
                            }
                            this.ucValueCalc.txtDisplay.Focus();
                        }
                    }
                }
                else
                {
                    MessageBox.ShowBox("MessageID105", BMC_Icon.Warning);
                    this.ucValueCalc.txtDisplay.Focus();
                }
            }
            catch (Exception ex)
            {
                BMC.Common.ExceptionManagement.ExceptionManager.Publish(ex);
            }
            finally
            {
                btnVerify.IsEnabled = true;
            }
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            bool isValid = false;
            RTOnlineTicketDetail objTicketDetail = null;
           
            double redeemTicketAmount = 0;

            bool IsCashDispenseError = false;
            try
            {

                if (isScannerFired) //check done not to fire the verify event twice while verifying a ticket using scanner
                {
                    isScannerFired = false;
                    return;
                }
                ClearAll(true);
                TextBlock_11.Text = string.Empty;
                txtAmount.Text = string.Empty;               
                btnVerify.IsEnabled = false;
                if ((sender is System.Windows.Controls.TextBox))
                    isScannerFired = true;
                else
                    isScannerFired = false;

                if (this.ucValueCalc.txtDisplay.Text.Trim().Length > 0)
                {
                    if (this.ucValueCalc.txtDisplay.Text.Trim().Length < 4 )
                    {
                        MessageBox.ShowBox("MessageID403", BMC_Icon.Error);
                        this.txtStatus.Visibility = Visibility.Hidden;
                        this.ucValueCalc.txtDisplay.Text = String.Empty;
                        return;
                    }

                    IRedeemOnlineTicket objCashDeskOper = RedeemOnlineTicketBusinessObject.CreateInstance();
                    objTicketDetail = new RTOnlineTicketDetail();

                    objTicketDetail.ClientSiteCode = Settings.SiteCode;
                    objTicketDetail.TicketString = this.ucValueCalc.txtDisplay.Text.Trim();
                    objTicketDetail.HostSiteCode = objTicketDetail.TicketString.Substring(0, 4);
                    objTicketDetail.RedeemedMachine = System.Environment.MachineName;

                    objTicketDetail = objCashDeskOper.GetRedeemTicketAmount(objTicketDetail);

                    if (objTicketDetail.TicketStatusCode == -990) //TIS Error (If any)
                    {
                        MessageBox.ShowBox(objTicketDetail.TicketErrorMessage, BMC_Icon.Error, true);
                        disptimerRedeem.Stop();
                        this.txtStatus.Visibility = Visibility.Hidden;
                        return;
                    }

                    if (objTicketDetail.TicketStatusCode == -234) //Exception Occured
                    {
                        MessageBox.ShowBox("MessageID425", BMC_Icon.Error);
                        disptimerRedeem.Stop();
                        this.txtStatus.Visibility = Visibility.Hidden;
                        return;
                    }

                    if (objTicketDetail.TicketStatusCode == -99) //Included for Cross Ticketing
                    {
                        MessageBox.ShowBox("MessageID403", BMC_Icon.Error);
                        disptimerRedeem.Stop();
                        this.txtStatus.Visibility = Visibility.Hidden;
                        this.ucValueCalc.txtDisplay.Text = String.Empty;
                        return;
                    }

                   
                   
                        if (objTicketDetail.TicketStatusCode == 250) //Any/specific player card required for TIS
                        {
                            bool ValidCard = false;
                            int PlayerCardClose = 0;
                            


                            if (objTicketDetail.CardRequired == 2)
                            {
                                PlayerCardValidation objPlayerCardValidation = new PlayerCardValidation(objTicketDetail.CardRequired);
                                objPlayerCardValidation.ShowDialogEx(this);
                                ValidCard = objPlayerCardValidation.valid;
                                PlayerCardClose = objPlayerCardValidation.Close;

                                if (PlayerCardClose == 1)
                                {
                                    this.ucValueCalc.txtDisplay.Text = String.Empty;
                                    this.ucValueCalc.txtDisplay.Focus();
                                    return;
                                }

                                else if (!ValidCard)
                                {
                                    MessageBox.ShowBox("PlayerCardRedeem6", BMC_Icon.Error);
                                    this.ucValueCalc.txtDisplay.Text = String.Empty;
                                    this.ucValueCalc.txtDisplay.Focus();
                                    return;
                                }

                            }
                            else if (objTicketDetail.CardRequired == 1)
                            {
                                PlayerCardValidation objPlayerCardValidation = new PlayerCardValidation(objTicketDetail.CardRequired, objTicketDetail.PlayerCardNumber);
                                objPlayerCardValidation.ShowDialogEx(this);
                                ValidCard = objPlayerCardValidation.valid;
                                PlayerCardClose = objPlayerCardValidation.Close;
                                if (PlayerCardClose == 1)
                                {
                                    this.ucValueCalc.txtDisplay.Text = String.Empty;
                                    this.ucValueCalc.txtDisplay.Focus();
                                    return;
                                }
                                else if (!ValidCard)
                                {
                                    MessageBox.ShowBox("PlayerCardRedeem6", BMC_Icon.Error);
                                    this.ucValueCalc.txtDisplay.Text = String.Empty;
                                    this.ucValueCalc.txtDisplay.Focus();
                                    return;
                                }
                            }

                            objTicketDetail.TicketStatusCode = 0;
                        }
                    

                    int ticketAmount = Convert.ToInt32(objTicketDetail.RedeemedAmount);

                    redeemTicketAmount = ticketAmount / 100;

                    objTicketDetail.CustomerId = Custid;

                    this.txtStatus.Visibility = Visibility.Visible;
                    this.txtStatus.Text = "VALIDATING.";
                    disptimerRedeem.IsEnabled = true;
                    disptimerRedeem.Start();


                    //if ((objCashDeskOper.CheckSDGTicket(objTicketDetail.TicketString) == 0) && (Settings.RedeemConfirm))
                    if (objTicketDetail.TicketStatusCode == 0 && (Settings.RedeemConfirm))
                    {
                        disptimerRedeem.Stop();
                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                        {
                            _diagResult = MessageBox.ShowBox("MessageID225", BMC_Icon.Question, BMC_Button.YesNo);
                        }
                        else
                        {
                            _diagResult = System.Windows.Forms.DialogResult.Yes;
                        }
                        if (_diagResult == System.Windows.Forms.DialogResult.Yes)
                        {
                            #region ITALY CODE COMMENTED
                            //if (Settings.RegulatoryEnabled == true && Settings.RegulatoryType == "AAMS")
                            //{
                            //    ProcessCancelled = false;
                            //    if (ticketStatus == 0)
                            //    {
                            //        if (redeemTicketAmount >= Settings.RedeemTicketCustomer_Min && redeemTicketAmount <= Settings.RedeemTicketCustomer_Max)
                            //        {
                            //            customerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                            //            customerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            //            customerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            //            Owner = Window.GetWindow(this);
                            //            customerDetails.ShowDialog();
                            //        }
                            //        else if (redeemTicketAmount >= Settings.RedeemTicketCustomer_BankAcctNo)
                            //        {
                            //            customerDetails = new BMC.Presentation.POS.Views.CustomerDetails(true);
                            //            customerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            //            customerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            //            Owner = Window.GetWindow(this);
                            //            customerDetails.ShowDialog();
                            //        }

                            //        if (ProcessCancelled)
                            //        {
                            //            MessageBox.ShowBox("MessageID299", BMC_Icon.Information);
                            //            this.ucValueCalc.txtDisplay.Text = string.Empty;
                            //            return;
                            //        }
                            //    }
                            //} 
                            #endregion

                            objTicketDetail = objCashDeskOper.RedeemOnlineTicket(objTicketDetail);
                            isValid = objTicketDetail.ValidTicket;
                        }
                        else
                        {
                            disptimerRedeem.Start();
                            this.txtStatus.Visibility = Visibility.Hidden;
                            return;
                        }
                        disptimerRedeem.Start();
                    }
                    //else if ((objCashDeskOper.CheckSDGTicket(objTicketDetail.TicketString) == -3) && (Settings.RedeemConfirm)
                    else if (objTicketDetail.TicketStatusCode == -3 && (Settings.RedeemConfirm) && Settings.RedeemExpiredTicket)
                    {
                        disptimerRedeem.Stop();

                        CAuthorize objAuthorize = null;
                        //Manoj 26th Aug 2010. CR383384
                        //RedeemExpiredTicket functionality has been implmented for Winchells.
                        //So, in settings RedeemExpiredTicket will be True for Winchells, for rest it will be False.
                        //So we dont need the following if condition.
                        //if (Settings.Client != null && Settings.Client.ToLower() == "winchells")
                        //{
                        objAuthorize = new CAuthorize("CashdeskOperator.Authorize.cs.ReedemExpiredTicket");
                        objAuthorize.User = Security.SecurityHelper.CurrentUser;
                        string Cur_User_Name = Security.SecurityHelper.CurrentUser.Last_Name + ", " + Security.SecurityHelper.CurrentUser.First_Name;
                        objTicketDetail.RedeemedUser = Cur_User_Name;
                        
                        if (!Security.SecurityHelper.HasAccess("CashdeskOperator.Authorize.cs.ReedemExpiredTicket"))
                        {
                            objAuthorize.ShowDialogEx(this);
                            
                            string Auth_User_Name = objAuthorize.User.UserName;
                            if (objAuthorize.User.Last_Name != null && objAuthorize.User.First_Name != null)
                            {
                                Auth_User_Name = objAuthorize.User.Last_Name + ", " + objAuthorize.User.First_Name;
                            }
                            else
                            {
                                Auth_User_Name = objAuthorize.User.UserName;
                            }

                            objTicketDetail.RedeemedUser = Auth_User_Name;
                            
                            if (!objAuthorize.IsAuthorized)
                            {
                                ClearAll(false);
                                return;
                            }
                        }
                        else
                        {
                            objAuthorize.IsAuthorized = true;
                        }
                        //}

                        if (objAuthorize != null && objAuthorize.IsAuthorized)
                        {
                            objTicketDetail.AuthorizedUser_No = objAuthorize.User.SecurityUserID;
                            objTicketDetail.Authorized_Date = DateTime.Now;

                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {

                                AuditModuleName = ModuleName.Voucher,
                                Audit_Screen_Name = "Vouchers|RedeemVoucher",
                                Audit_Desc = "Voucher Number-" + objTicketDetail.TicketString,
                                AuditOperationType = OperationType.MODIFY,
                                Audit_Field = "AuthorizedUser_No",
                                Audit_New_Vl = Security.SecurityHelper.CurrentUser.SecurityUserID.ToString()
                            });

                        }
                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                        {
                            _diagResult = MessageBox.ShowBox("MessageID225", BMC_Icon.Question, BMC_Button.YesNo);
                        }
                        else
                        {
                            _diagResult = System.Windows.Forms.DialogResult.Yes;
                        }
                        if (_diagResult == System.Windows.Forms.DialogResult.Yes)
                        {
                            #region ITALY CODE COMMENTED
                            //if (Settings.RegulatoryEnabled == true && Settings.RegulatoryType == "AAMS")
                            //{
                            //    ProcessCancelled = false;
                            //    if (ticketStatus == 0)
                            //    {
                            //        if (redeemTicketAmount >= Settings.RedeemTicketCustomer_Min && redeemTicketAmount <= Settings.RedeemTicketCustomer_Max)
                            //        {
                            //            customerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                            //            customerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            //            customerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            //            Owner = Window.GetWindow(this);
                            //            customerDetails.ShowDialog();
                            //        }
                            //        else if (redeemTicketAmount >= Settings.RedeemTicketCustomer_BankAcctNo)
                            //        {
                            //            customerDetails = new BMC.Presentation.POS.Views.CustomerDetails(true);
                            //            customerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            //            customerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            //            Owner = Window.GetWindow(this);
                            //            customerDetails.ShowDialog();
                            //        }

                            //        if (ProcessCancelled)
                            //        {
                            //            MessageBox.ShowBox("MessageID299", BMC_Icon.Information);
                            //            this.ucValueCalc.txtDisplay.Text = string.Empty;
                            //            return;
                            //        }
                            //    }
                            //}

                            #endregion
                            objTicketDetail = objCashDeskOper.RedeemOnlineTicket(objTicketDetail);
                            isValid = objTicketDetail.ValidTicket;
                        }
                        else
                        {
                            disptimerRedeem.Start();
                            this.txtStatus.Visibility = Visibility.Hidden;
                            return;
                        }
                        disptimerRedeem.Start();
                    }
                    else
                    {
                        objTicketDetail = objCashDeskOper.RedeemOnlineTicket(objTicketDetail);
                        isValid = objTicketDetail.ValidTicket;
                    }

                    if (objTicketDetail.TicketStatus == "MessageID210")
                        objTicketDetail.TicketStatus = Application.Current.FindResource(objTicketDetail.TicketStatus).ToString() +
                            "(" + CommonUtilities.GetCurrency(Convert.ToDouble(objTicketDetail.TicketValue / 100)) + ")";
                    else
                        objTicketDetail.TicketStatus = Application.Current.FindResource(objTicketDetail.TicketStatus).ToString();

                    IsCashDispenseError = true;
                    if (isValid && objTicketDetail.RedeemedMachine != null && objTicketDetail.RedeemedMachine != string.Empty)
                    {
                        try
                        {
                            //DateTime PrintDate;
                            //string strbar_pos = objCashDeskOper.GetTicketPrintDevice(objTicketDetail.TicketString, out PrintDate);
                            DateTime PrintDate = DateTime.Now;
                            string strbar_pos = objCashDeskOper.GetTicketPrintDevice(objTicketDetail.TicketString, out PrintDate);
                            //TextBlock_11.Text = "#" + strbar_pos + PrintDate.ToString().Replace("/", "").Replace(":", "").Replace("AM", "0").Replace("PM", "1").Replace(" ", "");
                            //TextBlock_11.Text = "#" + objTicketDetail.PrintedDevice + objTicketDetail.PrintedDate.ToString().Replace("/", "").Replace(":", "").Replace("AM", "0").Replace("PM", "1").Replace(" ", "");
                            if (objTicketDetail.RedeemedDate == null || objTicketDetail.RedeemedDate.ToString().Trim().Equals(string.Empty))
                            {
                                TextBlock_11.Text = string.Empty;
                            }
                            else
                            {
                                TextBlock_11.Text = "#" + strbar_pos + objTicketDetail.RedeemedDate.ToString("ddMMyyyyHHmmss");
                            }

                            txtAmount.Text = objTicketDetail.RedeemedAmount.GetUniversalCurrencyFormat();
                            if (!objTicketDetail.TicketStatus.Trim().ToUpper().Equals("ALREADY CLAIMED"))
                            {
                                #region GCD
                                if (Settings.IsGloryCDEnabled && Settings.CashDispenserEnabled)
                                {
                                    LogManager.WriteLog(string.Format("Process Redeem Voucher: {2} for Bar Postion: {0} - Amount: {1} in cents", strbar_pos, ticketAmount, objTicketDetail.TicketString), LogManager.enumLogLevel.Info);

                                    //implement Cash Dispenser
                                    LogManager.WriteLog(string.Format("Amount: {0:0.00} Sending to Cash Dispenser ", ticketAmount), LogManager.enumLogLevel.Info);
                                    LoadingWindow ld = new LoadingWindow(Window.GetWindow(this), ModuleName.Voucher, TextBlock_11.Text , strbar_pos, ticketAmount);
                                    ld.Topmost = true;
                                    ld.ShowDialogEx(this);
                                    Result res = ld.Result;
                                    if (!res.IsSuccess)
                                    {
                                        IsCashDispenseError = false;
                                        this.txtStatus.Text = res.error.Message;
                                        LogManager.WriteLog(string.Format("Unable to Dispense Cash - Amount: {0}", ticketAmount), LogManager.enumLogLevel.Info);
                                        LogManager.WriteLog("Rollback Redeem Voucher Process", LogManager.enumLogLevel.Info);
                                        AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                        {
                                            AuditModuleName = ModuleName.Voucher,
                                            Audit_Screen_Name = "Vouchers|RedeemVoucher",
                                            Audit_Desc = "Rollback redeem voucher:" + objTicketDetail.TicketString + " due to cash dispenser error",
                                            AuditOperationType = OperationType.MODIFY,
                                            Audit_Old_Vl = "iPayDeviceid:" + objTicketDetail.RedeemedDevice + ";dtPaid:" + objTicketDetail.RedeemedDate.GetUniversalDateTimeFormat() + ";Customerid:" + objTicketDetail.CustomerId.ToString()
                                        });
                                        objCashDeskOper.RollbackRedeemTicket(objTicketDetail.TicketString);
                                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                                        {
                                            BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);
                                        }
                                    }
                                    else
                                    {
                                        LogManager.WriteLog(string.Format("Cash Dispensed Successfully - Amount: {0}", ticketAmount), LogManager.enumLogLevel.Info);

                                        IsCashDispenseError = true;
                                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                                        {
                                            BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);
                                        }

                                    }
                                }
                                #endregion
                            }

                        }
                        catch (Exception Ex)
                        {
                            LogManager.WriteLog("Error showing Voucher Info :" + Ex.Message, LogManager.enumLogLevel.Error);
                        }
                    }

                    if (objTicketDetail.ShowOfflineTicketScreen)
                    {
                        int result;

                        if (objTicketDetail.HostSiteCode == Settings.SiteCode) // Offline Tickets redemption is valid only for local site code
                            result = objCashDeskOper.CheckSDGOfflineTicket(objTicketDetail.TicketString);
                        else
                            result = -14;

                        if (result == -14)// Site Code Mismatch
                        {
                            this.txtStatus.Visibility = Visibility.Visible;
                            this.txtStatus.Text = Application.Current.FindResource("MessageID312") as string;
                            this.txtStatus.Background = System.Windows.Media.Brushes.Red;
                            return;
                        }
                        else
                        {
                            frmRedeemOffline = new BMC.Presentation.POS.Views.CRedeemOfflineTicket();
                            frmRedeemOffline.TicketNumber = ucValueCalc.txtDisplay.Text.Trim();
                            frmRedeemOffline.ShowDialogEx(this);
                            if(frmRedeemOffline.IsSuccessfull)
                            {
                                this.ucValueCalc.txtDisplay.Text = frmRedeemOffline.TicketNumber;
                                button_Click(sender, e);
                            }
                            else
                            {
                                this.ucValueCalc.txtDisplay.Text = string.Empty;
                                this.txtStatus.Clear();
                            }
                        }
                    }
                    else
                    {
                        if (Settings.IsGloryCDEnabled && (!IsCashDispenseError))
                        {
                            disptimerRedeem.Stop();
                            this.txtStatus.Visibility = Visibility.Visible;
                            this.txtStatus.Background = System.Windows.Media.Brushes.Red;
                            TextBlock_11.Text = string.Empty;
                            txtAmount.Text = string.Empty;
                            System.Threading.Thread.Sleep(100);
                            //System.Threading.Thread.CurrentThread
                            disptimerRedeem.Start();
                        }
                        else
                        {
                            this.txtStatus.Text = objTicketDetail.TicketStatus;
                            //"(" + CommonUtilities.GetCurrency(Convert.ToDouble(TicketDetail.TicketValue / 100)) + ")";
                            if (Application.Current.FindResource("MessageID219").ToString() == objTicketDetail.TicketStatus)
                            {
                                bisTicketExpired = true;
                            }
                            this.txtWarning.Text = objTicketDetail.TicketWarning;
                            if (!objTicketDetail.ValidTicket)
                            {
                                this.txtStatus.Background = System.Windows.Media.Brushes.Red;

                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {

                                    AuditModuleName = ModuleName.Voucher,
                                    Audit_Screen_Name = "Vouchers|RedeemVoucher",
                                    Audit_Desc = "Invalid Voucher Redemption Attempt",
                                    AuditOperationType = OperationType.MODIFY,
                                    Audit_Field = "Voucher Number",
                                    Audit_New_Vl = objTicketDetail.TicketString
                                });

                            }
                            else
                            {
                                this.txtStatus.Background = System.Windows.Media.Brushes.White;

                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {

                                    AuditModuleName = ModuleName.Voucher,
                                    Audit_Screen_Name = "Vouchers|RedeemVoucher",
                                    Audit_Desc = "Voucher Number-" + objTicketDetail.TicketString,
                                    AuditOperationType = OperationType.ADD,
                                    Audit_Field = "Voucher Status",
                                    Audit_New_Vl = objTicketDetail.TicketStatus
                                });

                                //Cross Ticketing- Insert Local Record 
                                if (!string.IsNullOrEmpty(objTicketDetail.VoucherXMLData))
                                {
                                    objTicketDetail.RedeemedUser = Security.SecurityHelper.CurrentUser.UserName;
                                    objCashDeskOper.ImportVoucherDetails(objTicketDetail);
                                }

                                if (objTicketDetail.TicketStatus.Contains(Application.Current.FindResource("MessageID210").ToString()))
                                {
                                    //disptimerRedeem.Stop();

                                    Action act = new Action(() =>
                                    {
                                        if (Convert.ToBoolean(AppSettings.REDEEM_TICKET_POP_UP_ALERT_VISIBILITY))
                                        {
                                            if (IsCashDispenseError)
                                            {
                                                if (Settings.IsGloryCDEnabled)
                                                {
                                                    disptimerRedeem.Stop();
                                                    this.txtStatus.Visibility = Visibility.Visible;
                                                }
                                                else
                                                {
                                                    this.ClearAll(false);
                                                }
                                                MessageBox.ShowBox("MessageID377", BMC_Icon.Information);
                                            }


                                        }
                                        else
                                        {
                                            this.txtStatus.Text = Application.Current.FindResource("MessageID377").ToString();
                                            txtAmount.Text = Convert.ToDecimal(objTicketDetail.TicketValue / 100).GetUniversalCurrencyFormat();
                                            bisTicketExpired = false;
                                            this.txtStatus.Background = System.Windows.Media.Brushes.GreenYellow;
                                        }
                                        if (!Settings.IsGloryCDEnabled)
                                        {
                                            this.dispenserStatus.LoadItemsAysnc();
                                        }
                                    });

                                    if (!Settings.IsGloryCDEnabled)
                                    {
                                        _worker.Dispense("Voucher Number", objTicketDetail.TicketString, objTicketDetail.RedeemedAmount, act);

                                    }
                                    else
                                    {
                                        act();
                                        disptimerRedeem.Start();
                                    }

                                }
                            }
                            if (objTicketDetail.EnableTickerPrintDetails)
                            {
                                this.gridRedeemedTicket.Visibility = Visibility.Visible;
                                this.txtPrintedMachine.Text = objTicketDetail.RedeemedMachine;
                                this.txtClaimedDevice.Text = objTicketDetail.RedeemedDevice;
                                this.txtTickAmount.Text = objTicketDetail.RedeemedAmount.GetUniversalCurrencyFormatWithSymbol();
                                this.txtClaimedDate.Text = objTicketDetail.RedeemedDate.GetUniversalDateTimeFormat();
                            }
                            else
                            {
                                this.gridRedeemedTicket.Visibility = Visibility.Hidden;
                            }
                            this.ucValueCalc.txtDisplay.Focus();
                        }
                    }
                }
                else
                {
                    MessageBox.ShowBox("MessageID105", BMC_Icon.Warning);
                    this.ucValueCalc.txtDisplay.Focus();
                }
            }
            catch (Exception ex)
            {
                BMC.Common.ExceptionManagement.ExceptionManager.Publish(ex);
            }
            finally
            {
                btnVerify.IsEnabled = true;
            }
        }
        private void btnPerformSpotCheck_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!CheckMachineSelected()) return;
                this.IsEnabled = false;
                
                Installations objInstallationDetails = tvMachineList.SelectedItem as Installations;
                if (objInstallationDetails == null) return;

                int iLstIndx = -1;
                iLstIndx = (from SpotCheck objSpotCheck in lstSpotCheckSummaryDetails
                            where objSpotCheck.InstallationNo == objInstallationDetails.Installation_No
                            select lstSpotCheckSummaryDetails.LastIndexOf(objSpotCheck)).DefaultIfEmpty(-1).FirstOrDefault();

                Action doAnalysis = () =>
                {
                    if (iLstIndx >= 0)
                    {
                        lstSpotCheckSummaryDetails.RemoveAt(iLstIndx);
                    }
                        lstSpotCheckSummaryDetails.Add(oSpotCheckConfiguration.GetSpotCheckSummaryDetails(objInstallationDetails.Installation_No, objInstallationDetails.POP)[0]);
                };

                List<int> lstInatallation = new List<int>();
                lstInatallation.Add(objInstallationDetails.Installation_No);
                LoadingWindow ld_analysis = new LoadingWindow(this, ModuleName.SpotCheck, lstInatallation, doAnalysis);
                ld_analysis.ShowDialog();

                AfterProcessCompleted();
                //txtblkMessage.Text = (Application.Current.FindResource("MessageID504") as string).Replace("@@@@@@", objInstallationDetails.Bar_Position_Name);
            }

            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                //txtblkMessage.Text = Application.Current.FindResource("MessageID505") as string;
            }

            finally
            {
                this.IsEnabled = true;
            }
        }
        private void SaveManualHandpay()
        {
            if (cmbBarPositions.SelectedIndex <= 0)
                return;
            Window Owner;
            double amount = 0;
            int Auth_User_ID = 0;
            try
            {
                CAuthorize objAuthorize = null;

                if (txtBox != null && txtBox.Text.Length > 0)
                {
                    // Issue fix for ->set cultureinfo='en-US',  currencyculture='it-IT'
                    double.TryParse(txtBox.Text.ToString(), NumberStyles.Currency, new CultureInfo(ExtensionMethods.CurrentCurrenyCulture), out amount);
                }
                Auth_User_ID = Security.SecurityHelper.CurrentUser.User_No;
                if (Settings.Client != null && Settings.Client.ToLower() == "winchells"
                    && Settings.MaxHandPayAuthRequired
                    && txtBox != null
                    && (amount > Settings.HandpayPayoutCustomer_Max))
                {
                    objAuthorize = new CAuthorize("CashdeskOperator.Authorize.cs.MaxHandpay");
                   Auth_User_ID = Security.SecurityHelper.CurrentUser.User_No;
                    if (!Security.SecurityHelper.HasAccess("CashdeskOperator.Authorize.cs.MaxHandpay"))
                    {
                        objAuthorize.ShowDialogEx(this);
                        if (!objAuthorize.IsAuthorized)
                        {
                            IsProcessed = true;
                            return;
                        }
                        else
                        {
                            Auth_User_ID = handpay.GetUserID(objAuthorize.User.SecurityUserID);
                        }
                    }
                    else
                    {
                       objAuthorize.IsAuthorized = true;
                    }
                }

                if (Settings.RegulatoryEnabled == true && Settings.RegulatoryType == "AAMS")
                {
                    if (txtBox != null)
                    {
                        Custid = 0;
                        ProcessCancelled = false;
                        if (amount >= Settings.HandpayPayoutCustomer_Min && amount <= Settings.HandpayPayoutCustomer_Max)
                        {
                            oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                            oCustomerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            Owner = Window.GetWindow(this);
                            oCustomerDetails.ShowDialogEx(this);
                        }
                        else if (amount >= Settings.HandpayPayoutCustomer_BankAccNo)
                        {
                            oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails(true);
                            oCustomerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            Owner = Window.GetWindow(this);
                            oCustomerDetails.ShowDialogEx(this);
                        }
                        else if (amount >= Settings.HandpayPayoutCustomer_Max && amount <= Settings.HandpayPayoutCustomer_BankAccNo)
                        {
                            oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                            oCustomerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                            oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                            Owner = Window.GetWindow(this);
                            oCustomerDetails.ShowDialogEx(this);
                        }
                    }

                    if (ProcessCancelled) // if the process cancelled from the customer then  back to the handpay screen
                        return;
                }

                List<AssetNumberResult> lstasset = handpay.GetAssetNumber((cmbBarPositions.SelectedItem as BarPositions).Installation_No);

                string Asset = lstasset[0].Stock_No;

                treasury = new Treasury { InstallationNumber = (cmbBarPositions.SelectedItem as BarPositions).Installation_No };

                if (optHandpay.IsChecked == true)
                    treasury.TreasuryType = "AttendantPay Credit";
                else if (optJackpot.IsChecked == true)
                    treasury.TreasuryType = "AttendantPay Jackpot";
                else
                    treasury.TreasuryType = "PROGRESSIVE";
                treasury.TreasuryAmount = amount;
                treasury.ActualTreasuryDate = DateTime.Now;

              // treasury.UserID = Security.SecurityHelper.CurrentUser.User_No;               
                treasury.UserID = Auth_User_ID;


                treasury.Authorized_Date = DateTime.MinValue.DBMinValue();
                if (objAuthorize != null && objAuthorize.IsAuthorized)
                {
                    treasury.AuthorizedUser_No = Auth_User_ID;
                    treasury.Authorized_Date = DateTime.Now;

                    //Audit for authorization
                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {

                        AuditModuleName = ModuleName.ManualAttendantPay,
                        Audit_Screen_Name = "PositionDetails|ManualAttendantPay",
                        Audit_Desc = "Manual AttendantPay Type-" + treasury.TreasuryType,
                        AuditOperationType = OperationType.ADD,
                        Audit_Field = "AuthorizedUser_No",
                        Audit_New_Vl = Auth_User_ID.ToString(),
                        Audit_Slot = Asset
                    });

                }

                treasury.CustomerID = Custid; // add the customer to the treasury if amt between 1000 & 4000 or >5000

                Treasury_No = handpay.ProcessHandPay(treasury, 0);


                IsProcessed = true;
                if (Treasury_No > 0)
                {
                    DateTime dtTreasury = (DateTime)handpay.GetTreasuryDateTime(Treasury_No);

                    TextBlock_11.Text = "#" + (cmbBarPositions.SelectedItem as BarPositions).Bar_Pos_Name + dtTreasury.ToString("ddMMyyyyHHmmss");
                    txtAmount.Text = Convert.ToDecimal((treasury.TreasuryAmount)).GetUniversalCurrencyFormat();
                    #region GCD
                    if (Settings.IsGloryCDEnabled && Settings.CashDispenserEnabled)
                    {

                        LoadingWindow ld = new LoadingWindow(Window.GetWindow(this), ModuleName.ManualAttendantPay, Treasury_No.ToString(), (cmbBarPositions.SelectedItem as BarPositions).Bar_Pos_Name, Convert.ToInt32(treasury.TreasuryAmount * 100));
                        ld.Topmost = true;
                        ld.ShowDialogEx(this);
                        Result res = ld.Result;
                        if (res.IsSuccess && (Treasury_No > 0))
                        {
                            LogManager.WriteLog(string.Format("Cash Dispensed Successfully - Treasury Amount: {0:0.00}", treasury.TreasuryAmount), LogManager.enumLogLevel.Info);
                            LogManager.WriteLog("Export Manual AttendantPay Details to Enterprise", LogManager.enumLogLevel.Info);
                            handpay.ExportHandPay(Treasury_No);

                            BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);

                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {

                                AuditModuleName = ModuleName.AttendantPay,
                                Audit_Screen_Name = "PositionDetails|AttendantPay|Manual HandPay",
                                Audit_Desc = "Manual HandPay Succeed",
                                AuditOperationType = OperationType.ADD,
                                Audit_Old_Vl = "Ticket_ExceptionID:0 (Manual Handpay); TreasuryNo:" + Treasury_No + ";",

                            });

                        }
                        else
                        {
                            BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);
                            LogManager.WriteLog(string.Format("Unable to Dispense Cash - Treasury Amount: {0:0.00}", treasury.TreasuryAmount), LogManager.enumLogLevel.Info);
                            LogManager.WriteLog("Rollback Manual HandPay Process", LogManager.enumLogLevel.Info);
                            handpay.RollbackHandPay(0, Treasury_No);
                            MessageBox.ShowBox("MessageID117", BMC_Icon.Error);
                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {

                                AuditModuleName = ModuleName.AttendantPay,
                                Audit_Screen_Name = "PositionDetails|AttendantPay",
                                Audit_Desc = treasury.TreasuryType + " processing was not completed.",
                                AuditOperationType = OperationType.ADD,
                                Audit_Slot = Asset
                            });
                            AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                            {
                                AuditModuleName = ModuleName.AttendantPay,
                                Audit_Screen_Name = "PositionDetails|AttendantPay|Manual HandPay Process Failed",
                                Audit_Desc = "Rollback HandPay Process Voucher due to cash dispenser error",
                                AuditOperationType = OperationType.MODIFY,
                                Audit_Old_Vl = "Ticket_ExceptionID:0 (Manual Handpay); TreasuryNo:" + Treasury_No + ";"
                            });
                        }
                    }
                    else
                    {
                        this.ProcessCashDispense("Manual AttendantPay Type", treasury.TreasuryType, Convert.ToDecimal(amount));
                        MessageBox.ShowBox("MessageID116", BMC_Icon.Information);
                    }
                    #endregion

                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {

                        AuditModuleName = ModuleName.ManualAttendantPay,
                        Audit_Screen_Name = "PositionDetails|ManualAttendantPay",
                        Audit_Desc = "Manual AttendantPay Type-" + treasury.TreasuryType,
                        AuditOperationType = OperationType.ADD,
                        Audit_Field = "Amount",
                        Audit_New_Vl = String.Format("{0:0.00}", treasury.TreasuryAmount),
                        Audit_Slot = Asset
                    });

                    if (txtBox != null)
                    {
                        //txtBox.Text = "0.00";

                        txtBox.Text = this.DefaultAmount();
                        ucValueCalcComp.s_UnformattedText = "";
                    }

                    if (objAuthorize != null && objAuthorize.User != null)
                        (oCommonUtilities.CreateInstance()).PrintCommonReceipt(false, treasury.TreasuryType, Treasury_No.ToString(), objAuthorize.User);
                    else
                    (oCommonUtilities.CreateInstance()).PrintCommonReceipt(false, treasury.TreasuryType, Treasury_No.ToString());
                    if (((bool)optJackpot.IsChecked) || ((bool)optProgressive.IsChecked))// || ((bool)optHandpay.IsChecked))
                    {
                        treasury.Asset = Asset;
                        //string installationType = installationPathkey.GetValue("InstallationType").ToString();

                        //if (installationType.ToUpper().Equals("EXCHANGECLIENT"))
                        //{
                        //    if (Settings.SendPT10FromClient)
                        //        PostHandpayEvent(treasury);
                        //}
                        //else
                        PostHandpayEvent(treasury);
                    }
                }
                else
                {
                    if (optHandpay.IsChecked == true)
                        MessageBox.ShowBox("MessageID119", BMC_Icon.Error);
                    else if (optJackpot.IsChecked == true)
                        MessageBox.ShowBox("MessageID1191", BMC_Icon.Error);
                    else
                        MessageBox.ShowBox("MessageID1192", BMC_Icon.Error);


                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {

                        AuditModuleName = ModuleName.ManualAttendantPay,
                        Audit_Screen_Name = "PositionDetails|ManualAttendantPay",

                        Audit_Desc = "Manual AttendantPay Type-" + treasury.TreasuryType + " processing was not completed.",
                        AuditOperationType = OperationType.ADD,
                        Audit_Slot = Asset
                    });
                }
            }
            catch (Exception Ex)
            {
                ExceptionManager.Publish(Ex);
                MessageBox.ShowBox("MessageID119", BMC_Icon.Error);

                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                {

                    AuditModuleName = ModuleName.ManualAttendantPay,
                    Audit_Screen_Name = "PositionDetails|ManualAttendantPay",
                    Audit_Desc = "Manual AttendantPay Type-" + treasury.TreasuryType + " processing was not completed.",
                    AuditOperationType = OperationType.ADD,
                    Audit_Slot = Asset
                });
            }
        }
        private void ProcessHandpay(bool IsVoid)
        {
            Window Owner;
            double amount = 0;
            CAuthorize objAuthorize = null;
            Treasury treasury = null;
            int AuthUserID = 0;
            try
            {
                //
                if (!IsHandpayVoid)
                {
                    if ((lstHandpay.SelectedItem as FillTreasuryList).Amount != null && (double)(lstHandpay.SelectedItem as FillTreasuryList).Amount > 0)
                    {
                        //double.TryParse((lstHandpay.SelectedItem as FillTreasuryList).Amount.ToString(), NumberStyles.Currency, new CultureInfo(ExtensionMethods.CurrentCurrenyCulture), out amount);
                        //------->
                        // Issue fix for ->In ITALY environment if user currency setting is set as italy then while processing handpay amount 
                        // of 99,36 customer information screen is displaying. (If we set user currency setting as US or UK then 
                        // we are able to process handpays properly)
                        //<--------
                        double.TryParse((lstHandpay.SelectedItem as FillTreasuryList).Amount.ToString(), out amount);
                    }

                    if (Settings.W2GMessage)
                    {
                        if (amount > Settings.W2GWinAmount)
                        {
                            MessageBox.ShowBox("MessageID367", BMC_Icon.Information);
                            if (!Settings.ProcessW2GAmount)
                            {
                                MessageBox.ShowBox("MessageID531", BMC_Icon.Information);
                                IsProcessed = true;
                                return;
                            }
                        }
                    }
                    AuthUserID = Security.SecurityHelper.CurrentUser.User_No;

                    if (Settings.Client != null && Settings.Client.ToLower() == "winchells"
                        && Settings.MaxHandPayAuthRequired
                        && (lstHandpay.SelectedItem as FillTreasuryList).Amount != null
                        && (amount > Settings.HandpayPayoutCustomer_Max))
                    {
                        objAuthorize = new CAuthorize("CashdeskOperator.Authorize.cs.MaxHandpay");
                        objAuthorize.User = Security.SecurityHelper.CurrentUser;
                        if (!Security.SecurityHelper.HasAccess("CashdeskOperator.Authorize.cs.MaxHandpay"))
                        {
                            objAuthorize.ShowDialog();
                            if (!objAuthorize.IsAuthorized)
                                return;

                            else
                            {
                                AuthUserID = handpay.GetUserID(objAuthorize.User.SecurityUserID);

                            }
                        }
                        else
                        {
                            objAuthorize.IsAuthorized = true;
                        }
                    }

                    if (Settings.RegulatoryEnabled == true && Settings.RegulatoryType == "AAMS")
                    {
                        if ((lstHandpay.SelectedItem as FillTreasuryList).Amount != null)
                        {
                            Custid = 0;
                            ProcessCancelled = false;
                            if (amount >= Settings.HandpayPayoutCustomer_Min && amount <= Settings.HandpayPayoutCustomer_Max)
                            {
                                oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                                oCustomerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                                oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                                Owner = Window.GetWindow(this);
                                oCustomerDetails.ShowDialog();
                            }
                            else if (amount >= Settings.HandpayPayoutCustomer_BankAccNo)
                            {
                                oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails(true);
                                oCustomerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                                oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                                Owner = Window.GetWindow(this);
                                oCustomerDetails.ShowDialog();
                            }
                            else if (amount >= Settings.HandpayPayoutCustomer_Max && amount <= Settings.HandpayPayoutCustomer_BankAccNo)
                            {
                                oCustomerDetails = new BMC.Presentation.POS.Views.CustomerDetails();
                                oCustomerDetails.delCustomerUpdated += new BMC.Presentation.POS.Views.CustomerDetails.CustomerUpdateHandler(delCustomerUpdated);
                                oCustomerDetails.delCustomerCancelled += new BMC.Presentation.POS.Views.CustomerDetails.CustomerCancelHandler(delCustomerCancelled);
                                Owner = Window.GetWindow(this);
                                oCustomerDetails.ShowDialog();
                            }
                        }
                        if (ProcessCancelled)
                            return;
                    }
                }

                int TE_ID = (lstHandpay.SelectedItem as FillTreasuryList).TE_ID;
                treasury = new Treasury
                {
                    InstallationNumber =
                        (lstHandpay.SelectedItem as FillTreasuryList).Installation_No,
                    TreasuryType = (lstHandpay.SelectedItem as FillTreasuryList).HP_Type,
                    TreasuryAmount = (double)(lstHandpay.SelectedItem as FillTreasuryList).Amount,
                    TreasuryTemp = IsVoid ? true : false,
                    ActualTreasuryDate =
                        (DateTime)((lstHandpay.SelectedItem as FillTreasuryList).TreasuryDate)
                };
                treasury.CustomerID = Custid;
                treasury.UserID = AuthUserID;
                treasury.Authorized_Date = DateTime.Now.DBMinValue();

                if (objAuthorize != null && objAuthorize.IsAuthorized)
                {
                    treasury.AuthorizedUser_No = objAuthorize.User.SecurityUserID;
                    treasury.Authorized_Date = DateTime.Now;

                    //Audit for authorization
                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {

                        AuditModuleName = ModuleName.ManualAttendantPay,
                        Audit_Screen_Name = "PositionDetails|ManualAttendantPay",
                        Audit_Desc = "Manual AttendantPay Type-" + treasury.TreasuryType,
                        AuditOperationType = OperationType.ADD,
                        Audit_Field = "AuthorizedUser_No",
                        Audit_New_Vl = objAuthorize.User.SecurityUserID.ToString(),
                        Audit_Slot = (lstHandpay.SelectedItem as FillTreasuryList).Asset
                    });

                }
                Treasury_No = handpay.ProcessHandPay(treasury, TE_ID);

                if (Treasury_No > 0)
                {
                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {

                        AuditModuleName = ModuleName.AttendantPay,
                        Audit_Screen_Name = "PositionDetails|AttendantPay",
                        Audit_Desc = "AttendantPay Type-" + treasury.TreasuryType,
                        AuditOperationType = OperationType.ADD,
                        Audit_Field = "Treasury Amount",
                        Audit_New_Vl = String.Format("{0:0.00}", treasury.TreasuryAmount),
                        Audit_Slot = (lstHandpay.SelectedItem as FillTreasuryList).Asset
                    });

                    txtAmount.Text = "";

                    if ((bool)(lstHandpay.SelectedItem as FillTreasuryList).HP_Uncleared)
                    {
                        //LogManager.WriteLog("Executing Path : " + BMCRegistryHelper.GetRegLocalMachine().OpenSubKey("Software\\Honeyframe").GetValue("InstallationPath").ToString().Trim() + Common.ConfigurationManagement.ConfigManager.Read(
                        //            "HandpayCommandLinePrompt") + " ClearHandpay " + (lstHandpay.SelectedItem as FillTreasuryList).Datapak_No, LogManager.enumLogLevel.Info);



                        //System.Diagnostics.Process.Start(BMCRegistryHelper.GetRegLocalMachine().OpenSubKey("Software\\Honeyframe").GetValue("InstallationPath").ToString().Trim() + Common.ConfigurationManagement.ConfigManager.Read(
                        //            "HandpayCommandLinePrompt"), " ClearHandpay " + (lstHandpay.SelectedItem as FillTreasuryList).Datapak_No);

                        //var proc = new System.Diagnostics.Process
                        //{
                        //    StartInfo =
                        //    {
                        //        FileName =
                        //            Environment.CurrentDirectory + "\\" + Common.ConfigurationManagement.ConfigManager.Read(
                        //            "HandpayCommandLinePrompt"),
                        //        Arguments =
                        //            "ClearHandpay "+ (lstHandpay.SelectedItem as FillTreasuryList).Datapak_No
                        //    }
                        //};
                        //proc.Start();
                    }

                    if (!IsVoid)
                    {

                        #region GCD
                        if (Settings.IsGloryCDEnabled && Settings.CashDispenserEnabled)
                        {
                            LoadingWindow ld = new LoadingWindow(this, ModuleName.AttendantPay, Treasury_No.ToString(), sPos, Convert.ToInt32(treasury.TreasuryAmount * 100));
                            ld.Topmost = true;
                            ld.ShowDialog();
                            Result res = ld.Result;
                            if (res.IsSuccess && (Treasury_No > 0))
                            {
                                LogManager.WriteLog(string.Format("Cash Dispensed Successfully - Treasury Amount: {0:0.00}", treasury.TreasuryAmount), LogManager.enumLogLevel.Info);
                                LogManager.WriteLog("Export HandPay Details to Enterprise", LogManager.enumLogLevel.Info);
                                handpay.ExportHandPay(Treasury_No);

                                BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);
                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {

                                    AuditModuleName = ModuleName.AttendantPay,
                                    Audit_Screen_Name = "PositionDetails|AttendantPay|HandPay",
                                    Audit_Desc = "HandPay Succeed",
                                    AuditOperationType = OperationType.ADD,
                                    Audit_Old_Vl = "Ticket_ExceptionID:" + TE_ID + ";TreasuryNo:" + Treasury_No + ";",

                                });

                            }
                            else
                            {
                                BMC.Presentation.MessageBox.ShowBox(res.error.Message, res.error.MessageType.Equals("Error") ? BMC_Icon.Error : BMC_Icon.Information, true);
                                LogManager.WriteLog(string.Format("Unable to Dispense Cash - Treasury Amount: {0:0.00}", treasury.TreasuryAmount), LogManager.enumLogLevel.Info);
                                LogManager.WriteLog("Rollback HandPay Process", LogManager.enumLogLevel.Info);
                                handpay.RollbackHandPay(TE_ID, Treasury_No);
                                MessageBox.ShowBox("MessageID117", BMC_Icon.Error);
                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {

                                    AuditModuleName = ModuleName.AttendantPay,
                                    Audit_Screen_Name = "PositionDetails|AttendantPay",
                                    Audit_Desc = treasury.TreasuryType + " processing was not completed.",
                                    AuditOperationType = OperationType.ADD,
                                    Audit_Slot = (lstHandpay.SelectedItem as FillTreasuryList).Asset
                                });
                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {
                                    AuditModuleName = ModuleName.AttendantPay,
                                    Audit_Screen_Name = "PositionDetails|AttendantPay|HandPay Process Failed",
                                    Audit_Desc = "Rollback HandPay Process Voucher due to cash dispenser error",
                                    AuditOperationType = OperationType.MODIFY,
                                    Audit_Old_Vl = "Ticket_ExceptionID:" + TE_ID + ";TreasuryNo:" + Treasury_No + ";"
                                });
                            }
                        }
                        else
                        {
                            this.ProcessCashDispense("AttendantPay Type", treasury.TreasuryType, Convert.ToDecimal(treasury.TreasuryAmount));
                            MessageBox.ShowBox("MessageID116", BMC_Icon.Information);
                        }
                        #endregion

                        FillTreasury(sPos);
                        Helper_classes.Common.BindListView(treasuryList, lstHandpay);

                        //Newly Added - Venkatesh Kumar - SGVI

                        if (AppSettings.IsReceiptRequired)
                        {
                            if (objAuthorize != null && objAuthorize.User != null)
                                (oCommonUtilities.CreateInstance()).PrintCommonReceipt(false, treasury.TreasuryType, Treasury_No.ToString(), objAuthorize.User);
                            else
                                (oCommonUtilities.CreateInstance()).PrintCommonReceipt(false, treasury.TreasuryType, Treasury_No.ToString());
                        }

                        //---------************---------------

                        LogManager.WriteLog("Binding of Hand Pay completed for the pos : " + sPos, LogManager.enumLogLevel.Info);
                    }
                }
                else
                {

                    switch (Treasury_No)
                    {

                        case -2://LockExists
                        case -3://LockError
                            {
                                MessageBox.ShowBox("MessageID373", BMC_Icon.Error);

                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {

                                    AuditModuleName = ModuleName.AttendantPay,
                                    Audit_Screen_Name = "PositionDetails|AttendantPay",
                                    Audit_Desc = treasury.TreasuryType + " has been locked by another user for processing.",
                                    AuditOperationType = OperationType.ADD,
                                    Audit_Slot = (lstHandpay.SelectedItem as FillTreasuryList).Asset
                                });

                                break;
                            }
                        case -4://DatabaseError
                            {
                                MessageBox.ShowBox("MessageID374", BMC_Icon.Error);

                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {

                                    AuditModuleName = ModuleName.AttendantPay,
                                    Audit_Screen_Name = "PositionDetails|AttendantPay",
                                    Audit_Desc = treasury.TreasuryType + " -Unable to Access the database.",
                                    AuditOperationType = OperationType.ADD,
                                    Audit_Slot = (lstHandpay.SelectedItem as FillTreasuryList).Asset
                                });
                                break;
                            }
                        default:
                            {
                                MessageBox.ShowBox("MessageID117", BMC_Icon.Error);

                                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                                {

                                    AuditModuleName = ModuleName.AttendantPay,
                                    Audit_Screen_Name = "PositionDetails|AttendantPay",
                                    Audit_Desc = treasury.TreasuryType + " processing was not completed.",
                                    AuditOperationType = OperationType.ADD,
                                    Audit_Slot = (lstHandpay.SelectedItem as FillTreasuryList).Asset
                                });
                                break;
                            }
                    }


                }
            }
            catch (Exception Ex)
            {
                ExceptionManager.Publish(Ex);
                MessageBox.ShowBox("MessageID117", BMC_Icon.Error);

                AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                {

                    AuditModuleName = ModuleName.AttendantPay,
                    Audit_Screen_Name = "PositionDetails|AttendantPay",
                    Audit_Desc = treasury.TreasuryType + " processing was not completed.",
                    AuditOperationType = OperationType.ADD,
                    Audit_Slot = handpay.GetAssetNumber(InstallationNumber)[0].Stock_No
                });
            }
            finally
            {
                IsHandpayVoid = false;
            }
        }