Marked as 'AdvertsingProfitControl' but located in a 'projects' folder. Added a new 'Add Record' form with a completely neww interface. This is the start of the final look of the the form that'd allow the user to add, update and remove records.

This commit is contained in:
2021-01-28 20:00:16 -06:00
parent 75061c9d51
commit 21eaae4d67
21 changed files with 1613 additions and 9813 deletions
+100
View File
@@ -1185,5 +1185,105 @@ namespace AdvertsingProfitControl
return wasSuccessful;
}
public bool RemoveAdItem(string adItemName)
{
var success = false;
var oleDbCommand = new OleDbCommand
{
CommandText = "DELETE FROM AdItem WHERE AdItem = ?"
};
oleDbCommand.Parameters.AddWithValue("AdItemName", adItemName);
oleDbCommand.Connection = _connectionobject;
try
{
_connectionobject.Open();
var rowsEffected = oleDbCommand.ExecuteNonQuery();
if(rowsEffected == 1)
{
success = true;
}
else if(rowsEffected > 1)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Info, "Removed redundant entry " + adItemName + " from the database successfully.");
success = true;
}
else
{
}
}
catch (OleDbException e)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to delete the ad item " + adItemName + " from the database.");
_logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
}
finally
{
_connectionobject.Close();
}
return success;
}
public bool AddNewItem(string adItemName)
{
var success = false;
var oleDbCommand = new OleDbCommand
{
CommandText = "INSERT INTO AdItem (AdItem) VALUES (?)"
};
oleDbCommand.Parameters.AddWithValue("AdItemName", adItemName);
oleDbCommand.Connection = _connectionobject;
var redundantancyCheck = new OleDbCommand
{
CommandText = "SELECT AdItem FROM AdItem WHERE AdItem = ?"
};
redundantancyCheck.Parameters.AddWithValue("AdItemName", adItemName);
redundantancyCheck.Connection = _connectionobject;
try
{
_connectionobject.Open();
using(var reader = redundantancyCheck.ExecuteReader())
{
var rows = 0;
while(reader != null && reader.Read())
{
rows++;
}
if(rows == 0)
{
var rowsEffected = oleDbCommand.ExecuteNonQuery();
if (rowsEffected == 1)
{
success = true;
}
else
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to insert new ad item " + adItemName + ".");
}
}
else
{
success = true;
_logConsole.WriteToLog(FrmLogConsole.Level.Debug, "Ad Item " + adItemName + " found with " + rows + " row(s).");
}
}
}
catch (OleDbException e)
{
_logConsole.WriteToLog(FrmLogConsole.Level.Error, "Failed to add the new ad item " + adItemName + " to the database.");
_logConsole.WriteToLog(FrmLogConsole.Level.Error, e.Message);
}
finally
{
_connectionobject.Close();
}
return success;
}
}
}