123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data.SqlClient;
- using Cksoft.Data.Repository;
- using Cksoft.Data;
- namespace DllSqlAcc
- {
- public class SqlAcc
- {
- private string CurrDbCode = "dbcode";
- private string CurrMySqlCode = "mysqlsecs";
- public int BatIMcaSecVMst(DataSet ds, ref string errorinfo)
- {
- SqlConnection dbconn = null;
- try
- {
- string connstr = System.Configuration.ConfigurationManager.AppSettings[CurrDbCode].ToString();
- DataRow row = ds.Tables[0].Rows[0];
- dbconn = new SqlConnection(connstr);
- dbconn.Open();
- StringBuilder sqlstr = new StringBuilder(100);
- SqlTransaction mytrans = dbconn.BeginTransaction();
- SqlCommand scmd = dbconn.CreateCommand();
- scmd.Transaction = mytrans;
-
- DataSet tempds = ds.Clone();
- DataRow[] rows = ds.Tables["McaSecVMst"].Select("", "ID");
- foreach (DataRow temprow in rows)
- {
- tempds = ds.Clone();
- tempds.Tables["McaSecVMst"].ImportRow(temprow);
- if(ds.Tables.Contains("oaa"))
- {
- DataRow[] ttrows = ds.Tables["oaa"].Select("主档ID="+temprow["ID"].ToString());
- foreach(DataRow ttrow in ttrows)
- {
- tempds.Tables["oaa"].ImportRow(ttrow);
- }
- }
- if (ds.Tables.Contains("oab"))
- {
- DataRow[] ttrows = ds.Tables["oab"].Select("主档ID=" + temprow["ID"].ToString());
- foreach (DataRow ttrow in ttrows)
- {
- tempds.Tables["oab"].ImportRow(ttrow);
- }
- }
- int result = IMcaSecVMst(scmd, tempds, ref errorinfo);
- if(result<=0)
- {
- mytrans.Rollback();
- return -1;
- }
- }
- mytrans.Commit();
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- finally
- {
- if (dbconn != null)
- dbconn.Close();
- }
- }
- public int IMcaSecVMst(DataSet ds, ref string errorinfo)
- {
- SqlConnection dbconn = null;
- try
- {
- string connstr= System.Configuration.ConfigurationManager.AppSettings[CurrDbCode].ToString();
- DataRow row = ds.Tables[0].Rows[0];
- dbconn = new SqlConnection(connstr);
- dbconn.Open();
- StringBuilder sqlstr = new StringBuilder(100);
- SqlTransaction mytrans= dbconn.BeginTransaction();
- SqlCommand scmd = dbconn.CreateCommand();
- scmd.Transaction = mytrans;
- int result = JudgeEventSame(scmd, ds, ref errorinfo);
- if (result < 0)
- {
- mytrans.Rollback();
- return -1;
- }
- int mstid = 0;
- if (result == 0)
- {
- mstid = IMcaSecVMst(scmd, ds.Tables["McaSecVMst"].Rows[0], ref errorinfo);
- if (mstid < 0)
- {
- mytrans.Rollback();
- return -1;
- }
- if (int.Parse(ds.Tables["McaSecVMst"].Rows[0]["FType"].ToString()) > 0)
- {
- //DataSet tempds = MsgPackage.MsgPackage.BytesToDataSet((byte[])ds.Tables["McaSecVMst"].Rows[0]["fcon"], ref errorinfo);
- result = IMcaSecVDetail(scmd, ds.Tables["oab"], mstid, ref errorinfo);
- if (result < 0)
- {
- mytrans.Rollback();
- return -1;
- }
- }
- }
- else
- {
- //说明事件已经存在,只需添加时间明细
- mstid = result;
- }
- DateTime ptime = (DateTime)ds.Tables["McaSecVMst"].Rows[0]["ptime"];
- result = IMcaSecTime(scmd, mstid, ptime
- , long.Parse(ds.Tables["McaSecVMst"].Rows[0]["OrgFNum"].ToString()), ref errorinfo);
- if (result <= 0)
- {
- mytrans.Rollback();
- return -1;
- }
- mytrans.Commit();
- return mstid;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- finally
- {
- if (dbconn != null)
- dbconn.Close();
- }
- }
- public int IMcaSecVMst(SqlCommand scmd,DataSet ds, ref string errorinfo)
- {
- try
- {
- DataRow row = ds.Tables["McaSecVMst"].Rows[0];
- StringBuilder sqlstr = new StringBuilder(100);
- int result = JudgeEventSame(scmd, ds, ref errorinfo);
- if (result < 0)
- {
- return -1;
- }
- int mstid = 0;
- if (result == 0)
- {
- mstid = IMcaSecVMst(scmd, ds.Tables["McaSecVMst"].Rows[0], ref errorinfo);
- if (mstid < 0)
- {
- return -1;
- }
- if (int.Parse(ds.Tables["McaSecVMst"].Rows[0]["FType"].ToString()) > 0)
- {
- result = IMcaSecVDetail(scmd, ds.Tables["oab"], mstid, ref errorinfo);
- if (result < 0)
- {
- return -1;
- }
- }
- }
- else
- {
- //说明事件已经存在,只需添加时间明细
- mstid = result;
- }
- DateTime ptime = (DateTime)ds.Tables["McaSecVMst"].Rows[0]["ptime"];
- result = IMcaSecTime(scmd, mstid, ptime
- , long.Parse(ds.Tables["McaSecVMst"].Rows[0]["OrgFNum"].ToString()), ref errorinfo);
- if (result <= 0)
- {
- return -1;
- }
- return mstid;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- //判断事件是否与最后事件相同,返回值为该机台最后事件记录ID值
- public static int JudgeEventSame(SqlCommand scmd, DataSet ds, ref string errorinfo)
- {
- try
- {
- //说明不是事件,直接返回
- if (!ds.Tables.Contains("oab"))
- return 0;
- DataRow mainrow = ds.Tables["McaSecVMst"].Rows[0];
- string mcacode = mainrow["McaCode"].ToString();
- StringBuilder sqlstr = new StringBuilder(100);
- sqlstr.AppendFormat("select a.id,a.eventcode from mcasecvmst as a where a.id = (select MAX(id) from mcasecvmst where mcacode = '{0}')", mcacode);
- scmd.CommandText = sqlstr.ToString();
- SqlDataAdapter sda = new SqlDataAdapter(scmd);
- DataSet reds = new DataSet();
- sda.Fill(reds, "mcasecvmst");
- if (reds.Tables[0].Rows.Count <= 0)
- return 0;
- string eventcode = reds.Tables[0].Rows[0]["eventcode"].ToString();
- if (eventcode != mainrow["eventcode"].ToString())
- return 0;
- int preid = int.Parse(reds.Tables[0].Rows[0]["id"].ToString());
- //读取事件明细
- sqlstr.Clear();
- sqlstr.AppendFormat("select fcode,fval from McaSecVDetail where preid={0} order by fcode", preid);
- scmd.CommandText = sqlstr.ToString();
- sda.Fill(reds, "McaSecVDetail");
- DataRow[] orgrows = ds.Tables["oab"].Select("", "参数代码");
- if (orgrows.Length != reds.Tables[0].Rows.Count)
- return 0;
- for (int i = 0; i < orgrows.Length; i++)
- {
- if (orgrows[i]["参数代码"].ToString() != reds.Tables[0].Rows[i]["fcode"].ToString())
- return 0;
- if (orgrows[i]["数据内容"].ToString() != reds.Tables[0].Rows[i]["fval"].ToString())
- return 0;
- }
- return preid;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public static int IMcaSecVMst(SqlCommand scmd, DataRow row, ref string errorinfo)
- {
- try
- {
- StringBuilder sqlstr = new StringBuilder(100);
- 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
- scmd.CommandText = sqlstr.ToString();
- SqlDataAdapter sda = new SqlDataAdapter(scmd);
- SqlCommandBuilder ocb = new SqlCommandBuilder(sda);
- sda.InsertCommand = ocb.GetInsertCommand();
- sda.UpdateCommand = ocb.GetUpdateCommand();
- sda.DeleteCommand = ocb.GetDeleteCommand();
- DataSet reds = new DataSet();
- sda.Fill(reds, "McaSecVMst");
- DataRow orgrow = reds.Tables[0].NewRow();
- reds.Tables[0].Rows.Add(orgrow);
- //orgrow["id"] = row["id"];
- orgrow["McaCode"] = row["McaCode"];
- orgrow["ptime"] = row["ptime"];
- orgrow["EventID"] = row["EventID"];
- //orgrow["OrgFNum"] = row["OrgFNum"];
- orgrow["FType"] = row["FType"];
- orgrow["FStatus"] = row["FStatus"];
- orgrow["eventcode"] = row["eventcode"];
- orgrow["pMill"] = DateTime.Parse(row["ptime"].ToString()).Millisecond;
- int result = sda.Update(reds, "McaSecVMst");
- if (result < 0)
- {
- return -1;
- }
- //sqlstr.Clear();
- //sqlstr.AppendFormat("select SCOPE_IDENTITY()");//返回为当前会话和当前作用域中的某个表生成的最新标识值。
- //scmd.CommandText = sqlstr.ToString();
- //sda = new SqlDataAdapter(scmd);
- //reds = new DataSet();
- //sda.Fill(reds, "McaSecVMst");
- //sqlstr.Clear();
- //sqlstr.AppendFormat("select @@identity");//返回为跨所有作用域的当前会话中的某个表生成的最新标识值。
- //scmd.CommandText = sqlstr.ToString();
- //sda = new SqlDataAdapter(scmd);
- //reds = new DataSet();
- //sda.Fill(reds, "McaSecVMst");
- sqlstr.Clear();
- sqlstr.AppendFormat("select IDENT_CURRENT('McaSecVMst')");//返回为某个会话和用域中的指定表生成的最新标识值。
- scmd.CommandText = sqlstr.ToString();
- sda = new SqlDataAdapter(scmd);
- reds = new DataSet();
- sda.Fill(reds, "McaSecVMst");
-
- return int.Parse(reds.Tables[0].Rows[0][0].ToString());
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- //新增McaSecVDetail
- private static int IMcaSecVDetail(SqlCommand scmd, DataTable detaildt, int preid, ref string errorinfo)
- {
- try
- {
- StringBuilder sqlstr = new StringBuilder(100);
- int result = 0;
- sqlstr.Clear();
- sqlstr.AppendFormat("select a.PreID,a.FCode,a.ID,a.FVal from McaSecVDetail a where a.id=0");
- scmd.CommandText = sqlstr.ToString();
- SqlDataAdapter sda = new SqlDataAdapter(scmd);
- SqlCommandBuilder ocb = new SqlCommandBuilder(sda);
- sda.InsertCommand = ocb.GetInsertCommand();
- sda.UpdateCommand = ocb.GetUpdateCommand();
- sda.DeleteCommand = ocb.GetDeleteCommand();
- DataSet reds = new DataSet();
- sda.Fill(reds, "McaSecVDetail");
- DataRow[] temprows = detaildt.Select();
- DataRow orgrow = null;
- foreach (DataRow temprow in temprows)
- {
- orgrow = reds.Tables[0].NewRow();
- reds.Tables[0].Rows.Add(orgrow);
- orgrow["PreID"] = preid;
- orgrow["FCode"] = temprow["参数代码"];
- orgrow["FVal"] = temprow["数据内容"];
- }
- result = sda.Update(reds, "McaSecVDetail");
- if (result < 0)
- {
- return -1;
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- public static int IMcaSecTime(SqlCommand scmd, int preid, DateTime ptime, long fnum, ref string errorinfo)
- {
- try
- {
- StringBuilder sqlstr = new StringBuilder(100);
- sqlstr.AppendFormat("select a.preid,a.ptime,a.pMill,a.OrgFNum,a.id from McaSecTime a where a.id=0");
- scmd.CommandText = sqlstr.ToString();
- SqlDataAdapter sda = new SqlDataAdapter(scmd);
- SqlCommandBuilder ocb = new SqlCommandBuilder(sda);
- sda.InsertCommand = ocb.GetInsertCommand();
- sda.UpdateCommand = ocb.GetUpdateCommand();
- sda.DeleteCommand = ocb.GetDeleteCommand();
- DataSet reds = new DataSet();
- sda.Fill(reds, "McaSecTime");
-
- DataRow orgrow = reds.Tables[0].NewRow();
- reds.Tables[0].Rows.Add(orgrow);
- orgrow["preid"] = preid;
- orgrow["ptime"] = ptime;
- orgrow["OrgFNum"] = fnum;
- orgrow["pMill"] = ptime.Millisecond;
- int result = sda.Update(reds, "McaSecTime");
- if (result < 0)
- {
- return -1;
- }
- //更新主档事件数量
- sqlstr.Clear();
- //sqlstr.AppendFormat("update mcasecvmst ");
- //sqlstr.AppendFormat(" set fcount = (select COUNT(b.id) from McaSecTime b where b.preid = mcasecvmst.id)");
- //sqlstr.AppendFormat(",etime={0},eMill={1}",ptime,ptime.Millisecond);
- //sqlstr.AppendFormat(" where id = {0}",preid);
- sqlstr.AppendFormat("update a");
- sqlstr.AppendFormat(" set a.fcount = (select COUNT(b.id) from McaSecTime b where b.preid = a.id)");
- sqlstr.AppendFormat(",a.etime=CONVERT(datetime,'{0}',20),a.eMill={1}", ptime.ToString("yyyy-MM-dd HH:mm:ss.fff"), ptime.Millisecond);
- sqlstr.AppendFormat(" from mcasecvmst a");
- sqlstr.AppendFormat(" where a.id = {0}", preid);
- scmd.CommandText = sqlstr.ToString();
- result = scmd.ExecuteNonQuery();
- if (result < 0)
- return -1;
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- /// <summary>
- /// 读取所有机台最后一次事件
- /// </summary>
- /// <param name="ds"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public DataSet ReadLastMcaSecVMst(ref string errorinfo)
- {
- SqlConnection dbconn = null;
- try
- {
- string connstr = System.Configuration.ConfigurationManager.AppSettings[CurrDbCode].ToString();
- dbconn = new SqlConnection(connstr);
- dbconn.Open();
- StringBuilder sqlstr = new StringBuilder(100);
- SqlTransaction mytrans = dbconn.BeginTransaction();
- SqlCommand scmd = dbconn.CreateCommand();
- scmd.Transaction = mytrans;
- 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");
- sqlstr.AppendFormat(" from McaSecVMst a");
- sqlstr.AppendFormat(" inner");
- sqlstr.AppendFormat(" join");
- sqlstr.AppendFormat(" (SELECT McaCode");
- sqlstr.AppendFormat(" , max(ptime)maxtime");
- sqlstr.AppendFormat(" FROM McaSecVMst");
- sqlstr.AppendFormat(" group by McaCode) b on a.McaCode = b.McaCode and a.ptime = b.maxtime");
- scmd.CommandText = sqlstr.ToString();
- SqlDataAdapter sda = new SqlDataAdapter(scmd);
- DataSet reds = new DataSet();
- sda.Fill(reds, "McaSecVMst");
- sqlstr.Clear();
- sqlstr.AppendFormat("SELECT TOP 0 a.ID,a.PreID,a.FCode,a.FVal,a.fnum FROM McaSecVDetail a");
- sqlstr.AppendFormat(" inner join(select a.ID");
- sqlstr.AppendFormat(" from McaSecVMst a");
- sqlstr.AppendFormat(" inner");
- sqlstr.AppendFormat(" join");
- sqlstr.AppendFormat(" (SELECT McaCode");
- sqlstr.AppendFormat(" , max(ptime)maxtime");
- sqlstr.AppendFormat(" FROM McaSecVMst");
- sqlstr.AppendFormat(" group by McaCode) b on a.McaCode = b.McaCode and a.ptime = b.maxtime) c on a.preid=c.id");
- scmd.CommandText = sqlstr.ToString();
- sda = new SqlDataAdapter(scmd);
- DataTable tempdt = new DataTable("McaSecVDetail");
- sda.Fill(tempdt);
- reds.Merge(tempdt);
- sqlstr.Clear();
- sqlstr.AppendFormat("SELECT TOP 0 a.ID,a.PreID,a.ptime,a.pMill,a.OrgFNum FROM McaSecTime a");
- scmd.CommandText = sqlstr.ToString();
- sda = new SqlDataAdapter(scmd);
- tempdt = new DataTable("McaSecTime");
- sda.Fill(tempdt);
- reds.Merge(tempdt);
- mytrans.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- finally
- {
- if (dbconn != null)
- dbconn.Close();
- }
- }
- public int BatIMcaSecVMst01(DataSet ds, ref string errorinfo)
- {
- SqlConnection dbconn = null;
- try
- {
- string connstr = System.Configuration.ConfigurationManager.AppSettings[CurrDbCode].ToString();
- DataRow row = ds.Tables[0].Rows[0];
- dbconn = new SqlConnection(connstr);
- dbconn.Open();
- StringBuilder sqlstr = new StringBuilder(100);
- SqlTransaction mytrans = dbconn.BeginTransaction();
- //SqlCommand scmd = dbconn.CreateCommand();
- //scmd.Transaction = mytrans;
- DataTable mstdt = ds.Tables["McaSecVMst"].Clone();
- DataRow[] rows = ds.Tables["McaSecVMst"].Select("", "", DataViewRowState.Added);
- foreach (DataRow temprow in rows)
- mstdt.ImportRow(temprow);
- mstdt.Columns.Remove("islast");
- SqlBulkCopy bulkCopy = new SqlBulkCopy(dbconn,SqlBulkCopyOptions.CheckConstraints,mytrans);
-
- bulkCopy.DestinationTableName = mstdt.TableName;
- bulkCopy.BatchSize = mstdt.Rows.Count;
- bulkCopy.WriteToServer(mstdt);
- mstdt = ds.Tables["McaSecVDetail"].Clone();
- rows = ds.Tables["McaSecVDetail"].Select("", "", DataViewRowState.Added);
- foreach (DataRow temprow in rows)
- mstdt.ImportRow(temprow);
- bulkCopy = new SqlBulkCopy(dbconn, SqlBulkCopyOptions.CheckConstraints, mytrans);
- bulkCopy.DestinationTableName = mstdt.TableName;
- bulkCopy.BatchSize = mstdt.Rows.Count;
- bulkCopy.WriteToServer(mstdt);
- mstdt = ds.Tables["McaSecTime"].Clone();
- rows = ds.Tables["McaSecTime"].Select("", "", DataViewRowState.Added);
- foreach (DataRow temprow in rows)
- mstdt.ImportRow(temprow);
- bulkCopy = new SqlBulkCopy(dbconn, SqlBulkCopyOptions.CheckConstraints, mytrans);
- bulkCopy.DestinationTableName = mstdt.TableName;
- bulkCopy.BatchSize = mstdt.Rows.Count;
- bulkCopy.WriteToServer(mstdt);
- mytrans.Commit();
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- finally
- {
- if (dbconn != null)
- dbconn.Close();
- }
- }
- public DataSet ReadSecMstDs(ref string errorinfo)
- {
- IDatabase db = null;
- try
- {
- DataSet reds = new DataSet();
- db = DbFactory.Base(CurrMySqlCode);
- db.BeginTrans();
- //读取机台关联事件信息
- StringBuilder sqlstr = new StringBuilder(100);
- sqlstr.AppendFormat("select distinct a.FNum,a.EventReportMstID,b.EventID,c.FVal,w.fcode 参数代码,m.mc10 机台编号");
- sqlstr.AppendFormat(" from SecMstEvent a");
- sqlstr.AppendFormat(" inner join EventReportMst b on a.EventReportMstID = b.id");
- sqlstr.AppendFormat(" inner join SecDetail c on b.EventID = c.SecID and c.PreID = a.SecMstID");
- sqlstr.AppendFormat(" inner join McaEvent d on a.SecMstID = d.PreID");
- sqlstr.AppendFormat(" inner join Sec w on b.EventID = w.ID");
- sqlstr.AppendFormat(" inner join mca m on d.mcaid=m.id");
- //sqlstr.AppendFormat(" where d.McaID = {0}", mcaid);
- DataTable tempdt = db.FindTableFor(sqlstr.ToString(), "SecMstEvent");
- reds.Merge(tempdt);
- //读取机台事件关联报告信息
- sqlstr.Clear();
- sqlstr.AppendFormat("select distinct t.FNum,a.EventReportMstID,t.ReportMstID,c.FVal,m.mc10 机台编号");
- sqlstr.AppendFormat(" from EventReportDetail t");
- sqlstr.AppendFormat(" inner join SecMstEvent a on t.preid=a.EventReportMstID");
- sqlstr.AppendFormat(" inner join EventReportMst b on a.EventReportMstID = b.id");
- sqlstr.AppendFormat(" inner join SecDetail c on b.EventID = c.SecID and c.PreID = a.SecMstID");
- sqlstr.AppendFormat(" inner join McaEvent d on a.SecMstID = d.PreID");
- sqlstr.AppendFormat(" inner join mca m on d.mcaid=m.id");
- //sqlstr.AppendFormat(" where d.McaID = {0}", mcaid);
- tempdt = db.FindTableFor(sqlstr.ToString(), "EventReportDetail");
- reds.Merge(tempdt);
- //读取机台报告关联参数指令
- sqlstr.Clear();
- sqlstr.AppendFormat("select distinct z.FNum,z.SecID,z.PreID ReportMstID,c.FVal,w.FCode 参数代码,c.dcode 参数类型,m.mc10 机台编号");
- sqlstr.AppendFormat(" from ReportDetail z");
- sqlstr.AppendFormat(" inner join EventReportDetail t on z.PreID=t.ReportMstID");
- sqlstr.AppendFormat(" inner join SecMstEvent a on t.preid=a.EventReportMstID");
- sqlstr.AppendFormat(" inner join EventReportMst b on a.EventReportMstID = b.id");
- sqlstr.AppendFormat(" inner join SecDetail c on z.SecID = c.SecID and c.PreID = a.SecMstID");
- sqlstr.AppendFormat(" inner join McaEvent d on a.SecMstID = d.PreID");
- sqlstr.AppendFormat(" inner join Sec w on z.SecID = w.ID");
- sqlstr.AppendFormat(" inner join mca m on d.mcaid=m.id");
- //sqlstr.AppendFormat(" where d.McaID = {0}", mcaid);
- tempdt = db.FindTableFor(sqlstr.ToString(), "ReportDetail");
- reds.Merge(tempdt);
- sqlstr.Clear();
- sqlstr.AppendFormat("select distinct a.id,a.SVal,a.FVal,m.mc10 机台编号 from McaDynamicMst as a");
- sqlstr.AppendFormat(" inner join McaEvent as b on a.PreID = b.PreID");
- sqlstr.AppendFormat(" inner join mca m on b.mcaid=m.id");
- //sqlstr.AppendFormat(" where b.McaID = {0}", mcaid);
- tempdt = db.FindTableFor(sqlstr.ToString(), "McaDynamicMst");
- reds.Merge(tempdt);
- sqlstr.Clear();
- sqlstr.AppendFormat("select distinct f.FCode 参数代码,t.fnum 序号,d.fval 参数值,d.dcode 数据类型代码,t.preid,m.mc10 机台编号 from McaDynamicDetail as t");
- sqlstr.AppendFormat(" inner join McaDynamicMst as a on t.PreID = a.id");
- sqlstr.AppendFormat(" inner join McaEvent as b on a.PreID = b.PreID");
- sqlstr.AppendFormat(" inner join SecDetail d on a.preid = d.PreID and t.SecID = d.SecID");
- sqlstr.AppendFormat(" inner join Sec f on t.SecID = f.id");
- sqlstr.AppendFormat(" inner join mca m on b.mcaid=m.id");
- //sqlstr.AppendFormat(" where b.McaID = {0}", mcaid);
- tempdt = db.FindTableFor(sqlstr.ToString(), "McaDynamicDetail");
- reds.Merge(tempdt);
- db.Commit();
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- finally
- {
- if (db != null)
- db.Close();
- }
- }
- }
- }
|