private void btnClearBills_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (bStartClicked)
                {
                    //objNoteCumTktScanLib.CloseSerialCom();
                    MessageBox.ShowBox("MessageID355", BMC_Icon.Error);
                    return;
                }
                objBills.Clear();
                BillsDict.Clear();
                if (oBillDenoms != null)
                    oBillDenoms = null;
                lvBills.ItemsSource = null;
                txtTotalBills.Text = string.Empty;
            }
            catch (Exception Ex)
            {

                ExceptionManager.Publish(Ex);
            }
        }
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                if (bStartClicked)
                {

                    bIsUncommitted = true;
                    //string sNotesString = "TICKET:100100000000429685,TICKET:100100000000434979,TICKET:100100000000567875,TICKET:100100000000573265,TICKET:101000010000013362,TICKET:101000011000011440,TICKET:101000011000025478,TICKET:101000011000035880,TICKET:101000011000040730,TICKET:101000011000056618,ONES:1,TWOS:0,FIVES:1,TENS:1,TWENTIES:1,FIFTIES:1,HUNDREDS:1,";
                    //string sNotesString = "TICKET:101200004000214537,ONES:1,TWENTIES:1,FIFTIES:1,";

                    string sNotesString = string.Empty;

                    LogManager.WriteLog("CloseSerialCom() CALL", LogManager.enumLogLevel.Info);
                    objNoteCumTktScanLib.CloseSerialCom();
                    LogManager.WriteLog("CloseSerialCom() ACK", LogManager.enumLogLevel.Info);

                    LogManager.WriteLog("GetString() CALL", LogManager.enumLogLevel.Info);
                    objNoteCumTktScanLib.GetString(out sNotesString);
                    LogManager.WriteLog("GetString() ACK", LogManager.enumLogLevel.Info);

                    LogManager.WriteLog(sNotesString, LogManager.enumLogLevel.Info);

                   //if (_CurrentCollectionIndex==1)
                   // sNotesString = "TICKET:155500502000094416,TICKET:155500509000091859,TICKET:155500512000098672,ONES:1,TWOS:0,FIVES:1,TENS:1,TWENTIES:1,FIFTIES:1,HUNDREDS:1";
                   //else
                   // sNotesString = "TICKET:155500506000096290,TICKET:155500519000134672,TICKET:155500522000090600";
                    //sNotesString = "TICKET:155500554000092150,TICKET:155500559000111809,TICKET:155500904000133427,TICKET:55500560000090821,TICKET:155500754000094164,TICKET:155500776000092048";
                    //sNotesString = "TICKET:555500003000186248,TICKET:555500003000173743,TICKET:555500003000161115,TICKET:555500003000158641,TICKET:555500003000140721,TICKET:555500002000137694,TICKET:555500003000126343,TICKET:555500003000117037,TICKET:555500003000105065,TICKET:555500003000094567";
                    //sNotesString = "TICKET:555500003000042162,TICKET:102000002000084357,TICKET:102000000000141315,TICKET:555500000000083959,TICKET:101200282000074881,TICKET:102000000000132924,TICKET:101200282000069405,TICKET:101200282000059680,TICKET:101200000005945148,TICKET:101200000005930052";
                    bStartClicked = false;
                    bNoteCounterFinished = true;
                    btnStart.Content = Application.Current.FindResource("BillsTicketCounter_xaml_btnStart") as string;//"Start Counter";


                    string[] stemp = sNotesString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    string[] NameValuePair;

                    string sTemp = string.Empty;
                    string sCurrencySymbol = sTemp.GetCurrencySymbol();


                    foreach (var Entry in stemp)
                    {
                        NameValuePair = Entry.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                        switch (NameValuePair[0])
                        {
                            case "TICKET":
                                {
                                    sTickets += "," + NameValuePair[1];
                                    break;
                                }
                            case "ONES":
                                {
                                    if (!BillsDict.ContainsKey("ONES"))
                                        BillsDict.Add("ONES", Convert.ToInt64(NameValuePair[1]));
                                    else
                                        BillsDict["ONES"] = Convert.ToInt64(BillsDict["ONES"]) + Convert.ToInt64(NameValuePair[1]);
                                    break;
                                }
                            case "TWOS":
                                {
                                    if (!BillsDict.ContainsKey("TWOS"))
                                        BillsDict.Add("TWOS", Convert.ToInt64(NameValuePair[1]) * 2);
                                    else
                                        BillsDict["TWOS"] = Convert.ToInt64(BillsDict["TWOS"]) + (Convert.ToInt64(NameValuePair[1]) * 2);

                                    break;
                                }
                            case "FIVES":
                                {
                                    if (!BillsDict.ContainsKey("FIVES"))
                                        BillsDict.Add("FIVES", Convert.ToInt64(NameValuePair[1]) * 5);
                                    else
                                        BillsDict["FIVES"] = Convert.ToInt64(BillsDict["FIVES"]) + (Convert.ToInt64(NameValuePair[1]) * 5);

                                    break;
                                }
                            case "TENS":
                                {
                                    if (!BillsDict.ContainsKey("TENS"))
                                        BillsDict.Add("TENS", Convert.ToInt64(NameValuePair[1]) * 10);
                                    else
                                        BillsDict["TENS"] = Convert.ToInt64(BillsDict["TENS"]) + (Convert.ToInt64(NameValuePair[1]) * 10);
                                    break;
                                }
                            case "TWENTIES":
                                {
                                    if (!BillsDict.ContainsKey("TWENTIES"))
                                        BillsDict.Add("TWENTIES", Convert.ToInt64(NameValuePair[1]) * 20);
                                    else
                                        BillsDict["TWENTIES"] = Convert.ToInt64(BillsDict["TWENTIES"]) + (Convert.ToInt64(NameValuePair[1]) * 20);
                                    break;
                                }
                            case "FIFTIES":
                                {
                                    if (!BillsDict.ContainsKey("FIFTIES"))
                                        BillsDict.Add("FIFTIES", Convert.ToInt64(NameValuePair[1]) * 50);
                                    else
                                        BillsDict["FIFTIES"] = Convert.ToInt64(BillsDict["FIFTIES"]) + (Convert.ToInt64(NameValuePair[1]) * 50);
                                    break;
                                }
                            case "HUNDREDS":
                                {
                                    if (!BillsDict.ContainsKey("HUNDREDS"))
                                        BillsDict.Add("HUNDREDS", Convert.ToInt64(NameValuePair[1]) * 100);
                                    else
                                        BillsDict["HUNDREDS"] = Convert.ToInt64(BillsDict["HUNDREDS"]) + (Convert.ToInt64(NameValuePair[1]) * 100);
                                    break;
                                }
                            case "TWO_HUNDREDS":
                                {
                                    if (!BillsDict.ContainsKey("TWO_HUNDREDS"))
                                        BillsDict.Add("TWO_HUNDREDS", Convert.ToInt64(NameValuePair[1]) * 200);
                                    else
                                        BillsDict["TWO_HUNDREDS"] = Convert.ToInt64(BillsDict["HUNDREDS"]) + (Convert.ToInt64(NameValuePair[1]) * 200);
                                    break;
                                }
                            case "FIVE_HUNDREDS":
                                {
                                    if (!BillsDict.ContainsKey("FIVE_HUNDREDS"))
                                        BillsDict.Add("FIVE_HUNDREDS", Convert.ToInt64(NameValuePair[1]) * 500);
                                    else
                                        BillsDict["FIVE_HUNDREDS"] = Convert.ToInt64(BillsDict["HUNDREDS"]) + (Convert.ToInt64(NameValuePair[1]) * 500);
                                    break;
                                }
                            default:
                                break;
                        }
                    }

                    if (BillsDict.Count > 0)
                    {
                        objBills = new List<Bills>();
                        nTotal = 0;

                        string[] sCurrencyList;

                        //if (ExtensionMethods.CurrentSiteCulture == "it-IT")
                        //    sCurrencyList = new string[] { "FIVES", "TENS", "TWENTIES", "FIFTIES", "HUNDREDS", "TWO_HUNDREDS", "FIVE_HUNDREDS" };
                        //else
                        //    sCurrencyList = new string[] { "ONES", "TWOS", "FIVES", "TENS", "TWENTIES", "FIFTIES", "HUNDREDS" };

                        switch (ExtensionMethods.CurrentSiteCulture)
                        {
                            case "it-IT":
                                sCurrencyList = new string[] { "FIVES", "TENS", "TWENTIES", "FIFTIES", "HUNDREDS", "TWO_HUNDREDS", "FIVE_HUNDREDS" };
                                break;
                            case "es-ar":
                                sCurrencyList = new string[] { "TWOS", "FIVES", "TENS", "TWENTIES", "FIFTIES", "HUNDREDS", "TWO_HUNDREDS", "FIVE_HUNDREDS" };
                                break;
                            default:
                                sCurrencyList = new string[] { "ONES", "TWOS", "FIVES", "TENS", "TWENTIES", "FIFTIES", "HUNDREDS" };
                                break;
                        }

                        oBillDenoms = new BillDenoms();

                        foreach (var Denom in sCurrencyList)
                        {
                            if (BillsDict.ContainsKey(Denom))
                            {
                                nTotal += Convert.ToInt32(BillsDict[Denom]);
                                switch (Denom)
                                {
                                    case "ONES":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 1",
                                                Count = "",
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                                Value = BillsDict[Denom].ToString()

                                            });
                                            oBillDenoms.ONES = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    case "TWOS":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 2",
                                                Count = "",
                                                Value = BillsDict[Denom].ToString()
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                            });
                                            oBillDenoms.TWOS = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    case "FIVES":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 5",
                                                Count = "",
                                                Value = BillsDict[Denom].ToString()
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                            });
                                            oBillDenoms.FIVES = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    case "TENS":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 10",
                                                Count = "",
                                                Value = BillsDict[Denom].ToString()
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                            });
                                            oBillDenoms.TENS = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    case "TWENTIES":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 20",
                                                Count = "",
                                                Value = BillsDict[Denom].ToString()
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                            });
                                            oBillDenoms.TWENTIES = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    case "FIFTIES":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 50",
                                                Count = "",
                                                Value = BillsDict[Denom].ToString()
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                            });
                                            oBillDenoms.FIFTIES = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    case "HUNDREDS":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 100",
                                                Count = "",
                                                Value = BillsDict[Denom].ToString()
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                            });
                                            oBillDenoms.HUNDREDS = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    case "TWO_HUNDREDS":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 200",
                                                Count = "",
                                                Value = BillsDict[Denom].ToString()
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                            });
                                            oBillDenoms.TWO_HUNDREDS = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    case "FIVE_HUNDREDS":
                                        {
                                            objBills.Add(new Bills
                                            {
                                                Bill = sCurrencySymbol + " 500",
                                                Count = "",
                                                Value = BillsDict[Denom].ToString()
                                                //Value = sCurrencySymbol + " " + BillsDict[Denom].ToString()
                                            });
                                            oBillDenoms.FIVE_HUNDREDS = BillsDict[Denom].ToString();
                                            break;
                                        }
                                    default:
                                        break;

                                }
                            }
                        }

                        if (objBills.Count > 0)
                        {
                            bBillsAvailable = true;
                            lvBills.ItemsSource = objBills;
                            if (nTotal > 0)
                                txtTotalBills.Text = sCurrencySymbol + " " + nTotal.ToString();
                            lblcounterWarning.Text = string.Empty;
                        }

                    }
                    else
                        //MessageBox.ShowBox("MessageID357", BMC_Icon.Error);
                        lblcounterWarning.Text = "*" + Application.Current.FindResource("MessageID357") as string;

                    if (!sTickets.IsNullOrEmpty())
                    {
                        this.RefreshTickets();
                    }
                    else
                    {
                        //MessageBox.ShowBox("MessageID347", BMC_Icon.Error);
                        if (bBillsAvailable == false)
                        {
                            lblcounterWarning.Text = lblcounterWarning.Text + ((lblcounterWarning.Text.Length != 0) ? "   *" : string.Empty) + Application.Current.FindResource("MessageID347") as string;
                            return; // Return here to avoid showing save changes message in case no bill are voucher found. 
                        }
                        else
                        {
                            lblcounterWarning.Text = Application.Current.FindResource("MessageID347") as string;
                        }
                        //lblcounterWarning.Visibility = Visibility.Collapsed;
                    }
                    lblcounterWarning.Text = lblcounterWarning.Text + ((lblcounterWarning.Text.Length != 0) ? "   *" : string.Empty) + Application.Current.FindResource("MessageID430") as string;
                }
                else
                {
                    bNoteCounterFinished = false;
                    btnExceptionTickets.Visibility = Visibility.Collapsed;

                    LogManager.WriteLog("OpenSerialComPort() CALL", LogManager.enumLogLevel.Info);
                    if (objNoteCumTktScanLib.OpenSerialComPort(Settings.BillVoucherCounterCOMPort) != 0)
                    {
                        LogManager.WriteLog("OpenSerialComPort() NACK", LogManager.enumLogLevel.Info);
                        LogManager.WriteLog("CloseSerialCom() CALL", LogManager.enumLogLevel.Info);
                        objNoteCumTktScanLib.CloseSerialCom();
                        LogManager.WriteLog("CloseSerialCom() ACK", LogManager.enumLogLevel.Info);
                        MessageBox.ShowBox("MessageID295", BMC_Icon.Error);
                        return;//MessageBox unable to open COM Port-MessageID295

                    }
                    if (ExtensionMethods.CurrentSiteCulture == "en-US")
                    {
                        objNoteCumTktScanLib.SetDenom(1); //en-US-1, Euro-2,
                        LogManager.WriteLog("SetDenom(1) en-US", LogManager.enumLogLevel.Info);
                    }
                    else
                    {
                        objNoteCumTktScanLib.SetDenom(2);
                        LogManager.WriteLog("SetDenom(2) it-IT", LogManager.enumLogLevel.Info);
                    }

                    LogManager.WriteLog("OpenSerialComPort() ACK", LogManager.enumLogLevel.Info);
                    LogManager.WriteLog("StartRead() CALL", LogManager.enumLogLevel.Info);
                    objNoteCumTktScanLib.StartRead();
                    LogManager.WriteLog("StartRead() ACK", LogManager.enumLogLevel.Info);
                    bStartClicked = true;
                    btnStart.Content = Application.Current.FindResource("BillsTicketCounter_xaml_btnStop") as string;//"Stop Counter";
                    //Message:Please remove the Bills & Vouchers from the Currency Counter.
                    //MessageBox.ShowBox("MessageID352", BMC_Icon.Information, BMC_Button.OK);
                    lblcounterWarning.Text = Application.Current.FindResource("MessageID352") as string;

                }
            }
            catch (Exception Ex)
            {
                LogManager.WriteLog("Exception Thrown is Start/Stop Button Click", LogManager.enumLogLevel.Debug);
                //MessageBox.ShowBox("MessageID295", BMC_Icon.Error);
                if (!string.IsNullOrEmpty(Ex.Message))
                {
                    MessageBox.ShowBox(Ex.Message, BMC_Icon.Error, true);
                }
                ExceptionManager.Publish(Ex);
                btnStart.Content = "Start Counter";

            }
            finally
            {
                btnStart.IsEnabled = true;
                this.IsCounterStarted = bStartClicked;
            }
        }
        void ClearAll()
        {
            try
            {

                LogManager.WriteLog("BillsTicketCounter->ClearAll()", LogManager.enumLogLevel.Debug);

                if (bIsUncommitted)
                {
                    RevertExceptionTickets();
                    bIsUncommitted = false;
                }
                if (oBillDenoms != null)
                    oBillDenoms = null;
                lblcounterWarning.Text = string.Empty;
                objBills.Clear();
                lvBills.ItemsSource = null;
                txtTotalBills.Text = string.Empty;

                if (lsValidTicketsHolder != null)
                    lsValidTicketsHolder.Clear();
                if (BillsDict != null)
                    BillsDict.Clear();

                lvTickets.ItemsSource = null;
                lvInValidTickets.ItemsSource = null;
                sTickets = string.Empty;
                txtTotal.Text = string.Empty;
                txtQuantity.Text = string.Empty;
                txtQuantityIn.Text = string.Empty;
            }
            catch (Exception Ex)
            {

                ExceptionManager.Publish(Ex);
            }
        }
        void SaveAll()
        {

            LogManager.WriteLog("BillsTicketCounter->SaveAll()" + lstCollections[_CurrentCollectionIndex].CollectionNo.ToString(), LogManager.enumLogLevel.Debug);

            if (Settings.HANDLE_EXCEPTIONTICKETS_COUNTER)
            {
                _objCollectionHelper.DiscardExceptionVoucherChanges(lstCollections[_CurrentCollectionIndex].CollectionNo, lstCollections[_CurrentCollectionIndex].InstallationNo, false);
            }

            if (!this.txtTotal.Text.IsNullOrEmpty())
            {

                foreach (var listitem in this.lsValidTicketsHolder)
                {
                    int? i = 0;
                    _objCollectionHelper.InsertDeclaredTicket(listitem.strBarcode, Convert.ToDecimal(listitem.iAmount) / 100,
                                                                SecurityHelper.CurrentUser.SecurityUserID,
                                                                 0, 0, lstCollections[_CurrentCollectionIndex].InstallationNo, iCollectionNo, ref i);
                    _objCollectionHelper.UpdateVoucherCollection(listitem.strBarcode, "1");
                }
            }

            if (oBillDenoms == null)
            {
                oBillDenoms = new BillDenoms();
                oBillDenoms.FIVE_HUNDREDS = lstCollections[_CurrentCollectionIndex].P50000.ToString();
                oBillDenoms.TWO_HUNDREDS = lstCollections[_CurrentCollectionIndex].P20000.ToString();
                oBillDenoms.HUNDREDS = lstCollections[_CurrentCollectionIndex].P10000.ToString();
                oBillDenoms.FIFTIES = lstCollections[_CurrentCollectionIndex].P5000.ToString();
                oBillDenoms.TWENTIES = lstCollections[_CurrentCollectionIndex].P2000.ToString();
                oBillDenoms.TENS = lstCollections[_CurrentCollectionIndex].P1000.ToString();
                oBillDenoms.FIVES = lstCollections[_CurrentCollectionIndex].P500.ToString();
                oBillDenoms.TWOS = lstCollections[_CurrentCollectionIndex].P200.ToString();
                oBillDenoms.ONES = lstCollections[_CurrentCollectionIndex].P100.ToString();
            }
            _objCollectionHelper.AddCollectionToFullCollection(oBillDenoms.FIVE_HUNDREDS.EmptytoZero().GetCurrencyValueAsString(),
                oBillDenoms.TWO_HUNDREDS.EmptytoZero().GetCurrencyValueAsString(), oBillDenoms.HUNDREDS.EmptytoZero().GetCurrencyValueAsString(), oBillDenoms.FIFTIES.EmptytoZero().GetCurrencyValueAsString(),
                oBillDenoms.TWENTIES.EmptytoZero().GetCurrencyValueAsString(), oBillDenoms.TENS.EmptytoZero().GetCurrencyValueAsString(), oBillDenoms.FIVES.EmptytoZero().GetCurrencyValueAsString(),
               oBillDenoms.TWOS.EmptytoZero().GetCurrencyValueAsString(), oBillDenoms.ONES.EmptytoZero().GetCurrencyValueAsString(), lstCollections[_CurrentCollectionIndex].TotalCoins.GetCurrencyValueAsString(),
               txtTotal.Text.GetCurrencyValueAsString(),
               lstCollections[_CurrentCollectionIndex].Installation_Token_Value,
               lstCollections[_CurrentCollectionIndex].CollectionNo);
            bIsUncommitted = false;
            LogManager.WriteLog("BillsTicketCounter->SaveAll() Complete" + lstCollections[_CurrentCollectionIndex].CollectionNo.ToString(), LogManager.enumLogLevel.Debug);
            RefreshData(_CurrentCollectionIndex);


        }