예제 #1
0
        protected override void CustomizeControls()
        {
            var isCurrentUserSeller      = SecurityService.IsCurrentUserSeller;
            var isCurrentUserPurchaser   = SecurityService.IsCurrentUserPurchaser;
            var isCurrentUserDistributor = SecurityService.IsCurrentUserDistributor;

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

            case EditFormMode.Create:
                CheckHelper.WithinCondition(isCurrentUserSeller, "Only seller can create order.");

                var createFormModeForPurchaser = isCurrentUserPurchaser ? EditFormMode.Create : EditFormMode.View;

                ControlCustomizeHelper.CustomizeControl(_orderDateTimePicker, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_activeCheckBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerFirstNameWatermarkedTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerLastNameWatermarkedTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerAddressWatermarkedTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerCityWatermarkedTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerCountryWatermarkedTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerPostalCodeWatermarkedTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerPhoneNumberWatermarkedTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerEmailWatermarkedTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerPrepaidNumericUpDown, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_customerPaidNumericUpDown, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_rublesPerDollarNumericUpDown, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_distributorSpentOnDeliveryNumericUpDown, EditFormMode.View);
                ControlCustomizeHelper.CustomizeControl(_commentsTextBox, EditFormMode.Create);
                ControlCustomizeHelper.CustomizeControl(_parcelReferenceEditor, createFormModeForPurchaser);
                ControlCustomizeHelper.CustomizeControl(_trackingNumberTextBox, EditFormMode.View);
                break;

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

                var editFormModeForPurchaser   = isCurrentUserPurchaser ? EditFormMode.Edit : EditFormMode.View;
                var editFormModeForDistributor = Dto.IsCurrentUserDistributorForOrder() ? EditFormMode.Edit : EditFormMode.View;
                var editFormModeForSeller      = Dto.IsCurrentUserSellerForOrder() ? EditFormMode.Edit : EditFormMode.View;

                ControlCustomizeHelper.CustomizeControl(_orderDateTimePicker, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_activeCheckBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerFirstNameWatermarkedTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerLastNameWatermarkedTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerAddressWatermarkedTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerCityWatermarkedTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerCountryWatermarkedTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerPostalCodeWatermarkedTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerPhoneNumberWatermarkedTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerEmailWatermarkedTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerPrepaidNumericUpDown, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_customerPaidNumericUpDown, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_rublesPerDollarNumericUpDown, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_distributorSpentOnDeliveryNumericUpDown, editFormModeForDistributor);
                ControlCustomizeHelper.CustomizeControl(_commentsTextBox, editFormModeForSeller);
                ControlCustomizeHelper.CustomizeControl(_parcelReferenceEditor, editFormModeForPurchaser);
                ControlCustomizeHelper.CustomizeControl(_trackingNumberTextBox, editFormModeForDistributor);
                break;

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