📄 customerservice.cs
字号:
// 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 = 30;
header1Size = gx.MeasureString(columnHeaderOrderId.Text, OrdersListView.Font).ToSize().Width + spacing;
header2Size = gx.MeasureString(columnHeaderCustomer.Text, OrdersListView.Font).ToSize().Width + spacing;
header3Size = gx.MeasureString(columnHeaderState.Text, OrdersListView.Font).ToSize().Width + spacing;
header4Size = gx.MeasureString(columnHeaderDeliveryDate.Text, OrdersListView.Font).ToSize().Width + spacing;
columnHeaderDeliveryDate.Width = 0;
columnHeaderState.Width = 0;
if (OrdersListView.Width > header1Size + header2Size + header3Size + header4Size + 4)
{
columnHeaderOrderId.Width = header1Size;
columnHeaderDeliveryDate.Width = header4Size;
columnHeaderState.Width = header3Size;
columnHeaderCustomer.Width = OrdersListView.Width - header1Size - header3Size - header4Size - 4;
}
else if (OrdersListView.Width > header1Size + header2Size + header3Size + 4)
{
columnHeaderOrderId.Width = header1Size;
columnHeaderState.Width = header3Size;
columnHeaderCustomer.Width = OrdersListView.Width - header1Size - header3Size - 4;
}
else
{
this.columnHeaderCustomer.Width = this.OrdersListView.Width - this.columnHeaderOrderId.Width - 4;
}
}
/// <summary>
/// attach handlers for the synchronization events
/// </summary>
private void HandleBackgroundSync()
{
ClientSyncAgent.Instance.BakgroundSyncBegin += new EventHandler(ClientSyncAgent_SyncBegin);
ClientSyncAgent.Instance.BakgroundSyncEnd += new EventHandler(ClientSyncAgent_SyncEnd);
}
/// <summary>
/// Locks the screen and waits for the synchronization to end
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ClientSyncAgent_SyncBegin(object sender, EventArgs e)
{
//to deal with background thread
this.Invoke((EventHandler)delegate(object senderInner, EventArgs eInner)
{
Application.DoEvents();
Cursor.Current = Cursors.WaitCursor;
this.DisplayStatus(Resources.SyncDbMessage, 0);
Application.DoEvents();
}
);
}
/// <summary>
/// refreshes the orders and unlocks the screen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ClientSyncAgent_SyncEnd(object sender, EventArgs e)
{
this.Invoke((EventHandler)delegate(object sender1, EventArgs e1)
{
//refresh on-screen data
Application.DoEvents();
RefreshOrdersListView();
Application.DoEvents();
//clear the message
ClearStatus();
//reset the cursor back to the usual
Cursor.Current = Cursors.Default;
Application.DoEvents();
});
}
/// <summary>
/// attaches the gradient header 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>
/// cancels an order in the DB
/// </summary>
/// <param name="orderId">order identifier</param>
private void UpdateOrder(Guid orderId)
{
try
{
//Cancel Order
Business.Services.CancelOrder(orderId);
}
catch (Exception ex)
{
throw new Utilities.WrapperException(Resources.RemoveOrderError, ex);
}
}
/// <summary>
/// brings up the new order form to collect order information
/// </summary>
private void ShowNewOrderForm()
{
//if we already have an instance of the form, use it,
//else new up one and use that
NewOrder newOrder = new NewOrder();
newOrder.ShowDialog();
//Free the resources of the New Order form
newOrder.Dispose();
//bring back focus to this form
this.Activate();
}
/// <summary>
/// Fill the list view control with orders
/// and their associated status
/// </summary>
private void RefreshOrdersListView()
{
//start with fresh list
OrdersListView.Items.Clear();
//Retrieve OrderCollection
List<Order> orders = Business.Services.GetOrders(false, Business.OrderState.Active);
//check against empty list
if (null != orders && orders.Count > 0)
{
//add each order into the list view
foreach (Order currentOrder in orders)
{
// only add non cancelled orders
if (currentOrder.OrderState != OrderState.Cancelled)
{
InsertOrderIntoList(currentOrder);
}
}
}
}
/// <summary>
/// insert order item into the listview
/// </summary>
/// <param name="currentOrder">order object</param>
private void InsertOrderIntoList(Order currentOrder)
{
//Display Id
ListViewItem item = new ListViewItem(currentOrder.DisplayId.ToString());
//CustomerId
item.SubItems.Add(currentOrder.Customer.CustomerName.Trim());
//Order State
item.SubItems.Add(Business.Services.TranslateOrderState(currentOrder.OrderState));
//Delivery Date
item.SubItems.Add(currentOrder.DeliveryDate.Value.ToShortDateString());
//Order Id
item.SubItems.Add(currentOrder.OrderId.ToString());
//insert order
OrdersListView.Items.Add(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;
}
private ListViewItem GetSelectedOrder()
{
ListViewItem selectedOrder = null;
//Retrieve a collection of items from the list view control
ListView.ListViewItemCollection selectedItems = OrdersListView.Items;
//Iterate through the collection
foreach (ListViewItem item in selectedItems)
{
//Determine of item is selected
if (item.Selected)
{
selectedOrder = item;
break;
}
}
return selectedOrder;
}
/// <summary>
/// Display formatted order details
/// </summary>
/// <param name="orderId">order identifier</param>
/// <param name="customer">customer name</param>
private void DisplayOrderDetails(Guid orderId, string customer, string state)
{
try
{
//Retrieve OrderDetailsCollection
List<OrderDetail> orderDetailList = Business.Services.GetOrderDetails(orderId);
StringBuilder sb = new StringBuilder();
//Build display string
foreach (Business.OrderDetail orderDetailsItem in orderDetailList)
{
//Add quantity, hardware item, and in stock amount to stringbuilder
sb.Append(Resources.Qty + ": " + orderDetailsItem.Quantity.ToString() + " ");
sb.Append(Resources.Item + ": " + orderDetailsItem.Inventory.InventoryName.Trim() + " ");
sb.Append(Resources.Stock + ": " + orderDetailsItem.Inventory.InStock.ToString() + "\r\n");
}
//Open up the notification
HtmlFormEx notificationsForm = new HtmlFormEx(Resources.CustomerService,
Resources.Order + " ",
customer,
state + "\r\n" + sb.ToString());
notificationsForm.ShowDialog();
notificationsForm.Dispose();
//bring back focus
this.Activate();
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.OrderViewError, Resources.SystemError);
}
}
/// <summary>
/// bring up the help file
/// </summary>
private void DisplayHelp()
{
try
{
//Show Customer Service Help
OnlineHelper myHelp = new OnlineHelper(HELP_FILE);
myHelp.ShowDialog();
//Free the resources of the help form
myHelp.Dispose();
this.Activate();
}
catch (Exception ex)
{
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.HelpDisplayError, Resources.SystemError);
}
}
private void Synchronize()
{
try
{
//Log Application and Device Metrics
Business.Services.LogAppState();
Business.Services.SyncWithDataSource();
}
catch (Exception ex)
{
throw new Utilities.WrapperException(Resources.SyncDbError, ex);
}
}
/// <summary>
/// sends notification to the warehouse role that the order has been placed
/// </summary>
/// <param name="myOrder"></param>
/// <summary>
/// sends notification to the warehouse role that the order has been placed
/// </summary>
private void SendNotification()
{
try
{
Business.Services.SendNotification("Warehouse");
}
catch (Exception ex)
{
throw new Utilities.WrapperException(Resources.NotificationError, ex);
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -