private void btnDel_Click(object sender, EventArgs e) { if (txtCat.Text.Trim() == "") { MessageBox.Show("Select a category"); return; } cCategory cat = new cCategory(); cat.Category = txtCat.Text; if (cat.CategoryDelete()) { MessageBox.Show("Deleted"); txtCat.Clear(); } else MessageBox.Show("Not Deleted"); LoadCategories(); }
private void btnAdd_Click(object sender, EventArgs e) { if (txtCat.Text.Trim() == "") { MessageBox.Show("Category required"); return; } cCategory cat = new cCategory(0, txtCat.Text, dtpDtAdd.Value.ToString()); if (cat.checkCategory()) { MessageBox.Show("This category already exits!"); return; } if (cat.SaveRecord()) { MessageBox.Show("Saved"); txtCat.Clear(); txtCat.Focus(); } }
private void LoadCategories() { DataSet ds = new DataSet(); cCategory cat = new cCategory(); ds = cat.CategoryGet(); cmbCtgy.DataSource = ds.Tables[0]; cmbCtgy.ValueMember = "CategoryID"; cmbCtgy.DisplayMember = "Category"; cmbCtgy.SelectedIndex = -1; }
private void btnSave_Click(object sender, EventArgs e) { if (txtCat.Text.Trim() == "") { MessageBox.Show("Select a category"); return; } cCategory cat = new cCategory(); cat.CategoryID = Convert.ToUInt32(dgvCat["CategoryID", dgvCat.CurrentCell.RowIndex].Value); cat.Category = txtCat.Text; cat.DateAdded = dtpDtAdd.Value.ToString(); if (cat.checkCategory()) { MessageBox.Show("This category already exists!"); return; } if (cat.SaveRecord()) { MessageBox.Show("Saved"); txtCat.Clear(); } LoadCategories(); }
private void LoadCategories() { DataSet ds = new DataSet(); try { cCategory cat = new cCategory(); cat.CategoryID = 0; ds = cat.CategoryGet(); dgvCat.DataSource = ds.Tables[0]; dgvCat.Columns[0].HeaderText = "Category ID"; dgvCat.Columns[1].HeaderText = "Category"; dgvCat.Columns[2].HeaderText = "Date Added"; dgvCat.Columns[0].Visible = false; dgvCat.Columns[1].Width = 200; dgvCat.Columns[2].Width = 200; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { ds.Dispose(); } txtCat.Enabled = false; txtCat.Focus(); }