public WindowBase(Session session)
        {
            InitializeComponent();

            #region Initialize

            _session = session;

            WindowState = WindowState.Maximized;
            //ThemeManager.SetThemeName(this, "Office2007Blue");
            //ThemeManager.SetThemeName(this, "Office2007Black");
            //ThemeManager.SetThemeName(this, "LightGray");
            ThemeManager.SetThemeName(this, "DeepBlue");
            _session.GetDocument().DocProjected += DbDocProjected; // ???
            Closing += WindowBaseClosing;

            #endregion

            #region Initialize Background Worker

            _worker = new BackgroundWorker();
            _worker.DoWork += WorkerDoWork;
            _worker.RunWorkerCompleted += WorkerRunWorkerCompleted;
            _worker.ProgressChanged += WorkerProgressChanged;

            #endregion

            #region Initialize PivotGrid Control

            _pivotGridControl1.DataSource = _session.GetTableData(Table.TableBaseSource);
            _pivotGridControl1.HiddenFieldList += PivotGridControl1HiddenFieldList;

            List<Column> columns;

            try
            {
                columns = _session.GetTableColumns(Table.TableSecSource);
            }
            catch (AssortmentException ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            _pivotGridControl1.InitializeControl(columns, FormTypes.Base);

            _pivotGridControl1.Fields["LOC"].Area = FieldArea.ColumnArea;
            _pivotGridControl1.Fields["LOC"].Visible = true;
            _pivotGridControl1.Fields["ITEM"].Area = FieldArea.RowArea;
            _pivotGridControl1.Fields["ITEM"].Visible = true;
            _pivotGridControl1.Fields["MEASURE_STATUS_NEW"].Area = FieldArea.DataArea;
            _pivotGridControl1.Fields["MEASURE_STATUS_NEW"].Visible = true;

            _pivotGridControl1.ShowRowTotals = false;
            _pivotGridControl1.ShowColumnTotals = false;

            #endregion
        }
        public WindowSecondary(Session session, PivotGridControlModified control = null, bool isWhRestExistsCheckErrorDoc = false)
        {
            InitializeComponent();
            #region Initialize

            _session = session;
            _closeWithoutCheck = false;
            ThemeManager.SetThemeName(this, "DeepBlue");
            WindowState = WindowState.Maximized;
            _session.GetDocument().DocProjected += DbDocProjected; // ???
            Closing += WindowSecondaryClosing;
            _pivotGridControl2.CellClickAction += PivotGridControl2CellClickModified;
            Title = _session.GetTitle();

            #endregion

            #region Initialize PivotGrid Control

            _pivotGridControl2.DataSource = _session.GetTableData(Table.TableSecSource);
            _pivotGridControl2.HiddenFieldList += PivotGridControl2HiddenFieldList;
            _pivotGridControl2.FieldFilterChanged += _pivotGridControl2FieldFilterChanged;

            List<Column> columns;

            try
            {
                columns = _session.GetTableColumns(Table.TableSecSource);
            }
            catch (AssortmentException ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            _pivotGridControl2.InitializeControl(columns, FormTypes.Secondary);

            if (isWhRestExistsCheckErrorDoc)
            {
                
                _pivotGridControl2.Fields["LOC"].Area = FieldArea.ColumnArea;
                _pivotGridControl2.Fields["LOC"].Visible = true;
                _pivotGridControl2.Fields["ITEM"].Area = FieldArea.RowArea;
                _pivotGridControl2.Fields["ITEM"].Visible = true;
                _pivotGridControl2.Fields["MEASURE_STATUS_NEW"].Area = FieldArea.DataArea;
                _pivotGridControl2.Fields["MEASURE_STATUS_NEW"].Visible = true;
                _pivotGridControl2.SetFiltersForWhRestExistsCheckErrorDoc();
            }
            if (control == null)
                _pivotGridControl2.SetLayout(_session.GetDocument().PivotLayout);
            else
                _pivotGridControl2.CopyLayout(control);

            _pivotGridControl2.ShowRowTotals = false;
            _pivotGridControl2.ShowColumnTotals = false;

            #endregion
        }
        public WindowAssortmentCopy(Session session, SortedSet<IL> setIL)
        {
            InitializeComponent();

            _session = session;
            _rowGetter = new GridControlRowsGetter(gridControl1);
            _setIL = setIL;

            Loaded += WindowAssortmentCopyLoaded;
        }
        //private readonly PivotGridControlModified _pivotGridControl1;
        //private readonly Document _doc;

        //public WindowRegister(Object dbObject, Object pivotGridControl, Document doc)
        public WindowRegister(Session session)
        {
            InitializeComponent();

            Width = 880;
            Height = 720;

            _session = session;

            //_pivotGridControl1 = (PivotGridControlModified)pivotGridControl;
            //_db = (DBManager)dbObject;
            //_doc = doc;

            #region Initialize Background Worker

            _worker = new BackgroundWorker();
            _worker.DoWork += WorkerDoWork;
            _worker.RunWorkerCompleted += WorkerRunWorkerCompleted;
            _worker.ProgressChanged += WorkerProgressChanged;

            #endregion

            #region Initialize Control

            try
            {
                _session.FillRegister();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                throw;
            }

            gridControl1.DataSource = _session.GetTableData(Table.TableRegister);

            gridControl1.Columns.Add(new GridColumn { FieldName = "ID", Header = "Номер", AllowEditing = DefaultBoolean.False, AllowBestFit = DefaultBoolean.True, Visible = true });
            gridControl1.Columns.Add(new GridColumn { FieldName = "ID_USER", Header = "Пользователь", AllowEditing = DefaultBoolean.False, AllowBestFit = DefaultBoolean.True, CellTemplate = (DataTemplate)FindResource("RowTemplate") });
            gridControl1.Columns.Add(new GridColumn { FieldName = "CREATE_TIME", Header = "Дата создания", AllowEditing = DefaultBoolean.False, AllowBestFit = DefaultBoolean.True, CellTemplate = (DataTemplate)FindResource("RowTemplate") });
            gridControl1.Columns.Add(new GridColumn { FieldName = "ROW_COUNT", Header = "Количество строк", AllowEditing = DefaultBoolean.False, AllowBestFit = DefaultBoolean.True, CellTemplate = (DataTemplate)FindResource("RowTemplate") });
            gridControl1.Columns.Add(new GridColumn { FieldName = "STATUS", Header = "Статус", AllowEditing = DefaultBoolean.False, AllowBestFit = DefaultBoolean.True, CellTemplate = (DataTemplate)FindResource("RowTemplate") });
            gridControl1.Columns.Add(new GridColumn { FieldName = "DOC_TYPE", Header = "Тип", AllowEditing = DefaultBoolean.False, AllowBestFit = DefaultBoolean.True, CellTemplate = (DataTemplate)FindResource("RowTemplate") });
            gridControl1.Columns.Add(new GridColumn { FieldName = "LAST_UPDATE_TIME", Header = "Дата обновления", AllowEditing = DefaultBoolean.False, AllowBestFit = DefaultBoolean.True, CellTemplate = (DataTemplate)FindResource("RowTemplate") });
            gridControl1.Columns.Add(new GridColumn { FieldName = "DESCRIPTION", Header = "Комментарий", AllowEditing = DefaultBoolean.False, AllowBestFit = DefaultBoolean.True, CellTemplate = (DataTemplate)FindResource("RowTemplate") });

            gridControl1.SortBy(gridControl1.Columns["ID"]);

            gridControl1.MouseDoubleClick += GridControl1MouseDoubleClick;
            gridControl1.MouseRightButtonDown += GridControl1MouseRightButtonDown;

            //gridControl1.View.GroupRowTemplate = (DataTemplate)FindResource("RowTemplate");

            #endregion
        }
        public WindowCheck(Session session, CheckTypes checkType)
        {
            InitializeComponent();

            #region Initialize

            _session = session;
            _db = session.GetDbManager();
            _checkType = checkType;

            listBoxCheck.MouseDoubleClick += ListBoxCheckMouseDoubleClick;
            listBoxCheck.SelectionChanged += ListBoxCheckSelectionChanged;
            buttonCancel.Click += ButtonCancelClick;
            buttonSubmit.Click += ButtonSubmitClick;
            _session.GetDocument().DocProjected += DbDocProjected;

            _checkList = new List<Check>();

            try
            {
                _checkList.AddRange(_session.GetDocument().GetCheckList(_checkType));
            }
            catch (AssortmentDBException e)
            {
                MessageBox.Show(e.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            listBoxCheck.ItemsSource = _checkList;

            #endregion

            #region Initialize Background Worker

            _worker = new BackgroundWorker();
            _worker.DoWork += WorkerDoWork;
            _worker.RunWorkerCompleted += WorkerRunWorkerCompleted;
            _worker.ProgressChanged += WorkerProgressChanged;

            #endregion

            if (_checkList.Count == 0) return;

            _checkList[0].Status = CheckStatuses.Executing;
            _nCheck = 0;
            if (!_worker.IsBusy)
                _worker.RunWorkerAsync();
            else
            {
                MessageBox.Show("Проверки уже запущены", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void Authorization()
        {
            listLogin.IsEnabled = false;
            txtPassword.IsEnabled = false;
            btnSubmit.IsEnabled = false;
            labelStatus.Text = "Авторизация...";
            labelStatus.Visibility = Visibility.Visible;

            var data = imageLogo.Opacity == 1 ? OperationModes.Production : OperationModes.Test;

            _session = _testDb ?
                      new Session("ATRUSHINA", "atrushina", data, OperationModes.Test)
                    : new Session(_merchList[listLogin.SelectedValue.ToString()], txtPassword.Password, data, OperationModes.Production);


            if (!_worker.IsBusy)
            {
                _worker.RunWorkerAsync();
            }
            else
            {
                MessageBox.Show("Идёт формирование таблиц", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        public WindowRowOriented(Session session, PivotGridControl pivotGridControl1)
        {
            InitializeComponent();

            #region Initialize

            _session = session;
            _closeWithoutCheck = false;
            _db = _session.GetDbManager();
            _doc = _session.GetDocument();
            //ThemeManager.SetThemeName(this, "Office2007Silver");
            ThemeManager.SetThemeName(this, "DeepBlue");
            WindowState = WindowState.Maximized;
            Closing += WindowSecondaryClosing;
            _doc.DocProjected += DbDocProjected;
            var desc = _doc.Description;
            Title = "Документ: " + (desc ?? "не создан") + " (" + _doc.Id + ", " + DocTypes.Description(_doc.DocType) + ")";
            //Title = "Документ: " + (desc.Equals("") ? "не создан" : desc) + " (" + _doc.Id + ", " + (_doc.DocType == DocTypes.Operative ? "Оперативный" : "Обычный") + ")";

            try
            {
                _db.FillDataTableCustom(Table.TableSupplier.Name, Table.TableSupplier.SelectClause, Table.TableSupplier.KeyFields, false);
            }
            catch (AssortmentException ex)
            {
                MessageBox.Show(Table.TableSupplier + ": " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
/*
            if (_db.FillDataTableCustom(Table.TableSupplier.Name, Table.TableSupplier.SelectClause, Table.TableSupplier.KeyFields, false) == false)
            {
                MessageBox.Show("Ошибка при формировании источника: " + _db.Error, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
*/
            #endregion

            #region Initialize PivotGrid Control

            try
            {
                _db.FillDataTableCustom(Table.TableRowSource);
            }
            catch (AssortmentException ex)
            {
                MessageBox.Show(Table.TableRowSource + ": " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
/*
            if (_db.FillDataTableCustom(Table.TableRowSource) == false)
            {
                MessageBox.Show("Ошибка при формировании источника: " + _db.Error, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
*/
            _pivotGridControl2.DataSource = _db.DataTableGet(Table.TableRowSource.Name).DefaultView;
            _pivotGridControl2.HiddenFieldList += PivotGridControl2HiddenFieldList;

            var dimensions = _db.GetTableDefinition(Table.TableRowSource.DBName);

            if (dimensions == null)
            {
                MessageBox.Show("Список измерений для данной таблицы пуст", "Ошибка", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
            else
            {
                _pivotGridControl2.InitializeControl(dimensions, _db);
            }

            _pivotGridControl2.InitializeLayout(pivotGridControl1);

            _pivotGridControl2.ShowRowTotals = false;
            _pivotGridControl2.ShowColumnTotals = false;
            _pivotGridControl2.ShowColumnGrandTotals = false;
            _pivotGridControl2.ShowRowGrandTotals = false;

            _pivotGridControl2.CellClickInputData += PivotGridControl2CellClickInputData;

            _pivotGridControl2.BestFit();

            #endregion
        }
        public WindowCheckError(Session session, CheckTypes checkType, Check check)
        {
            WhRestExistsCheckNewDoc += WhRestExistsCheckNewDocHandler;
            _session = session;
            _check = check;
            InitializeComponent();
            this.DataContext = check;
            Title = check.Desc;
            if (_check.ProcedureName == "global_wh_rest_exists")
            {
                var menuItemSaveDoc = new MenuItem{Header="Создать документ"};
                menuItemSaveDoc.Click += menuItemSaveDoc_Click;
                menuMain.Items.Add(menuItemSaveDoc);
            }

            Width = 750;
            Height = 650;

            _db = session.GetDbManager();

            #region Initialize Control

            //gridControl1.AutoPopulateColumns = true;
            gridControl1.DataSource = _db.DataTableGet(check.ProcedureName).DefaultView;

            if (check.TableName != null)
            {
                List<Column> columns;

                try
                {

                    columns =
                        _db.GetTableDefinition(check.TableName);
                    /*
                                        columns =
                                            _db.GetTableDefinition(check.TableName ??
                                                                   (checkType == CheckTypes.Local
                                                                        ? "y_assortment_doc_detail"
                                                                        : "y_assortment_united_sec_gtt"));
                    */

                }
                catch (AssortmentException e)
                {
                    MessageBox.Show(e.Message, "Ошибка детализации", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                //var src = new DataTable("SRC");

                foreach (var column in columns)
                {
                    if (column.Name == "PARAMS")
                    {
                        var table = _db.DataTableGet(check.ProcedureName);
                        var maxColumn = 0;
                        /*
                                                foreach (DataColumn col in table.Columns)
                                                {
                                                    if (col.ColumnName != "PARAMS" && col.ColumnName.Contains("PARAM"))table.Columns.Remove(col);
                                                }
                        */


                        for (int i = 1; i < 30; i++)
                        {
                            try
                            {
                                table.Columns.Remove("PARAM" + i);
                            }
                            catch { }
                        }

                        foreach (DataRow row in table.Rows)
                        {
                            var rowParams = row["PARAMS"].ToString();
                            var qty = rowParams.Split(';').Length;
                            if (qty > maxColumn) maxColumn = qty;
                        }
                        for (int i = 1; i <= maxColumn; i++)
                        {
                            table.Columns.Add("PARAM" + i);

                            gridControl1.Columns.Add(new GridColumn
                            {
                                FieldName = "PARAM" + i,
                                Header = "Параметр " + i,
                                AllowEditing = DefaultBoolean.False
                            });
                        }
                        foreach (DataRow row in table.Rows)
                        {
                            var rowParams = row["PARAMS"].ToString();
                            var rowParamsArray = rowParams.Split(';');
                            for (int i = 1; i <= rowParamsArray.Length; i++)
                            {
                                row["PARAM" + i] = rowParamsArray[i - 1];
                            }
                        }
                    }
                    else
                    {
                        //src.Columns.Add(new DataColumn(column.Name));
                        gridControl1.Columns.Add(new GridColumn
                                                     {
                                                         FieldName = column.Name,
                                                         Header = column.Desc,
                                                         AllowEditing = DefaultBoolean.False
                                                     });
                    }
                }
            }
            else
            {

                switch (checkType)
                {
                    case CheckTypes.Local:
                        {
                            gridControl1.Columns.Add(new GridColumn { FieldName = "ITEM", Header = "Товар", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEM_DESC", Header = "Наименование", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "LOC", Header = "Магазин", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_LOC_DESC", Header = "Название", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "ACTION", Header = "Действие", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "SUPPLIER", Header = "Поставщик", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEMLOC_SUPPLIER_DESC", Header = "Название", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "SUPPLIER_NEW", Header = "Поставщик (новый)", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEMLOC_SUPPLIER_DESC_NEW", Header = "Название", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "ORDERPLACE", Header = "Место заказа", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "ORDERPLACE_NEW", Header = "Место заказа (новое)", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "SOURCEMETHOD", Header = "Тип поставки", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "SOURCEMETHOD_NEW", Header = "Тип поставки (новый)", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "SOURCEWH", Header = "Склад поставки", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "SOURCEWH_NEW", Header = "Склад поставки (новый)", AllowEditing = DefaultBoolean.False });
                            break;
                        }
                    case CheckTypes.Global:
                        {
                            gridControl1.Columns.Add(new GridColumn { FieldName = "ITEM", Header = "Товар", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEM_DESC", Header = "Наименование", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "LOC", Header = "Магазин", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_LOC_DESC", Header = "Название", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEMLOC_SUPPLIER_NEW", Header = "Поставщик", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEMLOC_SUPPLIER_DESC_NEW", Header = "Имя", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEMLOC_SOURCEMETHOD_NEW", Header = "Способ поставки", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEMLOC_SOURCEWH_NEW", Header = "Склад поставки", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "DIM_ITEMLOC_ORDERPLACE_NEW", Header = "Место заказа", AllowEditing = DefaultBoolean.False });
                            gridControl1.Columns.Add(new GridColumn { FieldName = "ACTION", Header = "Действие", AllowEditing = DefaultBoolean.False });

                            break;
                        }
                }

            }

            #endregion
        }