public PrintMainWindow(Invoice inv)
        {
            try
            {
                InitializeComponent();
                BillingDataDataContext db   = new BillingDataDataContext();
                List <RuntimeData>     data = UtilityClass.convertTransListToRuntimeList(db.ExecuteQuery <Transaction>(@"
                SELECT  [ID]
      ,[AmountPayed]
      ,[AmountCharged]
      ,[ConnsignmentNo]
      ,[Weight]
      ,[WeightByFranchize]
      ,[Destination]
      ,[DestinationPin]
      ,[UserId]
      ,[BookingDate]
      ,[AddDate]
      ,[LastModified]
      ,[Type]
      ,[Mode]
      ,[DOX]
      ,[ServiceTax]
      ,[SplDisc]
      ,[InvoiceNo]
      ,[InvoiceDate]
      ,[CustCode]
      ,[TransMF_No]
      ,[BilledWeight]
  FROM [BillingDatabase].[dbo].[InvoiceView]      
where [BillId] = '" + inv.BillId + @"'        
            ").ToList());
                source   = UtilityClass.convertToRuntimeVIew(data.OrderBy(x => x.BookingDate).ThenBy(z => z.ConsignmentNo).ToList());
                rs       = new ReportDataSource();
                rs.Value = source;
                if (inv.Misc == null)
                {
                    inv.Misc = 0;
                }
                if (inv.PreviousDue == null)
                {
                    inv.PreviousDue = 0;
                }

                Client clc = DataSources.ClientCopy.SingleOrDefault(x => x.CLCODE == inv.ClientCode);
                List <ReportParameter> repParams = new List <ReportParameter>();
                DateTime FromDate   = data.Min(x => x.BookingDate);
                DateTime ToDate     = data.Max(x => x.BookingDate);
                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}", inv.Basic)));
                repParams.Add(new ReportParameter("DiscountPString", String.Format("{0:0.00}", inv.Discount)));
                repParams.Add(new ReportParameter("FuelString", String.Format("{0:0.00}", inv.Fuel)));
                repParams.Add(new ReportParameter("FuelAmount", String.Format("{0:0.00}", inv.fuelAmount)));
                repParams.Add(new ReportParameter("ServiceTaxString", String.Format("{0:0.00}", inv.STax)));
                repParams.Add(new ReportParameter("ServiceTaxAmount", String.Format("{0:0.00}", inv.taxAmount)));
                repParams.Add(new ReportParameter("DiscountAmountString", String.Format("{0:0.00}", inv.discountAmount)));
                repParams.Add(new ReportParameter("SWC", String.Format("{0:0.00}", inv.SWC)));
                repParams.Add(new ReportParameter("MiscellaneousAmountString", String.Format("{0:0.00}", inv.Misc)));
                repParams.Add(new ReportParameter("TNC", Configs.Default.TNC));
                repParams.Add(new ReportParameter("TotalAmountString", String.Format("{0:0.00}", inv.totalAmount)));
                repParams.Add(new ReportParameter("TotalAmountInWordString", UtilityClass.NumbersToWords((int)Math.Round(inv.totalAmount))));
                if (inv.PreviousDue == 0 || inv.PreviousDue == null)
                {
                    repParams.Add(new ReportParameter("PreviousDueString", ""));
                }
                else
                {
                    repParams.Add(new ReportParameter("PreviousDueString", String.Format("{0:0.00}", inv.PreviousDue)));
                    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("TinNumber", Configs.Default.Tin ?? ""));
                repParams.Add(new ReportParameter("ClientName", clc.CLNAME));
                repParams.Add(new ReportParameter("ClientAddress", clc.ADDRESS));
                repParams.Add(new ReportParameter("ClientPhoneNo", clc.CONTACTNO));
                repParams.Add(new ReportParameter("ServiceTaxNumber", Configs.Default.ServiceTaxno ?? ""));

                // repParams.Add(new ReportParameter("Tinnumber", Configs.Default.Tin));
                DateTime invDateTime;
                if (inv.BillId.Length < 14)
                {
                    invDateTime = DateTime.ParseExact(inv.BillId, "yyyyMMddhhmm", CultureInfo.InvariantCulture);
                }
                else
                {
                    invDateTime = DateTime.ParseExact(inv.BillId, "yyyyMMddhhmmss", CultureInfo.InvariantCulture);
                }
                repParams.Add(new ReportParameter("InvoiceDate", invDateTime.ToString("dd-MMM-yyyy")));

                repParams.Add(new ReportParameter("InvoiceNumber", inv.BillId));
                BillViewer.LocalReport.ReportPath = "Report1.rdlc";
                BillViewer.LocalReport.DataSources.Clear();
                rs.Name = "DataSet1";
                BillViewer.LocalReport.DataSources.Add(rs);
                BillViewer.LocalReport.SetParameters(repParams);
                BillViewer.LocalReport.DisplayName = inv.ClientName + "-" + inv.BillId;
                BillViewer.RefreshReport();
            }
            catch (Exception)
            {
                MessageBox.Show("Error opening file.");
                this.Close();
            }
        }
        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();
        }