예제 #1
0
 public static TDocument Deserialize <TDocument>(byte[] bytes) where TDocument : AbstractDocument, new()
 {
     if (bytes == null)
     {
         throw new ArgumentException("Can't deserialize null", "bytes");
     }
     using (MemoryStream input = new MemoryStream(bytes))
     {
         BinaryReader binaryReader = new BinaryReader(input);
         try
         {
             byte b = binaryReader.ReadByte();
             if (b != 0)
             {
                 throw new CorruptionException("Can't deserialize format version " + b);
             }
             byte typeId = binaryReader.ReadByte();
             SerializedTypeReflection typeReflection = SerializerReflectionCache.GetTypeReflection(typeId);
             TDocument val = (TDocument)Activator.CreateInstance(typeReflection.Type);
             val.TypeId = typeId;
             SerializedFieldReflection[] fieldReflections = typeReflection.FieldReflections;
             byte b2 = binaryReader.ReadByte();
             for (int i = 0; i < b2; i++)
             {
                 byte b3        = binaryReader.ReadByte();
                 Type fieldType = GetFieldType(b3);
                 byte b4        = binaryReader.ReadByte();
                 SerializedFieldReflection fieldInfo = GetFieldInfo(fieldReflections, b4);
                 FieldTypeId        fieldTypeId      = (FieldTypeId)b3;
                 FieldTypeMapping[] array            = fieldTypeMappings;
                 for (int j = 0; j < array.Length; j++)
                 {
                     FieldTypeMapping fieldTypeMapping = array[j];
                     if (fieldTypeMapping.Id == fieldTypeId)
                     {
                         object value = fieldTypeMapping.Reader(binaryReader);
                         if (fieldInfo != null)
                         {
                             FieldInfo fieldInfo2 = fieldInfo.FieldInfo;
                             Type      fieldType2 = fieldInfo2.FieldType;
                             if (fieldType != fieldType2)
                             {
                                 throw new CorruptionException(string.Concat("Field ", b4, " has type ", fieldType, " in the data to deserialize and type ", fieldType2, " in the code"));
                             }
                             fieldInfo2.SetValue(val, value);
                             break;
                         }
                         break;
                     }
                 }
             }
             return(val);
         }
         catch (Exception innerException)
         {
             throw new CorruptionException("Unknown error while deserializing", innerException);
         }
     }
 }
예제 #2
0
 public virtual void WriteData(FastBinaryWriter writer, Object additionalInfo)
 {
     writer.Write(FieldTypeId.GetHashCode());
     writer.Write(Justification.GetHashCode());
     writer.WriteSafeString(Caption);
     writer.WriteSafeString(Format);
     writer.WriteSafeString(NullText);
 }
        private static int GetByteSize(FieldInfo fieldInfo, FieldTypeId id, SerializationHintsAttribute attribute)
        {
            if (attribute != null && attribute.BitPacked > 0)
            {
                switch (id)
                {
                case FieldTypeId.Class:
                case FieldTypeId.Double:
                case FieldTypeId.Single:
                case FieldTypeId.Struct:
                case FieldTypeId.String:
                    throw new NotSupportedException("Cannot specify BitPacket hint for this field.");
                }
                if ((attribute.BitPacked % 8) != 0)
                {
                    throw new NotSupportedException("Number of bits in BitPacked must be dividable by 8 to get complecte bytes.");
                }
                return(attribute.BitPacked / 8);
            }
            if (id == FieldTypeId.Enum)
            {
                Type underlayingType = Enum.GetUnderlyingType(fieldInfo.FieldType);
                switch (Type.GetTypeCode(underlayingType))
                {
                case TypeCode.Byte:
                case TypeCode.SByte:
                    return(1);

                case TypeCode.Int16:
                case TypeCode.UInt16:
                    return(2);

                case TypeCode.Int32:
                case TypeCode.UInt32:
                    return(4);

                case TypeCode.Int64:
                case TypeCode.UInt64:
                    return(8);
                }
            }
            return(byteSizes[(int)id]);
        }
예제 #4
0
        public static byte[] Serialize(object obj, Type objType)
        {
            if (obj == null)
            {
                throw new ArgumentException("Can't serialize null", "obj");
            }
            SerializedTypeReflection typeReflection = SerializerReflectionCache.GetTypeReflection(objType);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                BinaryWriter binaryWriter = new BinaryWriter(memoryStream, Encoding.UTF8);
                binaryWriter.Write((byte)0);
                binaryWriter.Write(typeReflection.Id);
                SerializedFieldReflection[] fieldReflections = typeReflection.FieldReflections;
                binaryWriter.Write((byte)fieldReflections.Length);
                SerializedFieldReflection[] array = fieldReflections;
                foreach (SerializedFieldReflection serializedFieldReflection in array)
                {
                    FieldInfo   fieldInfo   = serializedFieldReflection.FieldInfo;
                    Type        fieldType   = fieldInfo.FieldType;
                    FieldTypeId fieldTypeId = GetFieldTypeId(fieldType);
                    binaryWriter.Write((byte)fieldTypeId);
                    binaryWriter.Write(serializedFieldReflection.Id);
                    object             value  = fieldInfo.GetValue(obj);
                    FieldTypeMapping[] array2 = fieldTypeMappings;
                    for (int j = 0; j < array2.Length; j++)
                    {
                        FieldTypeMapping fieldTypeMapping = array2[j];
                        if (fieldTypeMapping.Type == fieldType)
                        {
                            fieldTypeMapping.Writer(value, binaryWriter);
                            break;
                        }
                    }
                }
                return(memoryStream.ToArray());
            }
        }
예제 #5
0
파일: Select.cs 프로젝트: fgma75/epiinfo
        public override string RenderHtml()
        {
            var html = new StringBuilder();

            var inputName = _fieldPrefix + _key;
            string ErrorStyle = string.Empty;

            var prompt = new TagBuilder("label");
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"(\r\n|\r|\n)+");
            string newText = regex.Replace(Prompt.Replace(" ", "&nbsp;"), "<br />");
            string NewPromp = System.Web.Mvc.MvcHtmlString.Create(newText).ToString();

            prompt.InnerHtml=NewPromp;
            prompt.Attributes.Add("for", inputName);
            prompt.Attributes.Add("class", "EpiLabel");
            prompt.Attributes.Add("Id", "label" + inputName);

            StringBuilder StyleValues = new StringBuilder();
            StyleValues.Append(GetControlStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, Height.ToString(),_IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

            if (!IsValid)
            {
                ErrorStyle = ";border-color: red";
            }

            //var select = new TagBuilder("select");
            TagBuilder select = null;
            if (this._choices.Count() < 200)
            {
                select = new TagBuilder("select");
            }
            else
            {
                var Value = _choices.FirstOrDefault(x => x.Value == true).Key;
                select = new TagBuilder("input");
                select.Attributes.Add("list", inputName + "_DataList");
                select.Attributes.Add("data-autofirst", "true");
                select.Attributes.Add("value", Value);
            }
            select.Attributes.Add("id", inputName);
            select.Attributes.Add("name", inputName);

            /*if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                select.Attributes.Add("onblur", "return " + _key + "_after();"); //After
            }
            if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
            {
                if( this.RelateCondition)
                {
                    select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + "null" + "','" + _key + "');" + _key + "_click();"); //click
                }
                else
                {
                    select.Attributes.Add("onchange", "return " + _key + "_click();"); //click
                }
            }
            else {
                if (this.RelateCondition)
                {
                    select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + "null"+ "','" + _key + "');"  ); //click
                }
            }
            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {
                select.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }*/
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);
            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {

                select.Attributes.Add("onblur", "return " + _key + "_after();"); //After
                // select.Attributes.Add("onchange", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);
            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {

                select.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }
            EnterRule FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);

            if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
            {
                select.Attributes.Add("onclick", "return " + _key + "_click();"); //click
            }
            if (this.RelateCondition)
            {
                select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + SourceTable + "'," + "''" + ",'" + TextColumnName + "','" + FieldRelateCondition + "');"); //click

            }
            ////////////Check code end//////////////////
            int LargestChoiseLength =0 ;
            string measureString = "";

            foreach (var choice in _choices)
            {
                if (choice.Key.ToString().Length > LargestChoiseLength)
                {
                    LargestChoiseLength = choice.Key.ToString().Length;
                    measureString = choice.Key.ToString();
                }
            }

            Font stringFont = new Font(ControlFontStyle, _ControlFontSize);

            SizeF size = new SizeF() ;

            using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
            {
                size = g.MeasureString(measureString.ToString(), stringFont);
            }

            if (Required == true)
            {
                if (this._choices.Count() < 200)
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        select.Attributes.Add("class", GetControlClass() + "fix-me");
                    }
                    else
                    {
                        select.Attributes.Add("class", GetControlClass());
                    }

                    select.Attributes.Add("data-prompt-position", "topRight:10");
                }
                else
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        select.Attributes.Add("class", GetControlClass() + "fix-me awesomplete Search ");
                    }
                    else
                    {
                        select.Attributes.Add("class", GetControlClass() + " awesomplete Search");
                    }

                    select.Attributes.Add("data-prompt-position", "topRight:10");

                }
            }
            else
            {
                if (this._choices.Count() < 200)
                {
                    //select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                    if ((size.Width) > _ControlWidth)
                    {
                        select.Attributes.Add("class", GetControlClass() + "fix-me ");
                    }
                    else
                    {

                        select.Attributes.Add("class", GetControlClass());
                    }
                    select.Attributes.Add("data-prompt-position", "topRight:10");
                }
                else
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        select.Attributes.Add("class", GetControlClass() + "fix-me awesomplete Search");
                    }
                    else
                    {

                        select.Attributes.Add("class", GetControlClass() + " awesomplete Search");
                    }
                    select.Attributes.Add("data-prompt-position", "topRight:10");

                }

            }

            string IsHiddenStyle = "";
            string IsHighlightedStyle = "";

            if(_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }

            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

            //if (_IsDisabled)
            //{
            //    select.Attributes.Add("disabled", "disabled");
            //}

            string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());
            select.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px ; font-size:" + _ControlFontSize + "pt;" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + ";" + InputFieldStyle);
            select.MergeAttributes(_inputHtmlAttributes);
            html.Append(select.ToString(TagRenderMode.StartTag));

            if (ReadOnly || _IsDisabled)
                {
                var scriptReadOnlyText = new TagBuilder("script");
                //scriptReadOnlyText.InnerHtml = "$(function(){$('#" + inputName + "').attr('disabled','disabled')});";
                scriptReadOnlyText.InnerHtml = "$(function(){  var List = new Array();List.push('" + _key + "');CCE_Disable(List, false);});";
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
                }
            if (this._choices.Count() > 200)
            {

                var scriptReadOnlyText = new TagBuilder("script");
                StringBuilder Script = new StringBuilder();
                Script.Append("$(window).load(function () {  ");
                //Script.Append(" $( '#" + inputName + "' ).next().css( 'width', '" + _ControlWidth.ToString() + "px' );  ");
                Script.Append(" $( '#" + inputName + "' ).next().css( 'left', '" + _left.ToString() + "px' );  ");
                Script.Append(" $( '#" + inputName + "' ).next().css( 'top', '" + (_top + 20).ToString() + "px' );  ");

                Script.Append("});");
                scriptReadOnlyText.InnerHtml = Script.ToString();
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            }

            // initial empty option
            if (this._choices.Count() < 200)
            {

                if (ShowEmptyOption)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("value", null);
                    opt.SetInnerText(EmptyOption);
                    html.Append(opt.ToString());
                }
            }

            //options
            //Build codes relatecondition Script Object

            if (this._choices.Count() < 200 && this.SelectedValue.ToString() != "18")
            {
                switch (FieldTypeId.ToString())
                {
                    case "11":
                        foreach (var choice in _choices)
                        {
                            var opt = new TagBuilder("option");
                            var optSelectedVale = "";
                            if (!string.IsNullOrEmpty(SelectedValue.ToString()))
                            {
                                optSelectedVale = SelectedValue.ToString();//=="1"? "Yes" : "No";
                            }
                            opt.Attributes.Add("value", (choice.Key == "Yes" ? "1" : "0"));
                            if (choice.Key == optSelectedVale.ToString())
                            {
                                opt.Attributes.Add("selected", "selected");

                            }
                            if (choice.Key == "Yes" || choice.Key == "No")
                            {
                                opt.SetInnerText(choice.Key);
                                html.Append(opt.ToString());
                            }
                        }
                        break;
                    case "17":
                        foreach (var choice in _choices)
                        {
                            var opt = new TagBuilder("option");
                            opt.Attributes.Add("value", choice.Key);
                            if (choice.Key == SelectedValue.ToString()) opt.Attributes.Add("selected", "selected");
                            opt.SetInnerText(choice.Key);
                            html.Append(opt.ToString());
                        }

                        break;
                    case "18":
                        foreach (var choice in _choices)
                        {
                            var opt = new TagBuilder("option");
                            opt.Attributes.Add("value", choice.Key);
                            if (choice.Key == SelectedValue.ToString()) opt.Attributes.Add("selected", "selected");
                            opt.SetInnerText(choice.Key);
                            html.Append(opt.ToString());
                        }

                        break;
                    case "19":
                        foreach (var choice in _choices)
                        {
                            var opt = new TagBuilder("option");

                            if (choice.Key.Contains("-"))
                            {
                                string[] keyValue = choice.Key.Split(new char[] { '-' }, 2);
                                string comment = keyValue[0].Trim();
                                string description = keyValue[1].Trim();

                                opt.Attributes.Add("value", comment);

                                if (choice.Value || comment == SelectedValue.ToString())
                                {
                                    opt.Attributes.Add("selected", "selected");
                                }

                                opt.SetInnerText(description);
                            }

                            html.Append(opt.ToString());
                        }
                        break;
                }
            }
            else
            {

                var datalist = new TagBuilder("datalist ");
                datalist.Attributes.Add("id", inputName + "_DataList");
                html.Append(datalist.ToString(TagRenderMode.StartTag));
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("value", choice.Key);
                    if (choice.Key == SelectedValue.ToString())
                    {
                        opt.SetInnerText(choice.Key);
                        opt.Attributes.Add("selected", "selected");
                    }
                    html.Append(opt.ToString());
                }

            }

            html.Append(select.ToString(TagRenderMode.EndTag));

            var hidden = new TagBuilder("input");
            hidden.Attributes.Add("type", "hidden");
            hidden.Attributes.Add("id", inputName + "_hidden");
            hidden.Attributes.Add("name", inputName);
            hidden.Attributes.Add("value", string.Empty);
            html.Append(hidden.ToString(TagRenderMode.SelfClosing));

            var wrapper = new TagBuilder(_fieldWrapper);
            wrapper.Attributes["class"] = _fieldWrapperClass;
            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";

            }
            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml = html.ToString();
            return wrapper.ToString();
        }
예제 #6
0
 private static int GetByteSize(FieldInfo fieldInfo, FieldTypeId id, SerializationHintsAttribute attribute)
 {
     if (attribute != null && attribute.BitPacked > 0)
     {
         switch (id)
         {
             case FieldTypeId.Class:
             case FieldTypeId.Double:
             case FieldTypeId.Single:
             case FieldTypeId.Struct:
             case FieldTypeId.String:
                 throw new NotSupportedException("Cannot specify BitPacket hint for this field.");
         }
         if ((attribute.BitPacked % 8) != 0)
             throw new NotSupportedException("Number of bits in BitPacked must be dividable by 8 to get complecte bytes.");
         return attribute.BitPacked / 8;
     }
     if (id == FieldTypeId.Enum)
     {
         Type underlayingType = Enum.GetUnderlyingType(fieldInfo.FieldType);
         switch (Type.GetTypeCode(underlayingType))
         {
             case TypeCode.Byte:
             case TypeCode.SByte:
                 return 1;
             case TypeCode.Int16:
             case TypeCode.UInt16:
                 return 2;
             case TypeCode.Int32:
             case TypeCode.UInt32:
                 return 4;
             case TypeCode.Int64:
             case TypeCode.UInt64:
                 return 8;
         }
     }
     return byteSizes[(int)id];
 }
예제 #7
0
        public override string RenderHtml()
        {
            int DropDownLimitSize = 1;

            int.TryParse(ConfigurationManager.AppSettings["CACHE_DURATION"].ToString(), out CacheDuration);
            CacheIsOn = ConfigurationManager.AppSettings["CACHE_IS_ON"];//false;
            IsCacheSlidingExpiration = ConfigurationManager.AppSettings["CACHE_SLIDING_EXPIRATION"].ToString();
            var html = new StringBuilder();

            var    inputName  = _form.FieldPrefix + _key;
            string ErrorStyle = string.Empty;

            // prompt
            var prompt = new TagBuilder("label");

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"(\r\n|\r|\n)+");

            string newText = regex.Replace(Prompt.Replace(" ", "&nbsp;"), "<br />");

            string NewPromp = System.Web.Mvc.MvcHtmlString.Create(newText).ToString();


            prompt.InnerHtml = NewPromp;
            prompt.Attributes.Add("for", inputName);
            prompt.Attributes.Add("class", "EpiLabel");
            prompt.Attributes.Add("Id", "label" + inputName);


            StringBuilder StyleValues = new StringBuilder();

            StyleValues.Append(GetControlStyle(_fontstyle.ToString(), _Prompttop.ToString(), _Promptleft.ToString(), null, Height.ToString(), _IsHidden));
            prompt.Attributes.Add("style", StyleValues.ToString());
            html.Append(prompt.ToString());

            // error label
            if (!IsValid)
            {
                //Add new Error to the error Obj

                ErrorStyle = ";border-color: red";
            }


            TagBuilder input = null;

            input = new TagBuilder("input");
            input.Attributes.Add("list", inputName + "_DataList");
            input.Attributes.Add("data-autofirst", "true");
            input.Attributes.Add("value", Value);
            input.Attributes.Add("id", inputName);
            input.Attributes.Add("name", inputName);
            ////////////Check code start//////////////////
            EnterRule FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);

            if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
            {
                input.Attributes.Add("onblur", "return " + _key + "_after();"); //After
                // select.Attributes.Add("onchange", "return " + _key + "_after();"); //After
            }
            EnterRule FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);

            if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
            {
                input.Attributes.Add("onfocus", "return " + _key + "_before();"); //Before
            }
            EnterRule FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);


            if (!string.IsNullOrEmpty(this.RelateCondition))
            {
                input.Attributes.Add("onchange", "SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + SourceTable + "'," + "''" + ",'" + TextColumnName + "','" + RelateCondition + "');"); //click
            }
            ////////////Check code end//////////////////
            int    LargestChoiseLength = 0;
            string measureString       = "";

            foreach (var choise in _choices)
            {
                if (choise.Key.ToString().Length > LargestChoiseLength)
                {
                    LargestChoiseLength = choise.Key.ToString().Length;

                    measureString = choise.Key.ToString();
                }
            }

            // LargestChoiseLength = LargestChoiseLength * _ControlFontSize;

            Font stringFont = new Font(ControlFontStyle, ControlFontSize);

            SizeF size = new SizeF();

            using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
            {
                size = g.MeasureString(measureString.ToString(), stringFont);
            }



            // stringSize = (int) Graphics.MeasureString(measureString.ToString(), stringFont).Width;


            if (_IsRequired == true)
            {
                //awesomplete
                if (this._choices.Count() < DropDownLimitSize)
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        // select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                        input.Attributes.Add("class", GetControlClass() + "fix-me");
                    }
                    else
                    {
                        // select.Attributes.Add("class", GetControlClass() + "text-input");
                        input.Attributes.Add("class", GetControlClass());
                    }
                    input.Attributes.Add("data-prompt-position", "topRight:10");
                }
                else
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        // select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                        input.Attributes.Add("class", GetControlClass() + "fix-me awesomplete Search");
                    }
                    else
                    {
                        // select.Attributes.Add("class", GetControlClass() + "text-input");
                        input.Attributes.Add("class", GetControlClass() + " awesomplete Search");
                    }
                    input.Attributes.Add("data-prompt-position", "topRight:10");
                }
            }
            else
            {
                //awesomplete
                if (this._choices.Count() < DropDownLimitSize)
                {
                    //select.Attributes.Add("class", GetControlClass() + "text-input fix-me");
                    if ((size.Width) > _ControlWidth)
                    {
                        input.Attributes.Add("class", GetControlClass() + "fix-me ");
                    }
                    else
                    {
                        input.Attributes.Add("class", GetControlClass());
                    }
                    input.Attributes.Add("data-prompt-position", "topRight:10");
                }
                else
                {
                    if ((size.Width) > _ControlWidth)
                    {
                        input.Attributes.Add("class", GetControlClass() + "fix-me awesomplete Search");
                    }
                    else
                    {
                        input.Attributes.Add("class", GetControlClass() + " awesomplete Search");
                    }
                    input.Attributes.Add("data-prompt-position", "topRight:10");
                }
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }
            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }

            //if (_IsDisabled)
            //{
            //    select.Attributes.Add("disabled", "disabled");
            //}

            string InputFieldStyle = GetInputFieldStyle(_InputFieldfontstyle.ToString(), _InputFieldfontSize, _InputFieldfontfamily.ToString());

            input.Attributes.Add("style", "position:absolute;left:" + _left.ToString() + "px;top:" + _top.ToString() + "px" + ";width:" + _ControlWidth.ToString() + "px ; font-size:" + ControlFontSize + "pt;" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle + ";" + InputFieldStyle);
            input.MergeAttributes(_inputHtmlAttributes);
            html.Append(input.ToString(TagRenderMode.StartTag));

            if (ReadOnly || _IsDisabled)
            {
                var scriptReadOnlyText = new TagBuilder("script");
                //scriptReadOnlyText.InnerHtml = "$(function(){$('#" + inputName + "').attr('disabled','disabled')});";
                scriptReadOnlyText.InnerHtml = "$(function(){  var List = new Array();List.push('" + _key + "');CCE_Disable(List, false);});";
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            }

            if (this._choices.Count() > DropDownLimitSize)
            {
                var           scriptReadOnlyText = new TagBuilder("script");
                StringBuilder Script             = new StringBuilder();
                Script.Append("$(window).load(function () {  ");

                Script.Append(" $( '#" + inputName + "' ).next().css( 'position', 'absolute' );  ");
                Script.Append(" $( '#" + inputName + "' ).next().css( 'left', '" + _left.ToString() + "px' );  ");
                Script.Append(" $( '#" + inputName + "' ).next().css( 'top', '" + (_top + 29).ToString() + "px' );  ");


                Script.Append("});");
                scriptReadOnlyText.InnerHtml = Script.ToString();
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));


                //var scriptReadOnlyText1 = new TagBuilder("script");
                //StringBuilder Script1 = new StringBuilder();
                //Script1.Append("  $(document).ready(function () {");


                //Script1.Append("$( '#" + inputName + "').blur(function() { ");
                //Script1.Append("SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + _key + "');  ");

                //Script1.Append("});");
                //Script1.Append("});");
                //scriptReadOnlyText1.InnerHtml = Script1.ToString();
                //html.Append(scriptReadOnlyText1.ToString(TagRenderMode.Normal));
            }

            var           scriptReadOnlyText2 = new TagBuilder("script");
            StringBuilder Script2             = new StringBuilder();

            if (!string.IsNullOrEmpty(this.RelateCondition))
            {
                // select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + SourceTable + "'," + "''" + ",'" + TextColumnName + "','" + FieldRelateCondition + "');"); //click
                string RelateConditionScript = "SetCodes_Val(this, '" + _form.SurveyInfo.SurveyId + "', '" + SourceTable + "', " + "''" + ", '" + TextColumnName + "', '" + this.RelateCondition + "');";
                Script2.Append("$('#" + inputName + "' ).on('awesomplete-selectcomplete',function () {  ");

                Script2.Append(RelateConditionScript);
                Script2.Append("});");
                scriptReadOnlyText2.InnerHtml = Script2.ToString();
                html.Append(scriptReadOnlyText2.ToString(TagRenderMode.Normal));
            }

            ///////////////////////////

            var datalist = new TagBuilder("datalist ");

            datalist.Attributes.Add("id", inputName + "_DataList");
            html.Append(datalist.ToString(TagRenderMode.StartTag));

            switch (FieldTypeId.ToString())

            {
            case "17":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    opt.Attributes.Add("value", choice.Key);
                    if (choice.Key == SelectedValue.ToString())
                    {
                        opt.Attributes.Add("selected", "selected");
                    }
                    opt.SetInnerText(choice.Key);
                    html.Append(opt.ToString());
                }
                break;

            case "18":
                //    foreach (var choice in _choices)
                //{
                //    var opt = new TagBuilder("option");
                //    opt.Attributes.Add("style", "");
                //    opt.Attributes.Add("value", choice.Key);
                //    if (choice.Key == SelectedValue.ToString()) opt.Attributes.Add("selected", "selected");
                //    opt.SetInnerText(choice.Key);
                //    html.Append(opt.ToString());
                //}
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("value", choice.Key);
                    opt.SetInnerText(choice.Key);

                    html.Append(opt.ToString());
                }
                break;

            case "19":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    if (choice.Key.Contains("-"))
                    {
                        string[] keyValue    = choice.Key.Split(new char[] { '-' }, 2);
                        string   comment     = keyValue[0].Trim();
                        string   description = keyValue[1].Trim();

                        opt.Attributes.Add("value", comment);

                        if (choice.Value || comment == SelectedValue.ToString())
                        {
                            opt.Attributes.Add("selected", "selected");
                        }

                        opt.SetInnerText(description);
                    }

                    html.Append(opt.ToString());
                }
                break;
            }
            // close select element
            html.Append(input.ToString(TagRenderMode.EndTag));

            // add hidden tag, so that a value always gets sent for select tags
            var hidden1 = new TagBuilder("input");

            hidden1.Attributes.Add("type", "hidden");
            hidden1.Attributes.Add("id", inputName + "_hidden");
            hidden1.Attributes.Add("name", inputName);
            hidden1.Attributes.Add("value", string.Empty);
            html.Append(hidden1.ToString(TagRenderMode.SelfClosing));

            var wrapper = new TagBuilder(_fieldWrapper);

            wrapper.Attributes["class"] = _fieldWrapperClass;
            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";
            }
            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }
예제 #8
0
        public void InitPage()
        {
            Init();

            var entMan = new EntityManager();

            ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object;

            var allCards = AdminPageUtils.GetFieldCards();

            if (FieldTypeId > 19 || FieldTypeId < 1)
            {
                FieldTypeId = 18;
            }

            FieldCard = allCards.First(x => (string)x["type"] == FieldTypeId.ToString());

            if (Enum.TryParse <FieldType>(FieldTypeId.ToString(), out FieldType result))
            {
                Type = result;
            }

            #region << Field Type init >>
            switch (Type)
            {
            case FieldType.AutoNumberField:
                DisplayFormat = "{0}";
                break;

            case FieldType.CurrencyField:
                CurrencyOptions = Helpers.GetAllCurrency().MapTo <SelectOption>();
                break;

            case FieldType.DateTimeField:
                Format = "yyyy-MMM-dd HH:mm";
                break;

            default:
                break;
            }

            #endregion

            #region << Init RecordPermissions >>
            var valueGrid = new List <KeyStringList>();
            PermissionOptions = new List <SelectOption>()
            {
                new SelectOption("read", "read"),
                new SelectOption("update", "update")
            };

            var roles = AdminPageUtils.GetUserRoles();             //Special order is applied

            foreach (var role in roles)
            {
                RoleOptions.Add(new SelectOption(role.Id.ToString(), role.Name));
                var keyValuesObj = new KeyStringList()
                {
                    Key    = role.Id.ToString(),
                    Values = new List <string>()
                };
            }

            #endregion

            #region << Actions >>
            HeaderActions.AddRange(new List <string>()
            {
                PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Create Field", formId: "CreateRecord", btnClass: "btn btn-green btn-sm", iconClass: "ti-plus"),
                PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: ReturnUrl)
            });

            #endregion
        }
예제 #9
0
        public override string RenderHtml()
        {
            var    html       = new StringBuilder();
            var    inputName  = _fieldPrefix + _key;
            string ErrorStyle = string.Empty;
            var    prompt     = new TagBuilder("label");

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"(\r\n|\r|\n)+");
            string newText  = regex.Replace(Prompt.Replace("  ", "&nbsp;"), "<br />");
            string NewPromp = System.Web.Mvc.MvcHtmlString.Create(newText).ToString();

            prompt.InnerHtml = NewPromp;
            prompt.Attributes.Add("for", inputName);
            prompt.Attributes.Add("class", "select");
            prompt.Attributes.Add("Id", "label" + inputName);

            prompt.Attributes.Add("style", "display:block !important; ");
            html.Append(prompt.ToString());
            var OuterDiv = new TagBuilder("div");

            //if (this.IsAndroidfield)
            //{

            OuterDiv.Attributes.Add("class", "mainselection");
            OuterDiv.Attributes.Add("id", inputName + "_mainselection");
            OuterDiv.SetInnerText("");
            html.Append(OuterDiv.ToString(TagRenderMode.StartTag));
            //}
            // if (this.IsAndroidfield)
            // {
            var Div = new TagBuilder("div");

            Div.Attributes.Add("class", "arrow_icon");
            Div.Attributes.Add("id", inputName + "_arrow_icon");
            Div.SetInnerText("");
            if (ReadOnly || _IsDisabled)
            {
                Div.Attributes.Add("style", "background-color:lightgray !important");
            }
            html.Append(Div.ToString());
            //}
            if (!IsValid)
            {
                ErrorStyle = ";border-color: red";
            }

            var select = new TagBuilder("select");

            select.Attributes.Add("id", inputName);
            select.Attributes.Add("name", inputName);

            //if (this.IsAndroidfield)
            //{
            select.Attributes.Add("data-role", "none");
            select.Attributes.Add("data-native-menu", "false");
            // }
            //select.Attributes.Add("data-corners",  "true");
            //select.Attributes.Add("data-icon", "arrow-d");
            //select.Attributes.Add("data-shadow", "true");
            //select.Attributes.Add("data-iconshadow", "true");
            //select.Attributes.Add("data-theme", "c");
            if (_form != null)
            {
                FunctionObjectAfter = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=after&identifier=" + _key);
                if (FunctionObjectAfter != null && !FunctionObjectAfter.IsNull())
                {
                    select.Attributes.Add("onchange", "return " + _key + "_after(this.id);"); //After
                }
                FunctionObjectBefore = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=before&identifier=" + _key);
                if (FunctionObjectBefore != null && !FunctionObjectBefore.IsNull())
                {
                    select.Attributes.Add("onfocus", "return " + _key + "_before(this.id);"); //Before
                }
                FunctionObjectClick = (EnterRule)_form.FormCheckCodeObj.GetCommand("level=field&event=click&identifier=" + _key);
                if (FunctionObjectClick != null && !FunctionObjectClick.IsNull())
                {
                    select.Attributes.Add("onclick", "return " + _key + "_click(this.id);"); //click
                }
                if (this.RelateCondition)
                {
                    select.Attributes.Add("onchange", "return SetCodes_Val(this,'" + _form.SurveyInfo.SurveyId + "','" + SourceTable + "'," + "''" + ",'" + TextColumnName + "','" + FieldRelateCondition + "');"); //click
                }
            }
            int    LargestChoiseLength = 0;
            string measureString       = "";

            foreach (var choice in _choices)
            {
                if (choice.Key.ToString().Length > LargestChoiseLength)
                {
                    LargestChoiseLength = choice.Key.ToString().Length;
                    measureString       = choice.Key.ToString();
                }
            }

            Font stringFont = new Font(ControlFontStyle, _ControlFontSize);

            SizeF size = new SizeF();

            using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
            {
                size = g.MeasureString(measureString.ToString(), stringFont);
            }

            if (Required == true)
            {
                if ((size.Width) > _ControlWidth)
                {
                    select.Attributes.Add("class", "validate[required] text-input fix-me   ");
                }
                else
                {
                    select.Attributes.Add("class", "validate[required] text-input   ");
                }
                select.Attributes.Add("data-prompt-position", "topLeft:10");
            }
            else
            {
                if ((size.Width) > _ControlWidth)
                {
                    select.Attributes.Add("class", "fix-me   ");
                }
            }
            string IsHiddenStyle      = "";
            string IsHighlightedStyle = "";

            if (_IsHidden)
            {
                IsHiddenStyle = "display:none";
            }

            if (_IsHighlighted)
            {
                IsHighlightedStyle = "background-color:yellow";
            }
            //if (_IsDisabled)
            //{
            //    select.Attributes.Add("disabled", "disabled");
            //}
            select.Attributes.Add("style", "" + ErrorStyle + ";" + IsHiddenStyle + ";" + IsHighlightedStyle);
            select.MergeAttributes(_inputHtmlAttributes);
            html.Append(select.ToString(TagRenderMode.StartTag));

            if (ReadOnly || _IsDisabled)
            {
                var scriptReadOnlyText = new TagBuilder("script");
                //scriptReadOnlyText.InnerHtml = "$(function(){$('#" + inputName + "').attr('disabled','disabled')});";
                scriptReadOnlyText.InnerHtml = "$(function(){  var List = new Array();List.push('" + _key + "');CCE_Disable(List, false);});";
                html.Append(scriptReadOnlyText.ToString(TagRenderMode.Normal));
            }
            //var optgroup = new TagBuilder("optgroup ");
            //if (this.IsAndroidfield)
            //{


            //    optgroup.Attributes.Add("label", null);
            //    optgroup.SetInnerText("");
            //   // html.Append(optgroup.ToString());
            //    html.Append(optgroup.ToString(TagRenderMode.StartTag));
            //}

            if (ShowEmptyOption)
            {
                var opt = new TagBuilder("option");
                opt.Attributes.Add("value", null);
                opt.SetInnerText(EmptyOption);
                opt.Attributes.Add("style", "");
                html.Append(opt.ToString());
            }

            switch (FieldTypeId.ToString())
            {
            case "11":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    var optSelectedVale = "";
                    if (!string.IsNullOrEmpty(SelectedValue.ToString()))
                    {
                        optSelectedVale = SelectedValue.ToString();    //=="1"? "Yes" : "No";
                    }
                    opt.Attributes.Add("value", (choice.Key == "Yes" ? "1" : "0"));
                    if (choice.Key == optSelectedVale.ToString())
                    {
                        opt.Attributes.Add("selected", "selected");
                    }
                    if (choice.Key == "Yes" || choice.Key == "No")
                    {
                        opt.SetInnerText(choice.Key);
                        html.Append(opt.ToString());
                    }
                }
                break;

            case "17":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    opt.Attributes.Add("value", choice.Key);
                    if (choice.Key == SelectedValue.ToString())
                    {
                        opt.Attributes.Add("selected", "selected");
                    }
                    opt.SetInnerText(choice.Key);
                    html.Append(opt.ToString());
                }
                break;

            case "18":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    opt.Attributes.Add("value", choice.Key);
                    if (choice.Key == SelectedValue.ToString())
                    {
                        opt.Attributes.Add("selected", "selected");
                    }
                    opt.SetInnerText(choice.Key);
                    html.Append(opt.ToString());
                }
                break;

            case "19":
                foreach (var choice in _choices)
                {
                    var opt = new TagBuilder("option");
                    opt.Attributes.Add("style", "");
                    if (choice.Key.Contains("-"))
                    {
                        string[] keyValue    = choice.Key.Split(new char[] { '-' }, 2);
                        string   comment     = keyValue[0].Trim();
                        string   description = keyValue[1].Trim();

                        opt.Attributes.Add("value", comment);

                        if (choice.Value || comment == SelectedValue.ToString())
                        {
                            opt.Attributes.Add("selected", "selected");
                        }

                        opt.SetInnerText(description);
                    }

                    html.Append(opt.ToString());
                }
                break;
            }
            //if (this.IsAndroidfield)
            //{

            //    html.Append(optgroup.ToString(TagRenderMode.EndTag));
            //}
            html.Append(select.ToString(TagRenderMode.EndTag));
            //  if (this.IsAndroidfield)
            // {

            html.Append(OuterDiv.ToString(TagRenderMode.EndTag));
            // }
            var hidden = new TagBuilder("input");

            hidden.Attributes.Add("type", "hidden");
            hidden.Attributes.Add("id", inputName + "_hidden");
            hidden.Attributes.Add("name", inputName);
            hidden.Attributes.Add("value", string.Empty);
            html.Append(hidden.ToString(TagRenderMode.SelfClosing));

            var    wrapper        = new TagBuilder(_fieldWrapper);
            string AndroidClasses = "";

            // if (this.IsAndroidfield)
            // {
            AndroidClasses = " ui-field-contain   ";
            // }
            if (!IsValid)
            {
                wrapper.Attributes["class"] = _fieldWrapperClass + " SelectNotValid" + AndroidClasses + "   ";
            }
            else
            {
                wrapper.Attributes["class"] = _fieldWrapperClass + AndroidClasses + "   ";
            }

            if (_IsHidden)
            {
                wrapper.Attributes["style"] = "display:none";
            }

            wrapper.Attributes["id"] = inputName + "_fieldWrapper";
            wrapper.InnerHtml        = html.ToString();
            return(wrapper.ToString());
        }
        private static void DeSerializeField(MemoryStream stream, object obj, FieldInfo fieldInfo)
        {
            SerializationHintsAttribute attribute = GetSerializationHintsAttribute(fieldInfo);
            FieldTypeId id = GetFieldTypeId(fieldInfo, attribute);

            if (id == FieldTypeId.NonSerializableFieldType)
            {
                return;
            }
            int   byteCount = GetByteSize(fieldInfo, id, attribute);
            ulong binValue;

            if (id != FieldTypeId.String && id != FieldTypeId.Class && id != FieldTypeId.Struct)
            {
                binValue = ReadUnsignedLong(stream, byteCount);
            }
            else
            {
                binValue = 0;
            }
            object value = null;

            switch (id)
            {
            case FieldTypeId.Boolean:
                value = binValue != 0;
                break;

            case FieldTypeId.Byte:
                value = (byte)binValue;
                break;

            case FieldTypeId.SByte:
                value = (sbyte)binValue;
                break;

            case FieldTypeId.Char:
                value = (char)binValue;
                break;

            case FieldTypeId.UInt16:
                value = (ushort)binValue;
                break;

            case FieldTypeId.Int16:
                value = (short)binValue;
                break;

            case FieldTypeId.UInt32:
                value = (uint)binValue;
                break;

            case FieldTypeId.Int32:
                value = (int)binValue;
                break;

            case FieldTypeId.UInt64:
                value = (ulong)binValue;
                break;

            case FieldTypeId.Int64:
                value = (long)binValue;
                break;

            case FieldTypeId.Enum:
                Type underlayingType = Enum.GetUnderlyingType(fieldInfo.FieldType);
                switch (Type.GetTypeCode(underlayingType))
                {
                case TypeCode.Byte:
                    value = (byte)binValue;
                    break;

                case TypeCode.SByte:
                    value = (sbyte)binValue;
                    break;

                case TypeCode.Int16:
                    value = (short)binValue;
                    break;

                case TypeCode.UInt16:
                    value = (ushort)binValue;
                    break;

                case TypeCode.Int32:
                    value = (int)binValue;
                    break;

                case TypeCode.UInt32:
                    value = (uint)binValue;
                    break;

                case TypeCode.Int64:
                    value = (long)binValue;
                    break;

                case TypeCode.UInt64:
                    value = (ulong)binValue;
                    break;
                }
                break;

            case FieldTypeId.Single:
                value = BitConverter.ToSingle(BitConverter.GetBytes((uint)binValue), 0);
                break;

            case FieldTypeId.Double:
                value = BitConverter.ToDouble(BitConverter.GetBytes((ulong)binValue), 0);
                break;

            case FieldTypeId.DateTime:
                value = new DateTime((long)binValue);
                break;

            case FieldTypeId.TimeSpan:
                value = new TimeSpan((long)binValue);
                break;

            case FieldTypeId.String:
                uint count = ReadCompressedUnsigned(stream);
                if (count != uint.MaxValue)
                {
                    byte[] bytes = new byte[count];
                    stream.Read(bytes, 0, (int)count);
                    value = Encoding.UTF8.GetString(bytes);
                }
                else
                {
                    value = null;
                }
                break;

            case FieldTypeId.Struct:
            case FieldTypeId.Class:
                value = DeSerializeObject(stream, fieldInfo.FieldType);
                break;

            default:
                throw new NotSupportedException();
            }
            fieldInfo.SetValue(obj, value);
        }
        private static void SerializeField(MemoryStream stream, object obj, FieldInfo fieldInfo)
        {
            object value = fieldInfo.GetValue(obj);
            ulong  binValue;
            SerializationHintsAttribute attribute = GetSerializationHintsAttribute(fieldInfo);
            FieldTypeId id = GetFieldTypeId(fieldInfo, attribute);

            switch (id)
            {
            case FieldTypeId.Boolean:
                binValue = ((bool)value) ? (ulong)1 : (ulong)0;
                break;

            case FieldTypeId.Byte:
                binValue = (byte)value;
                break;

            case FieldTypeId.SByte:
                binValue = (ulong)(sbyte)value;
                break;

            case FieldTypeId.Char:
                binValue = (char)value;
                break;

            case FieldTypeId.UInt16:
                binValue = (ushort)value;
                break;

            case FieldTypeId.Int16:
                binValue = (ulong)(short)value;
                break;

            case FieldTypeId.UInt32:
                binValue = (uint)value;
                break;

            case FieldTypeId.Int32:
                binValue = (ulong)(int)value;
                break;

            case FieldTypeId.UInt64:
                binValue = (ulong)value;
                break;

            case FieldTypeId.Int64:
                binValue = (ulong)(long)value;
                break;

            case FieldTypeId.Enum:
                Type underlayingType = Enum.GetUnderlyingType(fieldInfo.FieldType);
                switch (Type.GetTypeCode(underlayingType))
                {
                case TypeCode.Byte:
                    binValue = (byte)value;
                    break;

                case TypeCode.SByte:
                    binValue = (ulong)(sbyte)value;
                    break;

                case TypeCode.Int16:
                    binValue = (ulong)(short)value;
                    break;

                case TypeCode.UInt16:
                    binValue = (ushort)value;
                    break;

                case TypeCode.Int32:
                    binValue = (ulong)(int)value;
                    break;

                case TypeCode.UInt32:
                    binValue = (uint)value;
                    break;

                case TypeCode.Int64:
                    binValue = (ulong)(long)value;
                    break;

                case TypeCode.UInt64:
                    binValue = (ulong)value;
                    break;

                default:
                    throw new NotSupportedException("Invalid enum.");
                }
                break;

            case FieldTypeId.Single:
                binValue = BitConverter.ToUInt32(BitConverter.GetBytes((float)value), 0);
                break;

            case FieldTypeId.Double:
                binValue = BitConverter.ToUInt64(BitConverter.GetBytes((double)value), 0);
                break;

            case FieldTypeId.DateTime:
                binValue = (ulong)((DateTime)value).Ticks;
                break;

            case FieldTypeId.TimeSpan:
                binValue = (ulong)((TimeSpan)value).Ticks;
                break;

            case FieldTypeId.String:
                if (value != null)
                {
                    byte[] bytes = Encoding.UTF8.GetBytes((string)value);
                    WriteCompressedUnsigned(stream, (uint)bytes.Length);
                    stream.Write(bytes, 0, bytes.Length);
                }
                else
                {
                    WriteCompressedUnsigned(stream, uint.MaxValue);
                }
                return;

            case FieldTypeId.Struct:
                SerializeObject(stream, value, fieldInfo.FieldType);
                return;

            case FieldTypeId.Class:
                if (value == null)
                {
                    throw new NotSupportedException("Fields which are classes must not be null.");
                }
                SerializeObject(stream, value, fieldInfo.FieldType);
                return;

            case FieldTypeId.NonSerializableFieldType:
                return;

            default:
                throw new NotSupportedException();
            }
            int byteCount = GetByteSize(fieldInfo, id, attribute);

            WriteUnsignedLong(stream, binValue, byteCount);
        }
예제 #12
0
        public void InitPage(bool isGet = true)
        {
            IsPostgisInstalled = DbRepository.IsPostgisInstalled();

            var entMan = new EntityManager();

            ErpEntity = entMan.ReadEntity(ParentRecordId ?? Guid.Empty).Object;

            var allCards = AdminPageUtils.GetFieldCards();

            if (FieldTypeId == 20) //RelationField
            {
                throw new Exception("RelationField is unsupported field type");
            }

            FieldCard = allCards.First(x => (string)x["type"] == FieldTypeId.ToString());

            if (Enum.TryParse <FieldType>(FieldTypeId.ToString(), out FieldType result))
            {
                Type = result;
            }

            if (isGet)
            {
                #region << Field Type init >>
                switch (Type)
                {
                case FieldType.AutoNumberField:
                    DisplayFormat = "{0}";
                    break;

                case FieldType.CurrencyField:
                    CurrencyOptions = Helpers.GetAllCurrency().MapTo <SelectOption>();
                    break;

                case FieldType.DateTimeField:
                    Format = "yyyy-MMM-dd HH:mm";
                    break;

                case FieldType.GeographyField:
                {
                    foreach (int format in Enum.GetValues(typeof(GeographyFieldFormat)))
                    {
                        string value = format.ToString();
                        string name  = ((GeographyFieldFormat)format).ToString();
                        GeographyFormats.Add(new SelectOption(value, name));
                    }
                }
                break;

                default:
                    break;
                }

                #endregion

                #region << Init RecordPermissions >>
                var valueGrid = new List <KeyStringList>();
                PermissionOptions = new List <SelectOption>()
                {
                    new SelectOption("read", "read"),
                    new SelectOption("update", "update")
                };

                var roles = AdminPageUtils.GetUserRoles(); //Special order is applied

                foreach (var role in roles)
                {
                    RoleOptions.Add(new SelectOption(role.Id.ToString(), role.Name));
                    var keyValuesObj = new KeyStringList()
                    {
                        Key    = role.Id.ToString(),
                        Values = new List <string>()
                    };
                }

                #endregion
            }

            #region << Actions >>

            if (Type != FieldType.GeographyField)
            {
                HeaderActions.AddRange(new List <string>()
                {
                    PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Create Field", formId: "CreateRecord", btnClass: "btn btn-green btn-sm", iconClass: "fa fa-plus"),
                    PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: ReturnUrl)
                });
            }
            else if (Type == FieldType.GeographyField)
            {
                if (IsPostgisInstalled)
                {
                    HeaderActions.Add(PageUtils.GetActionTemplate(PageUtilsActionType.SubmitForm, label: "Create Field", formId: "CreateRecord", btnClass: "btn btn-green btn-sm", iconClass: "fa fa-plus"));
                }

                HeaderActions.Add(PageUtils.GetActionTemplate(PageUtilsActionType.Cancel, returnUrl: ReturnUrl));
            }
            #endregion
        }