DataAnalysisToPG.cs 34 KB

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