📄 directions.cs
字号:
using System;
using System.Drawing;
using System.Windows.Forms;
using HardwareDistributor.Business;
using HardwareDistributor.Properties;
namespace HardwareDistributor.UI
{
public partial class Directions : Form
{
#region Members
private int _customerId;
#endregion
#region Contructors
public Directions(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;
_customerId = customerId;
}
#endregion
#region Event Handlers
/// <summary>
/// Loading the directions dialog
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Directions_Load(object sender, EventArgs e)
{
try
{
Customer customer = GetCustomerDetails(_customerId);
DisplayMap( customer);
}
catch (Exception ex)
{
Cursor.Current = Cursors.Default;
Application.DoEvents();
Business.Services.LogErrors(ex);
MessageBox.Show(Resources.MapLoadError, Resources.SystemError);
}
}
/// <summary>
/// Dismiss the directions dialog and go back to the deliveries page
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItemDismiss_Click(object sender, EventArgs e)
{
this.Close();
}
/// 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();
}
}
#endregion
#region Methods
/// <summary>
/// Get map fro map service and display in picture box
/// </summary>
/// <param name="customer"></param>
private void DisplayMap(Customer customer)
{
Cursor.Current = Cursors.WaitCursor;
Application.DoEvents();
//get route map
Bitmap routeMap = Business.Services.GetRouteMap(
MapPictureBox.Height,
MapPictureBox.Width,
customer.StreetAddress.Trim(),
customer.City.Trim(),
customer.StateProvince.Trim());
Application.DoEvents();
if (null != routeMap)
{
this.MapPictureBox.Image = routeMap;
}
Cursor.Current = Cursors.Default;
}
/// <summary>
/// Get customer details from DB
/// </summary>
/// <param name="_customerId"></param>
/// <returns></returns>
private Customer GetCustomerDetails(int _customerId)
{
Customer customer = null;
//Iterate through Customer Collection
foreach (Business.Customer _customerItem in Business.GlobalCache.Instance.Customers)
{
//User Customer object with a matching CustomerId
if (_customerItem.CustomerId == _customerId)
{
customer = _customerItem;
break;
}
}
return customer;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -