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 System.Web.UI.WebControls;
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_TerminalDatatypeAdd : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    CultureInfo ci;
    TerminalDatatypeEventData objTerminalDatatype = new TerminalDatatypeEventData();
    cls_Common objCommon = new cls_Common();
    int gintUserId;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        gintUserId = Convert.ToInt32(Session["EmpAutoID"]);
        string strSetAlert = "";
        if (!Page.IsPostBack)
        {
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            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);
            UserRights();
            LoadStrings(ci);
            txtRawDataFormat.Focus();
            ViewState["FileType"] = string.Empty;
            ddlFileType.SelectedIndex = 0;
            txtConnectionString.Text = "";
            txtServerName.Text = "";
            txtDBName.Text = "";
            txtDBUserName.Text = "";
            txtDBPassword.Text = "";
            txtMDBDataSource.Text = "";
            txtMDBUserName.Text = "";
            txtMDBPassword.Text = "";
            txtTableName.Text = "";
            txtRDBMSReaderNo.Text = "";
            txtRDBMSCardNo.Text = "";
            txtRDBMSDate.Text = "";
            txt_RDBMSDateFormat.Text = "";
            txtRDBMSTime.Text = "";
            txt_RDBMSTimeFormat.Text = "";
            txtRDBMSDateTime.Text = "";
            txtRDBMSType.Text = "";
            txt_RDBMSTransactionIdentifier.Text = "";
            txt_TIValue.Text = "";
            txt_FlagField.Text = "";
            DataSet dsBrandType = new DataSet();
            dsBrandType = objTerminalDatatype.SelectBrandDetails();
            if (dsBrandType.Tables[0].Rows.Count > 0)
            {
                ddlBrandType.DataSource = dsBrandType.Tables[0];
                ddlBrandType.DataTextField = "DisplayName";
                ddlBrandType.DataValueField = "KeyValue";
                ddlBrandType.DataBind();
                ddlBrandType.Items.Insert(0, rm.GetString("Select", ci));
            }
            dsBrandType.Dispose();
            foreach (ListItem item in ddlBrandType.Items)
            {
                item.Attributes.Add("title", item.Text);
            }
            objCommon.menu("Terminal", "223");
        }
        if (IsPostBack)
        {
            if (rbtDelDateTime.Checked == true)
            {
                ddlDateTime.Enabled = true;
                txt_DelDateTimeFormat.Enabled = true;
                ddlDate.Enabled = false;
                txt_DelDateFormat.Enabled = false;
                ddlTime.Enabled = false;
                txt_DelTimeFormat.Enabled = false;
            }
            else
            {
                ddlDateTime.Enabled = false;
                txt_DelDateTimeFormat.Enabled = false;
                ddlDate.Enabled = true;
                txt_DelDateFormat.Enabled = true;
                ddlTime.Enabled = true;
                txt_DelTimeFormat.Enabled = true;
            }
            if (rbtFLDateTime.Checked == true)
            {
                txtFL_DateTimeFrom.Enabled = true;
                txtFL_DateTimeTo.Enabled = true;
                txt_FLDateTimeFormat.Enabled = true;
                txtFL_DateFrom.Enabled = false;
                txtFL_DateTo.Enabled = false;
                txt_FLDateFormat.Enabled = false;
                txtFL_TimeFrom.Enabled = false;
                txtFL_TimeTo.Enabled = false;
                txt_FLTimeFormat.Enabled = false;
            }
            else
            {
                txtFL_DateTimeFrom.Enabled = false;
                txtFL_DateTimeTo.Enabled = false;
                txt_FLDateTimeFormat.Enabled = false;
                txtFL_DateFrom.Enabled = true;
                txtFL_DateTo.Enabled = true;
                txt_FLDateFormat.Enabled = true;
                txtFL_TimeFrom.Enabled = true;
                txtFL_TimeTo.Enabled = true;
                txt_FLTimeFormat.Enabled = true;
            }
            if (rbtDateTime.Checked == true)
            {
                txtRDBMSDateTime.Enabled = true;
                txt_RDBMSDateTimeFormat.Enabled = true;
                txtRDBMSDate.Enabled = false;
                txt_RDBMSDateFormat.Enabled = false;
                txtRDBMSTime.Enabled = false;
                txt_RDBMSTimeFormat.Enabled = false;
            }
            else
            {
                txtRDBMSDateTime.Enabled = false;
                txt_RDBMSDateTimeFormat.Enabled = false;
                txtRDBMSDate.Enabled = true;
                txt_RDBMSDateFormat.Enabled = true;
                txtRDBMSTime.Enabled = true;
                txt_RDBMSTimeFormat.Enabled = true;
            }
        }
    }
    #endregion
    #region ButtonEvents
    protected void btnSave_Click(object sender, EventArgs e)
    {
        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 strRawDataFormat = txtRawDataFormat.Text.Trim();
        string strFileType = ddlFileType.SelectedValue;
        string strcon = "";
        switch (strFileType)
        {
            case "Delimiter":
                strFileSourcePath = txtDelimiterSourePath.Text.Trim();
                strFileBackupPath = txtDelimiterBackupPath.Text.Trim();
                if (!Directory.Exists(strFileSourcePath))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidFileSourcePath", ci) + "');", true);
                    return;
                }
                if (!Directory.Exists(strFileBackupPath))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidFileBackupPath", ci) + "');", true);
                    return;
                }
                if (rbt_DelMove.Checked == true)
                {
                    strFileBackupType = "MF";
                }
                else if (rbt_DelRename.Checked == true)
                {
                    strFileBackupType = "SF";
                }
                intNoOfFields = int.Parse(txtNumberOfFields.Text.Trim());
                strDelimiter = txtDelimiter.Text.Trim();
                strStringEnclosedBy = txtStringEnclosedBy.Text.Trim();
                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.Trim();
                }
                else if (rbtDelDateTimeSeperate.Checked == true)
                {
                    intDel_DateTimeBit = 0;
                    strDel_Date = ddlDate.SelectedItem.Text;
                    strDateFormat = txt_DelDateFormat.Text.Trim();
                    strDel_Time = ddlTime.SelectedItem.Text;
                    strTimeFormat = txt_DelTimeFormat.Text.Trim();
                }
                strDel_Type = ddlType.SelectedItem.Text;
                if (chk_DelTransIdentifier.Checked == true)
                {
                    intTransIdentifierBit = 1;
                    strDel_TransactionIdentifier = ddlTransactionIdentifier.SelectedItem.Text;
                    strTransIdentifierValue = txtDel_TIValue.Text.Trim();
                }
                break;
            case "Fixed Length":
                strFileSourcePath = txtFLSourcePath.Text.Trim();
                strFileBackupPath = txtFLBackupPath.Text.Trim();
                if (!Directory.Exists(strFileSourcePath))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidFileSourcePath", ci) + "');", true);
                    return;
                }
                if (!Directory.Exists(strFileBackupPath))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_InvalidFileBackupPath", ci) + "');", true);
                    return;
                }
                if (rbt_FLMove.Checked == true)
                {
                    strFileBackupType = "MF";
                }
                else if (rbt_FLRename.Checked == true)
                {
                    strFileBackupType = "SF";
                }
                intFL_ReaderNoFrom = int.Parse(txtFL_ReaderNoFrom.Text.Trim());
                intFL_ReaderNoTo = int.Parse(txtFL_ReaderNoTo.Text.Trim());
                if (chk_EmployeeId2.Checked == true)
                {
                    intIsEmployeeIdBit = 1;
                }
                intFL_CardNoFrom = int.Parse(txtFL_CardNoFrom.Text.Trim());
                intFL_CardNoTo = int.Parse(txtFL_CardNoTo.Text.Trim());
                if (rbtFLDateTime.Checked == true)
                {
                    intFL_DateTimeBit = 1;
                    intFL_DateTimeFrom = int.Parse(txtFL_DateTimeFrom.Text.Trim());
                    intFL_DateTimeTo = int.Parse(txtFL_DateTimeTo.Text.Trim());
                    strDateTimeFormat = txt_FLDateTimeFormat.Text.Trim();
                }
                else if (rbtFLDateTimeSeperate.Checked == true)
                {
                    intFL_DateTimeBit = 0;
                    intFL_DateFrom = int.Parse(txtFL_DateFrom.Text.Trim());
                    intFL_DateTo = int.Parse(txtFL_DateTo.Text.Trim());
                    strDateFormat = txt_FLDateFormat.Text.Trim();
                    intFL_TimeFrom = int.Parse(txtFL_TimeFrom.Text.Trim());
                    intFL_TimeTo = int.Parse(txtFL_TimeTo.Text.Trim());
                    strTimeFormat = txt_FLTimeFormat.Text.Trim();
                }
                intFL_TypeFrom = int.Parse(txtFL_TypeFrom.Text.Trim());
                intFL_TypeTo = int.Parse(txtFL_TypeTo.Text.Trim());
                if (chk_FLTransIdentifier.Checked == true)
                {
                    intTransIdentifierBit = 1;
                    intFL_TransIdentifierFrom = int.Parse(txtFL_TransIdentifierFrom.Text.Trim());
                    intFL_TransIdentifierTo = int.Parse(txtFL_TransIdentifierTo.Text.Trim());
                    strTransIdentifierValue = txtFL_TIValue.Text.Trim();
                }
                break;
            case "RDBMS":
            case "MariaDB":
            case "PostgreSQL":
                if (strFileType == "RDBMS")
                {
                    strcon = "Provider=SQLOLEDB.1;Data Source=" + txtServerName.Text + ";Initial Catalog=" + txtDBName.Text + ";User Id=" + txtDBUserName.Text + ";pwd=" + txtDBPassword.Text + ";";
                }
                else
                {
                    strcon = "Server =" + txtServerName.Text + ";Database=" + txtDBName.Text + ";Uid=" + txtDBUserName.Text + ";Pwd=" + txtDBPassword.Text + ";";
                }
                txtConnectionString.Text = "";
                txtConnectionString.Text = strcon;
                strConnectionString = txtConnectionString.Text.Trim();
                string strconstr = Encryption.Encrypt(strConnectionString, "");
                strTableName = txtTableName.Text.Trim();
                strRDBMS_ReaderNo = txtRDBMSReaderNo.Text.Trim();
                if (chk_EmployeeId3.Checked == true)
                {
                    intIsEmployeeIdBit = 1;
                }
                strRDBMS_CardNo = txtRDBMSCardNo.Text.Trim();
                if (rbtDateTime.Checked == true)
                {
                    intRDBMS_DateTimeBit = 1;
                    strRDBMS_DateTime = txtRDBMSDateTime.Text.Trim();
                    strDateTimeFormat = txt_RDBMSDateTimeFormat.Text.Trim();
                }
                else if (rbtDateTimeSeperate.Checked == true)
                {
                    intRDBMS_DateTimeBit = 0;
                    strRDBMS_Date = txtRDBMSDate.Text.Trim();
                    strDateFormat = txt_RDBMSDateFormat.Text.Trim();
                    strRDBMS_Time = txtRDBMSTime.Text.Trim();
                    strTimeFormat = txt_RDBMSTimeFormat.Text.Trim();
                    if (chkEncrypted.Checked == true)
                    {
                        intIsEncrypted = 1;
                    }
                }
                strRDBMS_Type = txtRDBMSType.Text;
                if (chk_TransIdentifier.Checked == true)
                {
                    intTransIdentifierBit = 1;
                    strRDBMS_TransactionIdentifier = txt_RDBMSTransactionIdentifier.Text.Trim();
                    strTransIdentifierValue = txt_TIValue.Text;
                }
                strMDB_RDBMS_Flag = txt_FlagField.Text.Trim();
                bool validation = false;
                if (rbtDateTime.Checked)
                {
                    if (strFileType == "RDBMS")
                    {
                        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;
                }
                ViewState["FileType"] = strFileType;
                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.Trim();
                strTableName = txtTableName.Text.Trim();
                strMDB_ReaderNo = txtRDBMSReaderNo.Text.Trim();
                if (chk_EmployeeId3.Checked == true)
                {
                    intIsEmployeeIdBit = 1;
                }
                strMDB_CardNo = txtRDBMSCardNo.Text.Trim();
                if (rbtDateTime.Checked == true)
                {
                    intMDB_DateTimeBit = 1;
                    strMDB_DateTime = txtRDBMSDateTime.Text.Trim();
                    strDateTimeFormat = txt_RDBMSDateTimeFormat.Text.Trim();
                }
                else if (rbtDateTimeSeperate.Checked == true)
                {
                    intMDB_DateTimeBit = 0;
                    strMDB_Date = txtRDBMSDate.Text.Trim();
                    strDateFormat = txt_RDBMSDateFormat.Text.Trim();
                    strMDB_Time = txtRDBMSTime.Text.Trim();
                    strTimeFormat = txt_RDBMSTimeFormat.Text.Trim();
                    if (chkEncrypted.Checked == true)
                    {
                        intIsEncrypted = 1;
                    }
                }
                strMDB_Type = txtRDBMSType.Text.Trim();
                if (chk_TransIdentifier.Checked == true)
                {
                    intTransIdentifierBit = 1;
                    strMDB_TransactionIdentifier = txt_RDBMSTransactionIdentifier.Text.Trim();
                    strTransIdentifierValue = txt_TIValue.Text.Trim();
                }
                strMDB_RDBMS_Flag = txt_FlagField.Text.Trim();
                break;
        }
        IsFreeScan = (rb_Yes.Checked == true) ? 1 : 0;
        try
        {
            int count = objTerminalDatatype.CheckTerminalDatatype('I', 0, 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 == 0)
            {
                objTerminalDatatype.Update_TerminalDatatype("I", 0, 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, ddlBrandType.SelectedValue, IsFreeScan);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_DuplicateTerminalDataType", ci) + "');", true);
                txtRawDataFormat.Focus();
                return;
            }
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
        string strScript = "";
        strScript = strScript + "<script language='javascript'>";
        strScript = strScript + "alert('" + rm.GetString("Alert_TerminalDataTypesavedsuccessfully", ci) + "');";
        strScript = strScript + "location.replace('TA_UI_Master_TerminalDatatype.aspx');";
        strScript = strScript + "</script>";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_TerminalDatatype.aspx");
    }
    #endregion
    #region UserDefinedFunctions
    // 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)
    {
        /* 
           Based on the value entered 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. 
        */
        ddlReaderNo.Items.Clear();
        ddlCardNo.Items.Clear();
        ddlDate.Items.Clear();
        ddlTime.Items.Clear();
        ddlDateTime.Items.Clear();
        ddlType.Items.Clear();
        ddlTransactionIdentifier.Items.Clear();
        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-");
        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);
        }
    }
    // **********************************************************************************************************************
    // 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);
        chk_DelTransIdentifier.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_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);
        lbl_Type3.Text = rm.GetString("PunchTypes_PunchTypes", ci);
        chk_TransIdentifier.Text = rm.GetString("TerminalDataType_TransactionIdentifier", 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);
        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);
        btnSave.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btnCancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lblBrandType.Text = rm.GetString("BrandType", ci);
        chkEncrypted.Text = rm.GetString("Encrypt", ci);
        ddlFileType.Items[0].Text = rm.GetString("Select", 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);

    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(10, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        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]) + ";";
            }
        }
        string checkConnection = connectionString;
        OleDbConnection oledbConnection;
        try
        {
            oledbConnection = new OleDbConnection(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)
        {
            /*The following line added by karthikeyan for the login faild issue occurred. 
             * Because the normal alert add the ' this signature so the javascript not run properly.*/
            string str = "";
            str = ex.Message.ToString();
            str = str.Replace("'", "\"");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + str + "');", true);
            txtConnectionString.Focus();
            return false;
        }
        //switch (Convert.ToString(ddlBrandType.SelectedItem.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);
        //                    }
        //                    objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), checkConnection);
        //                }
        //            }
        //        }
        //        break;
        //Commented due to some restriction in biostar 2
        //case "Suprema-Biostar 2":
        //    if (Convert.ToString(ddlFileType.SelectedItem.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);
        //                    }
        //                    objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), checkConnection);
        //                }
        //            }
        //        }
        //    break;
        //Querys are handled into Collect raw data service as inline query to avoid db access directly.
        //case "ESSL":
        //    if (File.Exists(Server.MapPath("ESSL_Script_Single.sql")))
        //    {
        //        StreamReader sr = new StreamReader(Server.MapPath("ESSL_Script_Single.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);
        //                }
        //                objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), checkConnection);
        //            }
        //        }
        //    }
        //    break;
        //}
        if (Convert.ToString(ddlBrandType.SelectedItem.Text) != "ESSL" && Convert.ToString(ddlBrandType.SelectedItem.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)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedTableNameisnotcorrectPleaseverify", ci) + "');", true);
                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)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedReaderNoisnotcorrectPleaseverify", ci) + "');", true);
                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)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedCardNoisnotcorrectPleaseverify", ci) + "');", true);
                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)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedinputisnotcorrectPleaseverify", ci) + "');", true);
                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)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedPunchTypeisnotcorrectPleaseverify", ci) + "');", true);
                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)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedTransactionIdentifierisnotcorrectPleaseverify", ci) + "');", true);
                    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)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedFlagisnotcorrectPleaseverify", ci) + "');", true);
                    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 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]) + ";";
            }
        }
        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)
        {
            /*The following line added by karthikeyan for the login faild issue occurred. 
             * Because the normal alert add the ' this signature so the javascript not run properly.*/
            string str = "";
            str = ex.Message.ToString();
            str = str.Replace("'", "\"");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + str + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedTableNameisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedReaderNoisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedCardNoisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedinputisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedPunchTypeisnotcorrectPleaseverify", ci) + "');", true);
            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)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedTransactionIdentifierisnotcorrectPleaseverify", ci) + "');", true);
                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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedFlagisnotcorrectPleaseverify", ci) + "');", true);
            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]) + ";";
            }
        }
        string checkConnection = connectionString;
        OleDbConnection oledbConnection;
        try
        {
            oledbConnection = new OleDbConnection(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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + ex.Message + "')", true);
            txtConnectionString.Focus();
            return false;
        }
        if (Convert.ToString(ddlBrandType.SelectedItem.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);
                        }
                        objTerminalDatatype.ExecuteTriggerAndTableScript(Convert.ToString(sb), checkConnection);
                    }
                }
            }
        }
        else if (Convert.ToString(ddlBrandType.SelectedItem.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);
                        }
                        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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedTableNameisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedReaderNoisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedCardNoisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedinputisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedinputisnotcorrectPleaseverify", ci) + "');", true);
            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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedPunchTypeisnotcorrectPleaseverify", ci) + "');", true);
            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)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedTransactionIdentifierisnotcorrectPleaseverify", ci) + "');", true);
                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)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_SpecifiedFlagisnotcorrectPleaseverify", ci) + "');", true);
            txt_FlagField.Focus();
            oledbConnection.Close();
            return false;
        }
        oledbConnection.Close();
        return true;
    }
    #endregion
}