private void cFMMI100010_Load(object sender, EventArgs e) { try { Application.EnableVisualStyles(); MigrateBackgroundWorker.DoWork += MigrateBackgroundWorker_DoWork; MigrateBackgroundWorker.ProgressChanged += MigrateBackgroundWorker_ProgressChanged; MigrateBackgroundWorker.RunWorkerCompleted += MigrateBackgroundWorker_RunWorkerCompleted; MigrateBackgroundWorker.WorkerReportsProgress = true; MigrateBackgroundWorker.RunWorkerAsync(); } catch (Exception ex) { MessageBox.Show(string.Format("cFMMI100010_Load: {0}", ex.Message), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void MigrateBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { try { this.Invoke(new Action(() => { MessageLabel.Text = "Iniciando proceso"; })); MigrateBackgroundWorker.ReportProgress(0); CheckInHoursBLL CheckInoursBLL = new CheckInHoursBLL(); ZKTecoHourAssistanceBLL zKTecoHourAssistanceBLL = new ZKTecoHourAssistanceBLL(); MigrateBackgroundWorker.ReportProgress(10); this.Invoke(new Action(() => { MessageLabel.Text = "Paso 1: Migrando información a la Base de datos"; })); string start = string.Empty; string end = string.Empty; try { MigrationHistoryBLL migrationHistoryBLL = new MigrationHistoryBLL(); string dateLastRecord = migrationHistoryBLL.LastRecord(); if (!string.IsNullOrEmpty(dateLastRecord)) { start = DateTime.Parse(dateLastRecord).AddMinutes(1).ToString(); DateTime _Today = DateTime.Now; MigrateBackgroundWorker.ReportProgress(20); if (DateTime.Parse(dateLastRecord).AddMinutes(1) <= _Today) { end = _Today.ToString(); zKTecoHourAssistanceBLL.MigrateHoursToBD(start, end); } } else { List <string> dateMigrate = zKTecoHourAssistanceBLL.MigrateHoursToBD(); if (dateMigrate != null && dateMigrate.Count == 2) { start = dateMigrate[0]; end = dateMigrate[1]; } } } catch { MessageBox.Show("cFMMI100010_Load: Error al conectar al lector.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } MigrateBackgroundWorker.ReportProgress(50); this.Invoke(new Action(() => { MessageLabel.Text = "Paso 2: Actualizando horarios de asistencia"; })); CheckInoursBLL.Migrate2(start, end); //if (this._type == 0) //{ //ProcessMigrate(Convert.ToInt32(ArgumentsList[4].ToString())); //CheckInoursBLL.Migrate2(_dividendo); //} //if (Convert.ToInt32(ArgumentsList[3].ToString()) == 1) //{ // if (ArgumentsList.Length > 3 && Convert.ToDateTime(ArgumentsList[4].ToString()) > Convert.ToDateTime(ArgumentsList[3].ToString())) // ProcessMigrate(Convert.ToDateTime(ArgumentsList[3]), Convert.ToDateTime(ArgumentsList[4]), Convert.ToInt32(ArgumentsList[5])); //} MigrateBackgroundWorker.ReportProgress(100); this.Invoke(new Action(() => { MessageLabel.Text = "Finalizando proceso"; })); } catch (Exception ex) { MessageBox.Show(string.Format("cFMMI100010_Load: {0}", ex.Message), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally{ this.Invoke(new Action(() => { this.Close(); })); } }