You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.6 KiB
C#
68 lines
2.6 KiB
C#
using Dapper;
|
|
using HandyControl.Controls;
|
|
using HandyControl.Themes;
|
|
using MySql.Data.MySqlClient;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Xml.Linq;
|
|
using Txgy.FilesWatcher.DBModels;
|
|
|
|
namespace Txgy.FilesWatcher.model
|
|
{
|
|
public class UploadMseedFile
|
|
{
|
|
|
|
public string FileName { get; set; }
|
|
|
|
public static void UploadMSeedOnce(string path, int workAreaId=1)
|
|
{
|
|
try
|
|
{
|
|
var currentTime = DateTime.Now;
|
|
var Dfiles = new DirectoryInfo(path).GetFiles("*.mseed");
|
|
foreach (var DFile in Dfiles)
|
|
{
|
|
string file = DFile.Name;
|
|
string tbname = file.Substring(3,10);
|
|
tbname=tbname.Replace("-","");
|
|
string uploadedtbname = $"uploaded{tbname}";
|
|
|
|
string sqlNumber = $"SELECT COUNT(*) FROM {uploadedtbname} WHERE filename = '{file}'";
|
|
//检查文件是否已经上传
|
|
using (var conn = DataBaseConnect.OpenConnection())
|
|
{
|
|
MySqlCommand cmd = new MySqlCommand(sqlNumber, conn);
|
|
var a = conn.QueryFirst<int>(sqlNumber);
|
|
if (a == 0)
|
|
{
|
|
//WorkAreaId = 1,更新
|
|
FileStream fs = new FileStream(DFile.FullName, FileMode.Open, FileAccess.Read);
|
|
BinaryReader mbr = new BinaryReader(fs);
|
|
Byte[] mseedDatas = mbr.ReadBytes((int)fs.Length);
|
|
fs.Close();
|
|
string WaveTime = tbname.Substring(3);
|
|
sqlNumber = $"INSERT INTO {tbname} (WaveTime, WorkAreaID, WaveData) VALUES('{WaveTime}', '{workAreaId}', @mseedD)";
|
|
var res = conn.Execute(sqlNumber, new { mseedD=mseedDatas});
|
|
|
|
//更新上传文件记录
|
|
sqlNumber = $"INSERT INTO {uploadedtbname}(filename, uploadtime) VALUES('{file}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
|
|
res = conn.Execute(sqlNumber);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Windows.MessageBox.Show(ex.ToString());
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|