/// <summary> /// 导入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImport_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbFileSavePath.Text)) { MessageBox.Show("请选择保存文件的路径"); return; } if (gvData.Rows.Count == 0) { MessageBox.Show("请先选择数据源文件"); } else { toolStripProgressBar1.ProgressBar.Visible = true; toolStripProgressBar1.ProgressBar.Minimum = 0; toolStripProgressBar1.ProgressBar.Maximum = gvData.Rows.Count; int i = 0; int okCount = 0; int errCount = 0; foreach (DataGridViewRow dr in gvData.Rows) { ImportDataInfo dInfo = DataRowToDataInfo(dr); if (dInfo != null) { try { ImportXlsData import = new ImportXlsData(dInfo); import.dataRowImportOk += new DataRowImportComplete(import_dataRowImportOk); import.CurrentRow = dr; import.SavePath = tbFileSavePath.Text + "\\"; import.Import(); okCount++; } catch(Exception ex) { errCount++; } toolStripStatusLabel1.Text = string.Format("成功导入{0}个,失败{1}个",okCount,errCount); } i++; toolStripProgressBar1.ProgressBar.Value = i; } toolStripProgressBar1.ProgressBar.Visible = false; toolStripStatusLabel1.Text = toolStripStatusLabel1.Text.Insert(0, "完成导入,"); btnImport.Enabled = false; } }
/// <summary> /// 导入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImport_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbFileSavePath.Text)) { MessageBox.Show("请选择保存文件的路径"); return; } if (gvData.Rows.Count == 0) { MessageBox.Show("请先选择数据源文件"); } else { toolStripProgressBar1.ProgressBar.Visible = true; toolStripProgressBar1.ProgressBar.Minimum = 0; toolStripProgressBar1.ProgressBar.Maximum = gvData.Rows.Count; int i = 0; int okCount = 0; int errCount = 0; foreach (DataGridViewRow dr in gvData.Rows) { ImportDataInfo dInfo = DataRowToDataInfo(dr); if (dInfo != null) { try { ImportXlsData import = new ImportXlsData(dInfo); import.dataRowImportOk += new DataRowImportComplete(import_dataRowImportOk); import.CurrentRow = dr; import.SavePath = tbFileSavePath.Text + "\\"; import.Import(); okCount++; } catch (Exception ex) { errCount++; } toolStripStatusLabel1.Text = string.Format("成功导入{0}个,失败{1}个", okCount, errCount); } i++; toolStripProgressBar1.ProgressBar.Value = i; } toolStripProgressBar1.ProgressBar.Visible = false; toolStripStatusLabel1.Text = toolStripStatusLabel1.Text.Insert(0, "完成导入,"); btnImport.Enabled = false; } }