SqlAcc.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Data.SqlClient;
  8. using Cksoft.Data.Repository;
  9. using Cksoft.Data;
  10. namespace DllSqlAcc
  11. {
  12. public class SqlAcc
  13. {
  14. private string CurrDbCode = "dbcode";
  15. private string CurrMySqlCode = "mysqlsecs";
  16. public int BatIMcaSecVMst(DataSet ds, ref string errorinfo)
  17. {
  18. SqlConnection dbconn = null;
  19. try
  20. {
  21. string connstr = System.Configuration.ConfigurationManager.AppSettings[CurrDbCode].ToString();
  22. DataRow row = ds.Tables[0].Rows[0];
  23. dbconn = new SqlConnection(connstr);
  24. dbconn.Open();
  25. StringBuilder sqlstr = new StringBuilder(100);
  26. SqlTransaction mytrans = dbconn.BeginTransaction();
  27. SqlCommand scmd = dbconn.CreateCommand();
  28. scmd.Transaction = mytrans;
  29. DataSet tempds = ds.Clone();
  30. DataRow[] rows = ds.Tables["McaSecVMst"].Select("", "ID");
  31. foreach (DataRow temprow in rows)
  32. {
  33. tempds = ds.Clone();
  34. tempds.Tables["McaSecVMst"].ImportRow(temprow);
  35. if(ds.Tables.Contains("oaa"))
  36. {
  37. DataRow[] ttrows = ds.Tables["oaa"].Select("主档ID="+temprow["ID"].ToString());
  38. foreach(DataRow ttrow in ttrows)
  39. {
  40. tempds.Tables["oaa"].ImportRow(ttrow);
  41. }
  42. }
  43. if (ds.Tables.Contains("oab"))
  44. {
  45. DataRow[] ttrows = ds.Tables["oab"].Select("主档ID=" + temprow["ID"].ToString());
  46. foreach (DataRow ttrow in ttrows)
  47. {
  48. tempds.Tables["oab"].ImportRow(ttrow);
  49. }
  50. }
  51. int result = IMcaSecVMst(scmd, tempds, ref errorinfo);
  52. if(result<=0)
  53. {
  54. mytrans.Rollback();
  55. return -1;
  56. }
  57. }
  58. mytrans.Commit();
  59. return 1;
  60. }
  61. catch (Exception ex)
  62. {
  63. errorinfo = ex.Message.ToString();
  64. return -1;
  65. }
  66. finally
  67. {
  68. if (dbconn != null)
  69. dbconn.Close();
  70. }
  71. }
  72. public int IMcaSecVMst(DataSet ds, ref string errorinfo)
  73. {
  74. SqlConnection dbconn = null;
  75. try
  76. {
  77. string connstr= System.Configuration.ConfigurationManager.AppSettings[CurrDbCode].ToString();
  78. DataRow row = ds.Tables[0].Rows[0];
  79. dbconn = new SqlConnection(connstr);
  80. dbconn.Open();
  81. StringBuilder sqlstr = new StringBuilder(100);
  82. SqlTransaction mytrans= dbconn.BeginTransaction();
  83. SqlCommand scmd = dbconn.CreateCommand();
  84. scmd.Transaction = mytrans;
  85. int result = JudgeEventSame(scmd, ds, ref errorinfo);
  86. if (result < 0)
  87. {
  88. mytrans.Rollback();
  89. return -1;
  90. }
  91. int mstid = 0;
  92. if (result == 0)
  93. {
  94. mstid = IMcaSecVMst(scmd, ds.Tables["McaSecVMst"].Rows[0], ref errorinfo);
  95. if (mstid < 0)
  96. {
  97. mytrans.Rollback();
  98. return -1;
  99. }
  100. if (int.Parse(ds.Tables["McaSecVMst"].Rows[0]["FType"].ToString()) > 0)
  101. {
  102. //DataSet tempds = MsgPackage.MsgPackage.BytesToDataSet((byte[])ds.Tables["McaSecVMst"].Rows[0]["fcon"], ref errorinfo);
  103. result = IMcaSecVDetail(scmd, ds.Tables["oab"], mstid, ref errorinfo);
  104. if (result < 0)
  105. {
  106. mytrans.Rollback();
  107. return -1;
  108. }
  109. }
  110. }
  111. else
  112. {
  113. //说明事件已经存在,只需添加时间明细
  114. mstid = result;
  115. }
  116. DateTime ptime = (DateTime)ds.Tables["McaSecVMst"].Rows[0]["ptime"];
  117. result = IMcaSecTime(scmd, mstid, ptime
  118. , long.Parse(ds.Tables["McaSecVMst"].Rows[0]["OrgFNum"].ToString()), ref errorinfo);
  119. if (result <= 0)
  120. {
  121. mytrans.Rollback();
  122. return -1;
  123. }
  124. mytrans.Commit();
  125. return mstid;
  126. }
  127. catch (Exception ex)
  128. {
  129. errorinfo = ex.Message.ToString();
  130. return -1;
  131. }
  132. finally
  133. {
  134. if (dbconn != null)
  135. dbconn.Close();
  136. }
  137. }
  138. public int IMcaSecVMst(SqlCommand scmd,DataSet ds, ref string errorinfo)
  139. {
  140. try
  141. {
  142. DataRow row = ds.Tables["McaSecVMst"].Rows[0];
  143. StringBuilder sqlstr = new StringBuilder(100);
  144. int result = JudgeEventSame(scmd, ds, ref errorinfo);
  145. if (result < 0)
  146. {
  147. return -1;
  148. }
  149. int mstid = 0;
  150. if (result == 0)
  151. {
  152. mstid = IMcaSecVMst(scmd, ds.Tables["McaSecVMst"].Rows[0], ref errorinfo);
  153. if (mstid < 0)
  154. {
  155. return -1;
  156. }
  157. if (int.Parse(ds.Tables["McaSecVMst"].Rows[0]["FType"].ToString()) > 0)
  158. {
  159. result = IMcaSecVDetail(scmd, ds.Tables["oab"], mstid, ref errorinfo);
  160. if (result < 0)
  161. {
  162. return -1;
  163. }
  164. }
  165. }
  166. else
  167. {
  168. //说明事件已经存在,只需添加时间明细
  169. mstid = result;
  170. }
  171. DateTime ptime = (DateTime)ds.Tables["McaSecVMst"].Rows[0]["ptime"];
  172. result = IMcaSecTime(scmd, mstid, ptime
  173. , long.Parse(ds.Tables["McaSecVMst"].Rows[0]["OrgFNum"].ToString()), ref errorinfo);
  174. if (result <= 0)
  175. {
  176. return -1;
  177. }
  178. return mstid;
  179. }
  180. catch (Exception ex)
  181. {
  182. errorinfo = ex.Message.ToString();
  183. return -1;
  184. }
  185. }
  186. //判断事件是否与最后事件相同,返回值为该机台最后事件记录ID值
  187. public static int JudgeEventSame(SqlCommand scmd, DataSet ds, ref string errorinfo)
  188. {
  189. try
  190. {
  191. //说明不是事件,直接返回
  192. if (!ds.Tables.Contains("oab"))
  193. return 0;
  194. DataRow mainrow = ds.Tables["McaSecVMst"].Rows[0];
  195. string mcacode = mainrow["McaCode"].ToString();
  196. StringBuilder sqlstr = new StringBuilder(100);
  197. sqlstr.AppendFormat("select a.id,a.eventcode from mcasecvmst as a where a.id = (select MAX(id) from mcasecvmst where mcacode = '{0}')", mcacode);
  198. scmd.CommandText = sqlstr.ToString();
  199. SqlDataAdapter sda = new SqlDataAdapter(scmd);
  200. DataSet reds = new DataSet();
  201. sda.Fill(reds, "mcasecvmst");
  202. if (reds.Tables[0].Rows.Count <= 0)
  203. return 0;
  204. string eventcode = reds.Tables[0].Rows[0]["eventcode"].ToString();
  205. if (eventcode != mainrow["eventcode"].ToString())
  206. return 0;
  207. int preid = int.Parse(reds.Tables[0].Rows[0]["id"].ToString());
  208. //读取事件明细
  209. sqlstr.Clear();
  210. sqlstr.AppendFormat("select fcode,fval from McaSecVDetail where preid={0} order by fcode", preid);
  211. scmd.CommandText = sqlstr.ToString();
  212. sda.Fill(reds, "McaSecVDetail");
  213. DataRow[] orgrows = ds.Tables["oab"].Select("", "参数代码");
  214. if (orgrows.Length != reds.Tables[0].Rows.Count)
  215. return 0;
  216. for (int i = 0; i < orgrows.Length; i++)
  217. {
  218. if (orgrows[i]["参数代码"].ToString() != reds.Tables[0].Rows[i]["fcode"].ToString())
  219. return 0;
  220. if (orgrows[i]["数据内容"].ToString() != reds.Tables[0].Rows[i]["fval"].ToString())
  221. return 0;
  222. }
  223. return preid;
  224. }
  225. catch (Exception ex)
  226. {
  227. errorinfo = ex.Message.ToString();
  228. return -1;
  229. }
  230. }
  231. public static int IMcaSecVMst(SqlCommand scmd, DataRow row, ref string errorinfo)
  232. {
  233. try
  234. {
  235. StringBuilder sqlstr = new StringBuilder(100);
  236. sqlstr.AppendFormat("select a.McaCode,a.ptime,a.EventID,a.FType,a.FStatus,a.eventcode,a.pMill,a.id from McaSecVMst a where a.id=0");//,a.OrgFNum
  237. scmd.CommandText = sqlstr.ToString();
  238. SqlDataAdapter sda = new SqlDataAdapter(scmd);
  239. SqlCommandBuilder ocb = new SqlCommandBuilder(sda);
  240. sda.InsertCommand = ocb.GetInsertCommand();
  241. sda.UpdateCommand = ocb.GetUpdateCommand();
  242. sda.DeleteCommand = ocb.GetDeleteCommand();
  243. DataSet reds = new DataSet();
  244. sda.Fill(reds, "McaSecVMst");
  245. DataRow orgrow = reds.Tables[0].NewRow();
  246. reds.Tables[0].Rows.Add(orgrow);
  247. //orgrow["id"] = row["id"];
  248. orgrow["McaCode"] = row["McaCode"];
  249. orgrow["ptime"] = row["ptime"];
  250. orgrow["EventID"] = row["EventID"];
  251. //orgrow["OrgFNum"] = row["OrgFNum"];
  252. orgrow["FType"] = row["FType"];
  253. orgrow["FStatus"] = row["FStatus"];
  254. orgrow["eventcode"] = row["eventcode"];
  255. orgrow["pMill"] = DateTime.Parse(row["ptime"].ToString()).Millisecond;
  256. int result = sda.Update(reds, "McaSecVMst");
  257. if (result < 0)
  258. {
  259. return -1;
  260. }
  261. //sqlstr.Clear();
  262. //sqlstr.AppendFormat("select SCOPE_IDENTITY()");//返回为当前会话和当前作用域中的某个表生成的最新标识值。
  263. //scmd.CommandText = sqlstr.ToString();
  264. //sda = new SqlDataAdapter(scmd);
  265. //reds = new DataSet();
  266. //sda.Fill(reds, "McaSecVMst");
  267. //sqlstr.Clear();
  268. //sqlstr.AppendFormat("select @@identity");//返回为跨所有作用域的当前会话中的某个表生成的最新标识值。
  269. //scmd.CommandText = sqlstr.ToString();
  270. //sda = new SqlDataAdapter(scmd);
  271. //reds = new DataSet();
  272. //sda.Fill(reds, "McaSecVMst");
  273. sqlstr.Clear();
  274. sqlstr.AppendFormat("select IDENT_CURRENT('McaSecVMst')");//返回为某个会话和用域中的指定表生成的最新标识值。
  275. scmd.CommandText = sqlstr.ToString();
  276. sda = new SqlDataAdapter(scmd);
  277. reds = new DataSet();
  278. sda.Fill(reds, "McaSecVMst");
  279. return int.Parse(reds.Tables[0].Rows[0][0].ToString());
  280. }
  281. catch (Exception ex)
  282. {
  283. errorinfo = ex.Message.ToString();
  284. return -1;
  285. }
  286. }
  287. //新增McaSecVDetail
  288. private static int IMcaSecVDetail(SqlCommand scmd, DataTable detaildt, int preid, ref string errorinfo)
  289. {
  290. try
  291. {
  292. StringBuilder sqlstr = new StringBuilder(100);
  293. int result = 0;
  294. sqlstr.Clear();
  295. sqlstr.AppendFormat("select a.PreID,a.FCode,a.ID,a.FVal from McaSecVDetail a where a.id=0");
  296. scmd.CommandText = sqlstr.ToString();
  297. SqlDataAdapter sda = new SqlDataAdapter(scmd);
  298. SqlCommandBuilder ocb = new SqlCommandBuilder(sda);
  299. sda.InsertCommand = ocb.GetInsertCommand();
  300. sda.UpdateCommand = ocb.GetUpdateCommand();
  301. sda.DeleteCommand = ocb.GetDeleteCommand();
  302. DataSet reds = new DataSet();
  303. sda.Fill(reds, "McaSecVDetail");
  304. DataRow[] temprows = detaildt.Select();
  305. DataRow orgrow = null;
  306. foreach (DataRow temprow in temprows)
  307. {
  308. orgrow = reds.Tables[0].NewRow();
  309. reds.Tables[0].Rows.Add(orgrow);
  310. orgrow["PreID"] = preid;
  311. orgrow["FCode"] = temprow["参数代码"];
  312. orgrow["FVal"] = temprow["数据内容"];
  313. }
  314. result = sda.Update(reds, "McaSecVDetail");
  315. if (result < 0)
  316. {
  317. return -1;
  318. }
  319. return 1;
  320. }
  321. catch (Exception ex)
  322. {
  323. errorinfo = ex.Message.ToString();
  324. return -1;
  325. }
  326. }
  327. public static int IMcaSecTime(SqlCommand scmd, int preid, DateTime ptime, long fnum, ref string errorinfo)
  328. {
  329. try
  330. {
  331. StringBuilder sqlstr = new StringBuilder(100);
  332. sqlstr.AppendFormat("select a.preid,a.ptime,a.pMill,a.OrgFNum,a.id from McaSecTime a where a.id=0");
  333. scmd.CommandText = sqlstr.ToString();
  334. SqlDataAdapter sda = new SqlDataAdapter(scmd);
  335. SqlCommandBuilder ocb = new SqlCommandBuilder(sda);
  336. sda.InsertCommand = ocb.GetInsertCommand();
  337. sda.UpdateCommand = ocb.GetUpdateCommand();
  338. sda.DeleteCommand = ocb.GetDeleteCommand();
  339. DataSet reds = new DataSet();
  340. sda.Fill(reds, "McaSecTime");
  341. DataRow orgrow = reds.Tables[0].NewRow();
  342. reds.Tables[0].Rows.Add(orgrow);
  343. orgrow["preid"] = preid;
  344. orgrow["ptime"] = ptime;
  345. orgrow["OrgFNum"] = fnum;
  346. orgrow["pMill"] = ptime.Millisecond;
  347. int result = sda.Update(reds, "McaSecTime");
  348. if (result < 0)
  349. {
  350. return -1;
  351. }
  352. //更新主档事件数量
  353. sqlstr.Clear();
  354. //sqlstr.AppendFormat("update mcasecvmst ");
  355. //sqlstr.AppendFormat(" set fcount = (select COUNT(b.id) from McaSecTime b where b.preid = mcasecvmst.id)");
  356. //sqlstr.AppendFormat(",etime={0},eMill={1}",ptime,ptime.Millisecond);
  357. //sqlstr.AppendFormat(" where id = {0}",preid);
  358. sqlstr.AppendFormat("update a");
  359. sqlstr.AppendFormat(" set a.fcount = (select COUNT(b.id) from McaSecTime b where b.preid = a.id)");
  360. sqlstr.AppendFormat(",a.etime=CONVERT(datetime,'{0}',20),a.eMill={1}", ptime.ToString("yyyy-MM-dd HH:mm:ss.fff"), ptime.Millisecond);
  361. sqlstr.AppendFormat(" from mcasecvmst a");
  362. sqlstr.AppendFormat(" where a.id = {0}", preid);
  363. scmd.CommandText = sqlstr.ToString();
  364. result = scmd.ExecuteNonQuery();
  365. if (result < 0)
  366. return -1;
  367. return 1;
  368. }
  369. catch (Exception ex)
  370. {
  371. errorinfo = ex.Message.ToString();
  372. return -1;
  373. }
  374. }
  375. /// <summary>
  376. /// 读取所有机台最后一次事件
  377. /// </summary>
  378. /// <param name="ds"></param>
  379. /// <param name="errorinfo"></param>
  380. /// <returns></returns>
  381. public DataSet ReadLastMcaSecVMst(ref string errorinfo)
  382. {
  383. SqlConnection dbconn = null;
  384. try
  385. {
  386. string connstr = System.Configuration.ConfigurationManager.AppSettings[CurrDbCode].ToString();
  387. dbconn = new SqlConnection(connstr);
  388. dbconn.Open();
  389. StringBuilder sqlstr = new StringBuilder(100);
  390. SqlTransaction mytrans = dbconn.BeginTransaction();
  391. SqlCommand scmd = dbconn.CreateCommand();
  392. scmd.Transaction = mytrans;
  393. sqlstr.AppendFormat("select a.ID,a.McaCode,a.ptime,a.pMill,a.etime,a.eMill,a.FType,a.FStatus,a.EventCode,a.FCount,a.EventID,1 islast");
  394. sqlstr.AppendFormat(" from McaSecVMst a");
  395. sqlstr.AppendFormat(" inner");
  396. sqlstr.AppendFormat(" join");
  397. sqlstr.AppendFormat(" (SELECT McaCode");
  398. sqlstr.AppendFormat(" , max(ptime)maxtime");
  399. sqlstr.AppendFormat(" FROM McaSecVMst");
  400. sqlstr.AppendFormat(" group by McaCode) b on a.McaCode = b.McaCode and a.ptime = b.maxtime");
  401. scmd.CommandText = sqlstr.ToString();
  402. SqlDataAdapter sda = new SqlDataAdapter(scmd);
  403. DataSet reds = new DataSet();
  404. sda.Fill(reds, "McaSecVMst");
  405. sqlstr.Clear();
  406. sqlstr.AppendFormat("SELECT TOP 0 a.ID,a.PreID,a.FCode,a.FVal,a.fnum FROM McaSecVDetail a");
  407. sqlstr.AppendFormat(" inner join(select a.ID");
  408. sqlstr.AppendFormat(" from McaSecVMst a");
  409. sqlstr.AppendFormat(" inner");
  410. sqlstr.AppendFormat(" join");
  411. sqlstr.AppendFormat(" (SELECT McaCode");
  412. sqlstr.AppendFormat(" , max(ptime)maxtime");
  413. sqlstr.AppendFormat(" FROM McaSecVMst");
  414. sqlstr.AppendFormat(" group by McaCode) b on a.McaCode = b.McaCode and a.ptime = b.maxtime) c on a.preid=c.id");
  415. scmd.CommandText = sqlstr.ToString();
  416. sda = new SqlDataAdapter(scmd);
  417. DataTable tempdt = new DataTable("McaSecVDetail");
  418. sda.Fill(tempdt);
  419. reds.Merge(tempdt);
  420. sqlstr.Clear();
  421. sqlstr.AppendFormat("SELECT TOP 0 a.ID,a.PreID,a.ptime,a.pMill,a.OrgFNum FROM McaSecTime a");
  422. scmd.CommandText = sqlstr.ToString();
  423. sda = new SqlDataAdapter(scmd);
  424. tempdt = new DataTable("McaSecTime");
  425. sda.Fill(tempdt);
  426. reds.Merge(tempdt);
  427. mytrans.Commit();
  428. return reds;
  429. }
  430. catch (Exception ex)
  431. {
  432. errorinfo = ex.Message.ToString();
  433. return null;
  434. }
  435. finally
  436. {
  437. if (dbconn != null)
  438. dbconn.Close();
  439. }
  440. }
  441. public int BatIMcaSecVMst01(DataSet ds, ref string errorinfo)
  442. {
  443. SqlConnection dbconn = null;
  444. try
  445. {
  446. string connstr = System.Configuration.ConfigurationManager.AppSettings[CurrDbCode].ToString();
  447. DataRow row = ds.Tables[0].Rows[0];
  448. dbconn = new SqlConnection(connstr);
  449. dbconn.Open();
  450. StringBuilder sqlstr = new StringBuilder(100);
  451. SqlTransaction mytrans = dbconn.BeginTransaction();
  452. //SqlCommand scmd = dbconn.CreateCommand();
  453. //scmd.Transaction = mytrans;
  454. DataTable mstdt = ds.Tables["McaSecVMst"].Clone();
  455. DataRow[] rows = ds.Tables["McaSecVMst"].Select("", "", DataViewRowState.Added);
  456. foreach (DataRow temprow in rows)
  457. mstdt.ImportRow(temprow);
  458. mstdt.Columns.Remove("islast");
  459. SqlBulkCopy bulkCopy = new SqlBulkCopy(dbconn,SqlBulkCopyOptions.CheckConstraints,mytrans);
  460. bulkCopy.DestinationTableName = mstdt.TableName;
  461. bulkCopy.BatchSize = mstdt.Rows.Count;
  462. bulkCopy.WriteToServer(mstdt);
  463. mstdt = ds.Tables["McaSecVDetail"].Clone();
  464. rows = ds.Tables["McaSecVDetail"].Select("", "", DataViewRowState.Added);
  465. foreach (DataRow temprow in rows)
  466. mstdt.ImportRow(temprow);
  467. bulkCopy = new SqlBulkCopy(dbconn, SqlBulkCopyOptions.CheckConstraints, mytrans);
  468. bulkCopy.DestinationTableName = mstdt.TableName;
  469. bulkCopy.BatchSize = mstdt.Rows.Count;
  470. bulkCopy.WriteToServer(mstdt);
  471. mstdt = ds.Tables["McaSecTime"].Clone();
  472. rows = ds.Tables["McaSecTime"].Select("", "", DataViewRowState.Added);
  473. foreach (DataRow temprow in rows)
  474. mstdt.ImportRow(temprow);
  475. bulkCopy = new SqlBulkCopy(dbconn, SqlBulkCopyOptions.CheckConstraints, mytrans);
  476. bulkCopy.DestinationTableName = mstdt.TableName;
  477. bulkCopy.BatchSize = mstdt.Rows.Count;
  478. bulkCopy.WriteToServer(mstdt);
  479. mytrans.Commit();
  480. return 1;
  481. }
  482. catch (Exception ex)
  483. {
  484. errorinfo = ex.Message.ToString();
  485. return -1;
  486. }
  487. finally
  488. {
  489. if (dbconn != null)
  490. dbconn.Close();
  491. }
  492. }
  493. public DataSet ReadSecMstDs(ref string errorinfo)
  494. {
  495. IDatabase db = null;
  496. try
  497. {
  498. DataSet reds = new DataSet();
  499. db = DbFactory.Base(CurrMySqlCode);
  500. db.BeginTrans();
  501. //读取机台关联事件信息
  502. StringBuilder sqlstr = new StringBuilder(100);
  503. sqlstr.AppendFormat("select distinct a.FNum,a.EventReportMstID,b.EventID,c.FVal,w.fcode 参数代码,m.mc10 机台编号");
  504. sqlstr.AppendFormat(" from SecMstEvent a");
  505. sqlstr.AppendFormat(" inner join EventReportMst b on a.EventReportMstID = b.id");
  506. sqlstr.AppendFormat(" inner join SecDetail c on b.EventID = c.SecID and c.PreID = a.SecMstID");
  507. sqlstr.AppendFormat(" inner join McaEvent d on a.SecMstID = d.PreID");
  508. sqlstr.AppendFormat(" inner join Sec w on b.EventID = w.ID");
  509. sqlstr.AppendFormat(" inner join mca m on d.mcaid=m.id");
  510. //sqlstr.AppendFormat(" where d.McaID = {0}", mcaid);
  511. DataTable tempdt = db.FindTableFor(sqlstr.ToString(), "SecMstEvent");
  512. reds.Merge(tempdt);
  513. //读取机台事件关联报告信息
  514. sqlstr.Clear();
  515. sqlstr.AppendFormat("select distinct t.FNum,a.EventReportMstID,t.ReportMstID,c.FVal,m.mc10 机台编号");
  516. sqlstr.AppendFormat(" from EventReportDetail t");
  517. sqlstr.AppendFormat(" inner join SecMstEvent a on t.preid=a.EventReportMstID");
  518. sqlstr.AppendFormat(" inner join EventReportMst b on a.EventReportMstID = b.id");
  519. sqlstr.AppendFormat(" inner join SecDetail c on b.EventID = c.SecID and c.PreID = a.SecMstID");
  520. sqlstr.AppendFormat(" inner join McaEvent d on a.SecMstID = d.PreID");
  521. sqlstr.AppendFormat(" inner join mca m on d.mcaid=m.id");
  522. //sqlstr.AppendFormat(" where d.McaID = {0}", mcaid);
  523. tempdt = db.FindTableFor(sqlstr.ToString(), "EventReportDetail");
  524. reds.Merge(tempdt);
  525. //读取机台报告关联参数指令
  526. sqlstr.Clear();
  527. sqlstr.AppendFormat("select distinct z.FNum,z.SecID,z.PreID ReportMstID,c.FVal,w.FCode 参数代码,c.dcode 参数类型,m.mc10 机台编号");
  528. sqlstr.AppendFormat(" from ReportDetail z");
  529. sqlstr.AppendFormat(" inner join EventReportDetail t on z.PreID=t.ReportMstID");
  530. sqlstr.AppendFormat(" inner join SecMstEvent a on t.preid=a.EventReportMstID");
  531. sqlstr.AppendFormat(" inner join EventReportMst b on a.EventReportMstID = b.id");
  532. sqlstr.AppendFormat(" inner join SecDetail c on z.SecID = c.SecID and c.PreID = a.SecMstID");
  533. sqlstr.AppendFormat(" inner join McaEvent d on a.SecMstID = d.PreID");
  534. sqlstr.AppendFormat(" inner join Sec w on z.SecID = w.ID");
  535. sqlstr.AppendFormat(" inner join mca m on d.mcaid=m.id");
  536. //sqlstr.AppendFormat(" where d.McaID = {0}", mcaid);
  537. tempdt = db.FindTableFor(sqlstr.ToString(), "ReportDetail");
  538. reds.Merge(tempdt);
  539. sqlstr.Clear();
  540. sqlstr.AppendFormat("select distinct a.id,a.SVal,a.FVal,m.mc10 机台编号 from McaDynamicMst as a");
  541. sqlstr.AppendFormat(" inner join McaEvent as b on a.PreID = b.PreID");
  542. sqlstr.AppendFormat(" inner join mca m on b.mcaid=m.id");
  543. //sqlstr.AppendFormat(" where b.McaID = {0}", mcaid);
  544. tempdt = db.FindTableFor(sqlstr.ToString(), "McaDynamicMst");
  545. reds.Merge(tempdt);
  546. sqlstr.Clear();
  547. sqlstr.AppendFormat("select distinct f.FCode 参数代码,t.fnum 序号,d.fval 参数值,d.dcode 数据类型代码,t.preid,m.mc10 机台编号 from McaDynamicDetail as t");
  548. sqlstr.AppendFormat(" inner join McaDynamicMst as a on t.PreID = a.id");
  549. sqlstr.AppendFormat(" inner join McaEvent as b on a.PreID = b.PreID");
  550. sqlstr.AppendFormat(" inner join SecDetail d on a.preid = d.PreID and t.SecID = d.SecID");
  551. sqlstr.AppendFormat(" inner join Sec f on t.SecID = f.id");
  552. sqlstr.AppendFormat(" inner join mca m on b.mcaid=m.id");
  553. //sqlstr.AppendFormat(" where b.McaID = {0}", mcaid);
  554. tempdt = db.FindTableFor(sqlstr.ToString(), "McaDynamicDetail");
  555. reds.Merge(tempdt);
  556. db.Commit();
  557. return reds;
  558. }
  559. catch (Exception ex)
  560. {
  561. errorinfo = ex.Message.ToString();
  562. return null;
  563. }
  564. finally
  565. {
  566. if (db != null)
  567. db.Close();
  568. }
  569. }
  570. }
  571. }