📄 services.cs
字号:
GetValue<string>(currentRow[Customer.STATEPROVINCE_COLUMN]),
GetValue<string>(currentRow[Customer.POSTALCODE_COLUMN]),
GetValue<string>(currentRow[Customer.CONTACTNAME_COLUMN]),
GetValue<string>(currentRow[Customer.CONTACTPHONE_COLUMN]),
GetValue<Nullable<int>>(currentRow[Customer.ROUTEID_COLUMN]));
//Return customerQuery as a List<Customer>
return customerQuery.ToList();
}
/// <summary>
/// Retrieve all the Inventory
/// </summary>
/// <returns>list of all inventory</returns>
public static List<Inventory> GetInventory()
{
// Build a Linq Query to build a list of inventory
// you could modify this to also find only specific inventory
// with a where clause
var inventoryQuery = from currentRow in _dataStore.Read(StoredProcs.GetInventory)
select CreateInventory(currentRow);
//Return inventoryQuery as a List<Inventory>
return inventoryQuery.ToList();
}
/// <summary>
/// Finds a specific inventory item
/// </summary>
/// <param name="findInventoryId">
/// id of the inventory item being sought
/// </param>
/// <returns>Inventory being sought</returns>
public static Inventory GetInventoryById(int findInventoryId)
{
List<Inventory> inventoryList;
Parameters parameters;
// Setup parameter to use SQL to find a specific inventory id.
parameters = new Parameters();
parameters.Add("@InventoryId", findInventoryId);
// this could have had a where clause rather than use SQL.
// if you did to boost performance use table direct and set an
// index with the value or range.
var inventoryQuery = from currentRow in _dataStore.Read(StoredProcs.GetInventoryById, parameters)
select CreateInventory(currentRow);
// Make sure an inventory id was found.
inventoryList = inventoryQuery.ToList();
if (inventoryList.Count == 0)
{
throw new ApplicationException("Could not find inventory item with InventoryId, " + findInventoryId.ToString());
}
return inventoryList.ElementAt(0);
}
/// <summary>
/// Get the latitude and longitude based on an address.
/// </summary>
/// <param name="address">address to find</param>
/// <param name="city">city of the address</param>
/// <param name="state">state of the address</param>
/// <param name="find">
/// service to use to find the latitude and longitude
/// </param>
/// <returns>Location of the address</returns>
private static Location GetLatLong(string address, string city, string state, FindServiceSoap find)
{
//Create an address object
Address _address = new Address();
//Set the address object's properties
_address.AddressLine = address;
_address.PrimaryCity = city;
_address.Subdivision = state;
//Create a FindAddressSpecification object
FindAddressSpecification _findAddressSpec = new FindAddressSpecification();
//Set the FindAddressSpecification's properties
_findAddressSpec.DataSourceName = "MapPoint.NA";
_findAddressSpec.InputAddress = _address;
//Retrieve address information
FindResults _results = find.FindAddress(_findAddressSpec);
//If address information exists
if (_results.NumberFound == 0)
{
return null;
}
else
{
//Return the Location
return _results.Results[0].FoundLocation;
}
}
/// <summary>
/// get a new local display id for the order
/// </summary>
/// <returns>new negative display id</returns>
private static int GetNewDisplayId()
{
int displayId = -1;
// Example of using SQL directly rather than a "stored procedure"
object obj = _dataStore.GetValue("SELECT MIN(DisplayId) FROM Orders WHERE DisplayId < 0");
if (!String.IsNullOrEmpty(Convert.ToString(obj)))
{
//start at the seed value
displayId = (int)obj - 1;
}
return displayId;
}
/// <summary>
/// Get a specific order by order id.
/// </summary>
/// <param name="orderId">id of the order to retrieve</param>
/// <returns>
/// An <see cref="Hardware.Business.Order"/> if found
/// </returns>
/// <exception cref="System.ApplicationException">
/// Throws an exception if order not found
/// </exception>
public static Order GetOrder(Guid findOrderId)
{
List<Order> listOrders;
Parameters parameters;
// Setup parameter for SQL
parameters = new Parameters();
parameters.Add("@OrderId", findOrderId);
// this could have had a where clause rather than use SQL.
// if you did to boost performance use table direct and set an
// index with the value or range.
var orderQuery = from currentRow in _dataStore.Read(StoredProcs.GetOrder, parameters)
select CreateOrder(currentRow);
listOrders = orderQuery.ToList();
// Make sure an order was found.
if (listOrders.Count == 0)
{
throw new ApplicationException("Could not find order with OrderId, " + findOrderId.ToString());
}
return listOrders.ElementAt(0);
}
/// <summary>
/// Retrieve a Collection of OrderDetails objects.
/// </summary>
/// <param name="orderId">order id of order details to find</param>
/// <returns>Order details</returns>
public static List<OrderDetail> GetOrderDetails(Guid findOrderId)
{
Parameters parameters;
parameters = new Parameters();
parameters.Add("@OrderId", findOrderId);
// Build a Linq Query to build a list of order details for a
// specific order.
var orderDetailQuery = from currentRow in _dataStore.Read(StoredProcs.GetOrderDetails, parameters)
select new OrderDetail(GetValue<Nullable<Guid>>(currentRow[OrderDetail.ORDERID_COLUMN]),
GetValue<Nullable<Guid>>(currentRow[OrderDetail.ORDERDETAILID_COLUMN]),
GetValue<Nullable<int>>(currentRow[OrderDetail.INVENTORYID_COLUMN]),
GetValue<Nullable<int>>(currentRow[OrderDetail.QUANTITY_COLUMN]));
//Return inventoryQuery as a List<Inventory>
return orderDetailQuery.ToList();
}
/// <summary>
/// Retrieve a Collection of Order objects
/// </summary>
/// <param name="tomorrow">true if date is tomorrow</param>
/// <param name="orderState">state of the order to find</param>
/// <returns>orders found</returns>
public static List<Order> GetOrders(bool tomorrow, OrderState findOrderState)
{
Parameters parameters = new Parameters();
string sql;
// Need to dynamically create SQL
// These could be changed to four stored procedures
parameters = new Parameters();
sql = "SELECT Orders.OrderId, Orders.DeliveryDate, Orders.OrderState, Orders.CustomerId, Orders.Signature, Orders.DisplayId " +
"FROM Orders ";
//If looking for just tomorrow's orders
if (tomorrow)
{
//Set the SQL statement
sql += "WHERE Orders.DeliveryDate = @deliveryDate AND ";
//Set DateTime object equal to one day in the future
parameters.Add("@deliveryDate", DateTime.Today.AddDays(1));
}
else
{
sql += "WHERE ";
}
//If you're looking for all orders
if (findOrderState == OrderState.All)
{
sql += "Orders.OrderState != 0";
}
//if looking for all orders under processing ( not cancelled, and not completed / delivered)
else if (findOrderState == OrderState.Active)
{
sql += " ( Orders.OrderState != 0 AND Orders.OrderState != 5 ) ";
}
//If you're looking for specific orders
else
{
sql += "Orders.OrderState = @orderState";
parameters.Add("@orderState", (int)findOrderState);
}
sql += " ORDER BY Orders.DisplayId ";
// Retrieve desired orders
// this could have had a where clause rather than use SQL.
// if you did to boost performance use table direct and set an
// index with the value or range.
var orderQuery = from currentRow in _dataStore.Read(sql, parameters)
select CreateOrder(currentRow);
return orderQuery.ToList();
}
/// <summary>
/// Get the price of an Inventory item
/// </summary>
/// <param name="inventoryId">inventory to price</param>
/// <returns>price of the inventory item</returns>
public static decimal GetPrice(int inventoryId)
{
decimal result;
Parameters parameters;
parameters = new Parameters();
parameters.Add("@inventoryId", inventoryId);
result = (decimal)_dataStore.GetValue(StoredProcs.GetPrice, parameters);
return result;
}
/// <summary>
/// Retrieve list of Role objects
/// </summary>
/// <returns>list of all roles</returns>
public static List<Role> GetRoles()
{
// Retrieve all roles
// this could have had a where clause rather than use SQL.
// if you did to boost performance use table direct and set an
// index with the value or range.
var roleQuery = from currentRow in _dataStore.Read(StoredProcs.GetRoles)
select new Role(GetValue<Nullable<int>>(currentRow[Role.ROLEID_COLUMN]),
GetValue<string>(currentRow[Role.ROLE_COLUMN]),
GetValue<string>(currentRow[Role.ROLEEMAIL_COLUMN]));
return roleQuery.ToList();
}
/// <summary>
/// Get the route map that the driver needs to follow
/// </summary>
/// <param name="Start">Starting location</param>
/// <param name="End">End location</param>
/// <param name="route">Route service</param>
/// <param name="render">Rendering service</param>
/// <param name="height">Height of image</param>
/// <param name="width">Width of image</param>
/// <returns>
/// Image of the height and width specified with the route drawn on it
/// </returns>
private static Bitmap GetRoute(Location Start, Location End, RouteServiceSoap route, RenderServiceSoap render, int height, int width)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -