public void Editar(Meta obj) { FbCommand sqlCommand = new FbCommand(); try { sqlCommand.Connection = this._conexao; sqlCommand.CommandText = "UPDATE META SET EMPRESA = @EMPRESA, FILIAL = @FILIAL, " + "INDICADOR = @INDICADOR, FUNCIONARIO = @FUNCIONARIO, DESCRICAO = @DESCRICAO WHERE CODIGO = @CODIGO"; sqlCommand.Parameters.AddRange(this.ParametrizarComando(obj)); sqlCommand.ExecuteNonQuery(); } catch (FbException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { sqlCommand.Dispose(); } }
public void Cadastrar(Meta obj) { FbCommand sqlCommand = new FbCommand(); try { sqlCommand.Connection = this._conexao; sqlCommand.CommandText = "INSERT INTO META (EMPRESA, FILIAL, DESCRICAO, DATACADASTRO, INDICADOR, FUNCIONARIO) " + "VALUES (@EMPRESA, @FILIAL, @DESCRICAO, @DATACADASTRO, @INDICADOR, @FUNCIONARIO)"; sqlCommand.Parameters.AddRange(this.ParametrizarComando(obj)); sqlCommand.ExecuteNonQuery(); } catch (FbException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { sqlCommand.Dispose(); } }
public void Editar(Meta obj) { IMetaRepositorio umaMetaRepositorio = new MetaDAO(this._conexao); obj.Empresa = this._empresa; obj.Filial = this._filial; umaMetaRepositorio.Editar(obj); List<Periodo> periodos = obj.Periodos; obj = umaMetaRepositorio.Consultar(this._empresa.Codigo, this._filial.Codigo, obj.Codigo); for (int x = 0; x < periodos.Count - 1; x++) { periodos[x].Realizado = obj.Periodos[x].Realizado; } IPeriodoNegocio umPeriodoNegocio = new PeriodoBUS(Conexao.Instacia, this._empresa, this._filial); int i = 0; foreach (var periodo in periodos) { periodo.Meta = obj; periodo.Mes = ++i; periodo.Meta.Codigo = obj.Codigo; periodo.Ano = DateTime.Now.Year; periodo.Empresa = this._empresa; periodo.Filial = this._filial; umPeriodoNegocio.Editar(periodo); } }
public void CadastrarMetasTest() { this.CriaInstancia(); Empresa umaEmpresa = new Empresa(); umaEmpresa.Codigo = "99"; Filial umaFilial = new Filial(); umaFilial.Codigo = "99"; IMetaNegocio umaMetaBUS = new MetaBUS(Conexao.Instacia, umaEmpresa, umaFilial); Meta umaMeta = new Meta(); umaMeta.Empresa = umaEmpresa; umaMeta.Filial = umaFilial; umaMeta.Descricao = "sasdsadsadasd"; umaMeta.Indicador = new Indicador { Codigo = 1 }; umaMeta.Funcionario = new Funcionario { Codigo = 2 }; umaMeta.DataCadastro = DateTime.Now; umaMetaBUS.Cadastrar(umaMeta); }
public void Cadastrar(Meta obj) { IMetaRepositorio umaMetaRepositorio = new MetaDAO(this._conexao); obj.Empresa = this._empresa; obj.Filial = this._filial; umaMetaRepositorio.Cadastrar(obj); IPeriodoNegocio umPeriodoNegocio = new PeriodoBUS(Conexao.Instacia, this._empresa, this._filial); int codigo = umaMetaRepositorio.UltimoId(); int i = 0; foreach (var periodo in obj.Periodos) { periodo.Meta = obj; periodo.Mes = ++i; periodo.Meta.Codigo = codigo; periodo.Ano = DateTime.Now.Year; periodo.Realizado = 0; umPeriodoNegocio.Cadastrar(periodo); } }
public void ExcluirMetasTest() { this.CriaInstancia(); Empresa umaEmpresa = new Empresa(); umaEmpresa.Codigo = "99"; Filial umaFilial = new Filial(); umaFilial.Codigo = "99"; IMetaNegocio umaMetaBUS = new MetaBUS(Conexao.Instacia, umaEmpresa, umaFilial); Meta umaMeta = new Meta(); umaMeta.Empresa = umaEmpresa; umaMeta.Filial = umaFilial; umaMeta.Codigo = 2; umaMetaBUS.Excluir(umaMeta); }
public void Excluir(Meta obj) { FbCommand sqlCommand = new FbCommand(); try { sqlCommand.Connection = this._conexao; sqlCommand.CommandText = "DELETE FROM META WHERE CODIGO = @CODIGO"; sqlCommand.Parameters.AddWithValue("@CODIGO", obj.Codigo); sqlCommand.ExecuteNonQuery(); } catch (FbException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { sqlCommand.Dispose(); } }
public Meta ColetarPeriodos(Meta meta) { meta.Periodos = new List<Periodo>(); IPeriodoRepositorio umPeriodoDAO = new PeriodoDAO(this._conexao); Dictionary<int, string> meses = TRS.Apoio.Meses.PegarMeses(); for (int i = 1; i <= 12; i++) { Periodo umPeriodo = umPeriodoDAO.Consultar(meta.Empresa.Codigo, meta.Filial.Codigo, DateTime.Now.Year, i, meta.Codigo, meta.Funcionario.Codigo); umPeriodo.NomeMes = meses[i]; if (umPeriodo != null) { meta.Periodos.Add(umPeriodo); } } return meta; }
protected IEnumerable<Meta> ConverteDataTableEmList(DataTable dt) { int indexEmpresa = dt.Columns["EMPRESA"].Ordinal; int indexFilial = dt.Columns["FILIAL"].Ordinal; int indexCodigo = dt.Columns["CODIGO"].Ordinal; int indexDescricao = dt.Columns["DESCRICAO"].Ordinal; int indexDataCadastro = dt.Columns["DATACADASTRO"].Ordinal; int indexCodIndicador = dt.Columns["CODINDICADOR"].Ordinal; int indexDescIndicador = dt.Columns["DESCINDICADOR"].Ordinal; int indexCodFuncionario = dt.Columns["CODFUNC"].Ordinal; int indexDescFuncioanrio = dt.Columns["NOMEFUNC"].Ordinal; int indexCodProjeto = dt.Columns["CODPROJETO"].Ordinal; int indexDescProjeto = dt.Columns["DESCPROJETO"].Ordinal; foreach (DataRow linha in dt.Rows) { Meta umaMeta = new Meta(); umaMeta.Empresa = new Empresa(); umaMeta.Empresa.Codigo = linha[indexEmpresa].ToString(); umaMeta.Filial = new Filial(); umaMeta.Filial.Codigo = linha[indexFilial].ToString(); umaMeta.Codigo = Convert.ToInt32(linha[indexCodigo].ToString()); umaMeta.Descricao = linha[indexDescricao].ToString(); umaMeta.DataCadastro = Convert.ToDateTime(linha[indexDataCadastro].ToString()); umaMeta.Indicador = new Indicador(); umaMeta.Indicador.Codigo = Convert.ToInt32(linha[indexCodIndicador].ToString()); umaMeta.Indicador.Descricao = linha[indexDescIndicador].ToString(); umaMeta.Funcionario = new Funcionario(); umaMeta.Funcionario.Codigo = Convert.ToInt32(linha[indexCodFuncionario].ToString()); umaMeta.Funcionario.Nome = linha[indexDescFuncioanrio].ToString(); umaMeta.Projeto = new Projeto(); umaMeta.Projeto.Codigo = linha[indexCodProjeto].ToString() != "" ? Convert.ToInt32(linha[indexCodProjeto].ToString()) : 0; umaMeta.Projeto.Descricao = linha[indexDescProjeto].ToString() != "" ? linha[indexDescProjeto].ToString() : ""; yield return umaMeta; } }
protected List<FbParameter> ParametrizarComando(Meta obj) { List<FbParameter> lista = new List<FbParameter>(); FbParameter sqlpEmpresa = new FbParameter(); sqlpEmpresa.ParameterName = "@EMPRESA"; sqlpEmpresa.Value = obj.Empresa.Codigo; lista.Add(sqlpEmpresa); FbParameter sqlpFilial = new FbParameter(); sqlpFilial.ParameterName = "@FILIAL"; sqlpFilial.Value = obj.Filial.Codigo; lista.Add(sqlpFilial); FbParameter sqlpCodigo = new FbParameter(); sqlpCodigo.ParameterName = "@CODIGO"; sqlpCodigo.Value = obj.Codigo; lista.Add(sqlpCodigo); FbParameter sqlpDescricao = new FbParameter(); sqlpDescricao.ParameterName = "@DESCRICAO"; sqlpDescricao.Value = obj.Descricao; lista.Add(sqlpDescricao); FbParameter sqlpIndicador = new FbParameter(); sqlpIndicador.ParameterName = "@INDICADOR"; sqlpIndicador.Value = obj.Indicador.Codigo; lista.Add(sqlpIndicador); FbParameter sqlpFuncionario = new FbParameter(); sqlpFuncionario.ParameterName = "@FUNCIONARIO"; sqlpFuncionario.Value = obj.Funcionario.Codigo; lista.Add(sqlpFuncionario); if (obj.Codigo == 0) { FbParameter sqlpDataCadastro = new FbParameter(); sqlpDataCadastro.ParameterName = "@DATACADASTRO"; sqlpDataCadastro.Value = obj.DataCadastro; lista.Add(sqlpDataCadastro); } return lista; }
public Meta Consultar(string empresa, string filia, int id) { FbCommand sqlCommand = new FbCommand(); try { sqlCommand.Connection = this._conexao; sqlCommand.CommandText = "SELECT META.EMPRESA, META.FILIAL, META.CODIGO, META.DESCRICAO, META.DATACADASTRO, " + "INDICADOR.CODIGO AS CODINDICADOR, INDICADOR.DESCRICAO AS DESCINDICADOR, " + "FUNCIONARIOS.CODIGO AS CODFUNC, FUNCIONARIOS.NOME AS NOMEFUNC, "+ "PROJETOS.CODIGO AS CODPROJETO, PROJETOS.DESCRICAO AS DESCPROJETO " + "FROM META " + "INNER JOIN INDICADOR ON INDICADOR.CODIGO = META.INDICADOR " + "INNER JOIN FUNCIONARIOS ON FUNCIONARIOS.CODIGO = META.FUNCIONARIO " + "LEFT JOIN PROJETOS ON PROJETOS.META = META.CODIGO " + "LEFT JOIN SYS_COMPANY ON SYS_COMPANY.EMPRESA = META.EMPRESA " + "LEFT JOIN SYS_BRANCH ON SYS_BRANCH.FILIAL = META.FILIAL " + "WHERE ((META.EMPRESA = @EMPRESA) OR (META.EMPRESA = '**')) AND " + "((META.FILIAL = @FILIAL) OR (META.FILIAL = '**')) AND META.CODIGO = @CODIGO"; sqlCommand.Parameters.AddWithValue("@EMPRESA", empresa); sqlCommand.Parameters.AddWithValue("@FILIAL", filia); sqlCommand.Parameters.AddWithValue("@CODIGO", id); FbDataReader sqlReader = sqlCommand.ExecuteReader(); Meta umaMeta = new Meta(); int indexEmpresa = sqlReader.GetOrdinal("EMPRESA"); int indexFilial = sqlReader.GetOrdinal("FILIAL"); int indexCodigo = sqlReader.GetOrdinal("CODIGO"); int indexDescricao = sqlReader.GetOrdinal("DESCRICAO"); int indexDataCadastro = sqlReader.GetOrdinal("DATACADASTRO"); int indexCodIndicador = sqlReader.GetOrdinal("CODINDICADOR"); int indexDescIndicador = sqlReader.GetOrdinal("DESCINDICADOR"); int indexCodFuncionario = sqlReader.GetOrdinal("CODFUNC"); int indexDescFuncioanrio = sqlReader.GetOrdinal("NOMEFUNC"); int indexCodProjeto = sqlReader.GetOrdinal("CODPROJETO"); int indexDescProjeto = sqlReader.GetOrdinal("DESCPROJETO"); while (sqlReader.Read()) { umaMeta.Empresa = new Empresa(); umaMeta.Empresa.Codigo = sqlReader.GetString(indexEmpresa); umaMeta.Filial = new Filial(); umaMeta.Filial.Codigo = sqlReader.GetString(indexFilial); umaMeta.Codigo = sqlReader.GetInt32(indexCodigo); umaMeta.Descricao = sqlReader.GetString(indexDescricao); umaMeta.DataCadastro = sqlReader.GetDateTime(indexDataCadastro); umaMeta.Indicador = new Indicador(); umaMeta.Indicador.Codigo = sqlReader.GetInt32(indexCodIndicador); umaMeta.Indicador.Descricao = sqlReader.GetString(indexDescIndicador); umaMeta.Funcionario = new Funcionario(); umaMeta.Funcionario.Codigo = sqlReader.GetInt32(indexCodFuncionario); umaMeta.Funcionario.Nome = sqlReader.GetString(indexDescFuncioanrio); umaMeta.Projeto = new Projeto(); umaMeta.Projeto.Codigo = sqlReader[indexCodProjeto] != DBNull.Value ? sqlReader.GetInt32(indexCodProjeto) : 0; umaMeta.Projeto.Descricao = sqlReader[indexDescProjeto] != DBNull.Value ? sqlReader.GetString(indexDescProjeto) : "0"; } return this.ColetarPeriodos(umaMeta); } catch (FbException ex) { throw ex; } catch (Exception ex) { throw ex; } finally { sqlCommand.Dispose(); } }
public ActionResult Delete(int id, Meta meta) { try { Conexao.Ativar(true); Usuario umUsuario = (Usuario)Session["UsuarioLogado"]; IMetaNegocio umaMetaBus = new MetaBUS(Conexao.Instacia, umUsuario.Funcionario.Empresa, umUsuario.Funcionario.Filial); meta.Codigo = id; meta.Funcionario = (Funcionario)Session["Func"]; umaMetaBus.Excluir(meta); return RedirectToAction("Index", new { st = "ok" }); } catch { return RedirectToAction("Index", new { st = "er" }); } finally { if (Conexao.Instacia.State == System.Data.ConnectionState.Open) { Conexao.Ativar(false); } } }
public ActionResult Create(Meta meta) { try { Conexao.Ativar(true); Usuario umUsuario = (Usuario)Session["UsuarioLogado"]; IMetaNegocio umaMetaBUS = new MetaBUS(Conexao.Instacia, umUsuario.Funcionario.Empresa, umUsuario.Funcionario.Filial); meta.DataCadastro = DateTime.Now; umaMetaBUS.Cadastrar(meta); return RedirectToAction("Index", new { st = "ok" }); } catch { return RedirectToAction("Index", new { st = "er" }); } finally { if (Conexao.Instacia.State == System.Data.ConnectionState.Open) { Conexao.Ativar(false); } } }
// // GET: /Meta/Create public ActionResult Create() { ViewBag.Title = "Cadastro - Metas"; try { Conexao.Ativar(true); Usuario umUsuario = (Usuario)Session["UsuarioLogado"]; if (umUsuario.IsAdministrador) { this.CarregarIndicadores(umUsuario); this.CarregarFuncionarios(umUsuario); Meta umaMeta = new Meta(); return View(umaMeta); } else { return RedirectToAction("Index", new { st = "er" }); } } catch (Exception) { return RedirectToAction("Index", new { st = "er" }); } finally { if (Conexao.Instacia.State == System.Data.ConnectionState.Open) { Conexao.Ativar(false); } } }
public void Excluir(Meta obj) { IMetaRepositorio umaMetaRepositorio = new MetaDAO(this._conexao); umaMetaRepositorio.Excluir(obj); IPeriodoNegocio umPeriodoNegocio = new PeriodoBUS(this._conexao, this._empresa, this._filial); for (int i = 1; i <= 12; i++) { Periodo umPeriodo = new Periodo(); umPeriodo.Meta = new Meta(); umPeriodo.Meta.Codigo = obj.Codigo; umPeriodo.Meta.Funcionario = obj.Funcionario; umPeriodo.Ano = DateTime.Now.Year; umPeriodo.Mes = i; umPeriodoNegocio.Excluir(umPeriodo); } }