private void ProcessToSyncTicket(ActiveMachine Machine)
        {

            MachineManagerLazyInitializer manager = null;
            ActiveMachine _activeMachine = null;


            try
            {
                _activeMachine = Machine as ActiveMachine;
                oCommonUtilities.CreateInstance().UpdateTicketExpire(Settings.Ticket_Expire);
                //MachineManagerInterface machineManagerInterface = new MachineManagerInterface();
                manager = new MachineManagerLazyInitializer();

                int nSuccess = manager.GetMachineManager().UpdateTicketConfig(_activeMachine.Installation_No, Settings.Ticket_Expire);
                if (nSuccess == 0)
                {
                    _activeMachine.Status = "Success";
                    oCommonUtilities.CreateInstance().UpdateGMUSiteCodeStatus(_activeMachine.Installation_No,1);
                }
                else
                {
                    _activeMachine.Status = "Failed";
                }
            }
            catch (Exception Ex)
            {

                LogManager.WriteLog("ProcessToSyncTicket: " + Ex.Message, LogManager.enumLogLevel.Info);
                ExceptionManager.Publish(Ex);
            }
            finally
            {
                if (manager != null)
                {
                    try
                    {
                        manager.ReleaseMachineManager();
                        manager = null;
                    }
                    catch (Exception Ex)
                    {
                        LogManager.WriteLog("ProcessToSyncTicket:ReleaseMachineManager " + Ex.Message, LogManager.enumLogLevel.Info); ;
                    }
                }

            }
        }
        public bool EmployeecardSend(string EmpCardNo, string EmployeeFlags, int InstallationNo)
        {
            try
            {
                string EmpFlags = EmployeeFlags.Substring(2);
                List<byte> enumver = Enumerable.Range(0, EmpFlags.Length)
                       .Where(x => x % 2 == 0)
                       .Select(x => Convert.ToByte(EmpFlags.Substring(x, 2), 16)).ToList();

                List<byte> cardno = Enumerable.Range(0, EmpCardNo.PadLeft(10, '0').Length)
                         .Where(x => x % 2 == 0)
                         .Select(x => Convert.ToByte(EmpCardNo.PadLeft(10, '0').Substring(x, 2), 16)).ToList();

                enumver.Insert(0, Convert.ToByte(EmployeeFlags.Substring(0, 1)));
                enumver.Insert(1, Convert.ToByte(EmployeeFlags.Substring(1, 1)));
                enumver.InsertRange(0, cardno);

                byte[] bData = enumver.ToArray();

                bool status = new MachineManagerLazyInitializer().GetMachineManager().SendEmpCard(InstallationNo, 84, bData);
                return status;
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                return false;
            }

        }
        private void rbReInstateMachine_Click(object sender, RoutedEventArgs e)
        {
            LogManager.WriteLog("rbReInstateMachine_Click", LogManager.enumLogLevel.Info);

            MachineManagerLazyInitializer manager = null;
            int nResult;
            try
            {

                var oDataContext =
                           new InstallationDataContext(oCommonUtilities.CreateInstance().GetConnectionString());
                //MachineManagerInterface machineManagerInterface = new MachineManagerInterface();
                manager = new MachineManagerLazyInitializer();

                if (!(Settings.NoWaitForDisableMachine))
                {
                    int nSuccess = manager.GetMachineManager().EnableMachineFromUI(_SlotMachine.InstallationNo);
                    if (nSuccess != 0)
                    {
                        MessageBox.ShowBox("MessageID362", BMC_Icon.Warning, _SlotMachine.AssetNo);
                        return;
                    }
                }

                //
                nResult = oDataContext.InsertReinstateMachine
                     (_SlotMachine.InstallationNo,
                         SecurityHelper.CurrentUser.SecurityUserID,
                         Convert.ToDouble("0"),
                         "Float Issued",
                         "FLOAT",
                         0,
                         0,
                         "SITE",
                         Settings.CD_Not_Use_Hoppers);

                if (nResult == 0)
                {
                    MessageBox.ShowBox("MessageID319", BMC_Icon.Information, BMC_Button.OK);
                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {
                        AuditModuleName = ModuleName.ReinstateMachine,
                        Audit_Screen_Name = "Position Details|Reinstate Machine",
                        Audit_Desc = "Machine Reinstated.",
                        AuditOperationType = OperationType.MODIFY,
                        Audit_Slot = _SlotMachine.AssetNumber
                    });

                }
                else
                {
                    MessageBox.ShowBox("MessageID320", BMC_Icon.Information, BMC_Button.OK);
                    AuditViewerBusiness.InsertAuditData(new Audit.Transport.Audit_History
                    {
                        AuditModuleName = ModuleName.ReinstateMachine,
                        Audit_Screen_Name = "Position Details|Reinstate Machine",
                        Audit_Desc = "Unable to Reinstate Machine.",
                        AuditOperationType = OperationType.MODIFY,
                        Audit_Slot = _SlotMachine.AssetNumber
                    });
                }

                if (Exit != null)
                {
                    Timer.Stop();
                    Exit.Invoke(this, new CancelEventArgs());
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
            }

            finally
            {
                if (manager != null)
                {
                    manager.ReleaseMachineManager();
                    manager = null;
                }
            }

        }
        //
        private void DoFinalDrop(bool bManualDrop)
        {
            MachineManagerLazyInitializer manager = null;

            try
            {

                if (rdoFinalCount.IsChecked == true)
                {
                    //if ((!Settings.AutoDropEnabled) || bManualDrop)

                    InstallationDataContext installationDataContext =
                                    new InstallationDataContext(oCommonUtilities.CreateInstance().GetConnectionString());


                    foreach (CreditStatus credits in _collectionHelper.GetHandPayPlayCreditStatus(SELECTED_MACHINES))
                    {
                        if (_mEvent.WaitOne(10))
                        {
                            break;
                        }


                        _InstallationnumberMR = Convert.ToInt32(credits.Installation_No);

                        if (credits.IsHandPayUnProcessed != 0 || credits.isCardedPlay != 0 || credits.inplay != 0)
                        {

                            MarkMachineDropStatus(false, false, NOTSET, Convert.ToInt32(credits.Installation_No), NOTSET, NOTSET.ToString(), NOTSET, NOTSET);
                            string strMsg = (credits.IsHandPayUnProcessed != 0) ? System.Windows.Application.Current.FindResource("MessageID313").ToString() :
                                (credits.inplay != 0) ? System.Windows.Application.Current.FindResource("MessageID316").ToString() : System.Windows.Application.Current.FindResource("MessageID317").ToString();
                            strMsg += " (" + GetStockNo(credits.Installation_No.Value) + ")";
                            MessageBox.ShowBox(strMsg, BMC_Icon.Warning, true);

                        }
                        else if (credits.isGMUUPdate != 0)
                        {
                            MarkMachineDropStatus(false, false, NOTSET, Convert.ToInt32(credits.Installation_No), NOTSET, NOTSET.ToString(), NOTSET, NOTSET);
                            string strMsg = System.Windows.Application.Current.FindResource("MessageID316a").ToString().Replace("@@@@@@",GetStockNo(credits.Installation_No.Value));                           
                            MessageBox.ShowBox(strMsg, BMC_Icon.Warning, true);
                        }
                        else
                        {
                            try
                            {
                                manager = new MachineManagerLazyInitializer();
                                int nSuccess = 0;
                                if (Settings.Disable_Machine_On_Drop)
                                    nSuccess = manager.GetMachineManager().DisableMachineFromUI(Convert.ToInt32(credits.Installation_No));
                                else
                                    LogManager.WriteLog("CPerformDrop->DoFinalDrop: Skip Disable Machine as Disable_Machine_On_Drop is false", LogManager.enumLogLevel.Info);


                                if (nSuccess != 0)
                                {
                                    if (!(Settings.NoWaitForDisableMachine))
                                    {
                                        MarkMachineDropStatus(false, false, NOTSET, Convert.ToInt32(credits.Installation_No), NOTSET, NOTSET.ToString(), NOTSET, NOTSET);
                                        MessageBox.ShowBox("MessageID361", BMC_Icon.Warning, GetStockNo(Convert.ToInt32(credits.Installation_No)));
                                    }
                                }

                                //Allow Machine Removal in CDO when CentralizedDeclaration declaration is Enabled 
                                //Allow Machine Removal in CDO when multiple drops is Enabled 
                                if (Settings.IsFinalDropRequiredForRemoval&&(Settings.AllowMultipleDrops || Settings.Allow_Machine_Removal) && rdoFinalCount.IsChecked == true)
                                {
                                    installationDataContext = new InstallationDataContext(oCommonUtilities.CreateInstance().GetConnectionString());
                                    installationDataContext.updateInstallationFloatStatus(_InstallationnumberMR);
                                }
                                //Allow Machine Removal in CDO when CentralizedDeclaration declaration is Enabled 

                            }
                            finally
                            {
                                if (manager != null)
                                {
                                    manager.ReleaseMachineManager();
                                    manager = null;
                                }
                            }

                        }

                        //}
                    }
                }
            }
            catch (Exception ex) { LogError("DoFinalDrop", ex); }
        }
        //private void RefreshButtons(SlotMachineStatus eStatus)
        //{
        //    //Remove Machine
        //    CollectionHelper CollectionHelper = new CollectionHelper();

        //    if ((eStatus == SlotMachineStatus.FloatCollection && !CollectionHelper.HasUndeclaredCollecion(_SlotMachine.InstallationNo))
        //        || !Settings.IsFinalDropRequiredForRemoval
        //        || eStatus == SlotMachineStatus.InstallationCompletedNonMetered
        //        || eStatus == SlotMachineStatus.GameInstallationAAMSPending
        //        || eStatus == SlotMachineStatus.VLTInstallationAAMSPending )
        //    {
        //        if (!Security.SecurityHelper.HasAccess("CashdeskOperator.FloorView.cs.RemoveMachine"))
        //            rbRemoveMachine.Visibility = Visibility.Collapsed;
        //        else
        //            rbRemoveMachine.Visibility = Visibility.Visible;
        //    }
        //    else
        //        rbRemoveMachine.Visibility = Visibility.Collapsed;


        //    //Reinstate Machine
        //    if ((eStatus == SlotMachineStatus.FloatCollection && !CollectionHelper.HasUndeclaredCollecion(_SlotMachine.InstallationNo)))
        //    {
        //        rbReInstateMachine.Visibility = Visibility.Visible;
        //        rbReInstateMachine.IsEnabled = true;
        //        rbEvents.Visibility = Visibility.Collapsed;
        //        rbFieldService.Visibility = Visibility.Collapsed;
        //        rbHandpay.Visibility = Visibility.Collapsed;
        //        rbMachineMaintenance.Visibility = Visibility.Collapsed;
        //        rbMachineMeters.Visibility = Visibility.Collapsed;
        //        rbPlayerClub.Visibility = Visibility.Collapsed;

        //        //rbRemoveMachine.IsChecked = true;

        //    }

        //    else
        //        rbReInstateMachine.Visibility = Visibility.Collapsed;

        //} 

        private void SyncTicketExpire_Click(object sender, RoutedEventArgs e)
        {
            LogManager.WriteLog("SyncTicketExpire_Click", LogManager.enumLogLevel.Info);
            MachineManagerLazyInitializer manager = null;

            try
            {
                if (MessageBox.ShowBox("MessageID365", BMC_Icon.Question, BMC_Button.YesNo) == System.Windows.Forms.DialogResult.No) return;
                int InstallationNo = _SlotMachine.InstallationNo;
                oCommonUtilities.CreateInstance().UpdateTicketExpire(Settings.Ticket_Expire);
                manager = new MachineManagerLazyInitializer();
                int nSuccess = manager.GetMachineManager().UpdateTicketConfig(InstallationNo, Settings.Ticket_Expire);
                if (!(nSuccess == 0))
                {
                    MessageBox.ShowBox("MessageID364", BMC_Icon.Warning, _SlotMachine.AssetNumber.ToString());
                    return;
                }
                else
                {
                    oCommonUtilities.CreateInstance().UpdateGMUSiteCodeStatus(InstallationNo, 1);
                }
                MessageBox.ShowBox("MessageID366", BMC_Icon.Information, _SlotMachine.AssetNumber.ToString());
            }
            catch (Exception Ex)
            {
                ExceptionManager.Publish(Ex);
            }
            finally
            {
                if (manager != null)
                {
                    manager.ReleaseMachineManager();
                    manager = null;
                }
            }
        }