📄 inventory.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlServerCe;
using System.Windows.Forms;
using System.Reflection;
namespace Microsoft.Sql.SqlCe.Samples.Cs.IBuySpyDelivery.IBuySpyDevice
{
/// <summary>
/// Summary description for the Inventory control. The Inventory control displays the products that can be added to existing
/// orders. Products are considered part of inventory only if they belong to an Order with a status of
/// "Failed".
/// </summary>
public class Inventory : System.Windows.Forms.Control
{
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Label lblSubtotal;
private System.Windows.Forms.Label lblPriceValue;
private System.Windows.Forms.Label lblPrice;
private System.Windows.Forms.Label lblQuantity;
private System.Windows.Forms.ComboBox cboProduct;
private System.Windows.Forms.Label lblProduct;
private System.Windows.Forms.Button btnAddProduct;
private System.Windows.Forms.ComboBox cboCategory;
private System.Windows.Forms.Label lblCategory;
private System.Windows.Forms.PictureBox pboIDegree;
private System.Windows.Forms.NumericUpDown numQuantity;
private System.Windows.Forms.Label lblSubTotalValue;
private System.Windows.Forms.PictureBox pboProductImage;
private FormIBuySpy formIBuySpy = null;
private IBuySpyData dataIBuySpy = null;
private DataTable dtCategories = null;
private DataView dvInventory = null;
private int orderID = -1;
private int categoryID = -1;
private int productID = -1;
internal event ViewOrdersEventHandler OnViewOrders;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Inventory(FormIBuySpy formIBuySpy)
{
this.formIBuySpy = formIBuySpy;
this.dataIBuySpy = IBuySpyData.GetInstance();
/// This call is required by the Windows.Forms Form Designer.
///
InitializeComponent();
this.pboIDegree.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("IBuySpyDevice.idegree.gif"));
}
internal int OrderID
{
get
{
return orderID;
}
set
{
orderID = value;
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnCancel = new System.Windows.Forms.Button();
this.pboProductImage = new System.Windows.Forms.PictureBox();
this.lblSubtotal = new System.Windows.Forms.Label();
this.lblPriceValue = new System.Windows.Forms.Label();
this.lblPrice = new System.Windows.Forms.Label();
this.lblQuantity = new System.Windows.Forms.Label();
this.cboProduct = new System.Windows.Forms.ComboBox();
this.lblProduct = new System.Windows.Forms.Label();
this.btnAddProduct = new System.Windows.Forms.Button();
this.cboCategory = new System.Windows.Forms.ComboBox();
this.lblCategory = new System.Windows.Forms.Label();
this.pboIDegree = new System.Windows.Forms.PictureBox();
this.numQuantity = new System.Windows.Forms.NumericUpDown();
this.lblSubTotalValue = new System.Windows.Forms.Label();
///
/// btnCancel
///
this.btnCancel.Location = new System.Drawing.Point(132, 198);
this.btnCancel.Size = new System.Drawing.Size(100, 24);
this.btnCancel.Text = "Cancel";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
///
/// pboProductImage
///
this.pboProductImage.Location = new System.Drawing.Point(128, 64);
this.pboProductImage.Size = new System.Drawing.Size(100, 75);
///
/// lblSubtotal
///
this.lblSubtotal.Location = new System.Drawing.Point(4, 124);
this.lblSubtotal.Size = new System.Drawing.Size(56, 16);
this.lblSubtotal.Text = "Subtotal:";
///
/// lblPriceValue
///
this.lblPriceValue.Location = new System.Drawing.Point(56, 98);
this.lblPriceValue.Size = new System.Drawing.Size(66, 13);
this.lblPriceValue.Text = "";
///
/// lblPrice
///
this.lblPrice.Location = new System.Drawing.Point(4, 97);
this.lblPrice.Size = new System.Drawing.Size(40, 16);
this.lblPrice.Text = "Price:";
///
/// lblQuantity
///
this.lblQuantity.Location = new System.Drawing.Point(4, 67);
this.lblQuantity.Size = new System.Drawing.Size(56, 16);
this.lblQuantity.Text = "Quantity:";
///
/// cboProduct
///
this.cboProduct.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboProduct.Location = new System.Drawing.Point(64, 37);
this.cboProduct.Size = new System.Drawing.Size(168, 21);
this.cboProduct.SelectedIndexChanged += new System.EventHandler(this.cboProduct_SelectedIndexChanged);
///
/// lblProduct
///
this.lblProduct.Location = new System.Drawing.Point(4, 40);
this.lblProduct.Size = new System.Drawing.Size(56, 16);
this.lblProduct.Text = "Product:";
///
/// btnAddProduct
///
this.btnAddProduct.Location = new System.Drawing.Point(132, 168);
this.btnAddProduct.Size = new System.Drawing.Size(100, 24);
this.btnAddProduct.Text = "Add Product";
this.btnAddProduct.Click += new System.EventHandler(this.btnAddProduct_Click);
///
/// cboCategory
///
this.cboCategory.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboCategory.Location = new System.Drawing.Point(64, 7);
this.cboCategory.Size = new System.Drawing.Size(168, 21);
this.cboCategory.SelectedIndexChanged += new System.EventHandler(this.cboCategory_SelectedIndexChanged);
///
/// lblCategory
///
this.lblCategory.Location = new System.Drawing.Point(4, 8);
this.lblCategory.Size = new System.Drawing.Size(56, 16);
this.lblCategory.Text = "Category:";
///
/// pboIDegree
///
this.pboIDegree.Location = new System.Drawing.Point(8, 168);
this.pboIDegree.Size = new System.Drawing.Size(120, 55);
///
/// numQuantity
///
this.numQuantity.Location = new System.Drawing.Point(64, 66);
this.numQuantity.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.numQuantity.Size = new System.Drawing.Size(56, 20);
this.numQuantity.Value = new System.Decimal(new int[] {
1,
0,
0,
0});
//this.numQuantity.TextChanged += new System.EventHandler(this.numQuantity_TextChanged);
this.numQuantity.ValueChanged += new System.EventHandler(this.numQuantity_ValueChanged);
///
/// lblSubTotalValue
///
this.lblSubTotalValue.Location = new System.Drawing.Point(56, 123);
this.lblSubTotalValue.Size = new System.Drawing.Size(66, 13);
this.lblSubTotalValue.Text = "";
///
/// Inventory
///
this.Controls.Add(this.lblSubTotalValue);
this.Controls.Add(this.numQuantity);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.pboProductImage);
this.Controls.Add(this.lblSubtotal);
this.Controls.Add(this.lblPriceValue);
this.Controls.Add(this.lblPrice);
this.Controls.Add(this.lblQuantity);
this.Controls.Add(this.cboProduct);
this.Controls.Add(this.lblProduct);
this.Controls.Add(this.btnAddProduct);
this.Controls.Add(this.cboCategory);
this.Controls.Add(this.lblCategory);
this.Controls.Add(this.pboIDegree);
this.Size = new System.Drawing.Size(240, 240);
}
#endregion
/// Load inventory data from the database to the Inventory dataset. Intialize the dataset and bind it
/// to the user interface controls.
///
internal bool InitInventory()
{
DataTable dtInventory = null;
this.dataIBuySpy.InventoryChanged = false;
Cursor.ShowWaitCursor(true);
try
{
try
{
this.dtCategories = dataIBuySpy.LoadCategories();
dtInventory = dataIBuySpy.LoadInventory();
}
finally
{
Cursor.ShowWaitCursor(false);
}
}
catch(SqlCeException e)
{
IBuySpyData.ShowErrors(e);
return false;
}
catch(Exception e)
{
MessageBox.Show("Init Inventory: " + e.Message, "IBuySpy Delivery");
return false;
}
if (null == dtCategories || 0 == this.dtCategories.Rows.Count)
{
MessageBox.Show("No inventory", "IBuySpy Delivery");
return false;
}
if (null == dtInventory || 0 == dtInventory.Rows.Count)
{
MessageBox.Show("No products", "IBuySpy Delivery");
return false;
}
if (null == this.dvInventory)
{
this.dvInventory = new DataView(dtInventory);
}
/// Bind the Category datatable to the Category combo box.
///
this.cboCategory.DisplayMember = "CategoryName";
this.cboCategory.ValueMember = "CategoryID";
this.cboCategory.DataSource = this.dtCategories;
/// Bind the UnitCost data value to the Price label text.
///
this.lblPriceValue.DataBindings.Clear();
this.lblPriceValue.DataBindings.Add("Text", this.dvInventory, "UnitCost");
/// Bind the Inventory data view to the Product combo box.
///
this.cboProduct.DisplayMember = "ModelName";
this.cboProduct.ValueMember = "ProductID";
this.cboProduct.DataSource = this.dvInventory;
this.categoryID = Convert.ToInt32(this.cboCategory.SelectedValue);
/// Filter the Inventory data view based on what category is currently selected.
///
this.dvInventory.RowFilter = String.Format("CategoryID = '{0}'", this.categoryID);
/// Update the user interface.
///
UpdateControls();
return true;
}
/// Refresh the Inventory data view based on which Category is selected.
///
internal bool RefreshInventory()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -