using System; using System.Collections.Generic; using Uninpho.DBOperation.Model; using Uninpho.DBOperation.Operation; using System.IO; namespace ZDHscript { /// /// 检查数据库 /// class CheckedDB { /// /// CheckedDataBase主函数 /// public static void DBCheckedFun() { // 1.检查 CheckedGeo(); CheckedBny(); // 2.往t_file_account新增数据 Add2fileAccount(); // 3.并记录到Store中 RecordNewData(); } /// /// 往t_file_account新增数据 /// 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,"轮轨力分析"); } /// /// 检查geo /// public static void CheckedGeo() { try { //1.检查T_file_account表 foreach (string file in Store.geoList) { List acc = DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(file)) as List; if (acc.Count == 0) { Store.newGeofiles.Add(file); ColorClass.Console_AddColor("新增数据:" + file); } else { //2.若之前执行过文件,则再检查T_jihefenxi_account表内数据是否存在 List jhacc = DataAnalysisToPG.QueryToPGByName(acc[0].Id.ToString()) as List; //不存在也当没执行过算法,加入执行列表 if (jhacc.Count == 0) { Store.newGeofiles.Add(file); ColorClass.Console_AddColor("新增数据:" + file); } } } } catch (Exception ex) { ColorClass.Console_EorrColor(ex.Message); throw; } } /// /// 检查bny /// public static void CheckedBny() { try { //1.检查T_file_account表 foreach (string file in Store.bnyList) { List acc = DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(file)) as List; if (acc.Count == 0) { Store.newBnyfiles.Add(file); ColorClass.Console_AddColor("新增数据:" + file); } else { //2.若之前执行过文件,则再检查T_lunguili_account表内数据是否存在 List jhacc = DataAnalysisToPG.QueryToPGByNameL(acc[0].Id.ToString()) as List; if (jhacc.Count == 0) { Store.newBnyfiles.Add(file); ColorClass.Console_AddColor("新增数据:" + file); } } } } catch (Exception ex) { ColorClass.Console_EorrColor(ex.Message); throw; } } /// /// 往数据库T_file_account表新插入的数据 /// /// public static void saveTfileName(List file,string str) { if (file.Count != 0) { try { List filelist = new List(); 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 + "没有新增文件"); } } /// /// 记录T_file_account表新插入的数据 /// 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)[0]); } for (int i = 0; i < Store.newBnyfiles.Count; i++) { Store.BnyfileAccount.Add((DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(Store.newBnyfiles[i])) as List)[0]); } } } public class JXSJ { /// /// 解析几何分析数据 /// /// /// 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 = "轨检车" }; } /// /// 解析轮轨力数据 /// /// /// 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 = "算法未执行" }; } /// /// 解析方向 /// public static string getZF(string ZF) { string zf = ZF.Split('_')[0]; if (zf == "0") { return "反向"; } else { return "正向"; } } /// /// 解析时间 /// 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 + "日"; } /// /// 解析行别和线路编号 /// 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 }; } } }