// creates inventory item for given SKU // loads info from DB private InventoryItem_AS3 CreateItem(int _skuID) { // build command, get reader string _query = string.Format("SELECT * FROM Inventory WHERE (SKU = {0});", _skuID); OleDbCommand _cmd = new OleDbCommand(_query, connection); OleDbDataReader _reader = _cmd.ExecuteReader(); if (!_reader.Read()) { Trace.Warn("shop error", string.Format("InventoryItem, no record for SKU#{0}", _skuID)); return(null); } // parse info from reader // SKU, Description, QOH, UnitWeight, UnitPrice int _sku = (int)_reader["SKU"]; string _description = (string)_reader["Description"]; int _qoh = (int)_reader["QOH"]; double _weight = (double)_reader["UnitWeight"]; double _price = (double)_reader["UnitPrice"]; // get list of suppliers List <Supplier_AS3> _suppliers = GetCreateSuppliers(_sku); InventoryItem_AS3 _item = new InventoryItem_AS3(_sku, _suppliers, _qoh, _description, _weight, _price); inventories.Add(_item); return(_item); }
// adds item line to invoice portion private void AddItemLine(Table _table, LineItem_AS3 _line) { TableRow _row = new TableRow(); InventoryItem_AS3 _item = _line.Item; _row.Cells.Add(CreateCell(string.Format("{0}", _item.SKU))); _row.Cells.Add(CreateCell(_item.Description)); _row.Cells.Add(CreateCell(string.Format("{0:c2}", _item.UnitPrice), HorizontalAlign.Right)); _row.Cells.Add(CreateCell(string.Format("{0}", _line.Quantity), HorizontalAlign.Right)); _row.Cells.Add(CreateCell(string.Format("{0:f2}", (double)_item.UnitWeight), HorizontalAlign.Right)); _row.Cells.Add(CreateCell(string.Format("{0:c2}", (double)_item.UnitPrice * _line.Quantity), HorizontalAlign.Right)); _row.Cells.Add(CreateCell(string.Format("{0:f2}", (double)_item.UnitWeight * _line.Quantity), HorizontalAlign.Right)); _table.Rows.Add(_row); }
// creates line for given record private LineItem_AS3 CreateLine(DbDataReader _reader) { // parse out info int _invoiceNumber = (int)_reader["InvoiceNumber"]; int _lineNumber = (int)_reader["LineNumber"]; int _sku = (int)_reader["SKU"]; int _quantity = (int)_reader["QuantityOrdered"]; // get inventory item InventoryItem_AS3 _item = GetCreateItem(_sku); if (_item == null) { Trace.Warn("shop errors", string.Format("Invoice({0})Line#{1}, failed to get item #{2}", _invoiceNumber, _lineNumber, _sku)); return(null); } return(new LineItem_AS3(_item, _quantity)); }
// constructor public LineItem_AS3(InventoryItem_AS3 _item, int _quantity) { Item = _item; Quantity = _quantity; }