using System;
using System.Configuration;
using System.Data;
using System.Globalization;
//using System.IO;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
using OLServices;
public partial class System_Settings_SystemSetting_LicenseRequest : System.Web.UI.Page
{
    #region Variable Declarion
    int MailSendOrNot = 0;
    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;
    string secEmailID = string.Empty, versiontype = string.Empty;
    string VersionNumber = string.Empty;
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    ResourceManager rm;
    OL_Services Objservices = new OL_Services();
    Licensing objLic = new Licensing();
    CultureInfo ci;
    cls_Common objClassCommon = new cls_Common();
    #endregion
    #region PageLoad
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtName.Focus();
            ClearValues();
            objClassCommon.menu("LicenseManager", "197");
        }
        //Call to a function to implement the UserRights
        UserRights();
        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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_NoOFConcurrentUsers", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
    }
    #endregion
    #region Button Click Events
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("System_LicenseManager.aspx");
    }
    protected void btnGenerateLicenseRequest_Click(object sender, EventArgs e)
    {
        try
        {
            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;
                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='SystemSetting_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);
                                    }
                                    else
                                    {
                                        string strScript = "<script language='javascript' type='text/javascript'>";
                                        strScript += "alert('Email notification is not in enabled mode, please enabled it first and then try license requisition');";
                                        strScript += " </script>";
                                        this.RegisterStartupScript("AlertLicInfoNotCorrect", strScript);
                                        return;
                                    }
                                    ClearValues();
                                    ScriptManager.RegisterStartupScript(this, GetType(), "Alert", "alert('" + rm.GetString("Alert_LicenseRequestSendSuccessfully", ci) + "');window.location='SystemSetting_LicenseRequest.aspx';", true);
                                }
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(this, GetType(), "Alert", "alert('" + rm.GetString("Alert_Unabletosendlicenserequest", 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;
                        string[] fileArr = Directory.GetFiles(Server.MapPath("..\\LicenseFile"), "*.lic");
                        int arrCount = fileArr.Length;
                        if (arrCount > 0)
                        {
                            string licenseFileName = fileArr[arrCount - 1].ToString();
                            FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
                            StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
                            string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
                            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();
                        logger.FileName = Server.MapPath("../LicenseFile/" + company + ".lrf");
                        System.IO.FileInfo fileInfo = new System.IO.FileInfo(logger.FileName);
                        NodeLocking nodeLocking = new NodeLocking();
                        logger.Write(nodeLocking.GetEncryptedNodeId("", companyDetails));
                        Response.Clear();
                        Response.ContentType = MimeType(logger.FileName);
                        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;
                    string[] fileArr = Directory.GetFiles(Server.MapPath("..\\LicenseFile"), "*.lic");
                    int arrCount = fileArr.Length;
                    if (arrCount > 0)
                    {
                        string licenseFileName = fileArr[arrCount - 1].ToString();
                        FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
                        StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
                        string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
                        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();
                    }
                    companyDetails += "*" + customerIdLicFile;
                    companyDetails += "*" + noOfTerminal;
                    companyDetails += "*" + secEmailID;
                    companyDetails += "*" + versiontype;
                    companyDetails += "*" + VersionNumber;
                    Session["companyDetails"] = companyDetails;
                    Logger logger = new Logger();
                    logger.FileName = Server.MapPath("../LicenseFile/" + company + ".lrf");
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(logger.FileName);
                    NodeLocking nodeLocking = new NodeLocking();
                    logger.Write(nodeLocking.GetEncryptedNodeId("", companyDetails));
                    Response.Clear();
                    Response.ContentType = MimeType(logger.FileName);
                    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();
                }
            }
        }
        catch (Exception ex)
        {
            string strScript = "<script language='javascript' type='text/javascript'>";
            strScript += "alert('" + ex.ToString() + "');";
            strScript += " </script>";
            this.RegisterStartupScript("AlertLicInfoNotCorrect", strScript);
            return;
        }
    }
    #endregion
    #region User Defiened Functions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("License_Request_Generation", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lblCompanyDetail.Text = rm.GetString("Customer", ci);
        lblName.Text = rm.GetString("OrgLevels_CompDetails_Name", ci);
        lblAddress1.Text = rm.GetString("Address_1", ci);
        lblAddress2.Text = rm.GetString("Address_2", ci);
        lblCity.Text = rm.GetString("Masters_Generic_City", ci);
        lblZipCode.Text = rm.GetString("Zip_Code", ci);
        lblState.Text = rm.GetString("Masters_Generic_State", ci);
        lblCountry.Text = rm.GetString("Masters_Generic_Country", ci);
        lblCommunicationDetail.Text = rm.GetString("Communication", ci);
        lblTelephoneNo.Text = rm.GetString("Telephone_No", ci);
        lblFaxNo.Text = rm.GetString("Fax_No", ci);
        lblMobileNo.Text = rm.GetString("Mobile_No", ci);
        lblLicenseDetail.Text = rm.GetString("License_For", ci);
        lblNoOfConcurrentUser.Text = rm.GetString("No_Of_Concurrent_Users", ci);
        lblNoOfEmployee.Text = rm.GetString("No_Of_Employees", ci);
        lblNoOfTerminal.Text = rm.GetString("No_Of_Terminals", ci);
        txtSecEmailID.Text = rm.GetString("lblSecondaryEmail", ci);
        lblEmailId.Text = rm.GetString("EmployeeMaster_EmailId", ci);
        btnGenerateLicenseRequest.Text = "&nbsp;&nbsp;" + rm.GetString("Generate", ci);
        btnBack.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        rfvName.ErrorMessage = rm.GetString("Alert_EnterName", ci);
        rfvAddress1.ErrorMessage = rm.GetString("Alert_EnterAddress1", ci);
        rfvCity.ErrorMessage = rm.GetString("Alert_EnterCity", ci);
        rfvState.ErrorMessage = rm.GetString("Alert_EnterState", ci);
        rfvCountry.ErrorMessage = rm.GetString("Validator_State_CountryName", ci);
        rfvTelephoneno.ErrorMessage = rm.GetString("Alert_EnterTelePhoneNo", ci);
        rfvMobileNo.ErrorMessage = rm.GetString("Alert_EnterMobileNo", ci);
        rfvEmailId.ErrorMessage = rm.GetString("Alert_EnterEMailId", ci);
        rfvNoOfConcurrentUser.ErrorMessage = rm.GetString("Alert_EnteNoOfConcurrentUsers", ci);
        revMailId.ErrorMessage = rm.GetString("Alert_EnterValidEmailId", ci);
        rfvNoOfEmployee.ErrorMessage = rm.GetString("Alert_EnterNoOfEmployees", ci);
        rfvNoOfTerminal.ErrorMessage = rm.GetString("Alert_EnterNoOfTerminals", ci);
        ddlCountry.Items[0].Text = rm.GetString("Select", ci);
    }
    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;
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(197, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("SystemLandingPage.aspx");
        }
    }
    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.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);
                }
            }
            // 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.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);
                }
            }
            // Send the e-mail message via the specified SMTP server
            client.Send(message);
            MailSendOrNot = 1;
        }
        catch (Exception errorInSendingMail)
        {
            //throw errorInSendingMail;
        }
    }
    #endregion
    #endregion
}