public void addNewProductRecord() { ProductRecord record = ProductDatabase.GetNewestProduct(); tlpDataRecords.Controls.Add(new Label() { Text = record.ProductID.ToString() }, 0, rowIndex); tlpDataRecords.Controls.Add(new Label() { Text = record.Name }, 1, rowIndex); tlpDataRecords.Controls.Add(new Label() { Text = record.Description }, 2, rowIndex); tlpDataRecords.Controls.Add(new Label() { Text = "$" + record.Price.ToString() }, 3, rowIndex); tlpDataRecords.Controls.Add(new Label() { Text = record.Category }, 4, rowIndex); rowIndex++; }
/// <summary> /// This method is responsible for adding the a new ProductRecord to the table. /// It does this by looking for the most recently added ProductRecord in the databse. /// </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 addNewProductRecord(TableLayoutPanel table, int rowIndex) { // Getting the new Product Record ProductRecord record = ProductDatabase.GetNewestProduct(); // Creates a new row in the table and updates the text in the cells table.Controls.Add(new Label() { Text = record.ProductID.ToString() }, 0, rowIndex); table.Controls.Add(new Label() { Text = record.Name }, 1, rowIndex); table.Controls.Add(new Label() { Text = record.Description }, 2, rowIndex); table.Controls.Add(new Label() { Text = "$" + record.Price.ToString() }, 3, rowIndex); table.Controls.Add(new Label() { Text = record.Category }, 4, rowIndex); }
/// <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 btnSave_Click(object sender, EventArgs e) { ProductRecord newProductRecord = new ProductRecord() { Name = txtName.Text, Description = txtDescription.Text, Price = Double.Parse(txtPrice.Text), Category = txtCategory.Text }; ProductDatabase.AddNewProduct(newProductRecord); Close(); }
private void Products_Load(object sender, EventArgs e) { List <ProductRecord> allProducts = ProductDatabase.GenerateAllProduct(); foreach (ProductRecord p in allProducts) { GUIFunctions.addNewProductRecord(tlpDataRecords, rowIndex, p); rowIndex++; } foreach (Label l in tlpDataRecords.Controls) { l.MouseClick += new MouseEventHandler(selectRow); } }
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); }
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); } } } }