/// <summary> /// This method is responsible for adding a SalesRecord 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> /// <param name="salesRecord">The SalesRecord you want to add to the table.</param> static public void addNewRecord(TableLayoutPanel table, int rowIndex, SalesRecord salesRecord) { // Finds the corresponding Product Record for the SalesRecord ProductRecord pRecord = ProductDatabase.GetProductByProductID(salesRecord.ProductID); // Creates a new row in the table and updates the text in the cells table.Controls.Add(new Label() { Text = salesRecord.SaleID.ToString() }, 0, rowIndex); table.Controls.Add(new Label() { Text = pRecord.Name.ToString() }, 1, rowIndex); table.Controls.Add(new Label() { Text = salesRecord.DateSold.ToString() }, 2, rowIndex); table.Controls.Add(new Label() { Text = salesRecord.Quantity.ToString() }, 3, rowIndex); table.Controls.Add(new Label() { Text = "$" + (pRecord.Price * salesRecord.Quantity).ToString() }, 4, rowIndex); }
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); } } } }