Exemplo n.º 1
0
        private async void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                var perms = API.GetInstance().CurrentUser.Permissions;
                if (!perms.HasFlag(UserPermissions.Write))
                {
                    throw new Exception("Доступ запрещен");
                }
                OperationCreateEditForm <OperationType, ContentType> createEditForm = new OperationCreateEditForm <OperationType, ContentType>();
                await createEditForm.LoadAsync();

                if (createEditForm.ShowDialog() == DialogResult.OK)
                {
                    await AsyncGetData();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка");
            }
        }
Exemplo n.º 2
0
        private async void dgvOpList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == dgvOpList.Columns["Изменить"].Index)
            {
                if (typeof(OperationType) == typeof(Shipment))
                {
                    MessageBox.Show("Для изменения удалите и создайте новую запись");
                    return;
                }
                try
                {
                    var perms = API.GetInstance().CurrentUser.Permissions;
                    if (!perms.HasFlag(UserPermissions.Write))
                    {
                        throw new Exception("Доступ запрещен");
                    }
                    var id   = (long)dgvOpList.Rows[e.RowIndex].Cells["ИД"].Value;
                    var item = (OperationType)(dgvOpList.CurrentRow.DataBoundItem as DataRowView).Row[0];
                    OperationCreateEditForm <OperationType, ContentType> createEditForm = new OperationCreateEditForm <OperationType, ContentType>(item, id);
                    await createEditForm.LoadAsync();

                    if (createEditForm.ShowDialog() == DialogResult.OK)
                    {
                        await AsyncGetData();

                        FillDetailsTable();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка");
                }
            }
            else if (e.ColumnIndex == dgvOpList.Columns["Удалить"].Index)
            {
                try
                {
                    var perms = API.GetInstance().CurrentUser.Permissions;
                    if (!perms.HasFlag(UserPermissions.Delete))
                    {
                        throw new Exception("Доступ запрещен");
                    }
                    var          id           = (long)dgvOpList.Rows[e.RowIndex].Cells["ИД"].Value;
                    DialogResult dialogResult = MessageBox.Show("Вы уверены?", "Удаление записи", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        API api = API.GetInstance();
                        await api.AsyncRemoveItem <OperationType>(id);
                        await AsyncGetData();

                        FillDetailsTable();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Во время удаления произошла ошибка");
                }
            }
            else
            {
                FillDetailsTable();
            }
        }