Ejemplo n.º 1
0
        private void LoadConnectionDefinitionToForm(PFConnectionDefinition conndef)
        {
            try
            {
                this.ConnectionName   = conndef.ConnectionName;
                this.ConnectionString = conndef.ConnectionString;
                PFKeyValueList <string, string> dbPlatformProperties = conndef.DbPlatformConnectionStringProperties;

                this.txtServerName.Text               = dbPlatformProperties.Find("ServerName").Value;
                this.txtDatabaseName.Text             = dbPlatformProperties.Find("DatabaseName").Value;
                this.txtUsername.Text                 = dbPlatformProperties.Find("Username").Value;
                this.txtPassword.Text                 = dbPlatformProperties.Find("Password").Value;
                this.txtApplicationName.Text          = dbPlatformProperties.Find("ApplicationName").Value;
                this.txtWorkstationId.Text            = dbPlatformProperties.Find("WorkstationId").Value;
                this.chkUseIntegratedSecurity.Checked = PFTextProcessor.ConvertStringToBoolean(dbPlatformProperties.Find("UseIntegratedSecurity").Value, "false");
                this.chkUseAsyncProcessing.Checked    = PFTextProcessor.ConvertStringToBoolean(dbPlatformProperties.Find("AsynchronousProcessing").Value, "false");

                SaveFormFields();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Error occurred loading saved connection definition. External XML file format may contain errors. ErrorMessage: \r\n");
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }
            finally
            {
                ;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes data contained in ADO.NET DataTable object to path stored in DocumentFilePath property.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be imported.</param>
        /// <returns>True if output operation is successful. False if write fails.</returns>
        public bool WriteDataToDocument(DataTable dt)
        {
            bool          success = true;
            PFWordInterop wordDoc = null;

            try
            {
                wordDoc = new PFWordInterop(enWordOutputFormat.RTF, this.DocumentFilePath, this.ReplaceExistingFile);
                success = wordDoc.WriteDataToDocument(dt);
            }
            catch (System.Exception ex)
            {
                success     = false;
                _msg.Length = 0;
                _msg.Append("Attempt to import DataTable into RTF document failed. ");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (wordDoc != null)
                {
                    wordDoc = null;
                }
            }

            return(success);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends the specified email.
        /// </summary>
        /// <param name="emailMsg">Email message object.</param>
        /// <param name="resendOnError">If true, email manager will attempt to resend a message that fails due to an SMTP error.</param>
        /// <returns>True if email sent successfully; otherwise false if an error occurred and email was not sent.</returns>
        /// <remarks>Email manager will retry up to MaxNumResendAttempts times.</remarks>
        public stEmailSendResult SendEmail(PFEmailMessage emailMsg, bool resendOnError)
        {
            stEmailSendResult result = new stEmailSendResult(enEmailSendResult.Unknown, enEmailFailedReason.Unknown);
            bool queueForResend      = false;

            try
            {
                emailMsg.Send();
                result.emailSendResult   = enEmailSendResult.Success;
                result.emailFailedReason = enEmailFailedReason.NoError;
                result.failureMessages   = string.Empty;
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Attempt to send email to ");
                _msg.Append(emailMsg.ToAddress);
                _msg.Append(" failed. Error Message: ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                result.emailSendResult = enEmailSendResult.Failed;
                result.failureMessages = _msg.ToString();
                if (ex is SmtpException)
                {
                    result.emailFailedReason = enEmailFailedReason.SmtpException;
                    queueForResend           = true;
                }
                else if (ex is SmtpFailedRecipientException)
                {
                    result.emailFailedReason = enEmailFailedReason.SmtpRecipientsException;
                    queueForResend           = true;
                }
                else if (ex is InvalidOperationException)
                {
                    result.emailFailedReason = enEmailFailedReason.InvalidOperationsException;
                }
                else if (ex is ArgumentNullException)
                {
                    result.emailFailedReason = enEmailFailedReason.ArgumentNullException;
                }
                else
                {
                    result.emailFailedReason = enEmailFailedReason.GeneralError;
                }
            }
            finally
            {
                if (queueForResend && resendOnError)
                {
                    stEmailArchiveEntry newEntry = new stEmailArchiveEntry(result, emailMsg);
                    newEntry.firstSendAttempt = DateTime.Now;
                    newEntry.lastSendAttempt  = DateTime.Now;
                    _emailResendQueue.Add(newEntry);
                    _emailResendQueue.SaveToXmlFile(_emailResendQueueFile);
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        private void PreviewTransactionData()
        {
            int maxTxsToGenerate = 0;

            try
            {
                DisableFormControls();
                maxTxsToGenerate = PFTextProcessor.ConvertStringToInt(this.txtNumPreviewTransactions.Text, 100);
                if (maxTxsToGenerate > 5000)
                {
                    this.txtNumPreviewTransactions.Text = "5000";
                    maxTxsToGenerate = 5000;
                }

                SaveFormValues();

                _generatorMessages.Length = 0;
                _generatorMessages.Append("Preview test orders running ...");
                _generatorMessages.Append(Environment.NewLine);

                //callbacks used below

                if (this.optPreviewSalesOrders.Checked)
                {
                    GenerateSalesOrderTransactions(maxTxsToGenerate, _generatorMessages);
                }

                if (this.optPreviewPurchaseOrders.Checked)
                {
                    GeneratePurchaseOrderTransactions(maxTxsToGenerate, _generatorMessages);
                }

                if (this.optPreviewDwInternet.Checked)
                {
                    GenerateInternetSalesTransactions(maxTxsToGenerate, _generatorMessages);
                }

                if (this.optPreviewDwReseller.Checked)
                {
                    GenerateResellerSalesTransactions(maxTxsToGenerate, _generatorMessages);
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                WriteToMessageLog(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _generatorMessages.Append("... Preview test orders finsiehd.");
                _generatorMessages.Append(Environment.NewLine);
                AppMessages.DisplayInfoMessage(_generatorMessages.ToString());
                EnableFormControls();
            }
        }
 private void SaveDatabaseConfigItems()
 {
     _databaseOptions.DefaultQueryDefinitionsFolder             = this.txtDefaultQueryDefinitionsFolder.Text;
     _databaseOptions.DefaultDataGridExportFolder               = this.txtDefaultDataGridExportFolder.Text;
     _databaseOptions.ShowInstalledDatabaseProvidersOnly        = this.chkShowInstalledDatabaseProvidersOnly.Checked;
     _databaseOptions.BatchSizeForDataImportsAndExports         = PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForDataImportsAndExports.Text, 1000);
     _databaseOptions.BatchSizeForRandomDataGeneration          = PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForRandomDataGeneration.Text, 5000);
     _databaseOptions.DefaultInputDatabaseType                  = this.cboDefaultInputDatabaseType.Text;
     _databaseOptions.DefaultInputDatabaseConnectionString      = this.txtDefaultInputDatabaseConnectionString.Text;
     _databaseOptions.DefaultOutputDatabaseType                 = this.cboDefaultOutputDatabaseType.Text;
     _databaseOptions.DefaultOutputDatabaseConnectionString     = this.txtDefaultOutputDatabaseConnectionString.Text;
     _databaseOptions.OverwriteOutputDestinationIfAlreadyExists = this.chkOverwriteOutputDestinationIfAlreadyExists.Checked;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads Mru List from file system location.
        /// </summary>
        public void LoadFromFileSystem()
        {
            PFTextFile    mruListFile     = null;
            StringBuilder mruListFilePath = new StringBuilder();
            string        mruItem         = string.Empty;

            if (fileSystemMruPath != null)
            {
                mruStripMutex.WaitOne();

                RemoveAll();

                mruListFilePath.Length = 0;
                try
                {
                    mruListFilePath.Append(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
                    if (mruListFilePath.ToString().EndsWith(@"\") == false)
                    {
                        mruListFilePath.Append(@"\");
                    }
                    mruListFilePath.Append(this.fileSystemMruPath);
                    if (mruListFilePath.ToString().EndsWith(@"\") == false)
                    {
                        mruListFilePath.Append(@"\");
                    }
                    if (Directory.Exists(mruListFilePath.ToString()) == false)
                    {
                        Directory.CreateDirectory(mruListFilePath.ToString());
                    }
                    mruListFilePath.Append(fileSystemMruFileName);
                }
                catch (SystemException ex)
                {
                    throw new System.Exception(PFTextProcessor.FormatErrorMessage(ex));
                }

                if (File.Exists(mruListFilePath.ToString()))
                {
                    mruListFile = new PFTextFile(mruListFilePath.ToString(), PFFileOpenOperation.OpenFileToRead);
                    while (mruListFile.Peek() >= 0)
                    {
                        mruItem = mruListFile.ReadLine();
                        AddFile(mruItem);
                    }
                    mruListFile.CloseFile();
                    mruListFile = null;
                }

                mruStripMutex.ReleaseMutex();
            }
        }
        /// <summary>
        /// Creates a table in the database specified for this instance. Data is loaded from the column definitions encapsulated by this instance.
        /// </summary>
        /// <returns>True if table is created.</returns>
        /// <remarks>Table create will fail if table already exists and you specify false for the DropOldTable option. Specify true for dropOldTable if you
        ///  want to create the table even if an older version of the table already exists.</remarks>
        public bool CreateTableFromTableColumns()
        {
            bool      tableCreated = false;
            DataTable dt           = null;

            try
            {
                if (_db.DbPlatform == DatabasePlatform.ODBC || _db.DbPlatform == DatabasePlatform.OLEDB || _db.DbPlatform == DatabasePlatform.MSAccess)
                {
                    dt = GetDataTableFromTableColumns(true);
                }
                else
                {
                    dt = GetDataTableFromTableColumns();
                }
                if (_dropOldTable)
                {
                    if (this.SchemaName.Trim().Length > 0)
                    {
                        if (_db.TableExists(this.SchemaName, this.TableName))
                        {
                            _db.DropTable(this.SchemaName, this.TableName);
                        }
                    }
                    else
                    {
                        if (_db.TableExists(this.TableName))
                        {
                            _db.DropTable(this.TableName);
                        }
                    }
                }
                tableCreated = _db.CreateTable(dt);
            }
            catch (System.Exception ex)
            {
                tableCreated = false;
                _msg.Length  = 0;
                _msg.Append("Error while trying to create table from DataTable object ");
                _msg.Append(this.TableName);
                _msg.Append(": ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new DataException(_msg.ToString());
            }
            finally
            {
                ;
            }

            return(tableCreated);
        }
        /// <summary>
        /// Routine to import the data table encapsulated in this instance to a corresponding table in the database.
        /// </summary>
        /// <returns>True if data import was successful.</returns>
        public bool ImportTableToDatabase()
        {
            bool      dataImportSuccessful = false;
            DataTable dt = null;

            try
            {
                if (_db.DbPlatform == DatabasePlatform.ODBC || _db.DbPlatform == DatabasePlatform.OLEDB || _db.DbPlatform == DatabasePlatform.MSAccess)
                {
                    dt = GetDataTableFromTableColumns(true);
                }
                else
                {
                    dt = GetDataTableFromTableColumns();
                }
                //dt = GetDataTableFromTableColumns();
                if (this.SchemaName.Trim().Length > 0)
                {
                    if (_db.TableExists(this.SchemaName, this.TableName) == false)
                    {
                        _db.CreateTable(dt);
                    }
                }
                else
                {
                    if (_db.TableExists(this.TableName) == false)
                    {
                        _db.CreateTable(dt);
                    }
                }
                _db.ImportDataFromDataTable(dt);
                dataImportSuccessful = true;
            }
            catch (System.Exception ex)
            {
                dataImportSuccessful = false;
                _msg.Length          = 0;
                _msg.Append("Error while trying to create table from DataTable object ");
                _msg.Append(this.TableName);
                _msg.Append(": ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new DataException(_msg.ToString());
            }
            finally
            {
                ;
            }

            return(dataImportSuccessful);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Saves Mru List to file system.
        /// </summary>
        public void SaveToFileSystem()
        {
            PFTextFile    mruListFile     = null;
            StringBuilder mruListFilePath = new StringBuilder();
            string        mruItem         = string.Empty;

            if (fileSystemMruPath != null)
            {
                mruStripMutex.WaitOne();

                mruListFilePath.Length = 0;
                try
                {
                    mruListFilePath.Append(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
                    if (mruListFilePath.ToString().EndsWith(@"\") == false)
                    {
                        mruListFilePath.Append(@"\");
                    }
                    mruListFilePath.Append(this.fileSystemMruPath);
                    if (mruListFilePath.ToString().EndsWith(@"\") == false)
                    {
                        mruListFilePath.Append(@"\");
                    }
                    if (Directory.Exists(mruListFilePath.ToString()) == false)
                    {
                        Directory.CreateDirectory(mruListFilePath.ToString());
                    }
                    mruListFilePath.Append(fileSystemMruFileName);
                }
                catch (SystemException ex)
                {
                    throw new System.Exception(PFTextProcessor.FormatErrorMessage(ex));
                }

                mruListFile = new PFTextFile(mruListFilePath.ToString(), PFFileOpenOperation.OpenFileForWrite);

                int i = 0;
                for (i = EndIndex - 1; i >= StartIndex; i--)
                {
                    mruItem = ((MruMenuItem)MenuItems[i]).Filename;
                    mruListFile.WriteLine(mruItem);
                }

                mruListFile.CloseFile();
                mruListFile = null;

                mruStripMutex.ReleaseMutex();
            }
        }
Ejemplo n.º 10
0
        //methods

        /// <summary>
        /// Creates SQLCE database file and populates it with required data table.
        /// </summary>
        public void CreateAppLogDatabase()
        {
            string          sqlStmt = string.Empty;
            PFSQLServerCE35 db      = null;

            try
            {
                db = new PFSQLServerCE35();

                db.CreateDatabase(_logConnectionString);

                db.ConnectionString = _logConnectionString;
                db.OpenConnection();

                sqlStmt = _appLogTableCreateSql;
                db.RunNonQuery(sqlStmt);
                sqlStmt = _appLogTableIdx1;
                db.RunNonQuery(sqlStmt);
                sqlStmt = _appLogTableIdx2;
                db.RunNonQuery(sqlStmt);
                sqlStmt = _appLogTableIdx3;
                db.RunNonQuery(sqlStmt);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Unable to create database: ");
                _msg.Append(_logConnectionString);
                if (sqlStmt.Length > 0)
                {
                    _msg.Append(" SQL statement: ");
                    _msg.Append(sqlStmt);
                }
                _msg.Append(" Error message: ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
                db = null;
            }
        }
Ejemplo n.º 11
0
 private void SaveUserConfigItems()
 {
     _userOptions.DefaultQueryDefinitionsFolder         = this.txtDefaultQueryDefinitionsFolder.Text;
     _userOptions.DefaultDataGridExportFolder           = txtDefaultDataGridExportFolder.Text;
     _userOptions.SaveFormLocationsOnExit               = this.chkSaveFormLocationsOnExit.Checked;
     _userOptions.ShowInstalledDatabaseProvidersOnly    = chkShowInstalledDatabaseProvidersOnly.Checked;
     _userOptions.ShowApplicationLogWindow              = this.chkShowApplicationLogWindow.Checked;
     _userOptions.DefaultInputDatabaseType              = this.cboDefaultInputDatabaseType.Text;
     _userOptions.DefaultInputDatabaseConnectionString  = this.txtDefaultInputDatabaseConnectionString.Text;
     _userOptions.DefaultOutputDatabaseType             = this.cboDefaultOutputDatabaseType.Text;
     _userOptions.DefaultOutputDatabaseConnectionString = this.txtDefaultOutputDatabaseConnectionString.Text;
     //_userOptions.DefaultApplicationtFont is saved in ChangeDefaultApplicationFont method
     _userOptions.BatchSizeForDataImportsAndExports = PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForDataImportsAndExports.Text, 1000);
     _userOptions.BatchSizeForRandomDataGeneration  = PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForRandomDataGeneration.Text, 5000);
 }
Ejemplo n.º 12
0
 private void SaveUserConfigItems()
 {
     _userOptions.SaveFormLocationsOnExit            = this.chkSaveFormLocationsOnExit.Checked;
     _userOptions.ShowOutputLog                      = this.chkShowOutputLog.Checked;
     _userOptions.ShowInstalledDatabaseProvidersOnly = this.chkShowInstalledDatabaseProvidersOnly.Checked;
     _userOptions.PreviewAllRows                     = this.optPreviewAllRows.Checked;
     _userOptions.LimitPreviewRows                   = this.optLimitPreviewRows.Checked;
     _userOptions.MaxNumberOfRows                    = PFTextProcessor.ConvertStringToInt(this.txtMaxNumberOfRows.Text, 1000);
     _userOptions.DefaultDataSourceType              = this.cboDefaultDataSourceType.Text;
     _userOptions.DefaultDataDestinationType         = this.cboDefaultDataDestinationType.Text;
     //_userOptions.DefaultApplicationtFont is saved in ChangeDefaultApplicationFont method
     _userOptions.BatchSizeForDataImportsAndExports     = PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForDataImportsAndExports.Text, 1000);
     _userOptions.BatchSizeForRandomDataGeneration      = PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForRandomDataGeneration.Text, 5000);
     _userOptions.DefaultExtractorDefinitionsSaveFolder = this.txtDefaultExtractorDefinitionsSaveFolder.Text;
     _userOptions.DefaultExtractorDefinitionName        = this.txtDefaultExtractorDefinitionName.Text;
 }
Ejemplo n.º 13
0
        private void LoadWordList()
        {
            try
            {
                _words = PFList <string> .LoadFromXmlFile(_wordListFile, _fileXlatKey, _fileXlatIV);

                _minListInx = 0;
                _maxListInx = _words.Count - 1;
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Unable to find word list file: ");
                _msg.Append(_wordListFile);
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
        }
Ejemplo n.º 14
0
        private string BuildConnectionString()
        {
            string connStr = string.Empty;

            //TODO: Change this (Changed)
            _db.SetPropertyValue("DatabasePath", this.txtDataSource.Text);
            _db.SetPropertyValue("DatabasePassword", this.txtPassword.Text);
            _db.SetPropertyValue("EncryptionOn", this.chkEncryptionOn.Checked);
            _db.SetPropertyValue("EncryptionMode", (SQLCE40EncryptionMode)Enum.Parse(typeof(SQLCE40EncryptionMode), this.cboEncryptionMode.Text));
            _db.SetPropertyValue("MaxDatabaseSize", PFTextProcessor.ConvertStringToInt(this.txtMaxDatabaseSize.Text, (int)enSQLCE40Defaults.MaxDatabaseSize));
            _db.SetPropertyValue("MaxBufferSize", PFTextProcessor.ConvertStringToInt(this.txtMaxBufferSize.Text, (int)enSQLCE40Defaults.MaxBufferSize));
            _db.SetPropertyValue("MaxTempFileSize", PFTextProcessor.ConvertStringToInt(this.txtMaxTempFileSize.Text, (int)enSQLCE40Defaults.MaxTempFileSize));
            //END TODO
            connStr = _db.ConnectionString;

            SaveFormFields();  //save field values so that Accept processing can determine if there are differences between connection string and the property values on the form.

            return(connStr);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// ExportDataToDataTable
        /// </summary>
        /// <param name="startRow">First row of Excel range.</param>
        /// <param name="startCol">First column of Excel range.</param>
        /// <param name="endRow">Last row of Excel range.</param>
        /// <param name="endCol">Last column of Excel range.</param>
        /// <param name="columnNamesInFirstRow">If true, then export will assume first row contains column names.</param>
        /// <returns>DataTable object that contains the values in the given range of Excel cells.</returns>
        /// <remarks>Row and col values are zero based. e.g. 0,0 to 99,99 for a range of 100 rows and 100 columns.</remarks>
        public DataTable ExportExcelDataToDataTable(int startRow, int startCol, int endRow, int endCol, bool columnNamesInFirstRow)
        {
            DataTable      dt       = null;
            PFExcelInterop excelDoc = null;

            try
            {
                if (this.ExcelOutputFormat == enExcelOutputFormat.Excel2007)
                {
                    excelDoc = new PFExcelInterop(enExcelOutputFormat.Excel2007, this.DocumentFilePath, this.SheetName, this.ReplaceExistingFile, this.ReplaceExistingSheet);
                }
                else if (this.ExcelOutputFormat == enExcelOutputFormat.Excel2003)
                {
                    excelDoc = new PFExcelInterop(enExcelOutputFormat.Excel2003, this.DocumentFilePath, this.SheetName, this.ReplaceExistingFile, this.ReplaceExistingSheet);
                }
                else
                {
                    excelDoc = new PFExcelInterop(enExcelOutputFormat.CSV, this.DocumentFilePath, this.SheetName, this.ReplaceExistingFile, this.ReplaceExistingSheet);
                }

                dt = excelDoc.ExportExcelDataToDataTable(startRow, startCol, endRow, endCol, columnNamesInFirstRow);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Attempt to output Excel data to DataTable failed.");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (excelDoc != null)
                {
                    excelDoc = null;
                }
            }



            return(dt);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Writes data contained in ADO.NET DataTable object to path stored in DocumentFilePath property.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be imported.</param>
        /// <returns>True if output operation is successful. False if write fails.</returns>
        /// <remarks>Ext version of WriteDataToDocument has extra logic for modifying existing documents.</remarks>
        public bool WriteDataToDocumentExt(DataTable dt)
        {
            bool           success  = true;
            PFExcelInterop excelDoc = null;

            try
            {
                if (this.ExcelOutputFormat == enExcelOutputFormat.Excel2007)
                {
                    excelDoc = new PFExcelInterop(enExcelOutputFormat.Excel2007, this.DocumentFilePath, this.SheetName, this.ReplaceExistingFile, this.ReplaceExistingSheet);
                }
                else if (this.ExcelOutputFormat == enExcelOutputFormat.Excel2003)
                {
                    excelDoc = new PFExcelInterop(enExcelOutputFormat.Excel2003, this.DocumentFilePath, this.SheetName, this.ReplaceExistingFile, this.ReplaceExistingSheet);
                }
                else
                {
                    excelDoc = new PFExcelInterop(enExcelOutputFormat.CSV, this.DocumentFilePath, this.SheetName, this.ReplaceExistingFile, this.ReplaceExistingSheet);
                }

                success = excelDoc.WriteDataToDocumentExt(dt);
            }
            catch (System.Exception ex)
            {
                success     = false;
                _msg.Length = 0;
                _msg.Append("Attempt to import DataTable into Excel document failed.");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (excelDoc != null)
                {
                    excelDoc = null;
                }
            }

            return(success);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Deletes all records from Retry Log table.
        /// </summary>
        public void DeleteRetryLogTable()
        {
            string          sqlStmt = string.Empty;
            PFSQLServerCE35 db      = null;

            try
            {
                db = new PFSQLServerCE35(_retryLogConnectionString);

                db.OpenConnection();

                sqlStmt = _retryLogTableDeleteSql;
                db.RunNonQuery(sqlStmt);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Unable to delete table: ");
                _msg.Append(_retryLogConnectionString);
                if (sqlStmt.Length > 0)
                {
                    _msg.Append(" SQL statement: ");
                    _msg.Append(sqlStmt);
                }
                _msg.Append(" Error message: ");
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (db != null)
                {
                    if (db.IsConnected)
                    {
                        db.CloseConnection();
                    }
                }
                db = null;
            }
        }
Ejemplo n.º 18
0
        public void RunTask()
        {
            PFTask             task = new PFTask();
            PFTaskHistoryEntry the  = new PFTaskHistoryEntry();

            PFTimers.Stopwatch sw = new PFTimers.Stopwatch();
            string             connectionString = string.Empty;
            string             scheduleFolder   = string.Empty;
            string             scheduleName     = string.Empty;

            try
            {
                if (_frm.chkEraseOutputBeforeEachTest.Checked)
                {
                    Program._messageLog.Clear();
                }

                if (_frm.txtTaskName.Text.Trim().Length == 0 ||
                    _frm.txtFileToRun.Text.Trim().Length == 0)
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify a the name and a file to run for RunTest");
                    throw new System.Exception(_msg.ToString());
                }

                sw.Start();

                _msg.Length = 0;
                _msg.Append("Before taskProcessor.Start");
                Program._messageLog.WriteLine(_msg.ToString());

                System.Diagnostics.Process p = Process.GetCurrentProcess();
                foreach (ProcessThread th in p.Threads)
                {
                    _msg.Length = 0;
                    _msg.Append("Thread ID: ");
                    _msg.Append(th.Id.ToString());
                    Program._messageLog.WriteLine(_msg.ToString());
                }

                scheduleFolder = _scheduleDefinitionsFolder;
                scheduleName   = Path.GetFileNameWithoutExtension(_frm.txtTaskSchedule.Text.Trim()) + ".xml";
                if (_frm.optUseXmlFiles.Checked)
                {
                    connectionString = Path.Combine(scheduleFolder, scheduleName);
                }
                else if (_frm.optUseDatabase.Checked)
                {
                    connectionString = _taskDefsDbConnectionString;
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("You must select storage type: XML Files or Database.");
                    throw new System.Exception(_msg.ToString());
                }


                task.TaskName              = _frm.txtTaskName.Text;
                task.TaskDescription       = _frm.txtTaskDescription.Text;
                task.TaskType              = PFAppUtils.PFEnumProcessor.StringToEnum <enTaskType>(_frm.cboTaskType.Text);
                task.MaxTaskHistoryEntries = Convert.ToInt32(_frm.txtMaxHistoryEntries.Text);
                if (_frm.optUseXmlFiles.Checked)
                {
                    task.Schedule = PFSchedule.LoadFromXmlFile(connectionString);
                }
                else
                {
                    task.Schedule = PFSchedule.LoadFromDatabase(connectionString, _frm.txtTaskSchedule.Text.Trim());
                }
                task.FileToRun        = _frm.txtFileToRun.Text;
                task.WorkingDirectory = _frm.txtWorkingDirectory.Text;
                string[] lines = _frm.txtArguments.Lines;
                task.Arguments              = lines;
                task.WindowStyle            = PFAppUtils.PFEnumProcessor.StringToEnum <enWindowStyle>(_frm.cboWindowStyle.Text);
                task.CreateNoWindow         = _frm.chkCreateNoWindow.Checked;
                task.UseShellExecute        = _frm.chkUseShellExecute.Checked;
                task.RedirectStandardOutput = _frm.chkRedirectStandardOutput.Checked;
                task.RedirectStandardError  = _frm.chkRedirectStandardError.Checked;

                the.TaskID             = task.ID;
                the.TaskName           = task.TaskName;
                the.ScheduledStartTime = task.Schedule.GetCurrentScheduledDateTime(DateTime.Now, DateTime.Now.AddHours(1));

                PFTaskProcessor taskProcessor = new PFTaskProcessor(task);
                taskProcessor.Start();

                _msg.Length = 0;
                _msg.Append("After taskProcessor.Start");
                Program._messageLog.WriteLine(_msg.ToString());

                System.Diagnostics.Process p1 = Process.GetCurrentProcess();
                foreach (ProcessThread th in p1.Threads)
                {
                    _msg.Length = 0;
                    _msg.Append("Thread ID: ");
                    _msg.Append(th.Id.ToString());
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                _msg.Length = 0;
                _msg.Append("Main thread id:    ");
                _msg.Append(System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());
                Program._messageLog.WriteLine(_msg.ToString());
                _msg.Length = 0;
                _msg.Append("Spawned thread id: ");
                _msg.Append(taskProcessor.ThreadID.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                while (taskProcessor.HasFinished == false)
                {
                    System.Threading.Thread.Sleep(1000);
                    System.Threading.Thread.Yield();
                }


                sw.Stop();

                _msg.Length = 0;
                _msg.Append("Elapsed time: ");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("\r\nTaskProcessor property values: \r\n");
                _msg.Append("Curr Directory:  ");
                _msg.Append(task.WorkingDirectory);
                _msg.Append("\r\n");
                _msg.Append("Command Line:    ");
                _msg.Append(task.FileToRun);
                _msg.Append(" ");
                _msg.Append(PFTextProcessor.ConvertStringArrayToString(task.Arguments));
                _msg.Append("\r\n");
                _msg.Append("StartTime:       ");
                _msg.Append(taskProcessor.StartTime.ToString("MM/dd/yyyy HH:mm:ss"));
                _msg.Append("\r\n");
                _msg.Append("FinishTime       ");
                _msg.Append(taskProcessor.FinishTime.ToString("MM/dd/yyyy HH:mm:ss"));
                _msg.Append("\r\n");
                _msg.Append("Elapsed Time:    ");
                _msg.Append(taskProcessor.ElapsedTimeFormatted);
                _msg.Append("\r\n");
                _msg.Append("Exit Code:       ");
                _msg.Append(taskProcessor.ProcessExitCode.ToString());
                _msg.Append("\r\n");
                _msg.Append("OutputMessages:  ");
                _msg.Append(taskProcessor.OutputMessages);
                _msg.Append("\r\n");
                _msg.Append("ErrorMessages:   ");
                _msg.Append(taskProcessor.ErrorMessages);
                _msg.Append("\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                //fill up and save the history entry
                the.ActualStartTime    = taskProcessor.StartTime;
                the.ActualEndTime      = taskProcessor.FinishTime;
                the.TaskOutputMessages = taskProcessor.OutputMessages;
                the.TaskErrorMessages  = taskProcessor.ErrorMessages;
                the.TaskReturnCode     = taskProcessor.ProcessExitCode;
                if (taskProcessor.ProcessExitCode == 0)
                {
                    the.TaskRunResult = enTaskRunResult.Success;
                }
                else
                {
                    the.TaskRunResult = enTaskRunResult.Failure;
                }
                if (_frm.optUseXmlFiles.Checked)
                {
                    string theFilename = _taskHistoryFolder + the.TaskName + "_" + the.ActualEndTime.ToString("_yyyyMMdd_HHmmss") + ".xml";
                    if (File.Exists(theFilename))
                    {
                        File.Delete(theFilename);
                    }
                    the.SaveToXmlFile(theFilename);
                }
                else if (_frm.optUseDatabase.Checked)
                {
                    the.SaveToDatabase(_taskDefsDbConnectionString);
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify whether to store the history in XML files or Database.");
                    throw new System.Exception(_msg.ToString());
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// ExportDataToDataTable
        /// </summary>
        /// <param name="startRow">First row of Excel range.</param>
        /// <param name="startCol">First column of Excel range.</param>
        /// <param name="endRow">Last row of Excel range.</param>
        /// <param name="endCol">Last column of Excel range.</param>
        /// <param name="columnNamesInFirstRow">If true, then export will assume first row contains column names.</param>
        /// <returns>DataTable object that contains the values in the given range of Excel cells.</returns>
        /// <remarks>Row and col values are one based. e.g. 1,1 to 100,100 for a range of 100 rows and 100 columns.</remarks>
        public DataTable ExportExcelDataToDataTable(int startRow, int startCol, int endRow, int endCol, bool columnNamesInFirstRow)
        {
            DataTable dt     = new DataTable();
            int       rowNum = 0;
            int       colNum = 0;

            Microsoft.Office.Interop.Excel.Application excelApp = null;

            try
            {
                if (this.SheetName.Trim().Length == 0)
                {
                    this.SheetName = "Sheet1";
                }

                excelApp = new Microsoft.Office.Interop.Excel.Application();

                Microsoft.Office.Interop.Excel.Workbook wb = null;

                if (File.Exists(this.DocumentFilePath))
                {
                    wb = excelApp.Workbooks.Open(this.DocumentFilePath);
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to load ");
                    _msg.Append(this.DocumentFilePath);
                    _msg.Append(". ExportExcelDataToDataTable has failed.");
                    throw new System.Exception(_msg.ToString());
                }

                Microsoft.Office.Interop.Excel.Worksheet ws = null;
                foreach (Microsoft.Office.Interop.Excel.Worksheet sh in wb.Sheets)
                {
                    if (sh.Name == this.SheetName)
                    {
                        ws = sh;
                    }
                }

                if (ws == null)
                {
                    _msg.Length = 0;
                    _msg.Append("Sheet ");
                    _msg.Append(this.SheetName);
                    _msg.Append(" does not exist. Will not be able to export data.");
                    throw new System.Exception(_msg.ToString());
                }

                if (endCol < startCol || endRow < startRow)
                {
                    _msg.Length = 0;
                    _msg.Append("Invalid row and column coordinates specified.");
                    _msg.Append("FROM row " + startRow.ToString() + " column " + startCol.ToString() + " TO  row " + endRow.ToString() + " column " + endCol.ToString() + ". ");
                    throw new System.Exception(_msg.ToString());
                }

                ws = wb.Sheets[this.SheetName];

                if (columnNamesInFirstRow)
                {
                    //set datatable column names to values in first row of spreadsheet
                    for (int colInx = startCol; colInx <= endCol; colInx++)
                    {
                        DataColumn dc = new DataColumn();
                        dc.ColumnName   = ws.Cells[startRow, colInx].Text.ToString();
                        dc.DataType     = Type.GetType("System.String");
                        dc.Caption      = dc.ColumnName;
                        dc.DefaultValue = string.Empty;
                        dc.MaxLength    = int.MaxValue;
                        dt.Columns.Add(dc);
                    }
                }
                else
                {
                    //create arbitrary column names
                    colNum = 0;
                    for (int colInx = startCol; colInx < endCol; colInx++)
                    {
                        colNum++;
                        DataColumn dc = new DataColumn();
                        dc.ColumnName   = "F" + colNum.ToString("0");
                        dc.DataType     = Type.GetType("System.String");
                        dc.Caption      = dc.ColumnName;
                        dc.DefaultValue = string.Empty;
                        dc.MaxLength    = int.MaxValue;
                        dt.Columns.Add(dc);
                    }
                }


                if (columnNamesInFirstRow)
                {
                    rowNum = startRow + 1;
                }
                else
                {
                    rowNum = startRow;
                }

                for (int rowInx = rowNum; rowInx <= endRow; rowInx++)
                {
                    DataRow dr = dt.NewRow();
                    colNum = 0;
                    for (int colInx = startCol; colInx <= endCol; colInx++)
                    {
                        dr[colNum] = ws.Cells[rowInx, colInx].Text.ToString();
                        colNum++;
                    }
                    dt.Rows.Add(dr);
                }

                wb.Close(false);
                excelApp.Quit();

                excelApp = null;
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Attempt to output Excel data to DataTable failed.");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (excelApp != null)
                {
                    excelApp.Quit();
                    excelApp = null;
                }
            }



            return(dt);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// ExportDataToDataTable
        /// </summary>
        /// <param name="excelRangeName">Name given to a range of cells in the document.</param>
        /// <param name="columnNamesInFirstRow">If true, then export will assume first row contains column names.</param>
        /// <returns>DataTable object that contains the values in the given excelNameRange.</returns>
        public DataTable ExportExcelDataToDataTable(string excelRangeName, bool columnNamesInFirstRow)
        {
            DataTable dt = null;

            Microsoft.Office.Interop.Excel.Application excelApp = null;

            try
            {
                if (this.ExcelOutputFormat == enExcelOutputFormat.CSV)
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to export data from a CSV file using a named range.");
                    throw new System.Exception(_msg.ToString());
                }


                if (File.Exists(this.DocumentFilePath) == false)
                {
                    _msg.Length = 0;
                    _msg.Append("File ");
                    _msg.Append(this.DocumentFilePath);
                    _msg.Append(" does not exist. Will not be able to export data.");
                    throw new System.Exception(_msg.ToString());
                }

                excelApp = new Microsoft.Office.Interop.Excel.Application();

                Microsoft.Office.Interop.Excel.Workbook wb = excelApp.Workbooks.Open(this.DocumentFilePath);

                Microsoft.Office.Interop.Excel.Worksheet ws = null;


                foreach (Microsoft.Office.Interop.Excel.Worksheet sh in wb.Sheets)
                {
                    if (sh.Name == this.SheetName)
                    {
                        ws = sh;
                    }
                }

                if (ws == null)
                {
                    _msg.Length = 0;
                    _msg.Append("Sheet ");
                    _msg.Append(this.SheetName);
                    _msg.Append(" does not exist. Will not be able to export data.");
                    throw new System.Exception(_msg.ToString());
                }

                Microsoft.Office.Interop.Excel.Range rng = null;
                try
                {
                    rng = ws.get_Range(excelRangeName, Type.Missing);
                }
                catch
                {
                    rng = null;
                }

                if (rng == null)
                {
                    _msg.Length = 0;
                    _msg.Append("Range ");
                    _msg.Append(excelRangeName);
                    _msg.Append(" does not exist. Will not be able to export data.");
                    throw new System.Exception(_msg.ToString());
                }

                dt = ExportExcelDataToDataTable(rng.Row, rng.Column, rng.Rows.Count, rng.Columns.Count, columnNamesInFirstRow);

                wb.Close(false);
                excelApp.Quit();
                excelApp = null;
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append("Attempt to export Excel data to DataTable failed.");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (excelApp != null)
                {
                    excelApp.Quit();
                    excelApp = null;
                }
            }

            return(dt);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Writes data contained in ADO.NET DataTable object to path stored in DocumentFilePath property.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be imported.</param>
        /// <returns>True if output operation is successful. False if write fails.</returns>
        /// <remarks>Ext version of WriteDataToDocument has extra logic for modifying existing documents.</remarks>
        public bool WriteDataToDocumentExt(DataTable dt)
        {
            bool success = true;

            try
            {
                if (File.Exists(this.DocumentFilePath))
                {
                    if (_replaceExistingFile)
                    {
                        File.SetAttributes(this.DocumentFilePath, FileAttributes.Normal);
                        File.Delete(this.DocumentFilePath);
                    }
                }

                Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();

                Microsoft.Office.Interop.Excel.Workbook wb = excelApp.Workbooks.Add(Type.Missing);

                excelApp.Columns.ColumnWidth = 30;

                Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)excelApp.Worksheets["Sheet1"];
                excelApp.DisplayAlerts = false;
                ws.Delete();


                if (File.Exists(this.DocumentFilePath))
                {
                    wb = excelApp.Workbooks.Open(this.DocumentFilePath);
                }

                if (this.SheetName.Trim().Length == 0)
                {
                    this.SheetName = "Sheet1";
                }


                if (this._replaceExistingSheet)
                {
                    foreach (Microsoft.Office.Interop.Excel.Worksheet sh in wb.Sheets)
                    {
                        if (sh.Name == this.SheetName)
                        {
                            sh.Delete();
                            break;
                        }
                    }
                }

                Microsoft.Office.Interop.Excel.Worksheet sheet = null;
                foreach (Microsoft.Office.Interop.Excel.Worksheet sh in wb.Sheets)
                {
                    if (sh.Name == this.SheetName)
                    {
                        sheet = sh;
                        break;
                    }
                }

                if (sheet == null)
                {
                    sheet      = wb.Sheets.Add(After: wb.Sheets[wb.Sheets.Count]);
                    sheet.Name = this.SheetName;
                }

                for (int c = 0; c < dt.Columns.Count; c++)
                {
                    sheet.Cells[1, c + 1] = dt.Columns[c].ColumnName;
                }

                for (int r = 0; r < dt.Rows.Count; r++)
                {
                    for (int c = 0; c < dt.Columns.Count; c++)
                    {
                        DataRow row = dt.Rows[r];
                        sheet.Cells[r + 2, c + 1] = row[c].ToString();
                    }
                }

                Microsoft.Office.Interop.Excel.XlFileFormat fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV;
                if (this.ExcelOutputFormat == enExcelOutputFormat.Excel2007)
                {
                    fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook;
                }
                else if (this.ExcelOutputFormat == enExcelOutputFormat.Excel2003)
                {
                    fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8;
                }
                else
                {
                    fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV;  //default to CSV for not specified or invalid format request
                }
                excelApp.DisplayAlerts = false;
                excelApp.ActiveWorkbook.SaveAs(this.DocumentFilePath, fileFormat);

                wb.Close(false);
                excelApp.Quit();

                excelApp = null;
            }
            catch (System.Exception ex)
            {
                success     = false;
                _msg.Length = 0;
                _msg.Append("Attempt to import DataTable into Excel document failed.");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                ;
            }

            return(success);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Writes data contained in ADO.NET DataTable object to path stored in DocumentFilePath property.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be imported.</param>
        /// <returns>True if output operation is successful. False if write fails.</returns>
        /// <remarks>AppendDataToExistingDocument will report an error if workbook or sheet cannot be found.s.</remarks>
        public bool AppendDataToExistingSheet(DataTable dt)
        {
            bool success  = true;
            int  excelRow = 0;

            try
            {
                Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();

                Microsoft.Office.Interop.Excel.Workbook wb = null;

                if (File.Exists(this.DocumentFilePath))
                {
                    wb = excelApp.Workbooks.Open(this.DocumentFilePath);
                }
                else
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to load ");
                    _msg.Append(this.DocumentFilePath);
                    _msg.Append(". AppendDataToExistSheet has failed.");
                    throw new System.Exception(_msg.ToString());
                }


                Microsoft.Office.Interop.Excel.Worksheet ws = null;

                foreach (Microsoft.Office.Interop.Excel.Worksheet sh in wb.Sheets)
                {
                    if (sh.Name == this.SheetName)
                    {
                        ws = sh;
                    }
                }

                if (ws == null)
                {
                    _msg.Length = 0;
                    _msg.Append("Unable to find sheet ");
                    _msg.Append(this.SheetName);
                    _msg.Append(". AppendDataToExistSheet has failed.");
                    throw new System.Exception(_msg.ToString());
                }


                //no headings output when appending to existing data

                Microsoft.Office.Interop.Excel.Range range = ws.UsedRange;

                excelRow = range.Rows.Count;

                for (int r = 0; r < dt.Rows.Count; r++)
                {
                    excelRow++;
                    for (int c = 0; c < dt.Columns.Count; c++)
                    {
                        DataRow row = dt.Rows[r];
                        excelApp.Cells[excelRow, c + 1] = row[c].ToString();
                    }
                }


                Microsoft.Office.Interop.Excel.XlFileFormat fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV;
                if (this.ExcelOutputFormat == enExcelOutputFormat.Excel2007)
                {
                    fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook;
                }
                else if (this.ExcelOutputFormat == enExcelOutputFormat.Excel2003)
                {
                    fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8;
                }
                else
                {
                    fileFormat = Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV;  //default to CSV for not specified or invalid format request
                }
                excelApp.DisplayAlerts = false;
                excelApp.ActiveWorkbook.SaveAs(this.DocumentFilePath, fileFormat);

                wb.Close(false);
                excelApp.Quit();

                excelApp = null;
            }
            catch (System.Exception ex)
            {
                success     = false;
                _msg.Length = 0;
                _msg.Append("Attempt to import DataTable into Excel document failed.");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                ;
            }

            return(success);
        }//end method
Ejemplo n.º 23
0
        private DialogResult ShowSaveFileDialog()
        {
            DialogResult res      = DialogResult.None;
            string       filename = string.Empty;

            _saveFileDialog.InitialDirectory    = this.txtInitialDirectory.Text;
            _saveFileDialog.FileName            = string.Empty;
            _saveFileDialog.Filter              = this.txtFilter.Text;
            _saveFileDialog.FilterIndex         = PFTextProcessor.ConvertStringToInt(this.txtFilterIndex.Text, 1);
            _saveFileDialog.ShowCreatePrompt    = this.chkCreatePrompt.Checked;
            _saveFileDialog.ShowOverwritePrompt = this.chkOverwritePrompt.Checked;

            res = _saveFileDialog.ShowSaveFileDialog();

            _msg.Length = 0;
            if (res == DialogResult.OK)
            {
                this.txtInitialDirectory.Text = _saveFileDialog.InitialDirectory;
                this.txtFilterIndex.Text      = _saveFileDialog.FilterIndex.ToString();
                UpdateMruList(_saveFileDialog.FileName);

                _msg.Append("Save File name: \r\n");
                _msg.Append(_saveFileDialog.FileName);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("ToXmlString:\r\n");
                _msg.Append(_saveFileDialog.ToXmlString());
                _msg.Append("\r\n");
                _msg.Append("ToXmlDocument:\r\n");
                _msg.Append(_saveFileDialog.ToXmlDocument().OuterXml);
                Program._messageLog.WriteLine(_msg.ToString());

                string xmlFileName = @"c:\temp\Dialog.xml";
                _saveFileDialog.SaveToXmlFile(xmlFileName);
                PFSaveFileDialog diag2 = PFSaveFileDialog.LoadFromXmlFile(xmlFileName);
                _msg.Length = 0;
                _msg.Append("\r\nXmlFileName: ");
                _msg.Append(xmlFileName);
                _msg.Append("\r\n");
                _msg.Append("\r\ndiag2 ToXmlString:\r\n");
                _msg.Append(diag2.ToXmlString());
                _msg.Append("\r\n");
                _msg.Append("\r\ndiag2 ToXmlDocument:\r\n");
                _msg.Append(diag2.ToXmlDocument().OuterXml);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("\r\nToString: ");
                _msg.Append(_saveFileDialog.ToString());
                Program._messageLog.WriteLine(_msg.ToString());
            }
            else
            {
                _msg.Append("SaveFileDiaglog result:\r\n");
                _msg.Append(res.ToString());
                Program._messageLog.WriteLine(_msg.ToString());
            }

            return(res);
        }
Ejemplo n.º 24
0
        private DialogResult ShowOpenFileDialog()
        {
            DialogResult res = DialogResult.None;

            _openFileDialog.InitialDirectory = this.txtInitialDirectory.Text;
            _openFileDialog.FileName         = string.Empty;
            _openFileDialog.Filter           = this.txtFilter.Text;
            _openFileDialog.FilterIndex      = PFTextProcessor.ConvertStringToInt(this.txtFilterIndex.Text, 1);
            _openFileDialog.MultiSelect      = this.chkMultiSelect.Checked;
            res = _openFileDialog.ShowOpenFileDialog();
            if (res == DialogResult.OK)
            {
                this.txtInitialDirectory.Text = _openFileDialog.InitialDirectory;
                this.txtFilterIndex.Text      = _openFileDialog.FilterIndex.ToString();
                _msg.Length = 0;
                if (chkMultiSelect.Checked)
                {
                    _msg.Append("Open File names: \r\n");
                    if (_openFileDialog.FileNames != null)
                    {
                        for (int i = 0; i < _openFileDialog.FileNames.Length; i++)
                        {
                            _msg.Append(_openFileDialog.FileNames[i]);
                            _msg.Append("\r\n");
                        }
                    }
                    else
                    {
                        _msg.Append("<Null>");
                    }
                }
                else
                {
                    _msg.Append("Open File name: \r\n");
                    _msg.Append(_openFileDialog.FileName);
                }
                Program._messageLog.WriteLine(_msg.ToString());

                if (_openFileDialog.MultiSelect)
                {
                    if (_openFileDialog.FileNames != null)
                    {
                        for (int i = 0; i < _openFileDialog.FileNames.Length; i++)
                        {
                            UpdateMruList(_openFileDialog.FileNames[i]);
                        }
                    }
                    else
                    {
                        ;
                    }
                }
                else
                {
                    UpdateMruList(_openFileDialog.FileName);
                }
                _msg.Length = 0;
                _msg.Append("ToXmlString:\r\n");
                _msg.Append(_openFileDialog.ToXmlString());
                _msg.Append("\r\n");
                _msg.Append("ToXmlDocument:\r\n");
                _msg.Append(_openFileDialog.ToXmlDocument().OuterXml);
                Program._messageLog.WriteLine(_msg.ToString());

                string xmlFileName = @"c:\temp\Dialog.xml";
                _openFileDialog.SaveToXmlFile(xmlFileName);
                PFOpenFileDialog diag2 = PFOpenFileDialog.LoadFromXmlFile(xmlFileName);
                _msg.Length = 0;
                _msg.Append("\r\nXmlFileName: ");
                _msg.Append(xmlFileName);
                _msg.Append("\r\n");
                _msg.Append("\r\ndiag2 ToXmlString:\r\n");
                _msg.Append(diag2.ToXmlString());
                _msg.Append("\r\n");
                _msg.Append("\r\ndiag2 ToXmlDocument:\r\n");
                _msg.Append(diag2.ToXmlDocument().OuterXml);
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("\r\nToString: ");
                _msg.Append(_openFileDialog.ToString());
                Program._messageLog.WriteLine(_msg.ToString());
            }
            else
            {
                _msg.Length = 0;
                _msg.Append("Dialog result is ");
                _msg.Append(res.ToString());
                Program._messageLog.WriteLine(_msg.ToString());
            }

            return(res);
        }
Ejemplo n.º 25
0
        //application routines
        private void RunCopy()
        {
            try
            {
                DisableFormControls();
                _appProcessor.SaveErrorMessagesToAppLog = _saveErrorMessagesToAppLog;
                this.Cursor = Cursors.WaitCursor;

                if (this.chkEraseOutputBeforeEachTest.Checked)
                {
                    Program._messageLog.Clear();
                }

                if (optSQLServerSV2.Checked)
                {
                    _sourceDbPlatform       = DatabasePlatform.MSSQLServer;
                    _sourceConnectionString = _sv2ConnectionString;
                }
                else if (optSQLServerWS3.Checked)
                {
                    _sourceDbPlatform       = DatabasePlatform.MSSQLServer;
                    _sourceConnectionString = _ws3ConnectionString;
                }
                else
                {
                    _sourceDbPlatform       = DatabasePlatform.SQLServerCE35;
                    _sourceConnectionString = _ce35ConnectionString;
                }

                DatabasePlatform destDbPlatform = (DatabasePlatform)Enum.Parse(typeof(DatabasePlatform), this.cboDatabaseTypeForOutputTables.Text);

                _appProcessor.CopyAdventureWorksDW(_sourceDbPlatform, _sourceConnectionString,
                                                   destDbPlatform, this.txtConnectionStringForOutputTables.Text,
                                                   this.chkReplaceExistingTables.Checked, PFTextProcessor.ConvertStringToInt(this.txtOutputBatchSize.Text, 120), this.txtOutputTablesSchema.Text);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                EnableFormControls();
                this.Cursor = Cursors.Default;
                this.Focus();
            }
        }
Ejemplo n.º 26
0
        private PFColumnDefinitionsExt CreateColDefs(bool verifyNumbers)
        {
            int           numErrors = 0;
            StringBuilder errMsg    = new StringBuilder();

            if (this.listviewColDefs.Items.Count < 1)
            {
                return(null);
            }
            PFColumnDefinitionsExt colDefs = new PFColumnDefinitionsExt(this.listviewColDefs.Items.Count);

            //error message only shown if errors occur
            errMsg.Append("Unable to create PFColumnDefinitionsExt object.");
            errMsg.Append(Environment.NewLine);


            try
            {
                for (int i = 0; i < this.listviewColDefs.Items.Count; i++)
                {
                    colDefs.ColumnDefinition[i].SourceColumnName = this.listviewColDefs.Items[i].SubItems[_fieldNameInx].Text;
                    colDefs.ColumnDefinition[i].OutputColumnName = this.listviewColDefs.Items[i].SubItems[_columnNameInx].Text;
                    if (verifyNumbers)
                    {
                        if (PFTextProcessor.StringIsInt(this.listviewColDefs.Items[i].SubItems[_columnLengthInx].Text))
                        {
                            int colLen = Convert.ToInt32(this.listviewColDefs.Items[i].SubItems[_columnLengthInx].Text);
                            if (colLen > 0)
                            {
                                colDefs.ColumnDefinition[i].OutputColumnLength = Convert.ToInt32(this.listviewColDefs.Items[i].SubItems[_columnLengthInx].Text);
                            }
                            else
                            {
                                numErrors++;
                                errMsg.Append("Invalid negative output column length: ");
                                errMsg.Append(this.listviewColDefs.Items[i].SubItems[_columnLengthInx].Text);
                                errMsg.Append(Environment.NewLine);
                            }
                        }
                        else
                        {
                            numErrors++;
                            errMsg.Append("Invalid output column length: ");
                            errMsg.Append(this.listviewColDefs.Items[i].SubItems[_columnLengthInx].Text);
                            errMsg.Append(Environment.NewLine);
                        }
                    }
                    else
                    {
                        if (PFTextProcessor.StringIsInt(this.listviewColDefs.Items[i].SubItems[_columnLengthInx].Text))
                        {
                            colDefs.ColumnDefinition[i].OutputColumnLength = Convert.ToInt32(this.listviewColDefs.Items[i].SubItems[_columnLengthInx].Text);
                        }
                        else
                        {
                            colDefs.ColumnDefinition[i].OutputColumnLength = -1;
                        }
                    }
                    colDefs.ColumnDefinition[i].OutputColumnDataAlignment = (PFDataAlign)Enum.Parse(typeof(PFDataAlign), this.listviewColDefs.Items[i].SubItems[_colummAlignmentInx].Text);
                }
                if (numErrors > 0)
                {
                    throw new System.Exception(errMsg.ToString());
                }
            }
            catch (System.Exception ex)
            {
                colDefs     = null;
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                WriteToMessageLog(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }



            return(colDefs);
        }
Ejemplo n.º 27
0
        private void UpdateListView()
        {
            int           numErrors = 0;
            StringBuilder errMsg    = new StringBuilder();

            if (PFTextProcessor.StringIsInt(this.txtColumnNumber.Text.Trim()) == false)
            {
                numErrors++;
                errMsg.Append("You must specify the column number.");
                errMsg.Append(Environment.NewLine);
            }
            if (this.txtFieldName.Text.Trim().Length == 0)
            {
                numErrors++;
                errMsg.Append("You must specify a source data field name.");
                errMsg.Append(Environment.NewLine);
            }
            if (this.txtColumnName.Text.Trim().Length == 0)
            {
                numErrors++;
                errMsg.Append("You must specify a column name.");
                errMsg.Append(Environment.NewLine);
            }
            if (PFTextProcessor.StringIsInt(this.txtColumnWidth.Text.Trim()) == false)
            {
                numErrors++;
                errMsg.Append("You must specify a valid number for the column width.");
                errMsg.Append(Environment.NewLine);
            }
            int colLen = Convert.ToInt32(this.txtColumnWidth.Text.Trim());

            if (colLen < 1)
            {
                numErrors++;
                errMsg.Append("You must specify a valid positive number for the column width.");
                errMsg.Append(Environment.NewLine);
            }
            if (this.cboValueAlignment.Text.Trim().Length == 0)
            {
                numErrors++;
                errMsg.Append("You must specify a text alignment for the output value.");
                errMsg.Append(Environment.NewLine);
            }

            if (numErrors > 0)
            {
                AppMessages.DisplayErrorMessage(errMsg.ToString());
                return;
            }

            int    colNum    = Convert.ToInt32(this.txtColumnNumber.Text);
            string colNumStr = colNum.ToString(_colNumFormat);

            if (this.listviewColDefs.SelectedIndices.Count == 1)
            {
                //this is an update to an old item
                int          currItemInx = this.listviewColDefs.SelectedIndices[0];
                ListViewItem currItem    = this.listviewColDefs.Items[currItemInx];
                currItem.SubItems[0].Text = colNumStr;
                currItem.SubItems[1].Text = this.txtFieldName.Text;
                currItem.SubItems[2].Text = this.txtColumnName.Text;
                currItem.SubItems[3].Text = this.txtColumnWidth.Text;
                currItem.SubItems[4].Text = this.cboValueAlignment.Text;
                this.listviewColDefs.Sort();
                currItem.Selected = true;
                currItem.EnsureVisible();
                this.listviewColDefs.Refresh();
            }
            else
            {
                //this is a new item
                ListViewItem newItem = new ListViewItem(colNumStr);
                newItem.SubItems.Add(this.txtFieldName.Text);
                newItem.SubItems.Add(this.txtColumnName.Text);
                newItem.SubItems.Add(this.txtColumnWidth.Text.Trim());
                newItem.SubItems.Add(this.cboValueAlignment.Text);
                this.listviewColDefs.Items.Add(newItem);
                this.listviewColDefs.Sort();
                newItem.Selected = true;
                newItem.EnsureVisible();
                this.listviewColDefs.Refresh();
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Writes data contained in ADO.NET DataTable object to path stored in DocumentFilePath property.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be imported.</param>
        /// <returns>True if output operation is successful. False if write fails.</returns>
        public bool WriteDataToDocument(DataTable dt)
        {
            bool   success = true;
            object missing = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word.Application wordApp = null;
            Microsoft.Office.Interop.Word.Document    wordDoc = null;
            int numCols   = 0;
            int numRows   = 0;
            int tblRows   = 0;
            int curTblRow = 0;

            try
            {
                if (File.Exists(this.DocumentFilePath))
                {
                    if (_replaceExistingFile)
                    {
                        File.SetAttributes(this.DocumentFilePath, FileAttributes.Normal);
                        File.Delete(this.DocumentFilePath);
                    }
                    else
                    {
                        _msg.Length = 0;
                        _msg.Append("Word document file exists and ReplaceExistingFile set to False. Write to Word document has failed.");
                        throw new System.Exception(_msg.ToString());
                    }
                }

                numCols = dt.Columns.Count;
                numRows = dt.Rows.Count;
                tblRows = numRows + 1;

                wordApp         = new Microsoft.Office.Interop.Word.Application();
                wordApp.Visible = false;

                Microsoft.Office.Interop.Word.WdSaveFormat fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
                switch (this.WordOutputFormat)
                {
                case enWordOutputFormat.Word2007:
                    fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXMLDocument;
                    break;

                case enWordOutputFormat.Word2003:
                    fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
                    break;

                case enWordOutputFormat.RTF:
                    fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
                    break;

                case enWordOutputFormat.PDF:
                    fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
                    break;

                default:
                    fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
                    break;
                }

                wordDoc = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
                wordDoc.Content.SetRange(0, 0);
                Microsoft.Office.Interop.Word.Paragraph para1 = wordDoc.Content.Paragraphs.Add(ref missing);
                Microsoft.Office.Interop.Word.Table     tbl   = wordDoc.Tables.Add(para1.Range, tblRows, numCols, ref missing, ref missing);

                curTblRow = 1;
                for (int c = 0; c < dt.Columns.Count; c++)
                {
                    tbl.Rows[curTblRow].Cells[c + 1].Range.Text = dt.Columns[c].ColumnName;
                }

                for (int r = 0; r < dt.Rows.Count; r++)
                {
                    curTblRow++;
                    for (int c = 0; c < dt.Columns.Count; c++)
                    {
                        tbl.Rows[curTblRow].Cells[c + 1].Range.Text = dt.Rows[r][c].ToString();
                    }
                }


                tbl.AllowAutoFit = true;
                tbl.AutoFitBehavior(Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitWindow);
                wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
                wordDoc.PageSetup.PaperSize   = Microsoft.Office.Interop.Word.WdPaperSize.wdPaper11x17;

                wordDoc.SaveAs2(this.DocumentFilePath, fileFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                //wordDoc.Save();
                //wordDoc.Close(false);
                //wordApp.Quit(false);
                //((Microsoft.Office.Interop.Word._Document)wordDoc).Close(ref nullobject, ref nullobject, ref nullobject);
                //((Microsoft.Office.Interop.Word._Application)wordApp).Quit(ref nullobject, ref nullobject, ref nullobject);
                ((Microsoft.Office.Interop.Word._Document)wordDoc).Close(null, null, null);
                ((Microsoft.Office.Interop.Word._Application)wordApp).Quit(null, null, null);
            }
            catch (System.Exception ex)
            {
                success     = false;
                _msg.Length = 0;
                _msg.Append("Attempt to import DataTable into Word document failed.");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (wordApp != null)
                {
                    wordApp = null;
                }
            }

            return(success);
        }
Ejemplo n.º 29
0
        private bool UpdateUserConfigItems(bool forceUpdate)
        {
            bool updateSuccessful    = true;
            int  numErrors           = 0;
            int  numUpdates          = 0;
            bool reloadDatabaseTypes = false;

            _msg.Length = 0;

            if (this.txtDefaultQueryDefinitionsFolder.Text.ToUpper().Trim() != _userOptions.DefaultQueryDefinitionsFolder.ToUpper().Trim() ||
                forceUpdate == true)
            {
                if (Directory.Exists(this.txtDefaultQueryDefinitionsFolder.Text.ToUpper().Trim()) ||
                    this.txtDefaultQueryDefinitionsFolder.Text.ToUpper().Trim().Length == 0)
                {
                    numUpdates++;
                    pfDataViewerCP.Properties.Settings.Default["DefaultQueryDefinitionsFolder"] = this.txtDefaultQueryDefinitionsFolder.Text;
                }
                else
                {
                    numErrors++;
                    _msg.Append("DefaultQueryDefinitionsFolder does not exist: ");
                    _msg.Append(this.txtDefaultQueryDefinitionsFolder.Text);
                    _msg.Append(Environment.NewLine);
                }
            }

            if (this.txtDefaultDataGridExportFolder.Text.ToUpper().Trim() != _userOptions.DefaultDataGridExportFolder.ToUpper().Trim() ||
                forceUpdate == true)
            {
                if (Directory.Exists(this.txtDefaultDataGridExportFolder.Text.ToUpper().Trim()) ||
                    this.txtDefaultDataGridExportFolder.Text.ToUpper().Trim().Length == 0)
                {
                    numUpdates++;
                    pfDataViewerCP.Properties.Settings.Default["DefaultDataGridExportFolder"] = this.txtDefaultDataGridExportFolder.Text;
                }
                else
                {
                    numErrors++;
                    _msg.Append("DefaultDataGridExportFolder does not exist: ");
                    _msg.Append(this.txtDefaultDataGridExportFolder.Text);
                    _msg.Append(Environment.NewLine);
                }
            }

            if (this.chkSaveFormLocationsOnExit.Checked != _userOptions.SaveFormLocationsOnExit ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["SaveFormLocationsOnExit"] = this.chkSaveFormLocationsOnExit.Checked;
            }

            if (this.chkShowInstalledDatabaseProvidersOnly.Checked != _userOptions.ShowInstalledDatabaseProvidersOnly ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["ShowInstalledDatabaseProvidersOnly"] = this.chkShowInstalledDatabaseProvidersOnly.Checked;
                reloadDatabaseTypes = true;
            }

            if (this.chkShowApplicationLogWindow.Checked != _userOptions.ShowApplicationLogWindow ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["ShowApplicationLogWindow"] = this.chkShowApplicationLogWindow.Checked;
            }

            if (this.cboDefaultInputDatabaseType.Text != _userOptions.DefaultInputDatabaseType ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["DefaultInputDatabaseType"] = this.cboDefaultInputDatabaseType.Text;
            }

            if (this.txtDefaultInputDatabaseConnectionString.Text != _userOptions.DefaultInputDatabaseConnectionString ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["DefaultInputDatabaseConnectionString"] = this.txtDefaultInputDatabaseConnectionString.Text;
            }

            if (this.cboDefaultOutputDatabaseType.Text != _userOptions.DefaultOutputDatabaseType ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["DefaultOutputDatabaseType"] = this.cboDefaultOutputDatabaseType.Text;
            }

            if (this.txtDefaultOutputDatabaseConnectionString.Text != _userOptions.DefaultOutputDatabaseConnectionString ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["DefaultOutputDatabaseConnectionString"] = this.txtDefaultOutputDatabaseConnectionString.Text;
            }

            if (PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForDataImportsAndExports.Text, 0) != _userOptions.BatchSizeForDataImportsAndExports ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["BatchSizeForDataImportsAndExports"] = PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForDataImportsAndExports.Text, 1000);
            }

            if (PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForRandomDataGeneration.Text, 0) != _userOptions.BatchSizeForRandomDataGeneration ||
                forceUpdate == true)
            {
                numUpdates++;
                pfDataViewerCP.Properties.Settings.Default["BatchSizeForRandomDataGeneration"] = PFTextProcessor.ConvertStringToInt(this.txtBatchSizeForRandomDataGeneration.Text, 5000);
            }



            if (numErrors > 0)
            {
                AppMessages.DisplayErrorMessage(_msg.ToString());
            }

            _msg.Length = 0;
            if (numUpdates > 0)
            {
                //save the changes
                pfDataViewerCP.Properties.Settings.Default.Save();
                if (numErrors > 0)
                {
                    _msg.Append("Update results: ");
                    _msg.Append(numUpdates.ToString());
                    _msg.Append(" items updated.");
                    _msg.Append(numErrors.ToString());
                    _msg.Append(" update errors.");
                }
                else
                {
                    _msg.Append(numUpdates.ToString());
                    _msg.Append(" items were successfully updated.");
                    SaveUserConfigItems();
                    if (reloadDatabaseTypes)
                    {
                        InitDefaultDatabaseType(this.cboDefaultInputDatabaseType, this.txtDefaultInputDatabaseConnectionString);
                        InitDefaultDatabaseType(this.cboDefaultOutputDatabaseType, this.txtDefaultOutputDatabaseConnectionString); //added 4/16/15 MC
                    }
                }
            }
            else
            {
                if (numErrors > 0)
                {
                    _msg.Append(numErrors.ToString());
                    if (numErrors == 1)
                    {
                        _msg.Append(" error ");
                    }
                    else
                    {
                        _msg.Append(" errors ");
                    }
                    _msg.Append(" encountered during update.");
                }
                else
                {
                    _msg.Append("No updates were needed. No data changes found.");
                }
            }

            this.lblUpdateResults.Text = _msg.ToString();

            if (numErrors == 0)
            {
                updateSuccessful = true;
            }
            else
            {
                updateSuccessful = false;
            }

            return(updateSuccessful);
        }
Ejemplo n.º 30
0
        private object GetColumnValue(System.Type typ, string colValue)
        {
            object val = null;

            switch (typ.FullName)
            {
            case "System.String":
                val = (object)Convert.ToString(colValue);
                break;

            case "System.Int32":
                val = (object)Convert.ToInt32(colValue);
                break;

            case "System.UInt32":
                val = (object)Convert.ToUInt32(colValue);
                break;

            case "System.Int64":
                val = (object)Convert.ToInt64(colValue);
                break;

            case "System.UInt64":
                val = (object)Convert.ToUInt64(colValue);
                break;

            case "System.Int16":
                val = (object)Convert.ToInt16(colValue);
                break;

            case "System.UInt16":
                val = (object)Convert.ToUInt16(colValue);
                break;

            case "System.Double":
                val = (object)Convert.ToDouble(colValue);
                break;

            case "System.Single":
                val = (object)Convert.ToSingle(colValue);
                break;

            case "System.Decimal":
                val = (object)Convert.ToDecimal(colValue);
                break;

            case "System.Boolean":
                val = (object)Convert.ToBoolean(colValue);
                break;

            case "System.Char":
                val = (object)Convert.ToChar(colValue);
                break;

            case "System.Char[]":
                val = (object)colValue.ToCharArray();
                break;

            case "System.Byte":
                val = (object)Convert.ToByte(colValue);
                break;

            case "System.Byte[]":
                val = (object)PFTextProcessor.ConvertStringToByteArray(colValue);
                break;

            case "System.SByte":
                val = (object)Convert.ToSByte(colValue);
                break;

            case "System.DateTime":
                val = (object)Convert.ToDateTime(colValue);
                break;

            case "System.Guid":
                val = (object)new Guid(colValue);
                break;

            case "System.Object":
                val = (object)PFTextProcessor.ConvertStringToByteArray(colValue);
                break;

            default:
                val = (object)PFTextProcessor.ConvertStringToByteArray(colValue);
                break;
            }


            return(val);
        }