private void pbxBack_Click(object sender, EventArgs e) { CategoryAllForm categoryAllForm = new CategoryAllForm(); categoryAllForm.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 CATEGORY 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 Categoria", DateTime.Now); CategoryAllForm categoryAllForm = new CategoryAllForm(); categoryAllForm.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 CATEGORY(NAME, ACTIVE) VALUES (@name, @active)"; //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("@active", active)); cmd.ExecuteNonQuery(); MessageBox.Show("Adicionado com sucesso!"); Log.SalvarLog("Adicionado Categoria", DateTime.Now); CleanData(); } catch (Exception ex) { //Tratar exceções MessageBox.Show("Erro ao adicionar categoria!" + ex.Message); CleanData(); } finally { //Fechar 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("Altereções salvas com sucesso!"); Log.SalvarLog("Alterado Categoria", DateTime.Now); } catch (Exception Ex) { MessageBox.Show("Erro ao editar esta categoria!" + "\n\n" + Ex.Message); throw; } finally { sqlConnect.Close(); CategoryAllForm categoryAllForm = new CategoryAllForm(); categoryAllForm.Show(); this.Hide(); } } }