Esempio n. 1
0
        public void GenerateSmp(int id_smp)
        {
            try
            {
                //BUSCAR SMP EN SU TABLA
                if (id_smp == 0)
                {
                    MessageBox.Show("SMP no cargado aún...");
                }
                else
                {
                    splash.Show();
                    //CREAR SMP A PARTIR DE LA BASE DE DATOS
                    //OBEJTO QUE PERMITE GESTIONAR DOCUMENTO EXCEL
                    Excel.Application xlApp = new Excel.Application();
                    //NO MOSTRAR ARCHIVO MIENTRAS SE UTILIZA
                    xlApp.Visible = false;
                    //DIRECTORIO DONDE SE COPIARÁ EL ARCHIVO TEMPORALMENTE
                    //PARA EDITARLO
                    string sru = System.IO.Path.GetTempPath();
                    //NOMBRE DEL ARCHIVO TEMPORAL
                    path = @"" + sru + "\\SMP_TEMP.xlsx";
                    //COPIAR EL ARCHIVO DE LOS RECURSOS DE LA APLICACIÓN
                    // A LA RUTA ESTABLECIDA
                    File.WriteAllBytes(path, Properties.Resources.SMP_MODIFICADO);

                    //VERIFICAR SI EL ARCHIVO ESTÁ BLOQUEADO O ESTA SIENDO UTILIZADO POR OTRO PROCESO
                    if (IsFileLocked(new FileInfo(path)))
                    {
                        MessageBox.Show("El archivo se está ejecutando, debe cerrarlo para continuar",
                                        "Abrir SMP", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        //CREAR EL OBJETO DEL LIBRO A PARTIR DE LA RUTA
                        Excel.Workbook wb = xlApp.Workbooks.Open(path);

                        //FIJAR EN OBJETOS LAS PESTAÑAS U HOJA DEL LIBRO PARA TRABAJAR
                        Excel.Worksheet ws2 = (Excel.Worksheet)wb.Worksheets[1];

                        //INFORMACIÓN DE BD
                        CustomSMP cs = daoSMP.GetCustomSMP(id_smp);
                        //////////////////////////////////////////////////
                        //**************** INFORMACIÓN BÁSICA ************
                        //////////////////////////////////////////////////
                        //LINEA
                        FillCell(ws2, 3, 5, cs.desc_linea);
                        //EQUIPO
                        FillCell(ws2, 4, 5, cs.desc_equipo);
                        //CLASDIFICACIÓN SMP
                        FillCell(ws2, 5, 5, cs.desc_clasificacion);
                        //NOMBRE SMP
                        FillCell(ws2, 2, 14, cs.nombre);
                        //NÚMERO SMP
                        FillCell(ws2, 3, 18, cs.numero.ToString());
                        //ELABORADO POR
                        FillCell(ws2, 3, 25, cs.desc_elaborador);
                        //APROBADO POR
                        FillCell(ws2, 3, 35, cs.desc_aprobador);
                        //FECHA
                        FillCell(ws2, 4, 40, cs.fecha_smp.ToString());
                        //NÚMERO DE TECNICOS REQUERIDOS
                        FillCell(ws2, 5, 14, cs.tecnicos_eq.ToString());
                        //TIPO MANTENIMIENTO
                        FillCell(ws2, 5, 24, cs.desc_tipo_mtto);
                        //DURACIÓN DE LA ACTIVIDAD
                        FillCell(ws2, 5, 30, cs.duracion_actividad.ToString());
                        //TIEMPO EQUIPO PARADO
                        FillCell(ws2, 5, 35, cs.equipo_parado.ToString());
                        ////FREUENCIA
                        FillCell(ws2, 5, 41, cs.frecuencia + " " + cs.desc_tipo_frecuencia.ToString());
                        ////LOTO
                        FillCell(ws2, 16, 3, cs.loto ? "SI" : "NO");

                        //IMAGEN 1
                        if (!cs.imagen_1.Equals(""))
                        {
                            Microsoft.Office.Interop.Excel.Range rIm = (Microsoft.Office.Interop.Excel.Range)ws2.Cells[7, 9];
                            SomeHelpers.AddImageExcel(ws2, Global.DIRECTORIO_IMAGENES + @"\" + cs.imagen_1, (float)rIm.Left + 1, (float)rIm.Top + 1, 152, 150);
                        }
                        //IMAGEN 2
                        if (!cs.imagen_2.Equals(""))
                        {
                            Microsoft.Office.Interop.Excel.Range rIm = (Microsoft.Office.Interop.Excel.Range)ws2.Cells[7, 21];
                            SomeHelpers.AddImageExcel(ws2, Global.DIRECTORIO_IMAGENES + @"\" + cs.imagen_2, (float)rIm.Left + 1, (float)rIm.Top + 1, 152, 150);
                        }

                        //PERMISOS DE TRABAJO
                        string[] permisos = cs.permisos.Split(',');
                        int      k        = 0;
                        for (int i = 5; i <= 30; i += 2)
                        {
                            if (k < permisos.Length)
                            {
                                //CÓDIGO PODEROSO
                                SomeHelpers.AddImageExcel(ws2, Util.Global.DIRECTORIO_IMAGENES + @"\"
                                                          + GetImageFromRisk(permisos[k]), (float)GetRangeImageRisk(ws2, i).Left + 1,
                                                          (float)GetRangeImageRisk(ws2, i).Top + 1, 55, 58);

                                FillCell(ws2, 19, i, permisos[k]);
                                k++;
                            }
                        }

                        //////////////////////////////////////////////////
                        //**************** EPPS *************************
                        //////////////////////////////////////////////////
                        //EPPS
                        //EPPS IMAGENES RANGO

                        int j = 0;

                        for (int i = 6; i <= 70; i += 2)
                        {
                            if (j < cs.list_epps.Count)
                            {
                                //CÓDIGO PODEROSO
                                SomeHelpers.AddImageExcel(ws2, Util.Global.DIRECTORIO_IMAGENES + @"\"
                                                          + cs.list_epps[j].foto, (float)GetRangeImageEpp(ws2, i).Left + 1,
                                                          (float)GetRangeImageEpp(ws2, i).Top + 1, 56, 59);

                                FillCell(ws2, 12, i, cs.list_epps[j].nombre);

                                j++;
                            }
                        }


                        //////////////////////////////////////////////////
                        //**************** HERRAMIENTAS *****************
                        //////////////////////////////////////////////////
                        int         herramientas_cant = cs.list_herramientas.Count;
                        int         inicio_herr       = 22;
                        Excel.Range linePpal          = (Excel.Range)ws2.Rows[inicio_herr - 1];
                        if (herramientas_cant > 0)
                        {
                            linePpal.RowHeight = 138.6;
                        }

                        //COMBINAR Y CENTRAR CELDAS
                        for (int i = 1; i < herramientas_cant; i++)
                        {
                            Excel.Range line = (Excel.Range)ws2.Rows[inicio_herr];
                            linePpal.RowHeight = 138.6;
                            line.Insert();

                            //COMBINAR CELDA DE FOTO
                            ws2.Range[ws2.Cells[inicio_herr, 26], ws2.Cells[inicio_herr, 42]].Merge();
                            //COMBINAR CELDA DE NOMBRE HERRAMIENTA
                            ws2.Range[ws2.Cells[inicio_herr, 13], ws2.Cells[inicio_herr, 25]].Merge();
                            //COMBINAR CELDA DE NOMBRE CATEGORÍA
                            ws2.Range[ws2.Cells[inicio_herr, 11], ws2.Cells[inicio_herr, 12]].Merge();
                        }
                        //SI HAY MAS DE 1 ELEMENTO, SE COMBINAN LAS COLUMNAS
                        if (herramientas_cant > 1)
                        {
                            ws2.Range[ws2.Cells[inicio_herr - 1, 3], ws2.Cells[inicio_herr + herramientas_cant - 2, 9]].Merge();
                        }

                        //AÑADIR ELEMENTOS A CELDAS
                        int l = inicio_herr - 1;

                        for (int i = 0; i < herramientas_cant; i++)
                        {
                            //OBTENER EL RANGO DEPENDIENDO DE CADA ELEMENTO
                            Microsoft.Office.Interop.Excel.Range picPosition = GetRangeHerramienta(ws2, l, 32);
                            //LA IMAGEN EN EL DATAGRID FUE DESCARGADA, SE OBTIENE LA RUTA PARA PEGAR EN EL EXCEL
                            string image_p = Util.Global.DIRECTORIO_IMAGENES + @"\" + System.IO.Path.GetFileName(cs.list_herramientas[i].image_path);
                            //SE INSERTA LA IMAGEN EN EL EXCEL, CONFIGURANDO ATRIBUTOS
                            SomeHelpers.AddImageExcelFromWeb(ws2, image_p, (float)picPosition.Left, (float)picPosition.Top + 1, 170, 137, cs.list_herramientas[i].image_path);
                            //NOMBRE DE LA HERRAMIENTA
                            FillCell(ws2, l, 13, cs.list_herramientas[i].herramienta);
                            l++;
                        }

                        //////////////////////////////////////////////////
                        //**************** REPUESTOS *****************
                        //////////////////////////////////////////////////
                        if (herramientas_cant == 0)
                        {
                            herramientas_cant++;
                        }

                        int         repuestos_cant = cs.list_repuestos.Count;
                        int         inicio_rep     = inicio_herr + herramientas_cant; //+ 1; //23;
                        Excel.Range linePpalRep    = (Excel.Range)ws2.Rows[inicio_rep - 1];
                        if (repuestos_cant > 0)
                        {
                            linePpalRep.RowHeight = 138.6;
                        }

                        //COMBINAR Y CENTRAR CELDAS
                        for (int i = 1; i < repuestos_cant; i++)
                        {
                            Excel.Range line = (Excel.Range)ws2.Rows[inicio_rep];
                            linePpalRep.RowHeight = 138.6;
                            line.Insert();

                            //COMBINAR CELDA DE FOTO
                            ws2.Range[ws2.Cells[inicio_rep, 26], ws2.Cells[inicio_rep, 42]].Merge();
                            //COMBINAR CELDA DE NOMBRE HERRAMIENTA
                            ws2.Range[ws2.Cells[inicio_rep, 13], ws2.Cells[inicio_rep, 25]].Merge();
                            //COMBINAR CELDA DE NOMBRE CATEGORÍA
                            ws2.Range[ws2.Cells[inicio_rep, 11], ws2.Cells[inicio_rep, 12]].Merge();
                        }
                        //SI HAY MAS DE 1 ELEMENTO, SE COMBINAN LAS COLUMNAS
                        if (repuestos_cant > 1)
                        {
                            ws2.Range[ws2.Cells[inicio_rep - 1, 3], ws2.Cells[inicio_rep + repuestos_cant - 2, 9]].Merge();
                        }

                        //AÑADIR ELEMENTOS A CELDAS
                        int b = inicio_rep - 1;

                        for (int i = 0; i < repuestos_cant; i++)
                        {
                            //OBTENER EL RANGO DEPENDIENDO DE CADA ELEMENTO
                            Microsoft.Office.Interop.Excel.Range picPosition = GetRangeHerramienta(ws2, b, 32);
                            //LA IMAGEN EN EL DATAGRID FUE DESCARGADA, SE OBTIENE LA RUTA PARA PEGAR EN EL EXCEL
                            string image_p = Util.Global.DIRECTORIO_IMAGENES + @"\" + System.IO.Path.GetFileName(cs.list_repuestos[i].image_path);
                            //SE INSERTA LA IMAGEN EN EL EXCEL, CONFIGURANDO ATRIBUTOS
                            SomeHelpers.AddImageExcelFromWeb(ws2, image_p, (float)picPosition.Left, (float)picPosition.Top + 1, 170, 137, cs.list_repuestos[i].image_path);
                            //NOMBRE DE LA HERRAMIENTA
                            FillCell(ws2, b, 13, "(" + cs.list_repuestos[i].cantidad + ") " + cs.list_repuestos[i].descripcion);
                            b++;
                        }

                        //////////////////////////////////////////////////
                        //**************** PASO A PASO *****************
                        //////////////////////////////////////////////////
                        if (repuestos_cant == 0)
                        {
                            repuestos_cant += 1;
                        }

                        int         paso_cant   = cs.list_pasos.Count;
                        int         inicio_paso = inicio_rep + repuestos_cant + 1; //23;
                        Excel.Range linePpalPas = (Excel.Range)ws2.Rows[inicio_paso - 1];
                        if (paso_cant > 0)
                        {
                            linePpalPas.RowHeight = 138.6;
                        }

                        //COMBINAR Y CENTRAR CELDAS
                        for (int i = 1; i < paso_cant; i++)
                        {
                            Excel.Range line = (Excel.Range)ws2.Rows[inicio_paso];
                            linePpalPas.RowHeight = 138.6;
                            line.Insert();

                            //COMBINAR CELDA DE FOTO
                            ws2.Range[ws2.Cells[inicio_paso, 26], ws2.Cells[inicio_paso, 42]].Merge();
                            //COMBINAR CELDA DESCRIPCIÓN DEL PASO
                            ws2.Range[ws2.Cells[inicio_paso, 13], ws2.Cells[inicio_paso, 25]].Merge();
                            //COMBINAR CELDA DE FOTO CATEGORÍA
                            ws2.Range[ws2.Cells[inicio_paso, 11], ws2.Cells[inicio_paso, 12]].Merge();
                            //COMBINAR CELDA DE DURACIÓN
                            ws2.Range[ws2.Cells[inicio_paso, 10], ws2.Cells[inicio_paso, 10]].Merge();
                            //COMBINAR CELDA DE NOMBRE
                            ws2.Range[ws2.Cells[inicio_paso, 3], ws2.Cells[inicio_paso, 9]].Merge();
                        }


                        System.Windows.Forms.Application.DoEvents();


                        //AÑADIR ELEMENTOS A CELDAS
                        int p = inicio_paso - 1;

                        for (int i = 0; i < paso_cant; i++)
                        {
                            //OBTENER EL RANGO DEPENDIENDO DE CADA ELEMENTO
                            Microsoft.Office.Interop.Excel.Range picPosition = GetRangeHerramienta(ws2, p, 32);
                            //LA IMAGEN EN EL DATAGRID FUE DESCARGADA, SE OBTIENE LA RUTA PARA PEGAR EN EL EXCEL
                            string image_p = Util.Global.DIRECTORIO_IMAGENES + @"\" + System.IO.Path.GetFileName(cs.list_pasos[i].imagen_paso_path);
                            //SE INSERTA LA IMAGEN EN EL EXCEL, CONFIGURANDO ATRIBUTOS
                            SomeHelpers.AddImageExcel(ws2, image_p, (float)picPosition.Left, (float)picPosition.Top + 1, 170, 137);

                            //DESCRIPCIÓN
                            FillCell(ws2, p, 13, cs.list_pasos[i].desc);
                            //NOMBRE
                            FillCell(ws2, p, 3, cs.list_pasos[i].paso);
                            //DURACIÓN
                            FillCell(ws2, p, 10, cs.list_pasos[i].duracion + "");
                            //NUMERO PASO
                            int num_pas = i + 1;
                            FillCell(ws2, p, 2, num_pas.ToString() + "");

                            //IMAGEN CATEGORIA
                            //OBTENER EL RANGO DEPENDIENDO DE CADA ELEMENTO
                            Microsoft.Office.Interop.Excel.Range picPositionCat = GetRangeHerramienta(ws2, p, 11);
                            //LA IMAGEN EN EL DATAGRID FUE DESCARGADA, SE OBTIENE LA RUTA PARA PEGAR EN EL EXCEL
                            string image_pCat = Util.Global.DIRECTORIO_IMAGENES + @"\" + System.IO.Path.GetFileName(cs.list_pasos[i].categoria + ".PNG");
                            //SE INSERTA LA IMAGEN EN EL EXCEL, CONFIGURANDO ATRIBUTOS
                            SomeHelpers.AddImageExcel(ws2, image_pCat, (float)picPositionCat.Left + 15, (float)picPositionCat.Top + 57, 20, 20);

                            p++;
                        }

                        int limit = inicio_paso + paso_cant;
                        //CONFIGURANDO AREA DE IMPRESIÓN
                        ws2.PageSetup.PrintArea = "$A$1:$AP$" + limit;

                        wb.Save();
                        wb.Close();

                        System.Diagnostics.Process.Start(path);
                        splash.Hide();
                    }
                }
            }
            catch (Exception ex)
            {
                splash.Hide();
                MessageBox.Show("Item inválido, " + ex.Message.ToLower());
            }
        }
Esempio n. 2
0
        public CustomSMP GetCustomSMP(int id_smp)
        {
            CustomSMP cs = new CustomSMP();

            try
            {
                using (var context = new MttoAppEntities())
                {
                    // Query for all
                    var als = from s in context.smp
                              join td in context.tipos_data
                              on s.id_linea equals td.Id
                              join e in context.equipos
                              on s.id_equipo equals e.Id
                              join tdc in context.tipos_data
                              on s.clasificacion equals tdc.Id
                              join tdtm in context.tipos_data
                              on s.tipo_mtto equals tdtm.Id
                              join tdtf in context.tipos_data
                              on s.tipo_frecuencia equals tdtf.Id
                              join t in context.tecnicos
                              on s.id_elaborador equals t.Id
                              join ta in context.tecnicos
                              on s.id_aprobador equals ta.Id
                              where s.Id == id_smp
                              select new { s, td, e, tdc, tdtm, tdtf, t, ta };

                    foreach (var item in als.ToList())
                    {
                        cs.id                   = item.s.Id;
                        cs.consecutivo          = (int)item.s.consecutivo;
                        cs.nombre               = item.s.nombre;
                        cs.numero               = (int)item.s.numero;
                        cs.id_linea             = (int)item.s.id_linea;
                        cs.desc_linea           = item.td.descripcion;
                        cs.id_equipo            = (int)item.s.id_equipo;
                        cs.desc_equipo          = item.e.Nombre;
                        cs.fecha_smp            = (DateTime)item.s.feha_smp;
                        cs.id_clasificacion     = (int)item.s.clasificacion;
                        cs.desc_clasificacion   = item.tdc.descripcion;
                        cs.tipo_mtto            = (int)item.s.tipo_mtto;
                        cs.desc_tipo_mtto       = item.tdtm.descripcion;
                        cs.tecnicos_eq          = (int)item.s.tecnicos_req;
                        cs.duracion_actividad   = (int)item.s.duracion_actividad;
                        cs.equipo_parado        = (int)item.s.equipo_parado;
                        cs.frecuencia           = (int)item.s.frecuencia;
                        cs.tipo_frecuencia      = (int)item.s.tipo_frecuencia;
                        cs.desc_tipo_frecuencia = item.tdtf.descripcion;
                        cs.id_elaborador        = (int)item.s.id_elaborador;
                        cs.desc_elaborador      = item.t.Nombre;
                        cs.id_aprobador         = (int)item.s.id_aprobador;
                        cs.desc_aprobador       = item.ta.Nombre;
                        cs.loto                 = (bool)item.s.loto;
                        cs.permisos             = item.s.permisos;
                        cs.imagen_1             = item.s.imagen_1;
                        cs.imagen_2             = item.s.imagen_2;
                    }

                    //CARGAR EPPS 9 - HERRAMIENTAS 10 - REPUESTOS 11
                    //var lt = from su in context.smp_util
                    //         where su.id_smp == id_smp
                    //         select su;

                    //cs.list_util = lt.ToList();

                    //CARGAR PASOS
                    cs.list_pasos = new List <PasoaPaso>();

                    var lp = from sp in context.smp_pasos
                             join td in context.tipos_data
                             on sp.categoria_id equals td.Id
                             where sp.id_smp == id_smp
                             select new { sp, td };

                    foreach (var item in lp.ToList())
                    {
                        cs.list_pasos.Add(new PasoaPaso()
                        {
                            categoria        = item.td.descripcion,
                            desc             = item.sp.descripcion,
                            duracion         = item.sp.duracion.ToString(),
                            Id               = item.sp.Id,
                            id_smp           = (int)item.sp.id_smp,
                            imagen_paso_path = item.sp.image_path,
                            paso             = item.sp.paso
                        });
                    }


                    //CARGAR EPPS DEPENDIENDO ID
                    cs.list_epps = new List <epps>();

                    var epps = from e in context.epps
                               join su in context.smp_util
                               on e.Id equals su.id_util
                               where su.id_tipo == 9 &&
                               su.id_smp == id_smp
                               select new { e };

                    foreach (var item in epps.ToList())
                    {
                        cs.list_epps.Add(new Database.epps()
                        {
                            codigo       = item.e.codigo,
                            foto         = item.e.foto,
                            Id           = item.e.Id,
                            nombre       = item.e.nombre,
                            seleccionado = item.e.seleccionado
                        });
                    }

                    //CARGAR HERRAMIENTAS DEPENDIENDO ID
                    cs.list_herramientas = new List <herramientas>();

                    var herr = from h in context.herramientas
                               join su in context.smp_util
                               on h.Id equals su.id_util
                               where su.id_tipo == 10 &&
                               su.id_smp == id_smp
                               select new { h };

                    foreach (var item in herr.ToList())
                    {
                        cs.list_herramientas.Add(new Database.herramientas()
                        {
                            Id          = item.h.Id,
                            herramienta = item.h.herramienta,
                            image_path  = item.h.image_path,
                            tipo        = item.h.tipo
                        });
                    }

                    //CARGAR REPUESTOS DEPENDIENDO ID
                    cs.list_repuestos = new List <repuestos_utilizados>();

                    var rep = from r in context.repuestos_utilizados
                              join su in context.smp_util
                              on r.Id equals su.id_util
                              where su.id_tipo == 11 &&
                              su.id_smp == id_smp
                              select new { r };

                    foreach (var item in rep.ToList())
                    {
                        cs.list_repuestos.Add(new Database.repuestos_utilizados()
                        {
                            Id          = item.r.Id,
                            cantidad    = item.r.cantidad,
                            image_path  = item.r.image_path,
                            descripcion = item.r.descripcion
                        });
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Excepción al consultar Custom SMP: " + e,
                                "Atención", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(cs);
        }
Esempio n. 3
0
 private void BgLoad_DoWork(object sender, DoWorkEventArgs e)
 {
     lc   = daoCal.GetCalendario(cmp.id, int.Parse(paramss[1]), int.Parse(paramss[0]));
     csmp = daoSmp.GetCustomSMP(cmp.id_smp);
 }