DataAnalysisToPG.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using SqlSugar;
  7. using Uninpho.DBOperation.Model;
  8. using System.IO;
  9. using Npgsql;
  10. using System.Data;
  11. namespace Uninpho.DBOperation.Operation
  12. {
  13. class mm
  14. {
  15. public int Max { get; set; }
  16. }
  17. public class DataAnalysisToPG
  18. {
  19. static SqlSugarClient db = Config.GetPgClient();
  20. public static void Test()
  21. {
  22. var list1 = db.SqlQueryable<T_daocha_account>("select * from \"t_daocha_account\"").ToList();
  23. var list2 = db.SqlQueryable<T_guanjie_account>("select * from \"t_guanjie_account\"").ToList();
  24. var list3 = db.SqlQueryable<T_quxian_account>("select * from \"t_quxian_account\"").ToList();
  25. var list4 = db.SqlQueryable<T_lunguili_account>("select * from \"t_lunguili_account\"").ToList();
  26. var list5 = db.SqlQueryable<T_jihefenxi_account>("select * from \"t_jihefenxi_account\"").ToList();
  27. var list6 = db.SqlQueryable<T_file_account>("select * from \"t_file_account\"").ToList();
  28. }
  29. /// <summary>
  30. /// 读取数据并展示
  31. /// </summary>
  32. public static Object getfile(string cxtj,List<int> suanfarunid,List<string> suanfazt)
  33. {
  34. var obj = db.SqlQueryable<T_file_account>("select * from \"t_file_account\"").Where(it => it.Houzhui == cxtj).ToList();
  35. for (int i = 0; i < obj.Count; i++)
  36. {
  37. if (!File.Exists(obj[i].Srlj))
  38. {
  39. obj[i].Wjzt = "文件未找到";
  40. }
  41. for (int j = 0; j < suanfarunid.Count; j++)
  42. {
  43. if (suanfarunid[j] == obj[i].Id)
  44. {
  45. obj[i].Rwzt = suanfazt[j];
  46. }
  47. }
  48. }
  49. return obj;
  50. }
  51. /// <summary>
  52. /// 读取数据并展示
  53. /// </summary>
  54. public static Object getDwfile(string cxtj, List<int> suanfarunid, List<string> suanfazt)
  55. {
  56. var obj = db.SqlQueryable<T_dwfile_account>("select * from \"t_dwfile_account\"").ToList();
  57. for (int i = 0; i < obj.Count; i++)
  58. {
  59. if (!File.Exists(obj[i].Srlj))
  60. {
  61. obj[i].FileStatus = "文件未找到";
  62. }
  63. ///for (int j = 0; j < suanfarunid.Count; j++)
  64. ///{
  65. /// if (suanfarunid[j] == obj[i].Id)
  66. /// {
  67. /// obj[i].TaskStatus = suanfazt[j];
  68. /// }
  69. ///}
  70. }
  71. return obj;
  72. }
  73. /// <summary>
  74. /// 自动化读取数据
  75. /// </summary>
  76. public static Object getfile(string cxtj)
  77. {
  78. var obj = db.SqlQueryable<T_file_account>("select * from \"t_file_account\"").Where(it => it.Houzhui == cxtj).ToList();
  79. return obj;
  80. }
  81. /// <summary>
  82. /// 更新任务状态
  83. /// </summary>
  84. public static void updataRWZT(string[] Yswjm)
  85. {
  86. NpgsqlConnection conn = new NpgsqlConnection();
  87. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  88. NpgsqlCommand comm = new NpgsqlCommand();
  89. comm.Connection = conn;
  90. conn.Open();
  91. comm.CommandText = "UPDATE \"t_file_account\" SET rwzt = '" + Yswjm[1] + "' WHERE id =" + Yswjm[0];
  92. //comm.CommandText = @"SELECT* FROM " + tablename + " where " + querystring;
  93. comm.ExecuteNonQuery();
  94. conn.Close();
  95. }
  96. /// <summary>
  97. /// 读取密贴离缝数据并展示
  98. /// </summary>
  99. public static List<T_mitielifeng_filelist> getfilemtlf()
  100. {
  101. var obj = db.SqlQueryable<T_mitielifeng_filelist>("select * from \"t_mitielifeng_filelist\"").ToList();
  102. return obj;
  103. }
  104. /// <summary>
  105. /// 读取逐枕几何数据并展示
  106. /// </summary>
  107. public static List<T_zhuzhenjihe_filelist> getfilezzjh()
  108. {
  109. var obj = db.SqlQueryable<T_zhuzhenjihe_filelist>("select * from \"t_zhuzhenjihe_filelist\"").ToList();
  110. return obj;
  111. }
  112. /// <summary>
  113. /// 读取线形线位list数据并展示
  114. /// </summary>
  115. public static List<T_xxxw_csvlist> getfilexxxwL()
  116. {
  117. var obj = db.SqlQueryable<T_xxxw_csvlist>("select * from \"t_xxxw_csvlist\"").ToList();
  118. return obj;
  119. }
  120. /// <summary>
  121. /// 读取线形线位数据并展示
  122. /// </summary>
  123. public static List<T_xxxw_csvdata> getfilexxxwD(string uuid)
  124. {
  125. var obj = db.SqlQueryable<T_xxxw_csvdata>("select * from \"t_xxxw_csvdata\" where listid = '" +uuid+"' ORDER BY cld ASC").ToList();
  126. return obj;
  127. }
  128. //**************************************增********************************************
  129. /// <summary>
  130. /// 更新最大id
  131. /// </summary>
  132. public static void InsertGetIdMAX(T_jihefenxi_boxing updateObjs)
  133. {
  134. db.Insertable(updateObjs).ExecuteCommand();
  135. }
  136. public static void InsertGetIdMAX(T_lunguili_boxing updateObjs)
  137. {
  138. db.Insertable(updateObjs).ExecuteCommand();
  139. }
  140. /// <summary>
  141. /// 插入csvdata信息数据表
  142. /// </summary>
  143. /// <param name="listqx"></param>
  144. public static void Insertdata_CsvData(List<T_xxxw_csvdata> listqx)
  145. {
  146. db.Insertable<T_xxxw_csvdata>(listqx).ExecuteCommand();//get change row count
  147. }
  148. /// <summary>
  149. /// 插入csvlist信息数据表
  150. /// </summary>
  151. /// <param name="listqx"></param>
  152. public static string Insertdata_CsvList(T_xxxw_csvlist updateObjs)
  153. {
  154. db.Insertable(updateObjs).ExecuteCommand();//get change row count
  155. return db.Queryable<T_xxxw_csvlist>().Where(it => it.Jiancharen == updateObjs.Jiancharen && it.Jianchariqi == updateObjs.Jianchariqi).Single().Id;
  156. }
  157. /// <summary>
  158. /// 插入功率信息数据表
  159. /// </summary>
  160. /// <param name="listqx"></param>
  161. public static void Insert_gl_data_CsvData(List<T_gonglv_account> gonglvCsvdata)
  162. {
  163. // db.Insertable(gonglvCsvdata).ExecuteCommand();
  164. db.Insertable<T_gonglv_account>(gonglvCsvdata).ExecuteCommand();//get change row count
  165. }
  166. /// <summary>
  167. /// 插入功率信息数据表
  168. /// </summary>
  169. /// <param name="listqx"></param>
  170. public static string Insertdata_gl_CsvList(T_gonglv_account gonglvCsvdata)
  171. {
  172. db.Insertable(gonglvCsvdata).ExecuteCommand();//get change row count
  173. return db.Queryable<T_gonglv_account>().Where(it => it.Chezhan == gonglvCsvdata.Chezhan).Single().Id;
  174. }
  175. /// <summary>
  176. /// T_file_account表添加新数据
  177. /// </summary>
  178. public static void InsertToPG(List<T_file_account> updateObjs)
  179. {
  180. db.Insertable(updateObjs).ExecuteCommand();
  181. }
  182. /// <summary>
  183. /// 密贴离缝表添加新数据
  184. /// </summary>
  185. public static string InsertMTLFListDataToPG(T_mitielifeng_filelist updateObjs)
  186. {
  187. db.Insertable(updateObjs).ExecuteCommand();
  188. return db.Queryable<T_mitielifeng_filelist>().Where(it => it.Remark == updateObjs.Remark && it.Excelbytearr == updateObjs.Excelbytearr).Single().Id;
  189. }
  190. /// <summary>
  191. /// 密贴离缝excel表添加新数据
  192. /// </summary>
  193. public static void InsertMTLFExcelDataToPG(T_mitielifeng_exceldata updateObjs)
  194. {
  195. db.Insertable(updateObjs).ExecuteCommand();
  196. }
  197. /// <summary>
  198. /// 逐枕几何表添加新数据
  199. /// </summary>
  200. public static string InsertZZJHListDataToPG(T_zhuzhenjihe_filelist updateObjs)
  201. {
  202. db.Insertable(updateObjs).ExecuteCommand();
  203. return db.Queryable<T_zhuzhenjihe_filelist>().Where(it => it.Remark == updateObjs.Remark && it.Excelbytearr == updateObjs.Excelbytearr).Single().Id;
  204. }
  205. /// <summary>
  206. /// 逐枕几何excel表添加新数据
  207. /// </summary>
  208. public static void InsertZZJHExcelDataToPG(List<T_zhuzhenjihe_exceldata> updateObjs)
  209. {
  210. db.Insertable(updateObjs).ExecuteCommand();
  211. }
  212. /// <summary>
  213. /// 道岔几何表添加新数据
  214. /// </summary>
  215. public static void InsertJHDataToPG(List<T_jihefenxi_account> updateObjs)
  216. {
  217. db.Insertable(updateObjs).ExecuteCommand();
  218. }
  219. /// <summary>
  220. /// 轮轨力表添加新数据
  221. /// </summary>
  222. public static void InsertLGLDataToPG(List<T_lunguili_account> updateObjs)
  223. {
  224. db.Insertable(updateObjs).ExecuteCommand();
  225. }
  226. /// <summary>
  227. /// 道岔几何波形表添加新数据
  228. /// </summary>
  229. public static void InsertJHBXDataToPG(List<T_jihefenxi_boxing> updateObjs)
  230. {
  231. db.Insertable(updateObjs).ExecuteCommand();
  232. }
  233. /// <summary>
  234. /// 轮轨力波形表添加新数据
  235. /// </summary>
  236. public static void InsertLGLBXDataToPG(List<T_lunguili_boxing> updateObjs)
  237. {
  238. db.Insertable(updateObjs).ExecuteCommand();
  239. }
  240. //**************************************改********************************************
  241. public static void UpdataToPG(T_file_account item)
  242. {
  243. db.Updateable<T_file_account>(it => new T_file_account() { Jccxx = item.Jccxx }).Where(it => it.Id == item.Id).ExecuteCommand();
  244. }
  245. /// <summary>
  246. /// 更新线形线位数据表
  247. /// </summary>
  248. public static void UpdataToPGXXXWD(string name ,string value,string uuid)
  249. {
  250. //db.Updateable<T_xxxw_csvdata>(it => new T_xxxw_csvdata() { }).Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  251. NpgsqlConnection conn = new NpgsqlConnection();
  252. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  253. NpgsqlCommand comm = new NpgsqlCommand();
  254. comm.Connection = conn;
  255. conn.Open();
  256. comm.CommandText = "UPDATE \"t_xxxw_csvdata\" SET " + name + " = '" + value + "' WHERE id ='" + uuid + "'";
  257. //comm.CommandText = @"SELECT* FROM " + tablename + " where " + querystring;
  258. comm.ExecuteNonQuery();
  259. conn.Close();
  260. }
  261. /// <summary>
  262. /// 更新线形线位list表
  263. /// </summary>
  264. public static void UpdataToPGXXXWL(string name, string value, string uuid)
  265. {
  266. db.Updateable<T_xxxw_csvlist>(it => new T_xxxw_csvlist() { Gengxinren = name,Gengxinriqi=value }).Where(it => it.Id.ToString() == uuid).ExecuteCommand();
  267. }
  268. public static void UpdataToPGMTLF(T_mitielifeng_filelist item)
  269. {
  270. db.Updateable<T_mitielifeng_filelist>(item).Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  271. //db.Updateable<T_mitielifeng_filelist>(it => new T_mitielifeng_filelist() { Gengxinriqi = item.Gengxinriqi, Gengxinren = item.Gengxinren, Excelbytearr = item.Excelbytearr }).Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  272. }
  273. public static void UpdataToPGZZJH(T_zhuzhenjihe_filelist item)
  274. {
  275. db.Updateable<T_zhuzhenjihe_filelist>(item).Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  276. //db.Updateable<T_zhuzhenjihe_filelist>(it => new T_zhuzhenjihe_filelist() { Gengxinriqi = item.Gengxinriqi, Gengxinren = item.Gengxinren, Excelbytearr = item.Excelbytearr }).Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  277. }
  278. /// <summary>
  279. /// 道岔几何表更新微小算法执行结果
  280. /// </summary>
  281. public static void UpdataJHDataToPG(List<T_jihefenxi_account> updateObjs)
  282. {
  283. for (int i = 0; i < updateObjs.Count; i++)
  284. {
  285. //使用 线路名、行别、尖轨尖里程、检测车、日期 5个条件进行匹配更新数据
  286. db.Updateable<T_jihefenxi_account>(it => new T_jihefenxi_account()
  287. {
  288. Wx_check = updateObjs[i].Wx_check,
  289. Wx_bhl_gd = updateObjs[i].Wx_bhl_gd,
  290. Wx_bhl_gj = updateObjs[i].Wx_bhl_gj,
  291. Wx_bhl_sp = updateObjs[i].Wx_bhl_sp,
  292. Wx_bhl_gx = updateObjs[i].Wx_bhl_gx,
  293. Wx_bhl_sjk = updateObjs[i].Wx_bhl_sjk,
  294. Wx_isload = 1,
  295. }).Where(it => it.Xlm == updateObjs[i].Xlm && it.Xingbie == updateObjs[i].Xingbie && it.Jgjlc == updateObjs[i].Jgjlc && it.Jcc == updateObjs[i].Jcc && it.Riqi == updateObjs[i].Riqi).ExecuteCommand();
  296. }
  297. }
  298. /// <summary>
  299. /// 道岔几何波形表更新微小算法执行结果
  300. /// </summary>
  301. public static void UpdataJHBXDataToPG(List<T_jihefenxi_boxing> updateObjs)
  302. {
  303. db.Updateable<T_jihefenxi_boxing>(updateObjs).ExecuteCommand();
  304. }
  305. //**************************************删********************************************
  306. /// <summary>
  307. /// 删除数据 account、boxing两个表
  308. /// type:"轮轨力"、"几何"、"微小"
  309. /// </summary>type
  310. public static void DelUpdataData(string yswjm,string type)
  311. {
  312. T_file_account file = db.SqlQueryable<T_file_account>("select * from \"t_file_account\" where id = " + yswjm).ToList()[0];
  313. //updataRWZT(new string[] { yswjm, "算法未执行" });
  314. if (type == "轮轨力")
  315. {
  316. List<T_lunguili_account> whichupdata = (List<T_lunguili_account>)QueryToPGByNameL(yswjm);
  317. DelToPGLGLBX(whichupdata);
  318. DelToPGLGL(file);
  319. }
  320. else if(type == "几何")
  321. {
  322. List<T_jihefenxi_account> whichupdata = (List<T_jihefenxi_account>)QueryToPGByName(yswjm);
  323. DelToPGJHBX(whichupdata);
  324. DelToPGJH(file);
  325. }
  326. }
  327. /// <summary>
  328. /// 删除数据 by ID
  329. /// </summary>
  330. public static void DelToPGXXXW(string Id)
  331. {
  332. db.Deleteable<T_xxxw_csvlist>().Where(it => it.Id.ToString() == Id).ExecuteCommand();
  333. db.Deleteable<T_xxxw_csvdata>().Where(it => it.Listid == Id).ExecuteCommand();
  334. }
  335. /// <summary>
  336. /// 删除数据 by ID
  337. /// </summary>
  338. public static void DelToPGXXXWD(string Id)
  339. {
  340. db.Deleteable<T_xxxw_csvdata>().Where(it => it.Id.ToString() == Id).ExecuteCommand();
  341. }
  342. /// <summary>
  343. /// 删除数据 by ID
  344. /// </summary>
  345. public static void DelToPGMTLF(T_mitielifeng_filelist item)
  346. {
  347. db.Deleteable<T_mitielifeng_filelist>().Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  348. db.Deleteable<T_mitielifeng_exceldata>().Where(it => it.Filelistid == item.Id).ExecuteCommand();
  349. }
  350. /// <summary>
  351. /// 删除数据 by ID
  352. /// </summary>
  353. public static void DelToPGZZJH(T_zhuzhenjihe_filelist item)
  354. {
  355. db.Deleteable<T_zhuzhenjihe_filelist>().Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  356. db.Deleteable<T_zhuzhenjihe_exceldata>().Where(it => it.Filelistid == item.Id).ExecuteCommand();
  357. }
  358. /// <summary>
  359. /// 删除数据 by ID
  360. /// </summary>
  361. public static void DelToPG(T_file_account item)
  362. {
  363. db.Deleteable<T_file_account>().Where(it => it.Id == item.Id).ExecuteCommand();
  364. }
  365. /// <summary>
  366. /// 删除数据 by Yswjm
  367. /// </summary>
  368. public static void DelToPG1(T_file_account item)
  369. {
  370. Console.WriteLine(item.Yswjm);
  371. db.Deleteable<T_file_account>().Where(it => it.Yswjm == item.Yswjm).ExecuteCommand();
  372. }
  373. /// <summary>
  374. /// 删除几何account表数据
  375. /// </summary>
  376. public static void DelToPGJH(T_file_account updateObjs)
  377. {
  378. db.Deleteable<T_jihefenxi_account>().Where(it => it.Filename_jh == updateObjs.Id.ToString()).ExecuteCommand();
  379. }
  380. /// <summary>
  381. /// 删除几何波形表数据
  382. /// </summary>
  383. public static void DelToPGJHBX(List<T_jihefenxi_account> updateObjs)
  384. {
  385. NpgsqlConnection conn = new NpgsqlConnection();
  386. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  387. NpgsqlCommand comm = new NpgsqlCommand();
  388. comm.Connection = conn;
  389. conn.Open();
  390. foreach (var item in updateObjs)
  391. {
  392. string[] dd = item.Yswjm_jhfx.Split(',');
  393. comm.CommandText = "DELETE FROM public.t_jihefenxi_boxing where id >= " + dd[0] + " and id <= " + dd[1];
  394. comm.ExecuteNonQuery();
  395. }
  396. conn.Close();
  397. }
  398. /// <summary>
  399. /// 删除轮轨力account表数据
  400. /// </summary>
  401. public static void DelToPGLGL(T_file_account updateObjs)
  402. {
  403. db.Deleteable<T_lunguili_account>().Where(it => it.Filename_lgl == updateObjs.Id.ToString()).ExecuteCommand();
  404. }
  405. /// <summary>
  406. /// 删除轮轨力波形表数据
  407. /// </summary>
  408. public static void DelToPGLGLBX(List<T_lunguili_account> updateObjs)
  409. {
  410. NpgsqlConnection conn = new NpgsqlConnection();
  411. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  412. NpgsqlCommand comm = new NpgsqlCommand();
  413. comm.Connection = conn;
  414. conn.Open();
  415. foreach (var item in updateObjs)
  416. {
  417. string[] dd = item.Yswjm.Split(',');
  418. comm.CommandText = "DELETE FROM public.t_lunguili_boxing where id >= " + dd[0] + " and id <= " + dd[1];
  419. comm.ExecuteNonQuery();
  420. }
  421. conn.Close();
  422. }
  423. /// <summary>
  424. /// 删除查询ID暂时添加的波形条数
  425. /// </summary>
  426. public static void InitBXID()
  427. {
  428. db.Deleteable<T_lunguili_boxing>().Where(it => it.Yswjm == "?????").ExecuteCommand();
  429. db.Deleteable<T_jihefenxi_boxing>().Where(it => it.Yswjm == "?????").ExecuteCommand();
  430. db.Insertable<T_lunguili_boxing>(new T_lunguili_boxing() {Yswjm = "?????" }).ExecuteCommand();
  431. db.Insertable<T_jihefenxi_boxing>(new T_jihefenxi_boxing() { Yswjm = "?????" }).ExecuteCommand();
  432. }
  433. /// <summary>
  434. /// 数据展示删除
  435. /// </summary>
  436. /// <param name="item"></param>
  437. /// <param name="itemjh"></param>
  438. public static void DelSJZS(string item,string itemjh,string xlm,string hangbie,string jgjlc)
  439. {
  440. NpgsqlConnection conn = new NpgsqlConnection();
  441. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  442. NpgsqlCommand comm = new NpgsqlCommand();
  443. comm.Connection = conn;
  444. conn.Open();
  445. if (item != "")
  446. {
  447. string[] dd = item.Split(',');
  448. comm.CommandText = "DELETE FROM public.t_lunguili_boxing where id >= " + dd[0] + " and id <= " + dd[1];
  449. comm.ExecuteNonQuery();
  450. comm.CommandText = "DELETE FROM public.t_lunguili_account where xlm = '" + xlm + "' and xingbie = '" + hangbie + "' and jgjlc = '" + jgjlc + "'";
  451. comm.ExecuteNonQuery();
  452. }
  453. if (itemjh != "")
  454. {
  455. string[] ddd = itemjh.Split(',');
  456. comm.CommandText = "DELETE FROM public.t_jihefenxi_boxing where id >= " + ddd[0] + " and id <= " + ddd[1];
  457. comm.ExecuteNonQuery();
  458. comm.CommandText = "DELETE FROM public.t_jihefenxi_account where xlm = '" + xlm + "' and xingbie = '" + hangbie + "' and jgjlc = '" + jgjlc + "'";
  459. comm.ExecuteNonQuery();
  460. }
  461. conn.Close();
  462. }
  463. //**************************************查********************************************
  464. /// <summary>
  465. /// 按Id查询
  466. /// </summary>
  467. public static Object QueryToPGById(int id_)
  468. {
  469. return db.Queryable<T_file_account>().Where(it => it.Id == id_).Single();
  470. }
  471. /// <summary>
  472. /// 按文件名查询文件
  473. /// </summary>
  474. public static Object QueryToPGByNameFile(string yswjm)
  475. {
  476. return db.Queryable<T_file_account>().Where(it => it.Yswjm == yswjm).ToList();
  477. }
  478. /// <summary>
  479. /// 微笑算法筛选Sudu >= 100 && Zcx != "侧向"的数据
  480. /// </summary>
  481. public static Object QueryToPGByNameWXSF(string id)
  482. {
  483. return db.Queryable<T_jihefenxi_account>().Where(it => it.Filename_jh == id && (it.Sudu_jhfx >= 100 && it.Zcx != "侧向" && it.Wx_isload == 0)).ToList();
  484. }
  485. /// <summary>
  486. /// 查可执行微小算法的数据
  487. /// </summary>
  488. public static Object QueryToPGByNameWXSFZD()
  489. {
  490. return db.Queryable<T_jihefenxi_account>().Where(it => it.Sudu_jhfx >= 100 && it.Zcx != "侧向" && it.Wx_isload == 0).ToList();
  491. }
  492. /// <summary>
  493. /// 查数据(条件:线路名、行别、尖轨尖里程、未执行微小算法wx_isload = 1)
  494. /// </summary>
  495. public static List<List<T_jihefenxi_account>> QueryToPGByNameWXSFZDReference(List<T_jihefenxi_account> newdata)
  496. {
  497. List<List<T_jihefenxi_account>> ReferenceList = new List<List<T_jihefenxi_account>>();
  498. for (int i = 0; i < newdata.Count; i++)
  499. {
  500. var aa = (db.Queryable<T_jihefenxi_account>().Where(it => it.Xlm == newdata[i].Xlm && it.Xingbie == newdata[i].Xingbie && it.Jgjlc == newdata[i].Jgjlc && it.Wx_isload == 1).ToList()) as List<T_jihefenxi_account>;
  501. if (aa.Count != 0)
  502. {
  503. ReferenceList.Add(aa);
  504. }
  505. }
  506. return ReferenceList;
  507. }
  508. /// <summary>
  509. /// 按文件名查询JH
  510. /// </summary>
  511. public static Object QueryToPGByName(string id)
  512. {
  513. return db.Queryable<T_jihefenxi_account>().Where(it => it.Filename_jh == id).ToList();
  514. }
  515. /// <summary>
  516. /// 按文件名查询LGL
  517. /// </summary>
  518. public static Object QueryToPGByNameL(string yswjm)
  519. {
  520. return db.Queryable<T_lunguili_account>().Where(it => it.Filename_lgl == yswjm).ToList();
  521. }
  522. /// <summary>
  523. /// 查询几何提取算法线路里程值
  524. /// </summary>
  525. /// <param name="xllc_">线路里程名称</param>
  526. /// <returns></returns>
  527. public static Object QueryToString(string xllc_)
  528. {
  529. return db.Queryable<T_xianlulicheng_sf>().Where(it => it.Xllc == xllc_).Single();
  530. }
  531. /// <summary>
  532. /// 查询线路名
  533. /// </summary>
  534. /// <param name="xllc_">简称</param>
  535. /// <returns></returns>
  536. public static Object QueryToXlm(string xlmjx)
  537. {
  538. return db.Queryable<T_luxianming_sf>().Where(it => it.Xlmsx == xlmjx).First();
  539. }
  540. /// <summary>
  541. /// 查询最大id
  542. /// </summary>
  543. /// <param name="tablename"></param>
  544. /// <returns></returns>
  545. public static int QueryMaxID(string tablename)
  546. {
  547. var list1 = new mm();
  548. if (tablename == "lgl")
  549. {
  550. list1 = db.SqlQueryable<mm>("select MAX(ID) from \"t_lunguili_boxing\"").Single();
  551. }
  552. else
  553. {
  554. list1 = db.SqlQueryable<mm>("select MAX(ID) from \"t_jihefenxi_boxing\"").Single();
  555. }
  556. return list1.Max;
  557. }
  558. /// <summary>
  559. /// 查询道岔台账全部信息
  560. /// </summary>
  561. public static List<T_daocha_account> QueryDCTZALL()
  562. {
  563. return db.Queryable<T_daocha_account>().ToList();
  564. }
  565. /// <summary>
  566. /// 查询道岔台账信息
  567. /// </summary>
  568. public static Object QueryDCTZ(string xlm,Char[] hangbie)
  569. {
  570. if (hangbie[hangbie.Length-1] == 'S')
  571. {
  572. return db.Queryable<T_daocha_account>().Where(it => it.Xlm == xlm && it.Xingbie == "上"||it.Xingbie == "上行").ToList();
  573. }
  574. else
  575. {
  576. return db.Queryable<T_daocha_account>().Where(it => it.Xlm == xlm && it.Xingbie == "下" || it.Xingbie == "下行").ToList();
  577. }
  578. }
  579. /// <summary>
  580. /// 查询管界台账信息
  581. /// </summary>
  582. public static Object QueryGJTZ(string xlm, Char[] hangbie)
  583. {
  584. if (hangbie[hangbie.Length - 1] == 'S')
  585. {
  586. return db.Queryable<T_guanjie_account>().Where(it => it.Xianming == xlm && it.Hangbie == "上" || it.Hangbie == "上行").ToList();
  587. }
  588. else
  589. {
  590. return db.Queryable<T_guanjie_account>().Where(it => it.Xianming == xlm && it.Hangbie == "下" || it.Hangbie == "下行").ToList();
  591. }
  592. }
  593. /// <summary>
  594. /// 查询曲线台账信息
  595. /// </summary>
  596. public static Object QueryQXTZ(string xlm, Char[] hangbie)
  597. {
  598. if (hangbie[hangbie.Length - 1] == 'S')
  599. {
  600. return db.Queryable<T_quxian_account>().Where(it => it.Xianming == xlm && it.Hangbie == "上" || it.Hangbie == "上行").ToList();
  601. }
  602. else
  603. {
  604. return db.Queryable<T_quxian_account>().Where(it => it.Xianming == xlm && it.Hangbie == "下" || it.Hangbie == "下行").ToList();
  605. }
  606. }
  607. //*********************************************************************************************************
  608. /// <summary>
  609. /// 插入尖轨尖心轨间距表
  610. /// </summary>
  611. public static void InsertJGJXGJJ(T_jgjdistance_table updateObjs)
  612. {
  613. db.Insertable(updateObjs).ExecuteCommand();
  614. }
  615. /// <summary>
  616. /// 查询尖轨尖心轨间距表
  617. /// </summary>
  618. public static List<T_jgjdistance_table> QueryJGJXGJJ()
  619. {
  620. return db.Queryable<T_jgjdistance_table>().ToList();
  621. }
  622. /// <summary>
  623. /// 删除数据 by ID
  624. /// </summary>
  625. public static void DelJGJXGJJ(string Id)
  626. {
  627. db.Deleteable<T_jgjdistance_table>().Where(it => it.Id.ToString() == Id).ExecuteCommand();
  628. }
  629. /// <summary>
  630. /// 更新数据
  631. /// </summary>
  632. /// <param name="uuid">更新的ID</param>
  633. /// <param name="issave">更新类型 true 仅为了逻辑 false 真是更新</param>
  634. public static void UpdataJGJXGJJ(bool issave,T_jgjdistance_table data)
  635. {
  636. if (issave)
  637. {
  638. db.Updateable<T_jgjdistance_table>(it => new T_jgjdistance_table() { Isnew = "no" }).Where(it => it.Id.ToString() == data.Id).ExecuteCommand();
  639. }
  640. else
  641. {
  642. db.Updateable<T_jgjdistance_table>(it => new T_jgjdistance_table() { Zch = data.Zch,Dcqc = data.Dcqc,Gdjxgjj=data.Gdjxgjj, Isnew = "yes" }).Where(it => it.Id.ToString() == data.Id).ExecuteCommand();
  643. }
  644. }
  645. /// <summary>
  646. /// 清理中间数据
  647. /// </summary>
  648. public static void ClearCacheJGJXGJJ()
  649. {
  650. db.Deleteable<T_jgjdistance_table>().Where(it => it.Isnew == "no" || it.Isnew == "").ExecuteCommand();
  651. }
  652. //*********************************************************************************************************
  653. /// <summary>
  654. /// 初始化表id值,因为id是自增的,有时候删除表内数据之后,id后间断
  655. /// 长时间下,可能未出现id间断几十万的情况,可以使用一下两句sql语句将id值重新归零,让他从1开始进行自增
  656. /// </summary>
  657. public static void chushihuaPG()
  658. {
  659. NpgsqlConnection conn = new NpgsqlConnection();
  660. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  661. NpgsqlCommand comm = new NpgsqlCommand();
  662. comm.Connection = conn;
  663. conn.Open();
  664. comm.CommandText = @"ALTER TABLE public.t_file_account DROP COLUMN id;alter table public.t_file_account add id serial PRIMARY KEY;";
  665. //comm.CommandText = @"SELECT* FROM " + tablename + " where " + querystring;
  666. comm.ExecuteNonQuery();
  667. conn.Close();
  668. }
  669. public static void GetTongDaoData(ref List<T_metadata_account> metadata)
  670. {
  671. metadata = db.Queryable<T_metadata_account>().ToList();
  672. }
  673. /// <summary>
  674. /// 查询全部
  675. /// </summary>
  676. public static void GetAllData(ref List<T_jihefenxi_boxing> jhbx, ref List<T_lunguili_boxing> lglbx,decimal jgj,string xlm,string xingbie)
  677. {
  678. //var aa = test.GetType() == typeof(List<T_daocha_account>);
  679. var dc = db.Queryable<T_daocha_account>().Where(it => it.Xlm == xlm && it.Xingbie == xingbie && it.Jgjlc == jgj).ToList();
  680. var jh = db.Queryable<T_jihefenxi_account>().Where(it => it.Xlm == xlm && it.Xingbie == xingbie && it.Jgjlc == jgj).ToList();
  681. var lgl = db.Queryable<T_lunguili_account>().Where(it => it.Xlm == xlm && it.Xingbie == xingbie && it.Jgjlc == jgj).ToList();
  682. if (dc.Count > 0 && jh.Count > 0 && lgl.Count > 0)
  683. {
  684. decimal jhindex0 = Convert.ToDecimal(jh[jh.Count - 1].Yswjm_jhfx.Split(',')[0]);
  685. decimal jhindex1 = Convert.ToDecimal(jh[jh.Count - 1].Yswjm_jhfx.Split(',')[1]);
  686. decimal lglindex0 = Convert.ToDecimal(lgl[0].Yswjm.Split(',')[0]);
  687. decimal lglindex1 = Convert.ToDecimal(lgl[0].Yswjm.Split(',')[1]);
  688. jhbx = db.Queryable<T_jihefenxi_boxing>().Where(it => it.Id >= jhindex0 && it.Id <= jhindex1).ToList();
  689. lglbx = db.Queryable<T_lunguili_boxing>().Where(it => it.Id >= lglindex0 && it.Id <= lglindex1).ToList();
  690. }
  691. }
  692. }
  693. }