コード例 #1
0
ファイル: EmpresaDAO.cs プロジェクト: romuloprg/crmonline
        public bool Inserir(EmpresaEntity empresa)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("INSERT INTO Empresa VALUES (@cnpjEmp, @nomEmp, @endEmp, @cidEmp, @ufEmp, @telEmp)", connection);
                command.Parameters.AddWithValue("@cnpjEmp", empresa.cnpjEmp);
                command.Parameters.AddWithValue("@nomEmp", empresa.nomEmp);
                command.Parameters.AddWithValue("@endEmp", empresa.endEmp);
                command.Parameters.AddWithValue("@cidEmp", empresa.cidEmp);
                command.Parameters.AddWithValue("@ufEmp", empresa.ufEmp);
                command.Parameters.AddWithValue("@telEmp", empresa.telEmp);
                command.ExecuteNonQuery();
            }
            catch
            {
                return false;
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }

            return true;
        }
コード例 #2
0
ファイル: EmpresaDAO.cs プロジェクト: romuloprg/crmonline
        public bool Atualizar(EmpresaEntity empresa)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("UPDATE Empresa SET nomEmp = @nomEmp, endEmp = @endEmp, cidEmp = @cidEmp, ufEmp = @ufEmp, telEmp = @telEmp WHERE cnpjEmp = @cnpjEmp", connection);
                command.Parameters.AddWithValue("@cnpjEmp", empresa.cnpjEmp);
                command.Parameters.AddWithValue("@nomEmp", empresa.nomEmp);
                command.Parameters.AddWithValue("@endEmp", empresa.endEmp);
                command.Parameters.AddWithValue("@cidEmp", empresa.cidEmp);
                command.Parameters.AddWithValue("@ufEmp", empresa.ufEmp);
                command.Parameters.AddWithValue("@telEmp", empresa.telEmp);
                command.ExecuteNonQuery();
            }
            catch
            {
                return false;
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }

            return true;
        }
コード例 #3
0
ファイル: Empresa.aspx.cs プロジェクト: romuloprg/crmonline
        protected void btnGravar_Click(object sender, EventArgs e)
        {
            EmpresaEntity empresa = new EmpresaEntity();
            EmpresaController empresaController = new EmpresaController();

            if (txtCnpj.Text == "" || txtNome.Text == "" || txtTelefone.Text == "")
                this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Preencha todos os campos!');</script>");
            else
            {
                empresa.cnpjEmp = txtCnpj.Text;
                empresa.nomEmp = txtNome.Text;
                empresa.endEmp = txtEndereco.Text;
                empresa.cidEmp = txtCidade.Text;
                empresa.ufEmp = txtUf.Text;
                empresa.telEmp = txtTelefone.Text;

                if (Session["cnpjEmp"] != null)
                {
                    if (empresaController.Atualizar(empresa))
                        this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Empresa alterada com sucesso!'); window.location.href='Home.aspx';</script>");
                    else
                        this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Erro na alteração do registro!');</script>");
                }
                else
                {
                    if (empresaController.Inserir(empresa))
                    {
                        ContratoEntity contrato = new ContratoEntity();
                        contrato.cpfUsu = Session["cpfUsu"].ToString();
                        contrato.cnpjEmp = empresa.cnpjEmp;
                        contrato.codCar = 3; // 3 -> código de proprietário
                        ContratoController contratoController = new ContratoController();
                        contratoController.Inserir(contrato);

                        this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Empresa salva com sucesso!'); window.location.href='Login.aspx';</script>");
                    }
                    else
                        this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Erro na inclusão do registro!');</script>");
                }
            }
        }
コード例 #4
0
 public bool Inserir(EmpresaEntity empresa)
 {
     IEmpresaDAO iEmpresaDAO = (IEmpresaDAO)DAOFactory.CreateDAO<IEmpresaDAO>();
     return iEmpresaDAO.Inserir(empresa);
 }
コード例 #5
0
 public bool Atualizar(EmpresaEntity empresa)
 {
     IEmpresaDAO iEmpresaDAO = (IEmpresaDAO)DAOFactory.CreateDAO<IEmpresaDAO>();
     return iEmpresaDAO.Atualizar(empresa);
 }
コード例 #6
0
ファイル: EmpresaDAO.cs プロジェクト: romuloprg/crmonline
        public EmpresaEntity Obter(string cnpjEmp)
        {
            EmpresaEntity empresa = new EmpresaEntity();

            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("SELECT DISTINCT cnpjEmp, nomEmp, endEmp, cidEmp, ufEmp, telEmp FROM Empresa WHERE cnpjEmp = @cnpjEmp ORDER BY nomEmp", connection);
                command.Parameters.AddWithValue("@cnpjEmp", cnpjEmp);
                IDataReader reader = command.ExecuteReader();

                reader.Read();

                empresa.cnpjEmp = ExtraDAO.ObterValor<string>(reader, 0, null);
                empresa.nomEmp = ExtraDAO.ObterValor<string>(reader, 1, null);
                empresa.endEmp = ExtraDAO.ObterValor<string>(reader, 2, null);
                empresa.cidEmp = ExtraDAO.ObterValor<string>(reader, 3, null);
                empresa.ufEmp = ExtraDAO.ObterValor<string>(reader, 4, null);
                empresa.telEmp = ExtraDAO.ObterValor<string>(reader, 5, null);
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }

            return empresa;
        }
コード例 #7
0
ファイル: EmpresaDAO.cs プロジェクト: romuloprg/crmonline
        public List<EmpresaEntity> ObterTodos(string cnpjEmp)
        {
            List<EmpresaEntity> empresas = new List<EmpresaEntity>();

            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("SELECT DISTINCT cnpjEmp, nomEmp, endEmp, cidEmp, ufEmp, telEmp FROM Empresa WHERE cnpjEmp <> @cnpjEmp AND cnpjEmp NOT IN (SELECT DISTINCT cnpjCli FROM Cliente WHERE cnpjEmp = @cnpjEmp) ORDER BY nomEmp", connection);
                command.Parameters.AddWithValue("@cnpjEmp", cnpjEmp);
                IDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    EmpresaEntity empresa = new EmpresaEntity();

                    empresa.cnpjEmp = ExtraDAO.ObterValor<string>(reader, 0, null);
                    empresa.nomEmp = ExtraDAO.ObterValor<string>(reader, 1, null);
                    empresa.endEmp = ExtraDAO.ObterValor<string>(reader, 2, null);
                    empresa.cidEmp = ExtraDAO.ObterValor<string>(reader, 3, null);
                    empresa.ufEmp = ExtraDAO.ObterValor<string>(reader, 4, null);
                    empresa.telEmp = ExtraDAO.ObterValor<string>(reader, 5, null);

                    empresas.Add(empresa);
                }
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }

            return empresas;
        }