private void buttonImport_Click(object sender, EventArgs e) { if (dataGridView1.ColumnCount == 0) { MessageBoxUtil.Exclamation("还未获取数据!"); return; } var classPropDef = dataGridView1.Columns[0].Tag as MfClassPropDef; if (classPropDef == null) { MessageBoxUtil.Exclamation("还未进行属性映射!"); return; } var currentClass = _currentClass; if (classPropDef.ClassId != currentClass.Id) { MessageBoxUtil.Exclamation("您重新选择了文档类别,请重新进行属性映射!"); return; } if (_worker.IsBusy) { MessageBox.Show("导入进行中..."); return; } _worker.RunWorkerAsync(); }
private void buttonMapping_Click(object sender, EventArgs e) { if (comboBoxClasses.Items.Count == 0) { MessageBoxUtil.Exclamation("无法获取对象类别列表!"); return; } var pvs = _colNames.Select(c => new PropValue { Name = c }).ToList(); var mf = new MappingForm(_vault, _currentObjType, _vault.GetClassProps(_currentClass.Id), pvs); var selProps = _vault.GetMappedProps(_currentClass.Id); if (selProps != null) { mf.SetSelectedProps(selProps); } var dr = mf.ShowDialog(this); if (dr == DialogResult.OK) { _selProps = mf.GetSelectedProps(); for (var i = 0; i < dataGridView1.ColumnCount; i++) { dataGridView1.Columns[i].Tag = _selProps[i]; } _vault.AddOrUpdateClassPropSet(_currentObjType, _currentClass, _selProps); buttonImport.Enabled = true; } }
private void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { var log = TraceLog.GetLogger <MainForm>(); log.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, e.Error.Message + "\r\n" + e.Error.StackTrace); log.Close(); MessageBoxUtil.Error("导入出错:" + e.Error.Message); } else if (e.Cancelled) { MessageBoxUtil.Exclamation("导入取消!"); } else { var msg = "导入完成!"; if (_errFiles.Count > 0) { msg += "有对象未能被导入,请查看输出文件!"; } MessageBox.Show(msg); } if (_errFiles.Count > 0) { var tPath = Path.GetTempPath(); var tFile = Path.Combine(tPath, "已存在或创建失败列表" + DateTime.Now.ToString("-yyyy-MM-dd-HH-mm") + ".txt"); using (var sw = new StreamWriter(tFile, false, Encoding.Default)) { foreach (var tf in _errFiles) { var err = "第" + (tf.Item1 + 1) + "行数据" + "\t原因:" + tf.Item2; sw.WriteLine(err); } sw.Close(); } System.Diagnostics.Process.Start(tFile); } ResetProgressBar(); }