Added a temporary form to convert the old database format. Updated the row parsing engine to handle ad special rows more effectively. Fixed a few bugs with the parsing engine not flagging member rows as dirty. Upped the character limit of the ad item and supplier columns.

This commit is contained in:
2017-01-22 20:46:07 -06:00
parent ac16bbc05c
commit 9f045175ed
13 changed files with 872 additions and 24 deletions
Binary file not shown.
@@ -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;
}
}
}
}
@@ -109,6 +109,12 @@
<Compile Include="ApplicationColors.cs" />
<Compile Include="DbTableWriterStatus.cs" />
<Compile Include="DbWriterStatus.cs" />
<Compile Include="DebugDatabaseConverter.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="DebugDatabaseConverter.Designer.cs">
<DependentUpon>DebugDatabaseConverter.cs</DependentUpon>
</Compile>
<Compile Include="Holiday.cs" />
<Compile Include="NewModifyRecord.cs">
<SubType>Form</SubType>
@@ -176,6 +182,9 @@
<Compile Include="RowParsing.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="DebugDatabaseConverter.resx">
<DependentUpon>DebugDatabaseConverter.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmAddRecord.resx">
<DependentUpon>FrmAddRecord.cs</DependentUpon>
</EmbeddedResource>
+27 -1
View File
@@ -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;
+105
View File
@@ -0,0 +1,105 @@
namespace AdvertsingProfitControl
{
partial class DebugDatabaseConverter
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}
@@ -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<DateTime>();
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;
}
}
}
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
+21 -1
View File
@@ -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;
}
}
+6
View File
@@ -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
+18 -3
View File
@@ -685,12 +685,11 @@ namespace AdvertsingProfitControl
e.Cancel = true; //Prevent the new row from being removed.
return;
}
else
{
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
+22 -9
View File
@@ -721,16 +721,13 @@ namespace AdvertsingProfitControl
e.Cancel = true; //Prevent the new row from being removed.
return;
}
else
{
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].HeaderCell.Style.BackColor = ApplicationColors.PendingEdit;
inventoryDataGridView.Rows[index].Cells[(int)InventoryTableColumns.IsDirty].Value = true;
@@ -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);
@@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>4D9q8qCwiqDGT3of5bXJu3aFzAW8154WMEsO9/5DONI=</dsig:DigestValue>
<dsig:DigestValue>ZmIrPQhvIF7GlBAJN0yBg3h1MuQtzkOJb1/UsrzEMy4=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
@@ -43,14 +43,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3626496">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="AdvertsingProfitControl.exe" size="3640832">
<assemblyIdentity name="AdvertsingProfitControl" version="0.9.5.2" language="neutral" processorArchitecture="amd64" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>IDxVw5Mjas8mXXn3h6ET9uRIbyaYf3MJ7XGeYh9OL1Y=</dsig:DigestValue>
<dsig:DigestValue>SWhDdqr4Cdz7+qIONWqHGBLDH1kQ6iFOt1ruAj6rHJo=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
@@ -93,7 +93,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>nsG4CuZailUF1ECpDsxZlFsXSEJmyBXTAvuId+rQuQ8=</dsig:DigestValue>
<dsig:DigestValue>nhqBAxGBZPH2N33Fm5tbmCgDtejNQUBm/H3EHe0p9bg=</dsig:DigestValue>
</hash>
</file>
<file name="APCTemplate.accdb" size="819200">