public LinhaEncomenda(ClassFornecedor forn, Encomendas enc, RegistarEncomendas registarEncomendas)
 {
     InitializeComponent();
     encomendas = enc;
     registar = registarEncomendas;
     fornecedor = forn;
     label11.Text = "Fornecedor: " + fornecedor.nome;
     conn.ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SiltesSaude;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
     //var bindingSource2 = new System.Windows.Forms.BindingSource { DataSource = encomendas };
     //dataGridViewEncomenda.DataSource = bindingSource2;
  
 }
        private void comboBoxFornecedor_SelectedIndexChanged(object sender, EventArgs e)
        {
            int var = (comboBoxFornecedor.SelectedItem as ComboBoxItem).Value;

            foreach (var item in fornecedores)
            {
                if (item.Value == var)
                {
                    fornecedor = new ClassFornecedor {
                        nome         = item.Text,
                        IdFornecedor = item.Value,
                    };
                }
            }
            UpdateGridViewConsultas();
        }
Beispiel #3
0
        private ClassFornecedor getFornecedor(int enviarFornecedor)
        {
            conn.Open();


            string     queryInsertData = "SELECT * from Fornecedor WHERE IdFornecedor = " + enviarFornecedor;
            SqlCommand sqlCommand      = new SqlCommand(queryInsertData, conn);

            SqlDataReader reader = sqlCommand.ExecuteReader();

            ClassFornecedor forn = null;

            while (reader.Read())
            {
                if ((int)reader["IdFornecedor"] == enviarFornecedor)
                {
                    forn = new ClassFornecedor
                    {
                        nome     = (string)reader["nome"],
                        nif      = ((reader["nif"] == DBNull.Value) ? null : (int?)reader["nif"]),
                        contacto = ((reader["contacto"] == DBNull.Value) ? null : (int?)reader["contacto"]),

                        email        = ((reader["email"] == DBNull.Value) ? "" : (string)reader["email"]),
                        rua          = (string)reader["rua"],
                        numeroMorada = ((reader["numeroMorada"] == DBNull.Value) ? null : (int?)reader["numeroMorada"]),
                        andarPiso    = ((reader["andarPiso"] == DBNull.Value) ? "" : (string)reader["andarPiso"]),
                        localidade   = (string)reader["localidade"],
                        bairroLocal  = ((reader["bairroLocal"] == DBNull.Value) ? "" : (string)reader["bairroLocal"]),
                        codigoPostal = (reader["codPostalPrefixo"]) + "-" + (reader["codPostalSufixo"]),
                        designacao   = ((reader["designacao"] == DBNull.Value) ? "" : (string)reader["designacao"]),
                        observacoes  = ((reader["observacoes"] == DBNull.Value) ? "" : (string)reader["observacoes"]),
                        IdFornecedor = (int)(reader["IdFornecedor"])
                    };
                }
            }
            conn.Close();

            return(forn);
        }
        private void UpdateDataGridView()
        {
            try
            {
                fornecedor.Clear();
                conn.Open();
                com.Connection = conn;
                SqlCommand    cmd    = new SqlCommand("select * from Fornecedor ORDER BY nome", conn);
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    ClassFornecedor forn = new ClassFornecedor
                    {
                        nome     = (string)reader["nome"],
                        nif      = ((reader["nif"] == DBNull.Value) ? null : (int?)reader["nif"]),
                        contacto = ((reader["contacto"] == DBNull.Value) ? null : (int?)reader["contacto"]),

                        email        = ((reader["email"] == DBNull.Value) ? "" : (string)reader["email"]),
                        rua          = (string)reader["rua"],
                        numeroMorada = ((reader["numeroMorada"] == DBNull.Value) ? null : (int?)reader["numeroMorada"]),
                        andarPiso    = ((reader["andarPiso"] == DBNull.Value) ? "" : (string)reader["andarPiso"]),
                        localidade   = (string)reader["localidade"],
                        bairroLocal  = ((reader["bairroLocal"] == DBNull.Value) ? "" : (string)reader["bairroLocal"]),
                        codigoPostal = (reader["codPostalPrefixo"]) + "-" + (reader["codPostalSufixo"]),
                        designacao   = ((reader["designacao"] == DBNull.Value) ? "" : (string)reader["designacao"]),
                        observacoes  = ((reader["observacoes"] == DBNull.Value) ? "" : (string)reader["observacoes"]),
                    };

                    fornecedor.Add(forn);
                }
                var bindingSource1 = new System.Windows.Forms.BindingSource {
                    DataSource = fornecedor
                };
                dataGridViewFornecedores.DataSource             = bindingSource1;
                dataGridViewFornecedores.Columns[0].HeaderText  = "Nome Fornecedor";
                dataGridViewFornecedores.Columns[1].HeaderText  = "Nif";
                dataGridViewFornecedores.Columns[2].HeaderText  = "Contacto";
                dataGridViewFornecedores.Columns[3].HeaderText  = "Email";
                dataGridViewFornecedores.Columns[4].HeaderText  = "Morada";
                dataGridViewFornecedores.Columns[5].HeaderText  = "Número";
                dataGridViewFornecedores.Columns[6].HeaderText  = "Andar/Piso";
                dataGridViewFornecedores.Columns[7].HeaderText  = "Localidade";
                dataGridViewFornecedores.Columns[8].HeaderText  = "Bairro/Local";
                dataGridViewFornecedores.Columns[9].HeaderText  = "Codigo Postal";
                dataGridViewFornecedores.Columns[10].HeaderText = "Designação";
                dataGridViewFornecedores.Columns[11].HeaderText = "Observações";
                dataGridViewFornecedores.Columns[12].Visible    = false;
                conn.Close();
                dataGridViewFornecedores.Update();
                dataGridViewFornecedores.Refresh();
            }
            catch (Exception)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                MessageBox.Show("Por erro interno é impossível visualizar os dados!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }