Exemplo n.º 1
0
 private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (listView1.SelectedIndex == -1)
     {
         idx = null;
     }
     else
     {
         int ID = transactions.IndexOf((FinancialTransaction)e.AddedItems[0]);
         FinancialTransaction c = transactions[ID];
         idx = c.DOC_NUM;
     }
     e.Handled = true;
 }
Exemplo n.º 2
0
 public bool VoidTransaction(int docNum)
 {
     try
     {
         using (ExpressTaxi ctx = new ExpressTaxi(conn))
         {
             FinancialTransaction t = ctx.FinancialTransactions.SingleOrDefault(r => r.DOC_NUM == docNum);
             if (t != null)
             {
                 t.IsValid = false;
                 ctx.SubmitChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         log.Error(ex);
     }
     return(false);
 }
Exemplo n.º 3
0
        private bool ExportReport(ReportType type, string outname, string fmt)
        {
            try
            {
                string deviceInfo =
                    "<DeviceInfo>" +
                    " <OutputFormat>" + fmt + "</OutputFormat>" +
                    " <PageWidth>21cm</PageWidth>" +
                    " <PageHeight>25cm</PageHeight>" +
                    " <MarginTop>2cm</MarginTop>" +
                    " <MarginLeft>2cm</MarginLeft>" +
                    " <MarginRight>2cm</MarginRight>" +
                    " <MarginBottom>2cm</MarginBottom>" +
                    "</DeviceInfo>";
                Warning[]   warnings;
                string[]    streams;
                byte[]      bytes;
                string      reportType        = fmt;
                string      mimeType          = "";
                string      encoding          = "";
                string      fileNameExtension = "";
                LocalReport _reportViewer     = new LocalReport();
                if (ReportType.REPORT_COMAPNY_LIST.Equals(type))
                {
                    #region COMPANY LIST REPORT CREATION LOGIC
                    using (ExpressTaxi ctx = new ExpressTaxi(conn))
                    {
                        var query = from c in ctx.Companies orderby c.CMP_COD select c;
                        if (query.Count() > 0)
                        {
                            ReportDataset dataset = new ReportDataset();
                            foreach (Company c in query)
                            {
                                dataset.Tables["Company"].Rows.Add(
                                    new object[]
                                {
                                    (int)c.CMP_COD,
                                    (string)c.CMP_NAME,
                                    (string)c.CMP_ADDRESS,
                                    (string)c.VIL_NAME,
                                    (string)c.PAR_NAME,
                                    (string)c.COU_NAME,
                                    (string)c.CMP_PHONE
                                }
                                    );
                            }
                            dataset.AcceptChanges();
                            _reportViewer.ReportEmbeddedResource = "ExpressTMS.CompanyList.rdlc";

                            ReportParameter[] param = new ReportParameter[4];
                            param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                            param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                            param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                            param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                            _reportViewer.SetParameters(param);
                            ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["Company"]);
                            _reportViewer.DataSources.Clear();
                            _reportViewer.DataSources.Add(datasource);

                            bytes = _reportViewer.Render(
                                reportType,
                                deviceInfo,
                                out mimeType,
                                out encoding,
                                out fileNameExtension,
                                out streams,
                                out warnings);

                            FileStream fs = new FileStream(outname,
                                                           FileMode.Create);
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();
                            return(true);
                        }
                    }
                    #endregion
                }
                else if (ReportType.REPORT_DRIVER_LIST.Equals(type))
                {
                    #region DRIVER LIST REPORT CREATION LOGIC
                    using (ExpressTaxi ctx = new ExpressTaxi(conn))
                    {
                        var query = from c in ctx.Drivers orderby c.DRV_COD select c;
                        if (query.Count() > 0)
                        {
                            ReportDataset dataset = new ReportDataset();
                            foreach (Driver c in query)
                            {
                                dataset.Tables["Driver"].Rows.Add(
                                    new object[]
                                {
                                    (int)c.DRV_COD,
                                    (string)c.DRV_NAME,
                                    (string)c.DRV_ADDRESS,
                                    (string)c.VIL_NAME,
                                    (string)c.PAR_NAME,
                                    (string)c.COU_NAME,
                                    (string)c.DRV_PHONE,
                                    (string)c.DRV_LICENSE
                                }
                                    );
                            }
                            dataset.AcceptChanges();
                            _reportViewer.ReportEmbeddedResource = "ExpressTMS.DriverList.rdlc";

                            ReportParameter[] param = new ReportParameter[4];
                            param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                            param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                            param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                            param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                            _reportViewer.SetParameters(param);

                            ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["Driver"]);
                            _reportViewer.DataSources.Clear();
                            _reportViewer.DataSources.Add(datasource);

                            bytes = _reportViewer.Render(
                                reportType,
                                deviceInfo,
                                out mimeType,
                                out encoding,
                                out fileNameExtension,
                                out streams,
                                out warnings);

                            FileStream fs = new FileStream(outname,
                                                           FileMode.Create);
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();
                            return(true);
                        }
                    }
                    #endregion
                }
                else if (ReportType.REPORT_SERVICES_CURRENT_DAY.Equals(type))
                {
                    #region SERVICES CURRENT DAY CREATION LOGIC
                    using (ExpressTaxi ctx = new ExpressTaxi(conn))
                    {
                        var query = from c in ctx.FinancialTransactions
                                    where
                                    c.TRANS_DATE >= startPeriod &&
                                    c.TRANS_DATE <= endPeriod && c.IsValid
                                    orderby c.TRANS_COD
                                    select c;
                        if (query.Count() > 0)
                        {
                            ReportDataset dataset = new ReportDataset();
                            foreach (FinancialTransaction c in query)
                            {
                                if (c.IsValid)
                                {
                                    dataset.Tables["ServicesCurrentDay"].Rows.Add(
                                        new object[]
                                    {
                                        (int)c.DOC_NUM,
                                        (string)c.Driver.DRV_LICENSE,
                                        (string)c.Driver.DRV_NAME,
                                        (string)c.Company.CMP_NAME,
                                        (string)c.TRANS_DESTINATION,
                                        (string)c.DOC_TYPE_NAME,
                                        (string)c.DOCUMENT_DATE.ToString("dd MMM yyyy"),
                                        (decimal)c.TRANS_VALUE,
                                        (decimal)c.TRANS_FINAL_VALUE
                                    }
                                        );
                                }
                            }
                            dataset.AcceptChanges();
                            _reportViewer.ReportEmbeddedResource = "ExpressTMS.ServicesCurrentDay.rdlc";

                            ReportParameter[] param = new ReportParameter[6];
                            param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                            param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                            param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                            param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                            param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                            param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                            _reportViewer.SetParameters(param);
                            ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["ServicesCurrentDay"]);
                            _reportViewer.DataSources.Clear();
                            _reportViewer.DataSources.Add(datasource);

                            bytes = _reportViewer.Render(
                                reportType,
                                deviceInfo,
                                out mimeType,
                                out encoding,
                                out fileNameExtension,
                                out streams,
                                out warnings);

                            FileStream fs = new FileStream(outname,
                                                           FileMode.Create);
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();
                            return(true);
                        }
                    }
                    #endregion
                }
                else if (ReportType.REPORT_ACCUMULATED_BY_DRIVER.Equals(type))
                {
                    #region ACCUMULATED BY DRIVER LOGIC
                    using (ExpressTaxi ctx = new ExpressTaxi(conn))
                    {
                        decimal FinalVal = decimal.Zero;

                        var query = from c in ctx.FinancialTransactions
                                    where
                                    c.TRANS_DATE >= startPeriod &&
                                    c.TRANS_DATE <= endPeriod &&
                                    c.Driver.DRV_LICENSE == DrvLicense &&
                                    c.Driver.DRV_NAME == DrvName &&
                                    c.IsValid
                                    orderby c.TRANS_COD
                                    select c;
                        if (query.Count() > 0)
                        {
                            ReportDataset dataset      = new ReportDataset();
                            ReportDataset tax          = new ReportDataset();
                            ReportDataset DeductionSet = new ReportDataset();

                            foreach (FinancialTransaction c in query)
                            {
                                if (c.IsValid)
                                {
                                    dataset.Tables["AccumulatedByDriver"].Rows.Add(
                                        new object[]
                                    {
                                        (int)c.DOC_NUM,
                                        (string)c.DOCUMENT_DATE.ToString("dd MMM yyyy"),
                                        (string)c.Driver.DRV_LICENSE,
                                        (string)c.Driver.DRV_NAME,
                                        (string)c.Company.CMP_NAME,
                                        (string)c.TRANS_DESTINATION,
                                        (decimal)c.TRANS_VALUE,
                                        (decimal)c.TRANS_REDUCTION,
                                        (decimal)c.TRANS_FINAL_VALUE,
                                        (string)c.TRANS_COMMENTS,
                                        (string)c.VOUCHER_NUM
                                    }
                                        );
                                    FinalVal = FinalVal + c.TRANS_FINAL_VALUE;
                                }
                            }

                            var query2 = from t in ctx.AppliedTaxes select t;
                            if (query2.Count() > 0)
                            {
                                int n = 0;
                                foreach (AppliedTax t in query2)
                                {
                                    tax.Tables["Tax"].Rows.Add(new object[] {
                                        (int)n,
                                        (string)t.TaxDescription,
                                        (decimal)(t.TaxAmount * FinalVal) / 100
                                    });
                                    n = n + 1;
                                }
                            }

                            DeductionSet.Tables["Deduction"].Rows.Add(new object[] { (decimal)Deduction });

                            dataset.AcceptChanges();
                            tax.AcceptChanges();
                            DeductionSet.AcceptChanges();
                            _reportViewer.ReportEmbeddedResource = "ExpressTMS.AccumulatedByDriver.rdlc";

                            ReportParameter[] param = new ReportParameter[6];
                            param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                            param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                            param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                            param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                            param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                            param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                            _reportViewer.SetParameters(param);
                            ReportDataSource datasource      = new ReportDataSource("DataSet1", dataset.Tables["AccumulatedByDriver"]);
                            ReportDataSource taxsource       = new ReportDataSource("DataSet2", tax.Tables["Tax"]);
                            ReportDataSource deductionsource = new ReportDataSource("DataSet3", DeductionSet.Tables["Deduction"]);
                            _reportViewer.DataSources.Clear();
                            _reportViewer.DataSources.Add(datasource);
                            _reportViewer.DataSources.Add(taxsource);
                            _reportViewer.DataSources.Add(deductionsource);

                            bytes = _reportViewer.Render(
                                reportType,
                                deviceInfo,
                                out mimeType,
                                out encoding,
                                out fileNameExtension,
                                out streams,
                                out warnings);

                            FileStream fs = new FileStream(outname,
                                                           FileMode.Create);
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();
                            return(true);
                        }
                    }
                    #endregion
                }
                else if (ReportType.REPORT_ACCUMULATED_PAID.Equals(type))
                {
                    #region ACCUMULATED PAID LOGIC
                    using (ExpressTaxi ctx = new ExpressTaxi(conn))
                    {
                        var query = from c in ctx.FinancialTransactions
                                    where
                                    c.TRANS_DATE >= startPeriod &&
                                    c.TRANS_DATE <= endPeriod && c.IsValid
                                    select c;
                        if (query.Count() > 0)
                        {
                            List <int> txNum  = new List <int>();
                            var        query2 = from d in query select new { d.DRV_COD };
                            foreach (var d in query2)
                            {
                                if (!txNum.Contains(d.DRV_COD))
                                {
                                    txNum.Add(d.DRV_COD);
                                }
                            }
                            ReportDataset dataset = new ReportDataset();
                            int           n       = 0;

                            foreach (var d in txNum)
                            {
                                var query3             = from tx in query where tx.DRV_COD.Equals(d) select tx;
                                FinancialTransaction c = query3.FirstOrDefault();
                                if (c != null)
                                {
                                    decimal TransValue      = decimal.Zero;
                                    decimal TransReduction  = decimal.Zero;
                                    decimal TransFinalValue = decimal.Zero;
                                    foreach (FinancialTransaction tx in query3)
                                    {
                                        TransValue     = TransValue + tx.TRANS_VALUE;
                                        TransReduction = TransReduction + tx.TRANS_REDUCTION;
                                    }
                                    TransFinalValue = TransValue - TransReduction;

                                    dataset.Tables["AccumulatedPaid"].Rows.Add(
                                        new object[]
                                    {
                                        (int)n,
                                        (string)c.Driver.DRV_LICENSE,
                                        (string)c.Driver.DRV_NAME,
                                        (decimal)TransValue,
                                        (decimal)TransReduction,
                                        (decimal)TransFinalValue
                                    }
                                        );
                                    n = n + 1;
                                }
                            }

                            dataset.AcceptChanges();

                            _reportViewer.ReportEmbeddedResource = "ExpressTMS.AccumulatedPaid.rdlc";

                            ReportParameter[] param = new ReportParameter[6];
                            param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                            param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                            param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                            param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                            param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                            param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                            _reportViewer.SetParameters(param);
                            ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["AccumulatedPaid"]);
                            _reportViewer.DataSources.Clear();
                            _reportViewer.DataSources.Add(datasource);

                            bytes = _reportViewer.Render(
                                reportType,
                                deviceInfo,
                                out mimeType,
                                out encoding,
                                out fileNameExtension,
                                out streams,
                                out warnings);

                            FileStream fs = new FileStream(outname,
                                                           FileMode.Create);
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();
                            return(true);
                        }
                    }
                    #endregion
                }
                else if (ReportType.REPORT_HOTEL_INFORMATION.Equals(type))
                {
                    #region SERVICES CURRENT DAY CREATION LOGIC
                    using (ExpressTaxi ctx = new ExpressTaxi(conn))
                    {
                        var query = from c in ctx.FinancialTransactions
                                    where
                                    c.TRANS_DATE >= startPeriod &&
                                    c.TRANS_DATE <= endPeriod &&
                                    c.Company.CMP_NAME == HotelInfo &&
                                    c.IsValid
                                    orderby c.TRANS_COD
                                    select c;
                        if (query.Count() > 0)
                        {
                            ReportDataset dataset = new ReportDataset();
                            foreach (FinancialTransaction c in query)
                            {
                                if (c.IsValid)
                                {
                                    dataset.Tables["HotelInformation"].Rows.Add(
                                        new object[]
                                    {
                                        (int)c.DOC_NUM,
                                        (string)c.Driver.DRV_LICENSE,
                                        (string)c.Driver.DRV_NAME,
                                        (string)c.Company.CMP_NAME,
                                        (string)c.TRANS_DESTINATION,
                                        (string)c.VOUCHER_NUM,
                                        (decimal)c.TRANS_FINAL_VALUE
                                    }
                                        );
                                }
                            }
                            dataset.AcceptChanges();
                            _reportViewer.ReportEmbeddedResource = "ExpressTMS.HotelInformation.rdlc";

                            ReportParameter[] param = new ReportParameter[7];
                            param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                            param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                            param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                            param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                            param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                            param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                            param[6] = new ReportParameter("AGENT", HotelInfo);
                            _reportViewer.SetParameters(param);
                            ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["HotelInformation"]);
                            _reportViewer.DataSources.Clear();
                            _reportViewer.DataSources.Add(datasource);

                            bytes = _reportViewer.Render(
                                reportType,
                                deviceInfo,
                                out mimeType,
                                out encoding,
                                out fileNameExtension,
                                out streams,
                                out warnings);

                            FileStream fs = new FileStream(outname,
                                                           FileMode.Create);
                            fs.Write(bytes, 0, bytes.Length);
                            fs.Close();
                            return(true);
                        }
                    }
                    #endregion
                }
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
            }
            return(false);
        }
Exemplo n.º 4
0
 public bool SaveTransaction()
 {
     try
     {
         if (ValidateTransaction())
         {
             using (ExpressTaxi ctx = new ExpressTaxi(conn))
             {
                 FinancialTransaction t = ctx.FinancialTransactions.SingleOrDefault(r => r.DOC_NUM == _DOC_NUM);
                 if (t == null)
                 {
                     t                   = new FinancialTransaction();
                     t.CMP_COD           = _CMP_COD;
                     t.DOC_NUM           = _DOC_NUM;
                     t.DOC_TYPE_NAME     = _Doc_Type_Name;
                     t.DOCUMENT_DATE     = _Doc_Date;
                     t.DRV_COD           = _DRV_COD;
                     t.IsValid           = true;
                     t.LAST_MODIFIED     = DateTime.Now;
                     t.NO_PAX            = _No_Pax;
                     t.SERV_NAME         = _Serv_Name;
                     t.TRANS_COMMENTS    = _Comments;
                     t.TRANS_DATE        = DateTime.Today;
                     t.TRANS_DESTINATION = _Destination;
                     t.TRANS_FINAL_VALUE = _Trans_Final;
                     t.TRANS_REDUCTION   = _Trans_Reduct;
                     t.TRANS_VALUE       = _Trans_Value;
                     t.VOUCHER_NUM       = _Voucher_Num;
                     UniqueNumber num = ctx.UniqueNumbers.SingleOrDefault(r => r.UniqueName == "Receipt");
                     if (num != null)
                     {
                         if (num.UniqueValue != _DOC_NUM)
                         {
                             _DOC_NUM  = num.UniqueValue;
                             t.DOC_NUM = _DOC_NUM;
                         }
                         num.UniqueValue = num.UniqueValue + 1;
                         ctx.FinancialTransactions.InsertOnSubmit(t);
                         ctx.SubmitChanges();
                         return(true);
                     }
                 }
                 else // edit mode
                 {
                     t.CMP_COD           = _CMP_COD;
                     t.DOC_NUM           = _DOC_NUM;
                     t.DOC_TYPE_NAME     = _Doc_Type_Name;
                     t.DOCUMENT_DATE     = _Doc_Date;
                     t.DRV_COD           = _DRV_COD;
                     t.IsValid           = true;
                     t.LAST_MODIFIED     = DateTime.Now;
                     t.NO_PAX            = _No_Pax;
                     t.SERV_NAME         = _Serv_Name;
                     t.TRANS_COMMENTS    = _Comments;
                     t.TRANS_DATE        = DateTime.Today;
                     t.TRANS_DESTINATION = _Destination;
                     t.TRANS_FINAL_VALUE = _Trans_Final;
                     t.TRANS_REDUCTION   = _Trans_Reduct;
                     t.TRANS_VALUE       = _Trans_Value;
                     t.VOUCHER_NUM       = _Voucher_Num;
                     ctx.SubmitChanges();
                     return(true);
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         log.Error(ex);
     }
     return(false);
 }
Exemplo n.º 5
0
        private void ReportViewer_Load(object sender, EventArgs e)
        {
            try
            {
                if (!_isReportViewerLoaded)
                {
                    if (ReportType.REPORT_COMAPNY_LIST.Equals(type))
                    {
                        #region COMPANY LIST REPORT CREATION LOGIC
                        using (ExpressTaxi ctx = new ExpressTaxi(conn))
                        {
                            var query = from c in ctx.Companies orderby c.CMP_COD select c;
                            if (query.Count() > 0)
                            {
                                ReportDataset dataset = new ReportDataset();
                                foreach (Company c in query)
                                {
                                    dataset.Tables["Company"].Rows.Add(
                                        new object[]
                                    {
                                        (int)c.CMP_COD,
                                        (string)c.CMP_NAME,
                                        (string)c.CMP_ADDRESS,
                                        (string)c.VIL_NAME,
                                        (string)c.PAR_NAME,
                                        (string)c.COU_NAME,
                                        (string)c.CMP_PHONE
                                    }
                                        );
                                }
                                dataset.AcceptChanges();
                                _reportViewer.LocalReport.ReportEmbeddedResource = "ExpressTMS.CompanyList.rdlc";

                                ReportParameter[] param = new ReportParameter[4];
                                param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                                param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                                param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                                param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                                _reportViewer.LocalReport.SetParameters(param);
                                ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["Company"]);
                                _reportViewer.LocalReport.DataSources.Clear();
                                _reportViewer.LocalReport.DataSources.Add(datasource);
                                _reportViewer.RefreshReport();
                                _isReportViewerLoaded = true;
                            }
                        }
                        #endregion
                    }
                    else if (ReportType.REPORT_DRIVER_LIST.Equals(type))
                    {
                        #region DRIVER LIST REPORT CREATION LOGIC
                        using (ExpressTaxi ctx = new ExpressTaxi(conn))
                        {
                            var query = from c in ctx.Drivers orderby c.DRV_COD select c;
                            if (query.Count() > 0)
                            {
                                ReportDataset dataset = new ReportDataset();
                                foreach (Driver c in query)
                                {
                                    dataset.Tables["Driver"].Rows.Add(
                                        new object[]
                                    {
                                        (int)c.DRV_COD,
                                        (string)c.DRV_NAME,
                                        (string)c.DRV_ADDRESS,
                                        (string)c.VIL_NAME,
                                        (string)c.PAR_NAME,
                                        (string)c.COU_NAME,
                                        (string)c.DRV_PHONE,
                                        (string)c.DRV_LICENSE
                                    }
                                        );
                                }
                                dataset.AcceptChanges();
                                _reportViewer.LocalReport.ReportEmbeddedResource = "ExpressTMS.DriverList.rdlc";

                                ReportParameter[] param = new ReportParameter[4];
                                param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                                param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                                param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                                param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                                _reportViewer.LocalReport.SetParameters(param);
                                ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["Driver"]);
                                _reportViewer.LocalReport.DataSources.Clear();
                                _reportViewer.LocalReport.DataSources.Add(datasource);
                                _reportViewer.RefreshReport();
                                _isReportViewerLoaded = true;
                            }
                        }
                        #endregion
                    }
                    else if (ReportType.REPORT_SERVICES_CURRENT_DAY.Equals(type))
                    {
                        #region SERVICES CURRENT DAY CREATION LOGIC
                        using (ExpressTaxi ctx = new ExpressTaxi(conn))
                        {
                            var query = from c in ctx.FinancialTransactions
                                        where
                                        c.TRANS_DATE >= startPeriod &&
                                        c.TRANS_DATE <= endPeriod &&
                                        c.IsValid
                                        orderby c.TRANS_COD
                                        select c;
                            if (query.Count() > 0)
                            {
                                ReportDataset dataset = new ReportDataset();
                                foreach (FinancialTransaction c in query)
                                {
                                    if (c.IsValid)
                                    {
                                        dataset.Tables["ServicesCurrentDay"].Rows.Add(
                                            new object[]
                                        {
                                            (int)c.DOC_NUM,
                                            (string)c.Driver.DRV_LICENSE,
                                            (string)c.Driver.DRV_NAME,
                                            (string)c.Company.CMP_NAME,
                                            (string)c.TRANS_DESTINATION,
                                            (string)c.DOC_TYPE_NAME,
                                            (string)c.DOCUMENT_DATE.ToString("dd MMM yyyy"),
                                            (decimal)c.TRANS_VALUE,
                                            (decimal)c.TRANS_FINAL_VALUE
                                        }
                                            );
                                    }
                                }
                                dataset.AcceptChanges();
                                _reportViewer.LocalReport.ReportEmbeddedResource = "ExpressTMS.ServicesCurrentDay.rdlc";

                                ReportParameter[] param = new ReportParameter[6];
                                param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                                param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                                param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                                param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                                param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                                param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                                _reportViewer.LocalReport.SetParameters(param);
                                ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["ServicesCurrentDay"]);
                                _reportViewer.LocalReport.DataSources.Clear();
                                _reportViewer.LocalReport.DataSources.Add(datasource);
                                _reportViewer.RefreshReport();
                                _isReportViewerLoaded = true;
                            }
                        }
                        #endregion
                    }
                    else if (ReportType.REPORT_ACCUMULATED_BY_DRIVER.Equals(type))
                    {
                        #region ACCUMULATED BY DRIVER LOGIC
                        using (ExpressTaxi ctx = new ExpressTaxi(conn))
                        {
                            decimal FinalVal = decimal.Zero;

                            var query = from c in ctx.FinancialTransactions
                                        where
                                        c.TRANS_DATE >= startPeriod &&
                                        c.TRANS_DATE <= endPeriod &&
                                        c.Driver.DRV_LICENSE == DrvLicense &&
                                        c.Driver.DRV_NAME == DrvName &&
                                        c.IsValid
                                        orderby c.TRANS_COD
                                        select c;
                            if (query.Count() > 0)
                            {
                                ReportDataset dataset      = new ReportDataset();
                                ReportDataset tax          = new ReportDataset();
                                ReportDataset DeductionSet = new ReportDataset();

                                foreach (FinancialTransaction c in query)
                                {
                                    if (c.IsValid)
                                    {
                                        dataset.Tables["AccumulatedByDriver"].Rows.Add(
                                            new object[]
                                        {
                                            (int)c.DOC_NUM,
                                            (string)c.DOCUMENT_DATE.ToString("dd MMM yyyy"),
                                            (string)c.Driver.DRV_LICENSE,
                                            (string)c.Driver.DRV_NAME,
                                            (string)c.Company.CMP_NAME,
                                            (string)c.TRANS_DESTINATION,
                                            (decimal)c.TRANS_VALUE,
                                            (decimal)c.TRANS_REDUCTION,
                                            (decimal)c.TRANS_FINAL_VALUE,
                                            (string)c.TRANS_COMMENTS,
                                            (string)c.VOUCHER_NUM
                                        }
                                            );
                                        FinalVal = FinalVal + c.TRANS_FINAL_VALUE;
                                    }
                                }

                                var query2 = from t in ctx.AppliedTaxes select t;
                                if (query2.Count() > 0)
                                {
                                    int n = 0;
                                    foreach (AppliedTax t in query2)
                                    {
                                        tax.Tables["Tax"].Rows.Add(new object[] {
                                            (int)n,
                                            (string)t.TaxDescription,
                                            (decimal)(t.TaxAmount * FinalVal) / 100
                                        });
                                        n = n + 1;
                                    }
                                }

                                DeductionSet.Tables["Deduction"].Rows.Add(new object[] { (decimal)Deduction });

                                dataset.AcceptChanges();
                                tax.AcceptChanges();
                                DeductionSet.AcceptChanges();
                                _reportViewer.LocalReport.ReportEmbeddedResource = "ExpressTMS.AccumulatedByDriver.rdlc";

                                ReportParameter[] param = new ReportParameter[6];
                                param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                                param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                                param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                                param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                                param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                                param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                                _reportViewer.LocalReport.SetParameters(param);
                                ReportDataSource datasource      = new ReportDataSource("DataSet1", dataset.Tables["AccumulatedByDriver"]);
                                ReportDataSource taxsource       = new ReportDataSource("DataSet2", tax.Tables["Tax"]);
                                ReportDataSource deductionsource = new ReportDataSource("DataSet3", DeductionSet.Tables["Deduction"]);
                                _reportViewer.LocalReport.DataSources.Clear();
                                _reportViewer.LocalReport.DataSources.Add(datasource);
                                _reportViewer.LocalReport.DataSources.Add(taxsource);
                                _reportViewer.LocalReport.DataSources.Add(deductionsource);
                                _reportViewer.RefreshReport();
                                _isReportViewerLoaded = true;
                            }
                        }
                        #endregion
                    }
                    else if (ReportType.REPORT_RECEIPT.Equals(type))
                    {
                        #region RECEIPT REPORT LOGIC
                        using (ExpressTaxi ctx = new ExpressTaxi(conn))
                        {
                            var query = from c in ctx.FinancialTransactions where c.DOC_NUM == DocNum select c;
                            if (query.Count() > 0)
                            {
                                ReportDataset dataset = new ReportDataset();
                                foreach (FinancialTransaction c in query)
                                {
                                    string VoidTxt = null;
                                    if (!c.IsValid)
                                    {
                                        VoidTxt = "VOIDED";
                                    }
                                    dataset.Tables["Receipt"].Rows.Add(
                                        new object[]
                                    {
                                        (int)c.DOC_NUM,
                                        (string)DateTime.Now.ToString("dd MMM yyyy"),
                                        (string)c.Driver.DRV_LICENSE,
                                        (string)c.Driver.DRV_NAME,
                                        (string)c.Company.CMP_NAME,
                                        (string)c.TRANS_DESTINATION,
                                        (string)c.DOC_TYPE_NAME,
                                        (int)c.NO_PAX,
                                        (string)c.DOCUMENT_DATE.ToString("dd MMM yyyy"),
                                        (decimal)c.TRANS_VALUE,
                                        (decimal)c.TRANS_FINAL_VALUE,
                                        (string)c.SERV_NAME,
                                        (string)c.VOUCHER_NUM,
                                        (string)VoidTxt
                                    }
                                        );
                                }
                                dataset.AcceptChanges();
                                _reportViewer.LocalReport.ReportEmbeddedResource = "ExpressTMS.ReceiptVoucher.rdlc";

                                ReportParameter[] param = new ReportParameter[4];
                                param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                                param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                                param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                                param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                                _reportViewer.LocalReport.SetParameters(param);
                                ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["Receipt"]);
                                _reportViewer.LocalReport.DataSources.Clear();
                                _reportViewer.LocalReport.DataSources.Add(datasource);
                                _reportViewer.RefreshReport();
                                _isReportViewerLoaded = true;
                            }
                        }
                        #endregion
                    }
                    else if (ReportType.REPORT_ACCUMULATED_PAID.Equals(type))
                    {
                        #region ACCUMULATED PAID LOGIC
                        using (ExpressTaxi ctx = new ExpressTaxi(conn))
                        {
                            var query = from c in ctx.FinancialTransactions
                                        where
                                        c.TRANS_DATE >= startPeriod &&
                                        c.TRANS_DATE <= endPeriod && c.IsValid
                                        select c;
                            if (query.Count() > 0)
                            {
                                List <int> txNum  = new List <int>();
                                var        query2 = from d in query select new { d.DRV_COD };
                                foreach (var d in query2)
                                {
                                    if (!txNum.Contains(d.DRV_COD))
                                    {
                                        txNum.Add(d.DRV_COD);
                                    }
                                }
                                ReportDataset dataset = new ReportDataset();
                                int           n       = 0;

                                foreach (var d in txNum)
                                {
                                    var query3             = from tx in query where tx.DRV_COD.Equals(d) select tx;
                                    FinancialTransaction c = query3.FirstOrDefault();
                                    if (c != null)
                                    {
                                        decimal TransValue      = decimal.Zero;
                                        decimal TransReduction  = decimal.Zero;
                                        decimal TransFinalValue = decimal.Zero;
                                        foreach (FinancialTransaction tx in query3)
                                        {
                                            TransValue     = TransValue + tx.TRANS_VALUE;
                                            TransReduction = TransReduction + tx.TRANS_REDUCTION;
                                        }
                                        TransFinalValue = TransValue - TransReduction;

                                        dataset.Tables["AccumulatedPaid"].Rows.Add(
                                            new object[]
                                        {
                                            (int)n,
                                            (string)c.Driver.DRV_LICENSE,
                                            (string)c.Driver.DRV_NAME,
                                            (decimal)TransValue,
                                            (decimal)TransReduction,
                                            (decimal)TransFinalValue
                                        }
                                            );
                                        n = n + 1;
                                    }
                                }

                                dataset.AcceptChanges();
                                _reportViewer.LocalReport.ReportEmbeddedResource = "ExpressTMS.AccumulatedPaid.rdlc";

                                ReportParameter[] param = new ReportParameter[6];
                                param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                                param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                                param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                                param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                                param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                                param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                                _reportViewer.LocalReport.SetParameters(param);
                                ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["AccumulatedPaid"]);
                                _reportViewer.LocalReport.DataSources.Clear();
                                _reportViewer.LocalReport.DataSources.Add(datasource);
                                _reportViewer.RefreshReport();
                                _isReportViewerLoaded = true;
                            }
                        }
                        #endregion
                    }
                    else if (ReportType.REPORT_SERVICES.Equals(type))
                    {
                        #region REPORT SERVICES LOGIC
                        using (ExpressTaxi ctx = new ExpressTaxi(conn))
                        {
                            var query = from c in ctx.FinancialTransactions
                                        where
                                        c.TRANS_DATE >= startPeriod &&
                                        c.TRANS_DATE <= endPeriod && c.IsValid
                                        select c;
                            if (query.Count() > 0)
                            {
                                ReportDataset dataset = new ReportDataset();
                                int           n       = 0;
                                foreach (FinancialTransaction c in query)
                                {
                                    dataset.Tables["Services"].Rows.Add(
                                        new object[]
                                    {
                                        (int)n,
                                        (string)c.TRANS_DATE.ToString("dd MMM yyyy"),
                                        (string)c.Driver.DRV_LICENSE + ", " + c.Driver.DRV_NAME,
                                        (int)c.NO_PAX,
                                        (string)c.TRANS_DESTINATION,
                                        (decimal)c.TRANS_FINAL_VALUE,
                                        (string)c.VOUCHER_NUM
                                    }
                                        );
                                    n = n + 1;
                                }
                                dataset.AcceptChanges();
                                _reportViewer.LocalReport.ReportEmbeddedResource = "ExpressTMS.ServicesReport.rdlc";

                                ReportParameter[] param = new ReportParameter[6];
                                param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                                param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                                param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                                param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                                param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                                param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                                _reportViewer.LocalReport.SetParameters(param);
                                ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["Services"]);
                                _reportViewer.LocalReport.DataSources.Clear();
                                _reportViewer.LocalReport.DataSources.Add(datasource);
                                _reportViewer.RefreshReport();
                                _isReportViewerLoaded = true;
                            }
                        }
                        #endregion
                    }
                    else if (ReportType.REPORT_HOTEL_INFORMATION.Equals(type))
                    {
                        #region HOTEL INFORMATION LOGIC
                        using (ExpressTaxi ctx = new ExpressTaxi(conn))
                        {
                            var query = from c in ctx.FinancialTransactions
                                        where
                                        c.TRANS_DATE >= startPeriod &&
                                        c.TRANS_DATE <= endPeriod &&
                                        c.Company.CMP_NAME == HotelInfo &&
                                        c.IsValid
                                        orderby c.TRANS_COD
                                        select c;
                            if (query.Count() > 0)
                            {
                                ReportDataset dataset = new ReportDataset();
                                foreach (FinancialTransaction c in query)
                                {
                                    if (c.IsValid)
                                    {
                                        dataset.Tables["HotelInformation"].Rows.Add(
                                            new object[]
                                        {
                                            (int)c.DOC_NUM,
                                            (string)c.Driver.DRV_LICENSE,
                                            (string)c.Driver.DRV_NAME,
                                            (string)c.Company.CMP_NAME,
                                            (string)c.TRANS_DESTINATION,
                                            (string)c.VOUCHER_NUM,
                                            (decimal)c.TRANS_FINAL_VALUE
                                        }
                                            );
                                    }
                                }
                                dataset.AcceptChanges();
                                _reportViewer.LocalReport.ReportEmbeddedResource = "ExpressTMS.HotelInformation.rdlc";

                                ReportParameter[] param = new ReportParameter[7];
                                param[0] = new ReportParameter("CMP_NAME", Config.CMP_NAME);
                                param[1] = new ReportParameter("CMP_ADDRESSLINE1", Config.CMP_ADDRESSLINE1);
                                param[2] = new ReportParameter("CMP_ADDRESSLINE2", Config.CMP_ADDRESSLINE2);
                                param[3] = new ReportParameter("CMP_PHONEFAX", Config.CMP_PHONEFAX);
                                param[4] = new ReportParameter("START_DATE", startPeriod.ToString("dd MMM yyyy"));
                                param[5] = new ReportParameter("END_DATE", endPeriod.ToString("dd MMM yyyy"));
                                param[6] = new ReportParameter("AGENT", HotelInfo);
                                _reportViewer.LocalReport.SetParameters(param);
                                ReportDataSource datasource = new ReportDataSource("DataSet1", dataset.Tables["HotelInformation"]);
                                _reportViewer.LocalReport.DataSources.Clear();
                                _reportViewer.LocalReport.DataSources.Add(datasource);
                                _reportViewer.RefreshReport();
                                _isReportViewerLoaded = true;
                            }
                        }
                        #endregion
                    }
                }
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                Config.FatalError();
            }
        }