Exemplo n.º 1
0
        private string ValidateFieldClone(WebPivotGridFieldClone clonedField, bool isDateTimeField)
        {
            string       error         = String.Empty;
            const string lineSeparator = "<br/>";

            if (string.IsNullOrEmpty(clonedField.CaptionEn))
            {
                bv.common.Core.Utils.AppendLine(ref error,
                                                StandardErrorHelper.Error(StandardError.Mandatory, Translator.GetMessageString("strNewColumnNameEn")),
                                                lineSeparator);
            }
            if (ModelUserContext.CurrentLanguage != Localizer.lngEn && string.IsNullOrEmpty(clonedField.Caption))
            {
                bv.common.Core.Utils.AppendLine(ref error,
                                                StandardErrorHelper.Error(StandardError.Mandatory, Translator.GetMessageString("strNewColumnName")),
                                                lineSeparator);
            }

            if (clonedField.AddMissedValues && isDateTimeField)
            {
                if (clonedField.DiapasonStartDate == null)
                {
                    bv.common.Core.Utils.AppendLine(ref error,
                                                    StandardErrorHelper.Error(StandardError.Mandatory, Translator.GetMessageString("DateFrom")),
                                                    lineSeparator);
                }
                if (clonedField.DiapasonEndDate == null)
                {
                    bv.common.Core.Utils.AppendLine(ref error,
                                                    StandardErrorHelper.Error(StandardError.Mandatory, Translator.GetMessageString("DateTo")),
                                                    lineSeparator);
                }
                if (ModelState.IsValid && clonedField.DiapasonStartDate > clonedField.DiapasonEndDate)
                {
                    bv.common.Core.Utils.AppendLine(ref error,
                                                    string.Format(Translator.GetMessageString("ErrUnstrictChainDate"), Translator.GetMessageString("DateFrom"),
                                                                  clonedField.DiapasonStartDate, Translator.GetMessageString("DateTo"), clonedField.DiapasonEndDate),
                                                    lineSeparator);
                }
            }
            return(error);
        }
Exemplo n.º 2
0
        public ActionResult OnSaveFieldChanges
            (string caption, string captionEn, string aggregateFunctionId, string precision, string basicCountFunctionId, string adminUnitField, string dateField,
            string groupInterval, string addMissedValue, string startDate, string endDate)
        {
            AvrPivotGridModel model = GetModelFromSession();

            if (model == null)
            {
                return(new JsonResult
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { result = "error", error = m_ErrorMessage }
                });
            }
            if (model.PivotSettings.SelectedField != null)
            {
                WebPivotGridFieldClone clonedField =
                    model.PivotSettings.SelectedField.GetClonedField(model.PivotSettings.LayoutDataset, false);
                if (ModelUserContext.CurrentLanguage != Localizer.lngEn)
                {
                    clonedField.Caption = caption;
                }
                clonedField.CaptionEn               = captionEn;
                clonedField.AggregateFunctionId     = bv.common.Core.Utils.ToLong(aggregateFunctionId);
                clonedField.BasicCountFunctionId    = bv.common.Core.Utils.ToLong(basicCountFunctionId);
                clonedField.Precision               = bv.common.Core.Utils.ToNullableInt(precision);
                clonedField.UnitLayoutSearchFieldId = bv.common.Core.Utils.ToNullableLong(adminUnitField);
                clonedField.DateLayoutSearchFieldId = bv.common.Core.Utils.ToNullableLong(dateField);
                bool updateMissedValues = (!clonedField.AddMissedValues.Equals(bool.Parse(addMissedValue)) ||
                                           !clonedField.DiapasonStartDate.Equals(bv.common.Core.Utils.ToDateNullable(startDate)) ||
                                           !clonedField.DiapasonEndDate.Equals(bv.common.Core.Utils.ToDateNullable(endDate)) ||
                                           !clonedField.PrivateGroupInterval.Equals(bv.common.Core.Utils.ToNullableLong(groupInterval)));
                clonedField.PrivateGroupInterval = bv.common.Core.Utils.ToNullableLong(groupInterval);
                bool fillEmptyValues =
                    LayoutPivotGridHelper.IsFieldGroupIntervalChanged(model.PivotSettings.SelectedField,
                                                                      clonedField.PrivateGroupInterval.HasValue ? (PivotGroupInterval)clonedField.PrivateGroupInterval : model.PivotSettings.SelectedField.GroupInterval);
                clonedField.AddMissedValues   = bool.Parse(addMissedValue);
                clonedField.DiapasonStartDate = bv.common.Core.Utils.ToDateNullable(startDate);
                clonedField.DiapasonEndDate   = bv.common.Core.Utils.ToDateNullable(endDate);
                string error = ValidateFieldClone(clonedField, model.PivotSettings.SelectedField.IsDateTimeField);
                if (!string.IsNullOrEmpty(error))
                {
                    return(new JsonResult
                    {
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                        Data = new { result = "error", error = error }
                    });
                }
                bool aggregateChanged =
                    !model.PivotSettings.SelectedField.AggregateFunctionId.Equals(clonedField.AggregateFunctionId);
                model.PivotSettings.SelectedField.FlashChanges(model.PivotSettings.LayoutDataset);
                if (aggregateChanged)
                {
                    WebPivotGridField field           = model.PivotSettings.SelectedField;
                    CustomSummaryType summaryTypeType =
                        AvrPivotGridHelper.ParseSummaryType(model.PivotSettings.SelectedField.AggregateFunctionId);
                    field.SummaryDisplayType = PivotSummaryDisplayType.Default;

                    PivotSummaryType summaryType = summaryTypeType == CustomSummaryType.Count
                        ? PivotSummaryType.Count
                        : PivotSummaryType.Custom;
                    field.CustomSummaryType = summaryTypeType;
                    field.SummaryType       = summaryType;
                }
                if (model.PivotSettings.SelectedField.Action != WebFieldAction.Add)
                {
                    model.PivotSettings.SelectedField.Action = WebFieldAction.Edit;
                }
                model.PivotSettings.UpdatedField = model.PivotSettings.SelectedField;
                if (model.PivotSettings.SelectedField.HasChanges)
                {
                    model.PivotSettings.HasChanges = true;
                }
                if (updateMissedValues)
                {
                    LayoutPivotGridHelper.CopyMissedValuesFromField(model.PivotSettings.SelectedField, model.PivotSettings.Fields);
                    LayoutPivotGridHelper.AddMissedValues(model, true);
                }
                else if (fillEmptyValues)
                {
                    LayoutPivotGridHelper.FillEmptyValuesInDataArea(model);
                }
                if (model.PivotSettings.SelectedField.Action != WebFieldAction.Add)
                {
                    return(new JsonResult {
                        Data = String.Empty, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
            return(new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new { result = "refresh", function = "RefeshData2" }
            });
        }