DataAnalysisToPG.cs 30 KB

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