PageRenderTime 32ms CodeModel.GetById 24ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/EQT_V2/EQT/EQT.DAL/DaTestItem.add.cs

http://sgsoft-las.googlecode.com/
C# | 278 lines | 210 code | 19 blank | 49 comment | 17 complexity | 0674ca1abc4ce21146be4ee12aaa719e MD5 | raw file
Possible License(s): LGPL-2.1
  1using System;
  2using System.Collections;
  3using System.Collections.Generic;
  4using System.Data;
  5using System.Globalization;
  6using System.Text;
  7using System.Xml;
  8using System.Data.Common;
  9using Microsoft.Practices.EnterpriseLibrary.Data;
 10using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
 11using EQT.Model;
 12
 13namespace EQT.Dal
 14{
 15    public partial class DaTestItem   //?????????,ITestItem 
 16    {
 17
 18        /// <summary>
 19        /// ??????,??.
 20        /// </summary>
 21        /// <param name="itemid"></param>
 22        /// <returns></returns>
 23        public bool DeleteTestItem(string itemid)
 24        {
 25            bool rc = false;
 26            using (DbConnection cnn = db.CreateConnection())
 27            {
 28                DbTransaction trans = null;
 29                try
 30                {
 31                    cnn.Open();
 32                    using (trans = cnn.BeginTransaction())
 33                    {
 34                        
 35                        //??????
 36                        this.DeleteByWhereClause(String.Format(" WHERE ITEM_CODE='{0}'",itemid), trans);
 37                        //???????
 38                        string strSQL = "DELETE FROM TEST_CATALOG  WHERE TEST_CTG_ID='" + itemid + "'";
 39                        db.ExecuteNonQuery(trans, CommandType.Text, strSQL);
 40                        //????????????
 41                        
 42                        trans.Commit();
 43                    }
 44                    cnn.Close();
 45                    rc = true;
 46                }
 47                catch (DbException ex)
 48                {
 49                    if (trans != null) trans.Rollback();
 50                    HandleDbException(ex);
 51                }
 52            }
 53            return rc;
 54        }
 55
 56        /// <summary>
 57        /// ??????,??.
 58        /// </summary>
 59        /// <param name="modCatalog"></param>
 60        /// <param name="modItem"></param>
 61        /// <returns></returns>
 62        public bool AddTestItem(MoTestCatalog modCatalog,MoTestItem modItem)
 63        {
 64            bool rc = false;
 65            using (DbConnection cnn = db.CreateConnection())
 66            {
 67                DbTransaction trans = null;
 68                try
 69                {
 70                    cnn.Open();
 71                    using (trans = cnn.BeginTransaction())
 72                    {
 73
 74                        //???????
 75                        this.Add(modItem, trans);
 76                        //??????
 77                        DaTestCatalog dacatalog = new DaTestCatalog(db);
 78                        dacatalog.Add(modCatalog, trans);
 79                        trans.Commit();
 80                    }
 81                    cnn.Close();
 82                    rc = true;
 83                }
 84                catch (DbException ex)
 85                {
 86                    if (trans != null) trans.Rollback();
 87                    HandleDbException(ex);
 88                }
 89            }
 90            return rc;
 91        }
 92
 93        /// <summary>
 94        /// ??????,??.
 95        /// </summary>
 96        /// <param name="modCatalog"></param>
 97        /// <param name="modItem"></param>
 98        /// <returns></returns>
 99        public bool UpdateTestItem(MoTestCatalog modCatalog, MoTestItem modItem)
100        {
101            bool rc = false;
102            using (DbConnection cnn = db.CreateConnection())
103            {
104                DbTransaction trans = null;
105                try
106                {
107                    cnn.Open();
108                    using (trans = cnn.BeginTransaction())
109                    {
110
111                        //???????
112                        this.Update(modItem, trans);
113                        //??????
114                        DaTestCatalog dacatalog = new DaTestCatalog(db);
115                        dacatalog.Update(modCatalog, trans);
116                        trans.Commit();
117                    }
118                    cnn.Close();
119                    rc = true;
120                }
121                catch (DbException ex)
122                {
123                    if (trans != null) trans.Rollback();
124                    HandleDbException(ex);
125                }
126            }
127            return rc;
128        }
129
130        /// <summary>
131        /// ????????doc,xls???
132        /// </summary>
133        /// <param name="ItemID"></param>
134        /// <returns></returns>
135        public DataSet QueryFileTemplate(string ItemID)
136        {
137            DataSet ds=new DataSet();
138            string strSQL = "SELECT m.*, (SELECT File_Name FROM TFiles WHERE File_ID = m.Doc_Url) AS docname,"+
139                            "(SELECT File_Name FROM TFiles WHERE File_ID = m.Xls_Url) AS xlsname"+
140                            " FROM File_Template m LEFT OUTER JOIN"+
141                            " Ref_File ref ON m.Item_Code = ref.EID LEFT OUTER JOIN"+
142                            " Test_Item i ON m.Item_Code = i.Item_Code where m.item_code='"+ItemID+"'";
143            try
144            {
145                ds = db.ExecuteDataSet(CommandType.Text, strSQL);
146            }
147            catch (DbException ex)
148            {
149                HandleDbException(ex);
150            }
151            return ds;
152        }
153
154        /// <summary>
155        /// ???????????
156        /// </summary>
157        /// <param name="templateid"></param>
158        /// <returns></returns>
159        public bool DeleteItemTemplate(string templateid)
160        {
161            bool rc = false;
162            using (DbConnection cnn = db.CreateConnection())
163            {
164                DbTransaction trans = null;
165                try
166                {
167                    cnn.Open();
168                    using (trans = cnn.BeginTransaction())
169                    {
170                        DaFileTemplate daTemplate = new DaFileTemplate();
171                        DaRefFile daRef = new DaRefFile();
172                        DaTfiles daFile = new DaTfiles();
173                        //????
174                        string strDelRefFile = "delete from ref_file where eid='" + templateid + "'";
175                        db.ExecuteNonQuery(trans, CommandType.Text, strDelRefFile);
176
177                        MoFileTemplate modtemplate = new MoFileTemplate();
178                        modtemplate.FtId = templateid;
179
180                        //????
181                        if (daTemplate.GetEntityEx(ref modtemplate))
182                        {
183                            daFile.DeleteByWhereClause(String.Format(" WHERE FILE_ID='{0}'", modtemplate.DocUrl), trans);
184                            daFile.DeleteByWhereClause(String.Format(" WHERE FILE_ID='{0}'", modtemplate.XlsUrl),trans);
185                        }
186                        //????
187                        string strDelTemplate = "delete from File_Template where FT_ID='"+templateid+"'";
188                        db.ExecuteNonQuery(trans, CommandType.Text, strDelTemplate);
189                        
190                        
191                        trans.Commit();
192                    }
193                    cnn.Close();
194                    rc = true;
195                }
196                catch (DbException ex)
197                {
198                    if (trans != null) trans.Rollback();
199                    HandleDbException(ex);
200                }
201            }
202            return rc;
203        }
204
205        /// <summary>
206        /// ??????Doc???
207        /// </summary>
208        /// <param name="motf"></param>
209        /// <param name="morf"></param>
210        /// <returns></returns>
211        public int AddTemplateDoc(MoTfiles motf, MoRefFile morf)
212        {
213            if (motf == null || morf == null) return 0;
214            int rc = 0;
215            using (DbConnection conn = db.CreateConnection())
216            {
217                try
218                {
219                    conn.Open();
220                    using (DbTransaction trans = conn.BeginTransaction())
221                    {
222                        DaRefFile darf = new DaRefFile(db);
223                        DaTfiles daf = new DaTfiles(db);
224                        rc += daf.Add(motf, trans);
225                        rc += darf.Add(morf, trans);
226                        string sql = "update File_Template set doc_url='" + motf.FileId + "' where FT_ID='" + morf.Eid + "'";
227                        db.ExecuteNonQuery(trans, CommandType.Text, sql);
228                        trans.Commit();
229                    }
230                    conn.Close();
231                }
232                catch (DbException de)
233                {
234
235                    throw new DalException("??????????????" + motf.ToString() + "\r\n" + morf.ToString(), de);
236                }
237            }
238            return rc;
239        }
240
241        /// <summary>
242        /// ??????Xls???
243        /// </summary>
244        /// <param name="motf"></param>
245        /// <param name="morf"></param>
246        /// <returns></returns>
247        public int AddTemplateXls(MoTfiles motf, MoRefFile morf)
248        {
249            if (motf == null || morf == null) return 0;
250            int rc = 0;
251            using (DbConnection conn = db.CreateConnection())
252            {
253                try
254                {
255                    conn.Open();
256                    using (DbTransaction trans = conn.BeginTransaction())
257                    {
258                        DaRefFile darf = new DaRefFile(db);
259                        DaTfiles daf = new DaTfiles(db);
260                        rc += daf.Add(motf, trans);
261                        rc += darf.Add(morf, trans);
262                        string sql = "update File_Template set xls_url='" + motf.FileId + "' where FT_ID='"+morf.Eid+"'";
263                        db.ExecuteNonQuery(trans, CommandType.Text, sql);
264                        trans.Commit();
265                    }
266                    conn.Close();
267                }
268                catch (DbException de)
269                {
270
271                    throw new DalException("??????????????" + motf.ToString() + "\r\n" + morf.ToString(), de);
272                }
273            }
274            return rc;
275        }
276    }
277}
278