📄 neworder.cs
字号:
(ordersListView.SelectedIndices.Count > 0 &&
(ordersListView.SelectedIndices[0] == (ordersListView.Items.Count - 1)))))
{
e.Handled = true;
this.SelectNextControl(ordersListView, true, true, false, true);
}
}
/// <summary>
/// Launch Help
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void linkLabelHelp_Click(object sender, EventArgs e)
{
try
{
//Show New Order Help
OnlineHelper myHelp = new OnlineHelper("neworder");
myHelp.ShowDialog();
//Free the resources of the help form
myHelp.Dispose();
}
catch (Exception ex)
{
Services.LogErrors(ex);
MessageBox.Show(Resources.HelpDisplayError, Resources.SystemError);
}
}
// <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();
}
}
private void NewOrder_Closing(object sender, CancelEventArgs e)
{
//remove the hooks for synchronization
ClientSyncAgent.Instance.BakgroundSyncBegin -= ClientSyncAgent_SyncBegin;
ClientSyncAgent.Instance.BakgroundSyncEnd -= ClientSyncAgent_SyncEnd;
}
#endregion
#region Methods
/// <summary>
/// Refresh Customer List
/// </summary>
private void RefreshCustomerList()
{
//Retrieve CustomerCollection
_customers = GlobalCache.Instance.Customers;
//Display customer information
CustomerComboBox.DisplayMember = "CustomerName";
CustomerComboBox.ValueMember = "CustomerId";
CustomerComboBox.DataSource = _customers;
}
/// <summary>
/// Set Default Delivery Date
/// </summary>
private void SetDefaultDeliveryDate()
{
//Set default delivery date to tomorrow
deliveryDateTimePicker.MinDate = System.DateTime.Today.AddDays(1);
}
/// <summary>
/// attach the event handlers to respond the sync events
/// </summary>
private void HandleBackgroundSync()
{
ClientSyncAgent.Instance.BakgroundSyncBegin += new EventHandler(ClientSyncAgent_SyncBegin);
ClientSyncAgent.Instance.BakgroundSyncEnd += new EventHandler(ClientSyncAgent_SyncEnd);
}
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>
/// Add an item to the list of items in the order
/// </summary>
/// <param name="inventory"></param>
/// <param name="quantity"></param>
public bool AddInventoryItem(Inventory inventory, int quantity)
{
bool success = false;
try
{
//Get item price
decimal _price = quantity * inventory.Price.Value;
//Get total price
_totalPrice += _price;
//Verify there's enough hardware left in stock
if (inventory.InStock >= quantity)
{
//Add Quantity
ListViewItem lvi = new ListViewItem(quantity.ToString());
//Add Inventory Name
lvi.SubItems.Add(inventory.InventoryName.Trim());
//Add Inventory ID
lvi.SubItems.Add(inventory.InventoryId.ToString());
//Add ListView Items to ListView
ordersListView.Items.Add(lvi);
//Update column header
ordersListView.Columns[1].Text = Resources.Hardware + " $ " + _totalPrice.ToString();
success = true;
}
else
{
MessageBox.Show(Resources.QtyExceedsStockDetailedMessage, Resources.QtyExceedsStockMessage);
}
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.AddingItemsError, Resources.SystemError);
}
return success;
}
/// <summary>
/// Removes inventory item from list and recalculate the total
/// </summary>
/// <param name="item"></param>
private void RemoveInventoryItem(ListViewItem item)
{
int _qty = int.Parse(item.SubItems[0].Text);
int _inventoryId = int.Parse(item.SubItems[2].Text);
//Get price based on InventoryId
decimal _price = Services.GetPrice(_inventoryId);
//Get Subtotal based on Qty
decimal _subTotal = _qty * _price;
//Subtract price from Total Price
_totalPrice -= _subTotal;
//Update column header
ordersListView.Columns[1].Text = Resources.Hardware + " $ " + _totalPrice.ToString();
//Remove item from list
ordersListView.Items.Remove(item);
}
/// <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>
/// create the order in client DB
/// </summary>
private void CreateOrder()
{
try
{
//Get Customer
Customer customer = (Customer)CustomerComboBox.SelectedItem;
//Get Delivery Date
string deliveryDate = deliveryDateTimePicker.Value.ToShortDateString();
//Get collection of items in ListView
ListView.ListViewItemCollection orderItems = ordersListView.Items;
Order myOrder = GetOrderDetails(customer.CustomerId.Value,
deliveryDate, orderItems);
Business.Services.SaveOrder(myOrder);
}
catch (Exception ex)
{
throw new Utilities.WrapperException(Resources.OrderCreationError, ex);
}
}
/// <summary>
/// collates the order details and returns an order object
/// </summary>
/// <param name="customerId"></param>
/// <param name="deliveryDate"></param>
/// <param name="orderItems"></param>
/// <returns></returns>
private static Order GetOrderDetails(int customerId, string deliveryDate, ListView.ListViewItemCollection orderItems)
{
Order order = new Order();
order.OrderState = OrderState.Placed;
order.DeliveryDate = Convert.ToDateTime(deliveryDate);
order.CustomerId = customerId;
//attach order details
foreach (ListViewItem item in orderItems)
{
OrderDetail detail = new OrderDetail();
detail.InventoryId = int.Parse(item.SubItems[2].Text);
detail.Quantity = int.Parse(item.SubItems[0].Text);
order.OrderDetails.Add(detail);
}
return order;
}
private void ShowNotification()
{
HtmlFormEx notificationsForm = new HtmlFormEx(Resources.CustomerService,
Resources.NewOrder,
Resources.SyncAfterNewOrderMessage,
string.Empty);
notificationsForm.ShowDialog();
notificationsForm.Dispose();
//bring back focus
this.Activate();
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -