Esempio n. 1
0
        public static DataTable table = gettable();//实例化表

        /*针对于DTS数据,把路径信息,时间信息,以及要存入的表格信息*/
        public static DataTable getDTSFileName(string foldPath)
        {
            DirectoryInfo TheFolder = new DirectoryInfo(foldPath);

            //遍历文件夹
            try
            {
                foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories())
                {
                    getDTSFileName(NextFolder.FullName);
                }
                //遍历文件
                foreach (FileInfo NextFile in TheFolder.GetFiles())
                {
                    if (NextFile.Extension == ".tra")                              //判断文件的后缀是否是所需要的
                    {
                        DateTime dt = generalClass.getFileTime(NextFile.FullName); //依靠路径获取时间点
                        DataRow  dr = table.NewRow();                              //创建数据行
                        dr["fa"] = NextFile.FullName;                              //路径
                        dr["fb"] = dt;                                             //时间
                        dr["fc"] = CreateTable.getTableName(dt, "DTS");            //获取文件将要存入的表名称
                        table.Rows.Add(dr);                                        //将创建的数据行添加到table中
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            catch// (Exception ex)
            {
                //writelog.WriteLog("部分文件夹或文件不可读" + ex);
            }
            return(table);
        }
Esempio n. 2
0
        public static void selectFolderGrat()
        {
            try
            {
                CreateTable.CTemporparyTable("temporpary_data");
            }
            catch
            {
            }
            FolderBrowserDialog dialog = new FolderBrowserDialog();

            dialog.Description = "请选择文件夹路径";
            DataTable table = importGrat.getfileGrat(MainForm.getInstance().GratFolder.Text);//获取DTS文件的路径,时间,将要存储到的表名称。

            if (table.Rows.Count != 0)
            {
                importDTS.import_temporpary_data(table);//存入数据库
            }
            else
            {
                MessageBox.Show("该路径中没有FBG文档");
            }
            MyClass.goTrue();
            MainForm.getInstance().FBRimportLable.Visible = false;
        }
Esempio n. 3
0
        public static void ImportDts()
        {
            DateTime startTime = DateTime.Now; //计算程序运行时间
            //TimeSpan ts = DateTime.Now - startTime;
            DataTable table  = getfenTable();  //获取所有tra文档路径信息
            DataTable table1 = getFenTable();  //获取不同数据表名称

            ThreadPool.SetMaxThreads(5, 5);    //最多执行5个线程
            importDTS    t = new importDTS();
            WaitCallback callBack;

            for (int i = 0; i < table1.Rows.Count; i++)
            {
                object ob        = new object();
                string tableName = table1.Rows[i][0].ToString();
                //创建数据库数据表
                CreateTable.CDataTable(tableName);
                DataTable newdt = new DataTable();
                newdt = table.Clone();                                            // 克隆dt 的结构,包括所有 dt 架构和约束,并无数据;
                DataRow[] rows = table.Select("folderTable='" + tableName + "'"); // 从dt 中查询符合条件的记录;
                foreach (DataRow row in rows)                                     // 将查询的结果添加到dt中;
                {
                    newdt.Rows.Add(row.ItemArray);
                }
                ob       = (Object)newdt;
                callBack = new WaitCallback(t.insertData);
                ThreadPool.QueueUserWorkItem(callBack, ob);
            }
            while (true)             //判断线程池中的线程是否完全结束
            {
                Thread.Sleep(10000); //这句写着,主要是没必要循环那么多次。去掉也可以。
                int maxWorkerThreads, workerThreads;
                int portThreads;
                ThreadPool.GetMaxThreads(out maxWorkerThreads, out portThreads);
                ThreadPool.GetAvailableThreads(out workerThreads, out portThreads);
                if (maxWorkerThreads - workerThreads == 0)
                {
                    TimeSpan ts = DateTime.Now - startTime;
                    MessageBox.Show("DTS数据导入完成,总共花费时间:" + ts.ToString(), "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MyClass.goTrue();
                    MainForm.getInstance().DTSimportLable.Visible = false;
                    break;
                }
            }
        }
Esempio n. 4
0
        public static void importDTSReal(DataTable table, string filename)
        {
            try {
                MySqlConnection mycon = getMycon();
                DateTime        dt    = Convert.ToDateTime(table.Rows[0][0]);
                //判断是否已经导入数据库
                string       Str   = "select COUNT(*) from  alltemporpary_data where  folderTime='" + dt + "'";//如果等于‘1’下面的代码不执行。
                MySqlCommand mycmd = new MySqlCommand(Str, mycon);
                int          count = Convert.ToInt32(mycmd.ExecuteScalar());
                if (count != 0)
                {
                }
                else
                {
                    string name = CreateTable.getTableName(dt, "DTS"); //获取文件将要存入的表名称
                    CreateTable.CDataTable(name);                      //创建表

                    string str, sum = null;
                    //try
                    //{
                    for (int h = 0; h < table.Rows.Count; h++)                                                                                         //依照辛工的要求,修改成具体数值,并修改下面代码
                    {
                        str = "('" + dt + "','" + float.Parse(table.Rows[h][1].ToString()) + "','" + float.Parse(table.Rows[h][2].ToString()) + "'),"; //有几个字段就写几个,行(i)是不变的,列值累加
                        sum = sum + str;
                    }
                    string str1 = "insert into " + name + "(RecordTime,Depth,TM) values" + sum;
                    string str2 = str1.Substring(0, str1.LastIndexOf(",")); //获取SQL语句
                    doStrmycon(str2, mycon);
                    filename = filename.Replace("\\", "\\\\");              //为了保存路径到数据库,不许进行的操作。
                    string str3 = "insert into alltemporpary_data(folderUrl,folderTime,folderTable) values ('" + filename + "','" + dt + "','" + name + "')";
                    doStrmycon(str3, mycon);
                    //}
                    //catch (Exception se)
                    //{
                    //    writelog.WriteLog("部分文件夹或文件不可读" + se);
                    //}
                }
                mycon.Close();
                mycon.Dispose();
            }
            catch //(Exception se)
            {
                //writelog.WriteLog("部分文件夹或文件不可读" + se);
            }
        }
Esempio n. 5
0
        public static void importGratReal(DataTable table, string filename)
        {
            MySqlConnection mycon = getMycon();
            DateTime        dt    = Convert.ToDateTime(table.Rows[0][0]);

            //判断是否已经导入数据库
            string       Str   = "select folderTime from  allGrat_data where  folderTime='" + dt + "'";//如果等于‘1’下面的代码不执行。
            MySqlCommand mycmd = new MySqlCommand(Str, mycon);
            object       count = mycmd.ExecuteScalar();

            if (count != null)
            {
            }
            else
            {
                //DateTime dt = Convert.ToDateTime(table.Rows[0][0]);
                //  = DateTime.ParseExact(Str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                string name = CreateTable.getGratTableName(dt, "fbr"); //获取文件将要存入的表名称
                CreateTable.CDataTable(name);                          //创建表
                string str, sum = null;
                try
                {
                    for (int h = 0; h < table.Rows.Count; h++)                                                                                       //依照辛工的要求,修改成具体数值,并修改下面代码
                    {
                        str = "('" + dt + "','" + int.Parse(table.Rows[h][1].ToString()) + "','" + float.Parse(table.Rows[h][2].ToString()) + "'),"; //有几个字段就写几个,行(i)是不变的,列值累加
                        sum = sum + str;
                    }
                    string str1 = "insert into " + name + "(RecordTime,Depth,TM) values" + sum;
                    string str2 = str1.Substring(0, str1.LastIndexOf(",")); //获取SQL语句
                    doStrmycon(str2, mycon);
                    filename = filename.Replace("\\", "\\\\");              //为了保存路径到数据库,不许进行的操作。
                    string str3 = "insert into allgrat_data(folderUrl,folderTime,folderTable) values ('" + filename + "','" + dt + "','" + name + "')";
                    doStrmycon(str3, mycon);
                }
                catch //(Exception se)
                {
                    // writelog.WriteLog("部分文件夹或文件不可读" + se);
                }
            }
            mycon.Close();
            mycon.Dispose();
        }
Esempio n. 6
0
        public static DataTable table = importDTS.gettable();//实例化表

        /*针对于Grat数据,把路径信息,时间信息,以及要存入的表格信息*/
        public static DataTable getfileGrat(string foldPath)
        {
            DirectoryInfo TheFolder = new DirectoryInfo(foldPath);

            //遍历文件夹
            try
            {
                foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories())
                {
                    getfileGrat(NextFolder.FullName);
                }
                //遍历文件
                foreach (FileInfo NextFile in TheFolder.GetFiles())
                {
                    if (NextFile.Extension == ".fbr")//判断文件的后缀是否是所需要的
                    {
                        string   filename = NextFile.FullName;
                        string   timestr  = filename.Substring(filename.LastIndexOf("\\") + 1, filename.LastIndexOf(".") - (filename.LastIndexOf("\\") + 1)); //去除后缀
                        string   str      = timestr.Remove(0, timestr.Length - 14);                                                                           //取去除后缀的文件名称的后14位数据。
                        DateTime dt       = DateTime.ParseExact(str, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);

                        DataRow dr = table.NewRow();                        //创建数据行
                        dr["fa"] = NextFile.FullName;                       //路径
                        dr["fb"] = dt;                                      //时间
                        dr["fc"] = CreateTable.getGratTableName(dt, "fbr"); //获取文件将要存入的表名称
                        table.Rows.Add(dr);                                 //将创建的数据行添加到table中
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            catch //(Exception ex)
            {
                //writelog.WriteLog("部分文件夹或文件不可读" + ex);
            }

            return(table);
        }
Esempio n. 7
0
        public static string  getWellStr()
        {
            float           wellzero = ZedGraphClass.getWellZero();
            MySqlConnection mycon    = new MySqlConnection();

            mycon = getMycon();
            string Str = null;
            //string aa = MainForm.getInstance().WellTime.Value.ToString();
            DateTime aa = MainForm.getInstance().WellTime.Value;//获取时间
            //string name = CreateTable.getTableName(aa, "DTS");//获取文件将要存入的表名称
            //CreateTable.CDataTable(name);//创建表
            string str = "SELECT DISTINCT folderTime from alltemporpary_data WHERE folderTime >=  \'" + aa + "\' order by folderTime";

            System.Data.DataTable dt = getDataTable(str, mycon);
            if (dt.Rows.Count != 0)
            {
                aa = Convert.ToDateTime(dt.Rows[0]["folderTime"]);
                string name = CreateTable.getTableName(aa, "DTS");//获取文件将要存入的表名称
                Str = "Select wellbore.mD,wellbore.DepthH,wellbore.TVD,wellbore.inclAngle," + name + ".TM  from wellbore ," + name + "  Where wellbore.mD =(" + name + ".Depth-" + wellzero + ") and " + name + ".RecordTime='" + aa + "'";
            }

            return(Str);
        }
Esempio n. 8
0
        //public static string getStr(DataTable table1,DateTime Time,string name)
        //{
        //    string str3, sum3 = null;
        //    for (int h = 0; h < table1.Rows.Count; h++)//依照辛工的要求,修改成具体数值,并修改下面代码
        //    {
        //        str3 = "('" + Time + "','" + int.Parse(table1.Rows[h][1].ToString()) + "','" + float.Parse(table1.Rows[h][2].ToString()) + "'),";//有几个字段就写几个,行(i)是不变的,列值累加
        //        sum3 = sum3 + str3;
        //    }
        //    str3 = "insert into " + name + "(RecordTime,Depth,TM) values" + sum3;
        //    str3 = str3.Substring(0, str3.LastIndexOf(","));//获取SQL语句
        //    return str3;

        //}
        //public  void getSQL(DataTable table, string filename, DateTime Time,string name,MySqlConnection mycon)
        //{
        //    string str, sum = null;
        //    try
        //    {
        //        for (int h = 115; h < 2615; h++)//依照辛工的要求,修改成具体数值,并修改下面代码
        //        {
        //            string readStr = table.Rows[h][1].ToString();
        //            string[] strs = readStr.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);//将读取的字符串按"制表符/t“和””“分割成数组
        //            str = "('" + Time + "','" + int.Parse(strs[1]) + "','" + float.Parse(strs[2]) + "'),";//有几个字段就写几个,行(i)是不变的,列值累加
        //            sum = sum + str;
        //        }
        //        string str1 = "insert into " + name + "(RecordTime,Depth,TM) values" + sum;
        //        string str2 = str1.Substring(0, str1.LastIndexOf(","));//获取SQL语句
        //        doStrmycon(str2, mycon);
        //        filename = filename.Replace("\\", "\\\\");//为了保存路径到数据库,不许进行的操作。
        //        string str3 = "insert into alltemporpary_data(folderUrl,folderTime,folderTable) values ('" + filename + "','" + Time + "','" + name + "')";
        //        doStrmycon(str3, mycon);
        //    }
        //    catch// (Exception se)
        //    {
        //        // writelog.WriteLog("部分文件夹或文件不可读" + se);
        //    }

        //}
        public static void selectFolder()
        {
            //创建临时表,并将路径信息导入临时表
            try
            {
                CreateTable.CTemporparyTable("temporpary_data");
            }
            catch//(Exception  ex)
            {
                //writelog.WriteLog("a"+ex);
            }
            DataTable table = importDTS.getDTSFileName(MainForm.getInstance().dataFolder.Text);//获取DTS文件的路径,时间,将要存储到的表名称。

            if (table.Rows.Count != 0)
            {
                importDTS.import_temporpary_data(table);//存入数据库
            }
            else
            {
                MessageBox.Show("该路径中没有DTS文档");
            }
            MyClass.goTrue();
            MainForm.getInstance().DTSimportLable.Visible = false;
        }