private void EmailInvoices()
        {
            try
            {
                string subject = txtSubject.Text.Trim();

                if (string.IsNullOrEmpty(subject))
                {
                    ENUtils.ShowMessage("Required : Email Subject");
                    return;
                }

                var rows = grdDriverCommission.Rows.Where(c => c.Cells[COLS.CommissionId].Value.ToLong() > 0).ToList();



                List <long> invoiceIds = rows.Select(c => c.Cells[COLS.CommissionId].Value.ToLong()).ToList <long>();

                if (invoiceIds.Count > 0)
                {
                    //frmDriverTransactionReport frm = new frmDriverTransactionReport(1);
                    frmDriverCommisionTransactionReport frm = new frmDriverCommisionTransactionReport(1);
                    var list = General.GetQueryable <vu_DriverCommision>(a => invoiceIds.Contains(a.Id)).ToList();

                    // frm.CompanyHeader = ddlSubCompany.Text.Trim();

                    List <Fleet_Driver> driversList = General.GetGeneralList <Fleet_Driver>(c => c.DriverTypeId == 2);

                    frmEmail frmEmail = new frmEmail(null, "", "");


                    foreach (var item in rows.Where(c => c.Cells["Check"].Value.ToBool()))
                    {
                        frm.DataSource = list.Where(c => c.Id == item.Cells[COLS.CommissionId].Value.ToLong()).OrderBy(c => c.PickupDate).ToList();


                        frm.GenerateReport();



                        //string email = driversList.FirstOrDefault(c => c.Id == item.Cells[COLS.Id].Value.ToInt()).DefaultIfEmpty().Email.ToStr().Trim();
                        string email = item.Cells[COLS.DriverEmail].Value.ToStr();


                        if (!string.IsNullOrEmpty(email))
                        {
                            frm.SendEmailInternally(frmEmail, subject, item.Cells[COLS.DriverNo].Value.ToStr().Trim(), email);
                        }
                    }


                    if (frmEmail != null && frmEmail.IsDisposed == false)
                    {
                        frmEmail.Close();
                        GC.Collect();
                    }



                    ENUtils.ShowMessage("Email has been sent successfully");
                }
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }
        private void EmailInvoices(long TransId)
        {
            bool IsSuccess = false;

            try
            {
                string subject = txtSubject.Text.Trim();

                if (string.IsNullOrEmpty(subject))
                {
                    ENUtils.ShowMessage("Required : Email Subject");
                    return;
                }

                List <GridViewRowInfo> rows = null;


                if (TransId == 0)
                {
                    rows = grdDriverCommission.Rows.Where(c => c.Cells["Check"].Value.ToBool() == true).ToList();
                }
                else
                {
                    rows = grdDriverCommission.Rows.Where(c => c.Cells["CommissionId"].Value.ToLong() == TransId).ToList();
                }



                //List<long> invoiceIds = rows.Select(c => c.Cells["CommissionId"].Value.ToLong()).ToList<long>();


                List <long> invoiceIds = new List <long>();

                if (TransId == 0)
                {
                    invoiceIds = rows.Select(c => c.Cells["CommissionId"].Value.ToLong()).ToList <long>();
                }
                else
                {
                    invoiceIds = new List <long>();
                    invoiceIds.Add(TransId);
                }


                if (invoiceIds.Count > 0)
                {
                    frmDriverCommisionTransactionExpensesReport3 frm = new frmDriverCommisionTransactionExpensesReport3(1);

                    var list  = General.GetQueryable <vu_DriverCommisionExpenses2>(a => invoiceIds.Contains(a.Id)).ToList();
                    var list2 = General.GetQueryable <vu_FleetDriverCommissionExpense>(a => invoiceIds.Contains(a.Id)).ToList();

                    List <Fleet_Driver> driversList = General.GetQueryable <Fleet_Driver>(c => c.DriverTypeId == 2).ToList();

                    frmEmail frmEmail = new frmEmail(null, "", "");

                    Fleet_Driver objDriver = null;
                    foreach (var item in rows.Where(c => c.Cells["Check"].Value.ToBool()))
                    {
                        frm.DataSource  = list.Where(c => c.Id == item.Cells["CommissionId"].Value.ToLong()).OrderBy(c => c.PickupDate).ToList();
                        frm.DataSource2 = list2.Where(c => c.CommissionId == item.Cells["CommissionId"].Value.ToLong()).OrderBy(c => c.Date).ToList();

                        frm.GenerateReport();

                        objDriver = driversList.FirstOrDefault(c => c.Id == item.Cells["DriverId"].Value.ToInt());
                        //string email = driversList.FirstOrDefault(c => c.Id == item.Cells[COLS.Id].Value.ToInt()).DefaultIfEmpty().Email.ToStr().Trim();
                        string email = objDriver.Email.ToStr().Trim();

                        if (!string.IsNullOrEmpty(email))
                        {
                            IsSuccess = frm.SendEmailInternally(frmEmail, subject, objDriver.DriverNo.ToStr().Trim(), email);
                        }
                    }


                    if (frmEmail != null && frmEmail.IsDisposed == false)
                    {
                        frmEmail.Close();
                        GC.Collect();
                    }


                    if (IsSuccess)
                    {
                        RadDesktopAlert alert = new RadDesktopAlert();
                        alert.ContentText = "Email has been sent successfully";
                        alert.Show();
                    }
                    // ENUtils.ShowMessage("Email has been sent successfully");
                }
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }
        private void EmailInvoices(long TransId)
        {
            bool IsSuccess = false;

            try
            {
                string subject = txtSubject.Text.Trim();

                if (string.IsNullOrEmpty(subject))
                {
                    ENUtils.ShowMessage("Required : Email Subject");
                    return;
                }


                if (txtBody.Text.Trim().Length > 0)
                {
                    subject += "||" + txtBody.Text;
                }

                List <GridViewRowInfo> rows = null;


                if (TransId == 0)
                {
                    rows = grdLister.Rows.Where(c => c.Cells["Check"].Value.ToBool() == true).ToList();
                }
                else
                {
                    rows = grdLister.Rows.Where(c => c.Cells["RentId"].Value.ToLong() == TransId).ToList();
                }



                //List<long> invoiceIds = rows.Select(c => c.Cells["RentId"].Value.ToLong()).ToList<long>();


                List <long> invoiceIds = new List <long>();

                if (TransId == 0)
                {
                    invoiceIds = rows.Select(c => c.Cells["RentId"].Value.ToLong()).ToList <long>();
                }
                else
                {
                    invoiceIds = new List <long>();
                    invoiceIds.Add(TransId);
                }


                if (invoiceIds.Count > 0)
                {
                    frmDriverRentTransactionExpensesReport3 frm = new frmDriverRentTransactionExpensesReport3(1);
                    frm.reportViewer1.Tag = "invoice";
                    var list  = General.GetQueryable <vu_DriverRentExpense>(a => invoiceIds.Contains(a.Id)).ToList();
                    var list2 = General.GetQueryable <vu_FleetDriverRentExpense>(a => invoiceIds.Contains(a.Id)).ToList();

                    List <Fleet_Driver> driversList = General.GetQueryable <Fleet_Driver>(c => c.DriverTypeId == 1).ToList();

                    frmEmail frmEmail = new frmEmail(null, "", "");

                    Fleet_Driver objDriver = null;
                    foreach (var item in rows.Where(c => c.Cells["Check"].Value.ToBool()))
                    {
                        if (optFullDetail.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
                        {
                            frm.optFullDetail.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On;
                        }
                        else if (optAccountJobs.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
                        {
                            frm.optAccountJobs.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On;
                        }
                        else if (optSummaryDetails.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
                        {
                            frm.optSummaryDetails.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On;
                        }
                        frm.DataSource  = list.Where(c => c.Id == item.Cells["RentId"].Value.ToLong()).OrderBy(c => c.PickupDate).ToList();
                        frm.DataSource2 = list2.Where(c => c.RentId == item.Cells["RentId"].Value.ToLong()).OrderBy(c => c.Date).ToList();
                        //    frm.objSubcompany = objSubcompany;
                        frm.objSubcompany = driversList.FirstOrDefault(C => C.Id == item.Cells["DriverId"].Value.ToInt()).DefaultIfEmpty().Gen_SubCompany.DefaultIfEmpty();

                        frm.GenerateReport(item.Cells["VAT"].Value.ToDecimal());

                        objDriver = driversList.FirstOrDefault(c => c.Id == item.Cells["DriverId"].Value.ToInt());
                        //string email = driversList.FirstOrDefault(c => c.Id == item.Cells[COLS.Id].Value.ToInt()).DefaultIfEmpty().Email.ToStr().Trim();
                        string email = "";

                        if (objDriver != null)
                        {
                            email = objDriver.Email.ToStr().Trim();
                        }

                        if (!string.IsNullOrEmpty(email))
                        {
                            IsSuccess = frm.SendEmailInternally(frmEmail, subject, objDriver.DriverNo.ToStr().Trim(), email);
                        }
                    }


                    if (frmEmail != null && frmEmail.IsDisposed == false)
                    {
                        frmEmail.Close();
                        GC.Collect();
                    }


                    if (IsSuccess)
                    {
                        RadDesktopAlert alert = new RadDesktopAlert();
                        alert.ContentText = "Email has been sent successfully";
                        alert.Show();
                    }
                    // ENUtils.ShowMessage("Email has been sent successfully");
                }
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }