/// <summary> /// perform to export datagridview records into a .xlsx file /// </summary> public override void ToExport() { if (dgv.Rows.Count > 0) { var withexcel = new withExcel(); withexcel.ExportData(dgv, statusinfolabel, typeof(T).Name); foreach (DataGridViewRow row in dgv.Rows) { string value = ""; foreach (DataGridViewCell cell in row.Cells) { value += $"{dgv.Columns[cell.ColumnIndex].HeaderText}: {cell.Value}; "; } WriteLog(CreateLog("Export", value)); } } else { withInfo.DisplayStatus("无记录!", statusinfolabel, false); } }
/// <summary> /// perform to import records from a .xls file /// </summary> public override void ToImport() { List <T> Importing = null; int originalcount = 0; int importedcount = 0; Importing = new withExcel().ImportData <T>(); originalcount = Importing == null ? 0 : Importing.Count; try { if (Importing != null) { foreach (var item in Importing) { if (!IsExist(item, true)) { if (tingmodelinstance.Add(item) == ActionResult.Success) { importedcount++; WriteLog(CreateLog("Import", item.DisplayValue)); } ; } } } } catch (Exception e) { MessageBox.Show(e.Message); } if (originalcount != 0) { MessageBox.Show($"申请导入【{originalcount}】条, \n实际导入【{importedcount}】条。"); UpdateList(); } }