private void SetSizeOptions(PrintProductControl printProductControl) { var sizeOptions = printProductControl.PrintProduct.SizeOptions; switch (printProductControl.PrintProduct.AdPricingStrategy) { case AdPricingStrategies.StandartPCI: case AdPricingStrategies.FlatModular: sizeOptions.ResetToDefaults(AdPricingStrategies.StandartPCI); _allowToSave = false; Controller.Instance.PrintProductRateCard.EditValue = null; Controller.Instance.PrintProductPercentOfPage.EditValue = null; Controller.Instance.PrintProductSharePageSquare.Items.Clear(); _allowToSave = true; sizeOptions.EnableSquare = Controller.Instance.PrintProductAdSizeStandartSquare.Checked; sizeOptions.Width = sizeOptions.EnableSquare ? (double)Controller.Instance.PrintProductStandartWidth.Value : 0; sizeOptions.Height = sizeOptions.EnableSquare ? (double)Controller.Instance.PrintProductStandartHeight.Value : 0; break; case AdPricingStrategies.SharePage: sizeOptions.ResetToDefaults(AdPricingStrategies.SharePage); _allowToSave = false; Controller.Instance.PrintProductAdSizeStandartSquare.Checked = false; Controller.Instance.PrintProductStandartHeight.Value = 0; Controller.Instance.PrintProductStandartWidth.Value = 0; _allowToSave = true; sizeOptions.RateCard = !string.IsNullOrEmpty((string)Controller.Instance.PrintProductRateCard.EditValue) ? Controller.Instance.PrintProductRateCard.EditValue.ToString() : null; sizeOptions.PercentOfPage = !string.IsNullOrEmpty((string)Controller.Instance.PrintProductPercentOfPage.EditValue) ? Controller.Instance.PrintProductPercentOfPage.EditValue.ToString() : null; var shareUnit = (from CheckedListBoxItem item in Controller.Instance.PrintProductSharePageSquare.Items where item.CheckState == CheckState.Checked select item.Value as ShareUnit).FirstOrDefault(); sizeOptions.Height = shareUnit != null ? shareUnit.HeightValue : 0; sizeOptions.HeightMeasure = shareUnit != null ? shareUnit.HeightMeasureUnit : sizeOptions.HeightMeasure; sizeOptions.Width = shareUnit != null ? shareUnit.WidthValue : 0; sizeOptions.WidthMeasure = shareUnit != null ? shareUnit.WidthMeasureUnit : sizeOptions.WidthMeasure; sizeOptions.EnableSquare = false; break; } sizeOptions.EnablePageSize = Controller.Instance.PrintProductPageSizeCheck.Checked; sizeOptions.PageSizeGroup = sizeOptions.EnablePageSize ? Controller.Instance.PrintProductPageSizeGroup.EditValue as String : null; sizeOptions.PageSize = sizeOptions.EnablePageSize ? Controller.Instance.PrintProductPageSizeName.EditValue as String : null; sizeOptions.EnableMechanicals = Controller.Instance.PrintProductMechanicalsCheck.Checked; sizeOptions.Mechanicals = sizeOptions.EnableMechanicals ? Controller.Instance.PrintProductMechanicalsName.EditValue as String : null; FormatAccordingSizeOptions(printProductControl); printProductControl.LoadInserts(); printProductControl.UpdateTotals(); printProductControl.UpdateProductButtonsState(); }
private void LoadSizeOptions(PrintProductControl printProductControl) { _allowToSave = false; var sizeOptions = printProductControl.PrintProduct.SizeOptions; Controller.Instance.PrintProductPageSizeCheck.Checked = sizeOptions.EnablePageSize; Controller.Instance.PrintProductPageSizeGroup.Properties.Items.Clear(); Controller.Instance.PrintProductPageSizeGroup.Properties.Items.AddRange(ListManager.Instance.PageSizes.Select(ps => ps.Code).Distinct().ToArray()); Controller.Instance.PrintProductPageSizeGroupContainer.Visible = Controller.Instance.PrintProductPageSizeGroup.Properties.Items.Count > 1; if (!String.IsNullOrEmpty(sizeOptions.PageSizeGroup)) Controller.Instance.PrintProductPageSizeGroup.EditValue = sizeOptions.PageSizeGroup; else Controller.Instance.PrintProductPageSizeGroup.EditValue = ListManager.Instance.PageSizes.Select(ps => ps.Code).Distinct().FirstOrDefault(); Controller.Instance.PrintProductPageSizeName.Properties.Items.Clear(); Controller.Instance.PrintProductPageSizeName.Properties.Items.AddRange(ListManager.Instance.PageSizes.Where(ps => ps.Code.Equals(Controller.Instance.PrintProductPageSizeGroup.EditValue as String) || Controller.Instance.PrintProductPageSizeGroup.Properties.Items.Count <= 1).Select(ps => ps.Name).ToArray()); Controller.Instance.PrintProductPageSizeName.EditValue = sizeOptions.PageSize; Controller.Instance.PrintProductMechanicalsCheck.Checked = sizeOptions.EnableMechanicals; Controller.Instance.PrintProductMechanicalsName.EditValue = sizeOptions.Mechanicals; Controller.Instance.PrintProductRateCard.Properties.Items.Clear(); Controller.Instance.PrintProductRateCard.Properties.Items.AddRange(ListManager.Instance.ShareUnits.Select(x => x.RateCard).Distinct().ToArray()); switch (printProductControl.PrintProduct.AdPricingStrategy) { case AdPricingStrategies.StandartPCI: case AdPricingStrategies.FlatModular: Controller.Instance.PrintProductAdSizeStandartSquare.Checked = sizeOptions.EnableSquare; Controller.Instance.PrintProductStandartWidth.Value = (decimal)sizeOptions.Width; Controller.Instance.PrintProductStandartHeight.Value = (decimal)sizeOptions.Height; break; case AdPricingStrategies.SharePage: Controller.Instance.PrintProductRateCard.EditValue = sizeOptions.RateCard; Controller.Instance.PrintProductPercentOfPage.Properties.Items.Clear(); if (!string.IsNullOrEmpty(sizeOptions.RateCard)) Controller.Instance.PrintProductPercentOfPage.Properties.Items.AddRange(ListManager.Instance.ShareUnits.Where(x => x.RateCard.Equals(sizeOptions.RateCard)).Select(x => x.PercentOfPage).Distinct().ToArray()); Controller.Instance.PrintProductPercentOfPage.EditValue = sizeOptions.PercentOfPage; Controller.Instance.PrintProductSharePageSquare.Items.Clear(); var shareUnits = new ShareUnit[] { }; if (Controller.Instance.PrintProductPercentOfPage.EditValue != null && Controller.Instance.PrintProductRateCard.EditValue != null) shareUnits = ListManager.Instance.ShareUnits.Where(x => x.RateCard.Equals(Controller.Instance.PrintProductRateCard.EditValue.ToString()) && x.PercentOfPage.Equals(Controller.Instance.PrintProductPercentOfPage.EditValue.ToString())).ToArray(); if (shareUnits.Length > 0) { var storedShareUnit = printProductControl.PrintProduct.SizeOptions.RelatedShareUnit; foreach (var shareUnit in shareUnits) Controller.Instance.PrintProductSharePageSquare.Items.Add(shareUnit, shareUnit.Dimensions, shareUnit.Dimensions.Equals(storedShareUnit.Dimensions) ? CheckState.Checked : CheckState.Unchecked, true); if (Controller.Instance.PrintProductSharePageSquare.CheckedIndices.Count == 0) Controller.Instance.PrintProductSharePageSquare.Items[0].CheckState = CheckState.Checked; } break; } FormatAccordingSizeOptions(printProductControl); printProductControl.UpdateProductButtonsState(); _allowToSave = true; }