Ejemplo n.º 1
0
        /// <summary>
        /// This method is responsible for adding the newest record in the database
        /// into the GUI table.
        /// </summary>
        /// <param name="table">A Table Layout Panel you want to add a new record to.</param>
        /// <param name="rowIndex">The row index where you want to add the new record.</param>
        static public void addNewRecord(TableLayoutPanel table, int rowIndex)
        {
            // Gets latest sale record from the database
            SalesRecord record = SalesDatabase.GetNewestSalesRecord();

            // Finds the corresponding Product Record for the SalesRecord
            ProductRecord pRecord = ProductDatabase.GetProductByProductID(record.ProductID);

            // Creates a new row in the table and updates the text in the cells
            table.Controls.Add(new Label()
            {
                Text = record.SaleID.ToString()
            }, 0, rowIndex);
            table.Controls.Add(new Label()
            {
                Text = pRecord.Name.ToString()
            }, 1, rowIndex);
            table.Controls.Add(new Label()
            {
                Text = record.DateSold.ToString()
            }, 2, rowIndex);
            table.Controls.Add(new Label()
            {
                Text = record.Quantity.ToString()
            }, 3, rowIndex);
            table.Controls.Add(new Label()
            {
                Text = "$" + (pRecord.Price * record.Quantity).ToString()
            }, 4, rowIndex);
        }
Ejemplo n.º 2
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            int prodId = Int32.Parse(txtProductID.Text);
            int quan   = Int32.Parse(txtQuantity.Text);

            SalesDatabase.NewSalesEntry(prodId, quan);

            Close();
        }
Ejemplo n.º 3
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            int    saleId = saleRecord.SaleID;
            int    prodId = Int32.Parse(txtProductID.Text);
            int    quan   = Int32.Parse(txtQuantity.Text);
            string dt     = txtDateSold.Text;

            SalesDatabase.EditSalesRecord(saleId, prodId, quan, dt);

            Close();
        }
Ejemplo n.º 4
0
        private void Main_Load(object sender, EventArgs e)
        {
            List <SalesRecord> allSales = SalesDatabase.GetAllSales();

            foreach (SalesRecord s in allSales)
            {
                GUIFunctions.addNewRecord(tlpDataRecords, rowIndex, s);
                rowIndex++;
            }
            foreach (Label l in tlpDataRecords.Controls)
            {
                l.MouseClick += new MouseEventHandler(selectRow);
            }
        }
Ejemplo n.º 5
0
        public List <SalesReport> ReportList(DateTime startDate, DateTime endDate)
        {
            List <ProductRecord> products = ProductDatabase.GenerateAllProduct();
            List <SalesReport>   report   = new List <SalesReport>();

            foreach (ProductRecord record in products)
            {
                report.Add(new SalesReport()
                {
                    ProductID = record.ProductID,
                    Name      = record.Name,
                    Quantity  = SalesDatabase.GenerateSalesAmount(record.ProductID, startDate, endDate),
                    Price     = record.Price,
                    Total     = Convert.ToDouble(SalesDatabase.GenerateSalesAmount(record.ProductID, startDate, endDate)) * record.Price
                });
            }
            return(report);
        }
Ejemplo n.º 6
0
        private void BtnEditRecord_Click(object sender, EventArgs e)
        {
            if (selectedRow == 0)
            {
                MessageBox.Show("Please select a sales record to edit first.");
            }
            else
            {
                using (EditSalesRecord editRecord = new EditSalesRecord())
                {
                    SalesRecord saleData = SalesDatabase.GetSalesRecordWithSaleID(Int32.Parse(tlpDataRecords.GetControlFromPosition(0, selectedRow).Text));
                    editRecord.SaleRecord = saleData;

                    if (editRecord.ShowDialog() == DialogResult.OK)
                    {
                        saleData = SalesDatabase.GetSalesRecordWithSaleID(Int32.Parse(tlpDataRecords.GetControlFromPosition(0, selectedRow).Text));
                        ProductRecord pRecord = ProductDatabase.GetProductByProductID(saleData.ProductID);
                        GUIFunctions.editRecord(tlpDataRecords, selectedRow, saleData, pRecord);
                    }
                }
            }
        }