コード例 #1
0
    private void Save()
    {
        txtLabel.Text = cbLabel.Value;
        if ((container != null) || (container == null && ddlContainerGroups.SelectedIndex != 0))
        {
            Page.Validate();
            if (Page.IsValid)
            {
                // Retrieve the new text in the templated columns
                // Prepare the command text
                lbError.Text = "";
                int  lookupValueId          = -1;
                bool isContainerTypeChanged = false;
                if (dlLookupField.SelectedIndex > 0)
                {
                    lookupValueId = Convert.ToInt32(dlLookupField.SelectedValue);
                }

                if (ViewState["action"].ToString() == "update")
                {
                    container.Tag            = txtTag.Text;
                    container.Name           = txtContainerName.Text;
                    container.Definition     = txtDefinition.Text;
                    container.EntryRule      = txtEntryRule.Text;
                    container.DataTypeCode   = Convert.ToChar(dlDataType.SelectedValue);
                    container.MaxLength      = Convert.ToInt32(txtMaxLength.Value);
                    container.ValidationMask = string.Empty;
                    container.Sample         = txtSample.Text;
                    container.Mecd           = cbMECD.Checked;
                    container.Mmd            = cbMMD.Checked;
                    container.Cdm            = cbCDM.Checked;
                    container.GroupId        = Convert.ToInt32(ddlContainerGroups.SelectedValue);
                    container.InputMask      = txtInputMask.Text;
                    container.LookupId       = lookupValueId;
                    container.DataTypeCode   = Convert.ToChar(dlDataType.SelectedValue);

                    // Note: When the container type is changed from or to features, then we will reload the complete page
                    if (container.ContainerTypeCode != Convert.ToChar(dlContainerType.SelectedValue) && (dlContainerType.SelectedValue == "F" || container.ContainerTypeCode.ToString() == "F"))
                    {
                        isContainerTypeChanged = true;
                    }
                    container.ContainerTypeCode   = Convert.ToChar(dlContainerType.SelectedValue);
                    container.Translatable        = cbTranslatable.Checked;
                    container.ModifierId          = SessionState.User.Id;
                    container.InheritanceMethodId = Convert.ToInt32(dlInheritanceMethod.SelectedValue);
                    container.Publishable         = cbPublishable.Checked;
                    container.Regionalizable      = cbRegionalizable.Checked;
                    container.Localizable         = cbLocalizable.Checked;
                    container.ReadOnly            = cbReadOnly.Checked;
                    container.Sort           = Convert.ToInt32(txtSort.Value);
                    container.Label          = cbLabel.Value;
                    container.LabelId        = -1; // The label is Always recreate
                    container.WWXPath        = tbWWXPath.Text;
                    container.KeepIfObsolete = cbKeepIfObsolete.Checked;
                    container.SegmentId      = Convert.ToInt32(ddlSegments.SelectedValue);
                }
                else
                {
                    container = new HyperCatalog.Business.Container(-1,
                                                                    txtTag.Text,
                                                                    txtContainerName.Text,
                                                                    txtDefinition.Text,
                                                                    txtEntryRule.Text,
                                                                    string.Empty,
                                                                    txtSample.Text,
                                                                    txtInputMask.Text,
                                                                    Convert.ToChar(dlDataType.SelectedValue),
                                                                    cbTranslatable.Checked,
                                                                    Convert.ToChar(dlContainerType.SelectedValue),
                                                                    Convert.ToInt32(txtMaxLength.Value),
                                                                    lookupValueId,
                                                                    Convert.ToInt32(txtSort.Value),
                                                                    SessionState.User.Id,
                                                                    -1,
                                                                    Convert.ToInt32(ddlContainerGroups.SelectedValue),
                                                                    DateTime.UtcNow,
                                                                    null,
                                                                    cbPublishable.Checked, false,
                                                                    Convert.ToInt32(dlInheritanceMethod.SelectedValue),
                                                                    cbRegionalizable.Checked,
                                                                    cbLocalizable.Checked,
                                                                    cbReadOnly.Checked,
                                                                    cbLabel.Value.ToString(),
                                                                    -1,
                                                                    tbWWXPath.Text,
                                                                    cbKeepIfObsolete.Checked,
                                                                    Convert.ToInt32(ddlSegments.SelectedValue),
                                                                    dlDataType.Text,
                                                                    dlContainerType.Text,
                                                                    cbMECD.Checked,
                                                                    cbMMD.Checked,
                                                                    cbCDM.Checked
                                                                    );
                }
                if (container.Save())
                {
                    SessionState.ClearAppContainers();
                    SessionState.ClearAppContainerGroups();
                    if (txtMaxLength.ValueDouble > 0)
                    {
                        txtMaxLength.MinValue = txtMaxLength.ValueDouble;
                    }

                    if (ViewState["action"].ToString() == "create")
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript1", "<script>UpdateTabs(" + container.Id + ");</script>");
                    }
                    else if (isContainerTypeChanged)
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript2", "<script>UpdateTabsAfterUpdate(" + container.Id + ");</script>");
                    }
                    else
                    {
                        container        = HyperCatalog.Business.Container.GetByKey(containerId);
                        lbError.CssClass = "hc_success";
                        lbError.Text     = "Data saved!";
                        lbError.Visible  = true;

                        if (container.Modifier != null && container.ModifyDate.HasValue)
                        {
                            hlModifier.NavigateUrl = "mailto:" + UITools.GetDisplayEmail(container.Modifier.Email);
                            hlModifier.Text        = "Modified by " + container.Modifier.FullName + " on " + SessionState.User.FormatUtcDate(container.ModifyDate.Value, true, SessionState.User.FormatDate + ' ' + SessionState.User.FormatTime) + "<br/><br/>";
                            hlModifier.Visible     = true;
                        }
                    }
                }
                else
                {
                    lbError.CssClass = "hc_error";
                    lbError.Text     = HyperCatalog.Business.Container.LastError;
                    lbError.Visible  = true;
                }
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alertmissing", "<script>alert('Label is mandatory');</script>");
            }
        }
        else
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "alertmissing", "<script>alert('Please choose a container group');</script>");
        }
        chianti();
    }