コード例 #1
0
        public override void LoadData()
        {
            dataGridView.AutoGenerateColumns = false;
            DockAreas        = WeifenLuo.WinFormsUI.Docking.DockAreas.Document;
            _softLicDocTypes = SoftLicDocTypesDataModel.GetInstance();

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

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

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

            dataGridView.DataSource           = _vSnapshotSoftLicDocTypes;
            idSoftLicDocType.DataPropertyName = "ID DocType";
            softLicDocType.DataPropertyName   = "DocType";

            dataGridView.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

            dataGridView.CellValidated += dataGridView_CellValidated;
            //События изменения данных для проверки соответствия реальным данным в модели
            dataGridView.CellValueChanged += dataGridView_CellValueChanged;
            //Синхронизация данных исходные->текущие
            _softLicDocTypes.Select().RowChanged  += SoftLicDocTypesViewport_RowChanged;
            _softLicDocTypes.Select().RowDeleting += SoftLicDocTypesViewport_RowDeleting;
            _softLicDocTypes.Select().RowDeleted  += SoftLicDocTypesViewport_RowDeleted;
        }
コード例 #2
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;
                    }
                }
            }
            ;
        }
コード例 #3
0
        public override void SaveRecord()
        {
            dataGridView.EndEdit();
            _syncViews = false;
            var list = SoftLicTypesFromViewport();

            if (!ValidateViewportData(list))
            {
                _syncViews = true;
                return;
            }
            for (var i = 0; i < list.Count; i++)
            {
                var row = _softLicDocTypes.Select().Rows.Find(list[i].IdDocType);
                if (row == null)
                {
                    var idSoftLicDocType = SoftLicDocTypesDataModel.Insert(list[i]);
                    if (idSoftLicDocType == -1)
                    {
                        _syncViews = true;
                        return;
                    }
                    ((DataRowView)_vSnapshotSoftLicDocTypes[i])["ID DocType"] = idSoftLicDocType;
                    _softLicDocTypes.Select().Rows.Add(DataRowViewToArray((DataRowView)_vSnapshotSoftLicDocTypes[i]));
                }
                else
                {
                    if (RowToSoftLicDocType(row) == list[i])
                    {
                        continue;
                    }
                    if (SoftLicDocTypesDataModel.Update(list[i]) == -1)
                    {
                        _syncViews = true;
                        return;
                    }
                    row["DocType"] = list[i].DocType == null ? DBNull.Value : (object)list[i].DocType;
                }
            }
            list = SoftLicTypesFromView();
            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["idSoftLicDocType"].Value != null) &&
                        !string.IsNullOrEmpty(dataGridView.Rows[j].Cells["idSoftLicDocType"].Value.ToString()) &&
                        ((int)dataGridView.Rows[j].Cells["idSoftLicDocType"].Value == list[i].IdDocType))
                    {
                        rowIndex = j;
                    }
                }
                if (rowIndex == -1)
                {
                    if (SoftLicDocTypesDataModel.Delete(list[i].IdDocType.Value) == -1)
                    {
                        _syncViews = true;
                        return;
                    }
                    _softLicDocTypes.Select().Rows.Find(list[i].IdDocType).Delete();
                }
            }
            _syncViews = true;
            MenuCallback.EditingStateUpdate();
        }