private void tblInstalacion_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (tblInstalacion.Columns[e.ColumnIndex].Name == "MARCA") { DataGridViewComboBoxCell Modelos = tblInstalacion.Rows[e.RowIndex].Cells[3] as DataGridViewComboBoxCell; //Cargar modelos List <CEModelo> modelos = equipos.CargarModelos(new CEMarca { id = Convert.ToInt32(tblInstalacion.Rows[e.RowIndex].Cells[2].Value) }); modelos.Insert(0, new CEModelo { id = 0, descripcion = "SELECCIONE UN MODELO" }); Modelos.ValueMember = "id"; Modelos.DisplayMember = "descripcion"; Modelos.DataSource = modelos; } } catch (Exception ex) { MessageBox.Show("Se presento el siguiente error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cmbMarca_SelectedIndexChanged(object sender, EventArgs e) { try { // Cargar combo modelos List <CEModelo> modelos = equipos.CargarModelos(new CEMarca { id = Convert.ToInt32(cmbMarca.SelectedValue) }); modelos.Insert(0, new CEModelo { id = 0, descripcion = "SELECCIONE UN MODELO" }); cmbModelo.ValueMember = "id"; cmbModelo.DisplayMember = "descripcion"; cmbModelo.DataSource = modelos; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void MostrarDatos() { try { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Libros de Excel |*.xls;*.xlsx"; dialog.FilterIndex = 1; dialog.RestoreDirectory = true; if (dialog.ShowDialog() == DialogResult.OK) { string conexion = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + dialog.FileName + ";Extended Properties=\"Excel 8.0; HDR=Yes\""; OleDbConnection origenDB = default; origenDB = new OleDbConnection(conexion); origenDB.Open(); List <CEProveedor> proveedores = personas.CargarComboProveedores(); foreach (CEProveedor proveedor in proveedores) { OleDbCommand Query = default; Query = new OleDbCommand("INSERT INTO [PROVEEDORES$] (PROV_NIT, PROV_NOMBRE) VALUES(@NIT, @NOMBRE)", origenDB); Query.Parameters.AddWithValue("NIT", proveedor.documento); Query.Parameters.AddWithValue("NOMBRE", proveedor.nombreCorto); Query.ExecuteNonQuery(); } List <CEModelo> modelos = equipos.CargarModelos(new CEMarca { id = 0 }); foreach (CEModelo modelo in modelos) { OleDbCommand Query = default; Query = new OleDbCommand("INSERT INTO [MODELOS$] (MODELO_ID, MODELO_DESC) VALUES(@ID, @DESC)", origenDB); Query.Parameters.AddWithValue("ID", modelo.id); Query.Parameters.AddWithValue("DESC", modelo.descripcion); Query.ExecuteNonQuery(); } List <CEProyecto> proyectos = personas.CargarProyectos(); foreach (CEProyecto proyecto in proyectos) { OleDbCommand Query = default; Query = new OleDbCommand("INSERT INTO [PROYECTOS$] (PROYECTO_ID, PROYECTO_DESC) VALUES(@ID, @DESC)", origenDB); Query.Parameters.AddWithValue("ID", proyecto.id); Query.Parameters.AddWithValue("DESC", proyecto.descripcion); Query.ExecuteNonQuery(); } List <CESede> sedes = personas.CargarSedes(); foreach (CESede sede in sedes) { OleDbCommand Query = default; Query = new OleDbCommand("INSERT INTO [SEDES$] (SEDE_ID, SEDE_DESC) VALUES(@ID, @DESC)", origenDB); Query.Parameters.AddWithValue("ID", sede.id); Query.Parameters.AddWithValue("DESC", sede.descripcion); Query.ExecuteNonQuery(); } List <CEUbicacion> ubicaciones = personas.CargarUbicaciones(); foreach (CEUbicacion ubicacion in ubicaciones) { OleDbCommand Query = default; Query = new OleDbCommand("INSERT INTO [UBICACIONES$] (UBICACION_ID, UBICACION_DESC) VALUES(@ID, @DESC)", origenDB); Query.Parameters.AddWithValue("ID", ubicacion.id); Query.Parameters.AddWithValue("DESC", ubicacion.descripcion); Query.ExecuteNonQuery(); } MessageBox.Show("Los datos auxiliares ya se encuentran en su hoja de excel para que aliste su plantilla de importacion", " ", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }