示例#1
0
    // creates an invoice from given record
    // adds to list of invoices
    private Invoice_AS3 CreateInvoice(OleDbDataReader _reader)
    {
        // parse info from reader
        int    _number         = (int)_reader["InvoiceNumber"];
        int    _customerID     = (int)_reader["CustNumber"];
        string _dateOrderStr   = (string)_reader["DateOrder"];
        string _dateShippedStr = (string)_reader["DateShipped"];
        string _status         = (string)_reader["Status"];

        // parse date strings
        DateTime _dateOrdered, _dateShipped;

        // formats
        string[] formats = { "dd-MM-yyyy", "d-MM-yyyy", "dd-M-yyyy", "d-M-yyyy" };

        // CultureInfo.InvariantCulture
        if (!DateTime.TryParseExact(_dateOrderStr, formats, null, DateTimeStyles.None, out _dateOrdered))
        {
            Trace.Warn("shop errors", string.Format("Invoice({0}), DateTime Ordered parse failed (\"{1}\")", _number, _dateOrderStr));
            return(null);
        }

        if (!DateTime.TryParseExact(_dateShippedStr, formats, null, DateTimeStyles.None, out _dateShipped))
        {
            Trace.Warn("shop errors", string.Format("Invoice({0}), DateTime Shipped parse failed (\"{1}\")", _number, _dateShippedStr));
            return(null);
        }

        // grab customer
        Customer_AS3 _customer = GetCreateCustomer(_customerID);

        if (_customer == null)
        {
            Trace.Warn("shop errors", string.Format("Invoice({0}), failed to get customer #{1}", _number, _customerID));
            return(null);
        }

        // grab list of items
        List <LineItem_AS3> _items = GetCreateLines(_number);

        if (_items == null)
        {
            Trace.Warn("shop errors", string.Format("Invoice({0}), failed to get lines", _number));
            return(null);
        }

        // build obj, add to list
        Invoice_AS3 _invoice = new Invoice_AS3(_number, _customer, _items, _dateOrdered, _dateShipped, _status);

        invoices.Add(_invoice);

        return(_invoice);
    }
示例#2
0
    // gets customer from DB, creates object
    // uses given ID
    private Customer_AS3 CreateCustomer(int _id)
    {
        // build command, get reader
        string          _query  = string.Format("SELECT * FROM Customer WHERE (CustNumber = {0});", _id);
        OleDbCommand    _cmd    = new OleDbCommand(_query, connection);
        OleDbDataReader _reader = _cmd.ExecuteReader();

        if (!_reader.Read())
        {
            Trace.Warn("shop errors", string.Format("Customer, failed to find record with id={0}", _id));
            return(null);
        }

        // parse information
        int    _number     = (int)_reader["CustNumber"];
        int    _addrShipID = (int)_reader["AddrShip"];
        int    _addrBillID = (int)_reader["AddrBill"];
        string _company    = (string)_reader["Company"];
        string _contact    = (string)_reader["Contact"];
        string _phone      = (string)_reader["Phone"];

        // get addresses
        Address_AS3 _addrShip = GetCreateAddress(_addrShipID);

        if (_addrShip == null)
        {
            Trace.Warn("shop errors", string.Format("Customer({0}), failed to parse shipping address ({1})", _id, _addrShipID));
            return(null);
        }

        Address_AS3 _addrBill = GetCreateAddress(_addrBillID);

        if (_addrBill == null)
        {
            Trace.Warn("shop errors", string.Format("Customer({0}), failed to parse billing address ({1})", _id, _addrBillID));
            return(null);
        }

        // build object, add to list
        Customer_AS3 _customer = new Customer_AS3(_number, _addrShip, _addrBill, _company, _contact, _phone);

        customers.Add(_customer);

        return(_customer);
    }
示例#3
0
    // builds top row for invoice section
    private void AddInvoiceTopRow(Table _table, Invoice_AS3 _invoice)
    {
        TableRow _row = new TableRow();

        Customer_AS3 _customer = _invoice.Customer;

        string _strCustomer = string.Format("Customer #{0} - {1}", _customer.Number, (_customer.Company.Equals("None", StringComparison.OrdinalIgnoreCase)) ? (_customer.Contact) : (_customer.Company));
        string _strOrder    = string.Format("Order #{0}", _invoice.Number);
        string _strStatus   = string.Format("Status: {0}", _invoice.Status);
        string _strOrdered  = string.Format("Ordered: {0}", _invoice.Ordered.ToString("M/d/yyyy HH:mm:ss tt"));

        _row.Cells.Add(CreateCell(_strCustomer, Color.White, HorizontalAlign.Left, BorderStyle.Solid, 2));
        _row.Cells.Add(CreateCell(_strOrder, Color.White, HorizontalAlign.Left, BorderStyle.Solid, 2));
        _row.Cells.Add(CreateCell(_strStatus, Color.White, HorizontalAlign.Left, BorderStyle.Solid, 2));
        _row.Cells.Add(CreateCell(_strOrdered, Color.White, HorizontalAlign.Left, BorderStyle.Solid, 2));

        _table.Rows.Add(_row);
    }
示例#4
0
    // Constructor
    public Invoice_AS3(int _number, Customer_AS3 _customer, List <LineItem_AS3> _items, DateTime _order, DateTime _ship, string _status)
    {
        Number    = _number;
        Customer  = _customer;
        LineItems = _items;
        Ordered   = _order;
        Shipped   = _ship;
        Status    = _status;

        // calculate totals
        int    _itemCount = 0;
        double _cost = 0, _weight = 0;

        foreach (LineItem_AS3 _line in LineItems)
        {
            _itemCount += _line.Quantity;
            _cost      += _line.Item.UnitPrice * _line.Quantity;
            _weight    += _line.Item.UnitWeight * _line.Quantity;
        }

        TotalItems  = _itemCount;
        TotalCost   = _cost;
        TotalWeight = _weight;
    }