Ejemplo n.º 1
0
        private void RefreshBySheet(bool isStartup, bool edit = false)
        {
            SrcDataGrid.Model = new DiffGridModel(SheetDiff, DiffType.Source);
            DstDataGrid.Model = new DiffGridModel(SheetDiff, DiffType.Dest);

            var fileSettings   = FindFileSettings(isStartup);
            var srcFileSetting = fileSettings.Item1;
            var dstFileSetting = fileSettings.Item2;

            var args1 = new DiffViewEventArgs <FastGridControl>(null, container, TargetType.First);

            if (!edit)
            {
                var args = new DiffViewEventArgs <FastGridControl>(SrcDataGrid, container);
                DataGridEventDispatcher.Instance.DispatchFileSettingUpdateEvent(args, srcFileSetting);

                args = new DiffViewEventArgs <FastGridControl>(DstDataGrid, container);
                DataGridEventDispatcher.Instance.DispatchFileSettingUpdateEvent(args, dstFileSetting);


                DataGridEventDispatcher.Instance.DispatchDisplayFormatChangeEvent(args1, ShowOnlyDiffRadioButton.IsChecked.Value);
                DataGridEventDispatcher.Instance.DispatchPostExecuteDiffEvent(args1);

                var summary = SheetDiff.CreateSummary();
                GetViewModel().UpdateDiffSummary(summary);

                if (App.Instance.Setting.NotifyEqual && !summary.HasDiff)
                {
                    MessageBox.Show(Properties.Resources.Message_NoDiff);
                }
            }


            if (!App.Instance.KeepFileHistory)
            {
                App.Instance.UpdateRecentFiles(SrcPathTextBox.Text, DstPathTextBox.Text);
            }

            if (App.Instance.Setting.FocusFirstDiff)
            {
                MoveNextModifiedCell();
            }
        }
Ejemplo n.º 2
0
        private void ExecuteDiff(bool isStartup = false)
        {
            if (!File.Exists(SrcPathTextBox.Text) || !File.Exists(DstPathTextBox.Text))
            {
                return;
            }

            SrcDataGrid.ScrollIntoView(FastGridCellAddress.Empty);
            DstDataGrid.ScrollIntoView(FastGridCellAddress.Empty);

            SrcDataGrid.FirstVisibleColumnScrollIndex = 0;
            SrcDataGrid.FirstVisibleRowScrollIndex    = 0;
            DstDataGrid.FirstVisibleColumnScrollIndex = 0;
            DstDataGrid.FirstVisibleRowScrollIndex    = 0;

            SrcDataGrid.InitializeComponent();
            DstDataGrid.InitializeComponent();

            SrcDataGrid.SetMaxColumnSize(App.Instance.Setting.CellWidth);
            DstDataGrid.SetMaxColumnSize(App.Instance.Setting.CellWidth);
            SrcDataGrid.SetMinColumnSize(App.Instance.Setting.CellWidth);
            DstDataGrid.SetMinColumnSize(App.Instance.Setting.CellWidth);

            var           srcPath = SrcPathTextBox.Text;
            var           dstPath = DstPathTextBox.Text;
            ExcelWorkbook wb1     = null;
            ExcelWorkbook wb2     = null;

            ProgressWindow.DoWorkWithModal(progress =>
            {
                progress.Report(Properties.Resources.Msg_ReadingFiles);

                var config = CreateReadConfig();
                wb1        = ExcelWorkbook.Create(srcPath, config);
                wb2        = ExcelWorkbook.Create(dstPath, config);
            });

            FileSetting srcSetting = null;
            FileSetting dstSetting = null;

            if (!IgnoreFileSettingCheckbox.IsChecked.Value)
            {
                srcSetting =
                    FindFilseSetting(Path.GetFileName(SrcPathTextBox.Text), SrcSheetCombobox.SelectedIndex, SrcSheetCombobox.SelectedItem.ToString(), isStartup);

                dstSetting =
                    FindFilseSetting(Path.GetFileName(DstPathTextBox.Text), DstSheetCombobox.SelectedIndex, DstSheetCombobox.SelectedItem.ToString(), isStartup);

                diffConfig = CreateDiffConfig(srcSetting, dstSetting, isStartup);
            }
            else
            {
                diffConfig = new ExcelSheetDiffConfig();

                diffConfig.SrcSheetIndex = Math.Max(SrcSheetCombobox.SelectedIndex, 0);
                diffConfig.DstSheetIndex = Math.Max(DstSheetCombobox.SelectedIndex, 0);
            }

            SrcSheetCombobox.SelectedIndex = diffConfig.SrcSheetIndex;
            DstSheetCombobox.SelectedIndex = diffConfig.DstSheetIndex;

            var sheet1 = wb1.Sheets[SrcSheetCombobox.SelectedItem.ToString()];
            var sheet2 = wb2.Sheets[DstSheetCombobox.SelectedItem.ToString()];

            if (sheet1.Rows.Count > 10000 || sheet2.Rows.Count > 10000)
            {
                MessageBox.Show(Properties.Resources.Msg_WarnSize);
            }

            ExcelSheetDiff diff = null;

            ProgressWindow.DoWorkWithModal(progress =>
            {
                progress.Report(Properties.Resources.Msg_ExtractingDiff);
                diff = ExcelSheet.Diff(sheet1, sheet2, diffConfig);
            });

            var modelConfig = new DiffGridModelConfig();
            var srcModel    = new DiffGridModel(DiffType.Source, diff, modelConfig);
            var dstModel    = new DiffGridModel(DiffType.Dest, diff, modelConfig);

            (DataContext as ViewModels.DiffViewModel).UpdateDiffSummary(diff.CreateSummary());

            SrcDataGrid.AlternatingColors = App.Instance.Setting.AlternatingColors;
            DstDataGrid.AlternatingColors = App.Instance.Setting.AlternatingColors;
            SrcDataGrid.CellFontName      = App.Instance.Setting.FontName;
            DstDataGrid.CellFontName      = App.Instance.Setting.FontName;

            SrcDataGrid.Model = srcModel;
            DstDataGrid.Model = dstModel;

            if (ShowOnlyDiffRadioButton.IsChecked.Value)
            {
                srcModel.HideEqualRows();
                srcModel.HideEqualRows();
            }

            if (srcSetting != null)
            {
                srcModel.SetColumnHeader(srcSetting.ColumnHeaderIndex);
                if (string.IsNullOrEmpty(srcSetting.RowHeaderName))
                {
                    srcModel.SetRowHeader(srcSetting.RowHeaderIndex);
                }
                else
                {
                    srcModel.SetRowHeader(srcSetting.RowHeaderName);
                }
                SrcDataGrid.MaxRowHeaderWidth = srcSetting.MaxRowHeaderWidth;
            }

            if (dstSetting != null)
            {
                dstModel.SetColumnHeader(dstSetting.ColumnHeaderIndex);
                if (string.IsNullOrEmpty(dstSetting.RowHeaderName))
                {
                    dstModel.SetRowHeader(dstSetting.RowHeaderIndex);
                }
                else
                {
                    dstModel.SetRowHeader(dstSetting.RowHeaderName);
                }
                DstDataGrid.MaxRowHeaderWidth = dstSetting.MaxRowHeaderWidth;
            }

            DataGridEventDispatcher.DispatchModelUpdateEvent(SrcDataGrid, container);
            DataGridEventDispatcher.DispatchModelUpdateEvent(DstDataGrid, container);

            if (!App.Instance.KeepFileHistory)
            {
                App.Instance.UpdateRecentFiles(SrcPathTextBox.Text, DstPathTextBox.Text);
            }
        }