コード例 #1
0
        public void mostrarEditarLocatario(VerLocatarios verLocatarios, CadLocatario cadLocatario)
        {
            String telRes;
            String telCel;



            DataGridViewRow selectedRow = verLocatarios.dgvLocatario.Rows[verLocatarios.linha];

            int usuario = Convert.ToInt16(selectedRow.Cells[9].Value);



            id_locatario_Do_Editar = Convert.ToInt16(selectedRow.Cells[0].Value);

            cadLocatario.txtNome.Text      = selectedRow.Cells[1].Value.ToString();
            cadLocatario.mtxtCpf.Text      = selectedRow.Cells[2].Value.ToString();
            cadLocatario.mtxtRg.Text       = selectedRow.Cells[3].Value.ToString();
            cadLocatario.mtxtDataNasc.Text = selectedRow.Cells[4].Value.ToString();

            telRes = selectedRow.Cells[5].Value.ToString();

            cadLocatario.mtxtTelRes1.Text = telRes.Substring(0, 3);
            cadLocatario.mtxtTelRel2.Text = telRes.Substring(3);

            telCel = selectedRow.Cells[6].Value.ToString();

            cadLocatario.mtxtTelCel1.Text = telCel.Substring(0, 3);
            cadLocatario.mtxtTelCel2.Text = telCel.Substring(3);

            cadLocatario.txtEmail.Text    = selectedRow.Cells[7].Value.ToString();
            cadLocatario.txtEndereco.Text = selectedRow.Cells[8].Value.ToString();

            cadLocatario.Visible = true;
        }
コード例 #2
0
        public bool cadastrar(CadLocatario cadLocatario)
        {
            String telRes = "";

            telRes += cadLocatario.mtxtTelRes1.Text;
            telRes += cadLocatario.mtxtTelRel2.Text;

            String telCel = "";

            telCel += cadLocatario.mtxtTelCel1.Text;
            telCel += cadLocatario.mtxtTelCel2.Text;

            comando = new SqlCommand();

            try
            {
                stringConexao.conn.Open();
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Falha na conexão!Contate o administrador do sistema", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

            comando.Connection = stringConexao.conn;

            comando.CommandText = "insert into Locatario(nome, cpf, rg, dataNasc, telRes, telCel, email, endereco," +
                                  "id_User) values ('" + cadLocatario.txtNome.Text + "', '" + cadLocatario.mtxtCpf.Text + "'," +
                                  "'" + cadLocatario.mtxtRg.Text + "', '" + cadLocatario.mtxtDataNasc.Text + "', '" + telRes + "'," +
                                  " '" + telCel + "', '" + cadLocatario.txtEmail.Text + "', '" + cadLocatario.txtEndereco.Text + "', " +
                                  "'" + cadLocatario.usuario + "')";

            try
            {
                comando.ExecuteNonQuery();
                MessageBox.Show("Cadastro Realizado com sucesso", "Mensagem", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                stringConexao.conn.Close();
                id_Atual_Locatario = getIdLocatarioByCpf(cadLocatario.mtxtCpf);
                return(true);
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Cadastro Falhou. Cheque se os campos estão " +
                                "preenchidos corretamente", "Mensagem", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                stringConexao.conn.Close();
                return(false);
            }
        }
コード例 #3
0
        public void editar(CadLocatario cadLocatario)
        {
            comando = new SqlCommand();

            try
            {
                stringConexao.conn.Open();
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Conexão falhou", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            comando.Connection = stringConexao.conn;

            string telRes = "";

            telRes += cadLocatario.mtxtTelRes1.Text;
            telRes += cadLocatario.mtxtTelRel2.Text;

            string telCel = "";

            telCel += cadLocatario.mtxtTelCel1.Text;
            telCel += cadLocatario.mtxtTelCel2.Text;

            MessageBox.Show(cadLocatario.usuario.ToString());

            comando.CommandText = "update Locatario set nome = '" + cadLocatario.txtNome.Text + "', " +
                                  "cpf = '" + cadLocatario.mtxtCpf.Text + "', rg = '" + cadLocatario.mtxtRg.Text + "', " +
                                  "dataNasc = '" + cadLocatario.mtxtDataNasc.Text + "', telRes = '" + telRes + "', " +
                                  "telCel = '" + telCel + "', email = '" + cadLocatario.txtEmail.Text + "'," +
                                  " endereco = '" + cadLocatario.txtEndereco.Text + "', id_User = '******' where " +
                                  "id = '" + id_locatario_Do_Editar + "'";

            try
            {
                comando.ExecuteNonQuery();
                MessageBox.Show("Atualização bem sucedida", "Mensagem", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            stringConexao.conn.Close();
        }