DataAnalysisToPG.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. /// T_dwfile_account表添加新数据
  184. /// </summary>
  185. public static void GLInsertToPG(List<T_dwfile_account> updateObjs)
  186. {
  187. db.Insertable(updateObjs).ExecuteCommand();
  188. }
  189. /// <summary>
  190. /// 密贴离缝表添加新数据
  191. /// </summary>
  192. public static string InsertMTLFListDataToPG(T_mitielifeng_filelist updateObjs)
  193. {
  194. db.Insertable(updateObjs).ExecuteCommand();
  195. return db.Queryable<T_mitielifeng_filelist>().Where(it => it.Remark == updateObjs.Remark && it.Excelbytearr == updateObjs.Excelbytearr).Single().Id;
  196. }
  197. /// <summary>
  198. /// 密贴离缝excel表添加新数据
  199. /// </summary>
  200. public static void InsertMTLFExcelDataToPG(T_mitielifeng_exceldata updateObjs)
  201. {
  202. db.Insertable(updateObjs).ExecuteCommand();
  203. }
  204. /// <summary>
  205. /// 逐枕几何表添加新数据
  206. /// </summary>
  207. public static string InsertZZJHListDataToPG(T_zhuzhenjihe_filelist updateObjs)
  208. {
  209. db.Insertable(updateObjs).ExecuteCommand();
  210. return db.Queryable<T_zhuzhenjihe_filelist>().Where(it => it.Remark == updateObjs.Remark && it.Excelbytearr == updateObjs.Excelbytearr).Single().Id;
  211. }
  212. /// <summary>
  213. /// 逐枕几何excel表添加新数据
  214. /// </summary>
  215. public static void InsertZZJHExcelDataToPG(List<T_zhuzhenjihe_exceldata> updateObjs)
  216. {
  217. db.Insertable(updateObjs).ExecuteCommand();
  218. }
  219. /// <summary>
  220. /// 道岔几何表添加新数据
  221. /// </summary>
  222. public static void InsertJHDataToPG(List<T_jihefenxi_account> updateObjs)
  223. {
  224. db.Insertable(updateObjs).ExecuteCommand();
  225. }
  226. /// <summary>
  227. /// 轮轨力表添加新数据
  228. /// </summary>
  229. public static void InsertLGLDataToPG(List<T_lunguili_account> updateObjs)
  230. {
  231. db.Insertable(updateObjs).ExecuteCommand();
  232. }
  233. /// <summary>
  234. /// 道岔几何波形表添加新数据
  235. /// </summary>
  236. public static void InsertJHBXDataToPG(List<T_jihefenxi_boxing> updateObjs)
  237. {
  238. db.Insertable(updateObjs).ExecuteCommand();
  239. }
  240. /// <summary>
  241. /// 轮轨力波形表添加新数据
  242. /// </summary>
  243. public static void InsertLGLBXDataToPG(List<T_lunguili_boxing> updateObjs)
  244. {
  245. db.Insertable(updateObjs).ExecuteCommand();
  246. }
  247. //**************************************改********************************************
  248. public static void UpdataToPG(T_file_account item)
  249. {
  250. db.Updateable<T_file_account>(it => new T_file_account() { Jccxx = item.Jccxx }).Where(it => it.Id == item.Id).ExecuteCommand();
  251. }
  252. /// <summary>
  253. /// 更新线形线位数据表
  254. /// </summary>
  255. public static void UpdataToPGXXXWD(string name ,string value,string uuid)
  256. {
  257. //db.Updateable<T_xxxw_csvdata>(it => new T_xxxw_csvdata() { }).Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  258. NpgsqlConnection conn = new NpgsqlConnection();
  259. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  260. NpgsqlCommand comm = new NpgsqlCommand();
  261. comm.Connection = conn;
  262. conn.Open();
  263. comm.CommandText = "UPDATE \"t_xxxw_csvdata\" SET " + name + " = '" + value + "' WHERE id ='" + uuid + "'";
  264. //comm.CommandText = @"SELECT* FROM " + tablename + " where " + querystring;
  265. comm.ExecuteNonQuery();
  266. conn.Close();
  267. }
  268. /// <summary>
  269. /// 更新线形线位list表
  270. /// </summary>
  271. public static void UpdataToPGXXXWL(string name, string value, string uuid)
  272. {
  273. db.Updateable<T_xxxw_csvlist>(it => new T_xxxw_csvlist() { Gengxinren = name,Gengxinriqi=value }).Where(it => it.Id.ToString() == uuid).ExecuteCommand();
  274. }
  275. public static void UpdataToPGMTLF(T_mitielifeng_filelist item)
  276. {
  277. db.Updateable<T_mitielifeng_filelist>(item).Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  278. //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();
  279. }
  280. public static void UpdataToPGZZJH(T_zhuzhenjihe_filelist item)
  281. {
  282. db.Updateable<T_zhuzhenjihe_filelist>(item).Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  283. //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();
  284. }
  285. /// <summary>
  286. /// 道岔几何表更新微小算法执行结果
  287. /// </summary>
  288. public static void UpdataJHDataToPG(List<T_jihefenxi_account> updateObjs)
  289. {
  290. for (int i = 0; i < updateObjs.Count; i++)
  291. {
  292. //使用 线路名、行别、尖轨尖里程、检测车、日期 5个条件进行匹配更新数据
  293. db.Updateable<T_jihefenxi_account>(it => new T_jihefenxi_account()
  294. {
  295. Wx_check = updateObjs[i].Wx_check,
  296. Wx_bhl_gd = updateObjs[i].Wx_bhl_gd,
  297. Wx_bhl_gj = updateObjs[i].Wx_bhl_gj,
  298. Wx_bhl_sp = updateObjs[i].Wx_bhl_sp,
  299. Wx_bhl_gx = updateObjs[i].Wx_bhl_gx,
  300. Wx_bhl_sjk = updateObjs[i].Wx_bhl_sjk,
  301. Wx_isload = 1,
  302. }).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();
  303. }
  304. }
  305. /// <summary>
  306. /// 道岔几何波形表更新微小算法执行结果
  307. /// </summary>
  308. public static void UpdataJHBXDataToPG(List<T_jihefenxi_boxing> updateObjs)
  309. {
  310. db.Updateable<T_jihefenxi_boxing>(updateObjs).ExecuteCommand();
  311. }
  312. //**************************************删********************************************
  313. /// <summary>
  314. /// 删除数据 account、boxing两个表
  315. /// type:"轮轨力"、"几何"、"微小"
  316. /// </summary>type
  317. public static void DelUpdataData(string yswjm,string type)
  318. {
  319. T_file_account file = db.SqlQueryable<T_file_account>("select * from \"t_file_account\" where id = " + yswjm).ToList()[0];
  320. //updataRWZT(new string[] { yswjm, "算法未执行" });
  321. if (type == "轮轨力")
  322. {
  323. List<T_lunguili_account> whichupdata = (List<T_lunguili_account>)QueryToPGByNameL(yswjm);
  324. DelToPGLGLBX(whichupdata);
  325. DelToPGLGL(file);
  326. }
  327. else if(type == "几何")
  328. {
  329. List<T_jihefenxi_account> whichupdata = (List<T_jihefenxi_account>)QueryToPGByName(yswjm);
  330. DelToPGJHBX(whichupdata);
  331. DelToPGJH(file);
  332. }
  333. }
  334. /// <summary>
  335. /// 删除数据 by ID
  336. /// </summary>
  337. public static void DelToPGXXXW(string Id)
  338. {
  339. db.Deleteable<T_xxxw_csvlist>().Where(it => it.Id.ToString() == Id).ExecuteCommand();
  340. db.Deleteable<T_xxxw_csvdata>().Where(it => it.Listid == Id).ExecuteCommand();
  341. }
  342. /// <summary>
  343. /// 删除数据 by ID
  344. /// </summary>
  345. public static void DelToPGXXXWD(string Id)
  346. {
  347. db.Deleteable<T_xxxw_csvdata>().Where(it => it.Id.ToString() == Id).ExecuteCommand();
  348. }
  349. /// <summary>
  350. /// 删除数据 by ID
  351. /// </summary>
  352. public static void DelToPGMTLF(T_mitielifeng_filelist item)
  353. {
  354. db.Deleteable<T_mitielifeng_filelist>().Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  355. db.Deleteable<T_mitielifeng_exceldata>().Where(it => it.Filelistid == item.Id).ExecuteCommand();
  356. }
  357. /// <summary>
  358. /// 删除数据 by ID
  359. /// </summary>
  360. public static void DelToPGZZJH(T_zhuzhenjihe_filelist item)
  361. {
  362. db.Deleteable<T_zhuzhenjihe_filelist>().Where(it => it.Id.ToString() == item.Id).ExecuteCommand();
  363. db.Deleteable<T_zhuzhenjihe_exceldata>().Where(it => it.Filelistid == item.Id).ExecuteCommand();
  364. }
  365. /// <summary>
  366. /// 删除数据 by ID
  367. /// </summary>
  368. public static void DelToPG(T_file_account item)
  369. {
  370. db.Deleteable<T_file_account>().Where(it => it.Id == item.Id).ExecuteCommand();
  371. }
  372. /// <summary>
  373. /// 删除数据 by Yswjm
  374. /// </summary>
  375. public static void DelToPG1(T_file_account item)
  376. {
  377. Console.WriteLine(item.Yswjm);
  378. db.Deleteable<T_file_account>().Where(it => it.Yswjm == item.Yswjm).ExecuteCommand();
  379. }
  380. /// <summary>
  381. /// 删除几何account表数据
  382. /// </summary>
  383. public static void DelToPGJH(T_file_account updateObjs)
  384. {
  385. db.Deleteable<T_jihefenxi_account>().Where(it => it.Filename_jh == updateObjs.Id.ToString()).ExecuteCommand();
  386. }
  387. /// <summary>
  388. /// 删除几何波形表数据
  389. /// </summary>
  390. public static void DelToPGJHBX(List<T_jihefenxi_account> updateObjs)
  391. {
  392. NpgsqlConnection conn = new NpgsqlConnection();
  393. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  394. NpgsqlCommand comm = new NpgsqlCommand();
  395. comm.Connection = conn;
  396. conn.Open();
  397. foreach (var item in updateObjs)
  398. {
  399. string[] dd = item.Yswjm_jhfx.Split(',');
  400. comm.CommandText = "DELETE FROM public.t_jihefenxi_boxing where id >= " + dd[0] + " and id <= " + dd[1];
  401. comm.ExecuteNonQuery();
  402. }
  403. conn.Close();
  404. }
  405. /// <summary>
  406. /// 删除轮轨力account表数据
  407. /// </summary>
  408. public static void DelToPGLGL(T_file_account updateObjs)
  409. {
  410. db.Deleteable<T_lunguili_account>().Where(it => it.Filename_lgl == updateObjs.Id.ToString()).ExecuteCommand();
  411. }
  412. /// <summary>
  413. /// 删除轮轨力波形表数据
  414. /// </summary>
  415. public static void DelToPGLGLBX(List<T_lunguili_account> updateObjs)
  416. {
  417. NpgsqlConnection conn = new NpgsqlConnection();
  418. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  419. NpgsqlCommand comm = new NpgsqlCommand();
  420. comm.Connection = conn;
  421. conn.Open();
  422. foreach (var item in updateObjs)
  423. {
  424. string[] dd = item.Yswjm.Split(',');
  425. comm.CommandText = "DELETE FROM public.t_lunguili_boxing where id >= " + dd[0] + " and id <= " + dd[1];
  426. comm.ExecuteNonQuery();
  427. }
  428. conn.Close();
  429. }
  430. /// <summary>
  431. /// 删除查询ID暂时添加的波形条数
  432. /// </summary>
  433. public static void InitBXID()
  434. {
  435. db.Deleteable<T_lunguili_boxing>().Where(it => it.Yswjm == "?????").ExecuteCommand();
  436. db.Deleteable<T_jihefenxi_boxing>().Where(it => it.Yswjm == "?????").ExecuteCommand();
  437. db.Insertable<T_lunguili_boxing>(new T_lunguili_boxing() {Yswjm = "?????" }).ExecuteCommand();
  438. db.Insertable<T_jihefenxi_boxing>(new T_jihefenxi_boxing() { Yswjm = "?????" }).ExecuteCommand();
  439. }
  440. /// <summary>
  441. /// 数据展示删除
  442. /// </summary>
  443. /// <param name="item"></param>
  444. /// <param name="itemjh"></param>
  445. public static void DelSJZS(string item,string itemjh,string xlm,string hangbie,string jgjlc)
  446. {
  447. NpgsqlConnection conn = new NpgsqlConnection();
  448. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  449. NpgsqlCommand comm = new NpgsqlCommand();
  450. comm.Connection = conn;
  451. conn.Open();
  452. if (item != "")
  453. {
  454. string[] dd = item.Split(',');
  455. comm.CommandText = "DELETE FROM public.t_lunguili_boxing where id >= " + dd[0] + " and id <= " + dd[1];
  456. comm.ExecuteNonQuery();
  457. comm.CommandText = "DELETE FROM public.t_lunguili_account where xlm = '" + xlm + "' and xingbie = '" + hangbie + "' and jgjlc = '" + jgjlc + "'";
  458. comm.ExecuteNonQuery();
  459. }
  460. if (itemjh != "")
  461. {
  462. string[] ddd = itemjh.Split(',');
  463. comm.CommandText = "DELETE FROM public.t_jihefenxi_boxing where id >= " + ddd[0] + " and id <= " + ddd[1];
  464. comm.ExecuteNonQuery();
  465. comm.CommandText = "DELETE FROM public.t_jihefenxi_account where xlm = '" + xlm + "' and xingbie = '" + hangbie + "' and jgjlc = '" + jgjlc + "'";
  466. comm.ExecuteNonQuery();
  467. }
  468. conn.Close();
  469. }
  470. //**************************************查********************************************
  471. /// <summary>
  472. /// 按Id查询
  473. /// </summary>
  474. public static Object QueryToPGById(int id_)
  475. {
  476. return db.Queryable<T_file_account>().Where(it => it.Id == id_).Single();
  477. }
  478. /// <summary>
  479. /// 按文件名查询文件
  480. /// </summary>
  481. public static Object QueryToPGByNameFile(string yswjm)
  482. {
  483. return db.Queryable<T_file_account>().Where(it => it.Yswjm == yswjm).ToList();
  484. }
  485. /// <summary>
  486. /// 按文件名查询电务文件
  487. /// </summary>
  488. public static Object DWQueryToPGByNameFile(string filename)
  489. {
  490. return db.Queryable<T_dwfile_account>().Where(it => it.Filename == filename).ToList();
  491. }
  492. /// <summary>
  493. /// 微笑算法筛选Sudu >= 100 && Zcx != "侧向"的数据
  494. /// </summary>
  495. public static Object QueryToPGByNameWXSF(string id)
  496. {
  497. return db.Queryable<T_jihefenxi_account>().Where(it => it.Filename_jh == id && (it.Sudu_jhfx >= 100 && it.Zcx != "侧向" && it.Wx_isload == 0)).ToList();
  498. }
  499. /// <summary>
  500. /// 查可执行微小算法的数据
  501. /// </summary>
  502. public static Object QueryToPGByNameWXSFZD()
  503. {
  504. return db.Queryable<T_jihefenxi_account>().Where(it => it.Sudu_jhfx >= 100 && it.Zcx != "侧向" && it.Wx_isload == 0).ToList();
  505. }
  506. /// <summary>
  507. /// 查数据(条件:线路名、行别、尖轨尖里程、未执行微小算法wx_isload = 1)
  508. /// </summary>
  509. public static List<List<T_jihefenxi_account>> QueryToPGByNameWXSFZDReference(List<T_jihefenxi_account> newdata)
  510. {
  511. List<List<T_jihefenxi_account>> ReferenceList = new List<List<T_jihefenxi_account>>();
  512. for (int i = 0; i < newdata.Count; i++)
  513. {
  514. 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>;
  515. if (aa.Count != 0)
  516. {
  517. ReferenceList.Add(aa);
  518. }
  519. }
  520. return ReferenceList;
  521. }
  522. /// <summary>
  523. /// 按文件名查询JH
  524. /// </summary>
  525. public static Object QueryToPGByName(string id)
  526. {
  527. return db.Queryable<T_jihefenxi_account>().Where(it => it.Filename_jh == id).ToList();
  528. }
  529. /// <summary>
  530. /// 按文件名查询LGL
  531. /// </summary>
  532. public static Object QueryToPGByNameL(string yswjm)
  533. {
  534. return db.Queryable<T_lunguili_account>().Where(it => it.Filename_lgl == yswjm).ToList();
  535. }
  536. /// <summary>
  537. /// 查询几何提取算法线路里程值
  538. /// </summary>
  539. /// <param name="xllc_">线路里程名称</param>
  540. /// <returns></returns>
  541. public static Object QueryToString(string xllc_)
  542. {
  543. return db.Queryable<T_xianlulicheng_sf>().Where(it => it.Xllc == xllc_).Single();
  544. }
  545. /// <summary>
  546. /// 查询线路名
  547. /// </summary>
  548. /// <param name="xllc_">简称</param>
  549. /// <returns></returns>
  550. public static Object QueryToXlm(string xlmjx)
  551. {
  552. return db.Queryable<T_luxianming_sf>().Where(it => it.Xlmsx == xlmjx).First();
  553. }
  554. /// <summary>
  555. /// 查询最大id
  556. /// </summary>
  557. /// <param name="tablename"></param>
  558. /// <returns></returns>
  559. public static int QueryMaxID(string tablename)
  560. {
  561. var list1 = new mm();
  562. if (tablename == "lgl")
  563. {
  564. list1 = db.SqlQueryable<mm>("select MAX(ID) from \"t_lunguili_boxing\"").Single();
  565. }
  566. else
  567. {
  568. list1 = db.SqlQueryable<mm>("select MAX(ID) from \"t_jihefenxi_boxing\"").Single();
  569. }
  570. return list1.Max;
  571. }
  572. /// 查询电务功率全部信息
  573. public static List<T_dwfile_account> QueryDWGLALL()
  574. {
  575. return db.Queryable<T_dwfile_account>().ToList();
  576. }
  577. /// <summary>
  578. /// 查询道岔台账全部信息
  579. /// </summary>
  580. public static List<T_daocha_account> QueryDCTZALL()
  581. {
  582. return db.Queryable<T_daocha_account>().ToList();
  583. }
  584. /// <summary>
  585. /// 查询道岔台账信息
  586. /// </summary>
  587. public static Object QueryDCTZ(string xlm,Char[] hangbie)
  588. {
  589. if (hangbie[hangbie.Length-1] == 'S')
  590. {
  591. return db.Queryable<T_daocha_account>().Where(it => it.Xlm == xlm && it.Xingbie == "上"||it.Xingbie == "上行").ToList();
  592. }
  593. else
  594. {
  595. return db.Queryable<T_daocha_account>().Where(it => it.Xlm == xlm && it.Xingbie == "下" || it.Xingbie == "下行").ToList();
  596. }
  597. }
  598. /// <summary>
  599. /// 查询管界台账信息
  600. /// </summary>
  601. public static Object QueryGJTZ(string xlm, Char[] hangbie)
  602. {
  603. if (hangbie[hangbie.Length - 1] == 'S')
  604. {
  605. return db.Queryable<T_guanjie_account>().Where(it => it.Xianming == xlm && it.Hangbie == "上" || it.Hangbie == "上行").ToList();
  606. }
  607. else
  608. {
  609. return db.Queryable<T_guanjie_account>().Where(it => it.Xianming == xlm && it.Hangbie == "下" || it.Hangbie == "下行").ToList();
  610. }
  611. }
  612. /// <summary>
  613. /// 查询曲线台账信息
  614. /// </summary>
  615. public static Object QueryQXTZ(string xlm, Char[] hangbie)
  616. {
  617. if (hangbie[hangbie.Length - 1] == 'S')
  618. {
  619. return db.Queryable<T_quxian_account>().Where(it => it.Xianming == xlm && it.Hangbie == "上" || it.Hangbie == "上行").ToList();
  620. }
  621. else
  622. {
  623. return db.Queryable<T_quxian_account>().Where(it => it.Xianming == xlm && it.Hangbie == "下" || it.Hangbie == "下行").ToList();
  624. }
  625. }
  626. //*********************************************************************************************************
  627. /// <summary>
  628. /// 插入尖轨尖心轨间距表
  629. /// </summary>
  630. public static void InsertJGJXGJJ(T_jgjdistance_table updateObjs)
  631. {
  632. db.Insertable(updateObjs).ExecuteCommand();
  633. }
  634. /// <summary>
  635. /// 查询尖轨尖心轨间距表
  636. /// </summary>
  637. public static List<T_jgjdistance_table> QueryJGJXGJJ()
  638. {
  639. return db.Queryable<T_jgjdistance_table>().ToList();
  640. }
  641. /// <summary>
  642. /// 删除数据 by ID
  643. /// </summary>
  644. public static void DelJGJXGJJ(string Id)
  645. {
  646. db.Deleteable<T_jgjdistance_table>().Where(it => it.Id.ToString() == Id).ExecuteCommand();
  647. }
  648. /// <summary>
  649. /// 更新数据
  650. /// </summary>
  651. /// <param name="uuid">更新的ID</param>
  652. /// <param name="issave">更新类型 true 仅为了逻辑 false 真是更新</param>
  653. public static void UpdataJGJXGJJ(bool issave,T_jgjdistance_table data)
  654. {
  655. if (issave)
  656. {
  657. db.Updateable<T_jgjdistance_table>(it => new T_jgjdistance_table() { Isnew = "no" }).Where(it => it.Id.ToString() == data.Id).ExecuteCommand();
  658. }
  659. else
  660. {
  661. 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();
  662. }
  663. }
  664. /// <summary>
  665. /// 清理中间数据
  666. /// </summary>
  667. public static void ClearCacheJGJXGJJ()
  668. {
  669. db.Deleteable<T_jgjdistance_table>().Where(it => it.Isnew == "no" || it.Isnew == "").ExecuteCommand();
  670. }
  671. //*********************************************************************************************************
  672. /// <summary>
  673. /// 初始化表id值,因为id是自增的,有时候删除表内数据之后,id后间断
  674. /// 长时间下,可能未出现id间断几十万的情况,可以使用一下两句sql语句将id值重新归零,让他从1开始进行自增
  675. /// </summary>
  676. public static void chushihuaPG()
  677. {
  678. NpgsqlConnection conn = new NpgsqlConnection();
  679. conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["dbConnection"] as string;
  680. NpgsqlCommand comm = new NpgsqlCommand();
  681. comm.Connection = conn;
  682. conn.Open();
  683. comm.CommandText = @"ALTER TABLE public.t_file_account DROP COLUMN id;alter table public.t_file_account add id serial PRIMARY KEY;";
  684. //comm.CommandText = @"SELECT* FROM " + tablename + " where " + querystring;
  685. comm.ExecuteNonQuery();
  686. conn.Close();
  687. }
  688. public static void GetTongDaoData(ref List<T_metadata_account> metadata)
  689. {
  690. metadata = db.Queryable<T_metadata_account>().ToList();
  691. }
  692. /// <summary>
  693. /// 查询全部
  694. /// </summary>
  695. public static void GetAllData(ref List<T_jihefenxi_boxing> jhbx, ref List<T_lunguili_boxing> lglbx,decimal jgj,string xlm,string xingbie)
  696. {
  697. //var aa = test.GetType() == typeof(List<T_daocha_account>);
  698. var dc = db.Queryable<T_daocha_account>().Where(it => it.Xlm == xlm && it.Xingbie == xingbie && it.Jgjlc == jgj).ToList();
  699. var jh = db.Queryable<T_jihefenxi_account>().Where(it => it.Xlm == xlm && it.Xingbie == xingbie && it.Jgjlc == jgj).ToList();
  700. var lgl = db.Queryable<T_lunguili_account>().Where(it => it.Xlm == xlm && it.Xingbie == xingbie && it.Jgjlc == jgj).ToList();
  701. if (dc.Count > 0 && jh.Count > 0 && lgl.Count > 0)
  702. {
  703. decimal jhindex0 = Convert.ToDecimal(jh[jh.Count - 1].Yswjm_jhfx.Split(',')[0]);
  704. decimal jhindex1 = Convert.ToDecimal(jh[jh.Count - 1].Yswjm_jhfx.Split(',')[1]);
  705. decimal lglindex0 = Convert.ToDecimal(lgl[0].Yswjm.Split(',')[0]);
  706. decimal lglindex1 = Convert.ToDecimal(lgl[0].Yswjm.Split(',')[1]);
  707. jhbx = db.Queryable<T_jihefenxi_boxing>().Where(it => it.Id >= jhindex0 && it.Id <= jhindex1).ToList();
  708. lglbx = db.Queryable<T_lunguili_boxing>().Where(it => it.Id >= lglindex0 && it.Id <= lglindex1).ToList();
  709. }
  710. }
  711. }
  712. }