private void button1_Click(object sender, EventArgs e)
        {
            Audit_History objAH = new Audit_History();

            objAH.Audit_User_ID = 101;
            objAH.Audit_User_Name = "user1";
            //objAH.AuditModuleID =ModuleID.Enrollment; //not required
            objAH.AuditModuleName = ModuleName.Enrollment;
            objAH.EnterpriseModuleName = ModuleNameEnterprise.Settings;
            objAH.Audit_Screen_Name = "Screen Name";
            
            objAH.Audit_Slot = "LC0003";
            objAH.Audit_Field = "FieldName"; //can be enumerated
            objAH.Audit_Old_Vl = "old";
            objAH.Audit_New_Vl = "new";
            objAH.Audit_Desc = "Desc";
            objAH.AuditOperationType = OperationType.ADD;
            


            AuditViewerBusiness.InsertAuditData(objAH);

            

            //business.InsertAuditData(userID, sUserName, nmoduleId, sModuleName, sSlot, sAudField, sOldValue, sNewValue, sAudDesc);


            //dataGridView1.DataSource = AVB.GetAuditDetails(System.DateTime.Now.AddDays(-3), System.DateTime.Now.AddDays(3), ((int)ModuleID.Enrollment).ToString());
            
        }
        //
        private void Audit(int batchID, CollectionType collectionType, string BarPos, bool Success)
        {
            /* 
             * Audit the success and failure of the drop performed
             */

            try
            {
                if (!string.IsNullOrEmpty(BarPos))
                {
                    Audit.Transport.Audit_History AH = new Audit.Transport.Audit_History();

                    AH.AuditModuleName = ModuleName.MachineDrop;

                    AH.Audit_Screen_Name = (Settings.AutoDropEnabled && collectionType == BMC.CashDeskOperator.CollectionType.FullCollection) ? "AutoDrop|Drop" : "MachineDrop|Drop";
                    if (batchID == 0) // Part_Collection 
                        AH.Audit_Desc = "Batch: " + batchID + ",DropType: " + GetDropType(collectionType);
                    else
                        AH.Audit_Desc = "Batch: " + batchID + ",DropType: " + GetDropType(collectionType) + AutoDropSession(batchID);
                    AH.AuditOperationType = OperationType.ADD;
                    AH.Audit_Field = Success ? "Machines Dropped" : "Drop Failed Machines";

                    if (Success && Settings.CentralizedDeclaration && batchID > 0)
                        _collectionHelper.InsertIntoExportHistory(batchID);

                    AH.Audit_New_Vl = BarPos;

                    if (AH.Audit_New_Vl.EndsWith(", "))
                        AH.Audit_New_Vl = AH.Audit_New_Vl.Substring(0, AH.Audit_New_Vl.Length - 2);

                    AuditViewerBusiness.InsertAuditData(AH);
                }
            }
            catch (Exception ex) { LogError("Audit", ex); }

        }
        protected override bool ProcessG2HMessageInternal(MonMsg_G2H request)
        {
            bool retVal = true;
            const string msg_type = "Card Out";
            InstallationDetailsForMSMQ installationDetails = null;

            // add the card detail
            var cardDetail = EPIManager.Current.AddOrUpdateCardInDetail(request.InstallationNo, request.CardNumber);

            using (ILogMethod method = Log.LogMethod("MonitorHandler_EPI_22_38", "ProcessG2HMessageInternal"))
            {
                try
                {
                    method.Info("Started Employee Card Out for " + request.CardNumber);

                    if (HandlerHelper.Current.IsEmployeeCardTrackingEnabled)
                    {
                        ExCommsDataContext.Current.UpdateFloorStatus(request.InstallationNo, DateTime.Now, null, null, null, null,
                                                               null, null, null, null, "", request.FaultDate.ToString(), null);

                        EPIManager.Current.CreateProcess(request.InstallationNo);
                        method.Info("Insert Employee card Session Details");
                        ExCommsDataContext.Current.UpdateEmployeeCardSessions(request.CardNumber, request.FaultDate, request.InstallationNo, msg_type);
                        installationDetails = request.Extra as InstallationDetailsForMSMQ;
                        ExCommsDataContext.Current.SendEmployeeSTMALert(installationDetails.Bar_Pos_No.ToString(), request.FaultDate, msg_type, request.CardNumber);

                        try
                        {
                            Audit.Transport.Audit_History m_AuditInfo = new Audit.Transport.Audit_History();
                            m_AuditInfo.AuditModuleName = ModuleName.MSMQ;
                            m_AuditInfo.Audit_Date = DateTime.Now.Date;
                            m_AuditInfo.Audit_User_ID = 0;
                            m_AuditInfo.Audit_User_Name = "System";
                            m_AuditInfo.Audit_Screen_Name = "Employee card";
                            m_AuditInfo.Audit_Desc = "Employee Card Out";
                            m_AuditInfo.AuditOperationType = OperationType.ADD;
                            m_AuditInfo.Audit_Field = "EmployeecardNumber";
                            m_AuditInfo.Audit_New_Vl = request.CardNumber;
                            m_AuditInfo.Audit_Slot = request.Asset;
                            Log.Info(method.PROC, "Insert Auditing info for Employee card out Event");
                            AuditViewerBusiness.InsertAuditData(m_AuditInfo);
                        }
                        catch (Exception ex)
                        {
                            Log.Exception(ex);
                        }

                        try
                        {
                            if (SDTMessages.Instance.ProcessEmployeeCardOut(request))
                            {
                                EPIManager.Current.CreateInactivityTimeout(request.InstallationNo);
                                EPIManager.Current.CreateIntervalRatingTimer(request.InstallationNo);
                            }
                        }
                        finally { }
                    }
                }
                catch (Exception ex)
                {
                    retVal = false;
                    // TODO: EPIMsgProcessor.SendCommand
                    if (installationDetails != null)
                        CurrentEPIMsgProcessor.DisplayBallyWelcomeMsg(request.InstallationNo, installationDetails.Bar_Pos_Name, DateTime.Now);
                    if (cardDetail != null)
                        cardDetail.Clear();
                    Log.Exception(ex);
                }
                finally
                {
                    method.Info("Employee Card Out completed for : " + request.CardNumber);
                }
            }
            return retVal;
        }
        private void btnIssue_Click(object sender, RoutedEventArgs e)
        {

            long lValue = 0;
            try
            {
                txt = (TextBox)this.ucValueCalc.txtDisplay;

                strValue = Convert.ToString(txt.Text);
                btnIssue.IsEnabled = false;
                if (strValue != null && strValue != string.Empty)
                    lValue = Convert.ToInt64(strValue.GetSingleFromString() * 100);
                else
                    lValue = 0;

                if (lValue <= 0)
                {
                    MessageBox.ShowBox("MessageID101");
                    return;
                }
              

                if (!string.IsNullOrEmpty(Settings.IssueTicketMaxValue))
                {
                    long lSettingValue = Convert.ToInt64(Settings.IssueTicketMaxValue.GetSingleFromString() * 100);
                    if (lValue > lSettingValue)
                    {
                        string sMessage = Application.Current.FindResource("MessageID247") as string;
                        //MessageBox.ShowBox(sMessage, BMC_Icon.Error, true);
                        MessageBox.ShowBox(sMessage + ": " +
                           ExtensionMethods.GetUniversalCurrencyFormat(Convert.ToInt64(Settings.IssueTicketMaxValue.GetSingleFromString())),
                                                                                                                    BMC_Icon.Error, true);

                        return;
                    }
                }
              
                if ((lValue <= 99999999) && (lValue > 0))
                {
                    issueTicketEntity.lnglValue = lValue;
                    issueTicketEntity.Type = UIIssueTicketConstants.STANDARDTICKET;
                    issueTicketEntity.dblValue = Convert.ToDouble(strValue, new CultureInfo(ExtensionMethods.CurrentCurrenyCulture));
                    issueTicketEntity.Date = DateTime.Now;

                    PrintTicketErrorCodes PrintResult = objCashDeskOperator.IssueTicket(issueTicketEntity);

                    switch (PrintResult)
                    {
                        case PrintTicketErrorCodes.OpenCOMPortFailure:
                            {

                                MessageBox.ShowBox("MessageID295", BMC_Icon.Warning); //Unable to open COM Port. Please check connectivity.
                                ClearValues();
                                Audit("Unable to open COM Port");
                                return;
                            }
                        case PrintTicketErrorCodes.OutofPaper:
                            {
                                MessageBox.ShowBox("MessageID294", BMC_Icon.Warning); //out of Paper
                                ClearValues();
                                Audit("Printer Out of Paper.");
                                return;
                            }
                        case PrintTicketErrorCodes.Success:
                            {

                                //Calling Audit Method
                                Audit.Transport.Audit_History AH = new Audit.Transport.Audit_History();
                                //Populate required Values

                                AH.AuditModuleName = ModuleName.Voucher;
                                AH.Audit_Screen_Name = "Vouchers|PrintVoucher";
                                AH.Audit_Desc = "Voucher Printed Value-" + strValue;
                                AH.AuditOperationType = OperationType.ADD;
                                AH.Audit_Field = "Voucher Number";
                                AH.Audit_New_Vl = issueTicketEntity.BarCode;

                                ClearValues();
                                MessageBox.ShowBox("MessageID103", BMC_Icon.Information);
                                AuditViewerBusiness.InsertAuditData(AH);
                                break;
                            }
                        case PrintTicketErrorCodes.eVoltErr:
                            {
                                MessageBox.ShowBox("Voltage Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Voltage Error");
                                return;
                            }
                        case PrintTicketErrorCodes.eHeadErr:
                            {
                                MessageBox.ShowBox("Printer Head Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Printer Head Error");
                                return;
                            }
                        case PrintTicketErrorCodes.ePaperOut:
                            {
                                MessageBox.ShowBox("Out of Paper", BMC_Icon.Error);
                                ClearValues();
                                Audit("Out of Paper");
                                return;
                            }
                        case PrintTicketErrorCodes.ePlatenUP:
                            {
                                MessageBox.ShowBox("Platen Up", BMC_Icon.Error);
                                ClearValues();
                                Audit("Platen Up");
                                return;
                            }
                        case PrintTicketErrorCodes.eSysErr:
                            {
                                MessageBox.ShowBox("System Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("System Error");
                                return;
                            }
                        case PrintTicketErrorCodes.eBusy:
                            {
                                MessageBox.ShowBox("Printer is Busy", BMC_Icon.Error);
                                ClearValues();
                                Audit("Printer is Busy");
                                return;
                            }
                        case PrintTicketErrorCodes.eJobMemOF:
                            {
                                MessageBox.ShowBox("Job Memory off", BMC_Icon.Error);
                                ClearValues();
                                Audit("Job Memory off");
                                return;
                            }
                        case PrintTicketErrorCodes.eBufOF:
                            {
                                MessageBox.ShowBox("Buffer off", BMC_Icon.Error);
                                ClearValues();
                                Audit("Buffer off");
                                return;
                            }
                        case PrintTicketErrorCodes.eLibLoadErr:
                            {
                                MessageBox.ShowBox("Library Load Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Library Load Error");
                                return;
                            }
                        case PrintTicketErrorCodes.ePRDataErr:
                            {
                                MessageBox.ShowBox("Printer Data Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Printer Data Error");
                                return;
                            }
                        case PrintTicketErrorCodes.eLibRefErr:
                            {
                                MessageBox.ShowBox("Library Reference Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Library Reference Error");
                                return;
                            }
                        case PrintTicketErrorCodes.eTempErr:
                            {
                                MessageBox.ShowBox("Temp Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Temp Error");
                                return;
                            }
                        case PrintTicketErrorCodes.eMissingSupplyIndex:
                            {
                                MessageBox.ShowBox("Supply Index is Missing", BMC_Icon.Error);
                                ClearValues();
                                Audit("Supply Index is Missing");
                                return;
                            }
                        case PrintTicketErrorCodes.eFlashProgErr:
                            {
                                MessageBox.ShowBox("Flash Program Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Flash Program Error");
                                return;
                            }
                        case PrintTicketErrorCodes.ePaperInChute:
                            {
                                MessageBox.ShowBox("Paper in Chute", BMC_Icon.Error);
                                ClearValues();
                                Audit("Paper in Chute");
                                return;
                            }
                        case PrintTicketErrorCodes.ePrintLibCorr:
                            {
                                MessageBox.ShowBox("Print library is corrupted.", BMC_Icon.Error);
                                ClearValues();
                                Audit("Print library is corrupted.");
                                return;
                            }
                        case PrintTicketErrorCodes.eCmdErr:
                            {
                                MessageBox.ShowBox("Command Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Command Error");
                                return;
                            }
                        case PrintTicketErrorCodes.ePaperLow:
                            {
                                MessageBox.ShowBox("Paper low.", BMC_Icon.Error);
                                ClearValues();
                                Audit("Paper low.");
                                return;
                            }
                        case PrintTicketErrorCodes.ePaperJam:
                            {
                                MessageBox.ShowBox("Paper jammed.", BMC_Icon.Error);
                                ClearValues();
                                Audit("Paper jammed.");
                                return;
                            }
                        case PrintTicketErrorCodes.eCurrentErr:
                            {
                                MessageBox.ShowBox("Current Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Current Error");
                                return;
                            }
                        case PrintTicketErrorCodes.eJournalPrint:
                            {
                                MessageBox.ShowBox("Journal Print Error", BMC_Icon.Error);
                                ClearValues();
                                Audit("Journal Print Error");
                                return;
                            }
                        default:
                            {
                                MessageBox.ShowBox("MessageID102", BMC_Icon.Warning);
                                ClearValues();
                                Audit("Unable to Print Voucher.");
                                return;
                            }

                    }
                }
                else
                {
                    MessageBox.ShowBox("MessageID104", BMC_Icon.Warning);
                    return;
                }
            }
            catch (Exception ex)
            {
                this.ucValueCalc.ClearValues();
                this.ucValueCalc.ValueText = ExtensionMethods.GetCurrencyDecimalDelimiter() + "00";
                this.ucValueCalc.s_UnformattedText = "";
                ExceptionManager.Publish(ex);
            }
            finally
            {
                btnIssue.IsEnabled = true;
            }
        }
        protected override bool ProcessG2HMessageInternal(MonMsg_G2H request)
        {
            bool retVal = true;
            const string msg_type = "Card In";
            InstallationDetailsForMSMQ installationDetails = null;

            // add the card detail
            var cardDetail = EPIManager.Current.AddOrUpdateCardInDetail(request.InstallationNo, request.CardNumber);

            using (ILogMethod method = Log.LogMethod("MonitorHandler_EPI_22_37", "ProcessG2HMessageInternal"))
            {
                try
                {
                    method.Info("Started Employee Card In for " + request.CardNumber);
                    EPIManager.Current.CreateProcess(request.InstallationNo);

                    if (HandlerHelper.Current.IsEmployeeCardTrackingEnabled)
                    {
                        method.Info("Insert Employee card Session Details");
                        ExCommsDataContext.Current.UpdateEmployeeCardSessions(request.CardNumber, request.FaultDate, request.InstallationNo, msg_type);
                        installationDetails = request.Extra as InstallationDetailsForMSMQ;
                        ExCommsDataContext.Current.SendEmployeeSTMALert(installationDetails.Bar_Pos_No.ToString(), request.FaultDate, msg_type, request.CardNumber);

                        try
                        {
                            Audit.Transport.Audit_History m_AuditInfo = new Audit.Transport.Audit_History();
                            m_AuditInfo.AuditModuleName = ModuleName.MSMQ;
                            m_AuditInfo.Audit_Date = DateTime.Now.Date;
                            m_AuditInfo.Audit_User_ID = 0;
                            m_AuditInfo.Audit_User_Name = "System";
                            m_AuditInfo.Audit_Screen_Name = "Employee card";
                            m_AuditInfo.Audit_Desc = "Employee Card In";
                            m_AuditInfo.AuditOperationType = OperationType.ADD;
                            m_AuditInfo.Audit_Field = "EmployeecardNumber";
                            m_AuditInfo.Audit_New_Vl = request.CardNumber;
                            m_AuditInfo.Audit_Slot = request.Asset;
                            Log.Info(method.PROC, "Insert Auditing info for Employee card In Event");
                            AuditViewerBusiness.InsertAuditData(m_AuditInfo);
                        }
                        catch (Exception ex)
                        {
                            Log.Exception(ex);
                        }

                        string empflags = ExCommsDataContext.Current.GetEmployeeFlags(request.CardNumber);
                        if (!String.IsNullOrEmpty(empflags))
                        {
                            method.Info("Flags " + empflags);
                            empflags = empflags.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, request.CardNumber.PadLeft(10, '0').Length)
                                                .Where((x) => x % 2 == 0)
                                                .Select((x) => Convert.ToByte(request.CardNumber.PadLeft(10, '0').Substring(x, 2), 16))
                                                .ToList();
                            enumver.Insert(0, Convert.ToByte(empflags[0]));
                            enumver.Insert(1, Convert.ToByte(empflags[1]));
                            enumver.InsertRange(0, cardno);

                            // TODO: EPIMsgProcessor.SendCommand

                        }
                    }

                    ExCommsDataContext.Current.UpdateFloorStatus(request.InstallationNo, DateTime.Now, null, null, null, null,
                                                               null, null, null, null, request.CardNumber, request.FaultDate.ToString(), null);
                    ExCommsDataContext.Current.UpdateGameCappingDetails(request.CardNumber, 1, false);
                    try
                    {
                        if (SDTMessages.Instance.ProcessEmployeeCardIn(request))
                        {
                            EPIManager.Current.CreateInactivityTimeout(request.InstallationNo);
                            EPIManager.Current.CreateIntervalRatingTimer(request.InstallationNo);
                        }
                    }
                    finally { }
                }
                catch (Exception ex)
                {
                    retVal = false;
                    // TODO: EPIMsgProcessor.SendCommand
                    if (installationDetails != null)
                        CurrentEPIMsgProcessor.DisplayBallyWelcomeMsg(request.InstallationNo, installationDetails.Bar_Pos_Name, DateTime.Now);
                    if (cardDetail != null)
                        cardDetail.Clear();
                    Log.Exception(ex);
                }
                finally
                {
                    method.Info("Employee Card In completed for : " + request.CardNumber);
                }
            }
            return retVal;
        }