DataAnalysisToPG.cs 38 KB

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