diff --git a/AdvertisingProfitControlData/Properties/AssemblyInfo.cs b/AdvertisingProfitControlData/Properties/AssemblyInfo.cs index d87bdb4..07b5f85 100644 --- a/AdvertisingProfitControlData/Properties/AssemblyInfo.cs +++ b/AdvertisingProfitControlData/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.0.1")] +[assembly: AssemblyFileVersion("1.0.0.1")] diff --git a/AdvertisingProfitControlData/Restore.cs b/AdvertisingProfitControlData/Restore.cs index ca2a8ff..c26ba33 100644 --- a/AdvertisingProfitControlData/Restore.cs +++ b/AdvertisingProfitControlData/Restore.cs @@ -1,5 +1,4 @@ -using System.Data; -using System.Data.SqlClient; +using System.Data.SqlClient; namespace AdvertisingProfitControlData { @@ -14,39 +13,27 @@ namespace AdvertisingProfitControlData { using (var conn = new SqlConnection(connectionString)) { - // var db = new AdvertisingProfitControlDbContext(); - //Drop the database to make sure it can be recreated and restored (necessary since the database MUST be on line for its file to be wiped from disk). - //if (db.Database.Connection.State == ConnectionState.Open) - //{ - // db.Database.Connection.Close(); - //} var query = - @"BEGIN TRY - DECLARE @DefaultDataPath varchar(max) - DECLARE @DefaultLogPath varchar(max) - SELECT @DefaultDataPath = CONVERT(varchar(max),SERVERPROPERTY('INSTANCEDEFAULTDATAPATH')) - SELECT @DefaultLogPath = CONVERT(varchar(max),SERVERPROPERTY('INSTANCEDEFAULTLOGPATH')) - SELECT @DefaultDataPath = CONCAT(@DefaultDataPath, N'" + sqlConStrBuilder.InitialCatalog + @".mdf') - SELECT @DefaultLogPath = CONCAT(@DefaultLogPath, N'" + sqlConStrBuilder.InitialCatalog + @".ldf') - IF db_id(N'" + sqlConStrBuilder.InitialCatalog + @"') IS NOT NULL - BEGIN - ALTER DATABASE " + sqlConStrBuilder.InitialCatalog + @" SET SINGLE_USER WITH ROLLBACK IMMEDIATE - DROP DATABASE " + sqlConStrBuilder.InitialCatalog + @" - CREATE DATABASE " + sqlConStrBuilder.InitialCatalog + @" - END - RESTORE DATABASE " + sqlConStrBuilder.InitialCatalog + @" FROM DISK ='" + databaseFilePath + @"' WITH CHECKSUM, REPLACE, - MOVE '" + sqlConStrBuilder.InitialCatalog + @"' TO @DefaultDataPath, - MOVE '" + sqlConStrBuilder.InitialCatalog + @"_log' TO @DefaultLogPath - END TRY - BEGIN CATCH - ALTER DATABASE " + sqlConStrBuilder.InitialCatalog + @" SET MULTI_USER - DECLARE @Error varchar(max) - SELECT @Error = ERROR_MESSAGE() - RAISERROR(@Error, 11, 1) - END CATCH"; + @"BEGIN TRY + use master + ALTER DATABASE " + sqlConStrBuilder.InitialCatalog + @" SET SINGLE_USER + DROP DATABASE AdvertisingProfitControl + RESTORE DATABASE " + sqlConStrBuilder.InitialCatalog + @" FROM Disk='" + databaseFilePath + @"' with checksum + END TRY + BEGIN CATCH + DECLARE @Error VARCHAR(max) + SELECT @Error = ERROR_MESSAGE() + ALTER DATABASE " + sqlConStrBuilder.InitialCatalog + @" SET MULTI_USER + RAISERROR(@Error, 11, 1) + END CATCH + ALTER DATABASE " + sqlConStrBuilder.InitialCatalog + @" SET MULTI_USER + "; //TODO: Verify that the database is good with DBCC command. conn.Open(); - var restoreCmd = new SqlCommand(query, conn); + var restoreCmd = new SqlCommand(query, conn) + { + CommandTimeout = 300 + }; restoreCmd.ExecuteNonQuery(); conn.Close(); return true; diff --git a/AdvertsingProfitControl/AdvertsingProfitControl.csproj b/AdvertsingProfitControl/AdvertsingProfitControl.csproj index 8de963b..1217c92 100644 --- a/AdvertsingProfitControl/AdvertsingProfitControl.csproj +++ b/AdvertsingProfitControl/AdvertsingProfitControl.csproj @@ -8,7 +8,7 @@ WinExe Properties AdvertsingProfitControl - AdvertsingProfitControl + AdvertisingProfitControl v4.5 512 diff --git a/AdvertsingProfitControl/DatabaseRecovery.cs b/AdvertsingProfitControl/DatabaseRecovery.cs index 95c7665..39c72f3 100644 --- a/AdvertsingProfitControl/DatabaseRecovery.cs +++ b/AdvertsingProfitControl/DatabaseRecovery.cs @@ -92,7 +92,7 @@ namespace AdvertsingProfitControl } } - if (backup.SingleFileBackup(customBackupLocation)) + if (backup.SingleFileBackup(Properties.Settings.Default.ConnectionString, customBackupLocation)) { //Check the state of the backup. if (backup.State == 0) @@ -196,7 +196,7 @@ namespace AdvertsingProfitControl return; } - if (restore.SingleFileRestore(restoreLocationTextBox.Text, Properties.Settings.Default.DefaultServer)) + if (restore.SingleFileRestore(restoreLocationTextBox.Text, Properties.Settings.Default.ConnectionString)) { restoreResultLabel.Text = @"Successfully restored the database."; restoreLocationTextBox.Text = string.Empty; diff --git a/AdvertsingProfitControl/FrmLoginForm.Designer.cs b/AdvertsingProfitControl/FrmLoginForm.Designer.cs index b8396a1..16aef6f 100644 --- a/AdvertsingProfitControl/FrmLoginForm.Designer.cs +++ b/AdvertsingProfitControl/FrmLoginForm.Designer.cs @@ -41,7 +41,6 @@ this.informationLabel = new System.Windows.Forms.Label(); this.mainMenu = new System.Windows.Forms.MenuStrip(); this.databaseToolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.backupRestoreMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.checkIntegrityToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mainMenu.SuspendLayout(); this.SuspendLayout(); @@ -70,7 +69,7 @@ // this.connectButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.connectButton.Location = new System.Drawing.Point(421, 257); - this.connectButton.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5); + this.connectButton.Margin = new System.Windows.Forms.Padding(5); this.connectButton.Name = "connectButton"; this.connectButton.Size = new System.Drawing.Size(128, 35); this.connectButton.TabIndex = 5; @@ -87,7 +86,7 @@ "Windows Authentication", "SQL Server Authentication"}); this.authenticationTypeComboBox.Location = new System.Drawing.Point(146, 108); - this.authenticationTypeComboBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.authenticationTypeComboBox.Margin = new System.Windows.Forms.Padding(2); this.authenticationTypeComboBox.MaxDropDownItems = 5; this.authenticationTypeComboBox.Name = "authenticationTypeComboBox"; this.authenticationTypeComboBox.Size = new System.Drawing.Size(230, 28); @@ -117,7 +116,7 @@ // this.loginTextBox.Enabled = false; this.loginTextBox.Location = new System.Drawing.Point(146, 163); - this.loginTextBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.loginTextBox.Margin = new System.Windows.Forms.Padding(2); this.loginTextBox.Name = "loginTextBox"; this.loginTextBox.Size = new System.Drawing.Size(230, 26); this.loginTextBox.TabIndex = 3; @@ -126,7 +125,7 @@ // this.passwordTextBox.Enabled = false; this.passwordTextBox.Location = new System.Drawing.Point(146, 216); - this.passwordTextBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.passwordTextBox.Margin = new System.Windows.Forms.Padding(2); this.passwordTextBox.Name = "passwordTextBox"; this.passwordTextBox.PasswordChar = '*'; this.passwordTextBox.RightToLeft = System.Windows.Forms.RightToLeft.No; @@ -137,7 +136,7 @@ // this.serverNameComboBox.FormattingEnabled = true; this.serverNameComboBox.Location = new System.Drawing.Point(146, 53); - this.serverNameComboBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.serverNameComboBox.Margin = new System.Windows.Forms.Padding(2); this.serverNameComboBox.Name = "serverNameComboBox"; this.serverNameComboBox.Size = new System.Drawing.Size(371, 28); this.serverNameComboBox.TabIndex = 1; @@ -166,23 +165,15 @@ // databaseToolsToolStripMenuItem // this.databaseToolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.backupRestoreMainMenu, this.checkIntegrityToolStripMenuItem}); this.databaseToolsToolStripMenuItem.Name = "databaseToolsToolStripMenuItem"; this.databaseToolsToolStripMenuItem.Size = new System.Drawing.Size(144, 29); this.databaseToolsToolStripMenuItem.Text = "&Database Tools"; // - // backupRestoreMainMenu - // - this.backupRestoreMainMenu.Name = "backupRestoreMainMenu"; - this.backupRestoreMainMenu.Size = new System.Drawing.Size(252, 30); - this.backupRestoreMainMenu.Text = "&Backup and Restore"; - this.backupRestoreMainMenu.Click += new System.EventHandler(this.backupRestoreToolStripMenuItem_Click); - // // checkIntegrityToolStripMenuItem // this.checkIntegrityToolStripMenuItem.Name = "checkIntegrityToolStripMenuItem"; - this.checkIntegrityToolStripMenuItem.Size = new System.Drawing.Size(252, 30); + this.checkIntegrityToolStripMenuItem.Size = new System.Drawing.Size(214, 30); this.checkIntegrityToolStripMenuItem.Text = "&Check Integrity"; this.checkIntegrityToolStripMenuItem.Click += new System.EventHandler(this.checkIntegrityToolStripMenuItem_Click); // @@ -206,7 +197,7 @@ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MainMenuStrip = this.mainMenu; - this.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5); + this.Margin = new System.Windows.Forms.Padding(5); this.MaximizeBox = false; this.Name = "FrmLoginForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; @@ -231,7 +222,6 @@ private System.Windows.Forms.Label informationLabel; private System.Windows.Forms.MenuStrip mainMenu; private System.Windows.Forms.ToolStripMenuItem databaseToolsToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem backupRestoreMainMenu; private System.Windows.Forms.ToolStripMenuItem checkIntegrityToolStripMenuItem; } } \ No newline at end of file diff --git a/AdvertsingProfitControl/FrmMain.cs b/AdvertsingProfitControl/FrmMain.cs index 4dd548b..b659cf7 100644 --- a/AdvertsingProfitControl/FrmMain.cs +++ b/AdvertsingProfitControl/FrmMain.cs @@ -512,8 +512,7 @@ namespace AdvertsingProfitControl var adSpecialIndex = -1; decimal totalSales = 0; decimal totalProfitReturn = 0; - var projections = db.Projections.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x).OrderBy(x => x.RowPosition); - + var projections = db.Projections.Where(x => x.WeekEndingDate.Id == dateRecord.Id).Select(x => x).OrderBy(x => x.RowPosition); foreach (var p in projections) { projectionsDataGridView.Rows.Add(); diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs index 91fb5a6..0aa4db0 100644 --- a/AdvertsingProfitControl/NewModifyRecord.cs +++ b/AdvertsingProfitControl/NewModifyRecord.cs @@ -77,14 +77,13 @@ namespace AdvertsingProfitControl public NewModifyRecord(DateTime date) { - InitializeComponent(); + InitializeComponent(); // weekEndingCalendar.SelectionStart = date; _currentActiveDate = date; InitializeForm(); mainTabControl.TabPages.Remove(mainTabControl.TabPages[4]); Text = @"Modify Record (Current Record: " + date.ToShortDateString() + @")"; - _isModifyingRecord = true; LoadDate(date); } @@ -2728,6 +2727,14 @@ out double beginningBinCount, out string _)) public void InitializeForm() { + //Apply a little nonsense fix for a but that occurs with the DataGridView control where if a cursor + //is placed over the top left hand header cell, it causes an InvalidOperationException. This mainly + //effects this form when its overloaded constructor is called since the mouse cursor is right on top + //of the aforementioned cell after clicking the "Modify Existing Record" menu option on the main form. + //More info one the bug here https://stackoverflow.com/questions/34344499/invalidoperationexception-this-operation-cannot-be-performed-while-an-auto-fill + //The following fix is applied to the projections DataGridView since its the first grid displayed to the user. + //The fix is simple however, force the form to create the cell as follows: + var projectionsLeftHeaderCell = projectionsDataGridView.TopLeftHeaderCell; var db = new AdvertisingProfitControlDbContext(); weekEndingCalendar.BoldedDates = db.WeekEndingDates.Select(zdate => zdate.EndingDate).ToArray(); weekEndingCalendar.DateChanged += ValidateDateChanged; diff --git a/AdvertsingProfitControl/Properties/AssemblyInfo.cs b/AdvertsingProfitControl/Properties/AssemblyInfo.cs index 5e19a28..4614a48 100644 --- a/AdvertsingProfitControl/Properties/AssemblyInfo.cs +++ b/AdvertsingProfitControl/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.5.*")] -[assembly: AssemblyFileVersion("3.5.1.0")] +[assembly: AssemblyVersion("3.7.0.0")] +[assembly: AssemblyFileVersion("3.7.0.0")] diff --git a/AdvertsingProfitControl/ReportGenerator.cs b/AdvertsingProfitControl/ReportGenerator.cs index 94f010d..d5dec81 100644 --- a/AdvertsingProfitControl/ReportGenerator.cs +++ b/AdvertsingProfitControl/ReportGenerator.cs @@ -54,7 +54,7 @@ namespace AdvertsingProfitControl } catch (IOException e) { - + Logger.WriteLog(DateTime.Now, "Generate Full Report", e.Message, Level.Error); } finally { diff --git a/SetupProject/Product.wxs b/SetupProject/Product.wxs index d83a4f7..389b63a 100644 --- a/SetupProject/Product.wxs +++ b/SetupProject/Product.wxs @@ -109,7 +109,7 @@ - +