예제 #1
0
        public static Ent_EncabezadoHume EncabezadoHume(string ruta)
        {
            Ent_EncabezadoHume EncabezadoHume = new Ent_EncabezadoHume();

            // Declaro las variables necesarias
            Microsoft.Office.Interop.Excel._Application xlApp;
            Microsoft.Office.Interop.Excel._Workbook    xlLibro;
            Microsoft.Office.Interop.Excel._Worksheet   xlHoja1;
            Microsoft.Office.Interop.Excel.Sheets       xlHojas;
            //asigno la ruta dónde se encuentra el archivo
            string fileName = ruta;

            //inicializo la variable xlApp (referente a la aplicación)
            xlApp = new Microsoft.Office.Interop.Excel.Application();
            //Muestra la aplicación Excel si está en true
            xlApp.Visible = false;
            //Abrimos el libro a leer (documento excel)
            xlLibro = xlApp.Workbooks.Open(fileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

            try
            {
                //  Asignamos las hojas
                xlHojas = xlLibro.Sheets;
                //Asignamos la hoja con la que queremos trabajar:
                //xlHoja1 = (Microsoft.Office.Interop.Excel._Worksheet)xlHojas["Hoja 1"];
                xlHoja1 = xlLibro.ActiveSheet;     //(Microsoft.Office.Interop.Excel. ._Worksheet)xlHojas["Hoja 1"];

                //recorremos las celdas que queremos
                string fecha          = (string)xlHoja1.get_Range("A" + 5, Missing.Value).Text;
                string muestras       = (string)xlHoja1.get_Range("D" + 5, Missing.Value).Text;
                string cliente        = (string)xlHoja1.get_Range("B" + 5, Missing.Value).Text;
                string auunidad       = (string)xlHoja1.get_Range("B" + 43, Missing.Value).Text;
                string aumetodo       = (string)xlHoja1.get_Range("B" + 44, Missing.Value).Text;
                string agunidad       = (string)xlHoja1.get_Range("C" + 43, Missing.Value).Text;
                string agmetodo       = (string)xlHoja1.get_Range("C" + 44, Missing.Value).Text;
                string humeunidad     = (string)xlHoja1.get_Range("D" + 43, Missing.Value).Text;
                string humemetodo     = (string)xlHoja1.get_Range("D" + 44, Missing.Value).Text;
                string tipomuestra    = (string)xlHoja1.get_Range("B" + 9, Missing.Value).Text;
                string orden          = (string)xlHoja1.get_Range("B" + 11, Missing.Value).Text;
                string clienteorden   = (string)xlHoja1.get_Range("B" + 13, Missing.Value).Text;
                string nummuestras    = (string)xlHoja1.get_Range("B" + 14, Missing.Value).Text;
                string fechamuestreo  = (string)xlHoja1.get_Range("B" + 15, Missing.Value).Text;
                string fechareporte   = (string)xlHoja1.get_Range("B" + 16, Missing.Value).Text;
                string notas          = (string)xlHoja1.get_Range("A" + 32, Missing.Value).Text;
                string codigoprepa    = (string)xlHoja1.get_Range("D" + 10, Missing.Value).Text;
                string descriprepa    = (string)xlHoja1.get_Range("F" + 10, Missing.Value).Text;
                string codigoanalisis = (string)xlHoja1.get_Range("D" + 16, Missing.Value).Text;
                string descrianalisis = (string)xlHoja1.get_Range("F" + 16, Missing.Value).Text;


                EncabezadoHume.Fecha               = fecha;
                EncabezadoHume.Muestras            = muestras;
                EncabezadoHume.Cliente             = cliente;
                EncabezadoHume.AuUnidad            = auunidad;
                EncabezadoHume.AuMetodo            = aumetodo;
                EncabezadoHume.AgUnidad            = agunidad;
                EncabezadoHume.AgMetodo            = agmetodo;
                EncabezadoHume.HumedadUnd          = humeunidad;
                EncabezadoHume.HumedadMet          = humemetodo;
                EncabezadoHume.TipoMuestras        = tipomuestra;
                EncabezadoHume.Orden               = orden;
                EncabezadoHume.ClienteOrden        = clienteorden;
                EncabezadoHume.NumMuestras         = nummuestras;
                EncabezadoHume.FechaMuestreo       = fechamuestreo;
                EncabezadoHume.FechaReporte        = fechareporte;
                EncabezadoHume.Notas               = notas;
                EncabezadoHume.CodigoPrepa         = codigoprepa;
                EncabezadoHume.DescripcionPrepa    = descriprepa;
                EncabezadoHume.CodigoAnalisis      = codigoanalisis;
                EncabezadoHume.DescripcionAnalisis = descrianalisis;
            }
            finally
            {
                //Cerrar el Libro
                xlLibro.Close(false, Missing.Value, Missing.Value);
                //Cerrar la Aplicación
                xlApp.Quit();
            }
            return(EncabezadoHume);
        }
예제 #2
0
        private void btnProcesar_Click(object sender, EventArgs e)
        {
            this.StsLabel1.Text        = "Llenando Encabezado";
            this.StsProgressBar1.Value = 50;
            #region Llenando el Encabezado
            if (this.TxbPath.Text.Length != 0)
            {
                Ent_EncabezadoHume Encabezado = LeerExcel.EncabezadoHume(this.TxbPath.Text);
                this.TxbFecha.Text                  = Encabezado.Fecha;
                this.TxbMuestras.Text               = Encabezado.Muestras;
                this.TxbCliente.Text                = Encabezado.Cliente;
                this.TxbAuUnidad.Text               = Encabezado.AuUnidad;
                this.TxbAuMetodo.Text               = Encabezado.AuMetodo;
                this.TxbAgUnidad.Text               = Encabezado.AgUnidad;
                this.TxbAgMetodo.Text               = Encabezado.AgMetodo;
                this.TxbHumeUnidad.Text             = Encabezado.HumedadUnd;
                this.TxbHumeMetodo.Text             = Encabezado.HumedadMet;
                this.TxbTipoMuestra.Text            = Encabezado.TipoMuestras;
                this.TxbOrden.Text                  = Encabezado.Orden;
                this.TxbClienteOrden.Text           = Encabezado.ClienteOrden;
                this.TxbNumMuestras.Text            = Encabezado.NumMuestras;
                this.TxbFechaMuestreo.Text          = Encabezado.FechaMuestreo;
                this.TxbFechaReporte.Text           = Encabezado.FechaReporte;
                this.TxbNotas.Text                  = Encabezado.Notas;
                this.TxbCodigoPreparacion.Text      = Encabezado.CodigoPrepa;
                this.TxbDescripcionPreparacion.Text = Encabezado.DescripcionPrepa;
                this.TxbCodigoAnalisis.Text         = Encabezado.CodigoAnalisis;
                this.TxbDescripcionAnalisis.Text    = Encabezado.DescripcionAnalisis;
                this.LblZC.Text = Encabezado.Orden;
            }
            #endregion



            this.StsLabel1.Text        = "Llenando Tabla Principal";
            this.StsProgressBar1.Value = 75;
            #region Llenando el dataGridView Principal
            if (this.TxbPath.Text.Length != 0)
            {
                DataSet DS;
                DS = LeerExcel.DatoHumedad(this.TxbPath.Text);
                dataGridView1.DataSource = DS.Tables[0];
                dataGridView1.AutoResizeColumns();
            }
            else
            {
                MessageBox.Show("Seleccione un archivo");
            }
            #endregion

            this.StsLabel1.Text        = "Marcando Sellos no reportados";
            this.StsProgressBar1.Value = 90;

            #region Marcando Sellos no reportados
            try
            {
                foreach (DataGridViewRow Row2 in dataGridView1.Rows)
                {
                    string         SelloConsulta = Convert.ToString(Row2.Cells[1].Value);
                    SqlParameter[] Parametros    = new SqlParameter[1];
                    Parametros[0] = new SqlParameter("@Sello", SelloConsulta);

                    ConsultaEntidades Entidad = new ConsultaEntidades();
                    Ent_MinaSello     Reader  = new Ent_MinaSello();
                    Reader = Entidad.MinaSello("ConsultarSelloSGS", Parametros);

                    if (Reader.Consecutivo == 0)
                    {
                        dataGridView1.Rows[Row2.Index].DefaultCellStyle.BackColor = Color.SkyBlue;
                    }
                }
            }
            catch (Exception Ext)
            {
                MessageBox.Show(Ext.Message);
            }
            #endregion

            for (int i = 0; i < 10000; i++)
            {
            }

            this.StsLabel1.Text        = "Listo";
            this.StsProgressBar1.Value = 100;
            this.StsProgressBar1.Value = 0;
        }