コード例 #1
0
        public static bool InsertBulkRows(string pFileString, string pSelectSQL, System.Data.Common.DbDataReader pDataReader, SetGadgetStatusHandler pStatusDelegate = null)
        {
            bool result = false;

            string connString = ParseConnectionString(pFileString);

            if (DataSource != null)
            {
                IDbDriver driver = DataSource.CreateDatabaseObject(new System.Data.Common.DbConnectionStringBuilder());
                driver.ConnectionString = connString;
                result = driver.InsertBulkRows(pSelectSQL, pDataReader, pStatusDelegate);
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Handles the DoWorker event for the worker
        /// </summary>
        /// <param name="sender">Object that fired the event</param>
        /// <param name="e">.NET supplied event parameters</param>
        private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            lock (syncLock)
            {
                System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                stopWatch.Start();

                try
                {
                    string tableName = (string)e.Argument;

                    SetGadgetStatusHandler      requestUpdateStatus  = new SetGadgetStatusHandler(RequestUpdateStatusMessage);
                    CheckForCancellationHandler checkForCancellation = new CheckForCancellationHandler(IsCancelled);

                    if (db.TableExists(tableName))
                    {
                        db.DeleteTable(tableName);
                    }

                    List <Epi.Data.TableColumn> tcList = dashboardHelper.GetFieldsAsListOfEpiTableColumns();

                    db.CreateTable(tableName, tcList);

                    DataView dv = dashboardHelper.DataSet.Tables[0].DefaultView;

                    System.Data.Common.DbDataReader dataReader = dv.ToTable().CreateDataReader();
                    db.InsertBulkRows("Select * From [" + tableName + "]", dataReader, requestUpdateStatus, checkForCancellation);
                }
                catch (Exception ex)
                {
                    this.Dispatcher.BeginInvoke(new SetStatusDelegate(SetWarningMessage), ex.Message);
                }
                finally
                {
                    stopWatch.Stop();
                    System.Diagnostics.Debug.Print("Export thread finished in " + stopWatch.Elapsed.ToString());
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Handles the DoWorker event for the worker
        /// </summary>
        /// <param name="sender">Object that fired the event</param>
        /// <param name="e">.NET supplied event parameters</param>
        private void datadriverWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            lock (syncLock)
            {
                System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                stopWatch.Start();

                try
                {
                    string tableName = (string)e.Argument;

                    SetGadgetStatusHandler      requestUpdateStatus  = new SetGadgetStatusHandler(RequestUpdateStatusMessage);
                    CheckForCancellationHandler checkForCancellation = new CheckForCancellationHandler(IsCancelled);

                    if (db.TableExists(tableName) && !db.ConnectionDescription.ToLower().Contains("excel"))
                    {
                        db.DeleteTable(tableName);
                    }
                    else if (db.TableExists(tableName))
                    {
                        this.Dispatcher.BeginInvoke(new SetStatusDelegate(SetErrorMessage), string.Format(SharedStrings.DASHBOARD_EXPORT_EXCEL_TABLE_OVERWRITE_FAIL, tableName));
                        stopWatch.Stop();
                        return;
                    }

                    dashboardHelper.PopulateDataSet(); // the only reason to call this is to see if any new user-defined vars have been added and apply them.
                    List <Epi.Data.TableColumn> tcList = dashboardHelper.GetFieldsAsListOfEpiTableColumns(useTabOrder);
                    allFieldsSelected = false;         // TODO: Fix?

                    if (allFieldsSelected)
                    {
                        if (tcList.Count <= 250)
                        {
                            db.CreateTable(tableName, tcList);
                            DataView  dv    = dashboardHelper.DataSet.Tables[0].DefaultView;
                            DataTable table = dv.ToTable(false);
                            if (useTabOrder)
                            {
                                dashboardHelper.OrderColumns(table, true);
                            }
                            System.Data.Common.DbDataReader dataReader = table.CreateDataReader();
                            db.InsertBulkRows("Select * From [" + tableName + "]", dataReader, requestUpdateStatus, checkForCancellation);
                        }
                        else
                        {
                            Dictionary <string, List <Epi.Data.TableColumn> > fieldTableDictionary = new Dictionary <string, List <Epi.Data.TableColumn> >();
                            int totalTablesNeeded = (tcList.Count / 250) + 1;
                            int tableNumber       = 0;
                            List <Epi.Data.TableColumn> tableTcList = new List <Epi.Data.TableColumn>();
                            for (int i = 0; i < tcList.Count; i++)
                            {
                                if (i % 250 == 0)
                                {
                                    if (tableNumber != 0)
                                    {
                                        fieldTableDictionary.Add(tableName + tableNumber.ToString(), tableTcList);
                                    }
                                    tableTcList = new List <Epi.Data.TableColumn>();
                                    tableNumber++;
                                }

                                tableTcList.Add(tcList[i]);

                                if (i == tcList.Count - 1)
                                {
                                    fieldTableDictionary.Add(tableName + tableNumber.ToString(), tableTcList);
                                }
                            }

                            foreach (KeyValuePair <string, List <Epi.Data.TableColumn> > kvp in fieldTableDictionary)
                            {
                                if (db.TableExists(kvp.Key))
                                {
                                    this.Dispatcher.BeginInvoke(new SetStatusDelegate(SetErrorMessage), string.Format(SharedStrings.DASHBOARD_EXPORT_WIDE_TABLE_FAIL, totalTablesNeeded.ToString()));
                                    return;
                                }
                            }

                            foreach (KeyValuePair <string, List <Epi.Data.TableColumn> > kvp in fieldTableDictionary)
                            {
                                db.CreateTable(kvp.Key, kvp.Value);
                            }

                            foreach (KeyValuePair <string, List <Epi.Data.TableColumn> > kvp in fieldTableDictionary)
                            {
                                List <string> exportTableFields = new List <string>();
                                foreach (Epi.Data.TableColumn tc in kvp.Value)
                                {
                                    exportTableFields.Add(tc.Name);
                                }

                                DataView  dv    = dashboardHelper.DataSet.Tables[0].DefaultView;
                                DataTable table = dv.ToTable(false, exportTableFields.ToArray());
                                if (useTabOrder)
                                {
                                    dashboardHelper.OrderColumns(table, true);
                                }
                                System.Data.Common.DbDataReader dataReader = table.CreateDataReader(); //dv.ToTable().CreateDataReader();
                                db.InsertBulkRows("Select * From [" + kvp.Key + "]", dataReader, requestUpdateStatus, checkForCancellation);
                            }
                        }
                    }
                    else
                    {
                        List <Epi.Data.TableColumn> tcFilteredList = new List <Epi.Data.TableColumn>();

                        foreach (string columnName in exportFields)
                        {
                            foreach (Epi.Data.TableColumn tc in tcList)
                            {
                                if (tc.Name.Equals(columnName) && !tcFilteredList.Contains(tc))
                                {
                                    tcFilteredList.Add(tc);
                                }
                            }
                        }

                        if (tcFilteredList.Count <= 250)
                        {
                            db.CreateTable(tableName, tcFilteredList);
                            DataView  dv    = dashboardHelper.DataSet.Tables[0].DefaultView;
                            DataTable table = dv.ToTable(false, exportFields.ToArray());
                            if (useTabOrder)
                            {
                                dashboardHelper.OrderColumns(table, true);
                            }
                            System.Data.Common.DbDataReader dataReader = table.CreateDataReader(); //dv.ToTable().CreateDataReader();
                            db.InsertBulkRows("Select * From [" + tableName + "]", dataReader, requestUpdateStatus, checkForCancellation);
                        }
                        else
                        {
                            Dictionary <string, List <Epi.Data.TableColumn> > fieldTableDictionary = new Dictionary <string, List <Epi.Data.TableColumn> >();
                            int totalTablesNeeded = (tcFilteredList.Count / 250) + 1;
                            int tableNumber       = 0;
                            List <Epi.Data.TableColumn> tableTcList = new List <Epi.Data.TableColumn>();
                            for (int i = 0; i < tcFilteredList.Count; i++)
                            {
                                if (i % 250 == 0)
                                {
                                    if (tableNumber != 0)
                                    {
                                        foreach (Epi.Data.TableColumn tc in tcFilteredList)
                                        {
                                            if (tc.Name == "GlobalRecordId")
                                            {
                                                if (!tableTcList.Contains(tc))
                                                {
                                                    tableTcList.Add(tc);
                                                }
                                            }
                                        }

                                        fieldTableDictionary.Add(tableName + tableNumber.ToString(), tableTcList);
                                    }
                                    tableTcList = new List <Epi.Data.TableColumn>();
                                    tableNumber++;
                                }

                                tableTcList.Add(tcFilteredList[i]);

                                if (i == tcFilteredList.Count - 1)
                                {
                                    foreach (Epi.Data.TableColumn tc in tcFilteredList)
                                    {
                                        if (tc.Name == "GlobalRecordId")
                                        {
                                            if (!tableTcList.Contains(tc))
                                            {
                                                tableTcList.Add(tc);
                                            }
                                        }
                                    }

                                    fieldTableDictionary.Add(tableName + tableNumber.ToString(), tableTcList);
                                }
                            }

                            foreach (KeyValuePair <string, List <Epi.Data.TableColumn> > kvp in fieldTableDictionary)
                            {
                                if (db.TableExists(kvp.Key))
                                {
                                    this.Dispatcher.BeginInvoke(new SetStatusDelegate(SetErrorMessage), string.Format(SharedStrings.DASHBOARD_EXPORT_WIDE_TABLE_FAIL, totalTablesNeeded.ToString()));
                                    return;
                                }
                            }

                            foreach (KeyValuePair <string, List <Epi.Data.TableColumn> > kvp in fieldTableDictionary)
                            {
                                db.CreateTable(kvp.Key, kvp.Value);
                            }

                            foreach (KeyValuePair <string, List <Epi.Data.TableColumn> > kvp in fieldTableDictionary)
                            {
                                List <string> exportTableFields = new List <string>();
                                foreach (Epi.Data.TableColumn tc in kvp.Value)
                                {
                                    exportTableFields.Add(tc.Name);
                                }

                                DataView  dv    = dashboardHelper.DataSet.Tables[0].DefaultView;
                                DataTable table = dv.ToTable(false, exportTableFields.ToArray());
                                if (useTabOrder)
                                {
                                    dashboardHelper.OrderColumns(table, true);
                                }
                                System.Data.Common.DbDataReader dataReader = table.CreateDataReader(); //dv.ToTable().CreateDataReader();
                                db.InsertBulkRows("Select * From [" + kvp.Key + "]", dataReader, requestUpdateStatus, checkForCancellation);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.Dispatcher.BeginInvoke(new SetStatusDelegate(SetErrorMessage), ex.Message);
                }
                finally
                {
                    stopWatch.Stop();
                    System.Diagnostics.Debug.Print("Export thread finished in " + stopWatch.Elapsed.ToString());
                }
            }
        }