private void updateBtn_Click(object sender, EventArgs e) { string name = nameBox.Text; int price = Convert.ToInt32(priceBox.Text); string category = categoryBox.Text; nameBox.Text = ""; priceBox.Text = ""; categoryBox.Text = ""; IdentityEventArgs args = new IdentityEventArgs(name, category, price); IdentityUpated(this, args); Close(); }
//use of delegete, linq and event to sell the data private void SellRecord(object sender, IdentityEventArgs ea) { if (ea.Name != "" && ea.Name.Length > 0 && ea.Category != "" && ea.Price > 0) { List <ItemDetail> modelList = new List <ItemDetail>(); if (!this.status) { itemList.Add(new ItemDetail() { Name = ea.Name, Price = ea.Price, Category = ea.Category, Quantity = 1 }); var items = itemList.GroupBy(x => new { x.Name }); foreach (var item in items) { modelList.Add(new ItemDetail() { Name = item.Key.Name, Price = item.Sum(x => x.Price), Quantity = item.Sum(x => x.Quantity), Category = (from x1 in item select x1.Category).FirstOrDefault().ToString() }); } } Ctrl.ClearGridView(sellDataView); for (int i = 0; i < modelList.Count; i++) { Console.WriteLine(i); sellDataView.Rows.Add(); sellDataView.Rows[i].Cells[0].Value = modelList[i].Name; sellDataView.Rows[i].Cells[1].Value = modelList[i].Category; sellDataView.Rows[i].Cells[2].Value = modelList[i].Price; sellDataView.Rows[i].Cells[3].Value = modelList[i].Quantity; } this.row = 0; this.status = false; } else { MessageBox.Show("Invalid name and product. Fill in the boxes with correct names."); } }
//use of delegete and event to update the data private void UpdateRecord(object sender, IdentityEventArgs ea) { dataGridView.Rows[row].Cells[0].Value = ea.Name; dataGridView.Rows[row].Cells[1].Value = ea.Category; dataGridView.Rows[row].Cells[2].Value = ea.Price; }