Marked as 'AdvertsingProfitControl 0.9.5.2' by its folder. I believe this version is where most of the main interface for the user was complete and I was toying with the idea of allowing the user to change the shrink on the main form.

This commit is contained in:
2021-01-28 20:03:54 -06:00
parent 676a9dd890
commit 687e37da94
21 changed files with 2755 additions and 292 deletions
Binary file not shown.
@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -9,5 +10,8 @@ namespace AdvertsingProfitControl
internal class ApcDatabaseWriter internal class ApcDatabaseWriter
{ {
private readonly FrmLogConsole _logConsole = FrmLogConsole.GetStaticInstance; private readonly FrmLogConsole _logConsole = FrmLogConsole.GetStaticInstance;
private OleDbConnection oleDbConnection;
} }
} }
@@ -104,6 +104,8 @@
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AdItemCollectionModel.cs" />
<Compile Include="AdvertisingProfitControlTableHelper.cs" />
<Compile Include="TextFormat.cs" /> <Compile Include="TextFormat.cs" />
<Compile Include="APCDatabaseWriter.cs" /> <Compile Include="APCDatabaseWriter.cs" />
<Compile Include="BackPageGenerator.cs" /> <Compile Include="BackPageGenerator.cs" />
+62 -5
View File
@@ -250,6 +250,63 @@ namespace AdvertsingProfitControl
#region Ad Item Functions #region Ad Item Functions
public Dictionary<int, string> GetAdItemsSuggestionDictionary(string connectionString)
{
var adItemDictionary = new Dictionary<int, string>();
var oleDbCommand = new OleDbCommand()
{
CommandText = "SELECT AdItem.ID, AdItem.AdItem FROM AdItem ORDER BY AdItem.AdItem ASC"
};
var connection = new OleDbConnection(connectionString);
oleDbCommand.Connection = connection;
using (connection)
{
using (oleDbCommand)
{
connection.Open();
using (var reader = oleDbCommand.ExecuteReader())
{
while (reader != null && reader.Read())
{
adItemDictionary.Add(int.Parse(reader["ID"].ToString()), reader["AdItem"].ToString());
}
}
}
}
return adItemDictionary;
}
public int GetLargestKeyValueForAdItems(string connectionString)
{
var id = -1;
var oleDbCommand = new OleDbCommand()
{
CommandText = "SELECT MAX(AdItem.ID) FROM AdItem"
};
var connection = new OleDbConnection(connectionString);
oleDbCommand.Connection = connection;
using (connection)
{
using (oleDbCommand)
{
connection.Open();
using (var reader = oleDbCommand.ExecuteReader())
{
while (reader != null && reader.Read())
{
int.TryParse(reader[0].ToString(), out id);
}
}
}
}
return id;
}
public string RetrieveAdItemId(string adItemName, string connectionString) public string RetrieveAdItemId(string adItemName, string connectionString)
{ {
var id = "0"; var id = "0";
@@ -283,7 +340,7 @@ namespace AdvertsingProfitControl
var adItemList = new List<string>(); var adItemList = new List<string>();
var oleDbCommand = new OleDbCommand var oleDbCommand = new OleDbCommand
{ {
CommandText = "SELECT AdItem.AdItem, APC.RowAttribute, APC.FK_AdSpecialName FROM (APC INNER JOIN AdItem ON APC.FK_AdItemID = AdItem.ID) WHERE FK_DateID = ? ORDER BY RowPosition ASC" CommandText = "SELECT AdItem.AdItem, ActualSales.RowAttribute, ActualSales.FK_AdSpecialGroupName FROM (ActualSales INNER JOIN AdItem ON ActualSales.FK_AdItemID = AdItem.ID) WHERE FK_DateID = ? ORDER BY RowPosition ASC"
}; };
oleDbCommand.Parameters.AddWithValue("DateID", dateId); oleDbCommand.Parameters.AddWithValue("DateID", dateId);
var connection = new OleDbConnection(connectionString); var connection = new OleDbConnection(connectionString);
@@ -297,7 +354,7 @@ namespace AdvertsingProfitControl
{ {
while (reader != null && reader.Read()) while (reader != null && reader.Read())
{ {
if (reader["FK_AdSpecialName"].ToString() != "" && int.Parse(reader["FK_AdSpecialName"].ToString()) >= 3) if (reader["FK_AdSpecialGroupName"].ToString() != "" && int.Parse(reader["FK_AdSpecialGroupName"].ToString()) >= 3)
{ {
adItemList.Add(reader[0] + ":2"); adItemList.Add(reader[0] + ":2");
} }
@@ -620,7 +677,7 @@ namespace AdvertsingProfitControl
var dataTable = new DataTable(); var dataTable = new DataTable();
var oleDbCommand = new OleDbCommand() var oleDbCommand = new OleDbCommand()
{ {
CommandText = "SELECT AdItem.AdItem, APC.ProjectionSold, APC.ProjectionSalePrice, APC.ProjectionTotalSales, APC.ProjectionCost, APC.ProjectionProfitReturn, APC.ProjectionTotalProfitReturn, APC.GroupNumber, APC.FK_AdSpecialName FROM (AdItem INNER JOIN APC ON AdItem.ID = APC.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC" CommandText = "SELECT AdItem.AdItem, Projections.Sold, Projections.SalePrice, Projections.TotalSales, Projections.Cost, Projections.ProfitReturn, Projections.TotalProfitReturn, Projections.RowAttribute, Projections.FK_AdSpecialGroupName FROM (AdItem INNER JOIN Projections ON AdItem.ID = Projections.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC"
}; };
oleDbCommand.Parameters.AddWithValue("DateID", dateId); oleDbCommand.Parameters.AddWithValue("DateID", dateId);
var connection = new OleDbConnection(connectionString); var connection = new OleDbConnection(connectionString);
@@ -645,7 +702,7 @@ namespace AdvertsingProfitControl
var dataTable = new DataTable(); var dataTable = new DataTable();
var oleDbCommand = new OleDbCommand() var oleDbCommand = new OleDbCommand()
{ {
CommandText = "SELECT AdItem.AdItem, APC.ActualSold, APC.ActualSalePrice, APC.ActualTotalSales, APC.ActualCost, APC.ActualProfitReturn, APC.ActualTotalProfitReturn, APC.GroupNumber, APC.FK_AdSpecialName FROM (AdItem INNER JOIN APC ON AdItem.ID = APC.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC" CommandText = "SELECT AdItem.AdItem, ActualSales.Sold, ActualSales.SalePrice, ActualSales.TotalSales, ActualSales.Cost, ActualSales.ProfitReturn, ActualSales.TotalProfitReturn, ActualSales.RowAttribute, ActualSales.FK_AdSpecialGroupName FROM (AdItem INNER JOIN ActualSales ON AdItem.ID = ActualSales.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC"
}; };
oleDbCommand.Parameters.AddWithValue("DateID", dateId); oleDbCommand.Parameters.AddWithValue("DateID", dateId);
var connection = new OleDbConnection(connectionString); var connection = new OleDbConnection(connectionString);
@@ -670,7 +727,7 @@ namespace AdvertsingProfitControl
var dataTable = new DataTable(); var dataTable = new DataTable();
var oleDbCommand = new OleDbCommand() var oleDbCommand = new OleDbCommand()
{ {
CommandText = "SELECT AdItem.AdItem, APC.BeginingInventory, APC.Received, APC.TotalInventory, APC.EndingInventory, APC.GroupNumber, APC.FK_AdSpecialName FROM (AdItem INNER JOIN APC ON AdItem.ID = APC.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC" CommandText = "SELECT AdItem.AdItem, Inventory.BeginningInventory, Inventory.Received, Inventory.TotalInventory, Inventory.EndingInventory, Inventory.RowAttribute, Inventory.FK_AdSpecialGroupName FROM (AdItem INNER JOIN Inventory ON AdItem.ID = Inventory.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC"
}; };
oleDbCommand.Parameters.AddWithValue("DateID", dateId); oleDbCommand.Parameters.AddWithValue("DateID", dateId);
var connection = new OleDbConnection(connectionString); var connection = new OleDbConnection(connectionString);
+375 -69
View File
@@ -1,18 +1,321 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Data.OleDb; using System.Data.OleDb;
using System.Transactions;
using System.Windows.Forms;
namespace AdvertsingProfitControl namespace AdvertsingProfitControl
{ {
class DatabaseWriter internal class DatabaseWriter
{ {
private readonly OleDbConnection _connectionobject = new OleDbConnection(); private readonly OleDbConnection _oleDbConnection = new OleDbConnection();
private readonly FrmLogConsole _logConsole = FrmLogConsole.GetStaticInstance; private readonly FrmLogConsole _logConsole = FrmLogConsole.GetStaticInstance;
public DatabaseWriter(string connectionString) public DatabaseWriter(string connectionString)
{ {
_connectionobject.ConnectionString = connectionString; _oleDbConnection.ConnectionString = connectionString;
} }
#region New Code
/// <summary>
/// Inserts new records into the specified sales table.
/// Supports rolling back the database to prevent corruption.
/// </summary>
/// <param name="salesTable">The data table that contains the data to be inserted.</param>
/// <param name="connectionString"></param>
/// <returns></returns>
public Dictionary<int, int> InsertIntoSalesTable(DataTable salesTable, string connectionString)
{
var rowIndex = 0;
var rows = new Dictionary<int, int>();
var oleDbConnection = new OleDbConnection(connectionString);
//IDs from the database can not be zero (0), so this will be the default value (no group).
var oleDbCommand = new OleDbCommand
{
Connection = oleDbConnection
};
OleDbTransaction oleDbTransaction = null;
try
{
oleDbConnection.Open();
oleDbTransaction = oleDbConnection.BeginTransaction();
oleDbCommand.Transaction = oleDbTransaction;
for (var i = 0; i < salesTable.Rows.Count; i++)
{
oleDbCommand.CommandText =
"INSERT INTO " + salesTable.TableName + " (Sold, SalePrice, TotalSales, Cost, ProfitReturn, TotalProfitReturn, FK_AdItemID, RowAttribute, FK_AdSpecialGroupName, RowPosition, FK_DateID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
//New Sales Table Layout (Based on the Database's Physical Layout)
//0: Sold 1:SalePrice 2:TotalSales 3:cost 4:ProfitReturn 5:TotalProfitReturn
//6:FK_AdItemID 7:RowAttribute 8:FK_AdSpecialGroupName (ID) 9:RowPosition (not index based)
//10:FK_DateID
oleDbCommand.Parameters.AddWithValue("Sold", salesTable.Rows[i][0]);
oleDbCommand.Parameters.AddWithValue("SalesPrice", salesTable.Rows[i][1]);
oleDbCommand.Parameters.AddWithValue("TotalSales", salesTable.Rows[i][2]);
oleDbCommand.Parameters.AddWithValue("Cost", salesTable.Rows[i][3]);
oleDbCommand.Parameters.AddWithValue("ProfitReturn", salesTable.Rows[i][4]);
oleDbCommand.Parameters.AddWithValue("TotalProfitReturn", salesTable.Rows[i][5]);
oleDbCommand.Parameters.AddWithValue("adItemID", int.Parse(salesTable.Rows[i][6].ToString()));
oleDbCommand.Parameters.AddWithValue("RowAttribute", int.Parse(salesTable.Rows[i][7].ToString()));
oleDbCommand.Parameters.AddWithValue("adSpecialID", int.Parse(salesTable.Rows[i][8].ToString()));
oleDbCommand.Parameters.AddWithValue("RowPosition", int.Parse(salesTable.Rows[i][9].ToString()));
oleDbCommand.Parameters.AddWithValue("dateID", salesTable.Rows[i][10]);
oleDbCommand.ExecuteNonQuery();
oleDbCommand.Parameters.Clear();
rowIndex++;
}
oleDbTransaction.Commit();
foreach (DataRow row in salesTable.Rows)
{
var rowId = RetrieveRowId(salesTable.TableName, int.Parse(row[6].ToString()), int.Parse(row[10].ToString()));
if (int.Parse(row[8].ToString()) != 0)
{
//Account for the ad special row.
rows.Add(int.Parse(row[9].ToString()) + 1, rowId);
}
else
{
rows.Add(int.Parse(row[9].ToString()), rowId);
}
}
}
catch (OleDbException ex)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to write to database: " + ex.Message);
if (rowIndex <= 0)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Failed to begin parsing data rows, var dump of erroneous row unavailable.");
}
else
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Failed on row " + (rowIndex + 1) + " due to the above error. Dumping contents of row " + (rowIndex + 1) + " from " + salesTable.TableName + ".");
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Ad Item ID: \"" +
salesTable.Rows[rowIndex][6] + "\" Sold: \"" + salesTable.Rows[rowIndex][0] + "\"");
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Sale Price: \"" + salesTable.Rows[rowIndex][1] + "\" Total Sales: \"" + salesTable.Rows[rowIndex][2] + "\"");
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Cost: \"" + salesTable.Rows[rowIndex][3] + "\" Profit Return: \"" + salesTable.Rows[rowIndex][4] + "\"");
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Total Profit Return: \"" +
salesTable.Rows[rowIndex][5] + "\" Ad Special Group: \"" + salesTable.Rows[rowIndex][8] + "\"");
}
oleDbTransaction?.Rollback();
_logConsole.WriteToLog(FrmLogConsole.Level.Critical, "Rollback completed successfully, " + salesTable.TableName+ " table failed on insertion.");
}
finally
{
_oleDbConnection.Close();
}
return rows;
}
public bool UpdateSalesTable(DataTable salesTable, string connectionString)
{
var wasSuccessful = false;
var rowIndex = 0;
var oleDbConnection = new OleDbConnection(connectionString);
//IDs from the database can not be zero (0), so this will be the default value (no group).
var oleDbCommand = new OleDbCommand
{
Connection = oleDbConnection
};
OleDbTransaction oleDbTransaction = null;
try
{
oleDbTransaction = oleDbConnection.BeginTransaction();
_oleDbConnection.Open();
oleDbCommand.Transaction = oleDbTransaction;
for (var i = 0; i < salesTable.Rows.Count; i++)
{
oleDbCommand.CommandText =
"UPDATE " + salesTable.TableName + " SET Sold = ?, SalePrice = ?, TotalSales = ?, Cost = ?, ProfitReturn = ?, TotalProfitReturn = ?, RowAttribute = ?, FK_AdSpecialGroupName = ?, RowPosition = ? WHERE ID = ?";
//Update Sales Table Layout (Based on the Database's Physical Layout)
//0:ID 1:Sold 2:SalePrice 3:TotalSales 4:cost 5:ProfitReturn 6:TotalProfitReturn
//7:FK_AdItemID 8:RowAttribute 9:FK_AdSpecialGroupName (ID) 10:RowPosition (not index based)
//11:FK_DateID
oleDbCommand.Parameters.AddWithValue("Sold", salesTable.Rows[i][1]);
oleDbCommand.Parameters.AddWithValue("SalesPrice", salesTable.Rows[i][2]);
oleDbCommand.Parameters.AddWithValue("TotalSales", salesTable.Rows[i][3]);
oleDbCommand.Parameters.AddWithValue("Cost", salesTable.Rows[i][4]);
oleDbCommand.Parameters.AddWithValue("ProfitReturn", salesTable.Rows[i][5]);
oleDbCommand.Parameters.AddWithValue("TotalProfitReturn", salesTable.Rows[i][6]);
oleDbCommand.Parameters.AddWithValue("RowAttribute", salesTable.Rows[i][8]);
oleDbCommand.Parameters.AddWithValue("adSpecialID", salesTable.Rows[i][9]);
oleDbCommand.Parameters.AddWithValue("RowPosition", salesTable.Rows[i][10]);
oleDbCommand.Parameters.AddWithValue("ID", salesTable.Rows[i][0]);
oleDbCommand.ExecuteNonQuery();
oleDbCommand.Parameters.Clear();
rowIndex++;
}
oleDbTransaction.Commit();
wasSuccessful = true;
}
catch (OleDbException ex)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to update the database for " + salesTable.TableName + ": " + ex.Message);
if (rowIndex <= 0)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Failed to begin parsing data rows, var dump of erroneous row unavailable.");
}
else
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Failed on row " + (rowIndex + 1) + " due to the above error. Dumping contents of row " + (rowIndex + 1) + " from " + salesTable.TableName + ".");
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Ad Item ID: \"" +
salesTable.Rows[rowIndex][7] + "\" Sold: \"" + salesTable.Rows[rowIndex][1] + "\"");
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Sale Price: \"" + salesTable.Rows[rowIndex][2] + "\" Total Sales: \"" + salesTable.Rows[rowIndex][3] + "\"");
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Cost: \"" + salesTable.Rows[rowIndex][4] + "\" Profit Return: \"" + salesTable.Rows[rowIndex][5] + "\"");
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Total Profit Return: \"" +
salesTable.Rows[rowIndex][6] + "\" Ad Special Group: \"" + salesTable.Rows[rowIndex][9] + "\"");
}
oleDbTransaction?.Rollback();
_logConsole.WriteToLog(FrmLogConsole.Level.Critical, "Rollback completed successfully, " + salesTable.TableName + " table failed on update.");
}
finally
{
_oleDbConnection.Close();
}
return wasSuccessful;
}
/// <summary>
/// Inserts a new ad item into the database and returns the new item's ID number.
/// Supports rolling back as to not corrupt the database.
/// </summary>
/// <param name="adItemName">The ad item's name that is to be added.</param>
/// <param name="oleDbCommand">A reference to a command that already has a transaction active.</param>
/// <returns>The ID number of the ad item that was just added.</returns>
public int InsertNewAdItem(string adItemName, OleDbCommand oleDbCommand = null)
{
var adItemId = 0;
var needsTransaction = false;
if (oleDbCommand == null)
{
oleDbCommand = new OleDbCommand
{
Connection = _oleDbConnection
};
needsTransaction = true;
}
oleDbCommand.CommandText = "INSERT INTO AdItem (AdItem) VALUES (?)";
oleDbCommand.Parameters.Clear();
oleDbCommand.Parameters.AddWithValue("AdItem", adItemName);
OleDbTransaction oleDbTransaction = null;
try
{
if (needsTransaction)
{
//If the OleDbCommand object is not supplied, then we'll need to create and assign the transaction object.
oleDbCommand.Connection = _oleDbConnection;
_oleDbConnection.Open();
oleDbTransaction = _oleDbConnection.BeginTransaction();
oleDbCommand.Transaction = oleDbTransaction;
}
if (oleDbCommand.ExecuteNonQuery() == 1)
{
oleDbCommand.CommandText = "SELECT ID FROM AdItem WHERE AdItem.AdItem = ?";
oleDbCommand.Parameters.Clear();
oleDbCommand.Parameters.AddWithValue("AdItem", adItemName);
var reader = oleDbCommand.ExecuteReader();
//Get the ID of the new ad item.
while (reader != null && reader.Read())
{
int.TryParse(reader[0].ToString(), out adItemId);
}
reader?.Close();
if (adItemId != 0)
{
//All was successful.
oleDbTransaction?.Commit();
}
else
{
//
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Ad item \"" + adItemName + "\" was not found in the database; rolling back changes.");
oleDbTransaction?.Rollback();
}
}
else
{
//Something failed but wasn't caught.
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Failed to add the ad item \"" + adItemName + "\" into the database.");
oleDbTransaction?.Rollback();
}
}
catch (OleDbException e)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Failed to insert ad item " + adItemName + " into the database.");
oleDbTransaction?.Rollback();
}
finally
{
if (needsTransaction)
{
_oleDbConnection.Close();
}
}
return adItemId;
}
/// <summary>
/// Infrastructure for the DatabaseWriter class, not meant to be used with external code.
/// Grabs the ID of the specified row.
/// </summary>
/// <param name="tableName">The name of the table to check for the row in.</param>
/// <param name="adItemId">The ID of the ad item in the row.</param>
/// <param name="dateId">The ID of the date in the row.</param>
/// <returns>The ID of the row, zero(0) if no rows are found.</returns>
private int RetrieveRowId(string tableName, int adItemId, int dateId)
{
var id = 0;
var rowsEffected = 0;
var oleDbCommand = new OleDbCommand
{
CommandText = "SELECT ID FROM " + tableName + " WHERE FK_AdItemID = ? AND FK_DateID = ?",
Connection = _oleDbConnection
};
oleDbCommand.Parameters.AddWithValue("AdItemID", adItemId);
oleDbCommand.Parameters.AddWithValue("DateID", dateId);
try
{
_oleDbConnection.Open();
var reader = oleDbCommand.ExecuteReader();
while (reader != null && reader.Read())
{
rowsEffected++;
int.TryParse(reader[0].ToString(), out id);
}
reader?.Close();
if (rowsEffected > 1)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error,
"Redundancy found row with the ad item ID " + adItemId + " with the date ID " + dateId + ".");
}
}
catch (OleDbException e)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to look up the existence of a row with the ad item ID " + adItemId + " with the date ID " + dateId + ".");
_logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
}
_oleDbConnection.Close();
return id;
}
#endregion
//10 to 1 ratio of tries to code //10 to 1 ratio of tries to code
//http://codebetter.com/karlseguin/2006/04/05/understanding-and-using-exceptions/nfrastructure //http://codebetter.com/karlseguin/2006/04/05/understanding-and-using-exceptions/nfrastructure
@@ -27,7 +330,7 @@ namespace AdvertsingProfitControl
CommandText = "INSERT INTO WeekEnding(EndOfWeekDate) VALUES ( dateString )" CommandText = "INSERT INTO WeekEnding(EndOfWeekDate) VALUES ( dateString )"
}; };
oleDbCommand.Parameters.AddWithValue("dateString", dateString); oleDbCommand.Parameters.AddWithValue("dateString", dateString);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
//Try to execute the query //Try to execute the query
try try
{ {
@@ -35,8 +338,8 @@ namespace AdvertsingProfitControl
//Check for the existence of the date string that was provided. //Check for the existence of the date string that was provided.
oleDbCommand.CommandText = "SELECT ID FROM WeekEnding WHERE EndOfWeekDate = @dateString"; oleDbCommand.CommandText = "SELECT ID FROM WeekEnding WHERE EndOfWeekDate = @dateString";
oleDbCommand.Parameters.AddWithValue("@dateString", dateString); oleDbCommand.Parameters.AddWithValue("@dateString", dateString);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
_connectionobject.Open(); _oleDbConnection.Open();
//Execute the SELECT statement and retrieve the row(s) effected. //Execute the SELECT statement and retrieve the row(s) effected.
var reader = oleDbCommand.ExecuteReader(); var reader = oleDbCommand.ExecuteReader();
var recordIndex = 0; var recordIndex = 0;
@@ -48,7 +351,7 @@ namespace AdvertsingProfitControl
} }
recordIndex++; recordIndex++;
} }
if (reader != null) reader.Close(); reader?.Close();
//IF one row was affected, then return with "True", since the value is already there. //IF one row was affected, then return with "True", since the value is already there.
if (numberOfRowsEffected == 1) if (numberOfRowsEffected == 1)
{ {
@@ -103,7 +406,7 @@ namespace AdvertsingProfitControl
finally finally
{ {
//Make certain that the connection is closed before returning. //Make certain that the connection is closed before returning.
_connectionobject.Close(); _oleDbConnection.Close();
} }
return insertWasSuccessful; return insertWasSuccessful;
@@ -115,7 +418,7 @@ namespace AdvertsingProfitControl
var insertWasSuccessful = false; var insertWasSuccessful = false;
var storedComment = ""; var storedComment = "";
//Set up the command object, SQL command string and parameters. //Set up the command object, SQL command string and parameters.
var oleDbCommand = new OleDbCommand {Connection = _connectionobject}; var oleDbCommand = new OleDbCommand {Connection = _oleDbConnection};
//Try to execute the query //Try to execute the query
try try
{ {
@@ -127,7 +430,7 @@ namespace AdvertsingProfitControl
oleDbCommand.CommandText = "SELECT Comment FROM Comment WHERE FK_DateID = dateID"; oleDbCommand.CommandText = "SELECT Comment FROM Comment WHERE FK_DateID = dateID";
oleDbCommand.Parameters.Clear(); oleDbCommand.Parameters.Clear();
oleDbCommand.Parameters.AddWithValue("dateID", dateIdString); oleDbCommand.Parameters.AddWithValue("dateID", dateIdString);
_connectionobject.Open(); _oleDbConnection.Open();
//OpenConnection(); //OpenConnection();
var reader = oleDbCommand.ExecuteReader(); var reader = oleDbCommand.ExecuteReader();
var recordIndex = 0; var recordIndex = 0;
@@ -146,7 +449,7 @@ namespace AdvertsingProfitControl
recordIndex++; recordIndex++;
} }
} }
if (reader != null) reader.Close(); reader?.Close();
//IF there is a comment that has the same date then check to see if it is the same as the one entered. //IF there is a comment that has the same date then check to see if it is the same as the one entered.
if (recordIndex == 1) if (recordIndex == 1)
{ {
@@ -235,7 +538,7 @@ namespace AdvertsingProfitControl
finally finally
{ {
//Make certain that the connection is closed before returning. //Make certain that the connection is closed before returning.
_connectionobject.Close(); _oleDbConnection.Close();
} }
return insertWasSuccessful; return insertWasSuccessful;
@@ -257,7 +560,7 @@ namespace AdvertsingProfitControl
var noRowsAdded = new List<int> {0}; var noRowsAdded = new List<int> {0};
return noRowsAdded; return noRowsAdded;
} }
_connectionobject.Open(); _oleDbConnection.Open();
var rowsAdded = new List<int>(); var rowsAdded = new List<int>();
var rowNumber = 0; var rowNumber = 0;
//DataTable's structure will reflect the APC database table structure. //DataTable's structure will reflect the APC database table structure.
@@ -309,7 +612,7 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("AdItemID", adItemId); oleDbCommand.Parameters.AddWithValue("AdItemID", adItemId);
oleDbCommand.Parameters.AddWithValue("GroupID", row[19]); oleDbCommand.Parameters.AddWithValue("GroupID", row[19]);
oleDbCommand.Parameters.AddWithValue("dateID", row[20]); oleDbCommand.Parameters.AddWithValue("dateID", row[20]);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
@@ -328,7 +631,7 @@ namespace AdvertsingProfitControl
{ {
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "An error occurred trying to write a record to the APC table."); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "An error occurred trying to write a record to the APC table.");
_logConsole.WriteToLog(FrmLogConsole.Level.Debug, e.Message); _logConsole.WriteToLog(FrmLogConsole.Level.Debug, e.Message);
_connectionobject.Close(); _oleDbConnection.Close();
//Add an error code at the end of array of rows that were added to show an error occurred. //Add an error code at the end of array of rows that were added to show an error occurred.
rowsAdded.Add(-1); rowsAdded.Add(-1);
return rowsAdded; return rowsAdded;
@@ -343,7 +646,7 @@ namespace AdvertsingProfitControl
rowsAdded.Add(0); rowsAdded.Add(0);
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "An error occurred trying to update a record APC table."); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "An error occurred trying to update a record APC table.");
_logConsole.WriteToLog(FrmLogConsole.Level.Debug, "An error occurred trying to update ad item ID " + adItemId + " and dateID " + dateId + "."); _logConsole.WriteToLog(FrmLogConsole.Level.Debug, "An error occurred trying to update ad item ID " + adItemId + " and dateID " + dateId + ".");
_connectionobject.Close(); _oleDbConnection.Close();
return rowsAdded; return rowsAdded;
} }
} }
@@ -351,7 +654,7 @@ namespace AdvertsingProfitControl
} }
//Close the database connection before returning. //Close the database connection before returning.
_connectionobject.Close(); _oleDbConnection.Close();
return rowsAdded; return rowsAdded;
} }
@@ -370,15 +673,16 @@ namespace AdvertsingProfitControl
oleDbCommand.CommandText = "SELECT ID FROM APC WHERE FK_AdItemID = adItemID AND FK_DateID = dateID"; oleDbCommand.CommandText = "SELECT ID FROM APC WHERE FK_AdItemID = adItemID AND FK_DateID = dateID";
oleDbCommand.Parameters.AddWithValue("adItemID", adItemId); oleDbCommand.Parameters.AddWithValue("adItemID", adItemId);
oleDbCommand.Parameters.AddWithValue("dateID", dateId); oleDbCommand.Parameters.AddWithValue("dateID", dateId);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
oleDbCommand.Transaction = _oleDbConnection.BeginTransaction();
var reader = oleDbCommand.ExecuteReader(); var reader = oleDbCommand.ExecuteReader();
while (reader != null && reader.Read()) while (reader != null && reader.Read())
{ {
rowsEffected++; rowsEffected++;
} }
if (reader != null) reader.Close(); reader?.Close();
} }
catch (OleDbException ex) catch (OleDbException ex)
{ {
@@ -424,10 +728,12 @@ namespace AdvertsingProfitControl
} }
//Record the number of rows affected when the statement is executed, again assume nothing was affected. //Record the number of rows affected when the statement is executed, again assume nothing was affected.
var adItemId = "0"; var adItemId = "0";
var oleDbCommand = new OleDbCommand(); var oleDbCommand = new OleDbCommand
oleDbCommand.CommandText = "INSERT INTO AdItem (AdItem) VALUES (?)"; {
CommandText = "INSERT INTO AdItem (AdItem) VALUES (?)",
Connection = _oleDbConnection
};
oleDbCommand.Parameters.AddWithValue("adItem", adItemName); oleDbCommand.Parameters.AddWithValue("adItem", adItemName);
oleDbCommand.Connection = _connectionobject;
//Attempt to execute the INSERT SQL statement. //Attempt to execute the INSERT SQL statement.
try try
{ {
@@ -443,7 +749,7 @@ namespace AdvertsingProfitControl
{ {
adItemId = reader[0].ToString(); adItemId = reader[0].ToString();
} }
if (reader != null) reader.Close(); reader?.Close();
} }
//ELSE IF more then one (1) row was affected... //ELSE IF more then one (1) row was affected...
else if (rowsEffected > 1) else if (rowsEffected > 1)
@@ -487,7 +793,7 @@ namespace AdvertsingProfitControl
} }
var oleDbCommand = new OleDbCommand {CommandText = "SELECT ID FROM AdItem WHERE UCASE(AdItem.AdItem) = UCASE(adItemName)"}; var oleDbCommand = new OleDbCommand {CommandText = "SELECT ID FROM AdItem WHERE UCASE(AdItem.AdItem) = UCASE(adItemName)"};
oleDbCommand.Parameters.AddWithValue("adItemName", adItemName); oleDbCommand.Parameters.AddWithValue("adItemName", adItemName);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
@@ -557,7 +863,7 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("groupID", parameters[19]); oleDbCommand.Parameters.AddWithValue("groupID", parameters[19]);
oleDbCommand.Parameters.AddWithValue("dateID", parameters[20]); oleDbCommand.Parameters.AddWithValue("dateID", parameters[20]);
oleDbCommand.Parameters.AddWithValue("adItemID", adItemId); oleDbCommand.Parameters.AddWithValue("adItemID", adItemId);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
@@ -597,22 +903,22 @@ namespace AdvertsingProfitControl
var supplierQueryCommand = new OleDbCommand var supplierQueryCommand = new OleDbCommand
{ {
CommandText = "SELECT ID FROM Supplier WHERE SupplierName = ?", CommandText = "SELECT ID FROM Supplier WHERE SupplierName = ?",
Connection = _connectionobject Connection = _oleDbConnection
}; };
//Grabbing the ID of the invoice by the invoice number and the supplier's ID. //Grabbing the ID of the invoice by the invoice number and the supplier's ID.
var invoiceCheckCommand = new OleDbCommand var invoiceCheckCommand = new OleDbCommand
{ {
CommandText = "SELECT ID FROM Invoice WHERE InvoiceNumber = ? AND FK_Supplier = ?", CommandText = "SELECT ID FROM Invoice WHERE InvoiceNumber = ? AND FK_Supplier = ?",
Connection = _connectionobject Connection = _oleDbConnection
}; };
//Inserting a new record into the Invoice table. //Inserting a new record into the Invoice table.
var insertNewInvoice = new OleDbCommand var insertNewInvoice = new OleDbCommand
{ {
CommandText = CommandText =
"INSERT INTO Invoice (InvoiceDate, InvoiceNumber, InvoiceNetAmountAtCost, InvoiceNetAmount, InvoiceNote, FK_Supplier, FK_DateID) VALUES (?, ?, ?, ?, ?, ?, ?)", "INSERT INTO Invoice (InvoiceDate, InvoiceNumber, InvoiceNetAmountAtCost, InvoiceNetAmount, InvoiceNote, FK_Supplier, FK_DateID) VALUES (?, ?, ?, ?, ?, ?, ?)",
Connection = _connectionobject Connection = _oleDbConnection
}; };
_connectionobject.Open(); _oleDbConnection.Open();
foreach (DataRow row in parameters.Rows) foreach (DataRow row in parameters.Rows)
{ {
var itemCount = 0; var itemCount = 0;
@@ -736,12 +1042,12 @@ namespace AdvertsingProfitControl
{ {
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to write supplier " + row[1] + " into the invoice table."); _logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to write supplier " + row[1] + " into the invoice table.");
_logConsole.WriteToLog(FrmLogConsole.Level.Debug, e.Message); _logConsole.WriteToLog(FrmLogConsole.Level.Debug, e.Message);
_connectionobject.Close(); _oleDbConnection.Close();
break; break;
} }
} }
_connectionobject.Close(); _oleDbConnection.Close();
return rowsAdded; return rowsAdded;
} }
/// <summary> /// <summary>
@@ -767,7 +1073,7 @@ namespace AdvertsingProfitControl
var supplierNameId = "0"; var supplierNameId = "0";
var oleDbCommand = new OleDbCommand {CommandText = "INSERT INTO Supplier (SupplierName) VALUES (?)"}; var oleDbCommand = new OleDbCommand {CommandText = "INSERT INTO Supplier (SupplierName) VALUES (?)"};
oleDbCommand.Parameters.AddWithValue("SupplierName", supplierName); oleDbCommand.Parameters.AddWithValue("SupplierName", supplierName);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
@@ -825,7 +1131,7 @@ namespace AdvertsingProfitControl
oleDbCommand.Parameters.AddWithValue("InvoiceNumber", invoiceField[2]); oleDbCommand.Parameters.AddWithValue("InvoiceNumber", invoiceField[2]);
oleDbCommand.Parameters.AddWithValue("SupplierID", supplierId); oleDbCommand.Parameters.AddWithValue("SupplierID", supplierId);
oleDbCommand.Parameters.AddWithValue("DateID", invoiceField[6]); oleDbCommand.Parameters.AddWithValue("DateID", invoiceField[6]);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
@@ -863,7 +1169,7 @@ namespace AdvertsingProfitControl
CommandText = "SELECT ID FROM WeeklySales WHERE FK_DateID = ?" CommandText = "SELECT ID FROM WeeklySales WHERE FK_DateID = ?"
}; };
weekEndingDateCheck.Parameters.AddWithValue("DateID", parameters[8]); weekEndingDateCheck.Parameters.AddWithValue("DateID", parameters[8]);
weekEndingDateCheck.Connection = _connectionobject; weekEndingDateCheck.Connection = _oleDbConnection;
//Object to update a field with the date supplied, assuming an entry was found with the previous object. //Object to update a field with the date supplied, assuming an entry was found with the previous object.
var updateWeeklySales = new OleDbCommand var updateWeeklySales = new OleDbCommand
{ {
@@ -879,7 +1185,7 @@ namespace AdvertsingProfitControl
updateWeeklySales.Parameters.AddWithValue("Saturday", parameters[6]); updateWeeklySales.Parameters.AddWithValue("Saturday", parameters[6]);
updateWeeklySales.Parameters.AddWithValue("TotalSales", parameters[7]); updateWeeklySales.Parameters.AddWithValue("TotalSales", parameters[7]);
updateWeeklySales.Parameters.AddWithValue("DateID", parameters[8]); updateWeeklySales.Parameters.AddWithValue("DateID", parameters[8]);
updateWeeklySales.Connection = _connectionobject; updateWeeklySales.Connection = _oleDbConnection;
//Object to insert a new field into the database if no entry is present. //Object to insert a new field into the database if no entry is present.
var insertWeeklySales = new OleDbCommand var insertWeeklySales = new OleDbCommand
{ {
@@ -895,10 +1201,10 @@ namespace AdvertsingProfitControl
insertWeeklySales.Parameters.AddWithValue("Saturday", parameters[6]); insertWeeklySales.Parameters.AddWithValue("Saturday", parameters[6]);
insertWeeklySales.Parameters.AddWithValue("TotalSales", parameters[7]); insertWeeklySales.Parameters.AddWithValue("TotalSales", parameters[7]);
insertWeeklySales.Parameters.AddWithValue("DateID", parameters[8]); insertWeeklySales.Parameters.AddWithValue("DateID", parameters[8]);
insertWeeklySales.Connection = _connectionobject; insertWeeklySales.Connection = _oleDbConnection;
try try
{ {
_connectionobject.Open(); _oleDbConnection.Open();
//Execute the select statement to check for the presence of an entry with the supplied date (parameters[8]). //Execute the select statement to check for the presence of an entry with the supplied date (parameters[8]).
var reader = weekEndingDateCheck.ExecuteReader(); var reader = weekEndingDateCheck.ExecuteReader();
@@ -931,7 +1237,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return rowsEffected; return rowsEffected;
@@ -947,18 +1253,18 @@ namespace AdvertsingProfitControl
CommandText = "SELECT ID FROM GroupCategory WHERE GroupDescription = ?" CommandText = "SELECT ID FROM GroupCategory WHERE GroupDescription = ?"
}; };
categoryDescCheckQueryCommand.Parameters.AddWithValue("GroupName", groupName); categoryDescCheckQueryCommand.Parameters.AddWithValue("GroupName", groupName);
categoryDescCheckQueryCommand.Connection = _connectionobject; categoryDescCheckQueryCommand.Connection = _oleDbConnection;
//Setting up an object to insert a new ad special keyword. //Setting up an object to insert a new ad special keyword.
var insertNewCategoryDesc = new OleDbCommand var insertNewCategoryDesc = new OleDbCommand
{ {
CommandText = "INSERT INTO GroupCategory (GroupDescription) VALUES (?)" CommandText = "INSERT INTO GroupCategory (GroupDescription) VALUES (?)"
}; };
insertNewCategoryDesc.Parameters.AddWithValue("GroupName", groupName); insertNewCategoryDesc.Parameters.AddWithValue("GroupName", groupName);
insertNewCategoryDesc.Connection = _connectionobject; insertNewCategoryDesc.Connection = _oleDbConnection;
try try
{ {
_connectionobject.Open(); _oleDbConnection.Open();
var reader = categoryDescCheckQueryCommand.ExecuteReader(); var reader = categoryDescCheckQueryCommand.ExecuteReader();
while (reader != null && reader.Read()) while (reader != null && reader.Read())
@@ -985,7 +1291,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return rowsEffected; return rowsEffected;
@@ -999,11 +1305,11 @@ namespace AdvertsingProfitControl
CommandText = "DELETE FROM GroupCategory WHERE GroupDescription = ?" CommandText = "DELETE FROM GroupCategory WHERE GroupDescription = ?"
}; };
oleDbCommand.Parameters.AddWithValue("AdSpecialName", adSpecialName); oleDbCommand.Parameters.AddWithValue("AdSpecialName", adSpecialName);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
_connectionobject.Open(); _oleDbConnection.Open();
rowsEffected = oleDbCommand.ExecuteNonQuery(); rowsEffected = oleDbCommand.ExecuteNonQuery();
} }
catch (OleDbException e) catch (OleDbException e)
@@ -1014,7 +1320,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return rowsEffected; return rowsEffected;
@@ -1029,11 +1335,11 @@ namespace AdvertsingProfitControl
}; };
deleteCommand.Parameters.AddWithValue("AdItemID", adItemId); deleteCommand.Parameters.AddWithValue("AdItemID", adItemId);
deleteCommand.Parameters.AddWithValue("DateID", dateId); deleteCommand.Parameters.AddWithValue("DateID", dateId);
deleteCommand.Connection = _connectionobject; deleteCommand.Connection = _oleDbConnection;
try try
{ {
_connectionobject.Open(); _oleDbConnection.Open();
recordsDeleted = deleteCommand.ExecuteNonQuery(); recordsDeleted = deleteCommand.ExecuteNonQuery();
} }
catch (OleDbException e) catch (OleDbException e)
@@ -1043,7 +1349,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return recordsDeleted; return recordsDeleted;
@@ -1058,11 +1364,11 @@ namespace AdvertsingProfitControl
}; };
oleDbCommand.Parameters.AddWithValue("InvoiceNumber", invoiceNumber); oleDbCommand.Parameters.AddWithValue("InvoiceNumber", invoiceNumber);
oleDbCommand.Parameters.AddWithValue("DateID", dateId); oleDbCommand.Parameters.AddWithValue("DateID", dateId);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
_connectionobject.Open(); _oleDbConnection.Open();
recordsAffected = oleDbCommand.ExecuteNonQuery(); recordsAffected = oleDbCommand.ExecuteNonQuery();
} }
catch (OleDbException e) catch (OleDbException e)
@@ -1072,7 +1378,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return recordsAffected; return recordsAffected;
@@ -1093,39 +1399,39 @@ namespace AdvertsingProfitControl
CommandText = "DELETE FROM APC WHERE FK_DateID = ?" CommandText = "DELETE FROM APC WHERE FK_DateID = ?"
}; };
clearApCommand.Parameters.AddWithValue("DateID", dateId); clearApCommand.Parameters.AddWithValue("DateID", dateId);
clearApCommand.Connection = _connectionobject; clearApCommand.Connection = _oleDbConnection;
//Object to clear comments associated with the date ID. //Object to clear comments associated with the date ID.
var clearCommentsCommand = new OleDbCommand() var clearCommentsCommand = new OleDbCommand()
{ {
CommandText = "DELETE FROM Comment WHERE FK_DateID = ?" CommandText = "DELETE FROM Comment WHERE FK_DateID = ?"
}; };
clearCommentsCommand.Parameters.AddWithValue("DateID", dateId); clearCommentsCommand.Parameters.AddWithValue("DateID", dateId);
clearCommentsCommand.Connection = _connectionobject; clearCommentsCommand.Connection = _oleDbConnection;
//Object to clear the invoices associated with the date ID. //Object to clear the invoices associated with the date ID.
var clearInvoicesCommand = new OleDbCommand() var clearInvoicesCommand = new OleDbCommand()
{ {
CommandText = "DELETE FROM Invoice WHERE FK_DateID = ?" CommandText = "DELETE FROM Invoice WHERE FK_DateID = ?"
}; };
clearInvoicesCommand.Parameters.AddWithValue("DateID", dateId); clearInvoicesCommand.Parameters.AddWithValue("DateID", dateId);
clearInvoicesCommand.Connection = _connectionobject; clearInvoicesCommand.Connection = _oleDbConnection;
//Object to clear the weekly sales associated with the date ID. //Object to clear the weekly sales associated with the date ID.
var clearWeeklySalesCommand = new OleDbCommand() var clearWeeklySalesCommand = new OleDbCommand()
{ {
CommandText = "DELETE FROM WeeklySales WHERE FK_DateID = ?" CommandText = "DELETE FROM WeeklySales WHERE FK_DateID = ?"
}; };
clearWeeklySalesCommand.Parameters.AddWithValue("DateID", dateId); clearWeeklySalesCommand.Parameters.AddWithValue("DateID", dateId);
clearWeeklySalesCommand.Connection = _connectionobject; clearWeeklySalesCommand.Connection = _oleDbConnection;
//Object to clear the date associated with the ID passed in. //Object to clear the date associated with the ID passed in.
var clearEndOfWeekDateCommand = new OleDbCommand() var clearEndOfWeekDateCommand = new OleDbCommand()
{ {
CommandText = "DELETE FROM WeekEnding WHERE ID = ?" CommandText = "DELETE FROM WeekEnding WHERE ID = ?"
}; };
clearEndOfWeekDateCommand.Parameters.AddWithValue("DateID", dateId); clearEndOfWeekDateCommand.Parameters.AddWithValue("DateID", dateId);
clearEndOfWeekDateCommand.Connection = _connectionobject; clearEndOfWeekDateCommand.Connection = _oleDbConnection;
try try
{ {
_connectionobject.Open(); _oleDbConnection.Open();
recordsRemoved += clearApCommand.ExecuteNonQuery(); recordsRemoved += clearApCommand.ExecuteNonQuery();
recordsRemoved += clearCommentsCommand.ExecuteNonQuery(); recordsRemoved += clearCommentsCommand.ExecuteNonQuery();
recordsRemoved += clearInvoicesCommand.ExecuteNonQuery(); recordsRemoved += clearInvoicesCommand.ExecuteNonQuery();
@@ -1139,7 +1445,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return recordsRemoved; return recordsRemoved;
} }
@@ -1161,12 +1467,12 @@ namespace AdvertsingProfitControl
}; };
oleDbCommand.Parameters.AddWithValue("Comment", comment); oleDbCommand.Parameters.AddWithValue("Comment", comment);
oleDbCommand.Parameters.AddWithValue("DateID", dateId); oleDbCommand.Parameters.AddWithValue("DateID", dateId);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
//IF the delete command deletes more then one row it returns 0. //IF the delete command deletes more then one row it returns 0.
_connectionobject.Open(); _oleDbConnection.Open();
var recordsEffected = oleDbCommand.ExecuteNonQuery(); var recordsEffected = oleDbCommand.ExecuteNonQuery();
if (recordsEffected == 1) if (recordsEffected == 1)
{ {
@@ -1180,7 +1486,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return wasSuccessful; return wasSuccessful;
@@ -1194,11 +1500,11 @@ namespace AdvertsingProfitControl
CommandText = "DELETE FROM AdItem WHERE AdItem = ?" CommandText = "DELETE FROM AdItem WHERE AdItem = ?"
}; };
oleDbCommand.Parameters.AddWithValue("AdItemName", adItemName); oleDbCommand.Parameters.AddWithValue("AdItemName", adItemName);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
try try
{ {
_connectionobject.Open(); _oleDbConnection.Open();
var rowsEffected = oleDbCommand.ExecuteNonQuery(); var rowsEffected = oleDbCommand.ExecuteNonQuery();
if(rowsEffected == 1) if(rowsEffected == 1)
@@ -1222,7 +1528,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return success; return success;
@@ -1236,17 +1542,17 @@ namespace AdvertsingProfitControl
CommandText = "INSERT INTO AdItem (AdItem) VALUES (?)" CommandText = "INSERT INTO AdItem (AdItem) VALUES (?)"
}; };
oleDbCommand.Parameters.AddWithValue("AdItemName", adItemName); oleDbCommand.Parameters.AddWithValue("AdItemName", adItemName);
oleDbCommand.Connection = _connectionobject; oleDbCommand.Connection = _oleDbConnection;
var redundantancyCheck = new OleDbCommand var redundantancyCheck = new OleDbCommand
{ {
CommandText = "SELECT AdItem FROM AdItem WHERE AdItem = ?" CommandText = "SELECT AdItem FROM AdItem WHERE AdItem = ?"
}; };
redundantancyCheck.Parameters.AddWithValue("AdItemName", adItemName); redundantancyCheck.Parameters.AddWithValue("AdItemName", adItemName);
redundantancyCheck.Connection = _connectionobject; redundantancyCheck.Connection = _oleDbConnection;
try try
{ {
_connectionobject.Open(); _oleDbConnection.Open();
using(var reader = redundantancyCheck.ExecuteReader()) using(var reader = redundantancyCheck.ExecuteReader())
{ {
var rows = 0; var rows = 0;
@@ -1280,7 +1586,7 @@ namespace AdvertsingProfitControl
} }
finally finally
{ {
_connectionobject.Close(); _oleDbConnection.Close();
} }
return success; return success;
@@ -47,7 +47,7 @@ namespace AdvertsingProfitControl
if (rowsEffected == 1) if (rowsEffected == 1)
{ {
RowParsing._adSpecialGroups.Add(enterNewKeyWordTextBox.Text); RowParsing.AdSpecialGroups.Add(enterNewKeyWordTextBox.Text);
var groupNameCollection = databaseReader.ReturnGroupNameList(databaseTracker.DatabaseConnectionString); var groupNameCollection = databaseReader.ReturnGroupNameList(databaseTracker.DatabaseConnectionString);
adSpecialKeyWordsListBox.Items.Clear(); adSpecialKeyWordsListBox.Items.Clear();
foreach (var groupName in groupNameCollection) foreach (var groupName in groupNameCollection)
+9 -9
View File
@@ -53,7 +53,7 @@ namespace AdvertsingProfitControl
_AdSpecialList = databaseReader.RetrieveAdSpecialList(databaseTracker.DatabaseConnectionString); _AdSpecialList = databaseReader.RetrieveAdSpecialList(databaseTracker.DatabaseConnectionString);
//Event handlers for the Projections DataGridView //Event handlers for the Projections DataGridView
projectionsDataGridView.CellValidating += OnCellValidating; projectionsDataGridView.CellValidating += OnCellValidating;
projectionsDataGridView.RowEnter += DetectAndDisplayIncompleteRows; //projectionsDataGridView.RowEnter += DetectAndDisplayIncompleteRows;
projectionsDataGridView.RowLeave += OnRowLeave; projectionsDataGridView.RowLeave += OnRowLeave;
projectionsDataGridView.RowsAdded += DisplayRowNumbers; projectionsDataGridView.RowsAdded += DisplayRowNumbers;
projectionsDataGridView.RowsRemoved += OnRowRemoved; projectionsDataGridView.RowsRemoved += OnRowRemoved;
@@ -62,14 +62,14 @@ namespace AdvertsingProfitControl
projectionsDataGridView.RowValidating += UpdateInventoryActualSalesDataGridView; projectionsDataGridView.RowValidating += UpdateInventoryActualSalesDataGridView;
//Event handlers for the Inventory / Actual Sales DataGridView //Event handlers for the Inventory / Actual Sales DataGridView
actualSalesDataGridView.CellValidating += OnCellValidating; actualSalesDataGridView.CellValidating += OnCellValidating; //
actualSalesDataGridView.RowEnter += DetectAndDisplayIncompleteRows; actualSalesDataGridView.RowEnter += DetectAndDisplayIncompleteRows;
actualSalesDataGridView.RowLeave += OnRowLeave; actualSalesDataGridView.RowLeave += OnRowLeave; //
actualSalesDataGridView.RowsAdded += DisplayRowNumbers; actualSalesDataGridView.RowsAdded += DisplayRowNumbers;//
actualSalesDataGridView.RowsRemoved += OnRowRemoved; actualSalesDataGridView.RowsRemoved += OnRowRemoved;//
actualSalesDataGridView.UserDeletingRow += OnRowRemoving; actualSalesDataGridView.UserDeletingRow += OnRowRemoving; //
actualSalesDataGridView.EditingControlShowing += DisplayAutoCompleteOnEditingControlShowing; actualSalesDataGridView.EditingControlShowing += DisplayAutoCompleteOnEditingControlShowing; //
actualSalesDataGridView.RowValidating += UpdateProjectionsDataGridView; actualSalesDataGridView.RowValidating += UpdateProjectionsDataGridView;//
//Event handlers for the Suppliers DataGridView //Event handlers for the Suppliers DataGridView
suppliersDataGridView.CellValidating += SupplierOnCellValidating; suppliersDataGridView.CellValidating += SupplierOnCellValidating;
@@ -726,7 +726,7 @@ namespace AdvertsingProfitControl
if (actualSalesDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString() != "") if (actualSalesDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString() != "")
{ {
var parser = new RowParsing(); var parser = new RowParsing();
var rowContents = new string[11]; object[] rowContents = new object[11];
//Check to make sure the user didn't simply leave a row that already exists. //Check to make sure the user didn't simply leave a row that already exists.
if (projectionsDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString() == actualSalesDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()) if (projectionsDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString() == actualSalesDataGridView.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString())
{ {
+32 -33
View File
@@ -7,8 +7,7 @@ namespace AdvertsingProfitControl
public sealed partial class FrmLogConsole : Form public sealed partial class FrmLogConsole : Form
{ {
//Source code: https://hashfactor.wordpress.com/2009/03/31/c-winforms-create-a-single-instance-form/ //Source code: https://hashfactor.wordpress.com/2009/03/31/c-winforms-create-a-single-instance-form/
private static readonly FrmLogConsole gLogConsoleInstance = new FrmLogConsole(); private static bool _gIsShown;
private static bool gIsShown = false;
public FrmLogConsole() public FrmLogConsole()
{ {
@@ -18,16 +17,18 @@ namespace AdvertsingProfitControl
logListView.View = View.Details; logListView.View = View.Details;
//Information for drawing header columns and sub-items in ListView: //Information for drawing header columns and sub-items in ListView:
//http://stackoverflow.com/questions/561798/how-do-i-align-text-for-a-single-subitem-in-a-listview-using-c //http://stackoverflow.com/questions/561798/how-do-i-align-text-for-a-single-subitem-in-a-listview-using-c
ColumnHeader header = new ColumnHeader(); var header = new ColumnHeader
header.Text = "Advertising Profit Control " + Application.ProductVersion + " Debug Console"; {
header.Name = "LogConsoleHeader"; Text = @"Advertising Profit Control " + Application.ProductVersion + @" Debug Console",
header.Width = logListView.Width; Name = "LogConsoleHeader",
Width = logListView.Width
};
logListView.Columns.Add(header); logListView.Columns.Add(header);
} }
static FrmLogConsole() static FrmLogConsole()
{ {
GetStaticInstance.FormClosing += new FormClosingEventHandler(LogConsole_FormClosing); GetStaticInstance.FormClosing += LogConsole_FormClosing;
//Set the maximum and minimum size of the form. //Set the maximum and minimum size of the form.
GetStaticInstance.MaximumSize = new Size(900, 900); GetStaticInstance.MaximumSize = new Size(900, 900);
GetStaticInstance.MinimumSize = new Size(400, 400); GetStaticInstance.MinimumSize = new Size(400, 400);
@@ -35,27 +36,25 @@ namespace AdvertsingProfitControl
public new void Show() public new void Show()
{ {
if (gIsShown) if (_gIsShown)
{ {
base.Show(); base.Show();
} }
else else
{ {
base.Show(); base.Show();
gIsShown = true; _gIsShown = true;
} }
} }
public new void Hide() public new void Hide()
{ {
if (gIsShown) if (!_gIsShown) return;
{ base.Hide();
base.Hide(); _gIsShown = false;
gIsShown = false;
}
} }
public enum Level : int public enum Level
{ {
Critical = 0, Critical = 0,
Error = 1, Error = 1,
@@ -68,7 +67,6 @@ namespace AdvertsingProfitControl
public void WriteToLog(Level level, string message) public void WriteToLog(Level level, string message)
{ {
Color color; Color color;
int index;
switch (level) switch (level)
{ {
@@ -87,14 +85,17 @@ namespace AdvertsingProfitControl
case Level.Verbose: case Level.Verbose:
color = Color.Blue; color = Color.Blue;
break; break;
case Level.Debug:
color = Color.Black;
break;
default: default:
color = Color.Black; color = Color.Black;
break; break;
} }
index = logListView.Items.Count; var index = logListView.Items.Count;
try try
{ {
message = String.Format("{0}: {1}", level, message); message = $"{level}: {message}";
if (level != Level.Info) if (level != Level.Info)
{ {
GlobalClasses.WriteToLog(DateTime.Now + ": " + message + Environment.NewLine); GlobalClasses.WriteToLog(DateTime.Now + ": " + message + Environment.NewLine);
@@ -107,13 +108,17 @@ namespace AdvertsingProfitControl
MessageBox.Show(e.Message); MessageBox.Show(e.Message);
} }
if (level == Level.Critical) switch (level)
{ {
logListView.Items[index].BackColor = Color.Red; case Level.Critical:
} logListView.Items[index].BackColor = Color.Red;
else break;
{ case Level.Error:
logListView.Items[index].BackColor = Color.WhiteSmoke; logListView.Items[index].ForeColor = Color.Maroon;
break;
default:
logListView.Items[index].BackColor = Color.WhiteSmoke;
break;
} }
} }
@@ -121,17 +126,11 @@ namespace AdvertsingProfitControl
{ {
e.Cancel = true; e.Cancel = true;
GetStaticInstance.Hide(); GetStaticInstance.Hide();
gIsShown = false; _gIsShown = false;
} }
public static FrmLogConsole GetStaticInstance public static FrmLogConsole GetStaticInstance { get; } = new FrmLogConsole();
{
get { return gLogConsoleInstance; }
}
public bool IsVisable public bool IsVisable => _gIsShown;
{
get { return gIsShown; }
}
} }
} }
+16 -12
View File
@@ -48,7 +48,7 @@
this.commentMainGroupBox = new System.Windows.Forms.GroupBox(); this.commentMainGroupBox = new System.Windows.Forms.GroupBox();
this.commentsTextBox = new System.Windows.Forms.TextBox(); this.commentsTextBox = new System.Windows.Forms.TextBox();
this.profitAnalysisMainGroupBox = new System.Windows.Forms.GroupBox(); this.profitAnalysisMainGroupBox = new System.Windows.Forms.GroupBox();
this.shrinkLabel = new System.Windows.Forms.Label(); this.shrinkLinkLabel = new System.Windows.Forms.LinkLabel();
this.totalProfitReturnLabel = new System.Windows.Forms.Label(); this.totalProfitReturnLabel = new System.Windows.Forms.Label();
this.totalProfitReturnFromRemaingLabel = new System.Windows.Forms.Label(); this.totalProfitReturnFromRemaingLabel = new System.Windows.Forms.Label();
this.totalProfitFromAdItemsLabel = new System.Windows.Forms.Label(); this.totalProfitFromAdItemsLabel = new System.Windows.Forms.Label();
@@ -286,7 +286,7 @@
// //
// profitAnalysisMainGroupBox // profitAnalysisMainGroupBox
// //
this.profitAnalysisMainGroupBox.Controls.Add(this.shrinkLabel); this.profitAnalysisMainGroupBox.Controls.Add(this.shrinkLinkLabel);
this.profitAnalysisMainGroupBox.Controls.Add(this.totalProfitReturnLabel); this.profitAnalysisMainGroupBox.Controls.Add(this.totalProfitReturnLabel);
this.profitAnalysisMainGroupBox.Controls.Add(this.totalProfitReturnFromRemaingLabel); this.profitAnalysisMainGroupBox.Controls.Add(this.totalProfitReturnFromRemaingLabel);
this.profitAnalysisMainGroupBox.Controls.Add(this.totalProfitFromAdItemsLabel); this.profitAnalysisMainGroupBox.Controls.Add(this.totalProfitFromAdItemsLabel);
@@ -304,15 +304,19 @@
this.profitAnalysisMainGroupBox.TabStop = false; this.profitAnalysisMainGroupBox.TabStop = false;
this.profitAnalysisMainGroupBox.Text = "Profit Analysis"; this.profitAnalysisMainGroupBox.Text = "Profit Analysis";
// //
// shrinkLabel // shrinkLinkLabel
// //
this.shrinkLabel.AutoSize = true; this.shrinkLinkLabel.AutoSize = true;
this.shrinkLabel.Location = new System.Drawing.Point(0, 36); this.shrinkLinkLabel.LinkArea = new System.Windows.Forms.LinkArea(20, 6);
this.shrinkLabel.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.shrinkLinkLabel.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
this.shrinkLabel.Name = "shrinkLabel"; this.shrinkLinkLabel.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.shrinkLabel.Size = new System.Drawing.Size(205, 25); this.shrinkLinkLabel.Location = new System.Drawing.Point(0, 37);
this.shrinkLabel.TabIndex = 6; this.shrinkLinkLabel.Name = "shrinkLinkLabel";
this.shrinkLabel.Text = "Assuming 30% Shrink"; this.shrinkLinkLabel.Size = new System.Drawing.Size(272, 27);
this.shrinkLinkLabel.TabIndex = 6;
this.shrinkLinkLabel.TabStop = true;
this.shrinkLinkLabel.Text = "Assuming 30% Shrink Change";
this.shrinkLinkLabel.UseCompatibleTextRendering = true;
// //
// totalProfitReturnLabel // totalProfitReturnLabel
// //
@@ -699,7 +703,7 @@
// //
// FrmMain // FrmMain
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(1734, 892); this.ClientSize = new System.Drawing.Size(1734, 892);
this.Controls.Add(this.mainTableLayoutPanel); this.Controls.Add(this.mainTableLayoutPanel);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
@@ -768,7 +772,6 @@
private System.Windows.Forms.Label departmentSalesLabel; private System.Windows.Forms.Label departmentSalesLabel;
private System.Windows.Forms.TabPage WeeklySalesTabPage; private System.Windows.Forms.TabPage WeeklySalesTabPage;
private System.Windows.Forms.DataGridView weeklySalesDataGridView; private System.Windows.Forms.DataGridView weeklySalesDataGridView;
private System.Windows.Forms.Label shrinkLabel;
private System.Windows.Forms.ToolStripMenuItem helpMainMenu; private System.Windows.Forms.ToolStripMenuItem helpMainMenu;
private System.Windows.Forms.ToolStripMenuItem showHideConsoleHelpMainMenu; private System.Windows.Forms.ToolStripMenuItem showHideConsoleHelpMainMenu;
private System.Windows.Forms.GroupBox taxableGroupBox; private System.Windows.Forms.GroupBox taxableGroupBox;
@@ -794,6 +797,7 @@
private System.Windows.Forms.Button printPreviewButton; private System.Windows.Forms.Button printPreviewButton;
private System.Windows.Forms.CheckBox usePreRenderedFilesCheckbox; private System.Windows.Forms.CheckBox usePreRenderedFilesCheckbox;
private System.Windows.Forms.ToolStripMenuItem newFormTestToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem newFormTestToolStripMenuItem;
private System.Windows.Forms.LinkLabel shrinkLinkLabel;
} }
} }
+1 -1
View File
@@ -45,7 +45,7 @@ namespace AdvertsingProfitControl
MessageBox.Show("The database has been successfully upgraded to version " + versionNumber + ".\nA back up of the old database has been made called APCDatabase.bak in the same location as the current database.", "Half Baked Code For The Win"); MessageBox.Show("The database has been successfully upgraded to version " + versionNumber + ".\nA back up of the old database has been made called APCDatabase.bak in the same location as the current database.", "Half Baked Code For The Win");
} }
} }
RowParsing._adSpecialGroups.AddRange(databaseReader.ReturnGroupNameList(databaseTracker.DatabaseConnectionString)); RowParsing.AdSpecialGroups.AddRange(databaseReader.ReturnGroupNameList(databaseTracker.DatabaseConnectionString));
FillDateSuggestionComboBoxes(); FillDateSuggestionComboBoxes();
BuildAndFillDataGridTables(); BuildAndFillDataGridTables();
CalculateProfitAnalysis(); CalculateProfitAnalysis();
+52 -31
View File
@@ -37,13 +37,15 @@
this.inventoryTabPage = new System.Windows.Forms.TabPage(); this.inventoryTabPage = new System.Windows.Forms.TabPage();
this.inventoryDataGridView = new System.Windows.Forms.DataGridView(); this.inventoryDataGridView = new System.Windows.Forms.DataGridView();
this.actualSalesTabPage = new System.Windows.Forms.TabPage(); this.actualSalesTabPage = new System.Windows.Forms.TabPage();
this.actualDataGridView = new System.Windows.Forms.DataGridView(); this.actualSalesDataGridView = new System.Windows.Forms.DataGridView();
this.invoicesTabPage = new System.Windows.Forms.TabPage(); this.invoicesTabPage = new System.Windows.Forms.TabPage();
this.invoicesDataGridView = new System.Windows.Forms.DataGridView(); this.invoicesDataGridView = new System.Windows.Forms.DataGridView();
this.tabPage1 = new System.Windows.Forms.TabPage(); this.debugTabPage = new System.Windows.Forms.TabPage();
this.mainMenuStrip = new System.Windows.Forms.MenuStrip(); this.mainMenuStrip = new System.Windows.Forms.MenuStrip();
this.FileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.FileMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.exitFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.exitFileMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.debugMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.getCellValueDebugMainMenu = new System.Windows.Forms.ToolStripMenuItem();
this.mainLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.mainLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.costAnalysisGroupBox = new System.Windows.Forms.GroupBox(); this.costAnalysisGroupBox = new System.Windows.Forms.GroupBox();
this.suppliesTextBox = new System.Windows.Forms.TextBox(); this.suppliesTextBox = new System.Windows.Forms.TextBox();
@@ -106,7 +108,7 @@
this.inventoryTabPage.SuspendLayout(); this.inventoryTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.inventoryDataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.inventoryDataGridView)).BeginInit();
this.actualSalesTabPage.SuspendLayout(); this.actualSalesTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.actualDataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.actualSalesDataGridView)).BeginInit();
this.invoicesTabPage.SuspendLayout(); this.invoicesTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.invoicesDataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.invoicesDataGridView)).BeginInit();
this.mainMenuStrip.SuspendLayout(); this.mainMenuStrip.SuspendLayout();
@@ -150,7 +152,7 @@
this.mainTabControl.Controls.Add(this.inventoryTabPage); this.mainTabControl.Controls.Add(this.inventoryTabPage);
this.mainTabControl.Controls.Add(this.actualSalesTabPage); this.mainTabControl.Controls.Add(this.actualSalesTabPage);
this.mainTabControl.Controls.Add(this.invoicesTabPage); this.mainTabControl.Controls.Add(this.invoicesTabPage);
this.mainTabControl.Controls.Add(this.tabPage1); this.mainTabControl.Controls.Add(this.debugTabPage);
this.mainTabControl.Dock = System.Windows.Forms.DockStyle.Fill; this.mainTabControl.Dock = System.Windows.Forms.DockStyle.Fill;
this.mainTabControl.Location = new System.Drawing.Point(4, 39); this.mainTabControl.Location = new System.Drawing.Point(4, 39);
this.mainTabControl.Margin = new System.Windows.Forms.Padding(4); this.mainTabControl.Margin = new System.Windows.Forms.Padding(4);
@@ -216,7 +218,7 @@
// //
// actualSalesTabPage // actualSalesTabPage
// //
this.actualSalesTabPage.Controls.Add(this.actualDataGridView); this.actualSalesTabPage.Controls.Add(this.actualSalesDataGridView);
this.actualSalesTabPage.Location = new System.Drawing.Point(4, 33); this.actualSalesTabPage.Location = new System.Drawing.Point(4, 33);
this.actualSalesTabPage.Margin = new System.Windows.Forms.Padding(4); this.actualSalesTabPage.Margin = new System.Windows.Forms.Padding(4);
this.actualSalesTabPage.Name = "actualSalesTabPage"; this.actualSalesTabPage.Name = "actualSalesTabPage";
@@ -225,21 +227,21 @@
this.actualSalesTabPage.Text = "Actual Sales"; this.actualSalesTabPage.Text = "Actual Sales";
this.actualSalesTabPage.UseVisualStyleBackColor = true; this.actualSalesTabPage.UseVisualStyleBackColor = true;
// //
// actualDataGridView // actualSalesDataGridView
// //
this.actualDataGridView.AllowDrop = true; this.actualSalesDataGridView.AllowDrop = true;
this.actualDataGridView.AllowUserToResizeRows = false; this.actualSalesDataGridView.AllowUserToResizeRows = false;
this.actualDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.actualSalesDataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.actualDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells; this.actualSalesDataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.actualDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.actualSalesDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.actualDataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.actualSalesDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
this.actualDataGridView.Location = new System.Drawing.Point(0, 0); this.actualSalesDataGridView.Location = new System.Drawing.Point(0, 0);
this.actualDataGridView.Margin = new System.Windows.Forms.Padding(4); this.actualSalesDataGridView.Margin = new System.Windows.Forms.Padding(4);
this.actualDataGridView.MultiSelect = false; this.actualSalesDataGridView.MultiSelect = false;
this.actualDataGridView.Name = "actualDataGridView"; this.actualSalesDataGridView.Name = "actualSalesDataGridView";
this.actualDataGridView.RowTemplate.Height = 28; this.actualSalesDataGridView.RowTemplate.Height = 28;
this.actualDataGridView.Size = new System.Drawing.Size(1660, 510); this.actualSalesDataGridView.Size = new System.Drawing.Size(1660, 510);
this.actualDataGridView.TabIndex = 1; this.actualSalesDataGridView.TabIndex = 1;
// //
// invoicesTabPage // invoicesTabPage
// //
@@ -268,22 +270,23 @@
this.invoicesDataGridView.Size = new System.Drawing.Size(1660, 510); this.invoicesDataGridView.Size = new System.Drawing.Size(1660, 510);
this.invoicesDataGridView.TabIndex = 1; this.invoicesDataGridView.TabIndex = 1;
// //
// tabPage1 // debugTabPage
// //
this.tabPage1.Location = new System.Drawing.Point(4, 33); this.debugTabPage.Location = new System.Drawing.Point(4, 33);
this.tabPage1.Name = "tabPage1"; this.debugTabPage.Name = "debugTabPage";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3); this.debugTabPage.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(1660, 510); this.debugTabPage.Size = new System.Drawing.Size(1660, 510);
this.tabPage1.TabIndex = 4; this.debugTabPage.TabIndex = 4;
this.tabPage1.Text = "tabPage1"; this.debugTabPage.Text = "DEBUG";
this.tabPage1.UseVisualStyleBackColor = true; this.debugTabPage.UseVisualStyleBackColor = true;
// //
// mainMenuStrip // mainMenuStrip
// //
this.mainLayoutPanel.SetColumnSpan(this.mainMenuStrip, 4); this.mainLayoutPanel.SetColumnSpan(this.mainMenuStrip, 4);
this.mainMenuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); this.mainMenuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
this.mainMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mainMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.FileMainMenu}); this.FileMainMenu,
this.debugMainMenu});
this.mainMenuStrip.Location = new System.Drawing.Point(0, 0); this.mainMenuStrip.Location = new System.Drawing.Point(0, 0);
this.mainMenuStrip.Name = "mainMenuStrip"; this.mainMenuStrip.Name = "mainMenuStrip";
this.mainMenuStrip.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2); this.mainMenuStrip.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2);
@@ -305,6 +308,21 @@
this.exitFileMainMenu.Size = new System.Drawing.Size(138, 34); this.exitFileMainMenu.Size = new System.Drawing.Size(138, 34);
this.exitFileMainMenu.Text = "E&xit"; this.exitFileMainMenu.Text = "E&xit";
// //
// debugMainMenu
//
this.debugMainMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.getCellValueDebugMainMenu});
this.debugMainMenu.Name = "debugMainMenu";
this.debugMainMenu.Size = new System.Drawing.Size(87, 31);
this.debugMainMenu.Text = "Debug";
//
// getCellValueDebugMainMenu
//
this.getCellValueDebugMainMenu.Name = "getCellValueDebugMainMenu";
this.getCellValueDebugMainMenu.Size = new System.Drawing.Size(233, 34);
this.getCellValueDebugMainMenu.Text = "Get Cell Value";
this.getCellValueDebugMainMenu.Click += new System.EventHandler(this.getCellValueDebugMainMenu_Click);
//
// mainLayoutPanel // mainLayoutPanel
// //
this.mainLayoutPanel.ColumnCount = 4; this.mainLayoutPanel.ColumnCount = 4;
@@ -841,6 +859,7 @@
this.addRecordButton.TabIndex = 26; this.addRecordButton.TabIndex = 26;
this.addRecordButton.Text = "Add Record"; this.addRecordButton.Text = "Add Record";
this.addRecordButton.UseVisualStyleBackColor = true; this.addRecordButton.UseVisualStyleBackColor = true;
this.addRecordButton.Click += new System.EventHandler(this.AddRecordsButtonClick);
// //
// NewAddRecord // NewAddRecord
// //
@@ -865,7 +884,7 @@
this.inventoryTabPage.ResumeLayout(false); this.inventoryTabPage.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.inventoryDataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.inventoryDataGridView)).EndInit();
this.actualSalesTabPage.ResumeLayout(false); this.actualSalesTabPage.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.actualDataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.actualSalesDataGridView)).EndInit();
this.invoicesTabPage.ResumeLayout(false); this.invoicesTabPage.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.invoicesDataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.invoicesDataGridView)).EndInit();
this.mainMenuStrip.ResumeLayout(false); this.mainMenuStrip.ResumeLayout(false);
@@ -901,7 +920,7 @@
private System.Windows.Forms.TabPage inventoryTabPage; private System.Windows.Forms.TabPage inventoryTabPage;
private System.Windows.Forms.DataGridView inventoryDataGridView; private System.Windows.Forms.DataGridView inventoryDataGridView;
private System.Windows.Forms.TabPage actualSalesTabPage; private System.Windows.Forms.TabPage actualSalesTabPage;
private System.Windows.Forms.DataGridView actualDataGridView; private System.Windows.Forms.DataGridView actualSalesDataGridView;
private System.Windows.Forms.TabPage invoicesTabPage; private System.Windows.Forms.TabPage invoicesTabPage;
private System.Windows.Forms.DataGridView invoicesDataGridView; private System.Windows.Forms.DataGridView invoicesDataGridView;
private System.Windows.Forms.TextBox suppliesTextBox; private System.Windows.Forms.TextBox suppliesTextBox;
@@ -957,9 +976,11 @@
private System.Windows.Forms.Panel dateTimeMaskedTextBoxPanel; private System.Windows.Forms.Panel dateTimeMaskedTextBoxPanel;
private System.Windows.Forms.MaskedTextBox weekEndingMaskedTextBox; private System.Windows.Forms.MaskedTextBox weekEndingMaskedTextBox;
private System.Windows.Forms.Label weekEndingMaskedTextBoxInstructionLabel; private System.Windows.Forms.Label weekEndingMaskedTextBoxInstructionLabel;
private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage debugTabPage;
private System.Windows.Forms.Panel informationPanel; private System.Windows.Forms.Panel informationPanel;
private System.Windows.Forms.Label errorLabel; private System.Windows.Forms.Label errorLabel;
private System.Windows.Forms.Label informationLabel; private System.Windows.Forms.Label informationLabel;
private System.Windows.Forms.ToolStripMenuItem debugMainMenu;
private System.Windows.Forms.ToolStripMenuItem getCellValueDebugMainMenu;
} }
} }
File diff suppressed because it is too large Load Diff
+7 -5
View File
@@ -8,20 +8,21 @@ namespace AdvertsingProfitControl
{ {
internal class RowParsing internal class RowParsing
{ {
public static List<string> _adSpecialGroups = new List<string>(); public static List<string> AdSpecialGroups = new List<string>();
public string CheckForGroupKeyWord(string cellContents) public string CheckForGroupKeyWord(string cellContents)
{ {
var keyWord = "NoGroupFound"; var keyWord = "NoGroupFound";
var query = from adI in _adSpecialGroups var query = from adI in AdSpecialGroups
where adI.Equals(cellContents, StringComparison.InvariantCultureIgnoreCase) where adI.Equals(cellContents, StringComparison.InvariantCultureIgnoreCase)
select adI; select adI;
if (query.ToArray().Length > 0) var enumerable = query as string[] ?? query.ToArray();
if (enumerable.ToArray().Length > 0)
{ {
//Grab the first object in the array and return it. //Grab the first object in the array and return it.
keyWord = query.ToArray().First(); keyWord = enumerable.ToArray().First();
} }
return keyWord; return keyWord;
@@ -50,6 +51,7 @@ namespace AdvertsingProfitControl
var i = 0; var i = 0;
foreach (DataGridViewCell cell in row.Cells) foreach (DataGridViewCell cell in row.Cells)
{ {
if (cell.ColumnIndex >= (int) SalesTableColumns.IsHeaderRow) { i++; continue;}
//Strip all whitespace characters from the cell, this includes vertical tabs, newlines, and any number of spaces. //Strip all whitespace characters from the cell, this includes vertical tabs, newlines, and any number of spaces.
var cellContentsStripped = new string(cell.EditedFormattedValue.ToString().Where(c => !char.IsWhiteSpace(c)).ToArray()); var cellContentsStripped = new string(cell.EditedFormattedValue.ToString().Where(c => !char.IsWhiteSpace(c)).ToArray());
//Now remove all zeros, including any decimal points as these values are meaningless. //Now remove all zeros, including any decimal points as these values are meaningless.
@@ -60,7 +62,7 @@ namespace AdvertsingProfitControl
rowContents.Add(cell.EditedFormattedValue.ToString()); rowContents.Add(cell.EditedFormattedValue.ToString());
} }
//If the first cell contains nothing, then return as IncompleteRow. //If the first cell contains nothing, then return as IncompleteRow.
else if (cellContentsStripped == "" && i == 0) else if (cellContentsStripped == "" && i == (int) SalesTableColumns.AdItem)
{ {
return RowAttribute.IncompleteRow; return RowAttribute.IncompleteRow;
} }
+16 -9
View File
@@ -28,7 +28,6 @@ namespace AdvertsingProfitControl
var isPreviousCharWhiteSpace = false; var isPreviousCharWhiteSpace = false;
var cleanedInputString = ""; var cleanedInputString = "";
var lastnumberStartingIndex = -1; var lastnumberStartingIndex = -1;
var removedCharacterOffset = 0;
//Create an array of brackets to test for, and either balance out or simply ignore the extras. //Create an array of brackets to test for, and either balance out or simply ignore the extras.
char[] openBrackets = { '(', '<', '{', '[' }; char[] openBrackets = { '(', '<', '{', '[' };
char[] closedBrackets = { ')', '>', '}', ']' }; char[] closedBrackets = { ')', '>', '}', ']' };
@@ -47,7 +46,6 @@ namespace AdvertsingProfitControl
if (isPreviousCharWhiteSpace) if (isPreviousCharWhiteSpace)
{ {
//If more then one space is found to be in a row, then ignore it and move onto the next character. //If more then one space is found to be in a row, then ignore it and move onto the next character.
removedCharacterOffset++;
continue; continue;
} }
//IF the current character is whitespace, then mark it and move onto the next loop. //IF the current character is whitespace, then mark it and move onto the next loop.
@@ -62,7 +60,6 @@ namespace AdvertsingProfitControl
if (isInsideBrackets) if (isInsideBrackets)
{ {
//If we are already inside of brackets then don't add anymore to the string just continue. //If we are already inside of brackets then don't add anymore to the string just continue.
removedCharacterOffset++;
continue; continue;
} }
isInsideBrackets = true; isInsideBrackets = true;
@@ -76,7 +73,6 @@ namespace AdvertsingProfitControl
//IF we're not inside brackets then there is an imbalance so discard this parenthesis. //IF we're not inside brackets then there is an imbalance so discard this parenthesis.
if (!isInsideBrackets) if (!isInsideBrackets)
{ {
removedCharacterOffset++;
continue; continue;
} }
//Just gonna force parenthesis for now. //Just gonna force parenthesis for now.
@@ -91,13 +87,13 @@ namespace AdvertsingProfitControl
if (!char.IsNumber(adItemText[currentCharacter]) && isPreviousCharWhiteSpace) if (!char.IsNumber(adItemText[currentCharacter]) && isPreviousCharWhiteSpace)
{ {
//Check to see the length of the string and determine if the word with the number needs to be capitalized. //Check to see the length of the string and determine if the word with the number needs to be capitalized.
if (char.IsNumber(cleanedInputString[currentCharacter - (2 + removedCharacterOffset)])) if (char.IsNumber(cleanedInputString[cleanedInputString.Length - 2]))
{ {
BuildAbbreviationsAndWordsLists(adItemText, currentCharacter, out abbreviations, out words); BuildAbbreviationsAndWordsLists(adItemText, currentCharacter, out abbreviations, out words);
//Remove the last space if there are any abbreviations or words found. //Remove the last space if there are any abbreviations or words found.
if (abbreviations.Count > 0 || words.Count > 0) if (abbreviations.Count > 0 || words.Count > 0)
{ {
cleanedInputString = cleanedInputString.Remove(currentCharacter - (1 + removedCharacterOffset), 1); cleanedInputString = cleanedInputString.Remove(cleanedInputString.Length - 1, 1);
} }
//Begin checking to see how to place these items back into the final string. //Begin checking to see how to place these items back into the final string.
if (abbreviations.Count >= 1 && words.Count == 0) if (abbreviations.Count >= 1 && words.Count == 0)
@@ -143,7 +139,7 @@ namespace AdvertsingProfitControl
else if (!char.IsNumber(adItemText[currentCharacter]) && char.IsLetter(adItemText[currentCharacter])) else if (!char.IsNumber(adItemText[currentCharacter]) && char.IsLetter(adItemText[currentCharacter]))
{ {
//IF the previous character is a number... //IF the previous character is a number...
if (char.IsNumber(cleanedInputString[currentCharacter - (1 + removedCharacterOffset)])) if (char.IsNumber(cleanedInputString[cleanedInputString.Length - 1]))
{ {
//Check to see the length of the string and determine if the word with the number needs to be capitalized. //Check to see the length of the string and determine if the word with the number needs to be capitalized.
BuildAbbreviationsAndWordsLists(adItemText, currentCharacter, out abbreviations, out words); BuildAbbreviationsAndWordsLists(adItemText, currentCharacter, out abbreviations, out words);
@@ -183,7 +179,7 @@ namespace AdvertsingProfitControl
break; break;
} }
} }
else if (char.IsLetter(adItemText[currentCharacter - 1])) else if (char.IsLetter(adItemText[currentCharacter - 1]) || adItemText[currentCharacter - 1] == '\'')
{ {
cleanedInputString += char.ToLowerInvariant(adItemText[currentCharacter]); cleanedInputString += char.ToLowerInvariant(adItemText[currentCharacter]);
} }
@@ -191,10 +187,20 @@ namespace AdvertsingProfitControl
//IF a number is found, and we're not inside brackets, check to see if there is an opening parenthesis and if there aren't create one. //IF a number is found, and we're not inside brackets, check to see if there is an opening parenthesis and if there aren't create one.
if (char.IsNumber(adItemText[currentCharacter])) if (char.IsNumber(adItemText[currentCharacter]))
{ {
cleanedInputString += adItemText[currentCharacter];
if (lastnumberStartingIndex == -1) if (lastnumberStartingIndex == -1)
{ {
lastnumberStartingIndex = currentCharacter - removedCharacterOffset; lastnumberStartingIndex = cleanedInputString.Length - 1; //Non-index based system, minus one for the index
} }
}
//Check for any allowed punctuation.
if (adItemText[currentCharacter] == '\'')
{
cleanedInputString += adItemText[currentCharacter];
}
//Check if the previous character is an "'".
else if (cleanedInputString[cleanedInputString.Length - 1] == '\'')
{
cleanedInputString += adItemText[currentCharacter]; cleanedInputString += adItemText[currentCharacter];
} }
//Since whitespace booleans are handled above, set the boolean for white spaces false. //Since whitespace booleans are handled above, set the boolean for white spaces false.
@@ -205,6 +211,7 @@ namespace AdvertsingProfitControl
{ {
cleanedInputString += ')'; cleanedInputString += ')';
} }
//removedCharacterOffset++;
} }
#if DEBUG #if DEBUG
+1 -1
View File
@@ -40,7 +40,7 @@
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />--> <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 --> <!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />--> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application> </application>
</compatibility> </compatibility>
+42 -14
View File
@@ -27,13 +27,13 @@ namespace StringInputParseTester
private void ExecuteParserCode(object sender, EventArgs e) private void ExecuteParserCode(object sender, EventArgs e)
{ {
var adItemText = inputTextBox.Text.Trim(); var adItemText = inputTextBox.Text.Trim();
//var splitInput = inputTextBox.Text.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
var isInsideBrackets = false; var isInsideBrackets = false;
var isPreviousCharWhiteSpace = false; var isPreviousCharWhiteSpace = false;
//preserveAcronyms //preserveAcronyms
var preserveAcronyms = true; var preserveAcronyms = true;
var cleanedInputString = ""; var cleanedInputString = "";
var lastnumberStartingIndex = -1; var lastnumberStartingIndex = -1;
var removedCharacterOffset = 0;
//Create an array of brackets to test for, and either balance out or simply ignore. //Create an array of brackets to test for, and either balance out or simply ignore.
char[] openBrackets = {'(', '<', '{', '['}; char[] openBrackets = {'(', '<', '{', '['};
char[] closedBrackets = {')', '>', '}', ']'}; char[] closedBrackets = {')', '>', '}', ']'};
@@ -52,7 +52,6 @@ namespace StringInputParseTester
if (isPreviousCharWhiteSpace) if (isPreviousCharWhiteSpace)
{ {
//If more then one space is found to be in a row, then ignore it and move onto the next character. //If more then one space is found to be in a row, then ignore it and move onto the next character.
removedCharacterOffset++;
continue; continue;
} }
//IF the current character is whitespace, then mark it and move onto the next loop. //IF the current character is whitespace, then mark it and move onto the next loop.
@@ -66,7 +65,6 @@ namespace StringInputParseTester
if (isInsideBrackets) if (isInsideBrackets)
{ {
//If we are already inside of brackets then don't add anymore to the string just continue. //If we are already inside of brackets then don't add anymore to the string just continue.
removedCharacterOffset++;
continue; continue;
} }
isInsideBrackets = true; isInsideBrackets = true;
@@ -80,7 +78,6 @@ namespace StringInputParseTester
//IF we're not inside brackets then there is an imbalance so discard this parenthesis. //IF we're not inside brackets then there is an imbalance so discard this parenthesis.
if (!isInsideBrackets) if (!isInsideBrackets)
{ {
removedCharacterOffset++;
continue; continue;
} }
//Just gonna force parenthesis for now. //Just gonna force parenthesis for now.
@@ -95,7 +92,7 @@ namespace StringInputParseTester
if (!char.IsNumber(adItemText[currentCharacter]) && isPreviousCharWhiteSpace) if (!char.IsNumber(adItemText[currentCharacter]) && isPreviousCharWhiteSpace)
{ {
//Check to see if the character before the whitespace is a number. //Check to see if the character before the whitespace is a number.
if (char.IsNumber(cleanedInputString[currentCharacter - (2 + removedCharacterOffset)])) if (char.IsNumber(cleanedInputString[cleanedInputString.Length - 2]))
{ {
var abbreviations = new List<string>(); var abbreviations = new List<string>();
var words = new List<string>(); var words = new List<string>();
@@ -103,7 +100,7 @@ namespace StringInputParseTester
//Remove the last space if there are any abbreviations or words found. //Remove the last space if there are any abbreviations or words found.
if (abbreviations.Count > 0 || words.Count > 0) if (abbreviations.Count > 0 || words.Count > 0)
{ {
cleanedInputString = cleanedInputString.Remove(currentCharacter - (1 + removedCharacterOffset), 1); cleanedInputString = cleanedInputString.Remove(cleanedInputString.Length - 1, 1);
} }
//Begin checking to see how to place these items back into the final string. //Begin checking to see how to place these items back into the final string.
if (abbreviations.Count >= 1 && words.Count == 0) if (abbreviations.Count >= 1 && words.Count == 0)
@@ -149,7 +146,7 @@ namespace StringInputParseTester
else if (!char.IsNumber(adItemText[currentCharacter]) && char.IsLetter(adItemText[currentCharacter])) else if (!char.IsNumber(adItemText[currentCharacter]) && char.IsLetter(adItemText[currentCharacter]))
{ {
//IF the previous character is a number... //IF the previous character is a number...
if (char.IsNumber(cleanedInputString[currentCharacter - (1 + removedCharacterOffset)])) if (char.IsNumber(cleanedInputString[cleanedInputString.Length - 1]))
{ {
//Check to see the length of the string and determine if the word with the number needs to be capitalized. //Check to see the length of the string and determine if the word with the number needs to be capitalized.
var abbreviations = new List<string>(); var abbreviations = new List<string>();
@@ -199,10 +196,21 @@ namespace StringInputParseTester
//IF a number is found, and we're not inside brackets, check to see if there is an opening parenthesis and if there aren't create one. //IF a number is found, and we're not inside brackets, check to see if there is an opening parenthesis and if there aren't create one.
if (char.IsNumber(adItemText[currentCharacter])) if (char.IsNumber(adItemText[currentCharacter]))
{ {
cleanedInputString += adItemText[currentCharacter];
if (lastnumberStartingIndex == -1) if (lastnumberStartingIndex == -1)
{ {
lastnumberStartingIndex = currentCharacter - removedCharacterOffset; lastnumberStartingIndex = cleanedInputString.Length - 1; //This is index based.
} }
}
//Check for any allowed punctuation.
if (adItemText[currentCharacter] == '\'')
{
cleanedInputString += adItemText[currentCharacter];
}
//Check if the previous character is an "'".
else if (cleanedInputString[cleanedInputString.Length - 1] == '\'')
{
cleanedInputString += adItemText[currentCharacter]; cleanedInputString += adItemText[currentCharacter];
} }
//Since whitespace booleans are handled above, set the boolean for white spaces false. //Since whitespace booleans are handled above, set the boolean for white spaces false.
@@ -224,23 +232,23 @@ namespace StringInputParseTester
/// three (3) characters long or being exactly three characters long but having /// three (3) characters long or being exactly three characters long but having
/// zero (0) vowels. /// zero (0) vowels.
/// </summary> /// </summary>
/// <param name="stringToCheck">The string to determine whether or not its a word.</param> /// <param name="text">The string to determine whether or not its a word.</param>
/// <returns></returns> /// <returns></returns>
private bool IsWord(string stringToCheck) private bool IsWord(string text)
{ {
if (string.IsNullOrEmpty(stringToCheck)) return false; if (string.IsNullOrEmpty(text)) return false;
var isWord = true; var isWord = true;
//Most abbreviations do not have vowels in them so check to see if the "abbreviation" //Most abbreviations do not have vowels in them so check to see if the "abbreviation"
//isn't just a short word like "Box", as opposed to "lbs". //isn't just a short word like "Box", as opposed to "lbs".
char[] vowels = {'a', 'e', 'i', 'o', 'u', 'y'}; char[] vowels = {'a', 'e', 'i', 'o', 'u', 'y'};
//Count the number of vowels the word has. //Count the number of vowels the word has.
var vowelCount = stringToCheck.Count(x => vowels.Contains(x)); var vowelCount = text.Count(x => vowels.Contains(x));
//IF the string is exactly three (3) characters long and has more then zero (0) vowels then it is considered a word. //IF the string is exactly three (3) characters long and has more then zero (0) vowels then it is considered a word.
if (stringToCheck.Length == 3 && vowelCount == 0) if (text.Length == 3 && vowelCount == 0)
{ {
isWord = false; isWord = false;
} }
else if (stringToCheck.Length < 3) else if (text.Length < 3)
{ {
isWord = false; isWord = false;
} }
@@ -307,5 +315,25 @@ namespace StringInputParseTester
words[i] = CapitalizeFirstLetter(words[i]); words[i] = CapitalizeFirstLetter(words[i]);
} }
} }
public string FormatShit(string inputString)
{
var finalString = "";
var workingText = "";
//The (char[])null avoids creating a new object in memory.
var splitInput = inputString.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
foreach (var text in splitInput)
{
//Clear the working text to start building the next one to test.
workingText = "";
foreach (var character in text)
{
}
}
return finalString;
}
} }
} }