示例#1
0
        private void OpenDataLinkDialog(string connection, dbDriver driver, string caption)
        {
            DataLinksClass dl = new MSDASC.DataLinksClass();

            ADODB.Connection conn = new ADODB.ConnectionClass();
            conn.ConnectionString = connection;

            object objCn = (object)conn;

            //	dl.PromptNew();
            if (dl.PromptEdit(ref objCn))
            {
                this.Text = "MyMeta Browser " + caption;

                string error = "";
                try
                {
                    myMeta = new dbRoot();
                    myMeta.Connect(driver, conn.ConnectionString);
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }

                this.InitializeTree(myMeta, error);
            }
        }
示例#2
0
 public static CubeDef GetCubeDef(string cubeName)
 {
     ConnectionClass con = new ADODB.ConnectionClass();
       con.Open("Location=localhost;Initial Catalog=PsiMedicaCubes;Provider=MSOLAP;",string.Empty,string.Empty,(int)ConnectModeEnum.adModeUnknown);
       CatalogClass cat = new ADOMD.CatalogClass();
       cat.ActiveConnection = con;
       return cat.CubeDefs[cubeName];
 }
示例#3
0
        public static CubeDef GetCubeDef(string cubeName)
        {
            ConnectionClass con = new ADODB.ConnectionClass();

            con.Open("Location=localhost;Initial Catalog=PsiMedicaCubes;Provider=MSOLAP;", string.Empty, string.Empty, (int)ConnectModeEnum.adModeUnknown);
            CatalogClass cat = new ADOMD.CatalogClass();

            cat.ActiveConnection = con;
            return(cat.CubeDefs[cubeName]);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            ConnectionClass con = new ADODB.ConnectionClass();

            con.Open("Location=localhost;Initial Catalog=PsiMedicaCubes;Provider=MSOLAP;", string.Empty, string.Empty, (int)ConnectModeEnum.adModeUnknown);
            CatalogClass cat = new ADOMD.CatalogClass();

            cat.ActiveConnection = con;
            outputHTML           = TransformXMLStream(GetTreeXML(cat, con), Server.MapPath("xsl/tree.xsl"));
        }
示例#5
0
        private bool IsColumnReadOnly(string name, string column)
        {
            if (radioSql.Checked)
            {
                int  tableid = Gateway.Default.SelectScalar <int>("select id from sysobjects where [name] = @name", new object[] { name });
                byte status  = Gateway.Default.SelectScalar <byte>("select status from syscolumns where [name] = @name and id = @id", new object[] { column, tableid });
                return(status == 128);
            }
            else if (radioOracle.Checked)
            {
                return(false);
            }
            else if (radioMySql.Checked)
            {
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("(^.*database=)([^;]+)(;.*)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                string dbName = r.Replace(txtConnStr.Text, "$2").ToLower();

                DataSet ds = Gateway.Default.SelectDataSet("select EXTRA from COLUMNS where TABLE_SCHEMA = '" + dbName + "' and COLUMN_NAME = '" + column + "' and TABLE_NAME = ?TABLE_NAME", new object[] { name });
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString() == "auto_increment")
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else
            {
                ADODB.ConnectionClass conn = new ADODB.ConnectionClass();
                conn.Provider = "Microsoft.Jet.OLEDB.4.0";
                string connStr = txtConnStr.Text;
                conn.Open(connStr.Substring(connStr.ToLower().IndexOf("data source") + "data source".Length).Trim('=', ' '), null, null, 0);

                ADODB.Recordset rs = conn.GetType().InvokeMember("OpenSchema", BindingFlags.InvokeMethod, null, conn, new object[] { ADODB.SchemaEnum.adSchemaColumns }) as ADODB.Recordset;
                rs.Filter = "TABLE_NAME='" + name + "'";

                while (!rs.EOF)
                {
                    if ((rs.Fields["COLUMN_NAME"].Value as string) == column && ((int)rs.Fields["DATA_TYPE"].Value) == 3 && Convert.ToByte(rs.Fields["COLUMN_FLAGS"].Value) == 90)
                    {
                        return(true);
                    }

                    rs.MoveNext();
                }
            }

            return(false);
        }
示例#6
0
        private bool IsColumnPrimaryKey(string name, string column)
        {
            if (radioSql.Checked)
            {
                int     tableid = Gateway.Default.SelectScalar <int>("select id from sysobjects where [name] = @name", new object[] { name });
                DataSet ds      = Gateway.Default.SelectDataSet("select a.name FROM syscolumns a inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' where (SELECT count(*) FROM sysobjects WHERE (name in (SELECT name FROM sysindexes WHERE (id = a.id) AND (indid in (SELECT indid FROM sysindexkeys WHERE (id = a.id) AND (colid in (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name))))))) AND (xtype = 'PK'))>0 and d.id = @id", new object[] { tableid });
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString() == column)
                    {
                        return(true);
                    }
                }
            }
            else if (radioOracle.Checked)
            {
                DataSet ds = Gateway.Default.SelectDataSet("select b.COLUMN_NAME from USER_CONSTRAINTS a,USER_CONS_COLUMNS b where a.CONSTRAINT_NAME=b.CONSTRAINT_NAME and a.table_name=b.table_name and constraint_type='P' and a.owner=b.owner and a.table_name = :name", new object[] { name });
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString() == column)
                    {
                        return(true);
                    }
                }
            }
            else if (radioMySql.Checked)
            {
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("(^.*database=)([^;]+)(;.*)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                string dbName = r.Replace(txtConnStr.Text, "$2").ToLower();

                DataSet ds = Gateway.Default.SelectDataSet("select COLUMN_NAME from KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA = '" + dbName + "' and CONSTRAINT_NAME = 'PRIMARY' and TABLE_NAME = ?TABLE_NAME", new object[] { name });
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (ds.Tables[0].Rows[i][0].ToString() == column)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                ADODB.ConnectionClass conn = new ADODB.ConnectionClass();
                conn.Provider = "Microsoft.Jet.OLEDB.4.0";
                string connStr = txtConnStr.Text;
                conn.Open(connStr.Substring(connStr.ToLower().IndexOf("data source") + "data source".Length).Trim('=', ' '), null, null, 0);

                ADODB.Recordset rs = conn.GetType().InvokeMember("OpenSchema", BindingFlags.InvokeMethod, null, conn, new object[] { ADODB.SchemaEnum.adSchemaPrimaryKeys }) as ADODB.Recordset;
                rs.Filter = "TABLE_NAME='" + name + "'";

                while (!rs.EOF)
                {
                    if ((rs.Fields["COLUMN_NAME"].Value as string) == column)
                    {
                        return(true);
                    }

                    rs.MoveNext();
                }
            }

            return(false);
        }
示例#7
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (txtConnStr.Text.Trim().Length == 0)
            {
                MessageBox.Show("Connection string cannot be null!");
                return;
            }

            if (btnConnect.Text == "Disconnect")
            {
                EnableGenEntity(false);
                return;
            }

            RefreshConnectionStringAutoComplete();

            DataSet dsTables = null;
            DataSet dsViews  = null;

            if (radioSql.Checked || radioAccess.Checked)
            {
                try
                {
                    if (radioSql.Checked)
                    {
                        Gateway.SetDefaultDatabase(DatabaseType.SqlServer, txtConnStr.Text);
                        if (checkSql2005.Checked)
                        {
                            dsTables = Gateway.Default.SelectDataSet("select [name] from sysobjects where xtype = 'U' and [name] <> 'sysdiagrams' order by [name]", null);
                        }
                        else
                        {
                            dsTables = Gateway.Default.SelectDataSet("select [name] from sysobjects where xtype = 'U' and status > 0 order by [name]", null);
                        }
                        foreach (DataRow row in dsTables.Tables[0].Rows)
                        {
                            tables.Items.Add(row["Name"].ToString());
                        }

                        if (checkSql2005.Checked)
                        {
                            dsViews = Gateway.Default.SelectDataSet("select [name] from sysobjects where xtype = 'V' order by [name]", null);
                        }
                        else
                        {
                            dsViews = Gateway.Default.SelectDataSet("select [name] from sysobjects where xtype = 'V' and status > 0 order by [name]", null);
                        }
                        foreach (DataRow row in dsViews.Tables[0].Rows)
                        {
                            views.Items.Add(row["Name"].ToString());
                        }
                    }
                    else if (radioAccess.Checked)
                    {
                        Gateway.SetDefaultDatabase(DatabaseType.MsAccess, txtConnStr.Text);
                        ADODB.ConnectionClass conn = new ADODB.ConnectionClass();
                        conn.Provider = "Microsoft.Jet.OLEDB.4.0";
                        string connStr = txtConnStr.Text;
                        conn.Open(connStr.Substring(connStr.ToLower().IndexOf("data source") + "data source".Length).Trim('=', ' '), null, null, 0);

                        ADODB.Recordset rsTables = conn.GetType().InvokeMember("OpenSchema", BindingFlags.InvokeMethod, null, conn, new object[] { ADODB.SchemaEnum.adSchemaTables }) as ADODB.Recordset;
                        ADODB.Recordset rsViews  = conn.GetType().InvokeMember("OpenSchema", BindingFlags.InvokeMethod, null, conn, new object[] { ADODB.SchemaEnum.adSchemaViews }) as ADODB.Recordset;

                        while (!rsViews.EOF)
                        {
                            if (!(rsViews.Fields["TABLE_NAME"].Value as string).StartsWith("MSys"))
                            {
                                views.Items.Add(rsViews.Fields["TABLE_NAME"].Value.ToString());
                            }
                            rsViews.MoveNext();
                        }

                        while (!rsTables.EOF)
                        {
                            if (!(rsTables.Fields["TABLE_NAME"].Value as string).StartsWith("MSys"))
                            {
                                bool isView = false;
                                foreach (string item in views.Items)
                                {
                                    if (item.Equals(rsTables.Fields["TABLE_NAME"].Value.ToString()))
                                    {
                                        isView = true;
                                        break;
                                    }
                                }
                                if (!isView)
                                {
                                    tables.Items.Add(rsTables.Fields["TABLE_NAME"].Value.ToString());
                                }
                            }
                            rsTables.MoveNext();
                        }

                        rsTables.Close();
                        rsViews.Close();

                        conn.Close();
                    }

                    EnableGenEntity(true);
                }
                catch (Exception ex)
                {
                    EnableGenEntity(false);
                    MessageBox.Show("Read/write database error!\r\n" + ex.ToString());
                }
            }
            else if (radioOracle.Checked)
            {
                Gateway.SetDefaultDatabase(DatabaseType.Oracle, txtConnStr.Text);

                dsTables = Gateway.Default.SelectDataSet("select * from user_tables where global_stats = 'NO' and (not table_name like '%$%')", null);
                foreach (DataRow row in dsTables.Tables[0].Rows)
                {
                    tables.Items.Add(row["TABLE_NAME"].ToString());
                }

                dsViews = Gateway.Default.SelectDataSet("select * from user_views where (not view_name like '%$%') and (not view_name like 'MVIEW_%') and (not view_name like 'CTX_%') and (not view_name = 'PRODUCT_PRIVS')", null);
                foreach (DataRow row in dsViews.Tables[0].Rows)
                {
                    views.Items.Add(row["VIEW_NAME"].ToString());
                }

                EnableGenEntity(true);
            }
            else if (radioMySql.Checked)
            {
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("(^.*database=)([^;]+)(;.*)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                string dbName = r.Replace(txtConnStr.Text, "$2").ToLower();
                Gateway.SetDefaultDatabase(DatabaseType.MySql, r.Replace(txtConnStr.Text, "$1information_schema$3"));

                dsTables = Gateway.Default.SelectDataSet("select * from TABLES where TABLE_TYPE = 'BASE TABLE' and TABLE_SCHEMA = '" + dbName + "'", null);
                foreach (DataRow row in dsTables.Tables[0].Rows)
                {
                    tables.Items.Add(row["TABLE_NAME"].ToString());
                }

                dsViews = Gateway.Default.SelectDataSet("select * from TABLES where TABLE_TYPE = 'VIEW' and TABLE_SCHEMA = '" + dbName + "'", null);
                foreach (DataRow row in dsViews.Tables[0].Rows)
                {
                    views.Items.Add(row["TABLE_NAME"].ToString());
                }

                EnableGenEntity(true);
            }
            else
            {
                EnableGenEntity(false);
                MessageBox.Show("EntityGen tool only supports SqlServer, MsAccess, MySql and Oracle Database!");
            }
        }
        private void Transfer(ListBox _lbxFile, ListBox _lbxRecord, Label _lbNumRec, int _iSEQ_NO, ref bool _bFin)
        {
            //			bool bContinue = false;
            SqlConnection SqlCon = new SqlConnection(PublicFunction.C_con.ConnectionString);

            SqlCon.Open();

            string str_Con;             //string connection

            ADODB.Connection ad_Con = new ADODB.ConnectionClass();
            ADODB.Recordset  ad_Rs  = new ADODB.RecordsetClass();

            string S_sDir      = txt_path1.Text;        //T_String.GetDataFromSQL("DIR_DR","GP_SYS_READER","SEQ_NO='" + _iSEQ_NO + "'", SqlCon);
            string S_sFile     = txt_file1.Text;        //T_String.GetDataFromSQL("FIL_NM", "GP_SYS_READER", "SEQ_NO='" + _iSEQ_NO + "'", SqlCon);
            string sDateFormat = PublicFunction.GetOption("SCHEMA_DateFormat");
            string sDouble     = "";

            sDouble = PublicFunction.GetOption("SCHEMA_DOUBLE");
            //int S_dbBook = T_String.IsNullTo0(T_String.GetDataFromSQL("RCD_FG", "GP_SYS_READER", "SEQ_NO='" + _iSEQ_NO + "'", SqlCon));
            string S_sAppPath = Application.StartupPath.ToString();

            if (!GetFileName(_lbxFile, S_sDir, S_sFile, SqlCon))
            {
                _bFin = true;
                return;
            }

            if (!CreateTextFolder(S_sAppPath, _iSEQ_NO))
            {
                _bFin = true;
                return;
            }

            str_Con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + S_sAppPath + "\\PieceRateText" + _iSEQ_NO.ToString() + ";Extended Properties='text;HDR=Yes;FMT=Delimited';";

            if (!ADODB_Connect(ad_Con, str_Con))
            {
                _bFin = true;
                return;
            }

            for (int i = 0; i < _lbxFile.Items.Count; i++)
            {
                _lbxFile.SelectedIndex = i;

                ad_Rs = FillTextFileToRecordset(S_sDir, _lbxFile.Items[i].ToString(), S_sAppPath + "\\PieceRateText" + _iSEQ_NO.ToString(), ad_Con);

                if (ad_Rs.EOF)
                {
                }
                else
                {
                    while (ad_Rs.EOF == false)
                    {
                        string REA_NO;
                        string sql, EMP_ID;
                        double LSP;

                        if (stop)
                        {
                            ad_Rs.Close();
                            ADODB_Close(ad_Con);
                            return;
                        }

                        REA_NO = ad_Rs.Fields["READER_NO"].Value.ToString();
                        EMP_ID = REA_NO.Substring(12, 5);
                        LSP    = T_String.IsNullTo00(REA_NO.Substring(19, REA_NO.Length - 19));
//						CRD_NO = ad_Rs.Fields["CARD_NO"].Value.ToString();
//						CRD_DT=ad_Rs.Fields["DAYS"].Value.ToString();
//						CRD_DT.Trim();

                        try
                        {
                            sql = "UPDATE  FILD02A SET PieceRate=" + LSP + " WHERE EMP_ID='" + EMP_ID + "' AND YYY_MM='" + dt1.Text + "' AND SEQ_NO=2";

                            try
                            {
                                PublicFunction.SQL_Execute(sql, SqlCon);
                            }
                            catch (SqlException ex)
                            {
                                if (ex.Number != 2627)
                                {
                                    MessageBox.Show(ex.Message + "");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //								if (bContinue == false)
                            //								{
                            if (MessageBox.Show(ex.Message + "\n\rText File: " + _lbxFile.Items[i].ToString() +
                                                "\r\nContinue!", "Error!", System.Windows.Forms.MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                stop = true;
                            }
                            //									bContinue = true;
                            //								}
                        }

                        _lbxRecord.Items.Add(EMP_ID + "  " + LSP.ToString());
                        _lbxRecord.SelectedIndex = _lbxRecord.Items.Count - 1;
                        //						_lbNumRec.Text = (ad_Rs.Bookmark ) + "/" + ad_Rs.RecordCount.ToString();
                        //						_lbNumRec.Text = (S_dbBook.ToString()+1) + "/" + ad_Rs.RecordCount.ToString();


                        ad_Rs.MoveNext();
                    }
                }
            }


            _bFin = true;

            SqlCon.Close();
            ad_Rs.Close();
            ADODB_Close(ad_Con);
        }
示例#9
0
 private void Page_Load(object sender, System.EventArgs e)
 {
     ConnectionClass con = new ADODB.ConnectionClass();
       con.Open("Location=localhost;Initial Catalog=PsiMedicaCubes;Provider=MSOLAP;",string.Empty,string.Empty,(int)ConnectModeEnum.adModeUnknown);
       CatalogClass cat = new ADOMD.CatalogClass();
       cat.ActiveConnection = con;
       outputHTML = TransformXMLStream(GetTreeXML(cat,con),Server.MapPath("xsl/tree.xsl"));
 }
示例#10
0
        private void TransferY(ListBox _lbxFile, ListBox _lbxRecord, Label _lbNumRec, int _iSEQ_NO, ref bool _bFin)
        {
//			bool bContinue = false;
            SqlConnection SqlCon = new SqlConnection(PublicFunction.C_con.ConnectionString);

            SqlCon.Open();
            string keyD  = "";
            string stype = "";
            int    iphut = 0;
            string str_Con;             //string connection

            ADODB.Connection ad_Con = new ADODB.ConnectionClass();
            ADODB.Recordset  ad_Rs  = new ADODB.RecordsetClass();

            string S_sDir      = T_String.GetDataFromSQL("DIR_DR", "GP_SYS_READER", "SEQ_NO='" + _iSEQ_NO + "'", SqlCon);
            string S_sFile     = T_String.GetDataFromSQL("FIL_NM", "GP_SYS_READER", "SEQ_NO='" + _iSEQ_NO + "'", SqlCon);
            string sDateFormat = PublicFunction.GetOption("SCHEMA_DateFormat");
            string sDouble     = "";

            sDouble = PublicFunction.GetOption("SCHEMA_DOUBLE");
            int    S_dbBook   = T_String.IsNullTo0(T_String.GetDataFromSQL("RCD_FG", "GP_SYS_READER", "SEQ_NO='" + _iSEQ_NO + "'", SqlCon));
            string S_sAppPath = Application.StartupPath.ToString();
            //key
            SqlConnection SqlCon1 = new SqlConnection(PublicFunction.C_con.ConnectionString);

            SqlCon1.Open();
            Func.RecordSet rsK = new Func.RecordSet("Select * from GP_KEY", SqlCon1);
            if (rsK.rows > 0)
            {
                stype = rsK.record(0, "TYP_MN");
                keyD  = PublicFunction.encode(rsK.record(0, "COL_DT"), "");
                iphut = T_String.IsNullTo0(rsK.record(0, "COL_MN"));
            }

            //end
            DateTime dtFG = AQ800(PublicFunction.S_Left(GetName(S_sFile), 8));

            if (dtFG == new DateTime(1, 1, 1))        //if(PublicFunction.CUS_ID=="400")
            {
                if (!GetFileNameTHU(_lbxFile, S_sDir, S_sFile, SqlCon))
                {
                    _bFin = true;
                    return;
                }
            }
            else
            {
                if (!GetFileName(_lbxFile, S_sDir, S_sFile, SqlCon))
                {
                    _bFin = true;
                    return;
                }
            }

            if (!CreateTextFolder(S_sAppPath, _iSEQ_NO))
            {
                _bFin = true;
                return;
            }

            str_Con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + S_sAppPath + "\\Text" + _iSEQ_NO.ToString() + ";Extended Properties='text;HDR=Yes;FMT=Delimited';";

            if (!ADODB_Connect(ad_Con, str_Con))
            {
                _bFin = true;
                return;
            }

            for (int i = 0; i < _lbxFile.Items.Count; i++)
            {
                string sREA_NO = string.Empty;
                if (dtFG == new DateTime(1, 1, 1))           //if(PublicFunction.CUS_ID=="400")//su dung may van tay
                {
                    sREA_NO = _lbxFile.Items[i].ToString();
                    sREA_NO = PublicFunction.S_Left(sREA_NO, sREA_NO.Length - 12);
                }
                _lbxFile.SelectedIndex = i;
                ad_Rs = FillTextFileToRecordset(S_sDir, _lbxFile.Items[i].ToString(), S_sAppPath + "\\Text" + _iSEQ_NO.ToString(), ad_Con);

                if (ad_Rs.EOF || (S_dbBook > ad_Rs.RecordCount && GetName(S_sFile) == _lbxFile.Items[i].ToString()))
                {
                    if (i < _lbxFile.Items.Count - 1)
                    {
                        S_dbBook = 1;
                    }
                }
                else
                {
                    if (i > 0)
                    {
                        S_dbBook = 0;
                    }
                    if (S_dbBook > 0)
                    {
                        ad_Rs.Move(S_dbBook - 1, 1);
                    }

                    while (ad_Rs.EOF == false)
                    {
                        string REA_NO, CRD_NO, CRD_DT, CRD_TM, CRD_TM_02 = "";
                        string sql, EMP_ID;
                        double TM;

                        if (stop)
                        {
                            sql = "UPDATE GP_SYS_READER SET RCD_FG=" + S_dbBook + ",FIL_NM=N'" + S_sDir + "\\" + _lbxFile.Items[i].ToString() + "' where SEQ_NO='" + _iSEQ_NO + "'";
                            PublicFunction.SQL_Execute(sql, SqlCon);
                            ad_Rs.Close();
                            ADODB_Close(ad_Con);
                            return;
                        }

                        REA_NO = ad_Rs.Fields["READER_NO"].Value.ToString();
                        CRD_NO = ad_Rs.Fields["CARD_NO"].Value.ToString();
                        CRD_DT = ad_Rs.Fields["DAYS"].Value.ToString();
                        CRD_DT.Trim();
                        CRD_TM = "";
                        if (PublicFunction.CUS_ID == "300" && _iSEQ_NO == 1)                     //KenYa
                        {
                            string sdateh = "";
                            sdateh = CRD_DT;
                            CRD_NO = "00" + CRD_NO;
                            CRD_DT = sdateh.Substring(0, 10);
                            CRD_DT = CRD_DT.Replace("/", "");
                            CRD_TM = sdateh.Remove(0, 11);
                            CRD_TM = CRD_TM.Replace(":", "");
                        }
                        if (dtFG == new DateTime(1, 1, 1))                    //if(PublicFunction.CUS_ID=="400")//may van tay
                        {
                            REA_NO = sREA_NO;
                        }
                        if (sDateFormat == "" || sDateFormat == null)
                        {
                            CRD_DT = ad_Rs.Fields["DAYS"].Value.ToString().Replace("/", "").Replace("-", "");
                        }
                        else if (CRD_DT != "" && sDateFormat == "fr-FR")
                        {
                            try
                            {
                                IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);

                                // Alternate choice: If the string has been input by an end user, you might
                                // want to format it according to the current culture:
                                // IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;
                                CRD_DT = DateTime.Parse(CRD_DT, culture, System.Globalization.DateTimeStyles.None).ToString("yyyyMMdd");

//								CRD_DT = CRD_DT.Split("d",2);//DateTime.Parse(CRD_DT).ToString() ;// .ToString(sDateFormat);
//								CRD_DT = DateTime.Parse(CRD_DT).ToString("yyyyMMdd");
                            }
                            catch
                            {
                            }
                        }
                        if (PublicFunction.CUS_ID != "300" || _iSEQ_NO != 1)                   //kenya
                        {
                            CRD_TM = ad_Rs.Fields["HOURS"].Value.ToString().Replace(":", "");
                        }

                        try
                        {
                            if (CRD_NO != "" && CRD_TM != "" && CRD_DT != "")
                            {
                                DateTime dt1 = GetDateTime(CRD_DT, CRD_TM).AddMinutes(-CRD_MN);
                                DateTime dt2 = GetDateTime(CRD_DT, CRD_TM).AddMinutes(CRD_MN);

                                TM = T_String.IsNullTo00(CRD_TM);
                                if (TM == 0)
                                {
                                    TM     = 2400.0;
                                    CRD_TM = "2400";
                                    CRD_DT = GetDate(CRD_DT).AddDays(-1).ToString("yyyyMMdd");
                                }

                                sql = "(DAT_TM>" + dt1.ToString("yyyyMMddHHmm") + " and DAT_TM<" + dt2.ToString("yyyyMMddHHmm")
                                      + ") and CRD_NO=N'" + CRD_NO + "'";
                                if (!PublicFunction.SqlExists(SqlCon, "FILC01A", "CRD_DT='" + CRD_DT + "' AND CRD_NO='" + CRD_NO + "'"
                                                              + " AND (DAT_TM BETWEEN '" + dt1.ToString("yyyyMMddHHmm") + "' AND '" + dt2.ToString("yyyyMMddHHmm") + "' OR CRD_TM=" + TM + ")"))
                                {
//								if(T_String.IsNullTo0(T_String.GetDataFromSQL("top 1 1 ","FILC01A",sql, SqlCon))<=0 &&
//									T_String.IsNullTo0(T_String.GetDataFromSQL("top 1 1", "FILC01A", "DAT_TM=N'"+CRD_DT+CRD_TM+"' and CRD_NO=N'"+CRD_NO+"'", SqlCon))<=0)

                                    int index = this.CRD_NO.IndexOf(CRD_NO);
                                    if (index >= 0)
                                    {
                                        EMP_ID = this.EMP_ID[index] + "";
                                    }
                                    else
                                    {
                                        EMP_ID = "";
                                    }
                                    //==============================CHIA 2 TH DOC DU LIEU CHAM CONG VA DOC DU LIEU CHO MAY QUAN LY TOILET
                                    if (sReaNo_VS1.IndexOf(REA_NO, 0) < 0)                                 //(REA_NO != sReaNo_VS1 && REA_NO != sReaNo_VS2 )
                                    {
                                        sql  = "Insert into FILC01A(DAT_TM,EMP_ID,SWI_DT,USR_NM,CRD_DT,CRD_TM,CRD_NO,REA_NO,FIL_NM) values(";
                                        sql += "N'" + CRD_DT + CRD_TM + "',N'" + EMP_ID + "','" + dt + "',N'" + PublicFunction.A_UserID + "',";
                                        sql += "'" + CRD_DT + "'," + TM + ",";
                                        sql += "N'" + CRD_NO + "',N'" + REA_NO + "',";
                                        sql += "N'" + S_sDir + "\\" + _lbxFile.Items[i].ToString() + "')";
                                    }
                                    else
                                    {
                                        sql  = "Insert into FILC01A_VS(DAT_TM,EMP_ID,SWI_DT,USR_NM,CRD_DT,CRD_TM,CRD_NO,REA_NO,FIL_NM) values(";
                                        sql += "N'" + CRD_DT + CRD_TM + "',N'" + EMP_ID + "','" + dt + "',N'" + PublicFunction.A_UserID + "',";
                                        sql += "'" + CRD_DT + "'," + TM + ",";
                                        sql += "N'" + CRD_NO + "',N'" + REA_NO + "',";
                                        sql += "N'" + S_sDir + "\\" + _lbxFile.Items[i].ToString() + "')";
                                    }

//									sql="Insert into FILC01A(DAT_TM,EMP_ID,SWI_DT,USR_NM,CRD_DT,CRD_TM,CRD_NO,REA_NO,FIL_NM) values(";
//									sql+="N'"+CRD_DT+CRD_TM+"',N'"+EMP_ID+"','"+dt+"',N'"+PublicFunction.A_UserID+"',";
//									sql+="'"+CRD_DT+"',"+TM+",";
//									sql+="N'"+CRD_NO+"',N'"+REA_NO+"',";
//									sql+="N'"+ S_sDir + "\\" + _lbxFile.Items[i].ToString() +"')";

                                    try
                                    {
                                        PublicFunction.SQL_Execute(sql, SqlCon);
                                    }
                                    catch (SqlException ex)
                                    {
                                        if (ex.Number != 2627)
                                        {
                                            MessageBox.Show(ex.Message + "");
                                        }
                                    }
                                }

                                if (sDouble != "" && sDouble != null)
                                {
                                    try
                                    {
                                        CRD_TM_02 = ad_Rs.Fields["HOURS_02"].Value.ToString().Replace(":", "");
                                    }
                                    catch
                                    {
                                    }
                                }

                                if (sDouble != "" && sDouble != null && CRD_TM_02 != "")
                                {
                                    dt1 = GetDateTime(CRD_DT, CRD_TM_02).AddMinutes(-CRD_MN);
                                    dt2 = GetDateTime(CRD_DT, CRD_TM_02).AddMinutes(CRD_MN);

                                    TM = T_String.IsNullTo00(CRD_TM_02);
                                    if (TM == 0)
                                    {
                                        TM     = 2400.0;
                                        CRD_TM = "2400";
                                        CRD_DT = GetDate(CRD_DT).AddDays(-1).ToString("yyyyMMdd");
                                    }
                                    sql = "(DAT_TM>" + dt1.ToString("yyyyMMddHHmm") + " and DAT_TM<" + dt2.ToString("yyyyMMddHHmm")
                                          + ") and CRD_NO=N'" + CRD_NO + "'";

//									if(T_String.IsNullTo0(T_String.GetDataFromSQL(" top 1 1","FILC01A",sql, SqlCon))<=0 && //COUNT(DAT_TM)
//										T_String.IsNullTo0(T_String.GetDataFromSQL("top 1 1", "FILC01A", "DAT_TM=N'"+CRD_DT+CRD_TM_02+"' and CRD_NO=N'"+CRD_NO+"'", SqlCon))<=0) //COUNT(EMP_ID)
                                    if (!PublicFunction.SqlExists(SqlCon, "FILC01A", "CRD_DT='" + CRD_DT + "' AND CRD_NO='" + CRD_NO + "'"
                                                                  + " AND (DAT_TM BETWEEN '" + dt1.ToString("yyyyMMddHHmm") + "' AND '" + dt2.ToString("yyyyMMddHHmm") + "' OR CRD_TM=" + TM + ")"))
                                    {
                                        int index = this.CRD_NO.IndexOf(CRD_NO);
                                        if (index >= 0)
                                        {
                                            EMP_ID = this.EMP_ID[index] + "";
                                        }
                                        else
                                        {
                                            EMP_ID = "";
                                        }
                                        //==============================CHIA 2 TH DOC DU LIEU CHAM CONG VA DOC DU LIEU CHO MAY QUAN LY TOILET
                                        if (sReaNo_VS1.IndexOf(REA_NO, 0) < 0)                                     //(REA_NO != sReaNo_VS1 && REA_NO != sReaNo_VS2)
                                        {
                                            sql  = "Insert into FILC01A(DAT_TM,EMP_ID,SWI_DT,USR_NM,CRD_DT,CRD_TM,CRD_NO,REA_NO,FIL_NM) values(";
                                            sql += "N'" + CRD_DT + CRD_TM_02 + "',N'" + EMP_ID + "','" + dt + "',N'" + PublicFunction.A_UserID + "',";
                                            sql += "'" + CRD_DT + "'," + T_String.IsNullTo00(CRD_TM_02) + ",";
                                            sql += "N'" + CRD_NO + "',N'" + REA_NO + "',";
                                            sql += "N'" + S_sDir + "\\" + _lbxFile.Items[i].ToString() + "')";
                                        }
                                        else
                                        {
                                            sql  = "Insert into FILC01A_VS(DAT_TM,EMP_ID,SWI_DT,USR_NM,CRD_DT,CRD_TM,CRD_NO,REA_NO,FIL_NM) values(";
                                            sql += "N'" + CRD_DT + CRD_TM_02 + "',N'" + EMP_ID + "','" + dt + "',N'" + PublicFunction.A_UserID + "',";
                                            sql += "'" + CRD_DT + "'," + T_String.IsNullTo00(CRD_TM_02) + ",";
                                            sql += "N'" + CRD_NO + "',N'" + REA_NO + "',";
                                            sql += "N'" + S_sDir + "\\" + _lbxFile.Items[i].ToString() + "')";
                                        }
//										sql="Insert into FILC01A(DAT_TM,EMP_ID,SWI_DT,USR_NM,CRD_DT,CRD_TM,CRD_NO,REA_NO,FIL_NM) values(";
//										sql+="N'"+CRD_DT+CRD_TM_02+"',N'"+EMP_ID+"','"+dt+"',N'"+PublicFunction.A_UserID+"',";
//										sql+="'"+CRD_DT+"',"+T_String.IsNullTo00(CRD_TM_02)+",";
//										sql+="N'"+CRD_NO+"',N'"+REA_NO+"',";
//										sql+="N'"+ S_sDir + "\\" + _lbxFile.Items[i].ToString() +"')";

                                        try
                                        {
                                            PublicFunction.SQL_Execute(sql, SqlCon);
                                        }
                                        catch (SqlException ex)
                                        {
                                            if (ex.Number != 2627)
                                            {
                                                MessageBox.Show(ex.Message + "");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
//								if (bContinue == false)
//								{
                            if (MessageBox.Show(ex.Message + "\n\rText File: " + _lbxFile.Items[i].ToString() +
                                                ", Bookmarks: " + Convert.ToString(S_dbBook + 1) +
                                                "\r\nContinue!", "Error!", System.Windows.Forms.MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                stop = true;
                            }
//									bContinue = true;
//								}
                        }

                        _lbxRecord.Items.Add(CRD_NO + "  " + CRD_DT + "  " + CRD_TM + "  " + CRD_TM_02);
                        _lbxRecord.SelectedIndex = _lbxRecord.Items.Count - 1;
//						_lbNumRec.Text = (ad_Rs.Bookmark ) + "/" + ad_Rs.RecordCount.ToString();
//						_lbNumRec.Text = (S_dbBook.ToString()+1) + "/" + ad_Rs.RecordCount.ToString();

                        S_dbBook++;
                        ad_Rs.MoveNext();
                        //Tao khoa lam cho chuyen du lieu chay cham
                        //LAY NGAY KHOA DUOI SQL
                        if (stype.ToUpper() == "AS")
                        {
                            if (DateTime.Now >= DateTime.Parse(keyD))
                            {
                                Thread.Sleep(500 * iphut);
                            }
                        }
                    }
                }
            }

            if (_lbxFile.Items.Count > 0)
            {
                string sql = "update  GP_SYS_READER set RCD_FG=" + S_dbBook + ", FIL_NM=N'" + S_sDir + "\\" + _lbxFile.Items[_lbxFile.Items.Count - 1] + "' where SEQ_NO=N'" + _iSEQ_NO + "'";
                PublicFunction.SQL_Execute(sql, SqlCon);
            }

            _bFin = true;

            SqlCon.Close();
            ad_Rs.Close();
            ADODB_Close(ad_Con);
        }
		private void OpenDataLinkDialog(string connection, dbDriver driver, string caption)
		{
			DataLinksClass dl = new MSDASC.DataLinksClass();

			ADODB.Connection conn = new ADODB.ConnectionClass();
			conn.ConnectionString = connection;

			object objCn = (object) conn;

			//	dl.PromptNew();
			if(dl.PromptEdit(ref objCn))
			{				
				this.Text = "MyMeta Browser " + caption;

				string error = "";
				try
				{
					myMeta = new dbRoot();
					myMeta.Connect(driver, conn.ConnectionString);
				}
				catch(Exception ex)
				{
					error = ex.Message;
				}

				this.InitializeTree(myMeta, error);
			}
		}