Esempio n. 1
0
        protected override void CustomizeControls()
        {
            var isCurrentUserPurchaser   = SecurityService.IsCurrentUserPurchaser;
            var isCurrentUserDistributor = SecurityService.IsCurrentUserDistributor;

            switch (Mode)
            {
            case EditFormMode.View:
                base.CustomizeControls();
                break;

            case EditFormMode.Create:
                CheckHelper.WithinCondition(isCurrentUserPurchaser, "Only purchaser can create parcel.");

                ControlCustomizeHelper.CustomizeControl(_trackingNumberTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_sentDatePicker, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_receivedDatePicker, EditFormMode.View);
                ControlCustomizeHelper.CustomizeControl(_distributorReferenceEditor, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_purchaserSpentOnDeliveryNumericUpDown, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_rublesPerDollarNumericUpDown, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_commentsTextBox, EditFormMode.Create);
                break;

            case EditFormMode.Edit:
                CheckHelper.WithinCondition(isCurrentUserPurchaser || isCurrentUserDistributor, "Only purchaser and distributor can change parcel.");

                var editFormModeForPurchaser   = isCurrentUserPurchaser ? EditFormMode.Edit : EditFormMode.View;
                var editFormModeForDistributor = Dto.IsCurrentUserDistributorForParcel() ? EditFormMode.Edit : EditFormMode.View;

                ControlCustomizeHelper.CustomizeControl(_trackingNumberTextBox, editFormModeForPurchaser);
                ControlCustomizeHelper.CustomizeControl(_sentDatePicker, editFormModeForPurchaser);
                ControlCustomizeHelper.CustomizeControl(_receivedDatePicker, editFormModeForDistributor);
                ControlCustomizeHelper.CustomizeControl(_distributorReferenceEditor, editFormModeForPurchaser);
                ControlCustomizeHelper.CustomizeControl(_purchaserSpentOnDeliveryNumericUpDown, editFormModeForPurchaser);
                ControlCustomizeHelper.CustomizeControl(_rublesPerDollarNumericUpDown, editFormModeForPurchaser);
                ControlCustomizeHelper.CustomizeControl(_commentsTextBox, editFormModeForPurchaser);
                break;

            default:
                throw new NotSupportedException(Mode.ToString());
            }
        }