public void WriteToDataGrid(DataTable dataTable, string prefab, ContentControl tab)
        {
            int sheetIndex = MasterTabControl.Items.IndexOf(tab);

            EditedCells.Insert(sheetIndex, new Dictionary <int, List <int> >());

            SfDataGrid dataGrid = UiHelper.DefaultDataGridTemplate(dataTable, sheetIndex, this, prefab);

            MasterDataGrids.Insert(sheetIndex, dataGrid);
            tab.Content = dataGrid;
        }
        public void ResetChanges()
        {
            foreach (Dictionary <int, List <int> > v in EditedCells)
            {
                EditedCells[EditedCells.IndexOf(v)].Clear();
            }

            //foreach (var grid in MasterDataGrids)
            //	try
            //	{
            //		grid.View.Refresh();
            //	}
            //	catch
            //	{
            //	}
        }
        public void InitializeOrRefreshEverything(int tabIndex)
        {
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

            CurrentVisualStyle      = Settings.Default.Theme;
            App.ThisIsNowConcurrent = false;
            App.ThisMadeLastChange  = false;

            ResetGroupsBox.IsChecked     = false;
            DeleteModeCheckBox.IsChecked = false;
            SearchField.Clear();
            SearchField.AutoCompleteSource = SearchBoxAutoCompleteItems;

            MasterTabControl.Items.Clear();
            var dataSets = App.MainSet(this);

            MasterDataSet = dataSets;
            MasterDataGrids.Clear();
            EditedCells.Clear();
            ProgressGrid.Visibility = Visibility.Hidden;

            using (var conn =
                       new SqlConnection(App.ConnectionString))
            {
                conn.Open();

                foreach (string s in App.GetTableNames(conn))
                {
                    var tab = new TabItemExt
                    {
                        Header = s
                    };
                    MasterTabControl.Items.Add(tab);
                }

                int i = 0;
                foreach (DataTable dt in MasterDataSet.Tables)
                {
                    WriteToDataGrid(dt, App.GetPrefabOfDataTable(conn, dt), (TabItem)MasterTabControl.Items[i]);
                    i++;
                }

                conn.Close();
            }

            if (MasterTabControl.Items.Count > 0 && tabIndex < MasterTabControl.Items.Count)
            {
                MasterTabControl.SelectedIndex = tabIndex;
            }
            else if (tabIndex >= MasterTabControl.Items.Count)
            {
                MasterTabControl.SelectedIndex = MasterTabControl.Items.Count - 1;
            }
            else
            {
                MasterTabControl.SelectedIndex = 0;
            }

            RefreshRevertTables();

            if (MasterTabControl.Items.Count < 1)
            {
                SearchField.IsEnabled        = false;
                ResetSorts.IsEnabled         = false;
                ResetGroupsBox.IsEnabled     = false;
                DeleteModeCheckBox.IsEnabled = false;
                //RevertChanges.IsEnabled = false;
                NewRowButton.IsEnabled           = false;
                RefreshAll.IsEnabled             = false;
                BarcodeTextBox.IsEnabled         = false;
                BarcodeInventoryCommit.IsEnabled = false;
            }
            else
            {
                SearchField.IsEnabled            = true;
                ResetSorts.IsEnabled             = true;
                ResetSorts.IsChecked             = true;
                ResetGroupsBox.IsEnabled         = true;
                DeleteModeCheckBox.IsEnabled     = true;
                RefreshAll.IsEnabled             = true;
                BarcodeTextBox.IsEnabled         = true;
                BarcodeInventoryCommit.IsEnabled = true;
                NewRowButton.IsEnabled           = true;
            }

            Recycled.FillRecycledDataTable();
            System.Windows.Forms.Cursor.Current = Cursors.Default;
        }