Esempio n. 1
0
        public void Parse(string fileName)
        {
            Application xlApp;
            Workbook    xlWorkBook;
            Worksheet   xlWorkSheet;

            ADOTemplate template = new ADOTemplate();

            xlApp      = new ApplicationClass();
            xlWorkBook = xlApp.Workbooks.Open(fileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

            for (int iSheet = 1; iSheet <= xlWorkBook.Worksheets.Count; iSheet++)
            {
                xlWorkSheet = (Worksheet)xlWorkBook.Worksheets.get_Item(iSheet);
                range       = xlWorkSheet.UsedRange;

                rowCount = range.Rows.Count;
                if (rowCount < 2)
                {
                    continue;
                }

                colCount = range.Columns.Count;

                this.ReadConfig();

                this.ReadColumns();

                IDbTransaction Transaction = null;
                using (IDbConnection connection = DBUtil.GetConnection(dbName))
                {
                    try
                    {
                        connection.Open();

                        Transaction = connection.BeginTransaction();

                        new TransactionContext(connection, Transaction, ConfigCache.GetDBType(dbName));

                        for (int iRow = 2; iRow <= rowCount; iRow++)
                        {
                            Hashtable data = this.ReadDataRow(iRow);

                            string op = (string)data["$op"];

                            if ("s".Equals(op))
                            {
                                template.Execute((string)data["$sql"], null, null);
                            }
                            else if ("i".Equals(op))
                            {
                                template.Execute(this.insertSql, data);
                            }
                            else if ("d".Equals(op))
                            {
                                template.Execute(this.deleteSql, data);
                            }
                        }

                        Transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        if (Transaction != null)
                        {
                            Transaction.Rollback();
                        }
                        throw e;
                    }
                    finally
                    {
                        if (connection != null && ConnectionState.Open == connection.State)
                        {
                            connection.Close();
                        }
                    }
                }

                ReleaseObject(xlWorkSheet);
            }

            xlWorkBook.Close(true, null, null);
            xlApp.Quit();

            ReleaseObject(xlWorkBook);
            ReleaseObject(xlApp);
        }
Esempio n. 2
0
 public virtual int Execute(string sql, String[] paramNames, Object[] paramValues)
 {
     return(template.Execute(sql, paramNames, paramValues));
 }