From 62a2c0f80e514dbdcd13582a1dd9b54b6773c999 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Tue, 11 Apr 2017 02:26:04 -0500 Subject: [PATCH] Created forms to allow the management of ad items, suppliers and ad special keywords. Updated the database migration tool to include the ad special table. Cleaned up the main form's code and did a slight touch up of the interface. --- AdvertsingProfitControl/APCDatabase.accdb | Bin 864256 -> 864256 bytes .../AdvertsingProfitControl.csproj | 18 + .../DebugDatabaseConverter.Designer.cs | 2 +- .../DebugDatabaseConverter.cs | 162 +++++---- AdvertsingProfitControl/FrmMain.Designer.cs | 97 +++-- AdvertsingProfitControl/FrmMain.cs | 344 ++++++++++-------- .../FrmManageAdItems.Designer.cs | 173 +++++++++ AdvertsingProfitControl/FrmManageAdItems.cs | 256 +++++++++++++ AdvertsingProfitControl/FrmManageAdItems.resx | 120 ++++++ .../FrmManageSuppliers.Designer.cs | 151 ++++++++ AdvertsingProfitControl/FrmManageSuppliers.cs | 180 +++++++++ .../FrmManageSuppliers.resx | 120 ++++++ .../FrmRegisterAdSpecial.Designer.cs | 22 +- .../FrmRegisterAdSpecial.cs | 78 ++-- ...gProfitControl.csproj.FileListAbsolute.txt | 23 ++ 15 files changed, 1443 insertions(+), 303 deletions(-) create mode 100644 AdvertsingProfitControl/FrmManageAdItems.Designer.cs create mode 100644 AdvertsingProfitControl/FrmManageAdItems.cs create mode 100644 AdvertsingProfitControl/FrmManageAdItems.resx create mode 100644 AdvertsingProfitControl/FrmManageSuppliers.Designer.cs create mode 100644 AdvertsingProfitControl/FrmManageSuppliers.cs create mode 100644 AdvertsingProfitControl/FrmManageSuppliers.resx create mode 100644 AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.csproj.FileListAbsolute.txt diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb index be1a05428abf55eac2c04cec35a770dc6cf7fa8a..0553c54d9b0eea3660c28577c5e2bc3846bddb79 100644 GIT binary patch delta 142 zcmZp8VAAlwWCIf)^FLPA&4PUI87C|7@iYl+6JR{S$M&^Xg`@e^^mB5I5{zfspUW|} zKbK=_e=f(|{#=fw{ka_L_UCeJHvzlg2n*;RBD+_Og#WF-+4fGq}XIOMKyZVGRJrr!-jr delta 140 zcmZp8VAAlwWCIf)^D0)=&4PUI87C|7@iYl+6JR{S$F_)zvt;kf>F4AaB^bA~KbK={ ze=f(={#=f^{ka@V`*S(g?a$@dZU!)Nw;#-BYd@IJ-hMEjqy1n$XZyi?uJ(iZ+}jW4 w^Efu}1akR=Ir=a#FfeRo*e>vaCxdbOvX4A5OcOU4Ot;M765B5Eh3ADe02pC2fdBvi diff --git a/AdvertsingProfitControl/AdvertsingProfitControl.csproj b/AdvertsingProfitControl/AdvertsingProfitControl.csproj index 4cb1db2..25301a2 100644 --- a/AdvertsingProfitControl/AdvertsingProfitControl.csproj +++ b/AdvertsingProfitControl/AdvertsingProfitControl.csproj @@ -128,6 +128,18 @@ DebugDatabaseConverter.cs + + Form + + + FrmManageAdItems.cs + + + Form + + + FrmManageSuppliers.cs + Form @@ -188,6 +200,12 @@ FrmLogConsole.cs + + FrmManageAdItems.cs + + + FrmManageSuppliers.cs + FrmRegisterAdSpecial.cs diff --git a/AdvertsingProfitControl/DebugDatabaseConverter.Designer.cs b/AdvertsingProfitControl/DebugDatabaseConverter.Designer.cs index 23d5744..5ccc135 100644 --- a/AdvertsingProfitControl/DebugDatabaseConverter.Designer.cs +++ b/AdvertsingProfitControl/DebugDatabaseConverter.Designer.cs @@ -83,7 +83,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(849, 827); + this.ClientSize = new System.Drawing.Size(701, 592); this.Controls.Add(this.convertButton); this.Controls.Add(this.moveOverButton); this.Controls.Add(this.datesToConvertListBox); diff --git a/AdvertsingProfitControl/DebugDatabaseConverter.cs b/AdvertsingProfitControl/DebugDatabaseConverter.cs index 92c7005..9ef96b0 100644 --- a/AdvertsingProfitControl/DebugDatabaseConverter.cs +++ b/AdvertsingProfitControl/DebugDatabaseConverter.cs @@ -1,15 +1,9 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Data; using System.Data.OleDb; -using System.Drawing; -using System.Globalization; using System.IO; using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; using System.Transactions; using System.Windows.Forms; @@ -113,6 +107,18 @@ namespace AdvertsingProfitControl db.Suppliers.Add(temp); db.SaveChanges(); } + var adSpecials = GetAdSpecials(); + foreach (var adSpecial in adSpecials) + { + var db = new AdvertisingProfitControlModel(); + if(db.AdSpecials.Any(x => x.Name == adSpecial)) continue; + var tempAd = new AdSpecial + { + Name = adSpecial + }; + db.AdSpecials.Add(tempAd); + db.SaveChanges(); + } foreach (var date in datesToConvertListBox.Items) { var oldDateId = GetDateIdByDateString(date.ToString()); @@ -145,30 +151,7 @@ namespace AdvertsingProfitControl { db.WeekEndingDates.Add(date); } - //oleDbConnection.Open(); - //oleDbTransaction = oleDbConnection.BeginTransaction(); - //oleDbCommand.Transaction = oleDbTransaction; - ////Get the date ID for the date string - //oleDbCommand.CommandText = "INSERT INTO WeekEnding (EndOfWeekDate) VALUES (?)"; - //oleDbCommand.Parameters.AddWithValue("DateString", dateString); - //var rowsEffected = oleDbCommand.ExecuteNonQuery(); - //oleDbCommand.Parameters.Clear(); - //if (rowsEffected == 0) - //{ - // oleDbTransaction.Rollback(); - // MessageBox.Show(@"Failed on date"); - // return; - //} - //oleDbCommand.CommandText = "SELECT WeekEnding.ID FROM WeekEnding WHERE EndOfWeekDate = ?"; - //oleDbCommand.Parameters.AddWithValue("Date", dateString); - //var reader = oleDbCommand.ExecuteReader(); - //oleDbCommand.Parameters.Clear(); - //var dateId = 0; - //while (reader != null && reader.Read()) - //{ - // dateId = int.Parse(reader[0].ToString()); - //} - //reader?.Close(); + var adSpecialId = -1; for (var rowIndex = 0; rowIndex < projections.Rows.Count; rowIndex++) { var projectionedSale = new Projection(); @@ -197,34 +180,29 @@ namespace AdvertsingProfitControl projectionedSale.TotalProfitReturn = decimal.Parse(projections.Rows[rowIndex][6].ToString()); projectionedSale.FkAdItemId = db.AdItems.First(x => x.Id == adItemId).Id; projectionedSale.RowAttribute = int.Parse(projections.Rows[rowIndex][7].ToString()); - projectionedSale.FkAdSpecialId = (int) projections.Rows[rowIndex][8]; + + if ((int) projections.Rows[rowIndex][8] == 0 && adSpecialId == -1) + { + projectionedSale.FkAdSpecialId = null; + } + else + { + if ((int) (projections.Rows[rowIndex][8]) == 0) + { + projectionedSale.FkAdSpecialId = adSpecialId; + } + else + { + adSpecialId = (int) projections.Rows[rowIndex][8]; + projectionedSale.FkAdSpecialId = (int) projections.Rows[rowIndex][8]; + } + } projectionedSale.RowPosition = rowIndex + 1; projectionedSale.FkDateId = date.Id; db.Projections.Add(projectionedSale); - //Get the ID number of the ad item. - // //Get the ID number of the ad item. - // var adItemId = int.Parse(RetrieveAdItemId(projections.Rows[rowIndex][0].ToString())); - // //Get the group name of the ad special its in. - // adspecialId = GetAdSpecialId(int.Parse(projections.Rows[rowIndex][8].ToString())); - // oleDbCommand.CommandText = - // "INSERT INTO Projections (Sold, SalePrice, TotalSales, Cost, ProfitReturn, TotalProfitReturn, FK_AdItemID, RowAttribute, FK_AdSpecialGroupName, RowPosition, FK_DateID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - // //SELECT AdItem.AdItem, APC.ProjectionSold, APC.ProjectionSalePrice, APC.ProjectionTotalSales, APC.ProjectionCost, APC.ProjectionProfitReturn, APC.ProjectionTotalProfitReturn, APC.RowAttribute, APC.FK_GroupID FROM (AdItem INNER JOIN APC ON AdItem.ID = APC.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC - // oleDbCommand.Parameters.AddWithValue("Sold", projections.Rows[rowIndex][1]); - // oleDbCommand.Parameters.AddWithValue("SalesPrice", projections.Rows[rowIndex][2]); - // oleDbCommand.Parameters.AddWithValue("TotalSales", projections.Rows[rowIndex][3]); - // oleDbCommand.Parameters.AddWithValue("Cost", projections.Rows[rowIndex][4]); - // oleDbCommand.Parameters.AddWithValue("ProfitReturn", projections.Rows[rowIndex][5]); - // oleDbCommand.Parameters.AddWithValue("TotalProfitReturn", projections.Rows[rowIndex][6]); - // oleDbCommand.Parameters.AddWithValue("adItemID", adItemId); - // oleDbCommand.Parameters.AddWithValue("RowAttribute", - // int.Parse(projections.Rows[rowIndex][7].ToString())); - // oleDbCommand.Parameters.AddWithValue("adSpecialID", adspecialId); - // oleDbCommand.Parameters.AddWithValue("RowPosition", (rowIndex + 1)); - // oleDbCommand.Parameters.AddWithValue("dateID", dateId); - // oleDbCommand.ExecuteNonQuery(); - // oleDbCommand.Parameters.Clear(); } //inventory + adSpecialId = -1; for (var i = 0; i < inventory.Rows.Count; i++) { var inventoryObject = new Inventory(); @@ -243,40 +221,39 @@ namespace AdvertsingProfitControl inventoryObject.EndingInventory = inventory.Rows[i][4].ToString(); inventoryObject.FkAdItemId = adItemId; inventoryObject.RowAttribute = int.Parse(inventory.Rows[i][5].ToString()); - inventoryObject.FkAdSpecialId = int.Parse(inventory.Rows[i][6].ToString()); + if ((int)inventory.Rows[i][6] == 0 && adSpecialId == -1) + { + inventoryObject.FkAdSpecialId = null; + } + else + { + if ((int)(inventory.Rows[i][6]) == 0) + { + inventoryObject.FkAdSpecialId = adSpecialId; + } + else + { + adSpecialId = (int)inventory.Rows[i][6]; + inventoryObject.FkAdSpecialId = (int)inventory.Rows[i][6]; + } + } inventoryObject.RowPosition = i + 1; inventoryObject.FkDateId = date.Id; db.Inventories.Add(inventoryObject); - // var adItemId = int.Parse(RetrieveAdItemId(inventory.Rows[i][0].ToString())); - // adspecialId = GetAdSpecialId(int.Parse(inventory.Rows[i][6].ToString())); - // oleDbCommand.CommandText = - // "INSERT INTO Inventory (BeginningInventory, Received, TotalInventory, EndingInventory, FK_AdItemID, RowAttribute, FK_AdSpecialGroupName, RowPosition, FK_DateID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; - // //"SELECT AdItem.AdItem, APC.BeginingInventory, APC.Received, APC.TotalInventory, APC.EndingInventory, APC.RowAttribute, APC.FK_GroupID FROM (AdItem INNER JOIN APC ON AdItem.ID = APC.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC" - // oleDbCommand.Parameters.AddWithValue("BeginningInventory", inventory.Rows[i][1].ToString()); - // oleDbCommand.Parameters.AddWithValue("Received", inventory.Rows[i][2].ToString()); - // oleDbCommand.Parameters.AddWithValue("TotalInventory", inventory.Rows[i][3].ToString()); - // oleDbCommand.Parameters.AddWithValue("EndingInventory", inventory.Rows[i][4].ToString()); - // oleDbCommand.Parameters.AddWithValue("AdItemID", adItemId); - // oleDbCommand.Parameters.AddWithValue("RowAttribute", int.Parse(inventory.Rows[i][5].ToString())); - // oleDbCommand.Parameters.AddWithValue("FK_AdSpecialGroup", adspecialId); - // oleDbCommand.Parameters.AddWithValue("RowPosition", (i + 1)); - // oleDbCommand.Parameters.AddWithValue("DateID", dateId); - // oleDbCommand.ExecuteNonQuery(); - // oleDbCommand.Parameters.Clear(); } //actual sales + adSpecialId = -1; for (var rowIndex = 0; rowIndex < actualSales.Rows.Count; rowIndex++) { var actualSale = new ActualSale(); //Get the ID number of the ad item. - AdItem adItem; var adItemId = 0; var spam = TextFormat.FormatAdItemText(actualSales.Rows[rowIndex][0].ToString()); if (db.AdItems.Any(x => x.Name == spam)) { //Exists - adItem = db.AdItems.First(x => x.Name == spam); + var adItem = db.AdItems.First(x => x.Name == spam); adItemId = adItem.Id; } //adspecialId = GetAdSpecialId(int.Parse(actualSales.Rows[rowIndex][8].ToString())); @@ -293,7 +270,22 @@ namespace AdvertsingProfitControl actualSale.TotalProfitReturn = decimal.Parse(actualSales.Rows[rowIndex][6].ToString()); actualSale.FkAdItemId = adItemId; actualSale.RowAttribute = int.Parse(actualSales.Rows[rowIndex][7].ToString()); - actualSale.FkAdSpecialId = (int) actualSales.Rows[rowIndex][8]; + if ((int)actualSales.Rows[rowIndex][8] == 0 && adSpecialId == -1) + { + actualSale.FkAdSpecialId = null; + } + else + { + if ((int)(projections.Rows[rowIndex][8]) == 0) + { + actualSale.FkAdSpecialId = adSpecialId; + } + else + { + adSpecialId = (int)actualSales.Rows[rowIndex][8]; + actualSale.FkAdSpecialId = (int)actualSales.Rows[rowIndex][8]; + } + } actualSale.RowPosition = rowIndex + 1; actualSale.FkDateId = date.Id; //db.WeekEndingDates.First(x => x.Id == dateId); //oleDbCommand.Parameters.AddWithValue("Sold", actualSales.Rows[rowIndex][1]); @@ -472,6 +464,30 @@ namespace AdvertsingProfitControl return adItems; } + public List GetAdSpecials() + { + var adItems = new List(); + var oleDbCommand = new OleDbCommand + { + CommandText = "SELECT AdSpecialName.AdSpecialName FROM AdSpecialName" + }; + var connection = new OleDbConnection(_connectionString); + oleDbCommand.Connection = connection; + using (connection) + { + using (oleDbCommand) + { + connection.Open(); + var reader = oleDbCommand.ExecuteReader(); + while (reader != null && reader.Read()) + { + adItems.Add(reader[0].ToString()); + } + } + } + return adItems; + } + public int GetSupplierId(string supplierName) { var supplier = new Supplier(); diff --git a/AdvertsingProfitControl/FrmMain.Designer.cs b/AdvertsingProfitControl/FrmMain.Designer.cs index 65d58dc..07fffd5 100644 --- a/AdvertsingProfitControl/FrmMain.Designer.cs +++ b/AdvertsingProfitControl/FrmMain.Designer.cs @@ -36,10 +36,14 @@ this.recordsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.addRecordsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.modifyRecordMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.reportsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.toolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); - this.adSpecialKeyWordsToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.clearRecordToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.clearCurrentRecordSelectedDateToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.selectRangeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.manageItemsToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); - this.clearSelectedDateToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.manageSuppliersToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.adSpecialKeyWordsToolsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.helpMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.showHideConsoleHelpMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.dbVersionHelpMainMenu = new System.Windows.Forms.ToolStripMenuItem(); @@ -104,7 +108,6 @@ this.grossProfitEstimatedWeeklyDeptmartmentExpenseLabel = new System.Windows.Forms.Label(); this.perfectGrossProfitLabel = new System.Windows.Forms.Label(); this.grossProfitDollarGrossProfitLabel = new System.Windows.Forms.Label(); - this.reportsMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.mainMenu.SuspendLayout(); this.mainTableLayoutPanel.SuspendLayout(); this.commentMainTableLayoutPanel.SuspendLayout(); @@ -186,46 +189,76 @@ this.addRecordsToolStripMenuItem.Name = "addRecordsToolStripMenuItem"; this.addRecordsToolStripMenuItem.Size = new System.Drawing.Size(323, 34); this.addRecordsToolStripMenuItem.Text = "&Add New Record"; - this.addRecordsToolStripMenuItem.Click += new System.EventHandler(this.addRecordToolStripMenuItem_Click); + this.addRecordsToolStripMenuItem.Click += new System.EventHandler(this.DisplayNewRecordForm); // // modifyRecordMainMenu // this.modifyRecordMainMenu.Name = "modifyRecordMainMenu"; this.modifyRecordMainMenu.Size = new System.Drawing.Size(323, 34); this.modifyRecordMainMenu.Text = "&Modify Existing Record "; - this.modifyRecordMainMenu.Click += new System.EventHandler(this.modifyRecordMainMenu_Click); + this.modifyRecordMainMenu.Click += new System.EventHandler(this.DisplayModifyRecordForm); + // + // reportsMainMenu + // + this.reportsMainMenu.Name = "reportsMainMenu"; + this.reportsMainMenu.Size = new System.Drawing.Size(95, 34); + this.reportsMainMenu.Text = "R&eports"; + this.reportsMainMenu.Visible = false; // // toolsMainMenu // this.toolsMainMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.clearSelectedDateToolsMainMenu, + this.clearRecordToolsMainMenu, this.manageItemsToolsMainMenu, + this.manageSuppliersToolsMainMenu, this.adSpecialKeyWordsToolsMainMenu}); this.toolsMainMenu.Name = "toolsMainMenu"; this.toolsMainMenu.Size = new System.Drawing.Size(72, 34); this.toolsMainMenu.Text = "&Tools"; // - // adSpecialKeyWordsToolsMainMenu + // clearRecordToolsMainMenu // - this.adSpecialKeyWordsToolsMainMenu.Name = "adSpecialKeyWordsToolsMainMenu"; - this.adSpecialKeyWordsToolsMainMenu.Size = new System.Drawing.Size(286, 34); - this.adSpecialKeyWordsToolsMainMenu.Text = "&Register Ad Special"; - this.adSpecialKeyWordsToolsMainMenu.Click += new System.EventHandler(this.adSpecialKeyWordsToolsMainMenu_Click); + this.clearRecordToolsMainMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.clearCurrentRecordSelectedDateToolsMainMenu, + this.selectRangeToolStripMenuItem}); + this.clearRecordToolsMainMenu.Name = "clearRecordToolsMainMenu"; + this.clearRecordToolsMainMenu.Size = new System.Drawing.Size(282, 34); + this.clearRecordToolsMainMenu.Text = "&Clear Record(s)"; + // + // clearCurrentRecordSelectedDateToolsMainMenu + // + this.clearCurrentRecordSelectedDateToolsMainMenu.Name = "clearCurrentRecordSelectedDateToolsMainMenu"; + this.clearCurrentRecordSelectedDateToolsMainMenu.Size = new System.Drawing.Size(244, 34); + this.clearCurrentRecordSelectedDateToolsMainMenu.Text = "C&urrent Record"; + this.clearCurrentRecordSelectedDateToolsMainMenu.Click += new System.EventHandler(this.ClearCurrentRecord); + // + // selectRangeToolStripMenuItem + // + this.selectRangeToolStripMenuItem.Name = "selectRangeToolStripMenuItem"; + this.selectRangeToolStripMenuItem.Size = new System.Drawing.Size(244, 34); + this.selectRangeToolStripMenuItem.Text = "Select Ran&ge..."; + this.selectRangeToolStripMenuItem.Click += new System.EventHandler(this.DisplayRecordDeletionRangeForm); // // manageItemsToolsMainMenu // this.manageItemsToolsMainMenu.Name = "manageItemsToolsMainMenu"; - this.manageItemsToolsMainMenu.Size = new System.Drawing.Size(286, 34); - this.manageItemsToolsMainMenu.Text = "&Manage Ad Items"; - this.manageItemsToolsMainMenu.Visible = false; - this.manageItemsToolsMainMenu.Click += new System.EventHandler(this.manageItemsToolsMainMenu_Click); + this.manageItemsToolsMainMenu.Size = new System.Drawing.Size(282, 34); + this.manageItemsToolsMainMenu.Text = "Manage Ad &Items"; + this.manageItemsToolsMainMenu.Click += new System.EventHandler(this.DisplayAdItemManager); // - // clearSelectedDateToolsMainMenu + // manageSuppliersToolsMainMenu // - this.clearSelectedDateToolsMainMenu.Name = "clearSelectedDateToolsMainMenu"; - this.clearSelectedDateToolsMainMenu.Size = new System.Drawing.Size(286, 34); - this.clearSelectedDateToolsMainMenu.Text = "&Clear Selected Date"; - this.clearSelectedDateToolsMainMenu.Click += new System.EventHandler(this.clearSelectedDateToolsMainMenu_Click); + this.manageSuppliersToolsMainMenu.Name = "manageSuppliersToolsMainMenu"; + this.manageSuppliersToolsMainMenu.Size = new System.Drawing.Size(286, 34); + this.manageSuppliersToolsMainMenu.Text = "Manage &Suppliers"; + this.manageSuppliersToolsMainMenu.Click += new System.EventHandler(this.manageSuppliersToolsMainMenu_Click); + // + // adSpecialKeyWordsToolsMainMenu + // + this.adSpecialKeyWordsToolsMainMenu.Name = "adSpecialKeyWordsToolsMainMenu"; + this.adSpecialKeyWordsToolsMainMenu.Size = new System.Drawing.Size(282, 34); + this.adSpecialKeyWordsToolsMainMenu.Text = "R&egister Ad Special"; + this.adSpecialKeyWordsToolsMainMenu.Click += new System.EventHandler(this.DisplayRegisterAdSpecial); // // helpMainMenu // @@ -240,15 +273,15 @@ // this.showHideConsoleHelpMainMenu.Name = "showHideConsoleHelpMainMenu"; this.showHideConsoleHelpMainMenu.Size = new System.Drawing.Size(304, 34); - this.showHideConsoleHelpMainMenu.Text = "&Show/Hide Console"; - this.showHideConsoleHelpMainMenu.Click += new System.EventHandler(this.showHideConsoleHelpMainMenu_Click); + this.showHideConsoleHelpMainMenu.Text = "Sh&ow/Hide Console"; + this.showHideConsoleHelpMainMenu.Click += new System.EventHandler(this.ShowHideLogConsole); // // dbVersionHelpMainMenu // this.dbVersionHelpMainMenu.Name = "dbVersionHelpMainMenu"; this.dbVersionHelpMainMenu.Size = new System.Drawing.Size(304, 34); this.dbVersionHelpMainMenu.Text = "Get &Database Version"; - this.dbVersionHelpMainMenu.Click += new System.EventHandler(this.dbVersionHelpMainMenu_Click); + this.dbVersionHelpMainMenu.Click += new System.EventHandler(this.DisplayDatabaseVersionNumber); // // debugMainMenu // @@ -266,21 +299,21 @@ this.rawViewDebugMainMenu.Name = "rawViewDebugMainMenu"; this.rawViewDebugMainMenu.Size = new System.Drawing.Size(270, 34); this.rawViewDebugMainMenu.Text = "Raw View"; - this.rawViewDebugMainMenu.Click += new System.EventHandler(this.rawViewDebugMainMenu_Click); + this.rawViewDebugMainMenu.Click += new System.EventHandler(this.DisplayRawDatabaseView); // // migrateDatabaseDebugMainMenu // this.migrateDatabaseDebugMainMenu.Name = "migrateDatabaseDebugMainMenu"; this.migrateDatabaseDebugMainMenu.Size = new System.Drawing.Size(270, 34); this.migrateDatabaseDebugMainMenu.Text = "Migrate Database"; - this.migrateDatabaseDebugMainMenu.Click += new System.EventHandler(this.debugToolStripMenuItem1_Click); + this.migrateDatabaseDebugMainMenu.Click += new System.EventHandler(this.DisplayDebugTool); // // addRecordToolStripMenuItem // this.addRecordToolStripMenuItem.Name = "addRecordToolStripMenuItem"; this.addRecordToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.addRecordToolStripMenuItem.Text = "Add Record"; - this.addRecordToolStripMenuItem.Click += new System.EventHandler(this.addRecordToolStripMenuItem_Click_1); + this.addRecordToolStripMenuItem.Click += new System.EventHandler(this.DisplayLegacyAddRecord); // // mainTableLayoutPanel // @@ -946,13 +979,6 @@ this.grossProfitDollarGrossProfitLabel.TabIndex = 2; this.grossProfitDollarGrossProfitLabel.Text = "Dollar Gross Profit: "; // - // reportsMainMenu - // - this.reportsMainMenu.Name = "reportsMainMenu"; - this.reportsMainMenu.Size = new System.Drawing.Size(95, 34); - this.reportsMainMenu.Text = "R&eports"; - this.reportsMainMenu.Visible = false; - // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); @@ -1073,10 +1099,13 @@ private System.Windows.Forms.DataGridView invoicesDataGridView; private System.Windows.Forms.ToolStripMenuItem debugMainMenu; private System.Windows.Forms.ToolStripMenuItem migrateDatabaseDebugMainMenu; - private System.Windows.Forms.ToolStripMenuItem clearSelectedDateToolsMainMenu; + private System.Windows.Forms.ToolStripMenuItem clearRecordToolsMainMenu; private System.Windows.Forms.ToolStripMenuItem addRecordToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem rawViewDebugMainMenu; private System.Windows.Forms.ToolStripMenuItem reportsMainMenu; + private System.Windows.Forms.ToolStripMenuItem manageSuppliersToolsMainMenu; + private System.Windows.Forms.ToolStripMenuItem clearCurrentRecordSelectedDateToolsMainMenu; + private System.Windows.Forms.ToolStripMenuItem selectRangeToolStripMenuItem; } } diff --git a/AdvertsingProfitControl/FrmMain.cs b/AdvertsingProfitControl/FrmMain.cs index 346e1d6..b65b953 100644 --- a/AdvertsingProfitControl/FrmMain.cs +++ b/AdvertsingProfitControl/FrmMain.cs @@ -4,7 +4,6 @@ using System.Drawing; using System.Drawing.Printing; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Transactions; using System.Windows.Forms; @@ -41,12 +40,10 @@ namespace AdvertsingProfitControl LoadDate(recentDate.EndingDate); } monthCalendar.DateChanged += ValidateDateChanged; - //projectionsDataGridView.KeyDown += FrmMain_KeyDown; - //var margin = new Margins(50, 50, 0, 0); - //_printDoc.DefaultPageSettings.Margins = margin; - } + #region Calculate Analysis Methods + private void CalculateProfitAnalysis(decimal shrink = 0.30m) { if (actualSalesDataGridView.Rows.Count == 0) @@ -128,7 +125,11 @@ namespace AdvertsingProfitControl perfectGrossProfitLabel.Text = @"Percent Gross Profit: " + grossProfitPercent.ToString("P"); } - private void addRecordToolStripMenuItem_Click(object sender, EventArgs e) + #endregion + + #region Main Menu Click Handlers + + private void DisplayNewRecordForm(object sender, EventArgs e) { var db = new AdvertisingProfitControlModel(); var form = new NewModifyRecord(); @@ -142,7 +143,119 @@ namespace AdvertsingProfitControl LoadDate(date.EndingDate); } - private void showHideConsoleHelpMainMenu_Click(object sender, EventArgs e) + private void DisplayModifyRecordForm(object sender, EventArgs e) + { + var form = new NewModifyRecord(_currentActiveDate); + form.ShowDialog(); + RefreshDateListing(); + //On return reload the date that was just modified by the modify record form. + LoadDate(_currentActiveDate); + } + + private void ClearCurrentRecord(object sender, EventArgs e) + { + var result = MessageBox.Show(@"Are you sure you want to delete all records for the date " + _currentActiveDate.ToShortDateString() + @"?", @"Clear Date", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (result == DialogResult.No) + { + return; + } + + var db = new AdvertisingProfitControlModel(); + var dateRecord = db.WeekEndingDates.Single(x => x.EndingDate == _currentActiveDate); + var projections = db.Projections.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); + var inventories = db.Inventories.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); + var actualSales = db.ActualSales.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); + var invoices = db.Invoices.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); + var weeklySale = db.WeeklySales.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); + var taxable = db.Taxables.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); + var costAnalysis = db.CostAnalysis.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); + var comment = db.Notes.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); + + using (var scope = new TransactionScope()) + { + try + { + //Clear projections + foreach (var projection in projections) + { + db.Projections.Remove(projection); + } + //Clear inventory + foreach (var inventory in inventories) + { + db.Inventories.Remove(inventory); + } + //Clear actual sales + foreach (var sale in actualSales) + { + db.ActualSales.Remove(sale); + } + //Clear invoices + foreach (var invoice in invoices) + { + db.Invoices.Remove(invoice); + } + if (weeklySale != null) + { + db.WeeklySales.Remove(weeklySale); + } + if (taxable != null) + { + db.Taxables.Remove(taxable); + } + if (costAnalysis != null) + { + db.CostAnalysis.Remove(costAnalysis); + } + if (comment != null) + { + db.Notes.Remove(comment); + } + db.WeekEndingDates.Remove(dateRecord); + db.SaveChanges(); + scope.Complete(); + ClearForm(); + } + catch (DbUpdateException ex) + { + MessageBox.Show(@"Failed to clear selected date.", @"Error"); + _console.WriteToLog(FrmLogConsole.Level.Error, ex.Message); + } + } + + RefreshDateListing(); + var mostRecentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault(); + if (mostRecentDate != null) + { + LoadDate(mostRecentDate.EndingDate); + } + } + + private void DisplayRecordDeletionRangeForm(object sender, EventArgs e) + { + //TODO: Create a form to allow the user to delete a range of dates. + } + + private void DisplayAdItemManager(object sender, EventArgs e) + { + var adItemManager = new FrmManageAdItems(); + adItemManager.ShowDialog(); + } + + + private void manageSuppliersToolsMainMenu_Click(object sender, EventArgs e) + { + var form = new FrmManageSuppliers(); + form.ShowDialog(); + } + + private void DisplayRegisterAdSpecial(object sender, EventArgs e) + { + var form = new FrmRegisterAdSpecial(); + form.ShowDialog(); + } + + private void ShowHideLogConsole(object sender, EventArgs e) { if (_console.IsVisable) { @@ -154,23 +267,7 @@ namespace AdvertsingProfitControl } } - private void modifyRecordMainMenu_Click(object sender, EventArgs e) - { - var form = new NewModifyRecord(_currentActiveDate); - form.ShowDialog(); - RefreshDateListing(); - //On return reload the date that was just modified by the modify record form. - LoadDate(_currentActiveDate); - } - - private void manageItemsToolsMainMenu_Click(object sender, EventArgs e) - { - //TODO: Bring back Manage Ad Items form and managing AdSpecials. - //var adItemManager = new FrmManageAdItems(); - //adItemManager.ShowDialog(); - } - - private void dbVersionHelpMainMenu_Click(object sender, EventArgs e) + private void DisplayDatabaseVersionNumber(object sender, EventArgs e) { var db = new AdvertisingProfitControlModel(); var version = db.Versions.FirstOrDefault(x => x.Id == 1); @@ -183,6 +280,9 @@ namespace AdvertsingProfitControl MessageBox.Show(@"The current database's version is " + version.VersionNumber + @".", @"Database Version Number", MessageBoxButtons.OK, MessageBoxIcon.Information); } + #endregion + + #region Print Handler Methods private void PrintPage(object sender, PrintPageEventArgs e) { @@ -264,9 +364,12 @@ namespace AdvertsingProfitControl printDialog.Document = new PrintDocument(); } + #endregion + + #region DataGridView Constructor Methods + /// - /// Fills the APC DataGridViews with the appropriate columns and starting row for the user to start - /// entering data. + /// Builds the appropriate columns in the APC DataGridViews so they can be filled. /// private void ConstructApcDataGridViews() { @@ -346,9 +449,14 @@ namespace AdvertsingProfitControl } } + #endregion + + #region Date Loading Methods + private void LoadDate(DateTime date) { var db = new AdvertisingProfitControlModel(); + //Check to see if that date record can be found before clearing the form. var dateRecord = db.WeekEndingDates.SingleOrDefault(x => x.EndingDate == date); if (dateRecord == null) { @@ -356,6 +464,7 @@ namespace AdvertsingProfitControl return; } ClearForm(); + //Load all the data attached to the date record. LoadProjectionsTable(dateRecord); LoadInventoryTable(dateRecord); LoadActualSalesTable(dateRecord); @@ -405,14 +514,12 @@ namespace AdvertsingProfitControl projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.MemberRow; } - if (p.FkAdSpecialId != null && adSpecialIndex == -1) - { - //TODO: Fix null reference when no object is found. - adSpecialIndex = index; - projectionsDataGridView.Rows.Insert(index, 1); - projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; - projectionsDataGridView.Rows[index].Cells[3].Value = db.AdSpecials.Single(x => x.Id == p.FkAdSpecialId).Name; - } + if (p.FkAdSpecialId == null || adSpecialIndex != -1) continue; + //TODO: Fix null reference when no object is found. + adSpecialIndex = index; + projectionsDataGridView.Rows.Insert(index, 1); + projectionsDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + projectionsDataGridView.Rows[index].Cells[3].Value = db.AdSpecials.Single(x => x.Id == p.FkAdSpecialId).Name; } //Now add the totals row. if (projectionsDataGridView.RowCount == 0) return; @@ -461,13 +568,11 @@ namespace AdvertsingProfitControl inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.MemberRow; } - if (i.FkAdSpecialId != null && adSpecialIndex == -1) - { - adSpecialIndex = index; - inventoryDataGridView.Rows.Insert(index, 1); - inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; - inventoryDataGridView.Rows[index].Cells[2].Value = db.AdSpecials.Single(x => x.Id == i.FkAdSpecialId).Name; - } + if (i.FkAdSpecialId == null || adSpecialIndex != -1) continue; + adSpecialIndex = index; + inventoryDataGridView.Rows.Insert(index, 1); + inventoryDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + inventoryDataGridView.Rows[index].Cells[2].Value = db.AdSpecials.Single(x => x.Id == i.FkAdSpecialId).Name; } } @@ -501,13 +606,11 @@ namespace AdvertsingProfitControl actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.MemberRow; } - if (a.FkAdSpecialId != null && adSpecialIndex == -1) - { - adSpecialIndex = index; - actualSalesDataGridView.Rows.Insert(index, 1); - actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; - actualSalesDataGridView.Rows[index].Cells[3].Value = db.AdSpecials.Single(x => x.Id == a.FkAdSpecialId).Name; - } + if (a.FkAdSpecialId == null || adSpecialIndex != -1) continue; + adSpecialIndex = index; + actualSalesDataGridView.Rows.Insert(index, 1); + actualSalesDataGridView.Rows[index].DefaultCellStyle.BackColor = ApplicationColors.AdSpecial; + actualSalesDataGridView.Rows[index].Cells[3].Value = db.AdSpecials.Single(x => x.Id == a.FkAdSpecialId).Name; } //Now add the totals row. if (actualSalesDataGridView.RowCount == 0) return; @@ -665,6 +768,8 @@ namespace AdvertsingProfitControl } } + #endregion + private string CheckForHoliday(DayOfWeek day) { var holidayText = string.Empty; @@ -709,6 +814,13 @@ namespace AdvertsingProfitControl return holidayText; } + #region Form Reset And Data Loading Methods + + /// + /// Checks to see if the newly selected date is one that should be loaded. + /// + /// + /// private void ValidateDateChanged(object sender, DateRangeEventArgs e) { if (e.Start == _currentActiveDate || !monthCalendar.BoldedDates.Contains(e.Start)) return; @@ -762,13 +874,6 @@ namespace AdvertsingProfitControl grossProfitEstimatedWeeklyDeptmartmentExpenseLabel.Text = @"Estimated Weekly" + Environment.NewLine + @"Department Expense: "; } - private void debugToolStripMenuItem1_Click(object sender, EventArgs e) - { - var form = new DebugDatabaseConverter(); - form.ShowDialog(); - RefreshDateListing(); - } - private void RefreshDateListing() { var db = new AdvertisingProfitControlModel(); @@ -776,129 +881,52 @@ namespace AdvertsingProfitControl if (monthCalendar.BoldedDates.Length > 0) { modifyRecordMainMenu.Enabled = true; - modifyRecordMainMenu.ToolTipText = @""; + modifyRecordMainMenu.ToolTipText = string.Empty; + clearCurrentRecordSelectedDateToolsMainMenu.Enabled = true; + clearCurrentRecordSelectedDateToolsMainMenu.ToolTipText = string.Empty; } else { dateTimeGroupBox.Text = @"No records found in the database."; modifyRecordMainMenu.Enabled = false; modifyRecordMainMenu.ToolTipText = @"There are no records to modify."; + clearCurrentRecordSelectedDateToolsMainMenu.Enabled = false; + clearCurrentRecordSelectedDateToolsMainMenu.ToolTipText = @"There is no date to clear."; } } - private void clearSelectedDateToolsMainMenu_Click(object sender, EventArgs e) + #endregion + + #region Debug Tool Menu Items + + private void DisplayDebugTool(object sender, EventArgs e) { - var result = MessageBox.Show(@"Are you sure you want to delete all records for the date " + _currentActiveDate.ToShortDateString() + @"?", @"Clear Date", MessageBoxButtons.YesNo, MessageBoxIcon.Question); - if (result == DialogResult.No) - { - return; - } - - var db = new AdvertisingProfitControlModel(); - var dateRecord = db.WeekEndingDates.Single(x => x.EndingDate == _currentActiveDate); - var projections = db.Projections.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); - var inventories = db.Inventories.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); - var actualSales = db.ActualSales.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); - var invoices = db.Invoices.Where(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); - var weeklySale = db.WeeklySales.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); - var taxable = db.Taxables.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); - var costAnalysis = db.CostAnalysis.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); - var comment = db.Notes.SingleOrDefault(x => x.WeekEndingDate.EndingDate == dateRecord.EndingDate); - - using (var scope = new TransactionScope()) - { - try - { - //Clear projections - foreach (var projection in projections) - { - db.Projections.Remove(projection); - } - //Clear inventory - foreach (var inventory in inventories) - { - db.Inventories.Remove(inventory); - } - //Clear actual sales - foreach (var sale in actualSales) - { - db.ActualSales.Remove(sale); - } - //Clear invoices - foreach (var invoice in invoices) - { - db.Invoices.Remove(invoice); - } - if (weeklySale != null) - { - db.WeeklySales.Remove(weeklySale); - } - if (taxable != null) - { - db.Taxables.Remove(taxable); - } - if (costAnalysis != null) - { - db.CostAnalysis.Remove(costAnalysis); - } - if (comment != null) - { - db.Notes.Remove(comment); - } - db.WeekEndingDates.Remove(dateRecord); - db.SaveChanges(); - scope.Complete(); - ClearForm(); - } - catch (DbUpdateException ex) - { - MessageBox.Show(@"Failed to clear selected date.", @"Error"); - _console.WriteToLog(FrmLogConsole.Level.Error, ex.Message); - } - } - + var form = new DebugDatabaseConverter(); + form.ShowDialog(); RefreshDateListing(); - var mostRecentDate = db.WeekEndingDates.OrderByDescending(x => x.EndingDate).FirstOrDefault(); - if (mostRecentDate != null) - { - LoadDate(mostRecentDate.EndingDate); - } } - private void addRecordToolStripMenuItem_Click_1(object sender, EventArgs e) + /// + /// Displays the legacy Add Record form. Completely for looks. + /// + /// + /// + private void DisplayLegacyAddRecord(object sender, EventArgs e) { var form = new FrmAddRecord(); form.ShowDialog(); } - private void rawViewDebugMainMenu_Click(object sender, EventArgs e) + /// + /// + /// + /// + /// + private void DisplayRawDatabaseView(object sender, EventArgs e) { } - private void adSpecialKeyWordsToolsMainMenu_Click(object sender, EventArgs e) - { - var form = new FrmRegisterAdSpecial(); - form.ShowDialog(); - } - } -} - //http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children - internal class DrawingControl - { - [DllImport("user32.dll")] - public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam); - - private const int WmSetredraw = 11; - - public static void SuspendDrawing(Control parent) - { - SendMessage(parent.Handle, WmSetredraw, false, 0); - } - - public static void ResumeDrawing(Control parent) - { - SendMessage(parent.Handle, WmSetredraw, true, 0); - parent.Refresh(); - } + #endregion } +} \ No newline at end of file diff --git a/AdvertsingProfitControl/FrmManageAdItems.Designer.cs b/AdvertsingProfitControl/FrmManageAdItems.Designer.cs new file mode 100644 index 0000000..8277a7f --- /dev/null +++ b/AdvertsingProfitControl/FrmManageAdItems.Designer.cs @@ -0,0 +1,173 @@ +namespace AdvertsingProfitControl +{ + partial class FrmManageAdItems + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.adItemsListView = new System.Windows.Forms.ListView(); + this.addUpdateItemButton = new System.Windows.Forms.Button(); + this.removeAdItemButton = new System.Windows.Forms.Button(); + this.newItemTextBox = new System.Windows.Forms.TextBox(); + this.descriptionTextBox = new System.Windows.Forms.TextBox(); + this.newItemLabel = new System.Windows.Forms.Label(); + this.descriptionLabel = new System.Windows.Forms.Label(); + this.informationLabel = new System.Windows.Forms.Label(); + this.filterLabel = new System.Windows.Forms.Label(); + this.filterComboBox = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // adItemsListView + // + this.adItemsListView.Location = new System.Drawing.Point(258, 12); + this.adItemsListView.Name = "adItemsListView"; + this.adItemsListView.Size = new System.Drawing.Size(452, 431); + this.adItemsListView.TabIndex = 3; + this.adItemsListView.TabStop = false; + this.adItemsListView.UseCompatibleStateImageBehavior = false; + this.adItemsListView.View = System.Windows.Forms.View.Details; + // + // addUpdateItemButton + // + this.addUpdateItemButton.Enabled = false; + this.addUpdateItemButton.Location = new System.Drawing.Point(506, 449); + this.addUpdateItemButton.Name = "addUpdateItemButton"; + this.addUpdateItemButton.Size = new System.Drawing.Size(200, 70); + this.addUpdateItemButton.TabIndex = 3; + this.addUpdateItemButton.Text = "Add New Item"; + this.addUpdateItemButton.UseVisualStyleBackColor = true; + this.addUpdateItemButton.Click += new System.EventHandler(this.AddUpdateItem); + // + // removeAdItemButton + // + this.removeAdItemButton.Enabled = false; + this.removeAdItemButton.Location = new System.Drawing.Point(13, 449); + this.removeAdItemButton.Name = "removeAdItemButton"; + this.removeAdItemButton.Size = new System.Drawing.Size(200, 70); + this.removeAdItemButton.TabIndex = 4; + this.removeAdItemButton.Text = "Remove Selected Item"; + this.removeAdItemButton.UseVisualStyleBackColor = true; + this.removeAdItemButton.Click += new System.EventHandler(this.RemoveSelectedAdItem); + // + // newItemTextBox + // + this.newItemTextBox.Location = new System.Drawing.Point(13, 55); + this.newItemTextBox.MaxLength = 32; + this.newItemTextBox.Name = "newItemTextBox"; + this.newItemTextBox.Size = new System.Drawing.Size(200, 29); + this.newItemTextBox.TabIndex = 1; + // + // descriptionTextBox + // + this.descriptionTextBox.Location = new System.Drawing.Point(13, 115); + this.descriptionTextBox.MaxLength = 128; + this.descriptionTextBox.Name = "descriptionTextBox"; + this.descriptionTextBox.Size = new System.Drawing.Size(200, 29); + this.descriptionTextBox.TabIndex = 2; + // + // newItemLabel + // + this.newItemLabel.AutoSize = true; + this.newItemLabel.Location = new System.Drawing.Point(12, 27); + this.newItemLabel.Name = "newItemLabel"; + this.newItemLabel.Size = new System.Drawing.Size(205, 25); + this.newItemLabel.TabIndex = 5; + this.newItemLabel.Text = "Register New Ad Item:"; + // + // descriptionLabel + // + this.descriptionLabel.AutoSize = true; + this.descriptionLabel.Location = new System.Drawing.Point(12, 87); + this.descriptionLabel.Name = "descriptionLabel"; + this.descriptionLabel.Size = new System.Drawing.Size(207, 25); + this.descriptionLabel.TabIndex = 6; + this.descriptionLabel.Text = "Description (Optional):"; + // + // informationLabel + // + this.informationLabel.AutoSize = true; + this.informationLabel.Location = new System.Drawing.Point(8, 219); + this.informationLabel.Name = "informationLabel"; + this.informationLabel.Size = new System.Drawing.Size(0, 25); + this.informationLabel.TabIndex = 7; + // + // filterLabel + // + this.filterLabel.AutoSize = true; + this.filterLabel.Location = new System.Drawing.Point(12, 147); + this.filterLabel.Name = "filterLabel"; + this.filterLabel.Size = new System.Drawing.Size(115, 25); + this.filterLabel.TabIndex = 8; + this.filterLabel.Text = "Apply Filter:"; + // + // filterComboBox + // + this.filterComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.filterComboBox.FormattingEnabled = true; + this.filterComboBox.Location = new System.Drawing.Point(13, 175); + this.filterComboBox.Name = "filterComboBox"; + this.filterComboBox.Size = new System.Drawing.Size(200, 32); + this.filterComboBox.TabIndex = 9; + this.filterComboBox.TabStop = false; + // + // FrmManageAdItems + // + this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(722, 532); + this.Controls.Add(this.filterComboBox); + this.Controls.Add(this.filterLabel); + this.Controls.Add(this.informationLabel); + this.Controls.Add(this.descriptionLabel); + this.Controls.Add(this.newItemLabel); + this.Controls.Add(this.descriptionTextBox); + this.Controls.Add(this.newItemTextBox); + this.Controls.Add(this.removeAdItemButton); + this.Controls.Add(this.addUpdateItemButton); + this.Controls.Add(this.adItemsListView); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; + this.Name = "FrmManageAdItems"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Manage Ad Items"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListView adItemsListView; + private System.Windows.Forms.Button addUpdateItemButton; + private System.Windows.Forms.Button removeAdItemButton; + private System.Windows.Forms.TextBox newItemTextBox; + private System.Windows.Forms.TextBox descriptionTextBox; + private System.Windows.Forms.Label newItemLabel; + private System.Windows.Forms.Label descriptionLabel; + private System.Windows.Forms.Label informationLabel; + private System.Windows.Forms.Label filterLabel; + private System.Windows.Forms.ComboBox filterComboBox; + } +} \ No newline at end of file diff --git a/AdvertsingProfitControl/FrmManageAdItems.cs b/AdvertsingProfitControl/FrmManageAdItems.cs new file mode 100644 index 0000000..10cc835 --- /dev/null +++ b/AdvertsingProfitControl/FrmManageAdItems.cs @@ -0,0 +1,256 @@ +using System; +using System.Data.Entity.Infrastructure; +using System.Linq; +using System.Transactions; +using System.Windows.Forms; + +namespace AdvertsingProfitControl +{ + public partial class FrmManageAdItems : Form + { + private bool _isUpdating; + + public FrmManageAdItems() + { + InitializeComponent(); + newItemTextBox.TextChanged += NewItemTextChanged; + adItemsListView.ItemSelectionChanged += UpdateAdItemTextFields; + var columnHeader = new ColumnHeader + { + Name = "AdItemHeaderColumn", + Width = Width / 2 + }; + adItemsListView.Columns.Add(columnHeader); + RefreshAdItemListing(); + } + + private void FilterValueChanged(object sender, EventArgs e) + { + if(filterComboBox.Enabled == false) return; + adItemsListView.Columns[0].Text = @"Current Ad Items (" + (filterComboBox.SelectedItem.ToString() == "All" ? "No Filter" : @"Filter " + filterComboBox.SelectedItem) + @"):"; + adItemsListView.Items.Clear(); + var db = new AdvertisingProfitControlModel(); + var adItems = db.AdItems.Select(x => x); + foreach (var adItem in adItems) + { + var item = new ListViewItem + { + Text = adItem.Name, + Tag = adItem + }; + + if (string.Equals(filterComboBox.SelectedItem.ToString(), "All", StringComparison.Ordinal)) + { + adItemsListView.Items.Add(item); + continue; + } + + if (string.Equals(filterComboBox.SelectedItem.ToString(), "0-9", StringComparison.Ordinal) && char.IsNumber(adItem.Name[0])) + { + adItemsListView.Items.Add(item); + } + else if (!string.Equals(filterComboBox.SelectedItem.ToString(), "0-9", StringComparison.Ordinal) && char.IsLetter(adItem.Name[0])) + { + if(filterComboBox.SelectedItem.ToString()[0] == adItem.Name[0]) + { adItemsListView.Items.Add(item);} + } + } + newItemTextBox.Text = string.Empty; + descriptionTextBox.Text = string.Empty; + removeAdItemButton.Enabled = false; + + } + + private void UpdateAdItemTextFields(object sender, ListViewItemSelectionChangedEventArgs e) + { + newItemTextBox.Text = ((AdItem)e.Item.Tag).Name; + descriptionTextBox.Text = ((AdItem)e.Item.Tag).Description; + _isUpdating = true; + removeAdItemButton.Enabled = true; + addUpdateItemButton.Text = @"Update Ad Item"; + newItemLabel.Text = @"Update Ad Item:"; + } + + private void NewItemTextChanged(object sender, EventArgs e) + { + if (_isUpdating && newItemTextBox.Text.Length == 0) + { + _isUpdating = false; + descriptionTextBox.Text = string.Empty; + addUpdateItemButton.Text = @"Register Ad Item"; + newItemLabel.Text = @"Register New Ad Item:"; + } + addUpdateItemButton.Enabled = newItemTextBox.Text.Length > 0; + } + + private void RefreshAdItemListing(string filter = "") + { + filterComboBox.SelectedIndexChanged -= FilterValueChanged; + //Check to see if the current view is empty. + if (adItemsListView.Items.Count == 0) filter = string.Empty; + adItemsListView.Items.Clear(); + filterComboBox.Items.Clear(); + filterComboBox.Items.Add("All"); + var db = new AdvertisingProfitControlModel(); + var adItems = db.AdItems.Select(x => x).OrderBy(x => x.Name); + var adItemCount = 0; + var numberFound = false; + foreach (var adItem in adItems) + { + var item = new ListViewItem + { + Text = adItem.Name, + Tag = adItem + }; + if (filter == string.Empty || filter == "All") + { + adItemsListView.Items.Add(item); + } + else if (adItem.Name[0].ToString() == filter) + { + adItemsListView.Items.Add(item); + } + else if (filter == "0-9" && char.IsNumber(adItem.Name[0])) + { + adItemsListView.Items.Add(item); + } + //Populate the filter. + if (!filterComboBox.Items.Contains(adItem.Name[0].ToString())) + { + if (char.IsDigit(adItem.Name[0]) && !numberFound) + { + filterComboBox.Items.Add("0-9"); + numberFound = true; + } + else + { + filterComboBox.Items.Add(adItem.Name[0].ToString()); + } + } + adItemCount++; + } + + if (adItemCount > 0) + { + filterComboBox.Enabled = true; + filterComboBox.SelectedIndex = filterComboBox.Items.Contains(filter) ? filterComboBox.Items.IndexOf(filter) : 0; + adItemsListView.Columns[0].Text = @"Current Ad Items (" + (filterComboBox.SelectedItem.ToString() == "All" ? "No Filter" : @"Filter " + filterComboBox.SelectedItem) + @"):"; + } + else + { + adItemsListView.Columns[0].Text = @"No Ad Items to Display."; + filterComboBox.SelectedIndex = 0; + } + removeAdItemButton.Enabled = false; + newItemTextBox.Text = string.Empty; + descriptionTextBox.Text = string.Empty; + filterComboBox.SelectedIndexChanged += FilterValueChanged; + } + + private void RemoveSelectedAdItem(object sender, EventArgs e) + { + var item = adItemsListView.SelectedItems[0]; + var oldAdItem = (AdItem)item.Tag; + var db = new AdvertisingProfitControlModel(); + var adItemEntry = db.AdItems.Single(x => x.Id == oldAdItem.Id); + //Check to see if the ad special is used by other tables. + if (adItemEntry.ActualSales.Count > 0) + { + //If so, display a warning to the user about the potential data loss. + var result = + MessageBox.Show( + adItemEntry.ActualSales.Count + + @" reference(s) to this item found. Do you want to delete these records? This can not be undone.", + @"References to " + oldAdItem.Name + @" Found", MessageBoxButtons.YesNoCancel, + MessageBoxIcon.Question); + if (result != DialogResult.Yes) return; + //Perform the necessary operations to remove all references to the key word. + using (var scope = new TransactionScope()) + { + try + { + db.Projections.RemoveRange(db.Projections.Where(x => x.FkAdItemId == oldAdItem.Id)); + db.Inventories.RemoveRange(db.Inventories.Where(x => x.FkAdItemId == oldAdItem.Id)); + db.ActualSales.RemoveRange(db.ActualSales.Where(x => x.FkAdItemId == oldAdItem.Id)); + db.AdItems.Remove(adItemEntry); + db.SaveChanges(); + scope.Complete(); + informationLabel.Text = @"Removed '" + Environment.NewLine + oldAdItem.Name + + Environment.NewLine + @"' successfully."; + adItemsListView.Items.RemoveAt(adItemsListView.SelectedItems[0].Index); + } + catch (DbUpdateException ex) + { + informationLabel.Text = @"Failed to remove " + Environment.NewLine + oldAdItem.Name + @"." + + Environment.NewLine + ex.Message; + } + } + } + else + { + try + { + db.AdItems.Remove(adItemEntry); + db.SaveChanges(); + informationLabel.Text = @"Removed '" + Environment.NewLine + oldAdItem.Name + + Environment.NewLine + @"' successfully."; + adItemsListView.Items.RemoveAt(adItemsListView.SelectedItems[0].Index); + } + catch (DbUpdateException ex) + { + informationLabel.Text = @"Failed to remove " + Environment.NewLine + oldAdItem.Name + @"." + Environment.NewLine + ex.Message; + } + } + RefreshAdItemListing(filterComboBox.SelectedItem.ToString()); + } + + private void AddUpdateItem(object sender, EventArgs e) + { + var db = new AdvertisingProfitControlModel(); + if (!_isUpdating) + { + if (!db.AdItems.Any(x => x.Name == newItemTextBox.Text)) + { + var adItem = new AdItem + { + Name = newItemTextBox.Text, + Description = descriptionTextBox.Text + }; + db.AdItems.Add(adItem); + try + { + db.SaveChanges(); + informationLabel.Text = @"Registered '" + Environment.NewLine + adItem.Name + Environment.NewLine + @"' successfully."; + } + catch (DbUpdateException ex) + { + informationLabel.Text = @"Failed to register '" + Environment.NewLine + adItem.Name + @"'." + Environment.NewLine + + ex.Message; + } + } + else + { + MessageBox.Show(@"Ad item '" + newItemTextBox.Text + @"' already exists.", + @"Duplicate Entry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + newItemTextBox.Text = string.Empty; + } + } + else + { + var item = adItemsListView.SelectedItems[0]; + var index = ((AdItem)item.Tag).Id; + var adItem = db.AdItems.SingleOrDefault(x => x.Id == index); + if (adItem == null) + { + informationLabel.Text = @"Failed to retrieve " + Environment.NewLine + @"ad item ID."; + return; + } + adItem.Name = newItemTextBox.Text; + adItem.Description = descriptionTextBox.Text; + db.SaveChanges(); + informationLabel.Text = @"Updated '" + Environment.NewLine + newItemTextBox.Text + Environment.NewLine + @"' successfully."; + } + RefreshAdItemListing(filterComboBox.SelectedItem.ToString()); + } + } +} diff --git a/AdvertsingProfitControl/FrmManageAdItems.resx b/AdvertsingProfitControl/FrmManageAdItems.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AdvertsingProfitControl/FrmManageAdItems.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AdvertsingProfitControl/FrmManageSuppliers.Designer.cs b/AdvertsingProfitControl/FrmManageSuppliers.Designer.cs new file mode 100644 index 0000000..20168f4 --- /dev/null +++ b/AdvertsingProfitControl/FrmManageSuppliers.Designer.cs @@ -0,0 +1,151 @@ +namespace AdvertsingProfitControl +{ + partial class FrmManageSuppliers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.suppliersListBox = new System.Windows.Forms.ListView(); + this.descriptionTextBox = new System.Windows.Forms.TextBox(); + this.descriptionLabel = new System.Windows.Forms.Label(); + this.informationLabel = new System.Windows.Forms.Label(); + this.newSupplierTextBox = new System.Windows.Forms.TextBox(); + this.newSupplierLabel = new System.Windows.Forms.Label(); + this.deleteSupplierButton = new System.Windows.Forms.Button(); + this.registerSupplierButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // suppliersListBox + // + this.suppliersListBox.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; + this.suppliersListBox.Location = new System.Drawing.Point(257, 12); + this.suppliersListBox.Name = "suppliersListBox"; + this.suppliersListBox.Size = new System.Drawing.Size(423, 412); + this.suppliersListBox.TabIndex = 16; + this.suppliersListBox.TabStop = false; + this.suppliersListBox.UseCompatibleStateImageBehavior = false; + this.suppliersListBox.View = System.Windows.Forms.View.Details; + // + // descriptionTextBox + // + this.descriptionTextBox.Location = new System.Drawing.Point(14, 115); + this.descriptionTextBox.MaxLength = 128; + this.descriptionTextBox.Name = "descriptionTextBox"; + this.descriptionTextBox.Size = new System.Drawing.Size(228, 29); + this.descriptionTextBox.TabIndex = 2; + // + // descriptionLabel + // + this.descriptionLabel.AutoSize = true; + this.descriptionLabel.Location = new System.Drawing.Point(14, 82); + this.descriptionLabel.Name = "descriptionLabel"; + this.descriptionLabel.Size = new System.Drawing.Size(207, 25); + this.descriptionLabel.TabIndex = 15; + this.descriptionLabel.Text = "Description (Optional):"; + // + // informationLabel + // + this.informationLabel.AutoSize = true; + this.informationLabel.Location = new System.Drawing.Point(14, 162); + this.informationLabel.Name = "informationLabel"; + this.informationLabel.Size = new System.Drawing.Size(0, 25); + this.informationLabel.TabIndex = 14; + // + // newSupplierTextBox + // + this.newSupplierTextBox.Location = new System.Drawing.Point(14, 45); + this.newSupplierTextBox.MaxLength = 32; + this.newSupplierTextBox.Name = "newSupplierTextBox"; + this.newSupplierTextBox.Size = new System.Drawing.Size(228, 29); + this.newSupplierTextBox.TabIndex = 1; + // + // newSupplierLabel + // + this.newSupplierLabel.AutoSize = true; + this.newSupplierLabel.Location = new System.Drawing.Point(14, 12); + this.newSupplierLabel.Name = "newSupplierLabel"; + this.newSupplierLabel.Size = new System.Drawing.Size(166, 25); + this.newSupplierLabel.TabIndex = 11; + this.newSupplierLabel.Text = "Register Supplier:"; + // + // deleteSupplierButton + // + this.deleteSupplierButton.Enabled = false; + this.deleteSupplierButton.Location = new System.Drawing.Point(12, 430); + this.deleteSupplierButton.Name = "deleteSupplierButton"; + this.deleteSupplierButton.Size = new System.Drawing.Size(200, 50); + this.deleteSupplierButton.TabIndex = 4; + this.deleteSupplierButton.Text = "Remove Supplier"; + this.deleteSupplierButton.UseVisualStyleBackColor = true; + this.deleteSupplierButton.Click += new System.EventHandler(this.deleteSupplierButton_Click); + // + // registerSupplierButton + // + this.registerSupplierButton.Enabled = false; + this.registerSupplierButton.Location = new System.Drawing.Point(480, 430); + this.registerSupplierButton.Name = "registerSupplierButton"; + this.registerSupplierButton.Size = new System.Drawing.Size(200, 50); + this.registerSupplierButton.TabIndex = 3; + this.registerSupplierButton.Text = "Register Supplier"; + this.registerSupplierButton.UseVisualStyleBackColor = true; + this.registerSupplierButton.Click += new System.EventHandler(this.registerSupplierButton_Click); + // + // FrmManageSuppliers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(692, 492); + this.Controls.Add(this.suppliersListBox); + this.Controls.Add(this.descriptionTextBox); + this.Controls.Add(this.descriptionLabel); + this.Controls.Add(this.informationLabel); + this.Controls.Add(this.newSupplierTextBox); + this.Controls.Add(this.newSupplierLabel); + this.Controls.Add(this.deleteSupplierButton); + this.Controls.Add(this.registerSupplierButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FrmManageSuppliers"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Manage Suppliers"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListView suppliersListBox; + private System.Windows.Forms.TextBox descriptionTextBox; + private System.Windows.Forms.Label descriptionLabel; + private System.Windows.Forms.Label informationLabel; + private System.Windows.Forms.TextBox newSupplierTextBox; + private System.Windows.Forms.Label newSupplierLabel; + private System.Windows.Forms.Button deleteSupplierButton; + private System.Windows.Forms.Button registerSupplierButton; + } +} \ No newline at end of file diff --git a/AdvertsingProfitControl/FrmManageSuppliers.cs b/AdvertsingProfitControl/FrmManageSuppliers.cs new file mode 100644 index 0000000..5d89ef3 --- /dev/null +++ b/AdvertsingProfitControl/FrmManageSuppliers.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Data.Entity.Infrastructure; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Transactions; +using System.Windows.Forms; + +namespace AdvertsingProfitControl +{ + public partial class FrmManageSuppliers : Form + { + private bool _isUpdating; + + public FrmManageSuppliers() + { + InitializeComponent(); + newSupplierTextBox.TextChanged += UpdateButtonOnTextChanged; + suppliersListBox.ItemSelectionChanged += UpdateSupplierFields; + var columnHeader = new ColumnHeader + { + Name = "SupplierHeaderColumn", + Width = Width / 2 + }; + suppliersListBox.Columns.Add(columnHeader); + RefreshSupplierListing(); + } + + private void UpdateSupplierFields(object sender, ListViewItemSelectionChangedEventArgs e) + { + newSupplierTextBox.Text = ((Supplier)e.Item.Tag).Name; + descriptionTextBox.Text = ((Supplier)e.Item.Tag).Description; + _isUpdating = true; + deleteSupplierButton.Enabled = true; + registerSupplierButton.Text = @"Update Supplier"; + newSupplierLabel.Text = @"Update Supplier:"; + } + + private void UpdateButtonOnTextChanged(object sender, EventArgs e) + { + if (_isUpdating && newSupplierTextBox.Text.Length == 0) + { + _isUpdating = false; + descriptionTextBox.Text = string.Empty; + registerSupplierButton.Text = @"Register Supplier"; + newSupplierLabel.Text = @"Register New Supplier:"; + } + registerSupplierButton.Enabled = newSupplierTextBox.Text.Length > 0; + } + + private void RefreshSupplierListing() + { + suppliersListBox.Items.Clear(); + var db = new AdvertisingProfitControlModel(); + var suppliers = db.Suppliers.Select(x => x).OrderBy(x => x.Name); + var supplierCount = 0; + foreach (var supplier in suppliers) + { + var item = new ListViewItem + { + Text = supplier.Name, + Tag = supplier + }; + suppliersListBox.Items.Add(item); + supplierCount++; + } + + suppliersListBox.Columns[0].Text = supplierCount > 0 ? @"Current Suppliers:" : @"No Suppliers to Display"; + deleteSupplierButton.Enabled = false; + newSupplierTextBox.Text = string.Empty; + descriptionTextBox.Text = string.Empty; + } + + private void registerSupplierButton_Click(object sender, EventArgs e) + { + var db = new AdvertisingProfitControlModel(); + if (!_isUpdating) + { + if (!db.Suppliers.Any(x => x.Name == newSupplierTextBox.Text)) + { + var supplier = new Supplier() + { + Name = newSupplierTextBox.Text, + Description = descriptionTextBox.Text + }; + db.Suppliers.Add(supplier); + try + { + db.SaveChanges(); + informationLabel.Text = @"Registered '" + Environment.NewLine + supplier.Name + Environment.NewLine + @"' successfully."; + } + catch (DbUpdateException ex) + { + informationLabel.Text = @"Failed to register '" + Environment.NewLine + supplier.Name + @"'." + Environment.NewLine + + ex.Message; + } + } + else + { + MessageBox.Show(@"Supplier '" + newSupplierTextBox.Text + @"' already exists.", + @"Duplicate Entry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + newSupplierTextBox.Text = string.Empty; + } + } + else + { + var item = suppliersListBox.SelectedItems[0]; + var index = ((Supplier)item.Tag).Id; + var supplier = db.Suppliers.SingleOrDefault(x => x.Id == index); + if (supplier == null) + { + informationLabel.Text = @"Failed to retrieve " + Environment.NewLine + @"supplier ID."; + return; + } + supplier.Name = newSupplierTextBox.Text; + supplier.Description = descriptionTextBox.Text; + db.SaveChanges(); + informationLabel.Text = @"Updated '" + Environment.NewLine + newSupplierTextBox.Text + Environment.NewLine + @"' successfully."; + } + RefreshSupplierListing(); + } + + private void deleteSupplierButton_Click(object sender, EventArgs e) + { + var item = suppliersListBox.SelectedItems[0]; + var oldSupplier = (Supplier)item.Tag; + var db = new AdvertisingProfitControlModel(); + var supplier = db.Suppliers.Single(x => x.Id == oldSupplier.Id); + //Check to see if the ad special is used by other tables. + if (supplier.Invoices.Count > 0) + { + //If so, display a warning to the user about the potential data loss. + var result = + MessageBox.Show( + supplier.Invoices.Count + + @" reference(s) to this supplier found. Do you want to delete these records? This can not be undone.", + @"References to " + oldSupplier.Name + @" Found", MessageBoxButtons.YesNoCancel, + MessageBoxIcon.Question); + if (result != DialogResult.Yes) return; + //Perform the necessary operations to remove all references to the key word. + using (var scope = new TransactionScope()) + { + try + { + db.Invoices.RemoveRange(db.Invoices.Where(x => x.FkSupplierId == oldSupplier.Id)); + db.Suppliers.Remove(supplier); + db.SaveChanges(); + scope.Complete(); + informationLabel.Text = @"Removed '" + Environment.NewLine + oldSupplier.Name + + Environment.NewLine + @"' successfully."; + } + catch (DbUpdateException ex) + { + informationLabel.Text = @"Failed to remove " + Environment.NewLine + oldSupplier.Name + @"." + + Environment.NewLine + ex.Message; + } + } + } + else + { + try + { + db.Suppliers.Remove(supplier); + db.SaveChanges(); + informationLabel.Text = @"Removed '" + Environment.NewLine + oldSupplier.Name + + Environment.NewLine + @"' successfully."; + } + catch (DbUpdateException ex) + { + informationLabel.Text = @"Failed to remove " + Environment.NewLine + oldSupplier.Name + @"." + Environment.NewLine + ex.Message; + } + } + RefreshSupplierListing(); + } + } +} diff --git a/AdvertsingProfitControl/FrmManageSuppliers.resx b/AdvertsingProfitControl/FrmManageSuppliers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AdvertsingProfitControl/FrmManageSuppliers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AdvertsingProfitControl/FrmRegisterAdSpecial.Designer.cs b/AdvertsingProfitControl/FrmRegisterAdSpecial.Designer.cs index 8fa0a00..2cdf65f 100644 --- a/AdvertsingProfitControl/FrmRegisterAdSpecial.Designer.cs +++ b/AdvertsingProfitControl/FrmRegisterAdSpecial.Designer.cs @@ -41,10 +41,10 @@ // registerAdSpecialButton // this.registerAdSpecialButton.Enabled = false; - this.registerAdSpecialButton.Location = new System.Drawing.Point(476, 428); + this.registerAdSpecialButton.Location = new System.Drawing.Point(480, 430); this.registerAdSpecialButton.Name = "registerAdSpecialButton"; this.registerAdSpecialButton.Size = new System.Drawing.Size(200, 50); - this.registerAdSpecialButton.TabIndex = 0; + this.registerAdSpecialButton.TabIndex = 3; this.registerAdSpecialButton.Text = "Register Ad Special"; this.registerAdSpecialButton.UseVisualStyleBackColor = true; this.registerAdSpecialButton.Click += new System.EventHandler(this.RegisterNewAdSpecial); @@ -52,10 +52,10 @@ // deleteAdSpecialButton // this.deleteAdSpecialButton.Enabled = false; - this.deleteAdSpecialButton.Location = new System.Drawing.Point(13, 428); + this.deleteAdSpecialButton.Location = new System.Drawing.Point(12, 430); this.deleteAdSpecialButton.Name = "deleteAdSpecialButton"; this.deleteAdSpecialButton.Size = new System.Drawing.Size(200, 50); - this.deleteAdSpecialButton.TabIndex = 2; + this.deleteAdSpecialButton.TabIndex = 4; this.deleteAdSpecialButton.Text = "Remove Ad Special"; this.deleteAdSpecialButton.UseVisualStyleBackColor = true; this.deleteAdSpecialButton.Click += new System.EventHandler(this.deleteAdSpecialButton_Click); @@ -72,18 +72,18 @@ // newAdSpecialTextBox // this.newAdSpecialTextBox.Location = new System.Drawing.Point(17, 54); + this.newAdSpecialTextBox.MaxLength = 32; this.newAdSpecialTextBox.Name = "newAdSpecialTextBox"; this.newAdSpecialTextBox.Size = new System.Drawing.Size(228, 29); - this.newAdSpecialTextBox.TabIndex = 4; + this.newAdSpecialTextBox.TabIndex = 1; // // informationLabel // this.informationLabel.AutoSize = true; this.informationLabel.Location = new System.Drawing.Point(17, 171); this.informationLabel.Name = "informationLabel"; - this.informationLabel.Size = new System.Drawing.Size(64, 25); + this.informationLabel.Size = new System.Drawing.Size(0, 25); this.informationLabel.TabIndex = 5; - this.informationLabel.Text = "label1"; // // adSpecialDescription // @@ -97,17 +97,19 @@ // descriptionTextBox // this.descriptionTextBox.Location = new System.Drawing.Point(17, 124); + this.descriptionTextBox.MaxLength = 128; this.descriptionTextBox.Name = "descriptionTextBox"; this.descriptionTextBox.Size = new System.Drawing.Size(228, 29); - this.descriptionTextBox.TabIndex = 7; + this.descriptionTextBox.TabIndex = 2; // // adSpecialsListBox // this.adSpecialsListBox.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; - this.adSpecialsListBox.Location = new System.Drawing.Point(256, 21); + this.adSpecialsListBox.Location = new System.Drawing.Point(260, 21); this.adSpecialsListBox.Name = "adSpecialsListBox"; this.adSpecialsListBox.Size = new System.Drawing.Size(420, 401); this.adSpecialsListBox.TabIndex = 8; + this.adSpecialsListBox.TabStop = false; this.adSpecialsListBox.UseCompatibleStateImageBehavior = false; this.adSpecialsListBox.View = System.Windows.Forms.View.Details; // @@ -115,7 +117,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(686, 489); + this.ClientSize = new System.Drawing.Size(692, 492); this.Controls.Add(this.adSpecialsListBox); this.Controls.Add(this.descriptionTextBox); this.Controls.Add(this.adSpecialDescription); diff --git a/AdvertsingProfitControl/FrmRegisterAdSpecial.cs b/AdvertsingProfitControl/FrmRegisterAdSpecial.cs index 68c1f3d..7b1a49d 100644 --- a/AdvertsingProfitControl/FrmRegisterAdSpecial.cs +++ b/AdvertsingProfitControl/FrmRegisterAdSpecial.cs @@ -1,19 +1,13 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Data.Entity.Infrastructure; -using System.Drawing; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Transactions; using System.Windows.Forms; namespace AdvertsingProfitControl { public partial class FrmRegisterAdSpecial : Form { - private readonly ToolTip _tt = new ToolTip(); private bool _isUpdating; public FrmRegisterAdSpecial() @@ -24,10 +18,9 @@ namespace AdvertsingProfitControl { Name = "AdSpecialsHeaderColumn", Text = @"Current Ad Special Grouping Keywords:", - Width = adSpecialsListBox.Width - 5 + Width = Width / 2 }; adSpecialsListBox.Columns.Add(columnHeader); - adSpecialsListBox.MouseMove += OnMouseMove; adSpecialsListBox.ItemSelectionChanged += UpdateAdSpecialTextBoxes; RefreshAdSpecialListing(); } @@ -39,6 +32,7 @@ namespace AdvertsingProfitControl _isUpdating = true; deleteAdSpecialButton.Enabled = true; registerAdSpecialButton.Text = @"Update Ad Special"; + newAdSpecialLabel.Text = @"Update Ad Special:"; } private void NewAdSpecialTextChanged(object sender, EventArgs e) @@ -48,6 +42,7 @@ namespace AdvertsingProfitControl _isUpdating = false; descriptionTextBox.Text = string.Empty; registerAdSpecialButton.Text = @"Register Ad Special"; + newAdSpecialLabel.Text = @"Register New Ad Special:"; } registerAdSpecialButton.Enabled = newAdSpecialTextBox.Text.Length > 0; } @@ -101,24 +96,11 @@ namespace AdvertsingProfitControl RefreshAdSpecialListing(); } - private void OnMouseMove(object sender, MouseEventArgs e) - { - var box = sender as ListBox; - if (box == null) return; - var listBox = box; - var point = new Point(e.X, e.Y); - var hoverIndex = listBox.IndexFromPoint(point); - if (hoverIndex >= 0 && hoverIndex < listBox.Items.Count) - { - // _tt.SetToolTip(listBox, _descriptions[hoverIndex]); - } - } - private void RefreshAdSpecialListing() { adSpecialsListBox.Items.Clear(); var db = new AdvertisingProfitControlModel(); - var adSpecials = db.AdSpecials.Select(x => x); + var adSpecials = db.AdSpecials.Select(x => x).OrderBy(x => x.Name); foreach (var adSpecial in adSpecials) { var item = new ListViewItem @@ -135,15 +117,57 @@ namespace AdvertsingProfitControl private void deleteAdSpecialButton_Click(object sender, EventArgs e) { - //TODO: Scan for Ad Specials that are in use by a table before removing. var item = adSpecialsListBox.SelectedItems[0]; var adSpecial = (AdSpecial) item.Tag; var db = new AdvertisingProfitControlModel(); var ad = db.AdSpecials.Single(x => x.Id == adSpecial.Id); - db.AdSpecials.Remove(ad); - db.SaveChanges(); + //Check to see if the ad special is used by other tables. + if (ad.ActualSales.Count > 0) + { + //If so, display a warning to the user about the potential data loss. + var result = + MessageBox.Show( + ad.ActualSales.Count + + @" reference(s) to this keyword found. Do you want to delete these records? This can not be undone.", + @"References to " + adSpecial.Name + @" Found", MessageBoxButtons.YesNoCancel, + MessageBoxIcon.Question); + if (result != DialogResult.Yes) return; + //Perform the necessary operations to remove all references to the key word. + using (var scope = new TransactionScope()) + { + try + { + db.Projections.RemoveRange(db.Projections.Where(x => x.FkAdSpecialId == adSpecial.Id)); + db.Inventories.RemoveRange(db.Inventories.Where(x => x.FkAdSpecialId == adSpecial.Id)); + db.ActualSales.RemoveRange(db.ActualSales.Where(x => x.FkAdSpecialId == adSpecial.Id)); + db.AdSpecials.Remove(ad); + db.SaveChanges(); + scope.Complete(); + informationLabel.Text = @"Removed '" + Environment.NewLine + adSpecial.Name + + Environment.NewLine + @"' successfully."; + } + catch (DbUpdateException ex) + { + informationLabel.Text = @"Failed to remove " + Environment.NewLine + adSpecial.Name + @"." + + Environment.NewLine + ex.Message; + } + } + } + else + { + try + { + db.AdSpecials.Remove(ad); + db.SaveChanges(); + informationLabel.Text = @"Removed '" + Environment.NewLine + adSpecial.Name + + Environment.NewLine + @"' successfully."; + } + catch (DbUpdateException ex) + { + informationLabel.Text = @"Failed to remove " + Environment.NewLine + adSpecial.Name + @"." + Environment.NewLine + ex.Message; + } + } RefreshAdSpecialListing(); - informationLabel.Text = @"Removed '" + Environment.NewLine + adSpecial.Name + Environment.NewLine + @"' successfully."; } } } diff --git a/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.csproj.FileListAbsolute.txt b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..e0b4939 --- /dev/null +++ b/AdvertsingProfitControl/obj/Debug/AdvertsingProfitControl.csproj.FileListAbsolute.txt @@ -0,0 +1,23 @@ +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.csprojResolveAssemblyReference.cache +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.DebugDatabaseConverter.resources +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmAddRecord.resources +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmMain.resources +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmLogConsole.resources +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.FrmRegisterAdSpecial.resources +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.NewModifyRecord.resources +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.Properties.Resources.resources +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.csproj.GenerateResource.Cache +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\APCDatabase.accdb +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertsingProfitControl.exe.config +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertsingProfitControl.exe +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\AdvertsingProfitControl.pdb +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\EntityFramework.dll +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\EntityFramework.SqlServer.dll +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\HtmlRenderer.dll +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\HtmlRenderer.WinForms.dll +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\EntityFramework.xml +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\EntityFramework.SqlServer.xml +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\HtmlRenderer.pdb +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\bin\Debug\HtmlRenderer.WinForms.pdb +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.exe +C:\Users\glmcc\Documents\Source Control\AdvertisingProfitControl\AdvertsingProfitControl\obj\Debug\AdvertsingProfitControl.pdb