コード例 #1
0
 private void bckIniciarComponetes_DoWork(object sender, DoWorkEventArgs e)
 {
     if (!UtilVarios.ExisteServicio("MySQL"))
     {
         this.pictureBox2.Location = new System.Drawing.Point(29, 55);
         label2.Text = "Iniciando el sistema por primera vez." + '\r' + "Este proceso puede tomar unos minutos.";
      //   label1.Text = "Instalando servidor de base de datos . . .";
       //  UtilDB.InstalarMySQL();
         label1.Text = "Configurando servidor de base de datos . . .";
         UtilDB.ConfigurarMySQL();
     }
     label1.Text = "Obteniendo datos del servidor . . .";
 reiniciar:
     try
     {                
         ds = BL.GetDataBLL.GetData();                
         string idRazonSocial = BL.GetDataBLL.RazonSocial().Rows[0][0].ToString();
         BL.MantenimientoBLL.Mantenimiento();
         BL.VentasBLL.VentasHistoricasMantener();
         label1.Text = "Importando datos . . .";
    //     BL.DatosBLL.GetDataPOS(false);  // false no importa los datos de hoy
         label1.Text = "Exportando datos . . .";
      //   BL.DatosBLL.ExportarDatos();
     }
     catch (ServidorMysqlInaccesibleException ex)
     {
         this.Invoke((Action)delegate
         {
             this.Visible = false;
             MessageBox.Show(ex.Message, "Trend Gestión",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         });
         System.Environment.Exit(1);
     }
     catch (System.TimeoutException)
     {
         this.Invoke((Action)delegate
         {
             this.Visible = false;
             MessageBox.Show("El tiempo de conexión con el servidor ha expirado. Intente nuevamente.", "Trend Gestión",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
             System.Environment.Exit(1);
         });
     }
     catch (IndexOutOfRangeException) // se produce la excepción si no existe el registro en la tabla. Lo agrego 
     {
         try
         {
             DataTable tblRazon = BL.GetDataBLL.RazonSocial();
             DataRow row = tblRazon.NewRow();
             Random rand = new Random();
             int clave = rand.Next(147483647, 2147483647);
             row["IdRazonSocialRAZ"] = clave;
             row["RazonSocialRAZ"] = "";
             row["NombreFantasiaRAZ"] = "";
             row["DomicilioRAZ"] = "";
             row["LocalidadRAZ"] = "";
             row["ProvinciaRAZ"] = "";
             row["IdCondicionIvaRAZ"] = DBNull.Value;
             row["CuitRAZ"] = "";
             row["IngresosBrutosRAZ"] = "";
             row["InicioActividadRAZ"] = DBNull.Value;
             tblRazon.Rows.Add(row);
             BL.RazonSocialBLL.GrabarDB(tblRazon);
         }
         catch (ServidorMysqlInaccesibleException ex)
         {
             this.Invoke((Action)delegate
             {
                 this.Visible = false;
                 MessageBox.Show(ex.Message, "Trend Gestión",
                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             });
             System.Environment.Exit(1);
         }
         goto reiniciar;
     }
     catch (WebException)
     {
         this.Invoke((Action)delegate
         {
             this.Visible = false;
             MessageBox.Show("No se pudo establecer conexión con el servidor remoto. No se actualizaron los datos.", "Trend Gestión",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         });
     }
     catch (Exception ex)
     {
         this.Invoke((Action)delegate
         {
             this.Visible = false;
             string error = ex.Message;
             MessageBox.Show(error, "Trend Gestión",
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         });
     }
 }