Ejemplo n.º 1
0
    private void Save()
    {
        DataType type = null;

        if (txtDataTypeCode.Enabled)
        {
            type = new DataType(Convert.ToChar(txtDataTypeCode.Text), txtDataType.Text,
                                Server.HtmlEncode(txtDescription.Text), Server.HtmlEncode(txtExample.Text),
                                Server.HtmlEncode(txtComment.Text), txtRegularExpression.Text,
                                txtInputType.Text, cbIsActive.Checked);
        }
        else
        {
            type                   = DataType.GetByKey(Convert.ToChar(txtDataTypeCode.Text));
            type.Name              = txtDataType.Text;
            type.Description       = Server.HtmlEncode(txtDescription.Text);
            type.Comment           = Server.HtmlEncode(txtComment.Text);
            type.RegularExpression = txtRegularExpression.Text;
            type.Sample            = Server.HtmlEncode(txtExample.Text);
            type.InputType         = txtInputType.Text;
            type.IsActive          = cbIsActive.Checked;
        }

        if (type != null)
        {
            if (type.Save(txtDataTypeCode.Enabled))
            {
                SessionState.ClearAppDataTypes();
                if (txtDataTypeCode.Enabled)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", "<script>back();</script>");
                }
                else
                {
                    lbError.CssClass = "hc_success";
                    lbError.Text     = "Data saved!";
                    lbError.Visible  = true;
                }
            }
            else
            {
                lbError.CssClass = "hc_error";
                lbError.Text     = DataType.LastError;
                lbError.Visible  = true;
            }
        }
        else
        {
            lbError.CssClass = "hc_error";
            lbError.Text     = "Error: Data type is null";
            lbError.Visible  = true;
        }
    }