Ejemplo n.º 1
0
        private void submit_bt_Click(object sender, EventArgs e)
        {
            InquilinoModel inq = new InquilinoModel();

            try
            {
                inq.fname        = fname_textbox.Text.ToString();
                inq.lname        = lname_textbox.Text.ToString();
                inq.telefone     = Decimal.Parse(tel_textbox.Text.ToString());
                inq.id           = Decimal.Parse(id_textBox.Text.ToString());
                inq.nif          = Decimal.Parse(nif_textBox.Text.ToString());
                inq.certificado  = cert_textBox.Text.ToString();
                inq.reg_criminal = reg_textBox.Text.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            saveInq(inq);

            Habitantes h = (Habitantes)Owner;

            h.GetPessoasByCasa(moradaGlobal);
            this.Close();
        }
Ejemplo n.º 2
0
        public void printInquilinos()
        {
            data.connectToDB();

            List <InquilinoModel> inqs = new List <InquilinoModel>();

            String        sql = "SELECT * FROM (proj_pessoa join proj_inquilino on proj_pessoa.nif=proj_inquilino.nif)";
            SqlCommand    com = new SqlCommand(sql, data.connection());
            SqlDataReader reader;

            reader = com.ExecuteReader();
            while (reader.Read())
            {
                InquilinoModel tmp = new InquilinoModel();

                tmp.fname        = reader.GetString(0);
                tmp.lname        = reader.GetString(1);
                tmp.telefone     = reader.GetDecimal(2);
                tmp.id           = reader.GetDecimal(3);
                tmp.nif          = reader.GetDecimal(4);
                tmp.certificado  = reader.GetString(6);
                tmp.reg_criminal = reader.GetString(7);


                inqs.Add(tmp);
            }
            data.close();

            fillDataGrid(inqs);
        }
Ejemplo n.º 3
0
        private void saveInq(InquilinoModel inq)
        {
            data.connectToDB();


            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "exec inserirInq @fname, @lname, @telefone, @id, @nif, @certificado, @reg_criminal, @morada";// INSERT proj_pessoa (fname, lname, telefone, id, nif) values(@fname, @lname, @telefone, @id, @nif)";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@lname", inq.lname);
            cmd.Parameters.AddWithValue("@fname", inq.fname);
            cmd.Parameters.AddWithValue("@telefone", inq.telefone);
            cmd.Parameters.AddWithValue("@id", inq.id);
            cmd.Parameters.AddWithValue("@nif", inq.nif);
            // cmd.Connection = data.connection();



            //SqlCommand cmd2 = new SqlCommand();
            //cmd2.CommandText = "INSERT proj_inquilino (nif, certificado, reg_criminal) values(@nif, @certificado, @reg_criminal)";
            //cmd2.Parameters.Clear();
            //cmd2.Parameters.AddWithValue("@nif", inq.nif);
            cmd.Parameters.AddWithValue("@certificado", inq.certificado);
            cmd.Parameters.AddWithValue("@reg_criminal", inq.reg_criminal);
            cmd.Parameters.AddWithValue("@morada", morada_box.Text);
            cmd.Connection = data.connection();

            //if (mor)
            //{
            //    SqlCommand cmd2 = new SqlCommand();
            //    cmd2.CommandText = "Insert into proj_casa_inquilino (nif, morada) values( @nif, @morada)";
            //    cmd2.Parameters.AddWithValue("@nif", inq.nif);
            //    cmd2.Parameters.AddWithValue("@morada", moradaGlobal);
            //}


            try
            {
                cmd.ExecuteNonQuery();
                MessageBox.Show("Entry Successful!");
            }
            catch (Exception ex)
            {
                //throw new Exception("Failed to insert in database. \n ERROR MESSAGE: \n" + ex.Message);
                MessageBox.Show("Não foi possível guardar os dados! Verifique os campos inseridos!");
            }
            finally
            {
                data.close();
                // DadosPessoais.printInquilinos();
            }
        }