public void editProduct() { frmProductDetail ProductDetail = new frmProductDetail(true, this); ProductDetail.setUpdateState(true); if (bool.Parse(form.getStatusProduct().Text)) { ProductDetail.getRadioButtonTrue().Checked = true; } else { ProductDetail.getRadioButtonFalse().Checked = true; } ProductDetail.getPrice().Text = form.getPriceProduct().Text; ProductDetail.getProductName().Text = form.getNameProduct().Text; ProductDetail.getQuantity().Text = form.getQuantityProduct().Text; ProductDetail.getComboBoxCategory().DataSource = bindingSourceCategory; ProductDetail.getComboBoxCategory().DisplayMember = "name"; ProductDetail.getComboBoxCategory().ValueMember = "idCategory"; DataTable dataTableCategory = (DataTable)bindingSourceCategory.DataSource; var selectedIdCategory = ""; foreach (DataRow row in dataTableCategory.Rows) { if (row["name"].ToString().Equals(form.getCategoryProduct().Text)) { selectedIdCategory = row["idCategory"].ToString(); } } ProductDetail.getComboBoxCategory().SelectedValue = selectedIdCategory; ProductDetail.ShowDialog(); }
public bool validateProduct(frmProductDetail frmProductDetail) { StringBuilder checkMessage = new StringBuilder(); if (frmProductDetail.getProductName().Text.Equals("")) { checkMessage.Append("Product name invalid\n"); } try { float.Parse(frmProductDetail.getPrice().Text); }catch (Exception e) { checkMessage.Append("Product price invalid\n"); } try { int.Parse(frmProductDetail.getQuantity().Text); }catch (Exception e) { checkMessage.Append("Product quantity invalid\n"); } if (checkMessage.Length > 0) { MessageBox.Show(checkMessage.ToString()); return(false); } return(true); }
private void button1_Click(object sender, EventArgs e) { frmProductDetail frm = new frmProductDetail(); frm.Show(); frm.Activate(); }
public void addProduct() { frmProductDetail ProductDetail = new frmProductDetail(true, this); ProductDetail.setUpdateState(false); ProductDetail.getComboBoxCategory().DataSource = bindingSourceCategory; ProductDetail.getComboBoxCategory().DisplayMember = "name"; ProductDetail.getComboBoxCategory().ValueMember = "idCategory"; ProductDetail.getRadioButtonTrue().Checked = true; ProductDetail.getRadioButtonFalse().Visible = false; ProductDetail.ShowDialog(); }
public void saveProduct(frmProductDetail frmProductDetail) { if (!validateProduct(frmProductDetail)) { return; } TblProductsDTO tblProductsDTO = new TblProductsDTO(); tblProductsDTO.price = float.Parse(frmProductDetail.getPrice().Text); tblProductsDTO.name = frmProductDetail.getProductName().Text; tblProductsDTO.quantity = int.Parse(frmProductDetail.getQuantity().Text); tblProductsDTO.idCategory = frmProductDetail.getComboBoxCategory().SelectedValue.ToString(); if (frmProductDetail.getRadioButtonFalse().Checked) { tblProductsDTO.status = false; } else { tblProductsDTO.status = true; } if (!frmProductDetail.getUpdateState()) { if (productModel.addProduct(tblProductsDTO)) { MessageBox.Show(MessageUtil.SAVE_SUCCESS); getAllProduct(); } else { MessageBox.Show(MessageUtil.ERROR + " save Product"); } } else { tblProductsDTO.idProduct = form.getIdProduct().Text; if (productModel.updateProduct(tblProductsDTO)) { MessageBox.Show(MessageUtil.SAVE_SUCCESS); getAllProduct(); } else { MessageBox.Show(MessageUtil.ERROR + " save Product"); } } }