protected void btnGravar_Click(object sender, EventArgs e)
        {
            ContratoEntity contrato = new ContratoEntity();
            ContratoController contratoController = new ContratoController();

            if (txtNome.Text == "" || txtCpf.Text == "" || txtCargo.SelectedValue == "0")
                this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Preencha todos os campos!');</script>");
            else
            {
                string cpfUsu = null;

                try
                {
                    cpfUsu = Request.QueryString["cpfUsu"].ToString();
                    contrato = contratoController.ObterAtivo(cpfUsu);
                    contrato.codCar = Convert.ToInt32(txtCargo.SelectedValue);
                }
                catch
                { }

                if (cpfUsu != null)
                {
                    if (contratoController.Atualizar(contrato))
                        this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Contrato alterado com sucesso!'); window.location.href='Funcionario.aspx';</script>");
                    else
                        this.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script>alert('Erro na alteração do registro!');</script>");
                }
            }
        }
Exemple #2
0
        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>");
                }
            }
        }
Exemple #3
0
        public bool Inserir(ContratoEntity contrato)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("INSERT INTO Contrato VALUES (@cpfUsu, @cnpjEmp, @codCar, GETDATE(), NULL)", connection);
                command.Parameters.AddWithValue("@cpfUsu", contrato.cpfUsu);
                command.Parameters.AddWithValue("@cnpjEmp", contrato.cnpjEmp);
                command.Parameters.AddWithValue("@codCar", contrato.codCar);
                command.ExecuteNonQuery();
            }
            catch
            {
                return false;
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }

            return true;
        }
Exemple #4
0
        public bool Atualizar(ContratoEntity contrato)
        {
            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("UPDATE Contrato SET codCar = @codCar WHERE cpfUsu = @cpfUsu AND cnpjEmp = @cnpjEmp", connection);
                command.Parameters.AddWithValue("@cpfUsu", contrato.cpfUsu);
                command.Parameters.AddWithValue("@cnpjEmp", contrato.cnpjEmp);
                command.Parameters.AddWithValue("@codCar", contrato.codCar);
                command.ExecuteNonQuery();
            }
            catch
            {
                return false;
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }

            return true;
        }
Exemple #5
0
        public List<ContratoEntity> ObterTodos(string cpfUsu)
        {
            List<ContratoEntity> contratos = new List<ContratoEntity>();

            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand("SELECT DISTINCT codCtr, Contrato.cpfUsu, Empresa.cnpjEmp, Contrato.codCar, iniCtr, fimCtr, nomUsu, nomEmp, nomCar FROM Contrato JOIN Cargo ON Contrato.codCar = Cargo.codCar JOIN Usuario ON Contrato.cpfUsu = Usuario.cpfUsu LEFT JOIN Empresa ON Contrato.cnpjEmp = Empresa.cnpjEmp WHERE Contrato.cpfUsu = @cpfUsu ORDER BY iniCtr", connection);
                command.Parameters.AddWithValue("@cpfUsu", cpfUsu);
                IDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    ContratoEntity contrato = new ContratoEntity();

                    contrato.codCtr = ExtraDAO.ObterValor<int>(reader, 0, 0);
                    contrato.cpfUsu = ExtraDAO.ObterValor<string>(reader, 1, null);
                    contrato.cnpjEmp = ExtraDAO.ObterValor<string>(reader, 2, null);
                    contrato.codCar = ExtraDAO.ObterValor<int>(reader, 3, 0);
                    contrato.iniCtr = ExtraDAO.ObterValor<DateTime>(reader, 4, new DateTime()).ToShortDateString();
                    contrato.fimCtr = ExtraDAO.ObterValor<DateTime>(reader, 5, new DateTime()).ToShortDateString();
                    contrato.nomUsu = ExtraDAO.ObterValor<string>(reader, 6, null);
                    contrato.nomEmp = ExtraDAO.ObterValor<string>(reader, 7, null);
                    contrato.nomCar = ExtraDAO.ObterValor<string>(reader, 8, null);

                    contratos.Add(contrato);
                }
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }

            return contratos;
        }