private void FetchInvoiceButton_Click(object sender, RoutedEventArgs e)
        {
            if (InvoiceDatagrid.SelectedItems.Count != 1)
            {
                MessageBox.Show("Please select one row to view the invoice details.");
                return;
            }
            Invoice inv = (Invoice)InvoiceDatagrid.SelectedItem;
            BillingDataDataContext db     = new BillingDataDataContext();
            PrintMainWindow        window = new PrintMainWindow(inv);

            try
            {
                window.Show();
            }catch (InvalidOperationException)
            {
                MessageBox.Show("Unable to open invoice");
            }
        }
        private void printMIS()
        {
            string errorMsg = "";

            if (ToDate.SelectedDate == null || FromDate.SelectedDate == null || ToDate.SelectedDate < FromDate.SelectedDate)
            {
                errorMsg += "Please set the date properly. \n";
            }
            Client selectedClient     = (Client)ClientList.SelectedItem;
            BillingDataDataContext db = new BillingDataDataContext();

            if (errorMsg != "")
            {
                MessageBox.Show(errorMsg);
                return;
            }

            List <MISReportView> source = db.MISReportViews.Where(x => x.CLCODE == selectedClient.CLCODE && x.BookingDate <= ToDate.SelectedDate && x.BookingDate >= FromDate.SelectedDate).ToList();

            if (SubClientComboBox.Text != null && SubClientComboBox.Text != "")
            {
                source = source.Where(x => x.SubClient == SubClientComboBox.Text).ToList();
            }
            ReportDataSource rs = new ReportDataSource();

            rs.Value = source;
            rs.Name  = "DataSet1";
            List <ReportParameter> repParams = new List <ReportParameter>();

            repParams.Add(new ReportParameter("ClientName", selectedClient.CLNAME + " " + SubClientComboBox.Text));
            repParams.Add(new ReportParameter("ClientAddress", selectedClient.ADDRESS));
            repParams.Add(new ReportParameter("ClientPhoneNo", selectedClient.CONTACTNO));
            repParams.Add(new ReportParameter("FromDate", ((DateTime)(FromDate.SelectedDate)).ToString()));
            repParams.Add(new ReportParameter("ToDate", ((DateTime)(ToDate.SelectedDate)).ToString()));
            PrintMainWindow window = new PrintMainWindow(rs, repParams, true);

            window.Show();
        }
        private void printObj(Client client = null)
        {
            #region temp
            string errorMsg = "";
            if (ToDate.SelectedDate == null || FromDate.SelectedDate == null || ToDate.SelectedDate < FromDate.SelectedDate)
            {
                errorMsg += "Please set the date properly. \n";
            }
            if (ServiceTaxBox.Text == "")
            {
                ServiceTaxBox.Text = "0";
            }
            double temp;
            if (TaxBox.Text == "")
            {
                TaxBox.Text = "0";
            }
            if (MiscBox.Text == "")
            {
                MiscBox.Text = "0";
            }
            if (PreviousDueTextBox.Text == "")
            {
                PreviousDueTextBox.Text = "0";
            }
            if (double.TryParse(TaxBox.Text, out temp) == false)
            {
                errorMsg += "Please enter fuel surcharge correctly. \n";
            }
            if (double.TryParse(ServiceTaxBox.Text, out temp) == false)
            {
                errorMsg += "Please enter service tax correctly. \n";
            }
            if (double.TryParse(MiscBox.Text, out temp) == false)
            {
                errorMsg += "Please enter miscellenaeous charge correctly. \n";
            }
            if (double.TryParse(PreviousDueTextBox.Text, out temp) == false)
            {
                errorMsg += "Please enter previous charge correctly. \n";
            }
            if (double.TryParse(DiscountBox.Text, out temp) == false)
            {
                errorMsg += "Enter customer discount properly. \n";
            }
            if (errorMsg != "")
            {
                MessageBox.Show(errorMsg);
                return;
            }
            #endregion
            invoice = new FinalUi.Invoice();
            BillingDataDataContext db = new BillingDataDataContext();
            source = UtilityClass.convertToRuntimeVIew(dataGridSource).Where(x => x.CustCode == ((Client)ClientList.SelectedItem).CLCODE && x.BookingDate <= ToDate.SelectedDate && x.BookingDate >= FromDate.SelectedDate).OrderBy(y => y.BookingDate).ThenBy(z => z.ConsignmentNo).ToList();
            if (SubClientComboBox.Text == "")
            {
                source = source.Where(x => x.SubClient == "" || x.SubClient == null).ToList();
            }
            else
            {
                source = source.Where(x => x.SubClient == SubClientComboBox.Text).ToList();
            }
            rs.Value = source;
            Client curClient;
            if (client == null)
            {
                curClient = ((Client)ClientList.SelectedItem);
            }
            else
            {
                curClient = client;
            }
            invoice.Basic      = (double)(source.Sum(x => x.FrAmount) ?? 0);
            invoice.ClientCode = curClient.CLCODE;
            invoice.Discount   = double.Parse(DiscountBox.Text);
            invoice.Fuel       = double.Parse(TaxBox.Text);
            invoice.STax       = double.Parse(ServiceTaxBox.Text);
            List <ReportParameter> repParams = new List <ReportParameter>();
            DateTime toDate     = ToDate.SelectedDate ?? DateTime.Today;
            DateTime fromDate   = FromDate.SelectedDate ?? DateTime.Today;
            string   dateString = fromDate.ToString("dd/MM/yyyy") + " to " + toDate.ToString("dd/MM/yyyy");
            repParams.Add(new ReportParameter("DateString", dateString));
            string descriptionString = "Total Consignments: " + source.Count;
            repParams.Add(new ReportParameter("DescriptionString", descriptionString));
            repParams.Add(new ReportParameter("MainAmountString", String.Format("{0:0.00}", invoice.Basic)));
            repParams.Add(new ReportParameter("FuelString", TaxBox.Text));
            repParams.Add(new ReportParameter("ServiceTaxString", String.Format("{0:0.00}", double.Parse(ServiceTaxBox.Text))));
            repParams.Add(new ReportParameter("DiscountPString", String.Format("{0:0.00}", double.Parse(DiscountBox.Text))));
            repParams.Add(new ReportParameter("MiscellaneousAmountString", MiscBox.Text));
            double temp2;
            if (double.TryParse(MiscBox.Text, out temp2))
            {
                invoice.Misc = temp2;
            }
            repParams.Add(new ReportParameter("DiscountAmountString", String.Format("{0:0.00}", invoice.discountAmount)));
            repParams.Add(new ReportParameter("FuelAmount", String.Format("{0:0.00}", invoice.fuelAmount)));
            repParams.Add(new ReportParameter("ServiceTaxAmount", String.Format("{0:0.00}", invoice.taxAmount)));
            repParams.Add(new ReportParameter("SWC", String.Format("{0:0.00}", invoice.SWC)));
            if (PreviousDueCheck.Checked == true)
            {
                invoice.PreviousDue = double.Parse(PreviousDueTextBox.Text);
            }
            repParams.Add(new ReportParameter("TotalAmountString", String.Format("{0:0.00}", invoice.totalAmount)));
            string totalAmountinWordString = UtilityClass.NumbersToWords((int)Math.Round(invoice.totalAmount));
            repParams.Add(new ReportParameter("TotalAmountInWordString", totalAmountinWordString));
            if (PreviousDueCheck.Checked == true)
            {
                repParams.Add(new ReportParameter("PreviousDueString", PreviousDueTextBox.Text));
                repParams.Add(new ReportParameter("PreviousDueCheck", "Previous Due .:"));
            }
            repParams.Add(new ReportParameter("CompanyName", Configs.Default.CompanyName));
            repParams.Add(new ReportParameter("ComapnyPhoneNo", Configs.Default.CompanyPhone));
            repParams.Add(new ReportParameter("CompanyAddress", Configs.Default.CompanyAddress));
            repParams.Add(new ReportParameter("CompanyEmail", Configs.Default.CompanyEmail));
            repParams.Add(new ReportParameter("CompanyFax", Configs.Default.CompanyFax));
            repParams.Add(new ReportParameter("ClientName", curClient.CLNAME + " " + SubClientComboBox.Text ?? " "));
            repParams.Add(new ReportParameter("ClientAddress", curClient.ADDRESS));
            repParams.Add(new ReportParameter("ClientPhoneNo", curClient.CONTACTNO));
            repParams.Add(new ReportParameter("TinNumber", Configs.Default.Tin ?? ""));
            repParams.Add(new ReportParameter("TNC", Configs.Default.TNC));
            repParams.Add(new ReportParameter("ServiceTaxNumber", Configs.Default.ServiceTaxno ?? ""));
            invoice.BillId  = (InvoiceDate.SelectedDate ?? DateTime.Today).ToString("yyyyMMdd");
            invoice.Date    = InvoiceDate.SelectedDate ?? DateTime.Today;
            invoice.BillId  = invoice.BillId + DateTime.Now.ToString("hhmmss");
            invoice.Remarks = RemarkBox.Text;

            invoice.TotalAmount = invoice.totalAmount;
            repParams.Add(new ReportParameter("InvoiceNumber", invoice.BillId));
            repParams.Add(new ReportParameter("InvoiceDate", (InvoiceDate.SelectedDate ?? DateTime.Today).ToString("dd-MMM-yyyy")));
            PrintMainWindow win = new PrintMainWindow(rs, repParams);
            win.Show();
        }