private void btnSave_Click(object sender, EventArgs e) { try { string resp = ""; if (txtNameConfig.Text == string.Empty || txtidcategory.Text == string.Empty || txtCode.Text == string.Empty) { MessageError("Fill the fields"); errorIcon.SetError(txtNameConfig, "Insert the name"); errorIcon.SetError(txtidcategory, "Insert the category id"); errorIcon.SetError(txtCode, "Insert the code"); } else { System.IO.MemoryStream ms = new System.IO.MemoryStream(); this.pxImage.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] image = ms.GetBuffer(); if (this.eNew) { resp = BProduct.Insert(this.txtCode.Text, this.txtNameConfig.Text, this.txtDescription.Text, image, Convert.ToInt32(this.txtidcategory.Text), Convert.ToInt32(this.cbPresentation.SelectedValue)); } else { resp = BProduct.Edit(Convert.ToInt32(this.txtIdProduct.Text), this.txtCode.Text, this.txtNameConfig.Text, this.txtDescription.Text, image, Convert.ToInt32(this.txtidcategory.Text), Convert.ToInt32(this.cbPresentation.SelectedValue)); } if (resp.Equals("OK")) { if (this.eNew) { this.MessageOk("Register saved"); } else { this.MessageOk("Register Edited"); } } else { this.MessageError(resp); } this.eNew = false; this.eEdit = false; this.Enabledbuttons(); this.Clean(); this.ShowValues(); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }