void ValidarDTO(ITENS_ESTOQUE_DTO ITENS_ESTOQUE) { if (string.IsNullOrEmpty(ITENS_ESTOQUE.SITUACAO)) { throw new ValidaException("Favor informa a situação"); } if (string.IsNullOrEmpty(ITENS_ESTOQUE.ITEM)) { throw new ValidaException("Favor informa o item"); } if (string.IsNullOrEmpty(ITENS_ESTOQUE.TIPO)) { throw new ValidaException("Favor informa o tipo"); } if (string.IsNullOrEmpty(ITENS_ESTOQUE.UNIDADE_MEDIDA)) { throw new ValidaException("Favor informa a unidade medida"); } if (ITENS_ESTOQUE.QUANTIDADE == null) { throw new ValidaException("Favor informa a quantidade"); } if (ITENS_ESTOQUE.VALOR_UNITARIO == null) { throw new ValidaException("Favor informa o valor unitário"); } if (ITENS_ESTOQUE.VALOR_TOTAL == null) { throw new ValidaException("Favor informa o valor total"); } }
private void DtgItensEstoque_DoubleClick(object sender, EventArgs e) { try { //Setando o mousepointer para ocupado. Cursor.Current = Cursors.WaitCursor; //Verifica se existem registros no datagrid if (dtgItensEstoque.RowCount == 0) { return; } //Visualizando o registro selecionado int Id = Convert.ToInt32(dtgItensEstoque.CurrentRow.Cells["Id"].Value.ToString()); if (Id != 0) { itens_estoque = new ITENS_ESTOQUE_BLL().Seleciona(Id); PopularTelaItensEstoque(); tabItensEstoque_InfoDoc.SelectedTab = tabItensEstoque_Info; } else { throw new Exception("O Descricao do registro selecionado está incorreto!"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void Alterar(ITENS_ESTOQUE_DTO ITENS_ESTOQUE) { using (SqlConnection scn = new SqlConnection(this.strConnection)) { try { scn.Open(); SqlCommand scm = scn.CreateCommand(); scm.Connection = scn; StringBuilder sb = new StringBuilder(); sb.Append("UPDATE ITENS_ESTOQUE "); sb.Append(" SET SITUACAO = @SITUACAO "); sb.Append(" ,ITEM = @ITEM "); sb.Append(" ,TIPO = @TIPO "); sb.Append(" ,UNIDADE_MEDIDA = @UNIDADE_MEDIDA"); sb.Append(" ,QUANTIDADE = @QUANTIDADE "); sb.Append(" ,VALOR_UNITARIO = @VALOR_UNITARIO"); sb.Append(" ,VALOR_TOTAL = @VALOR_TOTAL "); sb.Append(" ,OBSERVACAO = @OBSERVACAO "); sb.Append(" WHERE ID = @ID "); try { scm.CommandText = sb.ToString(); Popular_Parametros(ITENS_ESTOQUE, scm); scm.ExecuteNonQuery(); //RegistrarDependente(Cliente); } catch (Exception e) { try { throw e; } catch (SqlException ex) { throw new Exception("Erro ao gravar dados do registro atual: " + e.Message + " não foi possível reverter transação,motivo: " + ex.Message); } } } catch (SqlException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { scn.Close(); } } }
public void Alterar(ITENS_ESTOQUE_DTO ITENS_ESTOQUE) { try { ValidarDTO(ITENS_ESTOQUE); DAO.Alterar(ITENS_ESTOQUE); } catch (Exception ex) { throw ex; } }
public int Incluir(ITENS_ESTOQUE_DTO ITENS_ESTOQUE) { try { ValidarDTO(ITENS_ESTOQUE); return(DAO.Incluir(ITENS_ESTOQUE)); } catch (Exception ex) { throw ex; } }
public void Popular_DTO(ITENS_ESTOQUE_DTO ITENS_ESTOQUE, SqlDataReader dtr) { try { ITENS_ESTOQUE.ID = (dtr["Id"]) == DBNull.Value ? (int?)null : Convert.ToInt32(dtr["Id"]); ITENS_ESTOQUE.SITUACAO = Convert.ToString(dtr["SITUACAO"]); ITENS_ESTOQUE.ITEM = Convert.ToString(dtr["ITEM"]); ITENS_ESTOQUE.TIPO = Convert.ToString(dtr["TIPO"]); ITENS_ESTOQUE.UNIDADE_MEDIDA = Convert.ToString(dtr["UNIDADE_MEDIDA"]); ITENS_ESTOQUE.QUANTIDADE = (dtr["QUANTIDADE"]) == DBNull.Value ? (int?)null : Convert.ToInt32(dtr["QUANTIDADE"]); ITENS_ESTOQUE.VALOR_UNITARIO = dtr["VALOR_UNITARIO"] == DBNull.Value ? (decimal?)null : Convert.ToDecimal(dtr["VALOR_UNITARIO"]); ITENS_ESTOQUE.VALOR_TOTAL = dtr["VALOR_TOTAL"] == DBNull.Value ? (decimal?)null : Convert.ToDecimal(dtr["VALOR_TOTAL"]); ITENS_ESTOQUE.OBSERVACAO = Convert.ToString(dtr["OBSERVACAO"]); } catch { } }
void Popular_Parametros(ITENS_ESTOQUE_DTO ITENS_ESTOQUE, SqlCommand scm) { scm.Parameters.AddWithValue("@ID", ITENS_ESTOQUE.ID); scm.Parameters.AddWithValue("@SITUACAO", ITENS_ESTOQUE.SITUACAO); scm.Parameters.AddWithValue("@ITEM", ITENS_ESTOQUE.ITEM); scm.Parameters.AddWithValue("@TIPO", ITENS_ESTOQUE.TIPO); scm.Parameters.AddWithValue("@UNIDADE_MEDIDA", ITENS_ESTOQUE.UNIDADE_MEDIDA); scm.Parameters.AddWithValue("@QUANTIDADE", ITENS_ESTOQUE.QUANTIDADE); scm.Parameters.AddWithValue("@VALOR_UNITARIO", ITENS_ESTOQUE.VALOR_UNITARIO); scm.Parameters.AddWithValue("@VALOR_TOTAL", ITENS_ESTOQUE.VALOR_TOTAL); scm.Parameters.AddWithValue("@OBSERVACAO", ITENS_ESTOQUE.OBSERVACAO); foreach (SqlParameter Parameter in scm.Parameters) { if (Parameter.Value == null) { Parameter.Value = DBNull.Value; } } }
public ITENS_ESTOQUE_DTO Seleciona(int Id) { using (SqlConnection scn = new SqlConnection(this.strConnection)) { SqlDataReader dtr = null; ITENS_ESTOQUE_DTO ITENS_ESTOQUE = new ITENS_ESTOQUE_DTO(); try { StringBuilder sb = new StringBuilder(); sb.Append("SELECT * FROM [dbo].[ITENS_ESTOQUE] Where (ID = " + Id + ");"); scn.Open(); SqlCommand scm = new SqlCommand(sb.ToString(), scn); dtr = scm.ExecuteReader(); if (dtr.Read()) { Popular_DTO(ITENS_ESTOQUE, dtr); } return(ITENS_ESTOQUE); } catch (SqlException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { if (dtr != null) { dtr.Close(); } scn.Close(); } } }
public Cadastros(string tela = "", int ID = 0) { InitializeComponent(); PopularCombos(); try { switch (tela.ToLower()) { //MOTORISTA case "motorista": motorista = new MOTORISTA_DTO(); txtMotorista_ID.Enabled = false; break; //VEICULO case "veiculo": veiculo = new VEICULO_DTO(); txtVeiculo_Id.Enabled = false; break; //TRANSAÇÕES case "transacoes": transacoes = new TRANSACOES_DTO(); txtTransacao_Id.Enabled = false; break; //ITEM ESTOQUE case "item estoque": itens_estoque = new ITENS_ESTOQUE_DTO(); txtItemEstoque_ID.Enabled = false; break; } } catch (Exception ex) { throw ex; } }
public int Incluir(ITENS_ESTOQUE_DTO ITENS_ESTOQUE) { using (SqlConnection scn = new SqlConnection(this.strConnection)) { try { scn.Open(); SqlCommand scm = scn.CreateCommand(); SqlTransaction transaction; transaction = scn.BeginTransaction(IsolationLevel.ReadCommitted); scm.Connection = scn; scm.Transaction = transaction; StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append("INSERT INTO [ITENS_ESTOQUE]"); sb.Append(" ([SITUACAO] "); sb.Append(" ,[ITEM] "); sb.Append(" ,[TIPO] "); sb.Append(" ,[UNIDADE_MEDIDA] "); sb.Append(" ,[QUANTIDADE] "); sb.Append(" ,[VALOR_UNITARIO] "); sb.Append(" ,[VALOR_TOTAL] "); sb.Append(" ,[OBSERVACAO]) "); sb.Append("VALUES "); sb.Append(" (@SITUACAO, "); sb.Append(" @ITEM, "); sb.Append(" @TIPO, "); sb.Append(" @UNIDADE_MEDIDA, "); sb.Append(" @QUANTIDADE, "); sb.Append(" @VALOR_UNITARIO, "); sb.Append(" @VALOR_TOTAL, "); sb.Append(" @OBSERVACAO) "); sb.Append("select Scope_Identity();"); try { scm.CommandText = sb.ToString(); Popular_Parametros(ITENS_ESTOQUE, scm); ITENS_ESTOQUE.ID = Convert.ToInt32(scm.ExecuteScalar()); transaction.Commit(); return(Convert.ToInt32(ITENS_ESTOQUE.ID)); } catch (Exception e) { try { transaction.Rollback(); throw e; } catch (SqlException ex) { if (transaction == null || transaction.Connection == null) { throw ex; } else { throw new Exception("Erro ao gravar dados do registro atual: " + e.Message + " não foi possível reverter transação,motivo: " + ex.Message); } } } } catch (SqlException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { scn.Close(); } } }