private void pbxReturn_Click(object sender, EventArgs e) { ProductAllForm productall = new ProductAllForm(); productall.Show(); this.Hide(); }
private void pbxProduct_Click(object sender, EventArgs e) { ProductAllForm productAllForm = new ProductAllForm(); productAllForm.Show(); this.Hide(); }
private void pbxDelete_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(lblId.Text)) //----- { SqlConnection sqlConnect = new SqlConnection(connectionString); try { //Conectar sqlConnect.Open(); string sql = "DELETE FROM PRODUCT WHERE ID = @id"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@id", this.lblId.Text)); cmd.ExecuteNonQuery(); MessageBox.Show("Removido com sucesso!"); Log.SalvarLog("Removido Produto", DateTime.Now); ProductAllForm productall = new ProductAllForm(); productall.Show(); this.Hide(); //LogHelper log = new LogHelper(); //log.Insert("User Remove"); } catch (Exception ex) { //Tratar exce��es MessageBox.Show("Erro ao remover categoria!" + ex.Message); //throw; //LogHelper logBD = new LogHelper(); //logBD.PrintLog(Convert.ToString(ex)); } finally { //Fechar sqlConnect.Close(); } } }
private void pbxSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(lblId.Text)) //----- { GetData(); SqlConnection sqlConnect = new SqlConnection(connectionString); try { //Conectar sqlConnect.Open(); string sql = "INSERT INTO PRODUCT(NAME, PRICE, ACTIVE, FK_CATEGORY) VALUES (@name, @price, @active, @category)"; //string sql = "INSERT INTO CATEGORY(NAME, ACTIVE) VALUES (" // + this.tbxName.Text + "," + this.cbxActive.Checked + ")"; 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("@category", ((Category)cmbCategory.SelectedItem).Id)); cmd.Parameters.Add(new SqlParameter("@active", active)); cmd.ExecuteNonQuery(); MessageBox.Show("Adicionado com sucesso!"); Log.SalvarLog("Adicionado Produto", DateTime.Now); CleanData(); } catch (Exception ex) { //Tratar exceções MessageBox.Show("Erro ao adicionar produto!" + ex.Message); CleanData(); } finally { //Fechar sqlConnect.Close(); } CleanData(); } else { SqlConnection sqlConnect = new SqlConnection(connectionString); try { sqlConnect.Open(); string sql = "UPDATE PRODUCT SET NAME = @name, PRICE = @price, ACTIVE = @active 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.cbxActivation.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", ((Category)cmbCategory.SelectedItem).Id)); cmd.ExecuteNonQuery(); MessageBox.Show("Alterações salvas com sucesso!"); Log.SalvarLog("Alterado Produto", DateTime.Now); ProductAllForm productallform = new ProductAllForm(); productallform.Show(); this.Hide(); } catch (Exception Ex) { MessageBox.Show("Erro ao editar este produto!" + "\n\n" + Ex.Message); //throw; } finally { sqlConnect.Close(); } } }