private void pbxBack_Click(object sender, EventArgs e) { CategoryAllForm caf = new CategoryAllForm(aux); caf.Show(); this.Hide(); }
private void pbxDelete_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(lblId.Text)) { SqlConnection sqlConnect = new SqlConnection(connectionString); try { sqlConnect.Open(); string sql = "UPDATE CATEGORY SET ACTIVE = @active WHERE ID = @id"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@id", lblActive.Text)); cmd.Parameters.Add(new SqlParameter("@active", false)); cmd.ExecuteNonQuery(); MessageBox.Show("categoria inativa!"); Log.SaveLog("Categoria Excluida", "Exclusão", DateTime.Now); CategoryAllForm caf = new CategoryAllForm(aux); caf.Show(); this.Hide(); } catch (Exception Ex) { MessageBox.Show("Erro ao desativar esta categoria!" + "\n\n" + Ex.Message); throw; } finally { sqlConnect.Close(); } } }
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 CATEGORY(NAME, ACTIVE) VALUES (@name, @active)"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@name", name)); cmd.Parameters.Add(new SqlParameter("@active", active)); cmd.ExecuteNonQuery(); MessageBox.Show("Adicionado com sucesso!"); Log.SaveLog("Categoria Adicionada", "Adição", DateTime.Now); CleanData(); } catch (Exception ex) { MessageBox.Show("Erro ao adicionar categoria!" + ex.Message); CleanData(); } finally { sqlConnect.Close(); } } else { SqlConnection sqlConnect = new SqlConnection(connectionString); try { sqlConnect.Open(); string sql = "UPDATE CATEGORY SET NAME = @name, ACTIVE = @active Where ID = @id"; SqlCommand cmd = new SqlCommand(sql, sqlConnect); cmd.Parameters.Add(new SqlParameter("@id", this.lblId.Text)); cmd.Parameters.Add(new SqlParameter("@name", this.tbxName.Text)); cmd.Parameters.Add(new SqlParameter("@active", this.cbxActive.Checked)); cmd.ExecuteNonQuery(); MessageBox.Show("Alterações salvas com sucesso!"); Log.SaveLog("Categoria Editada ", "Edição", DateTime.Now); } catch (Exception Ex) { MessageBox.Show("Erro ao editar esta categoria!" + "\n\n" + Ex.Message); throw; } finally { sqlConnect.Close(); CategoryAllForm caf = new CategoryAllForm(aux); caf.Show(); this.Hide(); } } }
private void pbxCategory_Click(object sender, EventArgs e) { CategoryAllForm categoryAllForm = new CategoryAllForm(aux); categoryAllForm.Show(); }