Beispiel #1
0
        public static void ObtenerIndice(DateTime fe)
        {
            try {
                //Abrimos la conexion a la base de datos utilizando la cadena de conexion.
                MySqlConnection conn = new MySqlConnection(cred);
                MySqlCommand    cmd;
                //String dat = DateTime.Now.AddDays(0).ToString("yyyy/MM/dd");

                //Se debe agregar un argumento de tipo DateTime llamado 'fe'
                //fe = fe.AddHours(Double.Parse(DateTime.Now.ToString("HH")));
                //fe = fe.AddMinutes(Double.Parse(DateTime.Now.ToString("mm")));
                //fe = fe.AddSeconds(Double.Parse(DateTime.Now.ToString("ss")));
                String          dat = fe.ToString("yyyy/MM/dd");
                MySqlDataReader reader;

                conn.Open();

                cmd = new MySqlCommand("SELECT COUNT(*) From comentario_oceane_tc WHERE DATE_FORMAT(`Lastmodified`, '%Y/%m/%d') = '" + dat + "' AND LOWER(`operationcomment`) like '%[%]%'", conn);
                cmd.CommandTimeout = 2147483;
                reader             = cmd.ExecuteReader();

                while (reader.Read())
                {
                    comments = new String[Int32.Parse(reader.GetString(0)), 2];
                    indice   = Int32.Parse(reader.GetString(0));
                }

                conn.Close();
            } catch (Exception oI) {
                LOGS.Log("GestionDeTiemposTC (ObtenerIndice) --> " + oI + "\n");
            }
        }
Beispiel #2
0
        public static void UpdateTA()
        {
            MySqlCommand    cmdInternal;
            MySqlConnection conn = new MySqlConnection(cred);

            try {
                //MessageBox.Show("Ticket " + comments[i, 0] + " Correcto con el valor de tiempo (mins) --> " + val);
                //commets[i,0] --> Equivale al Ticket de la BD.
                for (int i = 0; i < indice; i++)
                {
                    cmdInternal = new MySqlCommand("UPDATE comentarios_oceane_ta SET Tiempo = " + Int64.Parse(updateData[i, 0]) + " WHERE `TicketID` = '" + updateData[i, 1] + "' AND ID = " + Int64.Parse(updateData[i, 2]), conn);
                    conn.Open();
                    cmdInternal.CommandTimeout = 2147483;
                    cmdInternal.ExecuteNonQuery();
                    conn.Close();
                }
                LOGS.Log("Actualiacion de Campos --> OK");
            } catch (Exception e) {
                LOGS.Log("GestionDeTiemposTA - UpdateTA --> " + e);
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Beispiel #3
0
        //Metodo que recibe el array de datos de los excels y el numero de registros o filas de datos del adjunto.
        public static void InsercionData(String[,] cellData, int registros, DateTime fe)
        {
            MySqlConnection conn = new MySqlConnection(cred);
            MySqlCommand    cmd;

            //Se abre la conexion a la base de datos.


            try {
                String dat = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");

                //fe = fe.AddHours(Double.Parse(DateTime.Now.ToString("HH")));
                //fe = fe.AddMinutes(Double.Parse(DateTime.Now.ToString("mm")));
                //fe = fe.AddSeconds(Double.Parse(DateTime.Now.ToString("ss")));
                //String dat = fe.ToString("yyyy/MM/dd HH:mm:ss");

                cmd = conn.CreateCommand();
                //registros - 5 para evitar que los datos de las primeras 5 filas sean leidos innecesariamente
                for (int i = 0; i < registros - 5; i++)
                {
                    try {
                        conn.Open();
                        //Sobreescibimos las fechas de los campos.
                        cellData[i, 3] = DateConverter(cellData, i, 3);
                        cellData[i, 8] = DateConverter(cellData, i, 8);
                        cellData[i, 9] = DateConverter(cellData, i, 9);
                        //Extraemos los caracteres ínvalidos del campo OperationComment.
                        String normalizado = cellData[i, 4].Normalize(System.Text.NormalizationForm.FormD);
                        Regex  reg         = new Regex("[']");
                        cellData[i, 4] = reg.Replace(normalizado, "");
                        if (cellData[i, 2] == null || cellData[i, 2] == "")
                        {
                            cellData[i, 2] = "0";
                        }

                        //Introducimos los datos del excel adjunto en la base de datos.
                        cmd.CommandText = "INSERT INTO comentario_oceane_tc (LastModified, TicketID, CommentID, CommentNumber, CommentDate, OperationComment, UserName, CommentType, CurrentAction, CreationDate, ClosureDate, TicketDuration, TicketType, ProblemDetail, ShortLabel, ClosureGroupID, OwnerGroupID) VALUES('" + dat + "', '" + cellData[i, 0] + "','" + cellData[i, 1] + "'," + cellData[i, 2] + ",'" + cellData[i, 3] + "','" + cellData[i, 4].ToString() + "','" + cellData[i, 5] + "','" + cellData[i, 6] + "','" + cellData[i, 7] + "','" + cellData[i, 8] + "','" + cellData[i, 9] + "'," + cellData[i, 10] + ",'" + cellData[i, 11] + "','" + cellData[i, 12] + "','" + cellData[i, 13] + "','" + cellData[i, 14] + "','" + cellData[i, 15] + "')";
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    } catch (FormatException) {
                        cellData[i, 3] = DateConverter(cellData, i, 8);
                    } catch (Exception e) {
                        LOGS.Log("InsercionCOTC 1erSubCatch --> " + e.StackTrace + "\n");
                    } finally {
                        if (conn.State == System.Data.ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }
                }
                LOGS.Log("COTC --> INSERCION --> OK");
            } catch (Exception) {
                throw;
            }
        }
        //Devolvemos una fecha por defecto para aquellos campos nulos que requieran una fecha.
        public static String DefaultDate()
        {
            DateTime dataValue   = new DateTime(1971, 01, 01, 00, 00, 00);;
            String   formatDates = null;

            try {
                formatDates = dataValue.ToString("yyyy/MM/dd HH:mm:ss");
            } catch (Exception e) {
                LOGS.Log("InsercionCOTA (defautlDate) --> " + e + "\n");
            }
            return(formatDates);
        }
Beispiel #5
0
        //Devolvemos una fecha por defecto para aquellos campos nulos que requieran una fecha.
        public static String DefaultDate()
        {
            DateTime dataValue   = new DateTime(1971, 01, 01, 00, 00, 00);;
            String   formatDates = null;

            try {
                formatDates = dataValue.ToString("yyyy/MM/dd HH:mm:ss");
            } catch (Exception def) {
                LOGS.Log("InsercionTCDA (DefaultData) --> " + def.StackTrace + "\n");
            }
            return(formatDates);
        }
Beispiel #6
0
        //Método que cambia el formato de la fecha del campo fecha del excel abierto.
        public static String DateConverter(String[,] Array, int indiceFor, int indiceCambio)
        {
            DateTime dataValue;
            String   formatDates = null;

            try {
                dataValue   = DateTime.Parse(Array[indiceFor, indiceCambio]);
                formatDates = dataValue.ToString("yyyy/MM/dd HH:mm:ss");
            } catch (Exception e) {
                LOGS.Log("InsercionCOTC (DateConverter) --> " + e.StackTrace + "\n");
            }
            return(formatDates);
        }
        public static void InsercionData(String[,] cellData, int registros, DateTime fe)
        {
            MySqlConnection conn = new MySqlConnection(cred);
            MySqlCommand    cmd;

            //Se abre la conexion a la base de datos
            conn.Open();

            try {
                String dat = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");

                //fe = fe.AddHours(Double.Parse(DateTime.Now.ToString("HH")));
                //fe = fe.AddMinutes(Double.Parse(DateTime.Now.ToString("mm")));
                //fe = fe.AddSeconds(Double.Parse(DateTime.Now.ToString("ss")));
                //String dat = fe.ToString("yyyy/MM/dd HH:mm:ss");

                cmd = conn.CreateCommand();

                for (int i = 0; i < registros - 5; i++)
                {
                    try {
                        //longitudes de campos en BBDD (Exceptuando Fechas en formato TimeStamp).
                        cellData[i, 16] = DateConverter(cellData, i, 16);

                        if (cellData[i, 10].Length > 500)
                        {
                            cellData[i, 10] = cellData[i, 10].Substring(0, 499);
                        }

                        cmd.CommandText = "INSERT INTO backlog_oceane (`Lastmodified`, `Ticket ID`, `Owner - Group ID`, `Ticket type`, `Identifier 1`, `Company name`, `Current action`, `Third party reference`, `Short label`, `Final nature`, `Problem family`, `Problem datail`, `Cause label`, `Initiator - User name`, `Closure user name`,  `Initiating group ID`, `Closure group ID`, `Creation date`, `Owner - Group ID II`) VALUES('" + dat + "', '" + cellData[i, 0] + "','" + cellData[i, 1] + "','" + cellData[i, 2] + "','" + cellData[i, 3] + "','" + cellData[i, 4] + "','" + cellData[i, 5] + "','" + cellData[i, 6] + "','" + cellData[i, 7] + "','" + cellData[i, 8] + "','" + cellData[i, 9] + "','" + cellData[i, 10] + "','" + cellData[i, 11] + "','" + cellData[i, 12] + "','" + cellData[i, 13] + "','" + cellData[i, 14] + "','" + cellData[i, 15] + "','" + cellData[i, 16] + "', '" + cellData[i, 18] + "')";
                        cmd.ExecuteNonQuery();
                    } catch (Exception e) {
                        LOGS.Log("InsercionBO 1erSubCatch --> " + e + "\n");
                        //MessageBox.Show("" + e);
                        if (conn.State == System.Data.ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }
                }
                conn.Close();
            } catch (Exception ex) {
                LOGS.Log("InsercionBO 1erCatch --> " + ex.StackTrace + "\n");
                throw;
            } finally {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Beispiel #8
0
        public static void TiempoFinalTCDA(DateTime fe)
        {
            MySqlCommand    cmdInternal;
            MySqlConnection conn = new MySqlConnection(cred);
            String          dat  = fe.AddDays(-1).ToString("yyyy/MM/dd");


            try {
                //MessageBox.Show("Ticket " + comments[i, 0] + " Correcto con el valor de tiempo (mins) --> " + val);
                //commets[i,0] --> Equivale al Ticket de la BD.
                cmdInternal = new MySqlCommand("UPDATE tickets_cerrados_da tcda SET tcda.Tiempo = (SELECT SUM(cotc.Tiempo) FROM comentario_oceane_tc cotc WHERE cotc.TicketID = tcda.`Ticket ID` AND DATE_FORMAT(cotc.`Closuredate`, '%Y/%m/%d') = '" + dat + "' GROUP BY cotc.TicketID) WHERE DATE_FORMAT(tcda.`Closure date`, '%Y/%m/%d') = '" + dat + "'", conn);
                conn.Open();
                cmdInternal.CommandTimeout = 2147483;
                cmdInternal.ExecuteNonQuery();
                conn.Close();
                LOGS.Log("Actualizacion --> OK");
            } catch (Exception e) {
                LOGS.Log("GestionDeTiemposTC - UpdateTA --> " + e);
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            //Bucle para incertar por dias (custom).
            //for (int i = 31; i <= 31; i++) {
            //DateTime a = DateTime.Parse(i + "/05/2018");

            try {
                // Si la carpeta tempcm existe se borra y se vuelve a crear.
                if (Directory.Exists((ConfigurationManager.AppSettings.Get("ruta").ToString() + "vdata\\")))
                {
                    Directory.Delete((ConfigurationManager.AppSettings.Get("ruta").ToString() + "vdata\\"), true);
                    Directory.CreateDirectory((ConfigurationManager.AppSettings.Get("ruta").ToString() + "vdata\\"));

                    //Desde la clase deseada llamar a este metodo pasandole como parametro una fecha (DateTime).
                    if (ConfigurationManager.AppSettings.Get("updateOnly").ToString() == "1")
                    {
                        DescargaDeAdjuntos.PasoFecha(DateTime.Today);
                        //DescargaDeAdjuntos.PasoFecha(a);
                        Thread.Sleep(2000);
                    }
                    LOGS.Log("Actualizando campo 'Tiempo' de COTC...");
                    GestionDeTiemposTC.ObtenerIndice(DateTime.Today);
                    GestionDeTiemposTC.RecuperarDatos(DateTime.Today);
                    GestionDeTiemposTC.UpdateTC();
                    GestionDeTiemposTC.TiempoFinalTCDA(DateTime.Today);
                    Thread.Sleep(2000);
                    LOGS.Log("Actualizando campo 'Tiempo' de COTA...");
                    GestionDeTiemposTA.ObtenerIndice(DateTime.Now);
                    GestionDeTiemposTA.RecuperarDatos(DateTime.Now);
                    GestionDeTiemposTA.UpdateTA();
                }
                else
                {
                    // Si la carpeta tempcm no existe se crea.
                    Directory.CreateDirectory((ConfigurationManager.AppSettings.Get("ruta").ToString() + "vdata\\"));

                    //Desde la clase deseada llamar a este metodo pasandole como parametro una fecha (DateTime).
                    if (ConfigurationManager.AppSettings.Get("updateOnly").ToString() == "1")
                    {
                        DescargaDeAdjuntos.PasoFecha(DateTime.Today);
                        //DescargaDeAdjuntos.PasoFecha(a);
                        Thread.Sleep(2000);
                    }

                    LOGS.Log("Actualizando campo 'Tiempo' de COTC...");
                    GestionDeTiemposTC.ObtenerIndice(DateTime.Today);
                    GestionDeTiemposTC.RecuperarDatos(DateTime.Today);
                    GestionDeTiemposTC.UpdateTC();
                    GestionDeTiemposTC.TiempoFinalTCDA(DateTime.Today);
                    Thread.Sleep(2000);
                    LOGS.Log("Actualizando campo 'Tiempo' de COTA...");
                    GestionDeTiemposTA.ObtenerIndice(DateTime.Today);
                    GestionDeTiemposTA.RecuperarDatos(DateTime.Today);
                    GestionDeTiemposTA.UpdateTA();
                }
                LOGS.Log("Ejecucion Terminada --> OK");
            } catch (IOException e) {
                LOGS.Log("Catch General 1 --> " + e.StackTrace);
                //MessageBox.Show(e.StackTrace, "Advertencia", MessageBoxButtons.OK);
            } catch (Exception ex) {
                LOGS.Log("Catch General 2 --> " + ex.StackTrace);
                //MessageBox.Show(ex.StackTrace, "Advertencia", MessageBoxButtons.OK);
            }
        }
Beispiel #10
0
        public static void RecuperarDatos(DateTime fe)
        {
            //Abrimos la conexion a la base de datos utilizando la cadena de conexion.
            MySqlConnection conn  = new MySqlConnection(cred);
            MySqlConnection conn2 = new MySqlConnection(cred2);
            MySqlCommand    cmd;
            MySqlDataReader reader;
            //String dat = DateTime.Now.AddDays(0).ToString("yyyy/MM/dd");

            //Se debe agregar un argumento de tipo DateTime llamado 'fe'
            //fe = fe.AddHours(Double.Parse(DateTime.Now.ToString("HH")));
            //fe = fe.AddMinutes(Double.Parse(DateTime.Now.ToString("mm")));
            //fe = fe.AddSeconds(Double.Parse(DateTime.Now.ToString("ss")));
            String dat = fe.ToString("yyyy/MM/dd");

            updateData = new string[indice, 3];


            try {
                //Se comprueba si en el campo `comentario` existe el patron '[%]', siendo '%' cualquier caracter.
                cmd = new MySqlCommand("SELECT * From comentario_oceane_tc WHERE DATE_FORMAT(`Lastmodified`, '%Y/%m/%d') = '" + dat + "' AND `operationcomment` like '%[%]%'", conn2);
                conn2.Open();
                cmd.CommandTimeout = 2147483;
                reader             = cmd.ExecuteReader();

                long      i = 0;
                long      total;
                long      totalFinal;
                Boolean   verfal        = false;
                ArrayList listaComenCor = new ArrayList();

                while (reader.Read())
                {
                    total      = 0;
                    totalFinal = 0;
                    verfal     = false;
                    listaComenCor.Clear();
                    long idTicket = reader.GetInt64(0);
                    comments[i, 0] = reader.GetString(2); //Campo ticketID
                    comments[i, 1] = reader.GetString(6); //Campo OperationComment

                    //Si el contenido del campo comentario contiene '`' o  `´` entonces se procede a sustituirlos
                    if (comments[i, 1].Contains("`") || comments[i, 1].Contains("´"))
                    {
                        comments[i, 1] = comments[i, 1].Replace("`", " ");
                        comments[i, 1] = comments[i, 1].Replace("´", " ");
                        comments[i, 1] = comments[i, 1].Replace("<", " ");
                        comments[i, 1] = comments[i, 1].Replace(">", " ");
                    }

                    //try {
                    //Se coge la longitud de la cadena (comentario).
                    for (int j = 0; j < comments[i, 1].Length; j++)
                    {
                        //Se comprueba si en la posicion j de la cadena existe el caracter '['.
                        if (comments[i, 1].ElementAt(j).ToString() == "[")
                        {
                            //Se le pasa el indice a K si en la posicion de j existe un '['.
                            int k = j;
                            //Variable la cual servira para comprobar si hay mas de un digito dentro de '[]'.
                            int secuencia = 0;
                            //Mientras que no haya cierre de corchete el bucle recorrera la cadena a partir del primer valor del corchete de apertura.
                            while (comments[i, 1].ElementAt(k + 1).ToString() != "]")
                            {
                                try {
                                    //Si la secuencia es 0 entonces recogera el valor que haya dentro de los '[]' (cuando hay un solo dígito dentro de los '[]').
                                    if (secuencia == 0)
                                    {
                                        total = Int64.Parse(comments[i, 1].Substring(k + 1, 1));
                                        //Si hay mas de un digito dentro de los '[]' entonces se procede a concatenarlos
                                    }
                                    else if (secuencia > 0)
                                    {
                                        total = Int64.Parse(total.ToString() + comments[i, 1].Substring(k + 1, 1));
                                    }
                                } catch (Exception) {
                                    verfal = true;
                                    break;
                                }
                                secuencia++;
                                k++;
                                verfal = false;
                            }
                            if (verfal == false)
                            {
                                listaComenCor.Add(total);
                            }
                        }
                    }
                    //} catch (Exception e) {
                    //    LOGS.Log("GestionDeTiemposTC (RecuperarDatos) --> " + e + "\n");
                    //    //MessageBox.Show("" + e);
                    //}

                    foreach (long valor in listaComenCor)
                    {
                        //Se suma todas las cifras del comentario, si hubieran mas de uno.
                        totalFinal = totalFinal + valor;
                    }

                    updateData[i, 0] = totalFinal.ToString();
                    updateData[i, 1] = comments[i, 0];
                    updateData[i, 2] = idTicket.ToString();

                    i++;
                }
                conn2.Close();
            } catch (Exception e) {
                LOGS.Log("GestionDeTiemposTC (RecuperarDatos LastTry) --> " + e + "\n");
                //MessageBox.Show(""+e);
                if (conn2.State == System.Data.ConnectionState.Open)
                {
                    conn2.Close();
                }
                else if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Beispiel #11
0
        public static void LeerFicheroOceane(String nombreAdjunto, DateTime fec)
        {
            String nFile    = ConfigurationManager.AppSettings.Get("ruta").ToString() + "vdata\\" + nombreAdjunto;
            var    misValue = Type.Missing;

            //Se comprueba si el archivo adjunto existe en la ruta --> nFile.
            if (!File.Exists(nFile))
            {
                return;
            }

            LOGS.Log("Empezando a leer --> " + nombreAdjunto);
            // abrir el documento
            xlApp       = new excel.Application();
            xlWorkBooks = xlApp.Workbooks;
            xlWorkBook  = xlWorkBooks.Open(nFile);

            // seleccion de la hoja de calculo
            xlWorkSheet = (excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            // seleccion rango activo
            range = xlWorkSheet.UsedRange;

            // leer las celdas
            int rows = range.Rows.Count;
            int cols = range.Columns.Count;

            dataColRow = new String[rows, cols];

            //Incrementamos valor dependiedo del numero de filas que haya en el excel adjunto.
            int i = 0;
            //Incrementamos valor dependiedo del numero de columnas que haya en el excel adjunto.
            int j = 0;

            //Guardamos el valor de cada celda en uso del adjunto en un array bidi.
            for (int row = 5; row <= rows; row++)
            {
                j = 0;
                for (int col = 1; col <= cols; col++)
                {
                    try {
                        // Valor de la celda actual.
                        valorCelda       = (range.Cells[row, col] as excel.Range).Value.ToString();
                        dataColRow[i, j] = valorCelda;
                        j++;
                        //MessageBox.Show(valorCelda);
                    } catch (RuntimeBinderException) {
                        dataColRow[i, j] = "";
                        j++;
                    }
                }
                i++;
            }

            //Seleccionaremos el método según el nombre del adjunto.
            if (nombreAdjunto.ToLower().Contains("COMENTARIOS OCEANE- TICKETS CERRADOS - POSTVENTA CONECTA PYMES".ToLower()))
            {
                LOGS.Log("Lectura del adjunto " + nombreAdjunto + " --> OK");
                InsercionCOTC.InsercionData(dataColRow, rows, fec);
            }
            else if (nombreAdjunto.ToLower().Contains("CERTIFICACION POSTVENTA REVISION DIARIA".ToLower()))
            {
                LOGS.Log("Lectura del adjunto " + nombreAdjunto + " --> OK");
                InsercionTCDA.InsercionData(dataColRow, rows, fec);
            }
            else if (nombreAdjunto.ToLower().Contains("BACKLOG OCEANE (ibermatica)".ToLower()))
            {
                LOGS.Log("Lectura del adjunto " + nombreAdjunto + " --> OK");
                InsercionBO.InsercionData(dataColRow, rows, fec);
            }
            else if (nombreAdjunto.ToLower().Contains("COMENTARIOS OCEANE- TICKETS ABIERTOS - POSTVENTA CONECTA PYMES".ToLower()))
            {
                LOGS.Log("Lectura del adjunto " + nombreAdjunto + " --> OK");
                InsercionCOTA.InsercionData(dataColRow, rows, fec);
            }

            //Cerramos el worbook.
            xlWorkBook.Close(false, misValue, misValue);
            //Cerramos el conjunto de workbooks
            xlWorkBooks.Close();
            //Salimos de excel.
            xlApp.Quit();
            //Liberamos los tres objetos usados anteriomente.
            Marshal.ReleaseComObject(xlWorkBook);
            Marshal.ReleaseComObject(xlWorkBooks);
            Marshal.ReleaseComObject(xlApp);
        }
Beispiel #12
0
        public static void InsercionData(String[,] cellData, int registros, DateTime fe)
        {
            MySqlConnection conn = new MySqlConnection(cred);
            MySqlCommand    cmd;

            //Abrimos la conexion a la base de datos utilizando la cadena de conexion.
            conn.Open();

            try {
                String dat = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");

                //fe = fe.AddHours(Double.Parse(DateTime.Now.ToString("HH")));
                //fe = fe.AddMinutes(Double.Parse(DateTime.Now.ToString("mm")));
                //fe = fe.AddSeconds(Double.Parse(DateTime.Now.ToString("ss")));
                //String dat = fe.ToString("yyyy/MM/dd HH:mm:ss");

                cmd = conn.CreateCommand();
                for (int i = 0; i < registros - 5; i++)
                {
                    try {
                        //Si el campo i, 7 que es una fecha es null, le asignamos el formato de fecha por defecto
                        if (cellData[i, 7] == null || cellData[i, 7] == "")
                        {
                            cellData[i, 7] = DefaultDate();
                        }
                        else
                        {
                            //Si el campo no es null, cambiamos su formato para que se adapte a lo que se quiere.
                            cellData[i, 7] = DateConverter(cellData, i, 7);
                        }

                        if (cellData[i, 8] == null || cellData[i, 8] == "")
                        {
                            cellData[i, 8] = DefaultDate();
                        }
                        else
                        {
                            cellData[i, 8] = DateConverter(cellData, i, 8);
                        }

                        if (cellData[i, 10] == null || cellData[i, 10] == "")
                        {
                            cellData[i, 10] = DefaultDate();
                        }
                        else
                        {
                            cellData[i, 10] = DateConverter(cellData, i, 10);
                        }

                        if (cellData[i, 11] == null || cellData[i, 11] == "")
                        {
                            cellData[i, 11] = DefaultDate();
                        }
                        else
                        {
                            cellData[i, 11] = DateConverter(cellData, i, 11);
                        }

                        if (cellData[i, 18] == null || cellData[i, 18] == "")
                        {
                            cellData[i, 18] = "0";
                        }

                        //Extraemos los caracteres ínvalidos del campo OperationComment.
                        String normalizado = cellData[i, 3].Normalize(System.Text.NormalizationForm.FormD);
                        Regex  reg         = new Regex("[']");
                        cellData[i, 3] = reg.Replace(normalizado, "");

                        try {
                            cmd.CommandText = "INSERT INTO tickets_cerrados_da (`Lastmodified`, `Ticket ID`, `Third Party reference`, `Identifier 1`, `Company name`, `Initiator - User name`, `Closure user name`, `Current action`, `tickets.creation date`, `closure date`, `Transfer date`, `Restoration date (UTC)`, `Last Resolution date (UTC)`, `Ticket dur. BH 8am - 8pm Mon to Fri`, `Time To Repair`, `Time To Resolv`, `Ticket Type`, `Problem detail`, `Short label`, `Recipient - Group ID`, `Closure group ID`, `Initiating group ID`, `Initial nature`, `Request date`, `Indentifier 3`, `Contractual duration (mm)`, `Cause Label`) VALUES('" + dat + "', '" + cellData[i, 0] + "','" + cellData[i, 1] + "','" + cellData[i, 2] + "','" + cellData[i, 3] + "','" + cellData[i, 4] + "','" + cellData[i, 5] + "','" + cellData[i, 6] + "','" + cellData[i, 7] + "','" + cellData[i, 8] + "','" + cellData[i, 9] + "','" + cellData[i, 10] + "','" + cellData[i, 11] + "'," + cellData[i, 12] + "," + cellData[i, 13] + "," + cellData[i, 14] + ",'" + cellData[i, 15] + "','" + cellData[i, 16] + "', '" + cellData[i, 17] + "', '" + cellData[i, 18] + "', " + cellData[i, 19] + ", " + cellData[i, 20] + ", '" + cellData[i, 21] + "','" + cellData[i, 22] + "', '" + cellData[i, 23] + "', " + cellData[i, 24] + ", '" + cellData[i, 25] + "')";
                            cmd.ExecuteNonQuery();
                        }catch (Exception e) {
                            LOGS.Log("InsercionTCDA 1erSubCatch --> " + e.StackTrace + "\n");
                            //MessageBox.Show("" + e);
                            //cmd.CommandText = "INSERT INTO tickets_cerrados_da (`Lastmodified`, `Ticket ID`, `Third Party reference`, `Identifier 1`, `Company name`, `Initiator - User name`, `Closure user name`, `Current action`, `tickets.creation date`, `closure date`, `Transfer date`, `Restoration date (UTC)`, `Last Resolution date (UTC)`, `Ticket dur. BH 8am - 8pm Mon to Fri`, `Time To Repair`, `Time To Resolv`, `Ticket Type`, `Problem detail`, `Short label`, `Recipient - Group ID`, `Closure group ID`, `Initiating group ID`, `Initial nature`, `Request date`, `Contractual duration (mm)`) VALUES('" + dat + "', '" + cellData[i, 0] + "','" + cellData[i, 1] + "','" + cellData[i, 2] + "','" + cellData[i, 3] + "','" + cellData[i, 4] + "','" + cellData[i, 5] + "','" + cellData[i, 6] + "','" + cellData[i, 7] + "','" + cellData[i, 8] + "','" + cellData[i, 9] + "','" + cellData[i, 10] + "','" + cellData[i, 11] + "','" + cellData[i, 12] + "'," + cellData[i, 13] + "," + cellData[i, 14] + ",'" + cellData[i, 15] + "','" + cellData[i, 16] + "', '" + cellData[i, 17] + "', " + cellData[i, 18] + ", " + cellData[i, 19] + ", " + cellData[i, 20] + ", '" + cellData[i, 21] + "','" + cellData[i, 22] + "', " + cellData[i, 23] + ")";
                            //cmd.ExecuteNonQuery();
                        }
                    } catch (Exception e) {
                        LOGS.Log("InsercionTCDA 1er Catch --> " + e.StackTrace + "\n");
                        if (conn.State == System.Data.ConnectionState.Open)
                        {
                            conn.Close();
                        }
                    }
                }
                LOGS.Log("TCDA --> INSERCION --> OK");
            } catch (Exception ex) {
                LOGS.Log("InsercionTCDA (InsercionData) --> " + ex + "\n");
                throw;
            } finally {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Beispiel #13
0
 private static void ArchivosAdjuntos(Outlook.MAPIFolder folder, string ruta, DateTime fec)
 {
     Outlook.Items fi = folder.Items;
     // Se ordenan los correos por fecha de entrega para evitar leer todos los correos que no sean del d�a actual.
     fi.Sort("[ReceivedTime]", true);
     if ((fi.ToString() != null))
     {
         foreach (Outlook.MailItem item in fi)
         {
             Outlook.MailItem mi = item;
             // Se listan todos los adjuntos del buzon.
             Outlook.Attachments attachments = mi.Attachments;
             string   nombreRemitente;
             DateTime fecha;
             // Se aplica un margen minimo y maximo el cual busque los correos.
             DateTime intervaloMenor = fec.AddHours(1);
             DateTime intervaloMayor = fec.AddHours(12);
             fecha           = mi.ReceivedTime;
             nombreRemitente = mi.SenderName;
             //fechaHora = fecha.Split(' ');
             //MessageBox.Show(fecha.Date.ToString());
             if (nombreRemitente.ToLower().Contains(ConfigurationManager.AppSettings.Get("remitente").ToLower()) && fecha.Date.Equals(fec.Date) && (mi.Subject.ToLower().Contains("CERTIFICACION POSTVENTA DIARIA".ToLower()) || mi.Subject.ToLower().Contains("BACKLOG OCEANE (ibermatica)".ToLower()) || mi.Subject.ToLower().Contains("COMENTARIOS OCEANE- TICKETS CERRADOS - POSTVENTA CONECTA PYMES".ToLower()) || mi.Subject.ToLower().Contains("COMENTARIOS OCEANE- TICKETS ABIERTOS - POSTVENTA CONECTA PYMES".ToLower())) && fecha.Hour >= intervaloMenor.Hour && fecha.Hour <= intervaloMayor.Hour)
             {
                 // Comprobamos si hay algun adjunto dentro del email recibido.
                 if ((attachments.Count != 0))
                 {
                     for (int i = 1; (i <= mi.Attachments.Count); i++)
                     {
                         // Guardamos el nombre del adjunto en "fn"
                         string fn = mi.Attachments[i].FileName.ToLower();
                         for (int j = 0; (j <= (extensionsArray.Length - 1)); j++)
                         {
                             // Utilizamos el array de extensiones para comprobar su compatibilidad y poder descargarlo.
                             if (fn.Contains(extensionsArray[j].ToString()))
                             {
                                 //  MessageBox.Show("Dia: " + fechaHora(0) + " Hora: " + fechaHora(1) & vbNewLine & "Adjunto: " + mi.Attachments(i).FileName, "Dato Adjunto")
                                 //Se realiza la comprobacion del archivo descargado (El primer if puede ser confuso, pero se realiza para evitar hacer una comrpobacion o insercion errónea de datos).
                                 if (mi.Attachments[i].FileName.Contains("Tickets Oceane Cerrados dia anterior - P.Segundo nivel"))
                                 {
                                 }
                                 else
                                 {
                                     if (mi.Attachments[i].FileName.ToLower().Contains("COMENTARIOS OCEANE- TICKETS CERRADOS - POSTVENTA CONECTA PYMES".ToLower()))
                                     {
                                         LOGS.Log("InsercionCOTA (InsercionData) --> Se Descarga el fichero 'COMENTARIOS OCEANE- TICKETS CERRADOS - POSTVENTA CONECTA PYMES'");
                                         // Se guarda el documento en la ruta especificada (se especifica en App.Config).
                                         mi.Attachments[i].SaveAsFile(ruta + "" + mi.Attachments[i].FileName);
                                         LecturaAdjuntos.LeerFicheroOceane(mi.Attachments[i].FileName, fec);
                                     }
                                     else if (mi.Attachments[i].FileName.ToLower().Contains("CERTIFICACION POSTVENTA REVISION DIARIA".ToLower()))
                                     {
                                         LOGS.Log("InsercionCOTA (InsercionData) --> Se Descarga el fichero 'Certificacion Postventa'");
                                         //Se guarda el documento en la ruta especificada (se especifica en App.Config).
                                         mi.Attachments[i].SaveAsFile(ruta + "" + mi.Attachments[i].FileName);
                                         LecturaAdjuntos.LeerFicheroOceane(mi.Attachments[i].FileName, fec);
                                     }
                                     else if (mi.Attachments[i].FileName.ToLower().Contains("BACKLOG OCEANE (ibermatica)".ToLower()))
                                     {
                                         if (comp < 1)
                                         {
                                             LOGS.Log("InsercionCOTA (InsercionData) --> Se Descarga el fichero 'BACKLOG OCEANE (ibermatica)'");
                                             // Se guarda el documento en la ruta especificada (se especifica en App.Config).
                                             mi.Attachments[i].SaveAsFile(ruta + "" + mi.Attachments[i].FileName);
                                             LecturaAdjuntos.LeerFicheroOceane(mi.Attachments[i].FileName, fec);
                                             comp++;
                                         }
                                     }
                                     else if (mi.Attachments[i].FileName.ToLower().Contains("COMENTARIOS OCEANE- TICKETS ABIERTOS - POSTVENTA CONECTA PYMES".ToLower()))
                                     {
                                         LOGS.Log("InsercionCOTA (InsercionData) --> Se Descarga el fichero 'COMENTARIOS OCEANE- TICKETS ABIERTOS - POSTVENTA CONECTA PYMES'");
                                         // Se guarda el documento en la ruta especificada (se especifica en App.Config).
                                         mi.Attachments[i].SaveAsFile(ruta + "" + mi.Attachments[i].FileName);
                                         LecturaAdjuntos.LeerFicheroOceane(mi.Attachments[i].FileName, fec);
                                     }
                                     j = extensionsArray.Length;
                                 }
                             }
                         }
                     }
                 }
             }
             else if (fecha.Date < fec.Date)
             {
                 break;
             }
         }
     }
 }