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); }
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); } }
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); }