📄 loading.cs
字号:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualBasic;
namespace HardwareDistributor.UI
{
/// <summary>
/// UI layer that displays staged items to load
/// </summary>
public partial class Loading : Form
{
int _orderId;
private Business.OrderDetailsCollection _orderDetails = null;
private Business.InventoryCollection _inventory = null;
private Business.TruckCollection _trucks = null;
/// <summary>
/// Pass in OrderId to constructor
/// </summary>
/// <param name="orderId"></param>
public Loading(int orderId)
{
InitializeComponent();
this._orderId = orderId;
}
/// <summary>
/// Cancel the Loading operation
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemCancel_Click(object sender, EventArgs e)
{
//Close form
this.Close();
}
/// <summary>
/// Load the form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Loading_Load(object sender, EventArgs e)
{
try
{
//Retrieve OrderDetailsCollection
_orderDetails = Business.Services.GetOrderDetails(_orderId);
//Retrieve InventoryCollection
_inventory = Business.Services.GetInventory();
//Retrieve Truck Collection
_trucks = Business.Services.GetTruckToLoad(_orderId);
txtTruckInfo.Text = "Truck Number: " + _trucks[0].TruckId.ToString() + ControlChars.CrLf + "License: " + _trucks[0].LicenseNumber + ControlChars.CrLf + "State/Province: " + _trucks[0].LicenseStateProvince;
int _quantity;
int _inventoryId;
string _hardwareName = string.Empty;
//Iterate through OrderDetailsCollection
foreach (Business.OrderDetails orderDetailsItem in _orderDetails)
{
//Get InventoryId
_inventoryId = orderDetailsItem.InventoryId;
//Get Quantity
_quantity = orderDetailsItem.Quantity;
//Iterate through InventoryCollection
foreach (Business.Inventory inventoryItem in _inventory)
{
//Search based on InventoryId
if (_inventoryId == inventoryItem.InventoryId)
{
//Get Hardware Name
_hardwareName = inventoryItem.InventoryName;
break;
}
}
//Add Quantity
ListViewItem lvi = new ListViewItem(_quantity.ToString());
//Add Hardware Name
lvi.SubItems.Add(_hardwareName);
//Add Inventory Id
lvi.SubItems.Add(_inventoryId.ToString());
//Add ListView Items to ListView
listView1.Items.Add(lvi);
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error displaying inventory items to load", "System Error");
}
}
/// <summary>
/// Add staged items to the loaded items listview
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLoad_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)
{
int _quantity = int.Parse(item.SubItems[0].Text);
string _hardwareName = item.SubItems[1].Text;
int _inventoryId = int.Parse(item.SubItems[2].Text);
//Add item to Loaded Items List View
//Add Quantity
ListViewItem lvi = new ListViewItem(_quantity.ToString());
//Add Hardware Name
lvi.SubItems.Add(_hardwareName);
//Add Inventory Id
lvi.SubItems.Add(_inventoryId.ToString());
//Add ListView Items to ListView
listView2.Items.Add(lvi);
//Remove item from list
listView1.Items.Remove(item);
break;
}
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error loading hardware items", "System Error");
}
}
/// <summary>
/// Finish loading the truck
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemFinish_Click(object sender, EventArgs e)
{
try
{
//Ensure that listview1 is empty and listview2 is greater than zero before proceeding
if (listView1.Items.Count == 0 && listView2.Items.Count > 0)
{
//Update the Orders table to reflect a new Order State of Loaded (3)
Business.Services.UpdateOrderState(_orderId, Business.OrderState.Loaded);
//Set Notification Balloon caption
notification1.Caption = "Order Loaded";
//Set Notification Balloon text
notification1.Text = "An order has been loaded on the truck. Please synchronize your device to inform the delivery driver that there's an order ready to be delivered.";
//Set duration that Notification Balloon will be visible
notification1.InitialDuration = 5;
//Set Notification Balloon to visible
Application.DoEvents();
notification1.Visible = true;
Application.DoEvents();
//Close form
this.Close();
}
else
{
MessageBox.Show("All staged items must be loaded on the truck", "Loading Error");
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error updating status of loaded hardware items", "System Error");
}
}
/// <summary>
/// Launch Help
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void linkLabelHelp_Click_1(object sender, EventArgs e)
{
try
{
//Show Loading Help
Help.ShowHelp(this, @Business.GlobalCache.Instance.AppPath + "HardwareHelp.htm#loading");
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show("Error displaying Help", "System Error");
}
}
/// <summary>
/// This event fires when the state of the Notification Balloon changes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void notification1_BalloonChanged(object sender, Microsoft.WindowsCE.Forms.BalloonChangedEventArgs e)
{
//If Balloon is not visible
if (!e.Visible)
{
//Dispose of that Notification Balloon object
((Microsoft.WindowsCE.Forms.Notification)sender).Dispose();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -