Exemple #1
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);
                    }
                }
            }
        }
 /// <summary>
 /// This method is responsible for adding a given ProductRecord to the 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="productRecord">The ProductRecod you want to add to the table.</param>
 static public void addNewProductRecord(TableLayoutPanel table, int rowIndex, ProductRecord productRecord)
 {
     // Creates a new row in the table and updates the text in the cells
     table.Controls.Add(new Label()
     {
         Text = productRecord.ProductID.ToString()
     }, 0, rowIndex);
     table.Controls.Add(new Label()
     {
         Text = productRecord.Name
     }, 1, rowIndex);
     table.Controls.Add(new Label()
     {
         Text = productRecord.Description
     }, 2, rowIndex);
     table.Controls.Add(new Label()
     {
         Text = "$" + productRecord.Price.ToString()
     }, 3, rowIndex);
     table.Controls.Add(new Label()
     {
         Text = productRecord.Category
     }, 4, rowIndex);
 }
 /// <summary>
 /// This method is responsible for editing a recod in the GUI
 /// </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 sales record that you are editting.</param>
 /// <param name="productRecord">The corresponding ProductRecord for the SalesRecord.</param>
 static public void editRecord(TableLayoutPanel table, int rowIndex, SalesRecord salesRecord, ProductRecord productRecord)
 {
     // Modifying the text within the labels for the SalesRecord
     table.GetControlFromPosition(1, rowIndex).Text = productRecord.Name;
     table.GetControlFromPosition(2, rowIndex).Text = salesRecord.DateSold.ToString();
     table.GetControlFromPosition(3, rowIndex).Text = salesRecord.Quantity.ToString();
     table.GetControlFromPosition(4, rowIndex).Text = "$" + (productRecord.Price * salesRecord.Quantity).ToString();
 }