private void SelectExcels(bool Selected) { if (!NotifySelectItemEvent_) { return; } try { NotifySelectItemEvent_ = false; for (var Index = 0; Index < CheckedListBoxExcels.Items.Count; ++Index) { CheckedListBoxExcels.SetItemChecked(Index, Selected); } if (Selected) { LabelExcelSelectCount.Text = $"选中:{CheckedListBoxExcels.Items.Count}"; } else { LabelExcelSelectCount.Text = "选中:0"; } } catch (Exception Ex) { Logger.Warning(Ex.Message); } finally { NotifySelectItemEvent_ = true; } }
private void ExportExcels() { try { var ExportCount = 0; var ExportPath = PathHelper.UnifyPath($"{CacheHelper.GetWorkPath()}Export/"); PathHelper.CreateDirectory(ExportPath); if (string.IsNullOrWhiteSpace(ExportPlugin_)) { MessageBox.Show("请选择导出格式"); return; } var FileList = new List <string>(); foreach (var ExcelPath in ExcelFiles_) { var FileName = PathHelper.GetFileNameWithoutExt(ExcelPath); for (var Index = 0; Index < CheckedListBoxExcels.Items.Count; ++Index) { if (CheckedListBoxExcels.GetItemText(CheckedListBoxExcels.Items[Index]) == FileName && CheckedListBoxExcels.GetItemChecked(Index)) { FileList.Add(ExcelPath); } } } ProgressBarMain.Value = 0; ProgressBarMain.Maximum = FileList.Count; ExportCount = ExcelExport.ExportDirectory(ExportPlugin_, FileList.ToArray(), CheckBoxExportAllSheet.Checked, ExportPath, (Cur, Max) => { ProgressBarMain.Value = Cur; Application.DoEvents(); }); if (CheckBoxAutoOpen.Checked && ExportCount != 0) { Process.Start(ExportPath); } RefreshExcels(); Logger.Warning($"总共:{FileList.Count}个文件,导出:{ExportCount}个文件"); if (ExportCount > 0) { MessageBox.Show($"总共:{FileList.Count}个文件,导出:{ExportCount}个文件", "DataExportTool", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception Ex) { Logger.Error(Ex.Message); } }
private void UpdateCheckedListBoxExcels(int ExcelIndex, bool IsChecked) { if (!NotifySelectAllItemEvent_) { return; } try { NotifySelectAllItemEvent_ = false; var Count = 0; for (var Index = 0; Index < CheckedListBoxExcels.Items.Count; ++Index) { if (ExcelIndex == Index) // ItemCheck事件在响应的时候,Item的值还未改变,所以用传入的参数判断 { if (IsChecked) { Count++; } } else if (CheckedListBoxExcels.GetItemChecked(Index)) { Count++; } } if (Count == 0) { CheckBoxSelectAll.CheckState = CheckState.Unchecked; } else if (Count == CheckedListBoxExcels.Items.Count) { CheckBoxSelectAll.CheckState = CheckState.Checked; } else { CheckBoxSelectAll.CheckState = CheckState.Indeterminate; } LabelExcelSelectCount.Text = $"选中:{Count}"; } catch (Exception Ex) { Logger.Warning(Ex.Message); } finally { NotifySelectAllItemEvent_ = true; } }