123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- using System;
- using System.Collections.Generic;
- using Uninpho.DBOperation.Model;
- using Uninpho.DBOperation.Operation;
- using System.IO;
- namespace ZDHscript
- {
- /// <summary>
- /// 检查数据库
- /// </summary>
- class CheckedDB
- {
- /// <summary>
- /// CheckedDataBase主函数
- /// </summary>
- public static void DBCheckedFun()
- {
- // 1.检查
- CheckedGeo();
- CheckedBny();
- // 2.往t_file_account新增数据
- Add2fileAccount();
- // 3.并记录到Store中
- RecordNewData();
- }
- /// <summary>
- /// 往t_file_account新增数据
- /// </summary>
- public static void Add2fileAccount()
- {
- //1.先删除t_file_account表内相关数据
- foreach (var item in Store.newGeofiles)
- {
- DataAnalysisToPG.DelToPG1(new T_file_account() { Yswjm = Path.GetFileName(item) });
- }
- foreach (var item in Store.newBnyfiles)
- {
- DataAnalysisToPG.DelToPG1(new T_file_account() { Yswjm = Path.GetFileName(item) });
- }
- //2.统一再添加一次
- saveTfileName(Store.newGeofiles,"几何分析");
- saveTfileName(Store.newBnyfiles,"轮轨力分析");
- }
- /// <summary>
- /// 检查geo
- /// </summary>
- public static void CheckedGeo()
- {
- try
- {
- //1.检查T_file_account表
- foreach (string file in Store.geoList)
- {
- List<T_file_account> acc = DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(file)) as List<T_file_account>;
- if (acc.Count == 0)
- {
- Store.newGeofiles.Add(file);
- ColorClass.Console_AddColor("新增数据:" + file);
- }
- else
- {
- //2.若之前执行过文件,则再检查T_jihefenxi_account表内数据是否存在
- List<T_jihefenxi_account> jhacc = DataAnalysisToPG.QueryToPGByName(acc[0].Id.ToString()) as List<T_jihefenxi_account>;
- //不存在也当没执行过算法,加入执行列表
- if (jhacc.Count == 0)
- {
- Store.newGeofiles.Add(file);
- ColorClass.Console_AddColor("新增数据:" + file);
- }
- }
- }
- }
- catch (Exception ex)
- {
- ColorClass.Console_EorrColor(ex.Message);
- throw;
- }
- }
- /// <summary>
- /// 检查bny
- /// </summary>
- public static void CheckedBny()
- {
- try
- {
- //1.检查T_file_account表
- foreach (string file in Store.bnyList)
- {
- List<T_file_account> acc = DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(file)) as List<T_file_account>;
- if (acc.Count == 0)
- {
- Store.newBnyfiles.Add(file);
- ColorClass.Console_AddColor("新增数据:" + file);
- }
- else
- {
- //2.若之前执行过文件,则再检查T_lunguili_account表内数据是否存在
- List<T_lunguili_account> jhacc = DataAnalysisToPG.QueryToPGByNameL(acc[0].Id.ToString()) as List<T_lunguili_account>;
- if (jhacc.Count == 0)
- {
- Store.newBnyfiles.Add(file);
- ColorClass.Console_AddColor("新增数据:" + file);
- }
- }
- }
- }
- catch (Exception ex)
- {
- ColorClass.Console_EorrColor(ex.Message);
- throw;
- }
- }
- /// <summary>
- /// 往数据库T_file_account表新插入的数据
- /// </summary>
- /// <param name="file"></param>
- public static void saveTfileName(List<string> file,string str)
- {
- if (file.Count != 0)
- {
- try
- {
- List<T_file_account> filelist = new List<T_file_account>();
- for (int i = 0; i < file.Count; i++)
- {
- T_file_account tfa = new T_file_account();
- if (Path.GetExtension(file[i]).ToLower() == ".geo")
- {
- tfa = JXSJ.FileNameSplit(file[i]);
- }
- else if (Path.GetExtension(file[i]).ToLower() == ".bny")
- {
- tfa = JXSJ.FileNameSplit1(file[i]);
- }
- filelist.Add(tfa);
- }
- DataAnalysisToPG.InsertToPG(filelist);
- ColorClass.Console_AddColor("文件入库成功");
- }
- catch (Exception ex)
- {
- ColorClass.Console_EorrColor("文件入库失败:" + ex.Message);
- throw;
- }
- }
- else
- {
- ColorClass.Console_AddColor(str + "没有新增文件");
- }
- }
- /// <summary>
- /// 记录T_file_account表新插入的数据
- /// </summary>
- public static void RecordNewData()
- {
- for (int i = 0; i < Store.newGeofiles.Count; i++)
- {
- Store.GeofileAccount.Add((DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(Store.newGeofiles[i])) as List<T_file_account>)[0]);
- }
- for (int i = 0; i < Store.newBnyfiles.Count; i++)
- {
- Store.BnyfileAccount.Add((DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(Store.newBnyfiles[i])) as List<T_file_account>)[0]);
- }
- }
- }
- public class JXSJ
- {
- /// <summary>
- /// 解析几何分析数据
- /// </summary>
- /// <param name="filename"></param>
- /// <returns></returns>
- public static T_file_account FileNameSplit(string filename)
- {
- string ysname = Path.GetFileName(filename);
- var filearr = ysname.Split('-');
- string[] xlbh = HBXLSplit(filearr[0]);
- string jcsj = getYMDHMS(filearr[3], filearr[4]);
- string FX = getZF(filearr[5]);//0反向、1正向
- string wjdx = Math.Ceiling(new FileInfo(filename).Length / 1024.0 / 1024.0) + " MB";
- T_luxianming_sf xlpg = DataAnalysisToPG.QueryToXlm(xlbh[0]) as T_luxianming_sf;
- return new T_file_account()
- {
- Xlm = xlpg.Xlm,
- Xlbh = xlpg.Xldj,
- Hangbie = xlbh[1],
- Jcsj = jcsj,
- Daxiao = wjdx,
- Yswjm = ysname,
- Houzhui = Path.GetExtension(filename).Remove(0, 1),
- Fangxiang = FX,
- Wjzt = "正常",
- Srlj = filename,
- Rwzt = "算法未执行",
- Jccxx = "轨检车"
- };
- }
- /// <summary>
- /// 解析轮轨力数据
- /// </summary>
- /// <param name="filename"></param>
- /// <returns></returns>
- public static T_file_account FileNameSplit1(string filename)
- {
- string ysname = Path.GetFileName(filename);
- var filearr = ysname.Split('_');
- string[] xlbh = HBXLSplit(filearr[2].Split('.')[0]);
- string jcsj = getYMDHMS(filearr[1]);
- string FX = getZF(filearr[2]);//0反向、1正向
- string wjdx = Math.Ceiling(new FileInfo(filename).Length / 1024.0 / 1024.0) + " MB";
- T_luxianming_sf xlpg = DataAnalysisToPG.QueryToXlm(xlbh[0]) as T_luxianming_sf;
- return new T_file_account()
- {
- Xlm = xlpg.Xlm,
- Xlbh = xlpg.Xldj,
- Hangbie = xlbh[1],
- Jcsj = jcsj,
- Daxiao = wjdx,
- Yswjm = ysname,
- Fangxiang = FX,
- Houzhui = Path.GetExtension(filename).Remove(0, 1),
- Wjzt = "正常",
- Srlj = filename,
- Jccxx = "轨检车",
- Rwzt = "算法未执行"
- };
- }
- /// <summary>
- /// 解析方向
- /// </summary>
- public static string getZF(string ZF)
- {
- string zf = ZF.Split('_')[0];
- if (zf == "0")
- {
- return "反向";
- }
- else
- {
- return "正向";
- }
- }
- /// <summary>
- /// 解析时间
- /// </summary>
- public static string getYMDHMS(string ymd, string hms)
- {
- //如果这里以后修改,轮轨力输入检测日期那块也要改!!!
- Char[] ymdcha = ymd.ToCharArray();//年月日
- Char[] hmscha = hms.ToCharArray();//时分秒
- string year = ymdcha[4].ToString() + ymdcha[5].ToString() + ymdcha[6].ToString() + ymdcha[7].ToString();
- string mouth = ymdcha[2].ToString() + ymdcha[3].ToString();
- string day = ymdcha[0].ToString() + ymdcha[1].ToString();
- string hour = hmscha[0].ToString() + hmscha[1].ToString();
- string minite = hmscha[2].ToString() + hmscha[3].ToString();
- string second = hmscha[4].ToString() + hmscha[5].ToString();
- return year + "年" + mouth + "月" + day + "日" + hour + "时" + minite + "分" + second + "秒";
- }
- public static string getYMDHMS(string ymd)
- {
- //如果这里以后修改,轮轨力输入检测日期那块也要改!!!
- Char[] ymdcha = ymd.ToCharArray();//年月日
- string year = ymdcha[0].ToString() + ymdcha[3].ToString();
- string mouth = ymdcha[6].ToString() + ymdcha[7].ToString();
- string day = ymdcha[4].ToString() + ymdcha[5].ToString();
- return year + "年" + mouth + "月" + day + "日";
- }
- /// <summary>
- /// 解析行别和线路编号
- /// </summary>
- public static string[] HBXLSplit(string arr0)
- {
- Char[] cha = arr0.ToCharArray();
- string hb = "", xl = "";
- for (int i = 0; i < cha.Length; i++)
- {
- if (i != cha.Length - 1)
- {
- xl += cha[i];
- }
- else
- {
- if (cha[i] == 'X')
- {
- hb = "下";
- }
- else if (cha[i] == 'S')
- {
- hb = "上";
- }
- else
- {
- hb = "未知";
- }
- }
- }
- return new string[] { xl, hb };
- }
- }
- }
|