Exemple #1
0
        /// <summary>
        /// Returns a list of all of the invoices in the database
        /// </summary>
        /// <returns></returns>
        public ObservableCollection <clsMainLogic> GetInvoices()
        {
            ObservableCollection <clsMainLogic> result = new ObservableCollection <clsMainLogic>();

            try
            {
                int     iRet = 0;
                DataSet ds   = dataAccess.ExecuteSQLStatement(sql.SelectAllInvoices(), ref iRet);
                for (int i = 0; i < iRet; ++i)
                {
                    clsMainLogic invoice = new clsMainLogic();
                    invoice.InvoiceNum  = Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString());
                    invoice.InvoiceDate = Convert.ToDateTime(ds.Tables[0].Rows[i][1].ToString());
                    invoice.TotalCharge = Convert.ToDecimal(ds.Tables[0].Rows[i][2].ToString());
                    result.Add(invoice);
                }
            }
            catch (Exception ex)
            {
                //Just throw the exception
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }

            return(result);
        }
 /// <summary>
 /// Constructor for the main window
 /// </summary>
 public MainWindow()
 {
     sqlProvider = new clsMainLogic();
     Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
     InitializeComponent();
     LoadItems();
 }
        /// <summary>
        /// This function deletes a particular invoice from the database
        /// </summary>
        /// <param name="Invoice">Invoice</param>
        public void DeleteInvoice(clsMainLogic Invoice)
        {
            try
            {
                DataSet ds   = new DataSet();
                int     iRet = 0;

                ds = db.ExecuteSQLStatement(SQLQueries.SelectLineItems(Invoice.InvoiceNum), ref iRet);

                // Delete all the line items that is associated with this invoice
                for (int i = 0; i < iRet; i++)
                {
                    int lineItemNum = Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString());
                    db.ExecuteNonQuery(SQLQueries.deleteLineItem(Invoice.InvoiceNum, lineItemNum));
                }

                // Delete the invoice
                db.ExecuteNonQuery(SQLQueries.deleteInvoice(Invoice.InvoiceNum));
            }
            catch (Exception ex)
            {
                //Just throw the exception
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
 /// <summary>
 /// default constructor
 /// </summary>
 public MainWindow()
 {
     InitializeComponent();
     controller = new clsMainLogic();
     updateAllInvoices();
     lbStock.ItemsSource = controller.getAllItemsInStock();
 }
        public MainWindow()
        {
            InitializeComponent();

            // load each of the 3 logic classes, all data will pass through here
            mn = new clsMainLogic();   // Load Main Class
            sl = new clsSearchLogic(); // Load Search Class
            il = new clsItemsLogic();  // Load Item Class
        }
        /// <summary>
        /// This function saves all the changes of current invoice into the database
        /// and returns the invoice number of the invoice that it saves change to
        /// </summary>
        /// <param name="Invoice">clsInvoice</param>
        /// <param name="isNewInvoice">Boolean</param>
        /// <returns>InvoiceNum</returns>
        public int SaveChanges(clsMainLogic Invoice, bool isNewInvoice)
        {
            try
            {
                int invoiceNum;

                // if this is not a new added invoice
                if (isNewInvoice == false)
                {
                    invoiceNum = Invoice.InvoiceNum;

                    DataSet ds = new DataSet();

                    int iRet = 0;
                    ds = db.ExecuteSQLStatement(SQLQueries.SelectLineItems(Invoice.InvoiceNum), ref iRet);

                    // Clear all the line items that is associated with this invoice
                    for (int i = 0; i < iRet; i++)
                    {
                        int lineItemNum = Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString());
                        db.ExecuteNonQuery(SQLQueries.deleteLineItem(Invoice.InvoiceNum, lineItemNum));
                    }

                    // Update the date and total charge for this invoice
                    db.ExecuteNonQuery(SQLQueries.updateInvoice(Invoice.InvoiceNum, Invoice.InvoiceDate, Invoice.TotalCharge));
                }
                // If this is a new invoice
                else
                {
                    db.ExecuteNonQuery(SQLQueries.InsertNewInvoice(Invoice.InvoiceDateString, Invoice.TotalCharge));

                    // Retrieves the invoice number that just got created
                    invoiceNum = Convert.ToInt32(db.ExecuteScalarSQL(SQLQueries.SelectTheLatestInvNum()));
                }

                // Insert all the line items related to this invoice in database
                for (int i = 0; i < Invoice.ItemsCollection.Count; i++)
                {
                    int    lineItemNum = Invoice.ItemsCollection[i].LineItemNum;
                    string itemCode    = Invoice.ItemsCollection[i].ItemCode;

                    db.ExecuteNonQuery(SQLQueries.InsertNewLineItem(invoiceNum, lineItemNum, itemCode));
                }

                return(invoiceNum);
            }
            catch (Exception ex)
            {
                //Just throw the exception
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
        /// <summary>
        /// Constructor for Main Window
        /// </summary>
        public MainWindow()
        {
            try
            {
                InitializeComponent();
                Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;

                ml = new clsMainLogic();
                //Populate Items ComboBox
                cmbInvoiceItem.ItemsSource = ml.getItems().Select(a => a.ItemDesc);

                //Populate DataGrid with Invoices
                List <clsInvoice> invoice = ml.GetAllInvoices();
                dgInvoices.ItemsSource = invoice;
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
        /// <summary>
        /// This function returns a particular clsInvoice object based on the invoice number parameter
        /// </summary>
        /// <param name="InvoiceNum"></param>
        /// <returns></returns>
        public clsMainLogic PopulateInvoice(int InvoiceNum)
        {
            try
            {
                DataSet ds   = new DataSet();
                int     iRet = 0;

                ds = db.ExecuteSQLStatement(SQLQueries.SelectInvoiceData(InvoiceNum), ref iRet);

                ObservableCollection <clsInvoiceItem> InvoiceItemCollection = new ObservableCollection <clsInvoiceItem>();

                for (int i = 0; i < iRet; i++)
                {
                    clsInvoiceItem InvoiceItem = new clsInvoiceItem();

                    InvoiceItem.ItemDesc    = ds.Tables[0].Rows[i][3].ToString();
                    InvoiceItem.ItemCost    = Convert.ToDecimal(ds.Tables[0].Rows[i][4].ToString());
                    InvoiceItem.LineItemNum = Convert.ToInt32(ds.Tables[0].Rows[i][5].ToString());
                    InvoiceItem.ItemCode    = ds.Tables[0].Rows[i][6].ToString();

                    InvoiceItemCollection.Add(InvoiceItem);
                }

                clsMainLogic currInvoice = new clsMainLogic();

                currInvoice.ItemsCollection = InvoiceItemCollection;
                currInvoice.InvoiceNum      = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
                currInvoice.InvoiceDate     = Convert.ToDateTime(ds.Tables[0].Rows[0][1].ToString());
                currInvoice.TotalCharge     = Convert.ToDecimal(ds.Tables[0].Rows[0][2].ToString());

                return(currInvoice);
            }
            catch (Exception ex)
            {
                //Just throw the exception
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." +
                                    MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
        /// <summary>
        /// Constructor for main window and application entry point.
        /// </summary>
        public MainWindow()
        {
            try
            {
                InitializeComponent();
                mainLogic = new clsMainLogic();
                Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;//close the application when the main window is closed
                //Maybe delete this line.
                MainWndwInvoice = new clsInvoices();

                dataGridList = new ObservableCollection <Item>();
                itemsWindow  = new wndItems();
                SearchWindow = new wndSearch();

                //this.Hide(); //temporary for austin's development
                //itemsWindow.Show(); //temporary for austin's development
            }
            catch (Exception ex)
            {               //this is reflection
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
Exemple #10
0
 /// <summary>
 /// Passes the invoice number to the InvoiceWindow
 /// It will be set as the active invoice
 /// The InvoiceWindow will be refreshed with the active invoice info
 /// </summary>
 /// <param name="invoice"></param>
 public void InvoiceSelected(clsMainLogic invoice)
 {
     invoiceInterface.SetInvoice(invoice.InvoiceNum);
 }