/EQT_V2/EQT/EQT.DAL/DaTestItem.add.cs
C# | 278 lines | 210 code | 19 blank | 49 comment | 17 complexity | 0674ca1abc4ce21146be4ee12aaa719e MD5 | raw file
Possible License(s): LGPL-2.1
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Globalization;
- using System.Text;
- using System.Xml;
- using System.Data.Common;
- using Microsoft.Practices.EnterpriseLibrary.Data;
- using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
- using EQT.Model;
-
- namespace EQT.Dal
- {
- public partial class DaTestItem //?????????,ITestItem
- {
-
- /// <summary>
- /// ??????,??.
- /// </summary>
- /// <param name="itemid"></param>
- /// <returns></returns>
- public bool DeleteTestItem(string itemid)
- {
- bool rc = false;
- using (DbConnection cnn = db.CreateConnection())
- {
- DbTransaction trans = null;
- try
- {
- cnn.Open();
- using (trans = cnn.BeginTransaction())
- {
-
- //??????
- this.DeleteByWhereClause(String.Format(" WHERE ITEM_CODE='{0}'",itemid), trans);
- //???????
- string strSQL = "DELETE FROM TEST_CATALOG WHERE TEST_CTG_ID='" + itemid + "'";
- db.ExecuteNonQuery(trans, CommandType.Text, strSQL);
- //????????????
-
- trans.Commit();
- }
- cnn.Close();
- rc = true;
- }
- catch (DbException ex)
- {
- if (trans != null) trans.Rollback();
- HandleDbException(ex);
- }
- }
- return rc;
- }
-
- /// <summary>
- /// ??????,??.
- /// </summary>
- /// <param name="modCatalog"></param>
- /// <param name="modItem"></param>
- /// <returns></returns>
- public bool AddTestItem(MoTestCatalog modCatalog,MoTestItem modItem)
- {
- bool rc = false;
- using (DbConnection cnn = db.CreateConnection())
- {
- DbTransaction trans = null;
- try
- {
- cnn.Open();
- using (trans = cnn.BeginTransaction())
- {
-
- //???????
- this.Add(modItem, trans);
- //??????
- DaTestCatalog dacatalog = new DaTestCatalog(db);
- dacatalog.Add(modCatalog, trans);
- trans.Commit();
- }
- cnn.Close();
- rc = true;
- }
- catch (DbException ex)
- {
- if (trans != null) trans.Rollback();
- HandleDbException(ex);
- }
- }
- return rc;
- }
-
- /// <summary>
- /// ??????,??.
- /// </summary>
- /// <param name="modCatalog"></param>
- /// <param name="modItem"></param>
- /// <returns></returns>
- public bool UpdateTestItem(MoTestCatalog modCatalog, MoTestItem modItem)
- {
- bool rc = false;
- using (DbConnection cnn = db.CreateConnection())
- {
- DbTransaction trans = null;
- try
- {
- cnn.Open();
- using (trans = cnn.BeginTransaction())
- {
-
- //???????
- this.Update(modItem, trans);
- //??????
- DaTestCatalog dacatalog = new DaTestCatalog(db);
- dacatalog.Update(modCatalog, trans);
- trans.Commit();
- }
- cnn.Close();
- rc = true;
- }
- catch (DbException ex)
- {
- if (trans != null) trans.Rollback();
- HandleDbException(ex);
- }
- }
- return rc;
- }
-
- /// <summary>
- /// ????????doc,xls???
- /// </summary>
- /// <param name="ItemID"></param>
- /// <returns></returns>
- public DataSet QueryFileTemplate(string ItemID)
- {
- DataSet ds=new DataSet();
- string strSQL = "SELECT m.*, (SELECT File_Name FROM TFiles WHERE File_ID = m.Doc_Url) AS docname,"+
- "(SELECT File_Name FROM TFiles WHERE File_ID = m.Xls_Url) AS xlsname"+
- " FROM File_Template m LEFT OUTER JOIN"+
- " Ref_File ref ON m.Item_Code = ref.EID LEFT OUTER JOIN"+
- " Test_Item i ON m.Item_Code = i.Item_Code where m.item_code='"+ItemID+"'";
- try
- {
- ds = db.ExecuteDataSet(CommandType.Text, strSQL);
- }
- catch (DbException ex)
- {
- HandleDbException(ex);
- }
- return ds;
- }
-
- /// <summary>
- /// ???????????
- /// </summary>
- /// <param name="templateid"></param>
- /// <returns></returns>
- public bool DeleteItemTemplate(string templateid)
- {
- bool rc = false;
- using (DbConnection cnn = db.CreateConnection())
- {
- DbTransaction trans = null;
- try
- {
- cnn.Open();
- using (trans = cnn.BeginTransaction())
- {
- DaFileTemplate daTemplate = new DaFileTemplate();
- DaRefFile daRef = new DaRefFile();
- DaTfiles daFile = new DaTfiles();
- //????
- string strDelRefFile = "delete from ref_file where eid='" + templateid + "'";
- db.ExecuteNonQuery(trans, CommandType.Text, strDelRefFile);
-
- MoFileTemplate modtemplate = new MoFileTemplate();
- modtemplate.FtId = templateid;
-
- //????
- if (daTemplate.GetEntityEx(ref modtemplate))
- {
- daFile.DeleteByWhereClause(String.Format(" WHERE FILE_ID='{0}'", modtemplate.DocUrl), trans);
- daFile.DeleteByWhereClause(String.Format(" WHERE FILE_ID='{0}'", modtemplate.XlsUrl),trans);
- }
- //????
- string strDelTemplate = "delete from File_Template where FT_ID='"+templateid+"'";
- db.ExecuteNonQuery(trans, CommandType.Text, strDelTemplate);
-
-
- trans.Commit();
- }
- cnn.Close();
- rc = true;
- }
- catch (DbException ex)
- {
- if (trans != null) trans.Rollback();
- HandleDbException(ex);
- }
- }
- return rc;
- }
-
- /// <summary>
- /// ??????Doc???
- /// </summary>
- /// <param name="motf"></param>
- /// <param name="morf"></param>
- /// <returns></returns>
- public int AddTemplateDoc(MoTfiles motf, MoRefFile morf)
- {
- if (motf == null || morf == null) return 0;
- int rc = 0;
- using (DbConnection conn = db.CreateConnection())
- {
- try
- {
- conn.Open();
- using (DbTransaction trans = conn.BeginTransaction())
- {
- DaRefFile darf = new DaRefFile(db);
- DaTfiles daf = new DaTfiles(db);
- rc += daf.Add(motf, trans);
- rc += darf.Add(morf, trans);
- string sql = "update File_Template set doc_url='" + motf.FileId + "' where FT_ID='" + morf.Eid + "'";
- db.ExecuteNonQuery(trans, CommandType.Text, sql);
- trans.Commit();
- }
- conn.Close();
- }
- catch (DbException de)
- {
-
- throw new DalException("??????????????" + motf.ToString() + "\r\n" + morf.ToString(), de);
- }
- }
- return rc;
- }
-
- /// <summary>
- /// ??????Xls???
- /// </summary>
- /// <param name="motf"></param>
- /// <param name="morf"></param>
- /// <returns></returns>
- public int AddTemplateXls(MoTfiles motf, MoRefFile morf)
- {
- if (motf == null || morf == null) return 0;
- int rc = 0;
- using (DbConnection conn = db.CreateConnection())
- {
- try
- {
- conn.Open();
- using (DbTransaction trans = conn.BeginTransaction())
- {
- DaRefFile darf = new DaRefFile(db);
- DaTfiles daf = new DaTfiles(db);
- rc += daf.Add(motf, trans);
- rc += darf.Add(morf, trans);
- string sql = "update File_Template set xls_url='" + motf.FileId + "' where FT_ID='"+morf.Eid+"'";
- db.ExecuteNonQuery(trans, CommandType.Text, sql);
- trans.Commit();
- }
- conn.Close();
- }
- catch (DbException de)
- {
-
- throw new DalException("??????????????" + motf.ToString() + "\r\n" + morf.ToString(), de);
- }
- }
- return rc;
- }
- }
- }
-