예제 #1
0
파일: Form1.cs 프로젝트: cuantico56/VARIOS
        /****************************************ENVIAR TAREAS ASINCRONICAS*************************************************************
         *
         *
         *      private async void  button2_Click(object sender, EventArgs e)
         *      {
         *          progressBar1.Value = 0;
         *          progressBar2.Value = 0;
         *          progressBar3.Value = 0;
         *          progressBar4.Value = 0;
         *          timer1.Start();
         *          timer2.Start();
         *          timer5.Start();
         *          timer6.Start();
         *          timer1.Enabled = true;
         *          timer2.Enabled = true;
         *          timer5.Enabled = true;
         *          timer6.Enabled = true;
         *
         *              richTextBox1.Text = string.Empty;
         *              richTextBox2.Text = string.Empty;
         *              richTextBox6.Text = string.Empty;
         *              richTextBox8.Text = string.Empty;
         *              Task<string> tarea = new Task<string>(EnviarFactura);  //Lamamos una tarea para hacerla asincrona
         *              Task<string> tarea2 = new Task<string>(EnviarFactura2);
         *              Task<string> tarea3 = new Task<string>(EnviarFactura3);
         *              Task<string> tarea4 = new Task<string>(EnviarFactura4);
         *              tarea.Start();
         *              tarea2.Start();
         *              tarea3.Start();
         *              tarea4.Start();
         *              progressBar1.Visible = true;
         *              progressBar2.Visible = true;
         *              progressBar3.Visible = true;
         *              progressBar4.Visible = true;
         *
         *              string resultado = await tarea;
         *              timer1.Stop();
         *              progressBar1.Value = 100;
         *
         *              string resultado2 = await tarea2;
         *              timer2.Stop();
         *              progressBar2.Value = 100;
         *
         *              string resultado3 = await tarea3;
         *              timer5.Stop();
         *              progressBar3.Value = 100;
         *
         *              string resultado4 = await tarea4;
         *              timer6.Stop();
         *              progressBar4.Value = 100;
         *
         *      }
         *
         *
         ********************************************************************************************************************/


        /*********************************************************funciones******************************************************
         *
         *     public string EnviarFactura()
         *     {
         *         WS_Ecuador.Integracion samir = new WS_Ecuador.Integracion();
         *
         *             byte[] a = File.ReadAllBytes(textBox1.Text);
         *
         *
         *
         *
         *             var resp = samir.Factura("1792433738001", "1792433738001_INT", "UF5L1AWUA1U2", a, "facturaTEST");
         *
         *
         *
         *
         *             if (InvokeRequired)
         *                 Invoke(new Action(() => richTextBox1.Text = resp.MensajeError + "\n"));
         *             Invoke(new Action(() => richTextBox2.Text = resp.NumeroError + "\n"));
         *
         *             return "ok";
         *     }
         *
         *
         * //*********************************************************************************************/



        // ***********************************************ENVIAR CONSULTA ESTATUS DOCUMENTO*****************************
        public string Estatus(string num)
        {
            try
            {
                WS_Ecuador.Integracion mario = new WS_Ecuador.Integracion();
                var res = mario.EstatusDocumento("1792433738001", "1792433738001_INT", "UF5L1AWUA1U2", num);
                codigo     = res.codigo;
                MenEstatus = "codigo: " + Convert.ToString(codigo) + "\n" + "Mensaje: " + res.mensaje;
                mario.Dispose();
            }
            catch (Exception e)
            {
                MessageBox.Show("Hubo un error: " + e);
            }
            return("ok");
        }
예제 #2
0
파일: Form1.cs 프로젝트: cuantico56/VARIOS
        //*******************************CARGAMOS VARIOS ARCHIVOS********************
        private async void button10_Click(object sender, EventArgs e)
        {
            data.Clear();


            try {
                FolderBrowserDialog dialog = new FolderBrowserDialog();

                dialog.SelectedPath = "C:\\LISTA";

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    string direcccion = dialog.SelectedPath;
                    folderBrowserDialog1.Dispose();
                }



                string[] allfiles = System.IO.Directory.GetFiles(dialog.SelectedPath, "*.txt*", System.IO.SearchOption.AllDirectories);

                int cuantos = allfiles.Length;
                rep = "";
                for (int i = 0; i < cuantos; i++)
                {
                    rep += allfiles[i] + "\n";
                }
                richTextBox5.Text = rep;


                //******************************************************CAMBIAR SECUENCIA Y FECHA DE CADA ARCHIVO*****************************

                /*
                 *          string camb = File.ReadAllText(allfiles[0]);
                 *          string[] contenido = camb.Split('|');
                 *          int secuencial;
                 *
                 *
                 *          secuencial = Convert.ToInt32(contenido[16]);
                 *          secuencial += secuencial;
                 *          contenido[16] = Convert.ToString(secuencial);
                 *
                 */


                //********************************* AQUI SE ENVIAN LA CANTIDAD DE ARCHIVOS****************************************



                if (comboBox1.SelectedIndex == 0)  // Si seleccionamos TEST
                {
                    MessageBox.Show("Usted escogió: " + Convert.ToString(comboBox1.SelectedIndex));


                    var envi = new WS_Ecuador.Integracion();
                    var resp = new List <WS_Ecuador.RespuestaTimbradoTXT>();



                    ruc        = textBox1.Text;
                    usuario    = textBox2.Text;
                    contraseña = textBox3.Text;



                    timer7.Start();

                    List <Task> Tareas = new List <Task>();


                    for (int j = 0; j < allfiles.Length; j++)
                    {
                        byte[] d = File.ReadAllBytes(allfiles[j]);
                        Tareas.Add(Task.Run(() => { resp.Add(envi.Factura(ruc, usuario, contraseña, d, "facturaTEST4")); }));
                    }


                    progressBar5.Value = 0;
                    timer7.Enabled     = true;



                    await Task.WhenAll(Tareas.ToArray());

                    timer7.Enabled     = false;
                    progressBar5.Value = 100;



                    for (int i = 0; i < Tareas.Count; i++)
                    {
                        var r = resp[i];


                        data.Add(r.UUID + ": Mensaje Error: " + r.MensajeError + "Numero Error: " + r.NumeroError + "\n");


                        StreamWriter doc = File.AppendText(@"C:\SALIDA\ArchivoSalidas.txt");
                        doc.WriteLine(r.UUID + ": Mensaje Error: " + r.MensajeError + "Numero Error: " + r.NumeroError + " Fecha: " + r.FechaHora + " Procesado: " + r.Procesado + "\n");
                        doc.Close();
                    }

                    rep = "";
                    for (int i = 0; i < data.Count; i++)
                    {
                        rep += data[i] + "\n";
                    }


                    richTextBox5.Text = rep;
                }

                if (comboBox1.SelectedIndex == 1)    //si seleccionamos DEMO

                {
                    MessageBox.Show("Usted escogió: " + Convert.ToString(comboBox1.SelectedIndex));
                    var envi = new WS_DEMO.Integracion();
                    var resp = new List <WS_DEMO.RespuestaTimbradoTXT>();



                    ruc        = textBox1.Text;
                    usuario    = textBox2.Text;
                    contraseña = textBox3.Text;



                    timer7.Start();

                    List <Task> Tareas = new List <Task>();


                    for (int j = 0; j < allfiles.Length; j++)
                    {
                        byte[] d = File.ReadAllBytes(allfiles[j]);
                        Tareas.Add(Task.Run(() => { resp.Add(envi.Factura(ruc, usuario, contraseña, d, "facturaTEST4")); }));
                    }


                    progressBar5.Value = 0;
                    timer7.Enabled     = true;



                    await Task.WhenAll(Tareas.ToArray());

                    timer7.Enabled     = false;
                    progressBar5.Value = 100;



                    for (int i = 0; i < Tareas.Count; i++)
                    {
                        var r = resp[i];


                        data.Add(r.UUID + ": Mensaje Error: " + r.MensajeError + "Numero Error: " + r.NumeroError + "\n");


                        StreamWriter doc = File.AppendText(@"C:\SALIDA\ArchivoSalidas.txt");
                        doc.WriteLine(r.UUID + ": Mensaje Error: " + r.MensajeError + "Numero Error: " + r.NumeroError + " Fecha: " + r.FechaHora + " Procesado: " + r.Procesado + "\n");
                        doc.Close();
                    }

                    rep = "";
                    for (int i = 0; i < data.Count; i++)
                    {
                        rep += data[i] + "\n";
                    }


                    richTextBox5.Text = rep;
                }


                if (comboBox1.SelectedIndex == -1)
                {
                    MessageBox.Show("NO fue procesada la petición, escoja una plataforma TEST/DEMO");
                }
            }

            catch (Exception a)
            {
                MessageBox.Show("Debes escojer una carpeta: ERRROR:   " + a);
            }
        }