📄 deliveries.cs
字号:
{
Application.DoEvents();
DisplayStatus(Resources.GettingDirectionsMessage, 0);
Application.DoEvents();
// go to the directions window
Directions directions = new Directions(_customerId);
directions.ShowDialog();
directions.Dispose();
this.Activate();
Application.DoEvents();
}
else
{
DisplayStatus(Resources.NetworkUnavailableMessage, 1000);
}
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.MapLoadError, Resources.SystemError);
}
finally
{
ClearStatus();
}
}
/// <summary>
/// Launch Help
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void linkLabelHelp_Click(object sender, EventArgs e)
{
try
{
//Show Deliveries Help
OnlineHelper myHelp = new OnlineHelper("deliveries");
myHelp.ShowDialog();
//Free the resources of the help form
myHelp.Dispose();
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.HelpDisplayError, Resources.SystemError);
}
}
/// <summary>
/// Handle the key down event for the listview, so that we can set focus to the next control
/// when we hit the first or last item in the list.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OrdersListView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up &&
(OrdersListView.Items.Count == 0 ||
(OrdersListView.SelectedIndices.Count > 0 && OrdersListView.SelectedIndices[0] == 0)))
{
e.Handled = true;
this.SelectNextControl(OrdersListView, false, true, false, true);
}
else if (e.KeyCode == Keys.Down &&
(OrdersListView.Items.Count == 0 ||
(OrdersListView.SelectedIndices.Count > 0 &&
(OrdersListView.SelectedIndices[0] == (OrdersListView.Items.Count - 1)))))
{
e.Handled = true;
this.SelectNextControl(OrdersListView, true, true, false, true);
}
}
// <summary>
/// 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
this.Close();
}
}
/// <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
RefreshOrdersListView();
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.OrderDisplayError, Resources.SystemError);
}
}
/// <summary>
/// Handles the repaint command for the dialog
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Deliveries_Paint(object sender, PaintEventArgs e)
{
// if the width of the listview no longer matches the width of the
// headers, then a rotation happened, so we need to adjust the
// width of all the columns
if (OrdersListView.Width != header.Width)
{
AdjustColumns();
}
}
#endregion
#region Methods
/// <summary>
/// Automatically adjust the column widths based on the width of the screen
/// if the screen can show extra columns, show them.
/// </summary>
private void AdjustColumns()
{
System.Drawing.Graphics gx = this.CreateGraphics();
int header1Size;
int header2Size;
int header3Size;
int header4Size;
int spacing;
spacing = 20;
header1Size = gx.MeasureString(columnHeaderOrderId.Text, OrdersListView.Font).ToSize().Width + spacing;
header2Size = gx.MeasureString(columnHeaderCustomer.Text, OrdersListView.Font).ToSize().Width + spacing;
header3Size = gx.MeasureString(columnHeaderDelivery.Text, OrdersListView.Font).ToSize().Width + spacing;
header4Size = gx.MeasureString(columnHeaderState.Text, OrdersListView.Font).ToSize().Width + spacing;
columnHeaderState.Width = 0;
columnHeaderDelivery.Width = 0;
if (OrdersListView.Width > header1Size + header2Size + header3Size + header4Size + 4)
{
columnHeaderOrderId.Width = header1Size;
columnHeaderDelivery.Width = header3Size;
columnHeaderState.Width = header4Size;
columnHeaderCustomer.Width = OrdersListView.Width - header1Size - header3Size - header4Size - 4;
}
else if (OrdersListView.Width > header1Size + header2Size + header3Size + 4)
{
columnHeaderOrderId.Width = header1Size;
columnHeaderDelivery.Width = header3Size;
columnHeaderCustomer.Width = OrdersListView.Width - header1Size - header3Size - 4;
}
else
{
this.columnHeaderCustomer.Width = this.OrdersListView.Width - this.columnHeaderOrderId.Width - 4;
}
}
/// <summary>
/// insert order item into the listview
/// </summary>
/// <param name="currentOrder">order object</param>
private void InsertOrderIntoList(Order currentOrder)
{
//Add OrderId
ListViewItem item = new ListViewItem(currentOrder.DisplayId.ToString());
//Add Customer Name
item.SubItems.Add(currentOrder.Customer.CustomerName.Trim());
//Add Delivery Date
item.SubItems.Add(currentOrder.DeliveryDate.Value.ToShortDateString());
//Add Order State
item.SubItems.Add(currentOrder.OrderState.ToString());
//Add CustomerId
item.SubItems.Add(currentOrder.CustomerId.ToString());
//Add CustomerId
item.SubItems.Add(currentOrder.OrderId.ToString());
//insert order
OrdersListView.Items.Add(item);
}
/// <summary>
/// Fill the list view control with order
/// customer data
/// </summary>
private void RefreshOrdersListView()
{
Application.DoEvents();
//Retrieve OrderCollection
List<Order> _orders = Business.Services.GetOrders(false, Business.OrderState.Loaded);
//Clear the list view before filling
OrdersListView.Items.Clear();
//Iterate through OrderCollection
foreach (Business.Order orderItem in _orders)
{
InsertOrderIntoList(orderItem);
}
}
/// <summary>
/// attach the gradient control to the list view
/// </summary>
private void AttachHeader()
{
// Create instance of the gradient header
header = new HardwareDistributor.Controls.GradientHeaders();
// Attach it to the listview
header.Attach(ref OrdersListView);
this.Controls.Add(header);
}
/// <summary>
/// Display status in form. Wait for the specified timeout so that the user can see the message
/// before returning
/// </summary>
/// <param name="statusText"></param>
/// <param name="timeout"></param>
private void DisplayStatus(string statusText, int timeout)
{
//Network isn't available
statusBarLabel.Visible = true;
statusBarLabel.Text = statusText;
Application.DoEvents();
System.Threading.Thread.Sleep(timeout);
Application.DoEvents();
}
/// <summary>
/// clear the status of the form.
/// </summary>
private void ClearStatus()
{
statusBarLabel.Text = string.Empty;
statusBarLabel.Visible = false;
}
/// <summary>
/// sends notification to the warehouse role that the order has been placed
/// </summary>
/// <param name="myOrder"></param>
private void SendNotification()
{
//get the address for Warehouse role
List<Role> roles = Business.Services.GetRoles();
//find the email address for the WareHouse role
string emailAddress = string.Empty;
foreach (Role role in roles)
{
if (role.RoleName.Trim().CompareTo("Warehouse") == 0)
{
emailAddress = role.EmailAddress;
break;
}
}
if (!string.IsNullOrEmpty(emailAddress))
{
NotificationAgent.Instance.SendMessage(emailAddress, "SYNC", null);
}
else
{
throw new ApplicationException("Could not find email address for next role");
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -