using System;
using System.Data;
using System.Data.OleDb;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Text;
using System.Threading;
using System.Web.UI;
using Npgsql;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                        Started Date  : 30-July-2007
* Module          : Terminal Datatype Master                         Last Modified : 13-Aug-2007
* Programmer      : Kumuthini.L
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          : \\windev\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_TerminalDatatypeModify : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    // Create object for the Class TerminalDatatypeEventData to use the methods that are used to interact with the Database
    TerminalDatatypeEventData objTerminalDatatype = new TerminalDatatypeEventData();
    cls_Common objCommon = new cls_Common();
    // Global Declarations
    int TerminalDatatypeID;
    int gintUserId;
    string gstrUserGroupName = string.Empty;
    DataSet dsTerminalDataType = new DataSet();
    DataTable dtTerminalDataType = new DataTable();
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        // Get the culture info to set the language
        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);
        // Get the Employee ID who have Logged In. This is tracked for Audit Trail.
        gintUserId = Int32.Parse(Convert.ToString(Session["EmpAutoID"]));
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_SelectBrandType") + "','" + rm.GetString("Alert_FillRawDataFormat") + "','" + rm.GetString("Alert_SelectFileType") + "','" + rm.GetString("Alert_FillDelimiterSourcePath") + "','" + rm.GetString("Alert_FillDelimiterBackupPath") + "','" + rm.GetString("Alert_CheckBackupTypeRadioButton") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_FillNumberOfFieldsPath") + "','" + rm.GetString("Alert_FillDelimiter") + "','" + rm.GetString("ALert_SelectReaderNumber") + "','" + rm.GetString("ALert_SelectCardNumber") + "','" + rm.GetString("Alert_CheckRadioButton") + "','" + rm.GetString("ALert_SelectDate") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_EnterDateFormat") + "','" + rm.GetString("Alert_SelectTime") + "','" + rm.GetString("Alert_EnterTimeFormat") + "','" + rm.GetString("Alert_SelectDateTime") + "','" + rm.GetString("Alert_EnterDateTimeFormat") + "','" + rm.GetString("ReqField_PunchType") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_SelectTransactionIdentifier") + "','" + rm.GetString("Alert_EnterTransactionIndentifierValue") + "','" + rm.GetString("ALert_SelectdifferentFieldNamesintheDropdownLists") + "','" + rm.GetString("Alert_FillSourcePath") + "','" + rm.GetString("Alert_FillBackupPath") + "','" + rm.GetString("Alert_FillReaderNumberFrom") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_FillReaderNumberTo") + "','" + rm.GetString("Alert_FillCardNumberFrom") + "','" + rm.GetString("Alert_FillCardNumberTo") + "','" + rm.GetString("Alert_FillDateFrom") + "','" + rm.GetString("Alert_FillDateTo") + "','" + rm.GetString("Alert_FillTimeFrom") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_FillTimeTo") + "','" + rm.GetString("Alert_FillDateTimeFrom") + "','" + rm.GetString("Alert_FillDateTimeTo") + "','" + rm.GetString("Alert_FillPunchTypeFrom") + "','" + rm.GetString("Alert_FillPunchTypeTo") + "','" + rm.GetString("Alert_EnterTransactionIdentifierFrom") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_EnterTransactionIdentifierTo") + "','" + rm.GetString("Alert_FillConnectionString") + "','" + rm.GetString("Aleart_FillDBDatabaseName") + "','" + rm.GetString("Aleart_FillDBServerName") + "','" + rm.GetString("Aleart_FillMDBDataSource") + "','" + rm.GetString("Alert_FillTableName") + "','" + rm.GetString("Alert_FillReaderNumberFieldName") + "','" + rm.GetString("Alert_FillCardNumberFieldName") + "','" + rm.GetString("Alert_FillDateTimeFieldName") + "',";
        strSetAlert = strSetAlert + "'" + rm.GetString("Alert_FillDateFieldName") + "','" + rm.GetString("Alert_FillTimeFieldName") + "','" + rm.GetString("Alert_FillPunchTypeFieldName") + "','" + rm.GetString("Alert_EnterTransactionIdentifier") + "','" + rm.GetString("Alert_EnterFlagFieldName") + "','" + rm.GetString("Alert_ConfirmSave") + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        //Set UserRights
        UserRights();
        if (Session["UserGroupName"] != null)
        {
            gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        }
        // Get the Terminal DataType ID from the Query String from the Terminal Datatype Main Page
        try
        {
            TerminalDatatypeID = Convert.ToInt16(Cryptographys.Cryptography.Decrypt(Convert.ToString(Request.QueryString["TerminalDatatype_ID"]), "TimecheckPhaseI"));
        }
        catch
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
        if (!IsPostBack)
        {
            // Call the Function GetTerminalDatatypeDetails() by passing Terminal Datatype ID.
            GetTerminalDatatypeDetails(TerminalDatatypeID);
            objCommon.menu("Terminal", "223");
        }
        if (IsPostBack)
        {
            //Delimiter
            if (rbtDelDateTime.Checked == true)
            {
                //combined
                ddlDateTime.Enabled = true;
                txt_DelDateTimeFormat.Enabled = true;
                ddlDateTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_DelDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                //separate
                ddlDate.Enabled = false;
                txt_DelDateFormat.Enabled = false;
                ddlTime.Enabled = false;
                txt_DelTimeFormat.Enabled = false;
                ddlDate.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_DelDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                ddlTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_DelTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
            }
            else
            {
                //combined
                ddlDateTime.Enabled = false;
                txt_DelDateTimeFormat.Enabled = false;
                ddlDateTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_DelDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                //separate
                ddlDate.Enabled = true;
                txt_DelDateFormat.Enabled = true;
                ddlTime.Enabled = true;
                txt_DelTimeFormat.Enabled = true;
                ddlDate.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_DelDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                ddlTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_DelTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
            }
            if (rbtFLDateTime.Checked == true)
            {
                //fixed length
                //combined
                txtFL_DateTimeFrom.Enabled = true;
                txtFL_DateTimeTo.Enabled = true;
                txt_FLDateTimeFormat.Enabled = true;
                txtFL_DateTimeFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txtFL_DateTimeTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_FLDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                //separate
                txtFL_DateFrom.Enabled = false;
                txtFL_DateTo.Enabled = false;
                txt_FLDateFormat.Enabled = false;
                txtFL_TimeFrom.Enabled = false;
                txtFL_TimeTo.Enabled = false;
                txt_FLTimeFormat.Enabled = false;
                txtFL_DateFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txtFL_DateTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_FLDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txtFL_TimeFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txtFL_TimeTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_FLTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
            }
            else
            {
                //combined
                txtFL_DateTimeFrom.Enabled = false;
                txtFL_DateTimeTo.Enabled = false;
                txt_FLDateTimeFormat.Enabled = false;
                txtFL_DateTimeFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txtFL_DateTimeTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_FLDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                //separate
                txtFL_DateFrom.Enabled = true;
                txtFL_DateTo.Enabled = true;
                txt_FLDateFormat.Enabled = true;
                txtFL_TimeFrom.Enabled = true;
                txtFL_TimeTo.Enabled = true;
                txt_FLTimeFormat.Enabled = true;
                txtFL_DateFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txtFL_DateTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_FLDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txtFL_TimeFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txtFL_TimeTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_FLTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
            }
            //DBMS
            if (rbtDateTime.Checked == true)
            {
                //combined
                txtRDBMSDateTime.Enabled = true;
                txt_RDBMSDateTimeFormat.Enabled = true;
                txtRDBMSDateTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_RDBMSDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                //separate
                txtRDBMSDate.Enabled = false;
                txt_RDBMSDateFormat.Enabled = false;
                txtRDBMSTime.Enabled = false;
                txt_RDBMSTimeFormat.Enabled = false;
                txtRDBMSDate.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_RDBMSDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txtRDBMSTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_RDBMSTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
            }
            else
            {
                //combined
                txtRDBMSDateTime.Enabled = false;
                txt_RDBMSDateTimeFormat.Enabled = false;
                txtRDBMSDateTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                txt_RDBMSDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                //separate
                txtRDBMSDate.Enabled = true;
                txt_RDBMSDateFormat.Enabled = true;
                txtRDBMSTime.Enabled = true;
                txt_RDBMSTimeFormat.Enabled = true;
                txtRDBMSDate.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_RDBMSDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txtRDBMSTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                txt_RDBMSTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
            }
        }
    }
    // **********************************************************************************************************************
    // Function Name : GetTerminalDatatypeDetails
    // Purpose :
    //     The GetTerminalDatatypeDetails Method is used to get the Details of the Terminal Datatype for a particular 
    //     Terminal Datatype ID and the details are assigned to the appropriate Controls
    // Inputs  :
    //     TerminalDatatypeID : Terminal Datatype ID
    // **********************************************************************************************************************
    #endregion
    #region UserDefinedFunctions
    private void GetTerminalDatatypeDetails(int TerminalDatatypeID)
    {
        //Get the Details of Terminal DataType by passing ID and store it in the Data Table
        dsTerminalDataType = objTerminalDatatype.Select_TerminalDatatypebyId(TerminalDatatypeID, gstrUserGroupName);
        dtTerminalDataType = dsTerminalDataType.Tables[0];
        // If Records are present
        if (dtTerminalDataType.Rows.Count > 0)
        {
            // Check for DBNull and Assign all the Terminal Datatype Details to the appropriate Controls
            if (dtTerminalDataType.Rows[0]["DisplayName"] != DBNull.Value)
                lblBrandType.Text = Convert.ToString(dtTerminalDataType.Rows[0]["DisplayName"]);
            if (dtTerminalDataType.Rows[0]["Raw_Data_Format"] != DBNull.Value)
                lblRawDataFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["Raw_Data_Format"]);
            if (dtTerminalDataType.Rows[0]["FileType"] != DBNull.Value)
                lblFileType.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FileType"]);
            if (dtTerminalDataType.Rows[0]["IsFreeScan"] != DBNull.Value)
                if (Convert.ToInt32(dtTerminalDataType.Rows[0]["IsFreeScan"]) == 1)
                {
                    rb_Yes.Checked = true;
                    rb_No.Checked = false;
                }
                else
                {
                    rb_No.Checked = true;
                    rb_Yes.Checked = false;
                }

            switch (Convert.ToString(lblFileType.Text))
            {
                case "Delimiter":
                    lblmancount.Text = "8";
                    if (dtTerminalDataType.Rows[0]["File_SourcePath"] != DBNull.Value)
                    {
                        txtDelimiterSourePath.Text = Convert.ToString(dtTerminalDataType.Rows[0]["File_SourcePath"]);
                    }
                    if (dtTerminalDataType.Rows[0]["File_BackupPath"] != DBNull.Value)
                    {
                        txtDelimiterBackupPath.Text = Convert.ToString(dtTerminalDataType.Rows[0]["File_BackupPath"]);
                    }
                    if (dtTerminalDataType.Rows[0]["Delimiter_NoOfFields"] != DBNull.Value)
                    {
                        txtNumberOfFields.Text = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_NoOfFields"]);
                    }
                    if (dtTerminalDataType.Rows[0]["File_BackupType"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["File_BackupType"]) == "MF")
                        {
                            rbt_DelMove.Checked = true;
                        }
                        else if (Convert.ToString(dtTerminalDataType.Rows[0]["File_BackupType"]) == "SF")
                        {
                            rbt_DelRename.Checked = true;
                        }
                    }
                    // This FillDropDownLists Function call is to fill the Reader No, Card No, Date, Time, DateTime and Type DropDown Lists
                    FillDropDownLists();
                    if (dtTerminalDataType.Rows[0]["Delimiter_Delimiter"] != DBNull.Value)
                    {
                        txtDelimiter.Text = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_Delimiter"]);
                    }
                    if (dtTerminalDataType.Rows[0]["Delimiter_StringEnclosedBy"] != DBNull.Value)
                    {
                        txtStringEnclosedBy.Text = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_StringEnclosedBy"]);
                    }
                    if (dtTerminalDataType.Rows[0]["Delimiter_ReaderNo"] != DBNull.Value)
                    {
                        ddlReaderNo.SelectedValue = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_ReaderNo"]);
                    }
                    if (dtTerminalDataType.Rows[0]["IsEmployeeId"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["IsEmployeeId"]) == "True")
                        {
                            chk_EmployeeId1.Checked = true;
                        }
                    }
                    if (dtTerminalDataType.Rows[0]["Delimiter_CardNo"] != DBNull.Value)
                    {
                        ddlCardNo.SelectedValue = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_CardNo"]);
                    }
                    if (dtTerminalDataType.Rows[0]["Delimiter_DateTimeBit"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_DateTimeBit"]) == "True")
                        {
                            rbtDelDateTime.Checked = true;
                            if (dtTerminalDataType.Rows[0]["Delimiter_DateTime"] != DBNull.Value)
                            {
                                ddlDateTime.SelectedValue = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_DateTime"]);
                            }
                            if (dtTerminalDataType.Rows[0]["DateTimeFormat"] != DBNull.Value)
                            {
                                txt_DelDateTimeFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["DateTimeFormat"]);
                            }
                            //combined
                            ddlDateTime.Enabled = true;
                            txt_DelDateTimeFormat.Enabled = true;
                            ddlDateTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txt_DelDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            //separate
                            ddlDate.Enabled = false;
                            txt_DelDateFormat.Enabled = false;
                            ddlTime.Enabled = false;
                            txt_DelTimeFormat.Enabled = false;
                            ddlDate.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_DelDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            ddlTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_DelTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                        }
                        else if (Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_DateTimeBit"]) == "False")
                        {
                            rbtDelDateTimeSeperate.Checked = true;
                            if ((dtTerminalDataType.Rows[0]["Delimiter_Date"] != DBNull.Value) && (dtTerminalDataType.Rows[0]["Delimiter_Time"] != DBNull.Value))
                            {
                                ddlDate.SelectedValue = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_Date"]);
                                ddlTime.SelectedValue = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_Time"]);
                            }
                            if (dtTerminalDataType.Rows[0]["DateFormat"] != DBNull.Value)
                            {
                                txt_DelDateFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["DateFormat"]);
                            }
                            if (dtTerminalDataType.Rows[0]["TimeFormat"] != DBNull.Value)
                            {
                                txt_DelTimeFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["TimeFormat"]);
                            }
                            //combined
                            ddlDateTime.Enabled = false;
                            txt_DelDateTimeFormat.Enabled = false;
                            ddlDateTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_DelDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            //separate
                            ddlDate.Enabled = true;
                            txt_DelDateFormat.Enabled = true;
                            ddlTime.Enabled = true;
                            txt_DelTimeFormat.Enabled = true;
                            ddlDate.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txt_DelDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            ddlTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txt_DelTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                        }
                    }
                    ddlType.SelectedValue = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_Type"]);
                    if (dtTerminalDataType.Rows[0]["TransactionIdentifierBit"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["TransactionIdentifierBit"]) == "True")
                        {
                            chk_DelTransIdentifier.Checked = true;
                            if (dtTerminalDataType.Rows[0]["Delimiter_TransactionIdentifier"] != DBNull.Value)
                            {
                                ddlTransactionIdentifier.SelectedValue = Convert.ToString(dtTerminalDataType.Rows[0]["Delimiter_TransactionIdentifier"]);
                            }
                            if (dtTerminalDataType.Rows[0]["TransactionIdentifierValue"] != DBNull.Value)
                            {
                                txtDel_TIValue.Text = Convert.ToString(dtTerminalDataType.Rows[0]["TransactionIdentifierValue"]);
                            }
                        }
                    }
                    break;
                case "Fixed Length":
                    lblmancount.Text = "7";
                    if (dtTerminalDataType.Rows[0]["File_SourcePath"] != DBNull.Value)
                    {
                        txtFLSourcePath.Text = Convert.ToString(dtTerminalDataType.Rows[0]["File_SourcePath"]);
                    }
                    if (dtTerminalDataType.Rows[0]["File_BackupPath"] != DBNull.Value)
                    {
                        txtFLBackupPath.Text = Convert.ToString(dtTerminalDataType.Rows[0]["File_BackupPath"]);
                    }
                    if (dtTerminalDataType.Rows[0]["File_BackupType"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["File_BackupType"]) == "MF")
                        {
                            rbt_FLMove.Checked = true;
                        }
                        else if (Convert.ToString(dtTerminalDataType.Rows[0]["File_BackupType"]) == "SF")
                        {
                            rbt_FLRename.Checked = true;
                        }
                    }
                    if (dtTerminalDataType.Rows[0]["FixedLength_ReaderNoFrom"] != DBNull.Value)
                    {
                        txtFL_ReaderNoFrom.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_ReaderNoFrom"]);
                    }
                    if (dtTerminalDataType.Rows[0]["FixedLength_ReaderNoTo"] != DBNull.Value)
                    {
                        txtFL_ReaderNoTo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_ReaderNoTo"]);
                    }
                    if (dtTerminalDataType.Rows[0]["IsEmployeeId"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["IsEmployeeId"]) == "True")
                        {
                            chk_EmployeeId2.Checked = true;
                        }
                    }
                    if (dtTerminalDataType.Rows[0]["FixedLength_CardNoFrom"] != DBNull.Value)
                    {
                        txtFL_CardNoFrom.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_CardNoFrom"]);
                    }
                    if (dtTerminalDataType.Rows[0]["FixedLength_CardNoTo"] != DBNull.Value)
                    {
                        txtFL_CardNoTo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_CardNoTo"]);
                    }
                    if (dtTerminalDataType.Rows[0]["FixedLength_DateTimeBit"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_DateTimeBit"]) == "True")
                        {
                            rbtFLDateTime.Checked = true;
                            if (dtTerminalDataType.Rows[0]["FixedLength_DateTimeFrom"] != DBNull.Value)
                            {
                                txtFL_DateTimeFrom.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_DateTimeFrom"]);
                            }
                            if (dtTerminalDataType.Rows[0]["FixedLength_DateTimeTo"] != DBNull.Value)
                            {
                                txtFL_DateTimeTo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_DateTimeTo"]);
                            }
                            if (dtTerminalDataType.Rows[0]["DateTimeFormat"] != DBNull.Value)
                            {
                                txt_FLDateTimeFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["DateTimeFormat"]);
                            }
                            //combined
                            txtFL_DateTimeFrom.Enabled = true;
                            txtFL_DateTimeTo.Enabled = true;
                            txt_FLDateTimeFormat.Enabled = true;
                            txtFL_DateTimeFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txtFL_DateTimeTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txt_FLDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            //separate
                            txtFL_DateFrom.Enabled = false;
                            txtFL_DateTo.Enabled = false;
                            txt_FLDateFormat.Enabled = false;
                            txtFL_TimeFrom.Enabled = false;
                            txtFL_TimeTo.Enabled = false;
                            txt_FLTimeFormat.Enabled = false;
                            txtFL_DateFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txtFL_DateTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_FLDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txtFL_TimeFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txtFL_TimeTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_FLTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                        }
                        else if (Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_DateTimeBit"]) == "False")
                        {
                            rbtFLDateTimeSeperate.Checked = true;
                            if (dtTerminalDataType.Rows[0]["FixedLength_DateFrom"] != DBNull.Value)
                            {
                                txtFL_DateFrom.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_DateFrom"]);
                            }
                            if (dtTerminalDataType.Rows[0]["FixedLength_DateTo"] != DBNull.Value)
                            {
                                txtFL_DateTo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_DateTo"]);
                            }
                            if (dtTerminalDataType.Rows[0]["DateFormat"] != DBNull.Value)
                            {
                                txt_FLDateFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["DateFormat"]);
                            }
                            if (dtTerminalDataType.Rows[0]["FixedLength_TimeFrom"] != DBNull.Value)
                            {
                                txtFL_TimeFrom.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_TimeFrom"]);
                            }
                            if (dtTerminalDataType.Rows[0]["FixedLength_TimeTo"] != DBNull.Value)
                            {
                                txtFL_TimeTo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_TimeTo"]);
                            }
                            if (dtTerminalDataType.Rows[0]["TimeFormat"] != DBNull.Value)
                            {
                                txt_FLTimeFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["TimeFormat"]);
                            }
                            //combined
                            txtFL_DateTimeFrom.Enabled = false;
                            txtFL_DateTimeTo.Enabled = false;
                            txt_FLDateTimeFormat.Enabled = false;
                            txtFL_DateTimeFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txtFL_DateTimeTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_FLDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            //separate
                            txtFL_DateFrom.Enabled = true;
                            txtFL_DateTo.Enabled = true;
                            txt_FLDateFormat.Enabled = true;
                            txtFL_TimeFrom.Enabled = true;
                            txtFL_TimeTo.Enabled = true;
                            txt_FLTimeFormat.Enabled = true;
                            txtFL_DateFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txtFL_DateTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txt_FLDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txtFL_TimeFrom.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txtFL_TimeTo.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txt_FLTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                        }
                    }
                    if (dtTerminalDataType.Rows[0]["FixedLength_TypeFrom"] != DBNull.Value)
                    {
                        txtFL_TypeFrom.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_TypeFrom"]);
                    }
                    if (dtTerminalDataType.Rows[0]["FixedLength_TypeTo"] != DBNull.Value)
                    {
                        txtFL_TypeTo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_TypeTo"]);
                    }
                    if (dtTerminalDataType.Rows[0]["TransactionIdentifierBit"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["TransactionIdentifierBit"]) == "True")
                        {
                            chk_FLTransIdentifier.Checked = true;
                            if (dtTerminalDataType.Rows[0]["FixedLength_TransactionIdentifierFrom"] != DBNull.Value)
                            {
                                txtFL_TransIdentifierFrom.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_TransactionIdentifierFrom"]);
                            }
                            if (dtTerminalDataType.Rows[0]["FixedLength_TransactionIdentifierTo"] != DBNull.Value)
                            {
                                txtFL_TransIdentifierTo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["FixedLength_TransactionIdentifierTo"]);
                            }
                            if (dtTerminalDataType.Rows[0]["TransactionIdentifierValue"] != DBNull.Value)
                            {
                                txtFL_TIValue.Text = Convert.ToString(dtTerminalDataType.Rows[0]["TransactionIdentifierValue"]);
                            }
                        }
                    }
                    break;
                case "RDBMS":
                case "MariaDB":
                case "PostgreSQL":
                    lblmancount.Text = "7";
                    if (dtTerminalDataType.Rows[0]["RDBMS_ReaderNo"] != DBNull.Value)
                        txtRDBMSReaderNo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_ReaderNo"]);
                    if (dtTerminalDataType.Rows[0]["RDBMS_CardNo"] != DBNull.Value)
                        txtRDBMSCardNo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_CardNo"]);
                    if (dtTerminalDataType.Rows[0]["RDBMS_DateTimeBit"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_DateTimeBit"]) == "True")
                        {
                            rbtDateTime.Checked = true;
                            if (dtTerminalDataType.Rows[0]["RDBMS_DateTime"] != DBNull.Value)
                            {
                                txtRDBMSDateTime.Text = Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_DateTime"]);
                            }
                            //combined
                            txtRDBMSDateTime.Enabled = true;
                            txt_RDBMSDateTimeFormat.Enabled = true;
                            txtRDBMSDateTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txt_RDBMSDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            //separate
                            txtRDBMSDate.Enabled = false;
                            txt_RDBMSDateFormat.Enabled = false;
                            txtRDBMSTime.Enabled = false;
                            txt_RDBMSTimeFormat.Enabled = false;
                            txtRDBMSDate.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_RDBMSDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txtRDBMSTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_RDBMSTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                        }
                        else if (Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_DateTimeBit"]) == "False")
                        {
                            rbtDateTimeSeperate.Checked = true;
                            if ((dtTerminalDataType.Rows[0]["RDBMS_Date"] != DBNull.Value) && (dtTerminalDataType.Rows[0]["RDBMS_Time"] != DBNull.Value))
                            {
                                txtRDBMSDate.Text = Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_Date"]);
                                txtRDBMSTime.Text = Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_Time"]);
                                if (Convert.ToString(dtTerminalDataType.Rows[0]["IsEncrypted"]) == "True")
                                {
                                    chkEncrypted.Checked = true;
                                }
                            }
                            //combined
                            txtRDBMSDateTime.Enabled = false;
                            txt_RDBMSDateTimeFormat.Enabled = false;
                            txtRDBMSDateTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            txt_RDBMSDateTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");
                            //separate
                            txtRDBMSDate.Enabled = true;
                            txt_RDBMSDateFormat.Enabled = true;
                            txtRDBMSTime.Enabled = true;
                            txt_RDBMSTimeFormat.Enabled = true;
                            txtRDBMSDate.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_RDBMSDateFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txtRDBMSTime.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                            txt_RDBMSTimeFormat.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                        }
                    }
                    if (dtTerminalDataType.Rows[0]["RDBMS_Type"] != DBNull.Value)
                    {
                        txtRDBMSType.Text = Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_Type"]);
                    }
                    if (dtTerminalDataType.Rows[0]["TransactionIdentifierBit"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["TransactionIdentifierBit"]) == "True")
                        {
                            chk_TransIdentifier.Checked = true;
                            if (dtTerminalDataType.Rows[0]["RDBMS_TransactionIdentifier"] != DBNull.Value)
                                txt_RDBMSTransactionIdentifier.Text = Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_TransactionIdentifier"]);
                            if (dtTerminalDataType.Rows[0]["TransactionIdentifierValue"] != DBNull.Value)
                                txt_TIValue.Text = Convert.ToString(dtTerminalDataType.Rows[0]["TransactionIdentifierValue"]);
                        }
                    }
                    break;
                case "MDB":
                    lblmancount.Text = "6";
                    if (dtTerminalDataType.Rows[0]["MDB_ReaderNo"] != DBNull.Value)
                    {
                        txtRDBMSReaderNo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["MDB_ReaderNo"]);
                    }
                    if (dtTerminalDataType.Rows[0]["MDB_CardNo"] != DBNull.Value)
                    {
                        txtRDBMSCardNo.Text = Convert.ToString(dtTerminalDataType.Rows[0]["MDB_CardNo"]);
                    }
                    if (dtTerminalDataType.Rows[0]["MDB_DateTimeBit"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["MDB_DateTimeBit"]) == "True")
                        {
                            rbtDateTime.Checked = true;
                            if (dtTerminalDataType.Rows[0]["MDB_DateTime"] != DBNull.Value)
                            {
                                txtRDBMSDateTime.Text = Convert.ToString(dtTerminalDataType.Rows[0]["MDB_DateTime"]);
                            }
                        }
                        else if (Convert.ToString(dtTerminalDataType.Rows[0]["MDB_DateTimeBit"]) == "False")
                        {
                            rbtDateTimeSeperate.Checked = true;
                            if ((dtTerminalDataType.Rows[0]["MDB_Date"] != DBNull.Value) && (dtTerminalDataType.Rows[0]["MDB_Time"] != DBNull.Value))
                            {
                                txtRDBMSDate.Text = Convert.ToString(dtTerminalDataType.Rows[0]["MDB_Date"]);
                                txtRDBMSTime.Text = Convert.ToString(dtTerminalDataType.Rows[0]["MDB_Time"]);
                                if (Convert.ToString(dtTerminalDataType.Rows[0]["IsEncrypted"]) == "True")
                                {
                                    chkEncrypted.Checked = true;
                                }
                            }
                        }
                    }
                    if (dtTerminalDataType.Rows[0]["MDB_Type"] != DBNull.Value)
                    {
                        txtRDBMSType.Text = Convert.ToString(dtTerminalDataType.Rows[0]["MDB_Type"]);
                    }
                    if (dtTerminalDataType.Rows[0]["TransactionIdentifierBit"] != DBNull.Value)
                    {
                        if (Convert.ToString(dtTerminalDataType.Rows[0]["TransactionIdentifierBit"]) == "True")
                        {
                            chk_TransIdentifier.Checked = true;
                            if (dtTerminalDataType.Rows[0]["MDB_TransactionIdentifier"] != DBNull.Value)
                            {
                                txt_RDBMSTransactionIdentifier.Text = Convert.ToString(dtTerminalDataType.Rows[0]["MDB_TransactionIdentifier"]);
                            }
                            if (dtTerminalDataType.Rows[0]["TransactionIdentifierValue"] != DBNull.Value)
                            {
                                txt_TIValue.Text = Convert.ToString(dtTerminalDataType.Rows[0]["TransactionIdentifierValue"]);
                            }
                        }
                    }
                    break;
            }
            if (lblFileType.Text == "RDBMS" || lblFileType.Text == "MDB" || lblFileType.Text == "MariaDB")
            {
                if (dtTerminalDataType.Rows[0]["ConnectionString"] != DBNull.Value)
                {
                    //This Line add by karthikeyan R for Check encrypt or decrypt connection string
                    char[] split = { ';' };
                    string strSpt = "";
                    string sptChr = Convert.ToString(dtTerminalDataType.Rows[0]["ConnectionString"]);
                    if (sptChr != "")
                    {
                        string[] strFilters = sptChr.Split(split);
                        if (strFilters.Length > 1)
                            txtConnectionString.Text = Convert.ToString(dtTerminalDataType.Rows[0]["ConnectionString"]);
                        else
                            txtConnectionString.Text = Encryption.Decrypt(Convert.ToString(dtTerminalDataType.Rows[0]["ConnectionString"]), "");
                    }
                    strSpt = "";
                    string strSpt1 = "";
                    switch (Convert.ToString(lblFileType.Text))
                    {
                        case "RDBMS":
                        case "MariaDB":
                            strSpt = splitstring(';', txtConnectionString.Text, 1);
                            strSpt1 = splitstring('=', strSpt, 1);
                            txtServerName.Text = strSpt1;
                            strSpt = "";
                            strSpt1 = "";
                            strSpt = splitstring(';', txtConnectionString.Text, 2);
                            strSpt1 = splitstring('=', strSpt, 1);
                            txtDBName.Text = strSpt1;
                            strSpt = "";
                            strSpt1 = "";
                            strSpt = splitstring(';', txtConnectionString.Text, 3);
                            strSpt1 = splitstring('=', strSpt, 1);
                            txtDBUserName.Text = strSpt1;
                            strSpt = "";
                            strSpt1 = "";
                            strSpt = splitstring(';', txtConnectionString.Text, 4);
                            strSpt1 = splitstring('=', strSpt, 1);
                            txtDBPassword.Attributes["value"] = strSpt1;
                            txtDBPassword.Attributes.Add("value", strSpt1);
                            txtDBPassword.Text = strSpt1;
                            break;
                        default:
                            strSpt = splitstring(';', Convert.ToString(txtConnectionString.Text), 1);
                            strSpt1 = splitstring('=', strSpt, 1);
                            txtMDBDataSource.Text = strSpt1;
                            strSpt = "";
                            strSpt1 = "";
                            strSpt = splitstring(';', Convert.ToString(txtConnectionString.Text), 2);
                            strSpt1 = splitstring('=', strSpt, 1);
                            txtMDBUserName.Text = strSpt1;
                            strSpt = "";
                            strSpt1 = "";
                            strSpt = splitstring(';', Convert.ToString(txtConnectionString.Text), 3);
                            strSpt1 = splitstring('=', strSpt, 1);
                            txtMDBPassword.Text = strSpt1;
                            break;
                    }
                }
                if (dtTerminalDataType.Rows[0]["TableName"] != DBNull.Value)
                    txtTableName.Text = Convert.ToString(dtTerminalDataType.Rows[0]["TableName"]);
                if (dtTerminalDataType.Rows[0]["RDBMS_MDB_Flag"] != DBNull.Value)
                    txt_FlagField.Text = Convert.ToString(dtTerminalDataType.Rows[0]["RDBMS_MDB_Flag"]);
                if (dtTerminalDataType.Rows[0]["DateTimeFormat"] != DBNull.Value)
                    txt_RDBMSDateTimeFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["DateTimeFormat"]);
                if (dtTerminalDataType.Rows[0]["DateFormat"] != DBNull.Value)
                    txt_RDBMSDateFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["DateFormat"]);
                if (dtTerminalDataType.Rows[0]["TimeFormat"] != DBNull.Value)
                    txt_RDBMSTimeFormat.Text = Convert.ToString(dtTerminalDataType.Rows[0]["TimeFormat"]);
                if (dtTerminalDataType.Rows[0]["IsEmployeeId"] != DBNull.Value)
                    if (Convert.ToString(dtTerminalDataType.Rows[0]["IsEmployeeId"]) == "True")
                        chk_EmployeeId3.Checked = true;
            }
        }
    }
    //This Add karthikeyan tom split Connectionsting 
    protected string splitstring(char chrStr, string sptChr, int sptCount)
    {
        char[] split = { chrStr };
        string strSpt = "";
        if (sptChr != "")
        {
            string[] strFilters = sptChr.Split(split);
            strSpt = "";
            strSpt = strFilters[sptCount];
        }
        return strSpt;
    }
    // NumberOfFields Text Box - TextChanged Event
    // Whenever Text in the NumberOfFields Text Box changes, the below function gets executed
    protected void txtNumberOfFields_TextChanged(object sender, EventArgs e)
    {
        // This FillDropDownLists Function call is to fill the Reader No, Card No, Date, Time, DateTime and Type DropDown Lists
        FillDropDownLists();
    }
    // **********************************************************************************************************************
    // Function Name : FillDropDownLists
    // Purpose :
    //     The FillDropDownLists Method to fill the Reader No, Card No, Date, Time, DateTime and Type DropDown Lists based
    //     on the value entered in the NumberOfFields TextBox
    // **********************************************************************************************************************
    public void FillDropDownLists()
    {
        /* 
          Based on the value in the NumberOfFields Text Box, then that many number of Field
          will be displayed in the Reader No, Card No, Date, Time, DateTime and Type DropDown Lists. 
          This will available if File Type selected is Delimiter. 
       */
        // Clear all the items in the DropDown Lists
        ddlReaderNo.Items.Clear();
        ddlCardNo.Items.Clear();
        ddlDate.Items.Clear();
        ddlTime.Items.Clear();
        ddlDateTime.Items.Clear();
        ddlType.Items.Clear();
        ddlTransactionIdentifier.Items.Clear();
        // Add the Default Item -Select- in the DropDown Lists
        ddlReaderNo.Items.Add("-Select-");
        ddlCardNo.Items.Add("-Select-");
        ddlDate.Items.Add("-Select-");
        ddlTime.Items.Add("-Select-");
        ddlDateTime.Items.Add("-Select-");
        ddlType.Items.Add("-Select-");
        ddlTransactionIdentifier.Items.Add("-Select-");
        // Based on the value in the Number Of Fields Text Box, add that many no. of items in the DropDown Lists
        for (int i = 1; i <= Convert.ToInt16(this.txtNumberOfFields.Text); i++)
        {
            ddlReaderNo.Items.Add("Field" + i);
            ddlCardNo.Items.Add("Field" + i);
            ddlDate.Items.Add("Field" + i);
            ddlTime.Items.Add("Field" + i);
            ddlDateTime.Items.Add("Field" + i);
            ddlType.Items.Add("Field" + i);
            ddlTransactionIdentifier.Items.Add("Field" + i);
        }
    }
    // Cancel Button - Click Event
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        //Response.Redirect("TA_UI_Master_TerminalDatatypeView.aspx?TerminalDatatype_ID=" + TerminalDatatypeID);
        Response.Redirect("TA_UI_Master_TerminalDatatype.aspx");
    }
    // **********************************************************************************************************************
    // Function Name : LoadStrings
    // Purpose :
    //     LoadStrings Function is used to get Information from resource file and display it in label
    // **********************************************************************************************************************
    private void LoadStrings(CultureInfo ci)
    {
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_Rawformat.Text = rm.GetString("TerminalDataType_RawDataFormat", ci);
        lbl_Filetype.Text = rm.GetString("TerminalDataType_FileType", ci);
        lbl_FileSourcePath1.Text = rm.GetString("TerminalDataType_File_Src_Path", ci);
        lbl_FileBackupPath1.Text = rm.GetString("TerminalDataType_File_Backup_Path", ci);
        lbl_DelBackupType.Text = rm.GetString("TerminalDataType_BackupType", ci);
        rbt_DelMove.Text = rm.GetString("rbtn_TerminalDataType_Move", ci);
        rbt_DelRename.Text = rm.GetString("rbtn_TerminalDataType_Rename", ci);
        lbl_NumberofFields.Text = rm.GetString("TerminalDataType_No_Of_Fields", ci);
        lbl_Delimiter.Text = rm.GetString("TerminalDataType_Delimiter", ci);
        lbl_StringEnclosedBy.Text = rm.GetString("TerminalDataType_Str_Enclosed_By", ci);
        lbl_OurFormat1.Text = rm.GetString("TerminalDataType_OurFormat", ci);
        lbl_RawFileFields1.Text = rm.GetString("TerminalDataType_RawFileFields", ci);
        lbl_ReaderNo1.Text = rm.GetString("TerminalDataType_Reader_No", ci);
        lbl_CardNo1.Text = rm.GetString("TerminalDataType_Card_No", ci);
        chk_EmployeeId1.Text = rm.GetString("email_EmployeeId", ci);
        lbl_DateandTime1.Text = rm.GetString("TerminalDataType_Date_And_Time", ci);
        lbl_DateandTime2.Text = rm.GetString("TerminalDataType_Date_And_Time", ci);
        lbl_Date1.Text = rm.GetString("Reports_Date", ci);
        lbl_Time1.Text = rm.GetString("TerminalDataType_Time", ci);
        lbl_DelDateTimeFormat.Text = rm.GetString("TerminalDataType_DateTimeFormat", ci);
        lbl_DelDateFormat.Text = rm.GetString("DateandTimeFormat_DateFormat", ci);
        lbl_DelTimeFormat.Text = rm.GetString("DateandTimeFormat_TimeFormat", ci);
        lbl_Type1.Text = rm.GetString("PunchTypes_PunchTypes", ci);
        lbl_TransactionIdentifier1.Text = rm.GetString("TerminalDataType_TransactionIdentifier", ci);
        lblDel_TIValue.Text = rm.GetString("TerminalDataType_TransactionIdentifier_Value", ci);
        lbl_FileSourcePath2.Text = rm.GetString("TerminalDataType_File_Src_Path", ci);
        lbl_FileBackupPath2.Text = rm.GetString("TerminalDataType_File_Backup_Path", ci);
        lbl_FLBackupType.Text = rm.GetString("TerminalDataType_BackupType", ci);
        rbt_FLMove.Text = rm.GetString("rbtn_TerminalDataType_Move", ci);
        rbt_FLRename.Text = rm.GetString("rbtn_TerminalDataType_Rename", ci);
        lbl_OurFormat2.Text = rm.GetString("TerminalDataType_OurFormat", ci);
        lbl_RawFileFields2.Text = rm.GetString("TerminalDataType_RawFileFields", ci);
        lbl_ReaderNo2.Text = rm.GetString("TerminalDataType_Reader_No", ci);
        lbl_CardNo2.Text = rm.GetString("TerminalDataType_Card_No", ci);
        chk_EmployeeId2.Text = rm.GetString("email_EmployeeId", ci);
        lbl_Date2.Text = rm.GetString("Reports_Date", ci);
        lbl_Time2.Text = rm.GetString("TerminalDataType_Time", ci);
        lbl_DateandTime3.Text = rm.GetString("TerminalDataType_Date_And_Time", ci);
        lbl_FLDateTimeFormat.Text = rm.GetString("TerminalDataType_DateTimeFormat", ci);
        lbl_FLDateFormat.Text = rm.GetString("DateandTimeFormat_DateFormat", ci);
        lbl_FLTimeFormat.Text = rm.GetString("DateandTimeFormat_TimeFormat", ci);
        lbl_Type2.Text = rm.GetString("PunchTypes_PunchTypes", ci);
        chk_FLTransIdentifier.Text = rm.GetString("TerminalDataType_TransactionIdentifier", ci);
        lblFL_TIValue.Text = rm.GetString("TerminalDataType_TransactionIdentifier_Value", ci);
        lbl_From1.Text = rm.GetString("email_FromDate", ci);
        lbl_From2.Text = rm.GetString("email_FromDate", ci);
        lbl_From3.Text = rm.GetString("email_FromDate", ci);
        lbl_From4.Text = rm.GetString("email_FromDate", ci);
        lbl_From5.Text = rm.GetString("email_FromDate", ci);
        lbl_From6.Text = rm.GetString("email_FromDate", ci);
        lbl_From7.Text = rm.GetString("email_FromDate", ci);
        lbl_To1.Text = rm.GetString("email_ToDate", ci);
        lbl_To2.Text = rm.GetString("email_ToDate", ci);
        lbl_To3.Text = rm.GetString("email_ToDate", ci);
        lbl_To4.Text = rm.GetString("email_ToDate", ci);
        lbl_To5.Text = rm.GetString("email_ToDate", ci);
        lbl_To6.Text = rm.GetString("email_ToDate", ci);
        lbl_To7.Text = rm.GetString("email_ToDate", ci);
        lbl_ConStr.Text = rm.GetString("lbl_ConnectionFilePath", ci);
        lbl_ConStr1.Text = rm.GetString("lbl_ConnectionFilePath", ci);
        lbl_ConnectionString.Text = rm.GetString("TerminalDataType_Con_string", ci);
        lbl_TableName.Text = rm.GetString("TerminalDataType_Table_Name", ci);
        lbl_OurFormat3.Text = rm.GetString("TerminalDataType_OurFormat", ci);
        lbl_RawFileFields3.Text = rm.GetString("TerminalDataType_RawFileFields", ci);
        lbl_ReaderNo3.Text = rm.GetString("TerminalDataType_Reader_No", ci);
        lbl_CardNo3.Text = rm.GetString("TerminalDataType_Card_No", ci);
        chk_EmployeeId3.Text = rm.GetString("email_EmployeeId", ci);
        lbl_DateandTime4.Text = rm.GetString("TerminalDataType_Date_And_Time", ci);
        lbl_DateandTime5.Text = rm.GetString("TerminalDataType_Date_And_Time", ci);
        lbl_Type3.Text = rm.GetString("PunchTypes_PunchTypes", ci);
        lbl_TransactionIdentifier3.Text = rm.GetString("TerminalDataType_TransactionIdentifier", ci);
        lbl_TIValue.Text = rm.GetString("TerminalDataType_TransactionIdentifier_Value", ci);
        lbl_FlagField.Text = rm.GetString("TerminalDatatype_FlagField", ci);
        lbl_Date3.Text = rm.GetString("Reports_Date", ci);
        lbl_Time3.Text = rm.GetString("TerminalDataType_Time", ci);
        lbl_RDBMSDateTimeFormat.Text = rm.GetString("TerminalDataType_DateTimeFormat", ci);
        lbl_RDBMSDateFormat.Text = rm.GetString("DateandTimeFormat_DateFormat", ci);
        lbl_RDBMSTimeFormat.Text = rm.GetString("DateandTimeFormat_TimeFormat", ci);
        rbtDateTime.Text = rm.GetString("DateTimeCombine", ci);
        rbtDateTimeSeperate.Text = rm.GetString("DateTimeSeparate", ci);
        rbtDelDateTime.Text = rm.GetString("DateTimeCombine", ci);
        rbtDelDateTimeSeperate.Text = rm.GetString("DateTimeSeparate", ci);
        rbtFLDateTime.Text = rm.GetString("DateTimeCombine", ci);
        rbtFLDateTimeSeperate.Text = rm.GetString("DateTimeSeparate", ci);
        lblDelimiterDateTimeSeparate.Text = rm.GetString("DateTimeSeparate", ci);
        lblDelimiterDateTimeCombine.Text = rm.GetString("DateTimeCombine", ci);
        lblFixedLengthDateTimeCombine.Text = rm.GetString("DateTimeCombine", ci);
        lblDBMSDateTimeCombine.Text = rm.GetString("DateTimeCombine", ci);
        lblDBMSDateTimeSeparate.Text = rm.GetString("DateTimeSeparate", ci);
        lbl_HeaderTerminalDatatype.Text = rm.GetString("Masters_Terminal_TerminalDataType", ci);
        btnModify.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Modify", ci);
        btnCancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lbl_BrandType.Text = rm.GetString("BrandType", ci);
        chkEncrypted.Text = rm.GetString("Encrypt", ci);
        lbl_DBServerName.Text = rm.GetString("Server_Name", ci);
        lbl_DBDatabaseName.Text = rm.GetString("DBDatabaseName", ci);
        lbl_DBUserName.Text = rm.GetString("DBUserID", ci);
        lbl_DBPassword.Text = rm.GetString("Caption_Password", ci);
        lbl_MDBDataSource.Text = rm.GetString("MDBDataSource", ci);
        lbl_MDBUserName.Text = rm.GetString("DBUserID", ci);
        lbl_MDBPassword.Text = rm.GetString("Caption_Password", ci);
        lblTerminalType.Text = rm.GetString("lbl_IsFreeScandevice", ci);
        rb_Yes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rb_No.Text = rm.GetString("ShiftSetting_No", ci);
        chk_TransIdentifier.Text = rm.GetString("TerminalDataType_TransactionIdentifier", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(10, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    /// <summary>
    /// Validate_s the connection string_ database_ table_ fields.
    /// </summary>
    /// <param name="connectionString">The connection string.</param>
    private bool Validate_ConnectionString_Database_Table_Fields(string connectionString, string tableName, string readerNo, string cardNo, string dateTime, string punchType, string transactionIdentifier, string flag)
    {
        string[] connectionStringArr = connectionString.Split(';');
        string checkStringSource = "Initial Catalog";
        checkStringSource = checkStringSource.ToUpper();
        string connection = string.Empty, databaseName = string.Empty;
        for (int i = 0; i < connectionStringArr.Length - 1; i++)
        {
            string[] initialCatalogPart = connectionStringArr[i].Split('=');
            string checkStringInput = Convert.ToString(initialCatalogPart[0]);
            checkStringInput = checkStringInput.ToUpper();
            if (checkStringSource == checkStringInput)
            {
                databaseName = Convert.ToString(initialCatalogPart[1]);
            }
            else
            {
                connection = connection + Convert.ToString(connectionStringArr[i]) + ";";
            }
        }
        // check for valid sql connection
        string checkConnection = connectionString;
        OleDbConnection oledbConnection;
        try
        {
            oledbConnection = new OleDbConnection(checkConnection);
            oledbConnection.Open();
            if (oledbConnection.State == ConnectionState.Open)
            {
                // connection string is correct                
            }
            else
            {
                // connection string is not correct check the connection string
                base.Message(rm.GetString("Alert_InvalidConnectionStringPleaseverify", ci));
                txtConnectionString.Focus();
                return false;
            }
        }
        catch (Exception ex)
        {
            base.Message(ex.Message);
            txtConnectionString.Focus();
            return false;
        }
        //We removed script execution as per client requisition on 06Feb2020 05:15 PM.
        //switch (Convert.ToString(lblBrandType.Text))
        //{
        //    case "Suprema":
        //        if (File.Exists(Server.MapPath("BioStar_TriggerTableCreation.sql")))
        //        {
        //            StreamReader sr = new StreamReader(Server.MapPath("BioStar_TriggerTableCreation.sql"));
        //            using (sr)
        //            {
        //                while (!sr.EndOfStream)
        //                {
        //                    StringBuilder sb = new StringBuilder();
        //                    while (!sr.EndOfStream)
        //                    {
        //                        string s = sr.ReadLine();
        //                        if (s != null && s.ToUpper().Trim().Equals("GO"))
        //                        {
        //                            break;
        //                        }
        //                        sb.AppendLine(s);
        //                    }
        //                    // Execute T-SQL against the target database                                      
        //                    objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), checkConnection);
        //                }
        //            }
        //        }
        //        break;
        //case "Suprema-Biostar 2":
        //    if (Convert.ToString(lblFileType.Text) == "RDBMS")
        //        if (File.Exists(Server.MapPath("BioStar2_TriggerTableCreation.sql")))
        //        {
        //            StreamReader sr = new StreamReader(Server.MapPath("BioStar2_TriggerTableCreation.sql"));
        //            using (sr)
        //            {
        //                while (!sr.EndOfStream)
        //                {
        //                    StringBuilder sb = new StringBuilder();
        //                    while (!sr.EndOfStream)
        //                    {
        //                        string s = sr.ReadLine();
        //                        if (s != null && s.ToUpper().Trim().Equals("GO"))
        //                        {
        //                            break;
        //                        }
        //                        sb.AppendLine(s);
        //                    }
        //                    // Execute T-SQL against the target database                                      
        //                    objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), checkConnection);
        //                }
        //            }
        //        }
        //    break;
        //}
        if (Convert.ToString(lblBrandType.Text) != "ESSL" && Convert.ToString(lblBrandType.Text) != "Suprema-Biostar 2")
        {
            OleDbCommand oledbCommand;
            string cmdColumn = string.Empty, columnName = string.Empty;
            string cmdTable = "select id, name from sysobjects where xtype='U' and type='U' and name = '" + tableName + "'";
            oledbCommand = new OleDbCommand(cmdTable, oledbConnection);
            int tabledId = Convert.ToInt32(oledbCommand.ExecuteScalar());
            if (tabledId == 0)
            {
                base.Message(rm.GetString("Alert_SpecifiedTableNameisnotcorrectPleaseverify", ci));
                txtTableName.Focus();
                oledbConnection.Close();
                return false;
            }
            cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + readerNo + "'";
            oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
            columnName = Convert.ToString(oledbCommand.ExecuteScalar());
            if (columnName == string.Empty)
            {
                base.Message(rm.GetString("Alert_SpecifiedReaderNoisnotcorrectPleaseverify", ci));
                txtRDBMSReaderNo.Focus();
                oledbConnection.Close();
                return false;
            }
            cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + cardNo + "'";
            oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
            columnName = Convert.ToString(oledbCommand.ExecuteScalar());
            if (columnName == string.Empty)
            {
                base.Message(rm.GetString("Alert_SpecifiedCardNoisnotcorrectPleaseverify", ci));
                txtRDBMSCardNo.Focus();
                oledbConnection.Close();
                return false;
            }
            cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + dateTime + "'";
            oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
            columnName = Convert.ToString(oledbCommand.ExecuteScalar());
            if (columnName == string.Empty)
            {
                base.Message(rm.GetString("Alert_SpecifiedinputisnotcorrectPleaseverify", ci));
                txtRDBMSDateTime.Focus();
                oledbConnection.Close();
                return false;
            }
            cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + punchType + "'";
            oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
            columnName = Convert.ToString(oledbCommand.ExecuteScalar());
            if (columnName == string.Empty)
            {
                base.Message(rm.GetString("Alert_SpecifiedPunchTypeisnotcorrectPleaseverify", ci));
                txtRDBMSType.Focus();
                oledbConnection.Close();
                return false;
            }
            if (chk_TransIdentifier.Checked == true)
            {
                cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + transactionIdentifier + "'";
                oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
                columnName = Convert.ToString(oledbCommand.ExecuteScalar());
                if (columnName == string.Empty)
                {
                    base.Message(rm.GetString("Alert_SpecifiedTransactionIdentifierisnotcorrectPleaseverify", ci));
                    txt_RDBMSTransactionIdentifier.Focus();
                    oledbConnection.Close();
                    return false;
                }
            }
            if (flag != "NoFlag")
            {
                cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + flag + "'";
                oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
                columnName = Convert.ToString(oledbCommand.ExecuteScalar());
                if (columnName == string.Empty)
                {
                    base.Message(rm.GetString("Alert_SpecifiedFlagisnotcorrectPleaseverify", ci));
                    txt_FlagField.Focus();
                    oledbConnection.Close();
                    return false;
                }
            }
            oledbConnection.Close();
        }
        return true;
    }
    /// <summary>
    /// Validate_s the connection string_ database_ table_ fields.
    /// </summary>
    /// <param name="connectionString">The connection string.</param>
    private bool Validate_ConnectionString_Database_Table_Fields(string connectionString, string tableName, string readerNo, string cardNo, string date, string time, string punchType, string transactionIdentifier, string flag)
    {
        string[] connectionStringArr = connectionString.Split(';');
        string checkStringSource = "Initial Catalog";
        checkStringSource = checkStringSource.ToUpper();
        string connection = string.Empty, databaseName = string.Empty;
        for (int i = 0; i < connectionStringArr.Length - 1; i++)
        {
            string[] initialCatalogPart = connectionStringArr[i].Split('=');
            string checkStringInput = Convert.ToString(initialCatalogPart[0]);
            checkStringInput = checkStringInput.ToUpper();
            if (checkStringSource == checkStringInput)
            {
                databaseName = Convert.ToString(initialCatalogPart[1]);
            }
            else
            {
                connection = connection + Convert.ToString(connectionStringArr[i]) + ";";
            }
        }
        // check for valid sql connection
        string checkConnection = connectionString;
        OleDbConnection oledbConnection;
        try
        {
            oledbConnection = new OleDbConnection(checkConnection);
            oledbConnection.Open();
            if (oledbConnection.State == ConnectionState.Open)
            {
                // connection string is correct                
            }
            else
            {
                // connection string is not correct check the connection string
                base.Message(rm.GetString("Alert_InvalidConnectionStringPleaseverify", ci));
                txtConnectionString.Focus();
                return false;
            }
        }
        catch (Exception ex)
        {
            base.Message(ex.Message);
            txtConnectionString.Focus();
            return false;
        }
        if (Convert.ToString(lblBrandType.Text) == "Suprema")
        {
            if (File.Exists(Server.MapPath("BioStar_TriggerTableCreation.sql")))
            {
                StreamReader sr = new StreamReader(Server.MapPath("BioStar_TriggerTableCreation.sql"));
                using (sr)
                {
                    while (!sr.EndOfStream)
                    {
                        StringBuilder sb = new StringBuilder();
                        while (!sr.EndOfStream)
                        {
                            string s = sr.ReadLine();
                            if (s != null && s.ToUpper().Trim().Equals("GO"))
                            {
                                break;
                            }
                            sb.AppendLine(s);
                        }
                        // Execute T-SQL against the target database                                      
                        objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), checkConnection);
                    }
                }
            }
        }
        else if (Convert.ToString(lblBrandType.Text) == "Suprema-Biostar 2")
        {
            if (File.Exists(Server.MapPath("BioStar2_TriggerTableCreation.sql")))
            {
                StreamReader sr = new StreamReader(Server.MapPath("BioStar2_TriggerTableCreation.sql"));
                using (sr)
                {
                    while (!sr.EndOfStream)
                    {
                        StringBuilder sb = new StringBuilder();
                        while (!sr.EndOfStream)
                        {
                            string s = sr.ReadLine();
                            if (s != null && s.ToUpper().Trim().Equals("GO"))
                            {
                                break;
                            }
                            sb.AppendLine(s);
                        }
                        // Execute T-SQL against the target database                                      
                        objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), checkConnection);
                    }
                }
            }
        }
        OleDbCommand oledbCommand;
        string cmdColumn = string.Empty, columnName = string.Empty;
        string cmdTable = "select id, name from sysobjects where xtype='U' and type='U' and name = '" + tableName + "'";
        oledbCommand = new OleDbCommand(cmdTable, oledbConnection);
        int tabledId = Convert.ToInt32(oledbCommand.ExecuteScalar());
        if (tabledId == 0)
        {
            base.Message(rm.GetString("Alert_SpecifiedTableNameisnotcorrectPleaseverify", ci));
            txtTableName.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + readerNo + "'";
        oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            base.Message(rm.GetString("Alert_SpecifiedReaderNoisnotcorrectPleaseverify", ci));
            txtRDBMSReaderNo.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + cardNo + "'";
        oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            base.Message(rm.GetString("Alert_SpecifiedCardNoisnotcorrectPleaseverify", ci));
            txtRDBMSCardNo.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + date + "'";
        oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            base.Message(rm.GetString("Alert_SpecifiedinputisnotcorrectPleaseverify", ci));
            txtRDBMSDate.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + time + "'";
        oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            base.Message(rm.GetString("Alert_SpecifiedinputisnotcorrectPleaseverify", ci));
            txtRDBMSTime.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + punchType + "'";
        oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            base.Message(rm.GetString("Alert_SpecifiedPunchTypeisnotcorrectPleaseverify", ci));
            txtRDBMSType.Focus();
            oledbConnection.Close();
            return false;
        }
        if (chk_TransIdentifier.Checked == true)
        {
            cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + transactionIdentifier + "'";
            oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
            columnName = Convert.ToString(oledbCommand.ExecuteScalar());
            if (columnName == string.Empty)
            {
                base.Message(rm.GetString("Alert_SpecifiedTransactionIdentifierisnotcorrectPleaseverify", ci));
                txt_RDBMSTransactionIdentifier.Focus();
                oledbConnection.Close();
                return false;
            }
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + flag + "'";
        oledbCommand = new OleDbCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            base.Message(rm.GetString("Alert_SpecifiedFlagisnotcorrectPleaseverify", ci));
            txt_FlagField.Focus();
            oledbConnection.Close();
            return false;
        }
        oledbConnection.Close();
        return true;
    }
    #endregion
    #region ButtonEvents
    // Modify Button - Click Event
    protected void btnModify_Click(object sender, EventArgs e)
    {
        // Declarations
        string strFileSourcePath = "", strFileBackupPath = "", strFileBackupType = "", strDelimiter = "", strStringEnclosedBy = "", strDel_ReaderNo = "";
        string strDel_CardNo = "", strDel_Date = "", strDel_Time = "", strDel_DateTime = "", strDel_Type = "", strDel_TransactionIdentifier = "";
        string strConnectionString = "", strTableName = "", strMDB_ReaderNo = "", strMDB_CardNo = "", strMDB_Date = "", strMDB_Time = "";
        string strMDB_DateTime = "", strMDB_Type = "", strMDB_TransactionIdentifier = "";
        string strRDBMS_ReaderNo = "", strRDBMS_CardNo = "", strRDBMS_Date = "", strRDBMS_Time = "", strRDBMS_DateTime = "", strRDBMS_Type = "", strRDBMS_TransactionIdentifier = "", strMDB_RDBMS_Flag = "";
        string strDateTimeFormat = "", strDateFormat = "", strTimeFormat = "", strTransIdentifierValue = "";
        int intNoOfFields = 0, intDel_DateTimeBit = 2, intFL_ReaderNoFrom = 0, intFL_ReaderNoTo = 0, intFL_CardNoFrom = 0, intFL_CardNoTo = 0;
        int intFL_DateTimeBit = 2, intFL_DateFrom = 0, intFL_DateTo = 0, intFL_TimeFrom = 0, intFL_TimeTo = 0, intFL_DateTimeFrom = 0;
        int intFL_DateTimeTo = 0, intFL_TypeFrom = 0, intFL_TypeTo = 0, intFL_TransIdentifierFrom = 0, intFL_TransIdentifierTo = 0;
        int intRDBMS_DateTimeBit = 2, intMDB_DateTimeBit = 2, intTransIdentifierBit = 0, intIsEmployeeIdBit = 0;
        int intIsEncrypted = 0, IsFreeScan = 0;
        // string strEntryDate = DateTime.Now.ToString("MM/dd/yyyy");
        string strRawDataFormat = lblRawDataFormat.Text;
        string strFileType = lblFileType.Text;
        // For Selected FileType, Get the Appropriate Details from the Web Page
        // If File Type is Delimiter
        string strcon = "";
        switch (strFileType)
        {
            case "Delimiter":
                strFileSourcePath = txtDelimiterSourePath.Text;
                strFileBackupPath = txtDelimiterBackupPath.Text;
                // To check whether the Delimiter File Source Path is valid or not
                if (!Directory.Exists(strFileSourcePath))
                {
                    base.Message(rm.GetString("Alert_InvalidFileSourcePath", ci));
                    return;
                }
                // To check whether the Delimiter File Backup Path is valid or not
                if (!Directory.Exists(strFileBackupPath))
                {
                    base.Message(rm.GetString("Alert_InvalidFileBackupPath", ci));
                    return;
                }
                if (rbt_DelMove.Checked == true)
                {
                    strFileBackupType = "MF";
                }
                else if (rbt_DelRename.Checked == true)
                {
                    strFileBackupType = "SF";
                }
                intNoOfFields = int.Parse(txtNumberOfFields.Text);
                strDelimiter = txtDelimiter.Text;
                strStringEnclosedBy = txtStringEnclosedBy.Text;
                strDel_ReaderNo = ddlReaderNo.SelectedItem.Text;
                if (chk_EmployeeId1.Checked == true)
                {
                    intIsEmployeeIdBit = 1;
                }
                strDel_CardNo = ddlCardNo.SelectedItem.Text;
                if (rbtDelDateTime.Checked == true)
                {
                    intDel_DateTimeBit = 1;
                    strDel_DateTime = ddlDateTime.SelectedItem.Text;
                    strDateTimeFormat = txt_DelDateTimeFormat.Text;
                }
                else if (rbtDelDateTimeSeperate.Checked == true)
                {
                    intDel_DateTimeBit = 0;
                    strDel_Date = ddlDate.SelectedItem.Text;
                    strDateFormat = txt_DelDateFormat.Text;
                    strDel_Time = ddlTime.SelectedItem.Text;
                    strTimeFormat = txt_DelTimeFormat.Text;
                }
                strDel_Type = ddlType.SelectedItem.Text;
                if (chk_DelTransIdentifier.Checked == true)
                {
                    intTransIdentifierBit = 1;
                    strDel_TransactionIdentifier = ddlTransactionIdentifier.SelectedItem.Text;
                    strTransIdentifierValue = txtDel_TIValue.Text;
                }
                break;
            case "Fixed Length":
                strFileSourcePath = txtFLSourcePath.Text;
                strFileBackupPath = txtFLBackupPath.Text;
                // To check whether the Fixed Length File Source Path is valid or not
                if (!Directory.Exists(strFileSourcePath))
                {
                    base.Message(rm.GetString("Alert_InvalidFileSourcePath", ci));
                    return;
                }
                // To check whether the Fixed Length File Backup Path is valid or not
                if (!Directory.Exists(strFileBackupPath))
                {
                    base.Message(rm.GetString("Alert_InvalidFileBackupPath", ci));
                    return;
                }
                if (rbt_FLMove.Checked == true)
                {
                    strFileBackupType = "MF";
                }
                else if (rbt_FLRename.Checked == true)
                {
                    strFileBackupType = "SF";
                }
                intFL_ReaderNoFrom = int.Parse(txtFL_ReaderNoFrom.Text);
                intFL_ReaderNoTo = int.Parse(txtFL_ReaderNoTo.Text);
                if (chk_EmployeeId2.Checked == true)
                {
                    intIsEmployeeIdBit = 1;
                }
                intFL_CardNoFrom = int.Parse(txtFL_CardNoFrom.Text);
                intFL_CardNoTo = int.Parse(txtFL_CardNoTo.Text);
                if (rbtFLDateTime.Checked == true)
                {
                    intFL_DateTimeBit = 1;
                    intFL_DateTimeFrom = int.Parse(txtFL_DateTimeFrom.Text);
                    intFL_DateTimeTo = int.Parse(txtFL_DateTimeTo.Text);
                    strDateTimeFormat = txt_FLDateTimeFormat.Text;
                }
                else if (rbtFLDateTimeSeperate.Checked == true)
                {
                    intFL_DateTimeBit = 0;
                    intFL_DateFrom = int.Parse(txtFL_DateFrom.Text);
                    intFL_DateTo = int.Parse(txtFL_DateTo.Text);
                    strDateFormat = txt_FLDateFormat.Text;
                    intFL_TimeFrom = int.Parse(txtFL_TimeFrom.Text);
                    intFL_TimeTo = int.Parse(txtFL_TimeTo.Text);
                    strTimeFormat = txt_FLTimeFormat.Text;
                }
                intFL_TypeFrom = int.Parse(txtFL_TypeFrom.Text);
                intFL_TypeTo = int.Parse(txtFL_TypeTo.Text);
                if (chk_FLTransIdentifier.Checked == true)
                {
                    intTransIdentifierBit = 1;
                    intFL_TransIdentifierFrom = int.Parse(txtFL_TransIdentifierFrom.Text);
                    intFL_TransIdentifierTo = int.Parse(txtFL_TransIdentifierTo.Text);
                    strTransIdentifierValue = txtFL_TIValue.Text;
                }
                break;
            case "RDBMS":
            case "MariaDB":
            case "PostgreSQL":

                if (strFileType != "PostgreSQL")
                {
                    strcon = "Provider=SQLOLEDB.1;Data Source=" + txtServerName.Text + ";Initial Catalog=" + txtDBName.Text + ";User Id=" + txtDBUserName.Text + ";pwd=" + txtDBPassword.Text + ";";
                }
                else
                {
                    strcon = "Server =" + txtServerName.Text + ";Initial Catalog=" + txtDBName.Text + ";User Id=" + txtDBUserName.Text + ";pwd=" + txtDBPassword.Text + ";";
                }
                txtConnectionString.Text = "";
                txtConnectionString.Text = strcon;
                strConnectionString = txtConnectionString.Text;
                strTableName = txtTableName.Text;
                strRDBMS_ReaderNo = txtRDBMSReaderNo.Text;
                if (chk_EmployeeId3.Checked == true)
                {
                    intIsEmployeeIdBit = 1;
                }
                strRDBMS_CardNo = txtRDBMSCardNo.Text;
                if (rbtDateTime.Checked == true)
                {
                    intRDBMS_DateTimeBit = 1;
                    strRDBMS_DateTime = txtRDBMSDateTime.Text;
                    strDateTimeFormat = txt_RDBMSDateTimeFormat.Text;
                }
                else if (rbtDateTimeSeperate.Checked == true)
                {
                    intRDBMS_DateTimeBit = 0;
                    strRDBMS_Date = txtRDBMSDate.Text;
                    strDateFormat = txt_RDBMSDateFormat.Text;
                    strRDBMS_Time = txtRDBMSTime.Text;
                    strTimeFormat = txt_RDBMSTimeFormat.Text;
                    if (chkEncrypted.Checked == true)
                    {
                        intIsEncrypted = 1;
                    }
                }
                strRDBMS_Type = txtRDBMSType.Text;
                if (chk_TransIdentifier.Checked == true)
                {
                    intTransIdentifierBit = 1;
                    strRDBMS_TransactionIdentifier = txt_RDBMSTransactionIdentifier.Text;
                    strTransIdentifierValue = txt_TIValue.Text;
                }
                strMDB_RDBMS_Flag = txt_FlagField.Text.Trim();
                // validate connection string and table name and field name
                bool validation = false;

                if (rbtDateTime.Checked)
                {
                    if (strFileType != "PostgreSQL")
                    {
                        validation = Validate_ConnectionString_Database_Table_Fields(strConnectionString, strTableName, strRDBMS_ReaderNo, strRDBMS_CardNo, strRDBMS_DateTime, strRDBMS_Type, strRDBMS_TransactionIdentifier, strMDB_RDBMS_Flag);
                    }
                    else
                    {
                        //  validation = Postgre_Validate_ConnectionString_Database_Table_Fields(strConnectionString, strTableName, strRDBMS_ReaderNo, strRDBMS_CardNo, strRDBMS_DateTime, strRDBMS_Type, strRDBMS_TransactionIdentifier, strMDB_RDBMS_Flag);
                    }
                }
                else if (rbtDateTimeSeperate.Checked)
                {
                    validation = Validate_ConnectionString_Database_Table_Fields(strConnectionString, strTableName, strRDBMS_ReaderNo, strRDBMS_CardNo, strRDBMS_Date, strRDBMS_Time, strRDBMS_Type, strRDBMS_TransactionIdentifier, strMDB_RDBMS_Flag);
                }
                if (validation != true)
                {
                    return;
                }
                switch (Convert.ToString(lblBrandType.Text))
                {
                    case "Suprema":
                        if (File.Exists(Server.MapPath("BioStar_TriggerTableCreation.sql")))
                        {
                            StreamReader sr = new StreamReader(Server.MapPath("BioStar_TriggerTableCreation.sql"));
                            using (sr)
                            {
                                while (!sr.EndOfStream)
                                {
                                    StringBuilder sb = new StringBuilder();
                                    while (!sr.EndOfStream)
                                    {
                                        string s = sr.ReadLine();
                                        if (s != null && s.ToUpper().Trim().Equals("GO"))
                                        {
                                            break;
                                        }
                                        sb.AppendLine(s);
                                    }
                                    // Execute T-SQL against the target database                                      
                                    objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), strConnectionString);
                                }
                            }
                        }
                        break;
                    case "Suprema-Biostar 2":
                        if (Convert.ToString(lblFileType.Text) == "RDBMS")
                            if (File.Exists(Server.MapPath("BioStar2_TriggerTableCreation.sql")))
                            {
                                StreamReader sr = new StreamReader(Server.MapPath("BioStar2_TriggerTableCreation.sql"));
                                using (sr)
                                {
                                    while (!sr.EndOfStream)
                                    {
                                        StringBuilder sb = new StringBuilder();
                                        while (!sr.EndOfStream)
                                        {
                                            string s = sr.ReadLine();
                                            if (s != null && s.ToUpper().Trim().Equals("GO"))
                                            {
                                                break;
                                            }
                                            sb.AppendLine(s);
                                        }
                                        // Execute T-SQL against the target database                                      
                                        objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), strConnectionString);
                                    }
                                }
                            }
                        break;
                }
                break;
            case "MDB":
                string MDBProvider1 = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["MDBConnectionString1"]);
                string MDBProvider2 = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["MDBConnectionString2"]);
                string MDBProvider3 = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["MDBConnectionString3"]);
                strcon = MDBProvider1 + txtMDBDataSource.Text + MDBProvider2 + txtMDBUserName.Text + MDBProvider3 + txtMDBPassword.Text + ";";
                txtConnectionString.Text = "";
                txtConnectionString.Text = strcon;
                strConnectionString = txtConnectionString.Text;
                strTableName = txtTableName.Text;
                strMDB_ReaderNo = txtRDBMSReaderNo.Text;
                if (chk_EmployeeId3.Checked == true)
                {
                    intIsEmployeeIdBit = 1;
                }
                strMDB_CardNo = txtRDBMSCardNo.Text;
                if (rbtDateTime.Checked == true)
                {
                    intMDB_DateTimeBit = 1;
                    strMDB_DateTime = txtRDBMSDateTime.Text;
                    strDateTimeFormat = txt_RDBMSDateTimeFormat.Text;
                }
                else if (rbtDateTimeSeperate.Checked == true)
                {
                    intMDB_DateTimeBit = 0;
                    strMDB_Date = txtRDBMSDate.Text;
                    strDateFormat = txt_RDBMSDateFormat.Text;
                    strMDB_Time = txtRDBMSTime.Text;
                    strTimeFormat = txt_RDBMSTimeFormat.Text;
                    if (chkEncrypted.Checked == true)
                    {
                        intIsEncrypted = 1;
                    }
                }
                strMDB_Type = txtRDBMSType.Text;
                if (chk_TransIdentifier.Checked == true)
                {
                    intTransIdentifierBit = 1;
                    strMDB_TransactionIdentifier = txt_RDBMSTransactionIdentifier.Text;
                    strTransIdentifierValue = txt_TIValue.Text;
                }
                strMDB_RDBMS_Flag = txt_FlagField.Text.Trim();
                break;
        }
        IsFreeScan = (rb_Yes.Checked == true) ? 1 : 0;
        try
        {
            // Check for Duplicate Records
            int count = objTerminalDatatype.CheckTerminalDatatype('U', TerminalDatatypeID, strRawDataFormat, strFileType, strFileSourcePath, strFileBackupPath, intNoOfFields, strDelimiter, strStringEnclosedBy, strDel_ReaderNo, strDel_CardNo, intDel_DateTimeBit, strDel_Date, strDel_Time, strDel_DateTime, strDel_Type, intFL_ReaderNoFrom, intFL_ReaderNoTo, intFL_CardNoFrom, intFL_CardNoTo, intFL_DateTimeBit, intFL_DateFrom, intFL_DateTo, intFL_TimeFrom, intFL_TimeTo, intFL_DateTimeFrom, intFL_DateTimeTo, intFL_TypeFrom, intFL_TypeTo, strConnectionString, strTableName, strMDB_ReaderNo, strMDB_CardNo, intMDB_DateTimeBit, strMDB_Date, strMDB_Time, strMDB_DateTime, strMDB_Type, strRDBMS_ReaderNo, strRDBMS_CardNo, intRDBMS_DateTimeBit, strRDBMS_Date, strRDBMS_Time, strRDBMS_DateTime, strRDBMS_Type, strMDB_RDBMS_Flag);
            // If count is 0, then insert into the Database
            if (count == 0)
            {
                // Pass all the values to the function defined in the TerminalDatatypeEventData Class to Update the Details in the Terminal DataType Table
                objTerminalDatatype.Update_TerminalDatatype("U", TerminalDatatypeID, strRawDataFormat, strFileType, strFileSourcePath, strFileBackupPath, strFileBackupType, intNoOfFields, strDelimiter, strStringEnclosedBy, strDel_ReaderNo, strDel_CardNo, intDel_DateTimeBit, strDel_Date, strDel_Time, strDel_DateTime, strDel_Type, strDel_TransactionIdentifier, intFL_ReaderNoFrom, intFL_ReaderNoTo, intFL_CardNoFrom, intFL_CardNoTo, intFL_DateTimeBit, intFL_DateFrom, intFL_DateTo, intFL_TimeFrom, intFL_TimeTo, intFL_DateTimeFrom, intFL_DateTimeTo, intFL_TypeFrom, intFL_TypeTo, intFL_TransIdentifierFrom, intFL_TransIdentifierTo, Encryption.Encrypt(strConnectionString, ""), strTableName, strMDB_ReaderNo, strMDB_CardNo, intMDB_DateTimeBit, strMDB_Date, strMDB_Time, strMDB_DateTime, strMDB_Type, strMDB_TransactionIdentifier, strRDBMS_ReaderNo, strRDBMS_CardNo, intRDBMS_DateTimeBit, strRDBMS_Date, strRDBMS_Time, strRDBMS_DateTime, strRDBMS_Type, strRDBMS_TransactionIdentifier, strMDB_RDBMS_Flag, intIsEmployeeIdBit, strDateTimeFormat, strDateFormat, strTimeFormat, intIsEncrypted, intTransIdentifierBit, strTransIdentifierValue, gintUserId, "", IsFreeScan);
            }
            // If count is not 0 (means that it has Duplicate Records)
            else if (count == 1)
            {
                base.Message(rm.GetString("Alert_DuplicateTerminalDataType", ci));
                return;
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
        //string strRedirectPage = "TA_UI_Master_TerminalDatatypeView.aspx?TerminalDatatype_ID=" +  Convert.ToString(TerminalDatatypeID);
        string strRedirectPage = "TA_UI_Master_TerminalDatatype.aspx";

        string strScript = "";
        strScript = strScript + "<script language='javascript'>";
        strScript = strScript + "alert('" + rm.GetString("Alert_TerminalDataTypemodifiedsuccessfully", ci) + "');";
        strScript = strScript + "location.replace('" + strRedirectPage + "');";
        strScript = strScript + "</script>";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
    }

    private bool Postgre_Validate_ConnectionString_Database_Table_Fields(string connectionString, string tableName, string readerNo, string cardNo, string dateTime, string punchType, string transactionIdentifier, string flag)
    {
        string[] connectionStringArr = connectionString.Split(';');
        string checkStringSource = "Initial Catalog";
        checkStringSource = checkStringSource.ToUpper();
        string connection = string.Empty, databaseName = string.Empty;
        for (int i = 0; i < connectionStringArr.Length - 1; i++)
        {
            string[] initialCatalogPart = connectionStringArr[i].Split('=');
            string checkStringInput = Convert.ToString(initialCatalogPart[0]);
            checkStringInput = checkStringInput.ToUpper();
            if (checkStringSource == checkStringInput)
            {
                databaseName = Convert.ToString(initialCatalogPart[1]);
            }
            else
            {
                connection = connection + Convert.ToString(connectionStringArr[i]) + ";";
            }
        }
        // check for valid sql connection
        string checkConnection = connectionString;
        NpgsqlConnection oledbConnection;
        try
        {
            oledbConnection = new NpgsqlConnection(checkConnection);
            oledbConnection.Open();
            if (oledbConnection.State == ConnectionState.Open)
            {
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidConnectionStringPleaseverify", ci) + "');", true);
                txtConnectionString.Focus();
                return false;
            }
        }
        catch (Exception ex)
        {
            Message(ex.Message);
            txtConnectionString.Focus();
            return false;
        }
        NpgsqlCommand oledbCommand;
        string cmdColumn = string.Empty, columnName = string.Empty;
        string cmdTable = "select id, name from sysobjects where xtype='U' and type='U' and name = '" + tableName + "'";
        oledbCommand = new NpgsqlCommand(cmdTable, oledbConnection);
        int tabledId = Convert.ToInt32(oledbCommand.ExecuteScalar());
        if (tabledId == 0)
        {
            Message(rm.GetString("Alert_SpecifiedTableNameisnotcorrectPleaseverify", ci));
            txtTableName.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + readerNo + "'";
        oledbCommand = new NpgsqlCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            Message(rm.GetString("Alert_SpecifiedReaderNoisnotcorrectPleaseverify", ci));
            txtRDBMSReaderNo.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + cardNo + "'";
        oledbCommand = new NpgsqlCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            Message(rm.GetString("Alert_SpecifiedCardNoisnotcorrectPleaseverify", ci));
            txtRDBMSCardNo.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + dateTime + "'";
        oledbCommand = new NpgsqlCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            Message(rm.GetString("Alert_SpecifiedinputisnotcorrectPleaseverify", ci));
            txtRDBMSDateTime.Focus();
            oledbConnection.Close();
            return false;
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + punchType + "'";
        oledbCommand = new NpgsqlCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            Message(rm.GetString("Alert_SpecifiedPunchTypeisnotcorrectPleaseverify", ci));
            txtRDBMSType.Focus();
            oledbConnection.Close();
            return false;
        }
        if (chk_TransIdentifier.Checked == true)
        {
            cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + transactionIdentifier + "'";
            oledbCommand = new NpgsqlCommand(cmdColumn, oledbConnection);
            columnName = Convert.ToString(oledbCommand.ExecuteScalar());
            if (columnName == string.Empty)
            {
                Message(rm.GetString("Alert_SpecifiedTransactionIdentifierisnotcorrectPleaseverify", ci));
                txt_RDBMSTransactionIdentifier.Focus();
                oledbConnection.Close();
                return false;
            }
        }
        cmdColumn = "select name from syscolumns where id = " + tabledId + " and name='" + flag + "'";
        oledbCommand = new NpgsqlCommand(cmdColumn, oledbConnection);
        columnName = Convert.ToString(oledbCommand.ExecuteScalar());
        if (columnName == string.Empty)
        {
            Message(rm.GetString("Alert_SpecifiedFlagisnotcorrectPleaseverify", ci));
            txt_FlagField.Focus();
            oledbConnection.Close();
            return false;
        }
        oledbConnection.Close();
        return true;
    }

    #endregion
}