Skip to content

Commit

Permalink
* Fixed issue where GetSales dialog is shown even if application is h…
Browse files Browse the repository at this point in the history
…idden.

* Changed notification message so it can represent all type of transactions.
* Fixed issue where transactions list refresh itself after every removal when user removes multiple transactions.
  • Loading branch information
ravibpatel committed Jun 3, 2017
1 parent 74f50ea commit a0bee99
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 56 deletions.
11 changes: 7 additions & 4 deletions Sales Manager/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 16 additions & 18 deletions Sales Manager/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace Sales_Manager
{
public partial class FormMain : Form
{
private bool _lock;

private readonly Timer _timer;

private GetSales _loadingForm;

#region Form Events

public FormMain()
Expand Down Expand Up @@ -286,6 +286,10 @@ private void Restore()
{
Show();
NativeMethods.ShowWindow(Handle, NativeMethods.SW_RESTORE);
if(_loadingForm != null)
{
_loadingForm.WindowState = FormWindowState.Normal;
}
}

private void PrepareChart()
Expand Down Expand Up @@ -448,8 +452,8 @@ private void removeTransactionToolStripMenuItem_Click(object sender, EventArgs e
{
var transaction = (Transaction)transactionObject;
transaction.Remove();
dateTimePicker_ValueChanged(sender, e);
}
dateTimePicker_ValueChanged(sender, e);
}
}
}
Expand Down Expand Up @@ -653,41 +657,35 @@ private void toolStripButtonRemove_Click(object sender, EventArgs e)

private void toolStripButtonUpdate_Click(object sender, EventArgs e)
{
if (!_lock)
if (_loadingForm == null)
{
_lock = true;
var totalTransactions = objectListViewTransactions.Items.Count;
var loadingForm = new GetSales(dateTimePickerFrom.Value, dateTimePickerTo.Value,
(Account)comboBoxAccounts.SelectedItem);
if (loadingForm.ShowDialog().Equals(DialogResult.OK))
_loadingForm = new GetSales(dateTimePickerFrom.Value, dateTimePickerTo.Value,
(Account)comboBoxAccounts.SelectedItem, WindowState != FormWindowState.Normal);
if (_loadingForm.ShowDialog(this).Equals(DialogResult.OK))
{
toolStripButtonEdit.Enabled = false;
toolStripButtonRemove.Enabled = false;
dateTimePicker_ValueChanged(sender, e);
GetCountriesList();
GetProductsList();
RefreshProductsComboBox();
var newSales = objectListViewTransactions.Items.Count - totalTransactions;
if (notifyIcon.Visible && newSales > 0)
var newTransactions = objectListViewTransactions.Items.Count - totalTransactions;
if (notifyIcon.Visible && newTransactions > 0)
{
notifyIcon.ShowBalloonTip(5, "New Sales", $"There are {newSales} new sales since you last updated.", ToolTipIcon.Info);
notifyIcon.ShowBalloonTip(5, "New Transactions", $"There are {newTransactions} new transactions since you last updated.", ToolTipIcon.Info);
}
_lock = false;
}
else
{
_lock = false;
if (!sender.Equals(_timer))
if (WindowState == FormWindowState.Normal)
{
MessageBox.Show(Resources.noInternetErrorMsg, Resources.noInternetErrorCaption,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
toolStripButtonUpdate_Click(sender, e);
}
}
_loadingForm = null;
}
}

Expand Down
20 changes: 10 additions & 10 deletions Sales Manager/GetSales.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 28 additions & 15 deletions Sales Manager/GetSales.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,44 @@ namespace Sales_Manager
{
public partial class GetSales : Form
{
public GetSales(DateTime fromDate, DateTime toDate, Account account)
public GetSales(DateTime fromDate, DateTime toDate, Account account, bool hide)
{
InitializeComponent();
HelperMethods.FixFonts(this);
var backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += delegate(object sender, DoWorkEventArgs args) {

if (hide)
{
StartPosition = FormStartPosition.CenterScreen;
WindowState = FormWindowState.Minimized;
}

var backgroundWorker = new BackgroundWorker()
{
WorkerReportsProgress = true
};

backgroundWorker.DoWork += delegate (object sender, DoWorkEventArgs args)
{
args.Result = Transaction.GetSales(fromDate, toDate, account, backgroundWorker);
};
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.ProgressChanged += BackgroundWorker_ProgressChanged;
backgroundWorker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs args)

backgroundWorker.ProgressChanged += delegate (object sender, ProgressChangedEventArgs args)
{
progressBar.Value = args.ProgressPercentage;
if (args.UserState.Equals(1))
{
progressBar.Style = ProgressBarStyle.Blocks;
labelInfo.Text = @"Calculating fees...";
}
};

backgroundWorker.RunWorkerCompleted += delegate (object sender, RunWorkerCompletedEventArgs args)
{
Close();
DialogResult = args.Result.Equals(false) ? DialogResult.Cancel : DialogResult.OK;
};
backgroundWorker.RunWorkerAsync();
}

private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
if (e.UserState.Equals(1)) {
progressBar.Style = ProgressBarStyle.Blocks;
labelInfo.Text = @"Calculating fees...";
}
backgroundWorker.RunWorkerAsync();
}
}
}
18 changes: 9 additions & 9 deletions Sales Manager/GetSales.resx
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,29 @@
<data name="&gt;&gt;progressBar.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="pictureBox1.Location" type="System.Drawing.Point, System.Drawing">
<data name="pictureBoxIcon.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 12</value>
</data>
<data name="pictureBox1.Size" type="System.Drawing.Size, System.Drawing">
<data name="pictureBoxIcon.Size" type="System.Drawing.Size, System.Drawing">
<value>48, 48</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="pictureBox1.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
<data name="pictureBoxIcon.SizeMode" type="System.Windows.Forms.PictureBoxSizeMode, System.Windows.Forms">
<value>CenterImage</value>
</data>
<data name="pictureBox1.TabIndex" type="System.Int32, mscorlib">
<data name="pictureBoxIcon.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="&gt;&gt;pictureBox1.Name" xml:space="preserve">
<value>pictureBox1</value>
<data name="&gt;&gt;pictureBoxIcon.Name" xml:space="preserve">
<value>pictureBoxIcon</value>
</data>
<data name="&gt;&gt;pictureBox1.Type" xml:space="preserve">
<data name="&gt;&gt;pictureBoxIcon.Type" xml:space="preserve">
<value>System.Windows.Forms.PictureBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;pictureBox1.Parent" xml:space="preserve">
<data name="&gt;&gt;pictureBoxIcon.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;pictureBox1.ZOrder" xml:space="preserve">
<data name="&gt;&gt;pictureBoxIcon.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="labelInfo.AutoSize" type="System.Boolean, mscorlib">
Expand Down

0 comments on commit a0bee99

Please sign in to comment.