📄 deliveryitems.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Status;
using HardwareDistributor.Properties;
namespace HardwareDistributor.UI
{
public partial class DeliveryItems : Form
{
int _itemsToDeliver;
Guid _orderId;
int _customerId;
private List<Business.OrderDetail> _orderDetails = null;
private List<Business.Inventory> _inventory = null;
private HardwareDistributor.Controls.GradientHeaders header;
private SystemState rotation = null;
public DeliveryItems(Guid orderId, int customerId)
{
InitializeComponent();
// Need to adjust the column width, so that we automatically adjust to different screen
// sizes and orientations.
AdjustColumns();
// 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;
// Create instance of the gradient header
header = new HardwareDistributor.Controls.GradientHeaders();
// Attach it to the listview
header.Attach(ref deliveryItemsListView);
this.Controls.Add(header);
}
/// <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 spacing;
spacing = 20;
header1Size = gx.MeasureString(columnHeaderQty.Text, deliveryItemsListView.Font).ToSize().Width + spacing;
header2Size = gx.MeasureString(columnHeaderItem.Text, deliveryItemsListView.Font).ToSize().Width + spacing;
header3Size = gx.MeasureString(columnHeaderPrice.Text, deliveryItemsListView.Font).ToSize().Width + spacing;
columnHeaderPrice.Width = 0;
columnHeaderInventoryId.Width = 0;
if (deliveryItemsListView.Width > header1Size + header2Size + header3Size + 4)
{
columnHeaderQty.Width = header1Size;
columnHeaderPrice.Width = header3Size;
columnHeaderItem.Width = deliveryItemsListView.Width - header1Size - header3Size - 4;
}
else
{
this.columnHeaderItem.Width = this.deliveryItemsListView.Width - this.columnHeaderQty.Width - 4;
}
}
/// <summary>
/// Load the Delivery Items form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DeliveryItems_Load(object sender, EventArgs e)
{
try
{
//Retrieve OrderDetailsCollection
_orderDetails = Business.Services.GetOrderDetails(_orderId);
//Retrieve InventoryCollection
_inventory = Business.Services.GetInventory();
string _hardwareName = string.Empty;
decimal _subTotal = 0;
decimal _totalPrice = 0;
//Iterate through OrderDetailsCollection
foreach (Business.OrderDetail orderDetailsItem in _orderDetails)
{
// get the line total
_subTotal = orderDetailsItem.Inventory.Price.Value * orderDetailsItem.Quantity.Value;
//Add the subtotals to get the total price for the order
_totalPrice += _subTotal;
//Add Quantity
ListViewItem lvi = new ListViewItem(orderDetailsItem.Quantity.ToString());
//Add Hardware Name
lvi.SubItems.Add(orderDetailsItem.Inventory.InventoryName);
//Add Price
lvi.SubItems.Add(_subTotal.ToString());
//Add Inventory Id
lvi.SubItems.Add(orderDetailsItem.InventoryId.ToString());
//Add ListView Items to ListView
deliveryItemsListView.Items.Add(lvi);
//Update column header
deliveryItemsListView.Columns[1].Text = Resources.Item + " $" + _totalPrice.ToString();
}
//This number will be compared later to see if order is complete
_itemsToDeliver = deliveryItemsListView.Items.Count;
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.CustomerDataDisplayError, Resources.SystemError);
}
}
/// <summary>
/// Go to the next state in the delivery wizard
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemNext_Click(object sender, EventArgs e)
{
try
{
//Test to see if any items exist in list view
if (deliveryItemsListView.Items.Count > 0)
{
//Count all the items that have been checked
ListView.ListViewItemCollection orderItems = deliveryItemsListView.Items;
int _checkedItems = 0;
foreach (ListViewItem item in orderItems)
{
if (item.Checked)
{
_checkedItems++;
}
}
//If the items checked equals the number of items to deliver then proceed
if (_checkedItems == _itemsToDeliver)
{
//Get the delivery signature
Form deliverySignatureForm = DeliverySignatureFormFactory.GetDeliverySignatureForm(_orderId, _customerId);
if (deliverySignatureForm.ShowDialog() == DialogResult.OK)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
deliverySignatureForm.Dispose();
}
else
{
MessageBox.Show(Resources.CheckAllItemsMessage, Resources.DeliveryError);
}
}
else
{
MessageBox.Show(Resources.NoDeliveryItemsMessage, Resources.DeliveryError);
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.CompletingDeliveryError, Resources.SystemError);
}
}
/// <summary>
/// Go to the last state in the delivery wizard
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemBack_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
// <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.DialogResult = DialogResult.Cancel;
this.Close();
}
}
/// <summary>
/// Handles the repaint command for the dialog
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DeliveryItems_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 (deliveryItemsListView.Width != header.Width)
{
AdjustColumns();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -