Esempio n. 1
0
        /// <summary>
        /// Tal método NÃO lê cada linha automaticamente. É preciso criar 2 for: O VALOR INICIAL DO FOR COM ROWS DEVE SER = 4, e o de Columns = 1.
        /// Escrita: for(int r = 4; r (menor que) xlsRowsCount(); r++)  {
        ///  for(int c = 4; c (menor que) xlsColumnsCount(); r++)
        ///   }
        /// 1º for menor que xlsRowsCount()
        /// 2º for menor que xlsColumnsCount().
        /// </summary>
        /// <param name="r">Valor atual de R dentro do for com comparação ao método xlsRowsCount()</param>
        /// <param name="c">Valor atual de C dentro do for com comparação ao método xlsColumnsCount()</param>
        /// <returns></returns>
        public static string LerArquivoESalvarManual(int r)
        {   //Arquivo Vazio
            if (arq != null || arq != "")
            {
                //Lendo a primeira linha apenas
                if (r == 1)
                {
                    //Verificando nome do funcionário
                    if (Convert.ToString((xlrange.Cells[1, 1] as Excel.Range).Value2) != "")
                    {
                        V11BD.Funcionario = (xlrange.Cells[1, 1] as Excel.Range).Value2;
                        if (V11BD.GetFuncionario() == false)
                        {
                            return("Funcionário não encontrado");
                        }
                    }
                    else
                    {
                        return("Nome do funcionário não informado");
                    }

                    //Verificando campo processo
                    if (Convert.ToString((xlrange.Cells[1, 10] as Excel.Range).Value2) != "")
                    {
                        try
                        {
                            V11BD.Processo = Convert.ToInt32((xlrange.Cells[1, 10] as Excel.Range).Value2);
                            if (V11BD.Processo != 3 && V11BD.Processo != 14)
                            {
                                return("Valores inválidos para Nº do processo");
                            }
                        }
                        catch
                        {
                            return("VALOR INVÁLIDO PARA 'PROCESSO' [1,10] ACEITANDO os NÚMEROS 3 OU 8 APENAS");
                        }
                    }
                    else
                    {
                        return("Processo não informado.");
                    }
                }
                else
                {
                    //verificando se esse CRM já foi preenchido
                    if (Convert.ToString((xlrange.Cells[r, 10] as Excel.Range).Value2) == "" || Convert.ToString((xlrange.Cells[r, 10] as Excel.Range).Value2) == null)
                    {
                        //Verificando se a primeira linha é válida (data)
                        if (Convert.ToString((xlrange.Cells[r, 1] as Excel.Range).Value2) != null || Convert.ToString((xlrange.Cells[r, 1] as Excel.Range).Value2) == "")
                        {
                            //Data
                            try
                            {
                                PROVdata = ((xlrange.Cells[r, 1] as Excel.Range).Value2);
                            }
                            catch
                            {
                                return("VALOR INVÁLIDO PARA A COLUNA DATA NA LINHA " + r);
                            }
                        }
                        else
                        {
                            return("VALOR INVÁLIDO PARA A COLUNA DATA NA LINHA " + r);
                        }
                        //Hora inicial
                        if (Convert.ToString((xlrange.Cells[r, 2] as Excel.Range).Value2) == null || Convert.ToString((xlrange.Cells[r, 2] as Excel.Range).Value2) == "")
                        {
                            return("CÉLULA DA COLUNA 'HORA INICIAL' NA LINHA " + r + " NÃO FOI PREENCHIDA.");
                        }
                        else
                        {
                            try
                            {
                                PROVhorai = (xlrange.Cells[r, 2] as Excel.Range).Value2;
                            }
                            catch
                            {
                                string aux = (xlrange.Cells[r, 2] as Excel.Range).Value2;
                                PROVdatain = DateTime.FromOADate(PROVdata).ToShortDateString() + " " + aux;
                            }
                        }
                        //Hora final
                        if (Convert.ToString((xlrange.Cells[r, 3] as Excel.Range).Value2) == null || Convert.ToString((xlrange.Cells[r, 3] as Excel.Range).Value2) == "")
                        {
                            return("CÉLULA DA COLUNA 'HORA FINAL' NA LINHA " + r + " NÃO FOI PREENCHIDA.");
                        }
                        else
                        {
                            try
                            {
                                PROVhoraf = (xlrange.Cells[r, 3] as Excel.Range).Value2;
                            }
                            catch
                            {
                                string aux = (xlrange.Cells[r, 3] as Excel.Range).Value2;
                                PROVdatafin = DateTime.FromOADate(PROVdata).ToShortDateString() + " " + aux;
                            }
                        }
                        //Cliente
                        if ((xlrange.Cells[r, 4] as Excel.Range).Value2 == null || (xlrange.Cells[r, 4] as Excel.Range).Value2 == "")
                        {
                            return("CÉLULA DA COLUNA 'CLIENTE' NA LINHA " + r + " NÃO PREENCHIDA");
                        }
                        else
                        {
                            V11BD.Cliente = (xlrange.Cells[r, 4] as Excel.Range).Value2;
                        }
                        //Cliente ID
                        if (Convert.ToString((xlrange.Cells[r, 5] as Excel.Range).Value2) == null || Convert.ToString((xlrange.Cells[r, 5] as Excel.Range).Value2) == "")
                        {
                            return("CÉLULA DA COLUNA 'CLIENTE ID' NA LINHA " + r + " NÃO PREENCHIDA");
                        }
                        else
                        {
                            try
                            {
                                V11BD.Cliente_id = Convert.ToInt32((xlrange.Cells[r, 5] as Excel.Range).Value2);
                            }
                            catch
                            {
                                return("VALOR INVÁLIDO INFORMADO NO CAMPO 'CLIENTE_ID' NA LINHA " + r);
                            }
                        }
                        //Centro de Custo
                        if (Convert.ToString((xlrange.Cells[r, 6] as Excel.Range).Value2) == null || Convert.ToString((xlrange.Cells[r, 6] as Excel.Range).Value2) == "")
                        {
                            return("CÉLULA DA COLUNA 'CENTRO.CUSTO' NA LINHA " + r + " NÃO PREENCHIDA");
                        }
                        else
                        {
                            try
                            {
                                V11BD.Centrodecusto = Convert.ToInt32((xlrange.Cells[r, 6] as Excel.Range).Value2);
                            }
                            catch
                            {
                                return("VALOR INVÁLIDO INFORMADO NO CAMPO 'CENTRO.CUSTO' NA LINHA " + r);
                            }
                        }
                        //Problema
                        if (Convert.ToString((xlrange.Cells[r, 7] as Excel.Range).Value2) == null || Convert.ToString((xlrange.Cells[r, 7] as Excel.Range).Value2) == "")
                        {
                            return(" CÉLULA DA COLUNA 'PROBLEMA' NA LINHA " + r + "NÃO FOI PREENCHIDA.");
                        }
                        else
                        {
                            V11BD.Problema = (xlrange.Cells[r, 7] as Excel.Range).Value2;
                            V11BD.Problema = V11BD.Problema.ToUpper();
                        }
                        //Solução
                        if (Convert.ToString((xlrange.Cells[r, 8] as Excel.Range).Value2) == null || Convert.ToString((xlrange.Cells[r, 8] as Excel.Range).Value2) == "")
                        {
                            return("CÉLULA DA COLUNA 'SOLUÇÃO' NA LINHA " + r + " NÃO FOI PREENCHIDA.");
                        }
                        else
                        {
                            V11BD.Solucao = (xlrange.Cells[r, 8] as Excel.Range).Value2;
                            V11BD.Solucao = V11BD.Solucao.ToUpper();
                        }

                        //Tentativa de conversão das datas
                        try
                        {
                            PROVdatain       = DateTime.FromOADate(PROVdata).ToShortDateString() + " " + DateTime.FromOADate(PROVhorai).ToShortTimeString();
                            PROVdatafin      = DateTime.FromOADate(PROVdata).ToShortDateString() + " " + DateTime.FromOADate(PROVhoraf).ToShortTimeString();
                            V11BD.Datainicio = Convert.ToDateTime(PROVdatain);
                            V11BD.Datafim    = Convert.ToDateTime(PROVdatafin);
                        }
                        catch
                        {
                            return("INFORMAÇÕES NA DATA HORA DA LINHA " + r + " NÃO FORAM INFORMADAS CORRETAMENTE");
                        }
                    }
                    else
                    {
                        return("skip");
                    }
                }
                aux = r;
                return("OK");
            }
            else
            {
                return("Não há arquivo para leitura");
            }
        }
Esempio n. 2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            bool keepfor = true;

            for (int r = 1; r <= CrmFile.xlsRowsCount(); r++)
            {
                if (keepfor == true)
                {
                    if (r == 1 || r > 3)
                    {
                        status = CrmFile.LerArquivoESalvarManual(r);
                    }
                    if (status == "OK")
                    {
                        if (progresso.Value != progresso.Maximum)
                        {
                            count = r;
                            backgroundWorker1.WorkerReportsProgress = true;
                            backgroundWorker1.ReportProgress(r);

                            if (r >= 4)
                            {
                                if (V11BD.GetContrato())
                                {
                                    if (V11BD.GetCentro_Custo())
                                    {
                                        info = V11BD.InsertIntoBD();
                                        if (info == "")
                                        {
                                            LOG.Logfile.WriteLine(CrmFile.ShowInformations());
                                        }
                                        else
                                        {
                                            LOG.Logfile.WriteLine(info);
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Centro de custo não encontrado", "Falha de GET", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        string inf = CrmFile.CloseXLS();
                                        if (inf == "")
                                        {
                                            LOG.Logfile.WriteLine("Arquivo/Processo xls fechado/finalizado");
                                        }
                                        else
                                        {
                                            LOG.Logfile.WriteLine(inf);
                                        }
                                        Conection.Close();
                                        break;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Contrato não encontrado", "Falha de GET", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    string inf = CrmFile.CloseXLS();
                                    if (inf == "")
                                    {
                                        LOG.Logfile.WriteLine("Arquivo/Processo xls fechado/finalizado");
                                    }
                                    else
                                    {
                                        LOG.Logfile.WriteLine(inf);
                                    }
                                    Conection.Close();
                                    break;
                                }
                            }
                        }
                    }
                    else if (status == "skip")
                    {
                        LOG.Logfile.WriteLine("Linha " + r + " já possui CRM cadastrado");
                    }
                    else if (status == "Arquivo para leitura inválido")
                    {
                        keepfor = false;
                        string inf = CrmFile.CloseXLS();
                        if (inf == "")
                        {
                            LOG.Logfile.WriteLine("Arquivo/Processo xls fechado/finalizado");
                        }
                        else
                        {
                            LOG.Logfile.WriteLine(inf);
                        }
                        Conection.Close();
                    }
                    else if (status == "" || status == null)
                    {
                        //Caso o campo de CRM ja esteja preenchido, não é preciso realizar o processo novamente.
                    }
                    else
                    {
                        MessageBox.Show(status, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        string inf = CrmFile.CloseXLS();
                        if (inf == "")
                        {
                            LOG.Logfile.WriteLine("Arquivo/Processo xls fechado/finalizado");
                        }
                        else
                        {
                            LOG.Logfile.WriteLine(inf);
                        }
                        Conection.Close();
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }