private void btnSave_Click(object sender, EventArgs e) { ep.Clear(); int er = 0; if (txtName.Text == "") { er++; ep.SetError(txtName, "Required"); } if (txtDescription.Text == "") { er++; ep.SetError(txtDescription, "Required"); } if (er > 0) { return; } DAL.Brand brand = new DAL.Brand(); brand.Id = Id; brand.Name = txtName.Text; brand.Description = txtDescription.Text; if (brand.Update()) { MessageBox.Show(@"Data Saved"); } else { MessageBox.Show(brand.Error); } }
private void btnDelete_Click(object sender, EventArgs e) { if (dgvBrand.SelectedRows.Count <= 0) { return; } DialogResult dr = MessageBox.Show("Are you sure ?", "Confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr != DialogResult.Yes) { return; } DAL.Brand br = new DAL.Brand(); br.Id = Convert.ToInt32(dgvBrand.SelectedRows[0].Cells["colId"].Value); if (br.Delete()) { MessageBox.Show("Deleted"); btnSearch.PerformClick(); } else { MessageBox.Show(br.Error); } }
private void btnSearch_Click(object sender, EventArgs e) { DAL.Brand br = new DAL.Brand(); br.Search = txtSearch.Text; br.Origin = txtOrigin.Text; dgvBrand.DataSource = br.Select().Tables[0]; }
private void buttonDelete_Click(object sender, EventArgs e) { if (proGrid1.SelectedRows.Count <= 0) { return; } DialogResult confurmDelete = MessageBox.Show("Are you sure?", "Confirmation.", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (confurmDelete != DialogResult.Yes) { return; } DAL.Brand brandDelete = new DAL.Brand(); string ids = ""; for (int i = 0; i < proGrid1.SelectedRows.Count; i++) { ids += proGrid1.SelectedRows[i].Cells["ColId"].Value.ToString() + ", "; } ids = ids.Substring(0, ids.Length - 2); if (brandDelete.Delete(ids)) { MessageBox.Show("Data deleted"); buttonSearch.PerformClick(); } else { MessageBox.Show(brandDelete.Error); } }
public int Save(MODEL.BrandModel model) { try { using (_context = new HSSNInventoryEntities()) { var addModel = new Brand() { BrandName = model.BrandName, Description = model.Description }; _context.Entry(addModel).State = EntityState.Added; _context.SaveChanges(); return addModel.BrandId; } } catch (Exception e) { //Console.WriteLine(e); return 0; } }