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:
@@ -1,19 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
public partial class FrmRegisterAdSpecial : Form
|
||||
{
|
||||
private readonly ToolTip _tt = new ToolTip();
|
||||
private bool _isUpdating;
|
||||
|
||||
public FrmRegisterAdSpecial()
|
||||
@@ -24,10 +18,9 @@ namespace AdvertsingProfitControl
|
||||
{
|
||||
Name = "AdSpecialsHeaderColumn",
|
||||
Text = @"Current Ad Special Grouping Keywords:",
|
||||
Width = adSpecialsListBox.Width - 5
|
||||
Width = Width / 2
|
||||
};
|
||||
adSpecialsListBox.Columns.Add(columnHeader);
|
||||
adSpecialsListBox.MouseMove += OnMouseMove;
|
||||
adSpecialsListBox.ItemSelectionChanged += UpdateAdSpecialTextBoxes;
|
||||
RefreshAdSpecialListing();
|
||||
}
|
||||
@@ -39,6 +32,7 @@ namespace AdvertsingProfitControl
|
||||
_isUpdating = true;
|
||||
deleteAdSpecialButton.Enabled = true;
|
||||
registerAdSpecialButton.Text = @"Update Ad Special";
|
||||
newAdSpecialLabel.Text = @"Update Ad Special:";
|
||||
}
|
||||
|
||||
private void NewAdSpecialTextChanged(object sender, EventArgs e)
|
||||
@@ -48,6 +42,7 @@ namespace AdvertsingProfitControl
|
||||
_isUpdating = false;
|
||||
descriptionTextBox.Text = string.Empty;
|
||||
registerAdSpecialButton.Text = @"Register Ad Special";
|
||||
newAdSpecialLabel.Text = @"Register New Ad Special:";
|
||||
}
|
||||
registerAdSpecialButton.Enabled = newAdSpecialTextBox.Text.Length > 0;
|
||||
}
|
||||
@@ -101,24 +96,11 @@ namespace AdvertsingProfitControl
|
||||
RefreshAdSpecialListing();
|
||||
}
|
||||
|
||||
private void OnMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
var box = sender as ListBox;
|
||||
if (box == null) return;
|
||||
var listBox = box;
|
||||
var point = new Point(e.X, e.Y);
|
||||
var hoverIndex = listBox.IndexFromPoint(point);
|
||||
if (hoverIndex >= 0 && hoverIndex < listBox.Items.Count)
|
||||
{
|
||||
// _tt.SetToolTip(listBox, _descriptions[hoverIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshAdSpecialListing()
|
||||
{
|
||||
adSpecialsListBox.Items.Clear();
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var adSpecials = db.AdSpecials.Select(x => x);
|
||||
var adSpecials = db.AdSpecials.Select(x => x).OrderBy(x => x.Name);
|
||||
foreach (var adSpecial in adSpecials)
|
||||
{
|
||||
var item = new ListViewItem
|
||||
@@ -135,15 +117,57 @@ namespace AdvertsingProfitControl
|
||||
|
||||
private void deleteAdSpecialButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO: Scan for Ad Specials that are in use by a table before removing.
|
||||
var item = adSpecialsListBox.SelectedItems[0];
|
||||
var adSpecial = (AdSpecial) item.Tag;
|
||||
var db = new AdvertisingProfitControlModel();
|
||||
var ad = db.AdSpecials.Single(x => x.Id == adSpecial.Id);
|
||||
db.AdSpecials.Remove(ad);
|
||||
db.SaveChanges();
|
||||
//Check to see if the ad special is used by other tables.
|
||||
if (ad.ActualSales.Count > 0)
|
||||
{
|
||||
//If so, display a warning to the user about the potential data loss.
|
||||
var result =
|
||||
MessageBox.Show(
|
||||
ad.ActualSales.Count +
|
||||
@" reference(s) to this keyword found. Do you want to delete these records? This can not be undone.",
|
||||
@"References to " + adSpecial.Name + @" Found", MessageBoxButtons.YesNoCancel,
|
||||
MessageBoxIcon.Question);
|
||||
if (result != DialogResult.Yes) return;
|
||||
//Perform the necessary operations to remove all references to the key word.
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
try
|
||||
{
|
||||
db.Projections.RemoveRange(db.Projections.Where(x => x.FkAdSpecialId == adSpecial.Id));
|
||||
db.Inventories.RemoveRange(db.Inventories.Where(x => x.FkAdSpecialId == adSpecial.Id));
|
||||
db.ActualSales.RemoveRange(db.ActualSales.Where(x => x.FkAdSpecialId == adSpecial.Id));
|
||||
db.AdSpecials.Remove(ad);
|
||||
db.SaveChanges();
|
||||
scope.Complete();
|
||||
informationLabel.Text = @"Removed '" + Environment.NewLine + adSpecial.Name +
|
||||
Environment.NewLine + @"' successfully.";
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
informationLabel.Text = @"Failed to remove " + Environment.NewLine + adSpecial.Name + @"." +
|
||||
Environment.NewLine + ex.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
db.AdSpecials.Remove(ad);
|
||||
db.SaveChanges();
|
||||
informationLabel.Text = @"Removed '" + Environment.NewLine + adSpecial.Name +
|
||||
Environment.NewLine + @"' successfully.";
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
informationLabel.Text = @"Failed to remove " + Environment.NewLine + adSpecial.Name + @"." + Environment.NewLine + ex.Message;
|
||||
}
|
||||
}
|
||||
RefreshAdSpecialListing();
|
||||
informationLabel.Text = @"Removed '" + Environment.NewLine + adSpecial.Name + Environment.NewLine + @"' successfully.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user