private void PreLoadData()
 {
     toolStripProgressBar.Maximum = 13;
     DepartmentsDataModel.GetInstance(toolStripProgressBar, 1);
     DevicesDataModel.GetInstance(toolStripProgressBar, 1);
     SoftwareDataModel.GetInstance(toolStripProgressBar, 1);
     SoftVersionsDataModel.GetInstance(toolStripProgressBar, 1);
     SoftInstallationsDataModel.GetInstance(toolStripProgressBar, 1);
     SoftInstallatorsDataModel.GetInstance(toolStripProgressBar, 1);
     SoftLicDocTypesDataModel.GetInstance(toolStripProgressBar, 1);
     SoftLicensesDataModel.GetInstance(toolStripProgressBar, 1);
     SoftLicKeysDataModel.GetInstance(toolStripProgressBar, 1);
     SoftLicTypesDataModel.GetInstance(toolStripProgressBar, 1);
     SoftMakersDataModel.GetInstance(toolStripProgressBar, 1);
     SoftSuppliersDataModel.GetInstance(toolStripProgressBar, 1);
     SoftTypesDataModel.GetInstance(toolStripProgressBar, 1);
 }
        public override void LoadData()
        {
            dataGridView.AutoGenerateColumns = false;
            DockAreas      = WeifenLuo.WinFormsUI.Docking.DockAreas.Document;
            _softSuppliers = SoftSuppliersDataModel.GetInstance();

            //Ожидаем дозагрузки данных, если это необходимо
            _softSuppliers.Select();

            _vSoftSuppliers = new BindingSource
            {
                DataMember = "SoftSuppliers",
                DataSource = DataSetManager.DataSet
            };

            //Инициируем колонки snapshot-модели
            for (var i = 0; i < _softSuppliers.Select().Columns.Count; i++)
            {
                _snapshotSoftSuppliers.Columns.Add(new DataColumn(
                                                       _softSuppliers.Select().Columns[i].ColumnName, _softSuppliers.Select().Columns[i].DataType));
            }
            //Загружаем данные snapshot-модели из original-view
            for (var i = 0; i < _vSoftSuppliers.Count; i++)
            {
                _snapshotSoftSuppliers.Rows.Add(DataRowViewToArray((DataRowView)_vSoftSuppliers[i]));
            }
            _vSnapshotSoftSuppliers = new BindingSource {
                DataSource = _snapshotSoftSuppliers
            };
            _vSnapshotSoftSuppliers.CurrentItemChanged += v_snapshotSuppliers_CurrentItemChanged;

            dataGridView.DataSource         = _vSnapshotSoftSuppliers;
            idSoftSupplier.DataPropertyName = "ID Supplier";
            softSupplier.DataPropertyName   = "Supplier";

            dataGridView.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

            dataGridView.CellValidated += dataGridView_CellValidated;
            //События изменения данных для проверки соответствия реальным данным в модели
            dataGridView.CellValueChanged += dataGridView_CellValueChanged;
            //Синхронизация данных исходные->текущие
            _softSuppliers.Select().RowChanged  += SoftSuppliersViewport_RowChanged;
            _softSuppliers.Select().RowDeleting += SoftSuppliersViewport_RowDeleting;
            _softSuppliers.Select().RowDeleted  += SoftSuppliersViewport_RowDeleted;
        }
Exemple #3
0
        public SearchLicensesForm()
        {
            InitializeComponent();
            var softMakers      = SoftMakersDataModel.GetInstance();
            var softTypes       = SoftTypesDataModel.GetInstance();
            var softSuppliers   = SoftSuppliersDataModel.GetInstance();
            var softLicTypes    = SoftLicTypesDataModel.GetInstance();
            var softLicDocTypes = SoftLicDocTypesDataModel.GetInstance();
            var departments     = DepartmentsDataModel.GetInstance();

            // Ожидаем дозагрузки, если это необходимо
            softMakers.Select();
            softTypes.Select();
            softSuppliers.Select();
            softLicTypes.Select();
            softLicDocTypes.Select();
            departments.Select();

            var vSoftMakers = new BindingSource
            {
                DataMember = "SoftMakers",
                DataSource = DataSetManager.DataSet
            };

            var vSoftTypes = new BindingSource
            {
                DataMember = "SoftTypes",
                DataSource = DataSetManager.DataSet
            };

            var vSoftSuppliers = new BindingSource
            {
                DataMember = "SoftSuppliers",
                DataSource = DataSetManager.DataSet
            };

            var vSoftLicTypes = new BindingSource
            {
                DataMember = "SoftLicTypes",
                DataSource = DataSetManager.DataSet
            };

            var vSoftLicDocTypes = new BindingSource
            {
                DataMember = "SoftLicDocTypes",
                DataSource = DataSetManager.DataSet
            };

            _vDepartments = new BindingSource {
                DataSource = departments.SelectVisibleDepartments()
            };

            comboBoxDepartmentID.DataSource    = _vDepartments;
            comboBoxDepartmentID.ValueMember   = "ID Department";
            comboBoxDepartmentID.DisplayMember = "Department";

            comboBoxSoftwareMaker.DataSource    = vSoftMakers;
            comboBoxSoftwareMaker.ValueMember   = "ID SoftMaker";
            comboBoxSoftwareMaker.DisplayMember = "SoftMaker";

            comboBoxSupplierID.DataSource    = vSoftSuppliers;
            comboBoxSupplierID.ValueMember   = "ID Supplier";
            comboBoxSupplierID.DisplayMember = "Supplier";

            comboBoxSoftwareType.DataSource    = vSoftTypes;
            comboBoxSoftwareType.ValueMember   = "ID SoftType";
            comboBoxSoftwareType.DisplayMember = "SoftType";

            comboBoxLicType.DataSource    = vSoftLicTypes;
            comboBoxLicType.ValueMember   = "ID LicType";
            comboBoxLicType.DisplayMember = "LicType";

            comboBoxLicDocType.DataSource    = vSoftLicDocTypes;
            comboBoxLicDocType.ValueMember   = "ID DocType";
            comboBoxLicDocType.DisplayMember = "DocType";

            comboBoxOpBuyLicenseDate.SelectedIndex    = 0;
            comboBoxOpExpireLicenseDate.SelectedIndex = 0;

            foreach (Control control in Controls)
            {
                control.KeyDown += (sender, e) =>
                {
                    var comboBox = sender as ComboBox;
                    if (comboBox != null && comboBox.DroppedDown)
                    {
                        return;
                    }
                    if (e.KeyCode == Keys.Enter)
                    {
                        vButtonSearch_Click(sender, e);
                    }
                    else
                    if (e.KeyCode == Keys.Escape)
                    {
                        DialogResult = DialogResult.Cancel;
                    }
                }
            }
            ;
        }
        public override void SaveRecord()
        {
            dataGridView.EndEdit();
            _syncViews = false;
            var list = SoftSuppliersFromViewport();

            if (!ValidateViewportData(list))
            {
                _syncViews = true;
                return;
            }
            for (var i = 0; i < list.Count; i++)
            {
                var row = _softSuppliers.Select().Rows.Find(list[i].IdSoftSupplier);
                if (row == null)
                {
                    var idSoftSupplier = SoftSuppliersDataModel.Insert(list[i]);
                    if (idSoftSupplier == -1)
                    {
                        _syncViews = true;
                        return;
                    }
                    ((DataRowView)_vSnapshotSoftSuppliers[i])["ID Supplier"] = idSoftSupplier;
                    _softSuppliers.Select().Rows.Add(DataRowViewToArray((DataRowView)_vSnapshotSoftSuppliers[i]));
                }
                else
                {
                    if (RowToSoftSupplier(row) == list[i])
                    {
                        continue;
                    }
                    if (SoftSuppliersDataModel.Update(list[i]) == -1)
                    {
                        _syncViews = true;
                        return;
                    }
                    row["Supplier"] = list[i].SoftSupplierName == null ? DBNull.Value : (object)list[i].SoftSupplierName;
                }
            }
            list = SoftSuppliersFromView();
            for (var i = 0; i < list.Count; i++)
            {
                var rowIndex = -1;
                for (var j = 0; j < dataGridView.Rows.Count; j++)
                {
                    if ((dataGridView.Rows[j].Cells["idSoftSupplier"].Value != null) &&
                        !string.IsNullOrEmpty(dataGridView.Rows[j].Cells["idSoftSupplier"].Value.ToString()) &&
                        ((int)dataGridView.Rows[j].Cells["idSoftSupplier"].Value == list[i].IdSoftSupplier))
                    {
                        rowIndex = j;
                    }
                }
                if (rowIndex == -1)
                {
                    if (SoftSuppliersDataModel.Delete(list[i].IdSoftSupplier.Value) == -1)
                    {
                        _syncViews = true;
                        return;
                    }
                    _softSuppliers.Select().Rows.Find(list[i].IdSoftSupplier).Delete();
                }
            }
            _syncViews = true;
            MenuCallback.EditingStateUpdate();
        }