Exemplo n.º 1
0
        private void editMaterial_()
        {
            if (materialsBS.Count != 0)
            {
                if (materialsBS.Count != 0)
                {
                    using (MaterialEditFm materialEditFm = new MaterialEditFm(Utils.Operation.Update, (MaterialsDTO)materialsBS.Current))
                    {
                        if (materialEditFm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            int return_MaterialId = materialEditFm.Return();
                            materialsGridView.BeginDataUpdate();

                            materialsService         = Program.kernel.Get <IMaterialsService>();
                            materialsBS.DataSource   = materialsService.GetMaterials();
                            materialsGrid.DataSource = materialsBS;

                            materialsGridView.EndDataUpdate();
                            int rowHandle = materialsGridView.LocateByValue("MaterialId", return_MaterialId);
                            materialsGridView.FocusedRowHandle = rowHandle;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void materialsGridEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            switch (e.Button.Index)
            {
            case 1:     //Добавить
            {
                using (MaterialEditFm materialEditFm = new MaterialEditFm(Utils.Operation.Add, new MaterialsDTO()))
                {
                    if (materialEditFm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        int return_MaterialId = materialEditFm.Return();

                        materialsService = Program.kernel.Get <IMaterialsService>();
                        materialsGridEdit.Properties.DataSource = materialsService.GetMaterials();
                        materialsGridEdit.EditValue             = return_MaterialId;
                    }
                }
                break;
            }

            case 2:     //Корректировать
            {
                object key           = materialsGridEdit.EditValue;
                var    selectedIndex = materialsGridEdit.Properties.GetIndexByKeyValue(key);

                if (selectedIndex == -1)
                {
                    return;
                }

                using (MaterialEditFm materialEditFm = new MaterialEditFm(Utils.Operation.Update, (MaterialsDTO)materialsGridEdit.GetSelectedDataRow()))
                {
                    if (materialEditFm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        int return_MaterialId = materialEditFm.Return();

                        materialsService = Program.kernel.Get <IMaterialsService>();
                        materialsGridEdit.Properties.DataSource = materialsService.GetMaterials();
                        materialsGridEdit.EditValue             = return_MaterialId;
                    }
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }