private void ComboBoxCategoria() { SISCategoria_TO SISCategoriaTO = new SISCategoria_TO(); SISCategoriaTO.tag = "PopularComboBoxCategoria"; DataTable dt = new SISCategoria_BO().GetCategoria(SISCategoriaTO); foreach (DataRow row in dt.Rows) { if (row["CAT_NOME"].ToString() != null) { string input = row["CAT_NOME"].ToString(); var myInt = int.Parse(row["CAT_CODIGO"].ToString()); input.Replace(" ", ""); string pattern = @"(?i)[^0-9a-záéíóúàèìòùâêîôûãõç\s]"; string replacement = ""; Regex rgx = new Regex(pattern); string result = rgx.Replace(input, replacement); this.cmbProCategoria.Items.Insert(myInt, input); } } }
public bool Delete(SISCategoria_TO pSISCategoriaTO, bool pOpcao) { bool lresultado = false; try { using (var transacao = TransactionScopeDefault.CreateTransactionScope()) { if (pSISCategoriaTO.tag != null) { if (pSISCategoriaTO.tag.Equals("tag_ExcluirCategoria")) { new SISCategoria_DAO().Delete(pSISCategoriaTO); } if (pSISCategoriaTO.tag.Equals("tag_ExcluirItem")) { new SISCategoria_DAO().Delete(pSISCategoriaTO); } } transacao.Complete(); lresultado = true; } } catch (Exception) { throw; } return(lresultado); }
public bool Save(SISCategoria_TO pCategoriaTO, bool pOpcao) { bool lresultado = false; try { using (var transacao = TransactionScopeDefault.CreateTransactionScope()) { if (pCategoriaTO.tag != null) { if (pCategoriaTO.tag.Equals("SalvarCategoria")) { new SISCategoria_DAO().Save(pCategoriaTO); } if (pCategoriaTO.tag.Equals("AtualizaCategoria")) { new SISCategoria_DAO().UpDate(pCategoriaTO); } } transacao.Complete(); lresultado = true; } } catch (Exception) { throw; } return(lresultado); }
internal bool Save(SISCategoria_TO pCategoriaTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); SqlDataReader reader = null; sql.AppendLine("INSERT INTO CATEGORIA "); sql.AppendLine("VALUES (@CAT_NOME"); sql.AppendLine(" ,@CAT_DESCRICAO"); sql.AppendLine(" ,GETDATE() "); sql.AppendLine(" ,GETDATE() )"); sql.Append(" SELECT @@IDENTITY AS 'ULTIMO_CAT_CODIGO' "); try { command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@CAT_NOME", pCategoriaTO.CAT_NOME); command.Parameters.AddWithValue("@CAT_DESCRICAO", pCategoriaTO.CAT_DESCRICAO); reader = command.ExecuteReader(); if (reader.Read()) { pCategoriaTO.CAT_CODIGO = Convert.ToInt32(reader["ULTIMO_CAT_CODIGO"]); retorno = true; } } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
internal DataTable GetCategoriaProduto(SISCategoria_TO pSISCategoriaTO) { SqlConnection connection = null; DataTable ldt = new DataTable(); try { // criando e abrindo a conexão connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); if (pSISCategoriaTO.tag.Equals("PopularComboBoxCategoria")) { sql.Append(" SELECT "); sql.Append(" CAT_NOME, CAT_DESCRICAO , CAT_CODIGO "); sql.AppendFormat(" FROM CATEGORIA "); } if (pSISCategoriaTO.tag.Equals("PopularLookupCategoria")) { sql.Append(" SELECT "); sql.Append(" CAT_CODIGO, (CAST(CAT_CODIGO AS CHAR(3)) + ' -' + CAT_NOME) AS CAT_NOME "); sql.AppendFormat(" FROM CATEGORIA "); } try { command = new SqlCommand(sql.ToString(), connection); SqlDataAdapter a = new SqlDataAdapter(command); a.Fill(ldt); } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(ldt); }
internal bool UpDate(SISCategoria_TO pSISCategoriaTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception) { throw; } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine("UPDATE CATEGORIA SET "); sql.AppendLine("CAT_NOME = @CAT_NOME ,"); sql.AppendLine("CAT_DESCRICAO = @CAT_DESCRICAO "); sql.AppendLine("WHERE CAT_CODIGO = @CAT_CODIGO"); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@CAT_NOME", pSISCategoriaTO.CAT_NOME); command.Parameters.AddWithValue("@CAT_DESCRICAO", pSISCategoriaTO.CAT_DESCRICAO); command.Parameters.AddWithValue("@CAT_CODIGO", pSISCategoriaTO.CAT_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception) { throw; } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
public DataTable GetCategoria(SISCategoria_TO pSISCategoriaTO) { if (!string.IsNullOrEmpty(pSISCategoriaTO.tag)) { if (pSISCategoriaTO.tag.Equals("PopularComboBoxCategoria")) { } else if (pSISCategoriaTO.tag.Equals("PopularCoqmboBoxCategoria")) { } } return(new SISCategoria_DAO().GetCategoriaProduto(pSISCategoriaTO)); }
internal bool Delete(SISCategoria_TO pSISCategoriaTO) { bool retorno = false; SqlConnection connection = null; try { connection = new SqlConnection(UtilConexion.GetConnectionString("strConexao")); connection.Open(); } catch (Exception ex) { throw new Exception(ex.Message); } SqlCommand command = null; StringBuilder sql = new StringBuilder(); try { sql.AppendLine("DELETE TOP (1) FROM CATEGORIA "); sql.AppendLine(" WHERE CAT_CODIGO = @CAT_CODIGO "); command = new SqlCommand(sql.ToString(), connection); command.Parameters.AddWithValue("@CAT_CODIGO", pSISCategoriaTO.CAT_CODIGO); command.ExecuteNonQuery(); retorno = true; } catch (Exception ex) { throw new Exception(ex.Message); } finally { command.Dispose(); connection.Close(); connection.Dispose(); } return(retorno); }
private void PopularGridCategoria() { SISCategoria_TO SISCategoriaTO = new SISCategoria_TO(); try { SISCategoriaTO.tag = "PopularComboBoxCategoria"; using (DataTable dt = new SISCategoria_BO().GetCategoria(SISCategoriaTO)) { gridViewCategoria.DataSource = dt; }; } catch (Exception ex) { Uteis.ExibirMensagem(ex.Message, titulo, TipoMensagem.Erro); } }
private void SalvarCategoria(object sender, EventArgs e = null) { try { bool lNovo = true; SISCategoria_TO SISCategoriaTO = new SISCategoria_TO(); SISCategoriaTO.tag = "SalvarCategoria"; SISCategoriaTO.CAT_NOME = txtCatNome.Text; SISCategoriaTO.CAT_DESCRICAO = txtCatDescricao.Text; if (new SISCategoria_BO().Save(SISCategoriaTO, lNovo)) { MessageBox.Show("Categoria salva com sucesso."); } } catch (Exception Ex) { MessageBox.Show("Esse erro:'" + Ex + "'Ok"); } }