private void btnSave_Click(object sender, EventArgs e) { int er = 0; if (txtName.Text == "") { er++; ep.SetError(txtName, "Required"); } if (txtDescription.Text == "") { er++; ep.SetError(txtDescription, "Required"); } if (txtCode.Text == "") { er++; ep.SetError(txtCode, "Required"); } if (txtType.Text == "") { er++; ep.SetError(txtOffer, "Required"); } if (txtTag.Text == "") { er++; ep.SetError(txtTag, "Required"); } if (txtDiscount.Text == "") { er++; ep.SetError(txtDiscount, "Required"); } if (cmbCategory.SelectedValue == null || cmbCategory.SelectedValue.ToString() == "") { er++; ep.SetError(cmbCategory, "Select One"); } if (cmbBrand.SelectedValue == null || cmbBrand.SelectedValue.ToString() == "") { er++; ep.SetError(cmbBrand, "Select One"); } if (er > 0) { return; } DAL.Product p = new DAL.Product(); p.Id = Id; p.BrandId = Convert.ToInt32(cmbBrand.SelectedValue); p.CategoryId = Convert.ToInt32(cmbCategory.SelectedValue); p.Code = txtCode.Text; p.Description = txtDescription.Text; p.Discount = Convert.ToDouble(txtDiscount.Text); p.Name = txtName.Text; p.Offers = txtOffer.Text; p.Tag = txtTag.Text; p.Type = txtType.Text; if (p.Update()) { MessageBox.Show("Data Saved"); } else { MessageBox.Show(p.Error); } }
private void buttonSave_Click(object sender, EventArgs e) { int error = 0; errorProvider.Clear(); if (textBoxName.Text == "") { error++; errorProvider.SetError(textBoxName, "Required"); } if (textBoxCode.Text == "") { error++; errorProvider.SetError(textBoxCode, "Required"); } if (textBoxDescription.Text == "") { error++; errorProvider.SetError(textBoxDescription, "Required"); } if (comboBoxBrand.Text == "") { error++; errorProvider.SetError(comboBoxBrand, "Required"); } if (comboBoxCategory.Text == "") { error++; errorProvider.SetError(comboBoxCategory, "Required"); } if (textBoxPrice.Text == "") { error++; errorProvider.SetError(textBoxPrice, "Required"); } if (error > 0) { return; } productEdit.Name = textBoxName.Text; productEdit.Code = textBoxCode.Text; productEdit.Description = textBoxDescription.Text; productEdit.BrandId = Convert.ToInt32(comboBoxBrand.SelectedValue); productEdit.CategoryId = Convert.ToInt32(comboBoxCategory.SelectedValue); productEdit.Price = Convert.ToDouble(textBoxPrice.Text); if (productEdit.Update()) { MessageBox.Show("Product Save"); textBoxName.Text = ""; textBoxCode.Text = ""; textBoxDescription.Text = ""; comboBoxBrand.Text = ""; comboBoxCategory.Text = ""; textBoxPrice.Text = ""; textBoxName.Focus(); } else { MessageBox.Show(productEdit.Error); } }