private void DoPaymentImp(string file, DataTable relations) { if (string.IsNullOrEmpty(selectedSheet)) { Invoke(new Action(delegate() { MessageBox.Show("请选择sheet!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); worker.Abort(); worker.Join(); this.btnImport.Enabled = true; this.btnCancel.Enabled = !this.btnImport.Enabled; return; })); } if (relations.Rows.Count == 0) { Invoke(new Action(delegate() { MessageBox.Show("学生基本信息有误", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); worker.Abort(); worker.Join(); this.btnImport.Enabled = true; this.btnCancel.Enabled = !this.btnImport.Enabled; return; })); } extReader.SheetName = selectedSheet; extReader.KeepConnectionOpen = true; DataTable dt = extReader.GetTable(selectedSheet); extReader.Close(); Global.Logger.Info("load excel data finished with rows=" + dt.Rows.Count); // remove empty rows DataRow[] rows = dt.Select(" XH IS NULL "); foreach (DataRow r in rows) { r.Delete(); } dt.AcceptChanges(); Global.Logger.Info("after remove null entries, rows=" + dt.Rows.Count); int cnt = dt.Rows.Count; if (cnt <= 0) { Invoke(new Action(delegate() { MessageBox.Show("没有可以导入的原始数据", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); })); return; } //show initial UI & analysis data Invoke(new Action(delegate() { this.pBar.Value = 0; this.pBar.Maximum = dt.Rows.Count; this.lblStatus.Text = "分析数据,可进一步处理的条数为:" + cnt.ToString(); rBox.Clear(); })); DataTransfer transfer = new DataTransfer(dt, dtRelation); transfer.EntryCompleted += delegate(object sender, EntryCompletedEventArgs e) { string msg = string.Format("{0}: {1}", e.EntryKey, e.Message); Invoke(new Action(delegate() { this.pBar.Value = this.pBar.Value < cnt ? this.pBar.Value + 1 : cnt; lblStatus.Text = msg; if (!e.CompletedFlag) AppendTextWithGivenColor(rBox, Color.Red, msg + System.Environment.NewLine); })); }; transfer.AllEntryCompleted += delegate(object sender, AllEntryCompletedEventArgs e) { Invoke(new Action(delegate() { this.pBar.Value = this.pBar.Maximum; this.btnCancel.Enabled = false; this.btnImport.Enabled = !this.btnCancel.Enabled; Global.Logger.Info(e.Summary); //save error name list string errorFile = Path.Combine(Application.StartupPath,Path.GetFileNameWithoutExtension(this.txtFile.Text)+DateTime.Now.ToString("yyyyMMddhhmmss") + ".err"); File.WriteAllText(errorFile,e.Summary); FrmSummary frm = new FrmSummary(e.Summary); frm.ShowDialog(); })); }; Global.Logger.Info("DoTransfer starts..."); transfer.DoTransfer(); }
private void DoPaymentImp(string file, DataTable relations) { if (string.IsNullOrEmpty(selectedSheet)) { Invoke(new Action(delegate() { MessageBox.Show("请选择sheet!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); worker.Abort(); worker.Join(); this.btnImport.Enabled = true; this.btnCancel.Enabled = !this.btnImport.Enabled; return; })); } if (relations.Rows.Count == 0) { Invoke(new Action(delegate() { MessageBox.Show("学生基本信息有误", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); worker.Abort(); worker.Join(); this.btnImport.Enabled = true; this.btnCancel.Enabled = !this.btnImport.Enabled; return; })); } extReader.SheetName = selectedSheet; extReader.KeepConnectionOpen = true; DataTable dt = extReader.GetTable(selectedSheet); extReader.Close(); Global.Logger.Info("load excel data finished with rows=" + dt.Rows.Count); // remove empty rows DataRow[] rows = dt.Select(" XH IS NULL "); foreach (DataRow r in rows) { r.Delete(); } dt.AcceptChanges(); Global.Logger.Info("after remove null entries, rows=" + dt.Rows.Count); int cnt = dt.Rows.Count; if (cnt <= 0) { Invoke(new Action(delegate() { MessageBox.Show("没有可以导入的原始数据", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); })); return; } //show initial UI & analysis data Invoke(new Action(delegate() { this.pBar.Value = 0; this.pBar.Maximum = dt.Rows.Count; this.lblStatus.Text = "分析数据,可进一步处理的条数为:" + cnt.ToString(); rBox.Clear(); })); DataTransfer transfer = new DataTransfer(dt, dtRelation); transfer.EntryCompleted += delegate(object sender, EntryCompletedEventArgs e) { string msg = string.Format("{0}: {1}", e.EntryKey, e.Message); Invoke(new Action(delegate() { this.pBar.Value = this.pBar.Value < cnt ? this.pBar.Value + 1 : cnt; lblStatus.Text = msg; if (!e.CompletedFlag) { AppendTextWithGivenColor(rBox, Color.Red, msg + System.Environment.NewLine); } })); }; transfer.AllEntryCompleted += delegate(object sender, AllEntryCompletedEventArgs e) { Invoke(new Action(delegate() { this.pBar.Value = this.pBar.Maximum; this.btnCancel.Enabled = false; this.btnImport.Enabled = !this.btnCancel.Enabled; Global.Logger.Info(e.Summary); //save error name list string errorFile = Path.Combine(Application.StartupPath, Path.GetFileNameWithoutExtension(this.txtFile.Text) + DateTime.Now.ToString("yyyyMMddhhmmss") + ".err"); File.WriteAllText(errorFile, e.Summary); FrmSummary frm = new FrmSummary(e.Summary); frm.ShowDialog(); })); }; Global.Logger.Info("DoTransfer starts..."); transfer.DoTransfer(); }