📄 deliveries.cs
字号:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace HardwareDistributor.UI
{
/// <summary>
/// UI layer form that displays deliveries that need to be made
/// </summary>
public partial class Deliveries : Form
{
public Deliveries()
{
InitializeComponent();
}
/// <summary>
/// Exit Deliveries form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemExit_Click(object sender, EventArgs e)
{
//Close form
this.Close();
}
/// <summary>
/// Fill the list view control with order
/// customer data
/// </summary>
private void FillListView()
{
Application.DoEvents();
//Retrieve OrderCollection
Business.OrderCollection _orders = Business.Services.GetOrders(false, Business.OrderState.Loaded);
//Clear the list view before filling
listView1.Items.Clear();
//Iterate through OrderCollection
foreach (Business.Order orderItem in _orders)
{
//Add OrderId
ListViewItem lvi = new ListViewItem(orderItem.OrderId.ToString());
//Add CustomerId
lvi.SubItems.Add(orderItem.CustomerName);
//Add Delivery Date
lvi.SubItems.Add(orderItem.DeliveryDate.ToShortDateString());
//Add Order State
lvi.SubItems.Add(orderItem.OrderState);
//Add CustomerId
lvi.SubItems.Add(orderItem.CustomerId.ToString());
//Add ListView Items to ListView
listView1.Items.Add(lvi);
}
}
/// <summary>
/// Load the Deliveries form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Deliveries_Load(object sender, EventArgs e)
{
try
{
//Fill the list view control with order and customer data
FillListView();
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error displaying orders to deliver", "System Error");
}
}
/// <summary>
/// Replicate with SQL Server 2005
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemSync_Click(object sender, EventArgs e)
{
Application.DoEvents();
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
try
{
//Test to see if Network is available
Application.DoEvents();
statusBar1.Text = "Checking network connectivity...";
Application.DoEvents();
if (Business.Services.GetConnectionStatus())
{
//Test to see if Replication URL is reachable
Application.DoEvents();
statusBar1.Text = "Testing IIS server...";
Application.DoEvents();
if (Business.Services.CheckReplicationUrl())
{
//Log Application and Device Metrics
Business.Services.LogAppState();
//Synchronize database changes
Application.DoEvents();
statusBar1.Text = "Synchronizing database...";
Application.DoEvents();
Business.Services.SyncWithDataSource();
//Refill list view with new data
FillListView();
}
else
{
//Replication URL isn't reachable
Application.DoEvents();
statusBar1.Text = "IIS server isn't available...";
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
}
}
else
{
//Network isn't available
Application.DoEvents();
statusBar1.Text = "Network isn't available...";
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error synchronizing database", "System Error");
}
Application.DoEvents();
statusBar1.Text = "";
Cursor.Current = Cursors.Default;
Application.DoEvents();
}
/// <summary>
/// Launch the Delivery form and pass in the
/// OrderId and CustomerId
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemDeliver_Click(object sender, EventArgs e)
{
try
{
//Retrieve a collection of items from the list view control
ListView.ListViewItemCollection checkedItems = listView1.Items;
//Iterate through the collection
foreach (ListViewItem item in checkedItems)
{
//Determine of item is checked
if (item.Checked)
{
//Get OrderId and CustomerId and pass to Delivery Screen
int _orderId = int.Parse(item.SubItems[0].Text);
int _customerId = int.Parse(item.SubItems[4].Text);
//Update the Orders table to reflect a new Order State of Out for Delivery (4)
Business.Services.UpdateOrderState(_orderId, Business.OrderState.OutForDelivery);
//Create the new Delivery form
Delivery delivery = new Delivery(_orderId, _customerId);
delivery.ShowDialog();
//Refresh the list view when the Delivery form closes
FillListView();
//Free the resources of the Delivery form
delivery.Dispose();
break;
}
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error loading Delivery screen", "System Error");
}
}
/// <summary>
/// Retrieve a route map from MapPoint
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemGetDirections_Click(object sender, EventArgs e)
{
try
{
Application.DoEvents();
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
//Determine Address of checked item
ListView.ListViewItemCollection checkedItems = listView1.Items;
//Iterate through the collection
foreach (ListViewItem item in checkedItems)
{
//Determine of item is checked
if (item.Checked)
{
//Get CustomerId
int _customerId = int.Parse(item.SubItems[4].Text);
//Retrieve Customer Collection
Business.CustomerCollection _customers = Business.GlobalCache.Instance.Customers;
//Iterate through Customer Collection
foreach (Business.Customer _customerItem in _customers)
{
//User Customer object with a matching CustomerId
if (_customerItem.CustomerId == _customerId)
{
Application.DoEvents();
statusBar1.Text = "Retrieving directions from MapPoint...";
Application.DoEvents();
//Call MapPoint
this.pictureBox1.Image = Business.Services.GetRouteMap(pictureBox1.Height, pictureBox1.Width, _customerItem.StreetAddress, _customerItem.City, _customerItem.StateProvince);
Application.DoEvents();
statusBar1.Text = "";
Application.DoEvents();
break;
}
}
break;
}
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error loading map from MapPoint web service", "System Error");
}
Application.DoEvents();
statusBar1.Text = "";
Cursor.Current = Cursors.Default;
Application.DoEvents();
}
/// <summary>
/// Launch Help
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void linkLabelHelp_Click_1(object sender, EventArgs e)
{
try
{
//Show Deliveries Help
Help.ShowHelp(this, @Business.GlobalCache.Instance.AppPath + "HardwareHelp.htm#deliveries");
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error displaying Help", "System Error");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -