Пример #1
0
        public async Task EnviarAsync(String Tabela, Int32 Empresa_id)
        {
            String          TelFormat = "";
            Int32           Enviados  = 0;
            Int32           Falhas    = 0;
            WhatsAppSendPST App;
            Hlp             Hlp;

            try
            {
                App = new WhatsAppSendPST();
                Con = new Connect();
                Hlp = new Hlp();

                EnviarOperadores();

                if (cb_filtros.Checked == true)
                {
                    DisplayData(App.Pesquisar(Tabela, Empresa_id, Hlp.DateFormat(dtp_inicial.Text), Hlp.DateFormat(dtp_final.Text)));
                }
                else
                {
                    DisplayData(App.Pesquisar(Tabela, Empresa_id));
                }

                for (int Cont = 0; Cont < Table.Rows.Count; Cont++)
                {
                    //Controles
                    if (Parar == true)
                    {
                        break;
                    }
                    if (Contador > 1000)
                    {
                        Contador = 0;
                    }

                    // Timer
                    await Task.Delay(Hlp.WaitTime(Contador));

                    App.Destinatario = new Destinatario();

                    App.Destinatario.Nome     = Table.Rows[Cont]["nome"].ToString();
                    App.Destinatario.Telefone = Hlp.TelFind(Table, Tabela, Cont);

                    if (!String.IsNullOrEmpty(App.Destinatario.Telefone))
                    {
                        TelFormat = Hlp.TelFormat(App.Destinatario.Telefone);
                    }

                    if (!String.IsNullOrEmpty(TelFormat))
                    {
                        if (cb_testar.Checked == false)
                        {
                            WebReq(URL_PLATFORM, TelFormat, App.Destinatario.Nome);
                        }
                        else
                        {
                            WebReq(URL_PLATFORM, TESTE_DESTINATARIO, App.Destinatario.Nome);
                            break;
                        }

                        Enviados++;
                        lbl_enviados.Text = "ENVIADOS: " + Enviados.ToString();
                        lbl_total.Text    = "TOTAL: " + (Enviados + Falhas).ToString();
                    }
                    else
                    {
                        dataGridView2.Rows.Add(App.Destinatario.Nome, App.Destinatario.Telefone, "FALHA");
                        Falhas++;
                        lbl_falhas.Text = "FALHAS: " + Falhas.ToString();
                        lbl_total.Text  = "TOTAL: " + (Enviados + Falhas).ToString();
                    }
                    Contador++;
                }

                lbl_enviados.Text = "ENVIADOS: " + Enviados.ToString();
                lbl_falhas.Text   = "FALHAS: " + Falhas.ToString();
                lbl_total.Text    = "TOTAL: " + (Enviados + Falhas).ToString();
                MessageBox.Show("O ENVIO FOI CONCLUIDO!");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }