Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
        }