Пример #1
0
        //--------------------------------------------------------------------------------------------------------------------------------
        //-----------------------------------------------------End Search Methods---------------------------------------------------------
        //--------------------------------------------------------------------------------------------------------------------------------
        #endregion


        #region Main Window Methods
        //--------------------------------------------------------------------------------------------------------------------------------
        //--------------------------------------------------Begin Main Window Methods-----------------------------------------------------
        //--------------------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the invoice with the given invoice number.
        /// </summary>
        /// <param name="id">The invoice number</param>
        /// <returns>The invoice</returns>
        public static Invoice getInvoiceByID(int id)
        {
            try
            {
                int     numRows = 0;
                DataSet ds      = dataAccess.ExecuteSQLStatement(SQLStrings.getInvoiceForId(id), ref numRows);
                if (numRows > 1)
                {
                    throw new Exception("Query returns multiple invoices for id " + id);
                }
                Invoice invoice = new Invoice();
                invoice.ID   = int.Parse(ds.Tables[0].Rows[0][0].ToString());
                invoice.Date = DateTime.Parse(ds.Tables[0].Rows[0][1].ToString());
                DataSet invoiceProducts = dataAccess.ExecuteSQLStatement(SQLStrings.getLineItemsForInvoice(id), ref numRows);
                if (numRows == 0) //no products on invoice
                {
                    return(invoice);
                }
                List <Product> products  = new List <Product>();
                double         totalCost = 0;
                foreach (DataRow row in invoiceProducts.Tables[0].Rows)
                {
                    Product product = new Product();
                    product.ProductCode        = row[1].ToString();
                    product.ProductDescription = row[2].ToString();
                    product.ProductCost        = double.Parse(row[3].ToString());
                    product.inDB = true;
                    totalCost   += product.ProductCost;
                    products.Add(product);
                }
                invoice.products = products;
                return(invoice);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + ":" +
                                    MethodInfo.GetCurrentMethod().Name + "->" + ex.Message);
            }
        }
Пример #2
0
        //--------------------------------------------------------------------------------------------------------------------------------
        //------------------------------------------------------End Product Methods-------------------------------------------------------
        //--------------------------------------------------------------------------------------------------------------------------------
        #endregion


        #region Search Methods
        //--------------------------------------------------------------------------------------------------------------------------------
        //-----------------------------------------------------Begin Search Methods-------------------------------------------------------
        //--------------------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Gets a DataSet of all invoices based on the search filters.
        /// </summary>
        /// <param name="id">Invoice ID.</param>
        /// <param name="date">Invoice Date.</param>
        /// <param name="total">Invoice Total.</param>
        /// <returns>A DataSet of all invoices based on the search filters.</returns>
        public static DataSet getInvoiceList(int id, DateTime?date, double total)
        {
            try
            {
                int    numRows = 0;
                string query   = "";
                if (id == -1)
                {
                    if (date == null)
                    {
                        if (total == -1.0)      //no id, no date, no total
                        {
                            query = SQLStrings.getAllInvoices();
                        }
                        else                    //no id, no date, total
                        {
                            query = SQLStrings.getInvoicesForTotal(total);
                        }
                    }
                    else
                    {
                        if (total == -1.0)      //no id, date, no total
                        {
                            query = SQLStrings.getInvoiceForDate(((DateTime)date).ToShortDateString());
                        }
                        else                    //no id, date, total
                        {
                            query = SQLStrings.getInvoice(((DateTime)date).ToShortDateString(), total);
                        }
                    }
                }
                else
                {
                    if (date == null)
                    {
                        if (total == -1.0)      //id, no date, no total
                        {
                            query = SQLStrings.getInvoiceForId(id);
                        }
                        else                    //id, no date, total
                        {
                            query = SQLStrings.getInvoiceByIDTotal(id, total);
                        }
                    }
                    else
                    {
                        if (total == -1.0)      //id, date, no total
                        {
                            query = SQLStrings.getInvoiceByIDDate(id, ((DateTime)date).ToShortDateString());
                        }
                        else                    //id, date, total
                        {
                            query = SQLStrings.getInvoiceByIDDateTotal(id, ((DateTime)date).ToShortDateString(), total);
                        }
                    }
                }

                return(dataAccess.ExecuteSQLStatement(query, ref numRows));
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }