📄 delivery.cs
字号:
#region usings
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using HardwareDistributor.Business;
using HardwareDistributor.Properties;
using Microsoft.VisualBasic;
#endregion
namespace HardwareDistributor.UI
{
/// <summary>
/// UI layer form that presents final delivery information
/// </summary>
public partial class Delivery : Form
{
#region Members
private Guid _orderId;
private int _customerId;
#endregion
#region Contructors
/// <summary>
/// Capture OrderId and CustomerId in constructor
/// </summary>
/// <param name="orderId"></param>
/// <param name="customerId"></param>
public Delivery(Guid orderId, int customerId)
{
InitializeComponent();
// We are removing both the Control Box and the Minimize Box, so that we don't
// have to handle these in our code. This is not necessary in Windows Mobile Standard,
// but we are writing this code so that it works on all platforms without any changes
// or any recompiling.
this.ControlBox = false;
this.MinimizeBox = false;
this._orderId = orderId;
this._customerId = customerId;
}
#endregion
#region Event Handlers
/// <summary>
/// Close form and roll back state
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemCancel_Click(object sender, EventArgs e)
{
RevertOrderState();
this.Close();
}
/// <summary>
/// Go to the next state in the delivery wizard
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemFinish_Click(object sender, EventArgs e)
{
ShowDeliveryItemsForm();
}
/// <summary>
/// Load the Delivery form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Delivery_Load(object sender, EventArgs e)
{
try
{
Customer customer = GetCustomerDetails(_customerId);
if (null != customer)
{
DisplayCustomerDetails(customer);
}
}
catch (Exception ex)
{
Services.LogErrors(ex);
MessageBox.Show(Resources.CustomerDataDisplayError, Resources.SystemError);
}
}
/// <summary>
/// Launch Help
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void linkLabelHelp_Click(object sender, EventArgs e)
{
try
{
//Show Delivery Help
OnlineHelper myHelp = new OnlineHelper("delivery");
myHelp.ShowDialog();
//Free the resources of the help form
myHelp.Dispose();
this.Activate();
}
catch (Exception ex)
{
Services.LogErrors(ex);
MessageBox.Show(Resources.HelpDisplayError, Resources.SystemError);
}
}
/// Custom Handling for the back key
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BackKeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == System.Windows.Forms.Keys.Back))
{
// Back
// if the back key is hit, close this dialog
menuItemCancel_Click(sender, e);
}
}
#endregion
#region Methods
/// <summary>
/// revert bacl the order to a "loaded" state
/// </summary>
private void RevertOrderState()
{
try
{
//Update the Orders table to reflect a reversion to an Order State of Loaded (3)
Order myOrder = Services.GetOrder(_orderId);
myOrder.OrderState = OrderState.Loaded;
Services.SaveOrder(myOrder);
}
catch (Exception ex)
{
Services.LogErrors(ex);
MessageBox.Show(Resources.LoadingCancelError, Resources.SystemError);
}
}
/// <summary>
/// bring up the delivery items form
/// </summary>
private void ShowDeliveryItemsForm()
{
DeliveryItems deliveryItemsForm = new DeliveryItems(_orderId, _customerId);
DialogResult result = deliveryItemsForm.ShowDialog();
deliveryItemsForm.Dispose();
if (result == DialogResult.OK)
{
this.Close();
}
else
{
//bring back focus
this.Activate();
}
}
/// <summary>
/// Display Customre Details
/// </summary>
/// <param name="cutomer"></param>
private void DisplayCustomerDetails(Customer cutomer)
{
//Build a list of customer information
StringBuilder sb = new StringBuilder();
sb.Append(Resources.Name);
sb.Append(": ");
sb.Append(cutomer.CustomerName);
sb.Append(ControlChars.CrLf);
sb.Append(Resources.Street);
sb.Append(": ");
sb.Append(cutomer.StreetAddress);
sb.Append(ControlChars.CrLf);
sb.Append(Resources.City);
sb.Append(": ");
sb.Append(cutomer.City);
sb.Append(ControlChars.CrLf);
sb.Append(Resources.Street);
sb.Append(": ");
sb.Append(cutomer.StateProvince);
sb.Append(ControlChars.CrLf);
sb.Append(Resources.PostalCode);
sb.Append(": ");
sb.Append(cutomer.PostalCode);
sb.Append(ControlChars.CrLf);
sb.Append(Resources.ContactName);
sb.Append(": ");
sb.Append(cutomer.ContactName);
sb.Append(ControlChars.CrLf);
sb.Append(Resources.ContactPhone);
sb.Append(": ");
sb.Append(cutomer.ContactPhone);
//Set address textbox equal to the stringbuilder contents
AddressTextBox.Text = sb.ToString();
}
/// <summary>
/// Retrieve customer details from the data store
/// </summary>
/// <param name="_customerId"></param>
/// <returns></returns>
private Customer GetCustomerDetails(int _customerId)
{
Customer customer = null;
//Retrieve Customer List
List<Customer> _customers = GlobalCache.Instance.Customers;
//Iterate through Customer Collection
foreach (Customer cutomer in _customers)
{
//If the Customer object matches the CustomerId
if (cutomer.CustomerId == _customerId)
{
customer = cutomer;
break;
}
}
return customer;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -