DataAnalysisToPG.cs 31 KB

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