Created forms to allow the management of ad items, suppliers and ad special keywords. Updated the database migration tool to include the ad special table. Cleaned up the main form's code and did a slight touch up of the interface.

This commit is contained in:
2017-04-11 02:26:04 -05:00
parent 09508aa16c
commit 62a2c0f80e
15 changed files with 1443 additions and 303 deletions
@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using System.Windows.Forms;
@@ -113,6 +107,18 @@ namespace AdvertsingProfitControl
db.Suppliers.Add(temp);
db.SaveChanges();
}
var adSpecials = GetAdSpecials();
foreach (var adSpecial in adSpecials)
{
var db = new AdvertisingProfitControlModel();
if(db.AdSpecials.Any(x => x.Name == adSpecial)) continue;
var tempAd = new AdSpecial
{
Name = adSpecial
};
db.AdSpecials.Add(tempAd);
db.SaveChanges();
}
foreach (var date in datesToConvertListBox.Items)
{
var oldDateId = GetDateIdByDateString(date.ToString());
@@ -145,30 +151,7 @@ namespace AdvertsingProfitControl
{
db.WeekEndingDates.Add(date);
}
//oleDbConnection.Open();
//oleDbTransaction = oleDbConnection.BeginTransaction();
//oleDbCommand.Transaction = oleDbTransaction;
////Get the date ID for the date string
//oleDbCommand.CommandText = "INSERT INTO WeekEnding (EndOfWeekDate) VALUES (?)";
//oleDbCommand.Parameters.AddWithValue("DateString", dateString);
//var rowsEffected = oleDbCommand.ExecuteNonQuery();
//oleDbCommand.Parameters.Clear();
//if (rowsEffected == 0)
//{
// oleDbTransaction.Rollback();
// MessageBox.Show(@"Failed on date");
// return;
//}
//oleDbCommand.CommandText = "SELECT WeekEnding.ID FROM WeekEnding WHERE EndOfWeekDate = ?";
//oleDbCommand.Parameters.AddWithValue("Date", dateString);
//var reader = oleDbCommand.ExecuteReader();
//oleDbCommand.Parameters.Clear();
//var dateId = 0;
//while (reader != null && reader.Read())
//{
// dateId = int.Parse(reader[0].ToString());
//}
//reader?.Close();
var adSpecialId = -1;
for (var rowIndex = 0; rowIndex < projections.Rows.Count; rowIndex++)
{
var projectionedSale = new Projection();
@@ -197,34 +180,29 @@ namespace AdvertsingProfitControl
projectionedSale.TotalProfitReturn = decimal.Parse(projections.Rows[rowIndex][6].ToString());
projectionedSale.FkAdItemId = db.AdItems.First(x => x.Id == adItemId).Id;
projectionedSale.RowAttribute = int.Parse(projections.Rows[rowIndex][7].ToString());
projectionedSale.FkAdSpecialId = (int) projections.Rows[rowIndex][8];
if ((int) projections.Rows[rowIndex][8] == 0 && adSpecialId == -1)
{
projectionedSale.FkAdSpecialId = null;
}
else
{
if ((int) (projections.Rows[rowIndex][8]) == 0)
{
projectionedSale.FkAdSpecialId = adSpecialId;
}
else
{
adSpecialId = (int) projections.Rows[rowIndex][8];
projectionedSale.FkAdSpecialId = (int) projections.Rows[rowIndex][8];
}
}
projectionedSale.RowPosition = rowIndex + 1;
projectionedSale.FkDateId = date.Id;
db.Projections.Add(projectionedSale);
//Get the ID number of the ad item.
// //Get the ID number of the ad item.
// var adItemId = int.Parse(RetrieveAdItemId(projections.Rows[rowIndex][0].ToString()));
// //Get the group name of the ad special its in.
// adspecialId = GetAdSpecialId(int.Parse(projections.Rows[rowIndex][8].ToString()));
// oleDbCommand.CommandText =
// "INSERT INTO Projections (Sold, SalePrice, TotalSales, Cost, ProfitReturn, TotalProfitReturn, FK_AdItemID, RowAttribute, FK_AdSpecialGroupName, RowPosition, FK_DateID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
// //SELECT AdItem.AdItem, APC.ProjectionSold, APC.ProjectionSalePrice, APC.ProjectionTotalSales, APC.ProjectionCost, APC.ProjectionProfitReturn, APC.ProjectionTotalProfitReturn, APC.RowAttribute, APC.FK_GroupID FROM (AdItem INNER JOIN APC ON AdItem.ID = APC.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC
// oleDbCommand.Parameters.AddWithValue("Sold", projections.Rows[rowIndex][1]);
// oleDbCommand.Parameters.AddWithValue("SalesPrice", projections.Rows[rowIndex][2]);
// oleDbCommand.Parameters.AddWithValue("TotalSales", projections.Rows[rowIndex][3]);
// oleDbCommand.Parameters.AddWithValue("Cost", projections.Rows[rowIndex][4]);
// oleDbCommand.Parameters.AddWithValue("ProfitReturn", projections.Rows[rowIndex][5]);
// oleDbCommand.Parameters.AddWithValue("TotalProfitReturn", projections.Rows[rowIndex][6]);
// oleDbCommand.Parameters.AddWithValue("adItemID", adItemId);
// oleDbCommand.Parameters.AddWithValue("RowAttribute",
// int.Parse(projections.Rows[rowIndex][7].ToString()));
// oleDbCommand.Parameters.AddWithValue("adSpecialID", adspecialId);
// oleDbCommand.Parameters.AddWithValue("RowPosition", (rowIndex + 1));
// oleDbCommand.Parameters.AddWithValue("dateID", dateId);
// oleDbCommand.ExecuteNonQuery();
// oleDbCommand.Parameters.Clear();
}
//inventory
adSpecialId = -1;
for (var i = 0; i < inventory.Rows.Count; i++)
{
var inventoryObject = new Inventory();
@@ -243,40 +221,39 @@ namespace AdvertsingProfitControl
inventoryObject.EndingInventory = inventory.Rows[i][4].ToString();
inventoryObject.FkAdItemId = adItemId;
inventoryObject.RowAttribute = int.Parse(inventory.Rows[i][5].ToString());
inventoryObject.FkAdSpecialId = int.Parse(inventory.Rows[i][6].ToString());
if ((int)inventory.Rows[i][6] == 0 && adSpecialId == -1)
{
inventoryObject.FkAdSpecialId = null;
}
else
{
if ((int)(inventory.Rows[i][6]) == 0)
{
inventoryObject.FkAdSpecialId = adSpecialId;
}
else
{
adSpecialId = (int)inventory.Rows[i][6];
inventoryObject.FkAdSpecialId = (int)inventory.Rows[i][6];
}
}
inventoryObject.RowPosition = i + 1;
inventoryObject.FkDateId = date.Id;
db.Inventories.Add(inventoryObject);
// var adItemId = int.Parse(RetrieveAdItemId(inventory.Rows[i][0].ToString()));
// adspecialId = GetAdSpecialId(int.Parse(inventory.Rows[i][6].ToString()));
// oleDbCommand.CommandText =
// "INSERT INTO Inventory (BeginningInventory, Received, TotalInventory, EndingInventory, FK_AdItemID, RowAttribute, FK_AdSpecialGroupName, RowPosition, FK_DateID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
// //"SELECT AdItem.AdItem, APC.BeginingInventory, APC.Received, APC.TotalInventory, APC.EndingInventory, APC.RowAttribute, APC.FK_GroupID FROM (AdItem INNER JOIN APC ON AdItem.ID = APC.FK_AdItemID) WHERE FK_DateID = ? ORDER BY RowPosition ASC"
// oleDbCommand.Parameters.AddWithValue("BeginningInventory", inventory.Rows[i][1].ToString());
// oleDbCommand.Parameters.AddWithValue("Received", inventory.Rows[i][2].ToString());
// oleDbCommand.Parameters.AddWithValue("TotalInventory", inventory.Rows[i][3].ToString());
// oleDbCommand.Parameters.AddWithValue("EndingInventory", inventory.Rows[i][4].ToString());
// oleDbCommand.Parameters.AddWithValue("AdItemID", adItemId);
// oleDbCommand.Parameters.AddWithValue("RowAttribute", int.Parse(inventory.Rows[i][5].ToString()));
// oleDbCommand.Parameters.AddWithValue("FK_AdSpecialGroup", adspecialId);
// oleDbCommand.Parameters.AddWithValue("RowPosition", (i + 1));
// oleDbCommand.Parameters.AddWithValue("DateID", dateId);
// oleDbCommand.ExecuteNonQuery();
// oleDbCommand.Parameters.Clear();
}
//actual sales
adSpecialId = -1;
for (var rowIndex = 0; rowIndex < actualSales.Rows.Count; rowIndex++)
{
var actualSale = new ActualSale();
//Get the ID number of the ad item.
AdItem adItem;
var adItemId = 0;
var spam = TextFormat.FormatAdItemText(actualSales.Rows[rowIndex][0].ToString());
if (db.AdItems.Any(x => x.Name == spam))
{
//Exists
adItem = db.AdItems.First(x => x.Name == spam);
var adItem = db.AdItems.First(x => x.Name == spam);
adItemId = adItem.Id;
}
//adspecialId = GetAdSpecialId(int.Parse(actualSales.Rows[rowIndex][8].ToString()));
@@ -293,7 +270,22 @@ namespace AdvertsingProfitControl
actualSale.TotalProfitReturn = decimal.Parse(actualSales.Rows[rowIndex][6].ToString());
actualSale.FkAdItemId = adItemId;
actualSale.RowAttribute = int.Parse(actualSales.Rows[rowIndex][7].ToString());
actualSale.FkAdSpecialId = (int) actualSales.Rows[rowIndex][8];
if ((int)actualSales.Rows[rowIndex][8] == 0 && adSpecialId == -1)
{
actualSale.FkAdSpecialId = null;
}
else
{
if ((int)(projections.Rows[rowIndex][8]) == 0)
{
actualSale.FkAdSpecialId = adSpecialId;
}
else
{
adSpecialId = (int)actualSales.Rows[rowIndex][8];
actualSale.FkAdSpecialId = (int)actualSales.Rows[rowIndex][8];
}
}
actualSale.RowPosition = rowIndex + 1;
actualSale.FkDateId = date.Id; //db.WeekEndingDates.First(x => x.Id == dateId);
//oleDbCommand.Parameters.AddWithValue("Sold", actualSales.Rows[rowIndex][1]);
@@ -472,6 +464,30 @@ namespace AdvertsingProfitControl
return adItems;
}
public List<string> GetAdSpecials()
{
var adItems = new List<string>();
var oleDbCommand = new OleDbCommand
{
CommandText = "SELECT AdSpecialName.AdSpecialName FROM AdSpecialName"
};
var connection = new OleDbConnection(_connectionString);
oleDbCommand.Connection = connection;
using (connection)
{
using (oleDbCommand)
{
connection.Open();
var reader = oleDbCommand.ExecuteReader();
while (reader != null && reader.Read())
{
adItems.Add(reader[0].ToString());
}
}
}
return adItems;
}
public int GetSupplierId(string supplierName)
{
var supplier = new Supplier();