Fixed a bug that caused the ModifyRecord form to crash on load if the cursor was over the top left hand header cell. Set a timeout for the restore SQL statement to hopefully prevent a timeout exception from being thrown. Minor code clean up.

This commit is contained in:
2018-04-04 01:47:02 -05:00
parent 65dd82cd31
commit f2fe8c592f
10 changed files with 45 additions and 62 deletions
@@ -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")]
+19 -32
View File
@@ -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;
@@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AdvertsingProfitControl</RootNamespace>
<AssemblyName>AdvertsingProfitControl</AssemblyName>
<AssemblyName>AdvertisingProfitControl</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
+2 -2
View File
@@ -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;
+7 -17
View File
@@ -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;
}
}
+1 -2
View File
@@ -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();
+9 -2
View File
@@ -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;
@@ -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")]
+1 -1
View File
@@ -54,7 +54,7 @@ namespace AdvertsingProfitControl
}
catch (IOException e)
{
Logger.WriteLog(DateTime.Now, "Generate Full Report", e.Message, Level.Error);
}
finally
{
+1 -1
View File
@@ -109,7 +109,7 @@
<File Source="$(var.SolutionDir)AdvertsingProfitControl\ssleay32.dll"/>
</Component>
<Component Id="wkhtmltox0">
<File Source="$(var.SolutionDir)AdvertsingProfitControl\wkhtmltox0.dll"/>
<File Source="$(var.SolutionDir)AdvertsingProfitControl\wkhtmltox0.dll" xml:lang="en-us"/>
</Component>
<Component Id="Spire">
<File Source="$(var.SolutionDir)\packages\FreeSpire.PDF.3.2\lib\net40\Spire.License.dll"/>