private void pbxBack_Click(object sender, EventArgs e) { ProductAllForm productallForm = new ProductAllForm(); productallForm.Show(); this.Hide(); }
private void pbxProduct_Click(object sender, EventArgs e) { ProductAllForm productallform = new ProductAllForm(); productallform.Show(); }
private void pbxProduct_Click(object sender, EventArgs e) { ProductAllForm pa = new ProductAllForm(); pa.Show(); }
private void pbxSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(lblId.Text)) { SqlConnection sqlConnect = new SqlConnection(connectionString); try { GetData(); sqlConnect.Open(); string sql = "INSERT INTO PRODUCT(NAME, PRICE, ACTIVE, FK_PRODUCT) VALUES (@name, @price, @active, @category)"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@name", name)); cmd.Parameters.Add(new SqlParameter("@price", price)); cmd.Parameters.Add(new SqlParameter("@active", active)); cmd.Parameters.Add(new SqlParameter("@category", ((Category)cmbCategory.SelectedItem).Id)); cmd.ExecuteNonQuery(); MessageBox.Show("Adicionado com sucesso!"); Log.SalvarLog("Produto Adicionado", "Adição", DateTime.Now); CleanData(); } catch (Exception ex) { MessageBox.Show("Erro ao adicionar produto!" + ex.Message); CleanData(); } finally { sqlConnect.Close(); } } else { SqlConnection sqlConnect = new SqlConnection(connectionString); try { sqlConnect.Open(); string sql = "UPDATE PRODUCT SET NAME = @name, ACTIVE = @active, PRICE = @price, FK_PRODUCT = @fk_product Where ID = @id"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@name", this.tbxName.Text)); cmd.Parameters.Add(new SqlParameter("@active", this.cbxActive.Checked)); cmd.Parameters.Add(new SqlParameter("@price", this.tbxPrice.Text)); cmd.Parameters.Add(new SqlParameter("@id", this.lblId.Text)); cmd.Parameters.Add(new SqlParameter("@fk_product", ((Category)(cmbCategory.SelectedItem)).Id)); cmd.ExecuteNonQuery(); MessageBox.Show("Alterações salvas com sucesso!"); Log.SalvarLog("Produto Editado", "Edição", DateTime.Now); } catch (Exception Ex) { MessageBox.Show("Erro ao editar este produto!" + "\n\n" + Ex.Message); throw; } finally { sqlConnect.Close(); ProductAllForm productAllForm = new ProductAllForm(); productAllForm.Show(); this.Hide(); } } ; }