using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
//using System.IO;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OLServices;
using System.Resources;
using System.Threading;
public partial class TA_UI_LicenseRequest : System.Web.UI.Page
{
    #region Variable Declarion
    int MailSendOrNot = 0;
    Licensing objLic = new Licensing();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    // variable declaration
    string company = string.Empty, address1 = string.Empty, address2 = string.Empty, state = string.Empty;
    string zipCode = string.Empty, city = string.Empty, country = string.Empty;
    string phNo = string.Empty, faxNo = string.Empty, mobileNo = string.Empty, emialId = string.Empty;
    string noOfConcurrentUser = string.Empty, noOfEmployee = string.Empty, noOfTerminal = string.Empty, versionType = string.Empty, VersionNumber = string.Empty;
    string secEmailID = string.Empty;
    OL_Services Objservices = new OL_Services();
    string strDelarLogo;
    CultureInfo ci;
    ResourceManager rm;
    #endregion
    #region PageLoad
    protected void Page_Load(object sender, EventArgs e)
    {
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (!IsPostBack)
        {
            txtName.Focus();
            ClearValues();
            GetImagePath();
        }
    }
    #endregion
    #region Button Click Events
    /// <summary>
    /// Handles the Click event of the btnGenerateLicenseRequest control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnGenerateLicenseRequest_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt16(txtNoOfConcurrentUser.Text) <= Convert.ToInt16(txtNoOfEmployee.Text))
        {
            company = txtName.Text.Trim();
            address1 = txtAddress1.Text.Trim();
            address2 = txtAddress2.Text.Trim();
            state = txtState.Text.Trim();
            zipCode = txtZipCode.Text.Trim();
            city = txtCity.Text.Trim();
            country = ddlCountry.SelectedItem.ToString();
            phNo = txtTelephoneNo.Text.Trim();
            faxNo = txtFaxNo.Text.Trim();
            mobileNo = txtMobileNo.Text.Trim();
            emialId = txtEmailId.Text.Trim();
            noOfConcurrentUser = txtNoOfConcurrentUser.Text.Trim();
            noOfEmployee = txtNoOfEmployee.Text.Trim();
            noOfTerminal = txtNoOfTerminal.Text.Trim();
            secEmailID = txtSecondEmailId.Text.Trim();
            versionType = Convert.ToString(ddlVersionType.SelectedItem.Text);
            string MacAddress = GetMACAddress();
            Int64 RequestID = -1;
            //Getting Applicatin version Number from database
            //Created By manikandan.R on 14-03-2014
            DataSet dsVersionDetails = new DataSet();
            dsVersionDetails = objLic.GettingVersionNumber();
            if (dsVersionDetails.Tables.Count > 0)
            {
                if (dsVersionDetails.Tables[0].Rows.Count > 0)
                {
                    VersionNumber = Convert.ToString(dsVersionDetails.Tables[0].Rows[0]["versionNumber"]);
                }
            }
            bool NetResult = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
            if (NetResult == true)
            {
                DataSet dsCheckRequestID = new DataSet();
                dsCheckRequestID = objLic.SelectLicenseRequestID();
                if (dsCheckRequestID.Tables.Count > 0)
                {
                    if (dsCheckRequestID.Tables[0].Rows.Count > 0)
                    {
                        RequestID = Convert.ToInt64(dsCheckRequestID.Tables[0].Rows[0]["RequestID"]);
                    }
                }
                try
                {
                    DataSet dsLicenseRequest = new DataSet();
                    dsLicenseRequest = Objservices.InsertRequest(RequestID, company, address1, address2, city, zipCode, state, country, phNo, faxNo, mobileNo, emialId, secEmailID, Convert.ToInt64(noOfConcurrentUser),
                            Convert.ToInt64(noOfEmployee), Convert.ToInt64(noOfTerminal), versionType, VersionNumber, MacAddress, Convert.ToString(Session["user"]), "");
                    if (dsLicenseRequest.Tables.Count > 0)
                    {
                        if (dsLicenseRequest.Tables[0].Rows.Count > 0)
                        {
                            Int64 ResponseID = Convert.ToInt64(dsLicenseRequest.Tables[0].Rows[0]["RequestID"]);
                            if (ResponseID == 0)
                            {
                                ScriptManager.RegisterStartupScript(this, GetType(), "Alert", "alert('" + rm.GetString("Alert_Licfilealreadygenerated", ci) + "');window.location='License_Activation.aspx';", true);
                                ClearValues();
                            }
                            else
                            {
                                string ToMailID = Convert.ToString(dsLicenseRequest.Tables[0].Rows[0]["ToMailID"]);
                                string CCmailID = Convert.ToString(dsLicenseRequest.Tables[0].Rows[0]["CCMailID"]);
                                string ClientEmail = Convert.ToString(txtEmailId.Text);
                                if (Convert.ToString(txtSecondEmailId.Text) != string.Empty)
                                {
                                    ClientEmail += ";" + txtSecondEmailId.Text;
                                }
                                objLic.InsertLicenseResponseData(ResponseID, MacAddress, Convert.ToBoolean(true));
                                if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
                                {
                                    TriggerMail("TimeCheck License Request Send Successfully", "TimeCheck License Request ", ToMailID, CCmailID);
                                    TriggerMailForClient("TimeCheck License Request Send Successfully", "TimeCheck License Request ", ClientEmail);
                                }
                                ClearValues();
                                ScriptManager.RegisterStartupScript(this, GetType(), "Alert", "alert('" + rm.GetString("Alert_LicenseRequestSendSuccessfully", ci) + "');window.location='TA_UI_LicenseRequest.aspx';", true);
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, GetType(), "Alert", "alert('" + rm.GetString("Unable to send license request", ci) + "');", true);
                        }
                    }
                }
                catch
                {
                    string companyDetails = string.Empty;
                    string customerIdLicFile = string.Empty;
                    companyDetails += company;
                    companyDetails += "*" + address1;
                    companyDetails += "*" + address2;
                    companyDetails += "*" + state;
                    companyDetails += "*" + zipCode;
                    companyDetails += "*" + city;
                    companyDetails += "*" + country;
                    companyDetails += "*" + phNo;
                    companyDetails += "*" + faxNo;
                    companyDetails += "*" + mobileNo;
                    companyDetails += "*" + emialId;
                    companyDetails += "*" + noOfConcurrentUser;
                    companyDetails += "*" + noOfEmployee;
                    // include customer id
                    string[] fileArr = Directory.GetFiles(Server.MapPath("LicenseFile"), "*.lic");
                    int arrCount = fileArr.Length;
                    if (arrCount > 0)
                    {
                        string licenseFileName = fileArr[arrCount - 1].ToString();
                        //File Stream pointing to License File,if exist
                        FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
                        //Stream Reader pointing to License  File
                        StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
                        // read license request file information from .lrf file
                        string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
                        //Close the Streams
                        licenseFileStreamReader.Close();
                        licenseFileStream.Close();
                        string decryptedLicFileInfo = string.Empty;
                        try
                        {
                            decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
                        }
                        catch
                        {
                            string strScript = "<script language='javascript' type='text/javascript'>";
                            strScript += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                            strScript += " </script>";
                            this.RegisterStartupScript("AlertLicInfoNotCorrect", strScript);
                            return;
                        }
                        string[] decryptedLicFileInfoArr = decryptedLicFileInfo.Split('#');
                        string basicLicInfo = decryptedLicFileInfoArr[0].ToString();
                        string[] basicLicInfoArr = basicLicInfo.Split(',');
                        customerIdLicFile = basicLicInfoArr[0].ToString();
                    }
                    else
                    {
                    }
                    companyDetails += "*" + customerIdLicFile;
                    companyDetails += "*" + noOfTerminal;
                    companyDetails += "*" + secEmailID;
                    companyDetails += "*" + versionType;
                    companyDetails += "*" + VersionNumber;
                    Session["companyDetails"] = companyDetails;
                    Logger logger = new Logger();
                    //get the .lrf path
                    logger.FileName = Server.MapPath("LicenseFile/" + company + ".lrf");
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(logger.FileName);
                    // create .lrf file      
                    NodeLocking nodeLocking = new NodeLocking();
                    logger.Write(nodeLocking.GetEncryptedNodeId("", companyDetails));
                    //Response.Redirect("LicenseFile/" + company + ".lrf");
                    Response.Clear();
                    Response.ContentType = MimeType(logger.FileName);
                    // Below line is commented by Gopinath on 14Aug14 for Bug No.25340
                    // Response.AddHeader("content-disposition", "attachment; filename=" + company + ".lrf");
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + Path.GetFileName(logger.FileName) + "\"");
                    FileStream sourceFile = new FileStream(logger.FileName, FileMode.Open);
                    long FileSize;
                    FileSize = sourceFile.Length;
                    byte[] getContent = new byte[(int)FileSize];
                    sourceFile.Read(getContent, 0, (int)sourceFile.Length);
                    sourceFile.Close();
                    Response.BinaryWrite(getContent);
                    Response.End();
                }
            }
            else
            {
                string companyDetails = string.Empty;
                string customerIdLicFile = string.Empty;
                companyDetails += company;
                companyDetails += "*" + address1;
                companyDetails += "*" + address2;
                companyDetails += "*" + state;
                companyDetails += "*" + zipCode;
                companyDetails += "*" + city;
                companyDetails += "*" + country;
                companyDetails += "*" + phNo;
                companyDetails += "*" + faxNo;
                companyDetails += "*" + mobileNo;
                companyDetails += "*" + emialId;
                companyDetails += "*" + noOfConcurrentUser;
                companyDetails += "*" + noOfEmployee;
                // include customer id
                string[] fileArr = Directory.GetFiles(Server.MapPath("LicenseFile"), "*.lic");
                int arrCount = fileArr.Length;
                if (arrCount > 0)
                {
                    string licenseFileName = fileArr[arrCount - 1].ToString();
                    //File Stream pointing to License File,if exist
                    FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
                    //Stream Reader pointing to License  File
                    StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
                    // read license request file information from .lrf file
                    string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
                    //Close the Streams
                    licenseFileStreamReader.Close();
                    licenseFileStream.Close();
                    string decryptedLicFileInfo = string.Empty;
                    try
                    {
                        decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
                    }
                    catch
                    {
                        string strScript = "<script language='javascript' type='text/javascript'>";
                        strScript += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                        strScript += " </script>";
                        this.RegisterStartupScript("AlertLicInfoNotCorrect", strScript);
                        return;
                    }
                    string[] decryptedLicFileInfoArr = decryptedLicFileInfo.Split('#');
                    string basicLicInfo = decryptedLicFileInfoArr[0].ToString();
                    string[] basicLicInfoArr = basicLicInfo.Split(',');
                    customerIdLicFile = basicLicInfoArr[0].ToString();
                }
                else
                {
                }
                companyDetails += "*" + customerIdLicFile;
                companyDetails += "*" + noOfTerminal;
                companyDetails += "*" + secEmailID;
                companyDetails += "*" + versionType;
                companyDetails += "*" + VersionNumber;
                Session["companyDetails"] = companyDetails;
                Logger logger = new Logger();
                //get the .lrf path
                logger.FileName = Server.MapPath("LicenseFile/" + company + ".lrf");
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(logger.FileName);
                // create .lrf file      
                NodeLocking nodeLocking = new NodeLocking();
                logger.Write(nodeLocking.GetEncryptedNodeId("", companyDetails));
                //Response.Redirect("LicenseFile/" + company + ".lrf");
                Response.Clear();
                Response.ContentType = MimeType(logger.FileName);
                // Below line is commented by Gopinath on 14Aug14 for Bug No.25340
                // Response.AddHeader("content-disposition", "attachment; filename=" + company + ".lrf");
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + Path.GetFileName(logger.FileName) + "\"");
                FileStream sourceFile = new FileStream(logger.FileName, FileMode.Open);
                long FileSize;
                FileSize = sourceFile.Length;
                byte[] getContent = new byte[(int)FileSize];
                sourceFile.Read(getContent, 0, (int)sourceFile.Length);
                sourceFile.Close();
                Response.BinaryWrite(getContent);
                Response.End();
            }
            //  Response.Redirect(Request.Path);
        }
        //  Response.Redirect(Request.Path);
    }
    /// <summary>
    /// Handles the Click event of the btnBack control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Valid.aspx");
        //Response.Redirect("index.aspx");
    }
    #endregion
    #region User Defiened Functions
    public void BindCountries()
    {
        System.Collections.Specialized.StringDictionary dic = new System.Collections.Specialized.StringDictionary();
        System.Collections.Generic.List<string> col = new System.Collections.Generic.List<string>();
        foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))
        {
            RegionInfo ri = new RegionInfo(ci.LCID);
            if (!dic.ContainsKey(ri.EnglishName))
                dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());
            if (!col.Contains(ri.EnglishName))
                col.Add(ri.EnglishName);
        }
        col.Sort();
        foreach (string key in col)
        {
            ddlCountry.Items.Add(new ListItem(key, dic[key]));
        }
        if (ddlCountry.SelectedIndex == 0 && Request.UserLanguages != null && Request.UserLanguages[0].Length == 5)
        {
            ddlCountry.SelectedValue = Request.UserLanguages[0].Substring(3);
        }
    }
    protected void GetImagePath()
    {
        try
        {
            if (System.Configuration.ConfigurationManager.AppSettings["DelarLogo"].ToString() != "")
            {
                strDelarLogo = System.Configuration.ConfigurationManager.AppSettings["DelarLogo"].ToString();
                IMG2.Visible = true;
                IMG2.Src = strDelarLogo;
            }
            else
            {
                IMG2.Visible = false;
            }
        }
        catch (Exception ex)
        {
        }
    }
    public void BindCountries2()
    {
        CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
        SortedDictionary<string, string> regionLookup = new SortedDictionary<string, string>(StringComparer.Ordinal);
        string s = string.Empty;
        foreach (CultureInfo cultInfo in cultures)
        {
            RegionInfo regionInfo = new RegionInfo(cultInfo.LCID);
            if (!regionLookup.ContainsKey(regionInfo.EnglishName))
            {
                regionLookup.Add(regionInfo.EnglishName, regionInfo.TwoLetterISORegionName);
            }
            else
            {
                s = s + " - " + regionInfo.EnglishName;
            }
        }
        ddlCountry.DataTextField = "Key";
        ddlCountry.DataValueField = "Value";
        ddlCountry.DataSource = regionLookup;
        ddlCountry.DataBind();
        foreach (ListItem item in ddlCountry.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    public string GetMACAddress()
    {
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
        String sMacAddress = string.Empty;
        foreach (NetworkInterface adapter in nics)
        {
            if (sMacAddress == String.Empty)// only return MAC Address from first card  
            {
                IPInterfaceProperties properties = adapter.GetIPProperties();
                sMacAddress = adapter.GetPhysicalAddress().ToString();
            }
        }
        return sMacAddress;
    }
    private string MimeType(string Filename)
    {
        string mime = "application/octetstream";
        string ext = System.IO.Path.GetExtension(Filename).ToLower();
        Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
        if (rk != null && rk.GetValue("Content Type") != null)
            mime = rk.GetValue("Content Type").ToString();
        return mime;
    }
    public void ClearValues()
    {
        txtName.Text = string.Empty;
        txtAddress1.Text = string.Empty;
        txtAddress2.Text = string.Empty;
        txtState.Text = string.Empty;
        txtZipCode.Text = string.Empty;
        txtCity.Text = string.Empty;
        ddlCountry.SelectedIndex = 0;
        txtTelephoneNo.Text = string.Empty;
        txtFaxNo.Text = string.Empty;
        txtMobileNo.Text = string.Empty;
        txtEmailId.Text = string.Empty;
        txtNoOfConcurrentUser.Text = "0";
        txtNoOfEmployee.Text = "0";
        txtNoOfTerminal.Text = "0";
        txtSecondEmailId.Text = string.Empty;
        ddlVersionType.SelectedIndex = 0;
    }
    #region EmailTriggering
    public void TriggerMail(string bodyContent, string subject, string ToEmail, string CcEmail)
    {
        string scriptText;
        string FromEmailId = string.Empty;
        string SMTPHost = string.Empty;
        string SMTPPort = string.Empty;
        string NetUserName = string.Empty;
        string NetPassword = string.Empty;
        DataTable dtTableScript = new DataTable();
        MailMessage message = new MailMessage();
        try
        {
            string ScriptType = "License Request";
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            scriptText = dtTableScript.Rows[0]["ScriptText"].ToString();
            FromEmailId = Convert.ToString(ConfigurationManager.AppSettings["FromId"]);
            SMTPHost = Convert.ToString(ConfigurationManager.AppSettings["SMTPClientHost"]);
            SMTPPort = Convert.ToString(ConfigurationManager.AppSettings["SMTPPort"]);
            NetUserName = Convert.ToString(ConfigurationManager.AppSettings["MailAuthenticateUser"]);
            NetPassword = Convert.ToString(ConfigurationManager.AppSettings["MailAuthenticatePassword"]);
            NetworkCredential crdntl = new NetworkCredential();
            SmtpClient client = new SmtpClient(SMTPHost, Convert.ToInt32(SMTPPort));
            message.IsBodyHtml = true;
            message.Subject = subject + " | " + txtName.Text.Trim() + " | " + System.DateTime.Now.ToLongDateString();
            message.Body = scriptText.Replace("<<licenserequestdetails>>", txtName.Text + " requested the license");
            message.Body = message.Body.Replace("<<lblemployee>>", "Number Of Employees");
            message.Body = message.Body.Replace("<<employee>>", txtNoOfEmployee.Text);
            message.Body = message.Body.Replace("<<lblconcurrentusers>>", "Number Of Concurrent Users");
            message.Body = message.Body.Replace("<<concurrentusers>>", txtNoOfConcurrentUser.Text);
            message.Body = message.Body.Replace("<<lblterminals>>", "Number Of Terminals");
            message.Body = message.Body.Replace("<<terminals>>", txtNoOfTerminal.Text);
            message.Body = message.Body.Replace("<<lblversion>>", "Version Type");
            message.Body = message.Body.Replace("<<version>>", ddlVersionType.SelectedItem.Text);
            message.Body = message.Body.Replace("<<regards>>", "Regards,");
            message.Body = message.Body.Replace("<<clientname>>", txtName.Text);
            message.From = new MailAddress(FromEmailId);
            AlternateView htmlview = default(AlternateView);
            htmlview = AlternateView.CreateAlternateViewFromString(message.Body, null, "text/html");
            LinkedResource imageResourceEs = new LinkedResource(Server.MapPath("~/images/" + "logo.png"), "image/png");
            imageResourceEs.ContentId = "image1";
            imageResourceEs.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            htmlview.LinkedResources.Add(imageResourceEs);
            LinkedResource imgCompLogo = new LinkedResource(Server.MapPath("~/images/" + "AngLogoNew_Email.png"), "image/png");
            imgCompLogo.ContentId = "imgCompLogo";
            imgCompLogo.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            htmlview.LinkedResources.Add(imgCompLogo);
            message.AlternateViews.Add(htmlview);
            char[] split = { ';' };
            string[] strToEmailIds = ToEmail.Split(split);
            foreach (string strToMail in strToEmailIds)
            {
                if (strToMail != string.Empty)
                {
                    message.To.Add(strToMail);
                }
            }
            string[] strCcEmailIds = CcEmail.Split(split);
            foreach (string strCcMail in strCcEmailIds)
            {
                if (strCcMail != string.Empty)
                {
                    message.CC.Add(strCcMail);
                }
            }
            //ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
            // Send the e-mail message via the specified SMTP server
            client.Send(message);
            MailSendOrNot = 1;
        }
        catch (Exception errorInSendingMail)
        {
            //throw errorInSendingMail;
        }
    }
    public void TriggerMailForClient(string bodyContent, string subject, string ToEmail)
    {
        string scriptText;
        string FromEmailId = string.Empty;
        string SMTPHost = string.Empty;
        string SMTPPort = string.Empty;
        string NetUserName = string.Empty;
        string NetPassword = string.Empty;
        DataTable dtTableScript = new DataTable();
        MailMessage message = new MailMessage();
        try
        {
            string ScriptType = "License Request Client";
            dtTableScript = objLeaveApplicationEventData.GetEmailScripts(ScriptType);
            scriptText = dtTableScript.Rows[0]["ScriptText"].ToString();
            FromEmailId = Convert.ToString(ConfigurationManager.AppSettings["FromId"]);
            SMTPHost = Convert.ToString(ConfigurationManager.AppSettings["SMTPClientHost"]);
            SMTPPort = Convert.ToString(ConfigurationManager.AppSettings["SMTPPort"]);
            NetUserName = Convert.ToString(ConfigurationManager.AppSettings["MailAuthenticateUser"]);
            NetPassword = Convert.ToString(ConfigurationManager.AppSettings["MailAuthenticatePassword"]);
            NetworkCredential crdntl = new NetworkCredential();
            SmtpClient client = new SmtpClient(SMTPHost, Convert.ToInt32(SMTPPort));
            message.IsBodyHtml = true;
            message.Subject = subject + " | " + txtName.Text.Trim() + " | " + System.DateTime.Now.ToLongDateString();
            message.Body = scriptText.Replace("<<licenserequestusername>>", "<b>Dear " + txtName.Text + "</b>");
            message.Body = message.Body.Replace("<<licenserequestdetails>>", " You have send TimeCheck license requestion ");
            message.Body = message.Body.Replace("<<lblemployee>>", "Number Of Employees");
            message.Body = message.Body.Replace("<<employee>>", txtNoOfEmployee.Text);
            message.Body = message.Body.Replace("<<lblconcurrentusers>>", "Number Of Concurrent Users");
            message.Body = message.Body.Replace("<<concurrentusers>>", txtNoOfConcurrentUser.Text);
            message.Body = message.Body.Replace("<<lblterminals>>", "Number Of Terminals");
            message.Body = message.Body.Replace("<<terminals>>", txtNoOfTerminal.Text);
            message.Body = message.Body.Replace("<<lblversion>>", "Version Type");
            message.Body = message.Body.Replace("<<version>>", ddlVersionType.SelectedItem.Text);
            message.Body = message.Body.Replace("<<regards>>", "Regards,");
            message.Body = message.Body.Replace("<<clientname>>", "TimeCheck");
            message.From = new MailAddress(FromEmailId);
            AlternateView htmlview = default(AlternateView);
            htmlview = AlternateView.CreateAlternateViewFromString(message.Body, null, "text/html");
            LinkedResource imageResourceEs = new LinkedResource(Server.MapPath("~/images/" + "logo.png"), "image/png");
            imageResourceEs.ContentId = "image1";
            imageResourceEs.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            htmlview.LinkedResources.Add(imageResourceEs);
            LinkedResource imgCompLogo = new LinkedResource(Server.MapPath("~/images/" + "AngLogoNew_Email.png"), "image/png");
            imgCompLogo.ContentId = "imgCompLogo";
            imgCompLogo.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
            htmlview.LinkedResources.Add(imgCompLogo);
            message.AlternateViews.Add(htmlview);
            char[] split = { ';' };
            string[] strToEmailIds = ToEmail.Split(split);
            foreach (string strToMail in strToEmailIds)
            {
                if (strToMail != string.Empty)
                {
                    message.To.Add(strToMail);
                }
            }
            //string[] strCcEmailIds = CcEmail.Split(split);
            //foreach (string strCcMail in strCcEmailIds)
            //{
            //    if (strCcMail != string.Empty)
            //    {
            //        message.CC.Add(strCcMail);
            //    }
            //}
            //ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
            // Send the e-mail message via the specified SMTP server
            client.Send(message);
            MailSendOrNot = 1;
        }
        catch (Exception errorInSendingMail)
        {
            //throw errorInSendingMail;
        }
    }
    #endregion
    #endregion
}
