Added support for color coding the DataGridViews' header cells based on row state (saved, pending edit, row error) and finished writing the last database writer function for cost analysis.

This commit is contained in:
2016-12-04 01:27:25 -06:00
parent 6813bbb341
commit d8c753f788
11 changed files with 770 additions and 562 deletions
+120 -17
View File
@@ -532,21 +532,15 @@ namespace AdvertsingProfitControl
{
Connection = oleDbConnection
};
OleDbTransaction oleDbTransaction = null;
try
{
oleDbConnection.Open();
oleDbTransaction = oleDbConnection.BeginTransaction();
oleDbCommand.Transaction = oleDbTransaction;
if (id == 0)
{
oleDbCommand.CommandText = "INSERT INTO Comment (Comment, FK_DateID) VALUES (?, ?)";
oleDbCommand.Parameters.AddWithValue("Comment", comments);
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
oleDbCommand.ExecuteNonQuery();
//If the execute non query didn't throw an exception then we're good to go.
oleDbTransaction.Commit();
//Now grab the ID number of the comment that was just added.
oleDbCommand.CommandText = "SELECT ID FROM Comment WHERE FK_DateID = ?";
oleDbCommand.Parameters.Clear();
@@ -564,8 +558,6 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("Comment", comments);
oleDbCommand.Parameters.AddWithValue("ID", id);
oleDbCommand.ExecuteNonQuery();
//If the execute non query didn't throw an exception then we're good to go.
oleDbTransaction.Commit();
}
}
catch (OleDbException e)
@@ -573,7 +565,6 @@ namespace AdvertsingProfitControl
status.SetStatus(WritingOperationStatus.Failed);
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the comment(s): " + e.Message);
status.SetErrorMessage("Failed to update or insert comments into the database.");
oleDbTransaction?.Rollback();
}
finally
{
@@ -590,12 +581,9 @@ namespace AdvertsingProfitControl
{
Connection = oleDbConnection
};
OleDbTransaction oleDbTransaction = null;
try
{
oleDbConnection.Open();
oleDbTransaction = oleDbConnection.BeginTransaction();
oleDbCommand.Transaction = oleDbTransaction;
if (id == 0)
{
@@ -610,8 +598,6 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("TotalSales", weeklySales[7]);
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
oleDbCommand.ExecuteNonQuery();
//If the execute non query didn't throw an exception then we're good to go.
oleDbTransaction.Commit();
//Now grab the ID number of the comment that was just added.
oleDbCommand.CommandText = "SELECT ID FROM WeeklySales WHERE FK_DateID = ?";
oleDbCommand.Parameters.Clear();
@@ -636,8 +622,6 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("TotalSales", weeklySales[7]);
oleDbCommand.Parameters.AddWithValue("ID", id);
oleDbCommand.ExecuteNonQuery();
//If the execute non query didn't throw an exception then we're good to go.
oleDbTransaction.Commit();
}
}
catch (OleDbException e)
@@ -645,7 +629,126 @@ namespace AdvertsingProfitControl
status.SetStatus(WritingOperationStatus.Failed);
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the weekly sales: " + e.Message);
status.SetErrorMessage("Failed to update or insert weekly sales into the database.");
oleDbTransaction?.Rollback();
}
finally
{
oleDbConnection.Close();
}
return status;
}
public DbWriterStatus ProcessTaxable(double[] taxable, int dateId, string connectionString, int id = 0)
{
var status = new DbWriterStatus();
var oleDbConnection = new OleDbConnection(connectionString);
var oleDbCommand = new OleDbCommand
{
Connection = oleDbConnection
};
try
{
oleDbConnection.Open();
if (id == 0)
{
oleDbCommand.CommandText = "INSERT INTO Taxable (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Total, FK_DateID) VALUES (?,?,?,?,?,?,?,?,?)";
oleDbCommand.Parameters.AddWithValue("Sunday", taxable[0]);
oleDbCommand.Parameters.AddWithValue("Monday", taxable[1]);
oleDbCommand.Parameters.AddWithValue("Tuesday", taxable[2]);
oleDbCommand.Parameters.AddWithValue("Wednesday", taxable[3]);
oleDbCommand.Parameters.AddWithValue("Thursday", taxable[4]);
oleDbCommand.Parameters.AddWithValue("Friday", taxable[5]);
oleDbCommand.Parameters.AddWithValue("Saturday", taxable[6]);
oleDbCommand.Parameters.AddWithValue("TotalSales", taxable[7]);
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
oleDbCommand.ExecuteNonQuery();
//Now grab the ID number of the comment that was just added.
oleDbCommand.CommandText = "SELECT ID FROM Taxable WHERE FK_DateID = ?";
oleDbCommand.Parameters.Clear();
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
//Now read the ID number and add it to the collection with a default key.
var reader = oleDbCommand.ExecuteReader();
while (reader != null && reader.Read())
{
status.AddRowId(0, int.Parse(reader[0].ToString()));
}
}
else
{
oleDbCommand.CommandText = "UPDATE Taxable SET Sunday = ?, Monday = ?, Tuesday = ?, Wednesday = ?, Thursday = ?, Friday = ?, Saturday = ?, Total = ? WHERE ID = ?";
oleDbCommand.Parameters.AddWithValue("Sunday", taxable[0]);
oleDbCommand.Parameters.AddWithValue("Monday", taxable[1]);
oleDbCommand.Parameters.AddWithValue("Tuesday", taxable[2]);
oleDbCommand.Parameters.AddWithValue("Wednesday", taxable[3]);
oleDbCommand.Parameters.AddWithValue("Thursday", taxable[4]);
oleDbCommand.Parameters.AddWithValue("Friday", taxable[5]);
oleDbCommand.Parameters.AddWithValue("Saturday", taxable[6]);
oleDbCommand.Parameters.AddWithValue("TotalSales", taxable[7]);
oleDbCommand.Parameters.AddWithValue("ID", id);
oleDbCommand.ExecuteNonQuery();
}
}
catch (OleDbException e)
{
status.SetStatus(WritingOperationStatus.Failed);
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the taxable: " + e.Message);
status.SetErrorMessage("Failed to update or insert taxable into the database.");
}
finally
{
oleDbConnection.Close();
}
return status;
}
public DbWriterStatus ProcessCostAnalysis(double[] costAnalysis, int dateId, string connectionString, int id = 0)
{
var status = new DbWriterStatus();
var oleDbConnection = new OleDbConnection(connectionString);
var oleDbCommand = new OleDbCommand
{
Connection = oleDbConnection
};
try
{
oleDbConnection.Open();
if (id == 0)
{
oleDbCommand.CommandText = "INSERT INTO CostOfSalesAnalysis (SalesPerManHour, SalaryPercentage, SalaryDollars, Supplies, FK_dateID) VALUES (?,?,?,?,?)";
oleDbCommand.Parameters.AddWithValue("SalesPerManHour", costAnalysis[0]);
oleDbCommand.Parameters.AddWithValue("SalaryPercentage", costAnalysis[1]);
oleDbCommand.Parameters.AddWithValue("SalaryDollars", costAnalysis[2]);
oleDbCommand.Parameters.AddWithValue("Supplies", costAnalysis[3]);
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
oleDbCommand.ExecuteNonQuery();
//Now grab the ID number of the comment that was just added.
oleDbCommand.CommandText = "SELECT ID FROM Taxable WHERE FK_DateID = ?";
oleDbCommand.Parameters.Clear();
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
//Now read the ID number and add it to the collection with a default key.
var reader = oleDbCommand.ExecuteReader();
while (reader != null && reader.Read())
{
status.AddRowId(0, int.Parse(reader[0].ToString()));
}
}
else
{
oleDbCommand.CommandText = "UPDATE CostOfSalesAnalysis SET SalesPerManHour = ?, SalaryPercentage = ?, SalaryDollars = ?, Supplies = ? WHERE ID = ?";
oleDbCommand.Parameters.AddWithValue("SalesPerManHour", costAnalysis[0]);
oleDbCommand.Parameters.AddWithValue("SalaryPercentage", costAnalysis[1]);
oleDbCommand.Parameters.AddWithValue("SalaryDollars", costAnalysis[2]);
oleDbCommand.Parameters.AddWithValue("Supplies", costAnalysis[3]);
oleDbCommand.Parameters.AddWithValue("ID", id);
oleDbCommand.ExecuteNonQuery();
}
}
catch (OleDbException e)
{
status.SetStatus(WritingOperationStatus.Failed);
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to process the taxable: " + e.Message);
status.SetErrorMessage("Failed to update or insert taxable into the database.");
}
finally
{