diff --git a/AdvertsingProfitControl/APCDatabase.accdb b/AdvertsingProfitControl/APCDatabase.accdb
index 3a240f4..2ebb38d 100644
Binary files a/AdvertsingProfitControl/APCDatabase.accdb and b/AdvertsingProfitControl/APCDatabase.accdb differ
diff --git a/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs b/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs
index 4f9c652..5dd7ec8 100644
--- a/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs
+++ b/AdvertsingProfitControl/AdvertisingProfitControlTableHelper.cs
@@ -208,6 +208,11 @@ namespace AdvertsingProfitControl
else if (rowStatus == RowAttribute.HeaderRow && !(bool)dataGridView.Rows[i - 1].Cells[isHeaderColumn].EditedFormattedValue)
{
//Set the previous row as a header row.
+ if (!(bool)dataGridView.Rows[i - 1].Cells[isMemberColumn].EditedFormattedValue)
+ {
+ dataGridView.Rows[i - 1].Cells[isDirtyColumn].Value = true;
+ dataGridView.Rows[i - 1].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
dataGridView.Rows[i - 1].Cells[isHeaderColumn].Value = true;
dataGridView.Rows[i - 1].Cells[isMemberColumn].Value = false;
dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.LightGray;
@@ -215,7 +220,7 @@ namespace AdvertsingProfitControl
dataGridView.Rows[i - 1].Cells[isDirtyColumn].Value = true;
dataGridView.Rows[i - 1].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
//Check for changes in the current row.
- if ((bool)dataGridView.Rows[i].Cells[isMemberColumn].EditedFormattedValue)
+ if (!(bool)dataGridView.Rows[i].Cells[isMemberColumn].EditedFormattedValue)
{
dataGridView.Rows[i].Cells[isDirtyColumn].Value = true;
dataGridView.Rows[i].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
@@ -253,6 +258,40 @@ namespace AdvertsingProfitControl
dataGridView.Rows[0].DefaultCellStyle.BackColor = Color.White;
}
}
+ else if (rowStatus == RowAttribute.AdSpecialRow)
+ {
+ if(i == 0) return;
+ //Get the previous row's attribute.
+ rowStatus = parser.GetRowAttribute(dataGridView.Rows[i - 1]);
+ if (rowStatus == RowAttribute.HeaderRow)
+ {
+ //Check to see if the previous row sees itself as a header row, if so mark it dirty.
+ if (!(bool)dataGridView.Rows[i - 1].Cells[isHeaderColumn].EditedFormattedValue)
+ {
+ dataGridView.Rows[i - 1].Cells[isDirtyColumn].Value = true;
+ dataGridView.Rows[i - 1].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
+ //Clear its color coding.
+ dataGridView.Rows[i - 1].Cells[isHeaderColumn].Value = false;
+ dataGridView.Rows[i - 1].Cells[isMemberColumn].Value = false;
+ dataGridView.Rows[i - 1].DefaultCellStyle.BackColor = Color.White;
+ }
+ //Next get the status of the next row.
+ rowStatus = parser.GetRowAttribute(dataGridView.Rows[i + 1]);
+ if (rowStatus == RowAttribute.MemberRow)
+ {
+ //Check to see if the next row thinks it is a member row.
+ if (!(bool)dataGridView.Rows[i + 1].Cells[isMemberColumn].EditedFormattedValue)
+ {
+ dataGridView.Rows[i + 1].Cells[isDirtyColumn].Value = true;
+ dataGridView.Rows[i + 1].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
+ }
+ //Clear its color coding.
+ dataGridView.Rows[i + 1].Cells[isMemberColumn].Value = false;
+ dataGridView.Rows[i + 1].Cells[isHeaderColumn].Value = false;
+ dataGridView.Rows[i + 1].DefaultCellStyle.BackColor = Color.White;
+ }
+ }
}
}
diff --git a/AdvertsingProfitControl/AdvertsingProfitControl.csproj b/AdvertsingProfitControl/AdvertsingProfitControl.csproj
index 9097f4a..b28db10 100644
--- a/AdvertsingProfitControl/AdvertsingProfitControl.csproj
+++ b/AdvertsingProfitControl/AdvertsingProfitControl.csproj
@@ -109,6 +109,12 @@
+
+ Form
+
+
+ DebugDatabaseConverter.cs
+
Form
@@ -176,6 +182,9 @@
+
+ DebugDatabaseConverter.cs
+
FrmAddRecord.cs
diff --git a/AdvertsingProfitControl/DatabaseReader.cs b/AdvertsingProfitControl/DatabaseReader.cs
index d13dae2..5c7aeef 100644
--- a/AdvertsingProfitControl/DatabaseReader.cs
+++ b/AdvertsingProfitControl/DatabaseReader.cs
@@ -375,7 +375,7 @@ namespace AdvertsingProfitControl
var id = "0";
var oleDbCommand = new OleDbCommand()
{
- CommandText = "SELECT AdItem.ID FROM AdItem WHERE UCASE(AdItem.AdItem) = UCASE(?)" //JUST MAKE A CUSTOM PARSING ENGINE
+ CommandText = "SELECT AdItem.ID FROM AdItem WHERE UCASE(AdItem.AdItem) = UCASE(?)"
};
oleDbCommand.Parameters.AddWithValue("AdItemName", adItemName);
var connection = new OleDbConnection(connectionString);
@@ -393,6 +393,32 @@ namespace AdvertsingProfitControl
id = reader[0].ToString();
}
}
+ if (id != "0") return id;
+ {
+ oleDbCommand.CommandText = "INSERT INTO AdItem (AdItem) VALUES (?)";
+ oleDbCommand.Parameters.Clear();
+ oleDbCommand.Parameters.AddWithValue("AdItem", TextFormat.FormatAdItemText(adItemName));
+
+ try
+ {
+ var rowsEffected = oleDbCommand.ExecuteNonQuery();
+ if (rowsEffected == 1)
+ {
+ oleDbCommand.Parameters.Clear();
+ oleDbCommand.CommandText = "SELECT AdItem.ID FROM AdItem WHERE AdItem.AdItem = ?";
+ oleDbCommand.Parameters.AddWithValue("ad", TextFormat.FormatAdItemText(adItemName));
+ var reader = oleDbCommand.ExecuteReader();
+ while (reader != null && reader.Read())
+ {
+ id = reader[0].ToString();
+ }
+ }
+ }
+ catch (OleDbException e)
+ {
+
+ }
+ }
}
}
return id;
diff --git a/AdvertsingProfitControl/DebugDatabaseConverter.Designer.cs b/AdvertsingProfitControl/DebugDatabaseConverter.Designer.cs
new file mode 100644
index 0000000..adf5cba
--- /dev/null
+++ b/AdvertsingProfitControl/DebugDatabaseConverter.Designer.cs
@@ -0,0 +1,105 @@
+namespace AdvertsingProfitControl
+{
+ partial class DebugDatabaseConverter
+ {
+ ///
+ /// 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.existingDatesListBox = new System.Windows.Forms.ListBox();
+ this.datesToConvertListBox = new System.Windows.Forms.ListBox();
+ this.moveOverButton = new System.Windows.Forms.Button();
+ this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
+ this.convertButton = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // existingDatesListBox
+ //
+ this.existingDatesListBox.FormattingEnabled = true;
+ this.existingDatesListBox.ItemHeight = 24;
+ this.existingDatesListBox.Location = new System.Drawing.Point(59, 84);
+ this.existingDatesListBox.Name = "existingDatesListBox";
+ this.existingDatesListBox.Size = new System.Drawing.Size(254, 316);
+ this.existingDatesListBox.TabIndex = 0;
+ //
+ // datesToConvertListBox
+ //
+ this.datesToConvertListBox.FormattingEnabled = true;
+ this.datesToConvertListBox.ItemHeight = 24;
+ this.datesToConvertListBox.Location = new System.Drawing.Point(373, 84);
+ this.datesToConvertListBox.Name = "datesToConvertListBox";
+ this.datesToConvertListBox.Size = new System.Drawing.Size(254, 316);
+ this.datesToConvertListBox.TabIndex = 1;
+ //
+ // moveOverButton
+ //
+ this.moveOverButton.Enabled = false;
+ this.moveOverButton.Location = new System.Drawing.Point(59, 446);
+ this.moveOverButton.Name = "moveOverButton";
+ this.moveOverButton.Size = new System.Drawing.Size(160, 56);
+ this.moveOverButton.TabIndex = 2;
+ this.moveOverButton.Text = "Move Selected";
+ this.moveOverButton.UseVisualStyleBackColor = true;
+ this.moveOverButton.Click += new System.EventHandler(this.moveOverButton_Click);
+ //
+ // openFileDialog1
+ //
+ this.openFileDialog1.FileName = "openFileDialog1";
+ //
+ // convertButton
+ //
+ this.convertButton.Location = new System.Drawing.Point(373, 452);
+ this.convertButton.Name = "convertButton";
+ this.convertButton.Size = new System.Drawing.Size(133, 50);
+ this.convertButton.TabIndex = 3;
+ this.convertButton.Text = "Convert";
+ this.convertButton.UseVisualStyleBackColor = true;
+ this.convertButton.Click += new System.EventHandler(this.convertButton_Click);
+ //
+ // DebugDatabaseConverter
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(849, 827);
+ this.Controls.Add(this.convertButton);
+ this.Controls.Add(this.moveOverButton);
+ this.Controls.Add(this.datesToConvertListBox);
+ this.Controls.Add(this.existingDatesListBox);
+ this.Name = "DebugDatabaseConverter";
+ this.Text = "DebugDatabaseConverter";
+ this.Load += new System.EventHandler(this.DebugDatabaseConverter_Load);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.ListBox existingDatesListBox;
+ private System.Windows.Forms.ListBox datesToConvertListBox;
+ private System.Windows.Forms.Button moveOverButton;
+ private System.Windows.Forms.OpenFileDialog openFileDialog1;
+ private System.Windows.Forms.Button convertButton;
+ }
+}
\ No newline at end of file
diff --git a/AdvertsingProfitControl/DebugDatabaseConverter.cs b/AdvertsingProfitControl/DebugDatabaseConverter.cs
new file mode 100644
index 0000000..373d544
--- /dev/null
+++ b/AdvertsingProfitControl/DebugDatabaseConverter.cs
@@ -0,0 +1,492 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Data.OleDb;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace AdvertsingProfitControl
+{
+ public partial class DebugDatabaseConverter : Form
+ {
+ private string _filePath;
+ private string _connectionString;
+ public DebugDatabaseConverter()
+ {
+ InitializeComponent();
+ existingDatesListBox.SelectedIndexChanged += EnableButton;
+ }
+
+ private void EnableButton(object sender, EventArgs e)
+ {
+ moveOverButton.Enabled = true;
+ }
+
+ private void DebugDatabaseConverter_Load(object sender, EventArgs e)
+ {
+ openFileDialog1.DefaultExt = "accdb";
+ openFileDialog1.Filter = @"Access Files (*.accdb) | *.accdb";
+
+ if (openFileDialog1.ShowDialog() == DialogResult.OK)
+ {
+ var filePath = openFileDialog1.FileName;
+ if (File.Exists(filePath))
+ {
+ _filePath = filePath;
+ //Get the list of dates.
+ var connectionString =
+ "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Persist Security Info=False";
+ _connectionString = connectionString;
+ var dates = new List();
+ var oleDbCommand = new OleDbCommand
+ {
+ CommandText = "SELECT EndOfWeekDate FROM WeekEnding"
+ };
+ var connection = new OleDbConnection(connectionString);
+ oleDbCommand.Connection = connection;
+
+ using (connection)
+ {
+ using (oleDbCommand)
+ {
+ connection.Open();
+ using (var reader = oleDbCommand.ExecuteReader())
+ {
+ while (reader != null && reader.Read())
+ {
+ dates.Add(DateTime.Parse(reader[0].ToString()));
+ }
+ }
+ }
+ }
+
+ foreach (var date in dates)
+ {
+ existingDatesListBox.Items.Add(date.ToShortDateString());
+ }
+ }
+ }
+ }
+
+ private void moveOverButton_Click(object sender, EventArgs e)
+ {
+ if (existingDatesListBox.SelectedIndex != -1)
+ {
+ datesToConvertListBox.Items.Add(existingDatesListBox.SelectedItem);
+ existingDatesListBox.Items.Remove(existingDatesListBox.SelectedItem);
+ moveOverButton.Enabled = false;
+ }
+ }
+
+ private void convertButton_Click(object sender, EventArgs e)
+ {
+ if (datesToConvertListBox.Items.Count == 0)
+ {
+ return;
+ }
+ foreach (var date in datesToConvertListBox.Items)
+ {
+ var oldDateId = GetDateIdByDateString(date.ToString());
+ //Get the tables.
+ var projectionsTable = ReturnProjections(oldDateId);
+ var inventoryTable = ReturnInventory(oldDateId);
+ var actualSales = ReturnActualSales(oldDateId);
+ var invoices = ReturnInvoiceTable(oldDateId);
+ var weeklySales = ReturnWeeklySalesFromDateId(oldDateId);
+ MassiveWriteFunction(date.ToString(), projectionsTable, inventoryTable, actualSales, invoices, weeklySales);
+ }
+ }
+
+
+ private void MassiveWriteFunction(string dateString, DataTable projections, DataTable inventory, DataTable actualSales, DataTable invoice, DataTable weeklySales)
+ {
+ var dbT = new DatabaseTracker();
+ var dbR = new DatabaseReader();
+ //Get a new ID number for the date supplied.
+ var oleDbConnection = new OleDbConnection(dbT.DatabaseConnectionString);
+ var oleDbCommand = new OleDbCommand
+ {
+ Connection = oleDbConnection
+ };
+ OleDbTransaction oleDbTransaction = null;
+ try
+ {
+ 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();
+ int adspecialId = 0;
+ for (var rowIndex = 0; rowIndex < projections.Rows.Count; rowIndex++)
+ {
+ //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
+ for (var i = 0; i < inventory.Rows.Count; i++)
+ {
+ 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("BegnningInventory", inventory.Rows[i][1]);
+ oleDbCommand.Parameters.AddWithValue("Received", inventory.Rows[i][2]);
+ oleDbCommand.Parameters.AddWithValue("TotalInventory", inventory.Rows[i][3]);
+ oleDbCommand.Parameters.AddWithValue("EndingInventory", inventory.Rows[i][4]);
+ 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
+ for (var rowIndex = 0; rowIndex < actualSales.Rows.Count; rowIndex++)
+ {
+ //Get the ID number of the ad item.
+ var adItemId = int.Parse(RetrieveAdItemId(actualSales.Rows[rowIndex][0].ToString()));
+ adspecialId = GetAdSpecialId(int.Parse(actualSales.Rows[rowIndex][8].ToString()));
+ oleDbCommand.CommandText =
+ "INSERT INTO ActualSales (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", actualSales.Rows[rowIndex][1]);
+ oleDbCommand.Parameters.AddWithValue("SalesPrice", actualSales.Rows[rowIndex][2]);
+ oleDbCommand.Parameters.AddWithValue("TotalSales", actualSales.Rows[rowIndex][3]);
+ oleDbCommand.Parameters.AddWithValue("Cost", actualSales.Rows[rowIndex][4]);
+ oleDbCommand.Parameters.AddWithValue("ProfitReturn", actualSales.Rows[rowIndex][5]);
+ oleDbCommand.Parameters.AddWithValue("TotalProfitReturn", actualSales.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();
+ }
+
+ for (var i = 0; i < invoice.Rows.Count; i++)
+ {
+ var supplierId = GetSupplierId(invoice.Rows[i][1].ToString());
+ //SELECT Invoice.InvoiceDate, Supplier.SupplierName, Invoice.InvoiceNumber, Invoice.InvoiceNetAmountAtCost, Invoice.InvoiceNetAmount, Invoice.InvoiceNote FROM (Supplier INNER JOIN Invoice ON Supplier.ID = Invoice.FK_Supplier) WHERE FK_DateID = ?
+ oleDbCommand.CommandText =
+ "INSERT INTO Invoice (InvoiceDate, InvoiceNumber, InvoiceNetAmountAtCost, InvoiceNetAmount, InvoiceNote, FK_Supplier, FK_DateID) VALUES(?,?,?,?,?,?,?)";
+ oleDbCommand.Parameters.AddWithValue("InvoiceDate", invoice.Rows[i][0].ToString());
+ oleDbCommand.Parameters.AddWithValue("InvoiceNumber", invoice.Rows[i][2].ToString());
+ oleDbCommand.Parameters.AddWithValue("InvoiceNetAmountAtCost", invoice.Rows[i][3].ToString() == "" ? 0 : double.Parse(invoice.Rows[i][3].ToString()));
+ oleDbCommand.Parameters.AddWithValue("InvoiceNetAmount", invoice.Rows[i][4].ToString() == "" ? 0 : double.Parse(invoice.Rows[i][4].ToString()));
+ oleDbCommand.Parameters.AddWithValue("InvoiceNote", invoice.Rows[i][5].ToString());
+ oleDbCommand.Parameters.AddWithValue("FK_Supplier", supplierId);
+ oleDbCommand.Parameters.AddWithValue("FK_DateID", dateId);
+ oleDbCommand.ExecuteNonQuery();
+ oleDbCommand.Parameters.Clear();
+ }
+ //"SELECT WeeklySales.Sunday, WeeklySales.Monday, WeeklySales.Tuesday, WeeklySales.Wednesday, WeeklySales.Thursday, WeeklySales.Friday, WeeklySales.Saturday, WeeklySales.TotalSales FROM WeeklySales WHERE FK_DateID = ?"
+ oleDbCommand.CommandText = "INSERT INTO WeeklySales (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, TotalSales, FK_DateID) VALUES (?,?,?,?,?,?,?,?,?)";
+ oleDbCommand.Parameters.AddWithValue("Sunday", weeklySales.Rows[0][0]);
+ oleDbCommand.Parameters.AddWithValue("Monday", weeklySales.Rows[0][1]);
+ oleDbCommand.Parameters.AddWithValue("Tuesday", weeklySales.Rows[0][2]);
+ oleDbCommand.Parameters.AddWithValue("Wednesday", weeklySales.Rows[0][3]);
+ oleDbCommand.Parameters.AddWithValue("Thursday", weeklySales.Rows[0][4]);
+ oleDbCommand.Parameters.AddWithValue("Friday", weeklySales.Rows[0][5]);
+ oleDbCommand.Parameters.AddWithValue("Saturday", weeklySales.Rows[0][6]);
+ oleDbCommand.Parameters.AddWithValue("TotalSales", weeklySales.Rows[0][7]);
+ oleDbCommand.Parameters.AddWithValue("DateID", dateId);
+ oleDbCommand.ExecuteNonQuery();
+
+ oleDbTransaction.Commit();
+ }
+ catch (OleDbException e)
+ {
+ MessageBox.Show(e.Message);
+ oleDbTransaction?.Rollback();
+ }
+ }
+
+ public int GetSupplierId(string supplierName)
+ {
+ var dbT = new DatabaseTracker();
+ var supplierId = 0;
+ var oleDbConnection = new OleDbConnection(dbT.DatabaseConnectionString);
+ var oleDbCommand = new OleDbCommand
+ {
+ Connection = oleDbConnection,
+ CommandText = "SELECT Supplier.ID FROM Supplier WHERE SupplierName = ?"
+ };
+ oleDbCommand.Parameters.AddWithValue("eh", supplierName);
+
+ try
+ {
+ oleDbConnection.Open();
+ var reader = oleDbCommand.ExecuteReader();
+ while (reader != null && reader.Read())
+ {
+ supplierId = int.Parse(reader[0].ToString());
+ }
+ }
+ catch (OleDbException e)
+ {
+ MessageBox.Show(e.Message);
+ }
+
+ return supplierId;
+ }
+
+ public int GetAdSpecialId(int adSpecialId)
+ {
+ var id = 0;
+ var dbT = new DatabaseTracker();
+ var dbR = new DatabaseReader();
+ //Get a new ID number for the date supplied.
+ var oleDbConnection = new OleDbConnection(_connectionString);
+ var oleDbCommand = new OleDbCommand
+ {
+ Connection = oleDbConnection,
+ CommandText = "SELECT GroupCategory.GroupDescription FROM GroupCategory WHERE GroupCategory.ID = ?"
+ };
+ oleDbCommand.Parameters.AddWithValue("eh", adSpecialId);
+
+ try
+ {
+ oleDbConnection.Open();
+ var reader = oleDbCommand.ExecuteReader();
+ string adSpecialText = "";
+ while (reader != null && reader.Read())
+ {
+ adSpecialText = reader[0].ToString();
+ }
+ oleDbCommand.Parameters.Clear();
+ oleDbCommand.Connection.Close();
+ var spam = new OleDbConnection(dbT.DatabaseConnectionString);
+ var newSpam = new OleDbCommand
+ {
+ Connection = spam,
+ CommandText =
+ "SELECT AdSpecialName.ID FROM AdSpecialName WHERE AdSpecialName.AdSpecialName = ?"
+ };
+ spam.Open();
+ newSpam.Parameters.AddWithValue("text", adSpecialText);
+ reader?.Close();
+ reader = newSpam.ExecuteReader();
+ while (reader != null && reader.Read())
+ {
+ id = int.Parse(reader[0].ToString());
+ }
+ reader?.Close();
+ }
+ catch (OleDbException e)
+ {
+ MessageBox.Show(e.Message);
+ throw;
+ }
+ return id;
+ }
+
+ public string RetrieveAdItemId(string adItemName)
+ {
+ var dbT = new DatabaseTracker();
+ var dbR = new DatabaseReader();
+
+ return dbR.RetrieveAdItemId(adItemName, dbT.DatabaseConnectionString);
+ }
+
+ private int GetDateIdByDateString(string dateString)
+ {
+ var dateId = 0;
+ var oleDbCommand = new OleDbCommand()
+ {
+ CommandText = "SELECT WeekEnding.ID FROM WeekEnding WHERE WeekEnding.EndOfWeekDate = ?"
+ };
+ oleDbCommand.Parameters.AddWithValue("DateString", dateString);
+ var connection = new OleDbConnection(_connectionString);
+ oleDbCommand.Connection = connection;
+
+ using (connection)
+ {
+ using (oleDbCommand)
+ {
+ connection.Open();
+ using (var reader = oleDbCommand.ExecuteReader())
+ {
+ while (reader != null && reader.Read())
+ {
+ dateId = int.Parse(reader[0].ToString());
+ }
+ }
+ }
+ }
+
+ return dateId;
+ }
+
+ private DataTable ReturnProjections(int dateId)
+ {
+ var dataTable = new DataTable();
+ var oleDbCommand = new OleDbCommand
+ {
+ CommandText = "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("DateID", dateId);
+ var connection = new OleDbConnection(_connectionString);
+ oleDbCommand.Connection = connection;
+
+ using (connection)
+ {
+ using (oleDbCommand)
+ {
+ connection.Open();
+ using (var dataAdapter = new OleDbDataAdapter(oleDbCommand))
+ {
+ dataAdapter.Fill(dataTable);
+ }
+ }
+ }
+ return dataTable;
+ }
+
+ public DataTable ReturnInventory(int dateId)
+ {
+ var dataTable = new DataTable();
+ var oleDbCommand = new OleDbCommand()
+ {
+ CommandText = "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("DateID", dateId);
+ var connection = new OleDbConnection(_connectionString);
+ oleDbCommand.Connection = connection;
+
+ using (connection)
+ {
+ using (oleDbCommand)
+ {
+ connection.Open();
+ using (var dataAdapter = new OleDbDataAdapter(oleDbCommand))
+ {
+ dataAdapter.Fill(dataTable);
+ }
+ }
+ }
+ return dataTable;
+ }
+
+ public DataTable ReturnActualSales(int dateId)
+ {
+ var dataTable = new DataTable();
+ var oleDbCommand = new OleDbCommand()
+ {
+ CommandText = "SELECT AdItem.AdItem, APC.ActualSold, APC.ActualSalePrice, APC.ActualTotalSales, APC.ActualCost, APC.ActualProfitReturn, APC.ActualTotalProfitReturn, 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("DateID", dateId);
+ var connection = new OleDbConnection(_connectionString);
+ oleDbCommand.Connection = connection;
+
+ using (connection)
+ {
+ using (oleDbCommand)
+ {
+ connection.Open();
+ using (var dataAdapter = new OleDbDataAdapter(oleDbCommand))
+ {
+ dataAdapter.Fill(dataTable);
+ }
+ }
+ }
+ return dataTable;
+ }
+
+ public DataTable ReturnInvoiceTable(int dateId)
+ {
+ var dataTable = new DataTable();
+ var oleDbCommand = new OleDbCommand()
+ {
+ CommandText = "SELECT Invoice.InvoiceDate, Supplier.SupplierName, Invoice.InvoiceNumber, Invoice.InvoiceNetAmountAtCost, Invoice.InvoiceNetAmount, Invoice.InvoiceNote FROM (Supplier INNER JOIN Invoice ON Supplier.ID = Invoice.FK_Supplier) WHERE FK_DateID = ?"
+ };
+ oleDbCommand.Parameters.AddWithValue("DateID", dateId);
+ var connection = new OleDbConnection(_connectionString);
+ oleDbCommand.Connection = connection;
+
+ using (connection)
+ {
+ using (oleDbCommand)
+ {
+ using (var adapter = new OleDbDataAdapter(oleDbCommand))
+ {
+ adapter.Fill(dataTable);
+ }
+ }
+ }
+
+ return dataTable;
+ }
+
+ public DataTable ReturnWeeklySalesFromDateId(int dateId)
+ {
+ var dataTable = new DataTable();
+ var oleDbCommand = new OleDbCommand()
+ {
+ CommandText = "SELECT WeeklySales.Sunday, WeeklySales.Monday, WeeklySales.Tuesday, WeeklySales.Wednesday, WeeklySales.Thursday, WeeklySales.Friday, WeeklySales.Saturday, WeeklySales.TotalSales FROM WeeklySales WHERE FK_DateID = ?"
+ };
+ oleDbCommand.Parameters.AddWithValue("DateID", dateId);
+ var connection = new OleDbConnection(_connectionString);
+ oleDbCommand.Connection = connection;
+ using (connection)
+ {
+ using (oleDbCommand)
+ {
+ connection.Open();
+ using (var dataAdapter = new OleDbDataAdapter(oleDbCommand))
+ {
+ dataAdapter.Fill(dataTable);
+ }
+ }
+ }
+
+ return dataTable;
+ }
+ }
+}
diff --git a/AdvertsingProfitControl/DebugDatabaseConverter.resx b/AdvertsingProfitControl/DebugDatabaseConverter.resx
new file mode 100644
index 0000000..9bad2f5
--- /dev/null
+++ b/AdvertsingProfitControl/DebugDatabaseConverter.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/AdvertsingProfitControl/FrmMain.Designer.cs b/AdvertsingProfitControl/FrmMain.Designer.cs
index e0c21ec..d6c8416 100644
--- a/AdvertsingProfitControl/FrmMain.Designer.cs
+++ b/AdvertsingProfitControl/FrmMain.Designer.cs
@@ -100,6 +100,8 @@
this.grossProfitEstimatedWeeklyDeptmartmentExpenseLabel = new System.Windows.Forms.Label();
this.perfectGrossProfitLabel = new System.Windows.Forms.Label();
this.grossProfitDollarGrossProfitLabel = new System.Windows.Forms.Label();
+ this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.debugToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.mainMenu.SuspendLayout();
this.mainTableLayoutPanel.SuspendLayout();
this.commentMainTableLayoutPanel.SuspendLayout();
@@ -143,7 +145,8 @@
this.fileMainMenu,
this.recordsToolStripMenuItem,
this.toolsMainMenu,
- this.helpMainMenu});
+ this.helpMainMenu,
+ this.debugToolStripMenuItem});
this.mainMenu.Location = new System.Drawing.Point(0, 0);
this.mainMenu.Name = "mainMenu";
this.mainMenu.Padding = new System.Windows.Forms.Padding(10, 3, 0, 3);
@@ -909,6 +912,21 @@
this.grossProfitDollarGrossProfitLabel.TabIndex = 2;
this.grossProfitDollarGrossProfitLabel.Text = "Dollar Gross Profit: ";
//
+ // debugToolStripMenuItem
+ //
+ this.debugToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.debugToolStripMenuItem1});
+ this.debugToolStripMenuItem.Name = "debugToolStripMenuItem";
+ this.debugToolStripMenuItem.Size = new System.Drawing.Size(87, 34);
+ this.debugToolStripMenuItem.Text = "Debug";
+ //
+ // debugToolStripMenuItem1
+ //
+ this.debugToolStripMenuItem1.Name = "debugToolStripMenuItem1";
+ this.debugToolStripMenuItem1.Size = new System.Drawing.Size(240, 34);
+ this.debugToolStripMenuItem1.Text = "Debug";
+ this.debugToolStripMenuItem1.Click += new System.EventHandler(this.debugToolStripMenuItem1_Click);
+ //
// FrmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F);
@@ -1028,6 +1046,8 @@
private System.Windows.Forms.DataGridView actualSalesDataGridView;
private System.Windows.Forms.TabPage suppliersTabPage;
private System.Windows.Forms.DataGridView invoicesDataGridView;
+ private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem1;
}
}
diff --git a/AdvertsingProfitControl/FrmMain.cs b/AdvertsingProfitControl/FrmMain.cs
index 69f7afd..2fa1d80 100644
--- a/AdvertsingProfitControl/FrmMain.cs
+++ b/AdvertsingProfitControl/FrmMain.cs
@@ -1224,6 +1224,12 @@ namespace AdvertsingProfitControl
perfectGrossProfitLabel.Text = @"Percent Gross Profit: ";
grossProfitEstimatedWeeklyDeptmartmentExpenseLabel.Text = @"Estimated Weekly Department Expense: ";
}
+
+ private void debugToolStripMenuItem1_Click(object sender, EventArgs e)
+ {
+ var form = new DebugDatabaseConverter();
+ form.ShowDialog();
+ }
}
}
//http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children
diff --git a/AdvertsingProfitControl/NewAddRecord.cs b/AdvertsingProfitControl/NewAddRecord.cs
index 2a776e9..98880cd 100644
--- a/AdvertsingProfitControl/NewAddRecord.cs
+++ b/AdvertsingProfitControl/NewAddRecord.cs
@@ -685,12 +685,11 @@ namespace AdvertsingProfitControl
e.Cancel = true; //Prevent the new row from being removed.
return;
}
- else
- {
- e.Cancel = true;
- }
+ e.Cancel = true;
}
//Mark all rows under the row that just got deleted as dirty.
+ if (dataGridView.Rows.Count != inventoryDataGridView.Rows.Count ||
+ dataGridView.Rows.Count != actualSalesDataGridView.Rows.Count) return;
for (var index = currentRowIndex; currentRowIndex < dataGridView.Rows.Count; index++)
{
projectionsDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true;
@@ -1748,6 +1747,10 @@ namespace AdvertsingProfitControl
{
column.Visible = false;
}
+ if (name == "AdItem")
+ {
+ column.MaxInputLength = 64;
+ }
projectionsDataGridView.Columns.Add(column);
}
else
@@ -1780,6 +1783,10 @@ namespace AdvertsingProfitControl
{
column.Visible = false;
}
+ if (name == "AdItem")
+ {
+ column.MaxInputLength = 64;
+ }
inventoryDataGridView.Columns.Add(column);
}
else
@@ -1812,6 +1819,10 @@ namespace AdvertsingProfitControl
{
column.Visible = false;
}
+ if (name == "AdItem")
+ {
+ column.MaxInputLength = 64;
+ }
actualSalesDataGridView.Columns.Add(column);
}
else
@@ -1852,6 +1863,10 @@ namespace AdvertsingProfitControl
{
column.Visible = false;
}
+ if (name == "Supplier")
+ {
+ column.MaxInputLength = 64;
+ }
invoicesDataGridView.Columns.Add(column);
}
else
diff --git a/AdvertsingProfitControl/NewModifyRecord.cs b/AdvertsingProfitControl/NewModifyRecord.cs
index dbbab17..10150c6 100644
--- a/AdvertsingProfitControl/NewModifyRecord.cs
+++ b/AdvertsingProfitControl/NewModifyRecord.cs
@@ -721,21 +721,18 @@ namespace AdvertsingProfitControl
e.Cancel = true; //Prevent the new row from being removed.
return;
}
- else
- {
- e.Cancel = true;
- }
+ e.Cancel = true;
}
//Mark all rows under the row that just got deleted as dirty.
- for (var index = currentRowIndex; index < dataGridView.Rows.Count; index++)
+ if (dataGridView.Rows.Count != inventoryDataGridView.Rows.Count ||
+ dataGridView.Rows.Count != actualSalesDataGridView.Rows.Count) return;
+ for (var index = currentRowIndex; currentRowIndex < dataGridView.Rows.Count; index++)
{
- if (index == _adSpecialIndex + 1) continue;
- if (projectionsDataGridView.Rows[index].IsNewRow) continue;
- projectionsDataGridView.Rows[index].Cells[(int) SalesTableColumns.IsDirty].Value = true;
+ projectionsDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true;
projectionsDataGridView.Rows[index].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
- inventoryDataGridView.Rows[index].Cells[(int) InventoryTableColumns.IsDirty].Value = true;
+ inventoryDataGridView.Rows[index].Cells[(int)InventoryTableColumns.IsDirty].Value = true;
inventoryDataGridView.Rows[index].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
- actualSalesDataGridView.Rows[index].Cells[(int) SalesTableColumns.IsDirty].Value = true;
+ actualSalesDataGridView.Rows[index].Cells[(int)SalesTableColumns.IsDirty].Value = true;
actualSalesDataGridView.Rows[index].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
}
}
@@ -1781,6 +1778,10 @@ namespace AdvertsingProfitControl
{
column.Visible = false;
}
+ if (name == "AdItem")
+ {
+ column.MaxInputLength = 64;
+ }
projectionsDataGridView.Columns.Add(column);
}
else
@@ -1813,6 +1814,10 @@ namespace AdvertsingProfitControl
{
column.Visible = false;
}
+ if (name == "AdItem")
+ {
+ column.MaxInputLength = 64;
+ }
inventoryDataGridView.Columns.Add(column);
}
else
@@ -1845,6 +1850,10 @@ namespace AdvertsingProfitControl
{
column.Visible = false;
}
+ if (name == "AdItem")
+ {
+ column.MaxInputLength = 64;
+ }
actualSalesDataGridView.Columns.Add(column);
}
else
@@ -1883,7 +1892,11 @@ namespace AdvertsingProfitControl
};
if (name.Contains("ID"))
{
- //column.Visible = false;
+ column.Visible = false;
+ }
+ if (name == "Supplier")
+ {
+ column.MaxInputLength = 64;
}
invoicesDataGridView.Columns.Add(column);
}
@@ -1893,7 +1906,7 @@ namespace AdvertsingProfitControl
{
Name = name,
ValueType = typeof(bool),
- //Visible = false,
+ Visible = false,
SortMode = DataGridViewColumnSortMode.NotSortable
};
invoicesDataGridView.Columns.Add(column);
@@ -2405,7 +2418,7 @@ namespace AdvertsingProfitControl
errorLabel.Text = @"Failed to get the date ID number, aborting load operation." + Environment.NewLine;
return;
}
- informationLabel.Text = @"Loading data for " + _currentActiveDate.ToString("d") + "." + Environment.NewLine;
+ informationLabel.Text = @"Loading data for " + _currentActiveDate.ToString("d") + @"." + Environment.NewLine;
var projections = databaseReader.ReturnProjectionsTable(dateId, databaseTracker.DatabaseConnectionString);
var inventory = databaseReader.ReturnInventoryTable(dateId, databaseTracker.DatabaseConnectionString);
var actualSales = databaseReader.ReturnActualSales(dateId, databaseTracker.DatabaseConnectionString);
diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
index 9ca45df..f3048b8 100644
--- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
+++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.application
@@ -14,7 +14,7 @@
- 4D9q8qCwiqDGT3of5bXJu3aFzAW8154WMEsO9/5DONI=
+ ZmIrPQhvIF7GlBAJN0yBg3h1MuQtzkOJb1/UsrzEMy4=
diff --git a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
index 90eb453..b96c020 100644
--- a/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
+++ b/AdvertsingProfitControl/bin/Debug/AdvertsingProfitControl.vshost.exe.manifest
@@ -43,14 +43,14 @@
-
+
- IDxVw5Mjas8mXXn3h6ET9uRIbyaYf3MJ7XGeYh9OL1Y=
+ SWhDdqr4Cdz7+qIONWqHGBLDH1kQ6iFOt1ruAj6rHJo=
@@ -93,7 +93,7 @@
- nsG4CuZailUF1ECpDsxZlFsXSEJmyBXTAvuId+rQuQ8=
+ nhqBAxGBZPH2N33Fm5tbmCgDtejNQUBm/H3EHe0p9bg=