Esempio n. 1
0
 private void ProcessEnum(MemberHandler m, object value)
 {
     string v = (value == null) ? "" : value.ToString();
     if(value != null && value is string)
     {
         v = "";
     }
     _html.tag("select").id(_id).name(_name);
     foreach (string s in Enum.GetNames(m.MemberType))
     {
         object e = Enum.Parse(m.MemberType, s);
         _html.tag("option").attr("value", s);
         if (s == v)
         {
             _html.attr("selected", "true");
         }
         _html.text(StringHelper.EnumToString(e)).end.over();
     }
     _html.end.over();
     if (value != null && value is string)
     {
         _html.include("<script type=\"text/javascript\">document.getElementById(\"")
             .include(_id)
             .include("\").value = '")
             .include(value.ToString())
             .include("';</script>");
     }
 }
Esempio n. 2
0
 private void ProcessMember(MemberHandler m)
 {
     Type mft = m.MemberType;
     if (mft.IsEnum)
     {
         ProcessEnum(m);
     }
     else if (mft == typeof(bool))
     {
         ProcessBoolean(m);
     }
     else if (mft == typeof(string))
     {
         ProcessString(m);
     }
     else if (mft == typeof(DateTime))
     {
         ProcessDateTime(m);
     }
     else if (mft.IsValueType)
     {
         ProcessValueType(m);
     }
     else
     {
         throw new ApplicationException(string.Format("Out of scope of member {0} of class: {1}", m.MemberInfo.Name, _type.FullName));
     }
 }
Esempio n. 3
0
 internal ObjectInfo(Type t)
 {
     this.HandleType = t;
     this.CheckTypeIsModel();
     List<MemberHandler> members = this.GetMembers();
     this.KeyMembers = members.FindAll(m => m.Is.Key).ToArray();
     this.CheckKeys();
     this.SimpleMembers = this.GetSimpleMembers(members);
     this.RelationMembers = members.FindAll(m => !m.Is.SimpleField).ToArray();
     this.Members = this.GetAllMembers();
     this.From = GetObjectFromClause(t);
     this.AllowSqlLog = this.IsAllowSqlLog();
     this.HasSystemKey = this.GetHasSystemKey();
     this.HasRelation = members.Exists(delegate(MemberHandler m)
     {
         if ((!m.Is.HasOne && !m.Is.HasMany) && !m.Is.HasAndBelongsToMany)
         {
             return m.Is.BelongsTo;
         }
         return true;
     });
     this.LockVersion = members.FirstOrDefault(m => m.Is.LockVersion);
     this.HasOnePrimaryKey = this.GetHasOnePrimaryKey();
     this.SoftDeleteColumnName = this.GetSoftDeleteColumnName();
     this.DeleteToTableName = this.GetDeleteToTableName();
     this.ContextName = this.GetContextName();
     this.QueryRequiredFields = this.GetQueryRequiredFields();
     this.Cacheable = this.HandleType.HasAttribute<CacheableAttribute>(false);
     this.GetIndexes();
     SetManyToManyFrom(this, this.From.MainModelName, this.Members);
 }
Esempio n. 4
0
        public ControlMapper(MemberHandler m, string id, string name, object value)
        {
            this._id = id;
            this._name = name;

            _html = HtmlBuilder.New;

            ProcessField(m.Is.LazyLoad ? m.MemberType.GetGenericArguments()[0] : m.MemberType, m, value);
        }
Esempio n. 5
0
 public override void ProcessBelongsTo(UpdateStatementBuilder builder, MemberHandler m, object fk)
 {
     object v;
     if (_LoadedColumns.TryGetValue(m.Name, out v)) {
         if (NotEqual(v, fk)) {
             base.ProcessBelongsTo(builder, m, fk);
         }
     }
 }
Esempio n. 6
0
 public override void ProcessSimpleMember(UpdateStatementBuilder builder, MemberHandler m, object n)
 {
     object v;
     if (_LoadedColumns.TryGetValue(m.Name, out v)) {
         if (NotEqual(v, n)) {
             base.ProcessSimpleMember(builder, m, n);
         }
     }
 }
Esempio n. 7
0
 private static string GetBtName(MemberHandler mh)
 {
     if(mh.Is.BelongsTo)
     {
         var t = mh.MemberType.GetGenericArguments()[0];
         var ctx = ModelContext.GetInstance(t);
         return ctx.Info.From.MainTableName;
     }
     return null;
 }
Esempio n. 8
0
 public override void ProcessLazyLoad(UpdateStatementBuilder builder, MemberHandler m, object value, Type type)
 {
     object v;
     if (_LoadedColumns.TryGetValue(m.Name, out v)) {
         if (!NotEqual(value, v)) {
             return;
         }
     }
     base.ProcessLazyLoad(builder, m, value, type);
 }
Esempio n. 9
0
 private void ProcessDateTime(MemberHandler m, object value)
 {
     _html.input.id(_id).name(_name).type("text").attr("cols", 19).attr("onclick", "PickDate(this)");
     if (m.Is.AutoSavedValue)
     {
         _html.attr("disabled", "true");
     }
     if (value != null)
     {
         _html.value(value);
     }
     _html.end.over();
 }
Esempio n. 10
0
        protected void ProcessEnum(MemberHandler m)
        {
            Type t = m.MemberType;
            _b.asp("DropDownList", _id);

            foreach (string s in Enum.GetNames(t))
            {
                object e = Enum.Parse(t, s);
                string text = StringHelper.EnumToString(e);
                _b.tag("asp:ListItem").attr("Text", text).attr("Value", s).end.over();
            }
            _b.end.over();
        }
Esempio n. 11
0
 private static KeyValue GetKeyValue(ObjectInfo oi, MemberHandler fi)
 {
     if (fi.Is.BelongsTo)
     {
         Type type = fi.MemberType.GetGenericArguments()[0];
         MemberHandler handler = (oi.HandleType == type) ? oi.KeyMembers[0] : ModelContext.GetInstance(type).Info.KeyMembers[0];
         return new KeyValue(fi.Name, null, handler.MemberType);
     }
     if (fi.Is.LazyLoad)
     {
         return new KeyValue(fi.Name, null, fi.MemberType.GetGenericArguments()[0]);
     }
     return new KeyValue(fi.Name, null, fi.MemberType);
 }
Esempio n. 12
0
 private static Type GetType(MemberHandler fh)
 {
     if (fh.Is.BelongsTo)
     {
         var ctx = ModelContext.GetInstance(fh.MemberType.GetGenericArguments()[0]);
         if (ctx.Info.KeyMembers != null && ctx.Info.KeyMembers.Length == 1)
         {
             return ctx.Info.KeyMembers[0].MemberType;
         }
     }
     else if(fh.Is.LazyLoad)
     {
         return fh.MemberType.GetGenericArguments()[0];
     }
     return fh.MemberType;
 }
Esempio n. 13
0
 private static void CheckMemberCast(MemberHandler member, object value, StringBuilder text)
 {
     if ((value == null || value == DBNull.Value) && member.Is.AllowNull)
     {
         return;
     }
     if (member.MemberType.IsEnum && value is Int32)
     {
         return;
     }
     if (member.MemberType == typeof(long) && value.GetType () == typeof(int)) {
         return;
     }
     if (member.MemberType != value.GetType())
     {
         text.AppendFormat("The type of member [{0}] is [{1}] but the type in Database of it is [{2}]\n",
                           member.Name, member.MemberType, value.GetType());
     }
 }
Esempio n. 14
0
 protected void ProcessBoolean(MemberHandler m)
 {
     _b.asp("CheckBox", _id).end.over();
 }
Esempio n. 15
0
 private bool ValidateStringField(string field, MemberHandler fh, StringBuilder errMsg)
 {
     if (field == null || (field == "" && _emptyAsNull))
     {
         if (fh.Is.AllowNull)
         {
             return true;
         }
         errMsg.Append(_notAllowNullText).Append(_separatorText);
         return false;
     }
     bool isValid = true;
     field = field.Trim();
     if (fh.MaxLength > 0)
     {
         isValid &= IsValidStringField(field, fh.MinLength, fh.MaxLength, !fh.Is.Unicode,
             string.IsNullOrEmpty(fh.LengthErrorMessage) ? _lengthText : fh.LengthErrorMessage, errMsg);
     }
     if (!string.IsNullOrEmpty(fh.Regular))
     {
         bool iv = Regex.IsMatch(field, fh.Regular);
         if (!iv)
         {
             if (string.IsNullOrEmpty(fh.RegularErrorMessage))
             {
                 errMsg.Append(_notMatchedText).Append(_separatorText);
             }
             else
             {
                 errMsg.Append(fh.RegularErrorMessage).Append(_separatorText);
             }
         }
         isValid &= iv;
     }
     return isValid;
 }
Esempio n. 16
0
 internal ColumnInfo(MemberHandler mh)
     : this(mh.Name, GetType(mh), mh.Is.Key, mh.Is.DbGenerate, mh.Is.AllowNull, mh.Is.Unicode, mh.MaxLength, mh.DecimalPart, GetBtName(mh))
 {
 }
Esempio n. 17
0
 protected void ProcessString(MemberHandler m)
 {
     int iml = m.MaxLength;
     _b.asp("TextBox", _id);
     if (iml > 0)
     {
         _b.attr("MaxLength", iml).attr("Columns", iml > 60 ? 60 : iml);
     }
     else
     {
         _b.attr("TextMode", "MultiLine").attr("Columns", 60).attr("Rows", 10);
     }
     _b.end.over();
 }
Esempio n. 18
0
 public virtual void ProcessBelongsTo(UpdateStatementBuilder builder, MemberHandler m, object fk)
 {
     builder.Values.Add(new KeyOpValue(m.Name, fk, fk == null ? typeof(long) : fk.GetType()));
 }
Esempio n. 19
0
 private object GetDefaultValue(MemberHandler member, DbDialect dialect)
 {
     if(member.Is.AllowNull)
     {
         return null;
     }
     var t = member.MemberType;
     if(t == typeof(string) || t == typeof(byte[]))
     {
         return dialect.EmptyString;
     }
     if(t == typeof(DateTime) || t == typeof(Date) || t == typeof(Time))
     {
         return dialect.QuoteDateTimeValue(dialect.DefaultDateTimeString());
     }
     if(t == typeof(Guid))
     {
         return "'" + Guid.NewGuid().ToString() + "'";
     }
     return 0;
 }
Esempio n. 20
0
 public static HtmlBuilder Map(MemberHandler m, string id, string name, object value)
 {
     var c = new ControlMapper(m, id, name, value);
     return c._html;
 }
Esempio n. 21
0
 public virtual void ProcessLazyLoad(UpdateStatementBuilder builder, MemberHandler m, object value, Type type)
 {
     builder.Values.Add (new KeyOpValue (m.Name, value, type));
 }
Esempio n. 22
0
 private void ProcessString(MemberHandler m, object value)
 {
     if (m.MaxLength < 256 && m.MaxLength > 0)
     {
         _html.input.id(_id).name(_name).type("text");
         int size = m.MaxLength > 100 ? 100 : m.MaxLength;
         _html.attr("maxlength", m.MaxLength).attr("size", size);
         if (value != null)
         {
             _html.value(value);
         }
         _html.end.over();
     }
     else
     {
         string s = (value == null) ? "" : value.ToString();
         _html.tag("textarea").id(_id).name(_name).attr("cols", 50).attr("rows", 5).include(s).end.over();
     }
 }
Esempio n. 23
0
 public virtual void ProcessSimpleMember(UpdateStatementBuilder builder, MemberHandler m, object n)
 {
     builder.Values.Add(new KeyOpValue(m.Name, n, m.MemberType));
 }
Esempio n. 24
0
 private void ProcessField(Type fieldType, MemberHandler m, object value)
 {
     if (fieldType.IsEnum)
     {
         ProcessEnum(m, value);
     }
     else if (fieldType == typeof(bool))
     {
         ProcessBoolean(value);
     }
     else if (fieldType == typeof(string))
     {
         ProcessString(m, value);
     }
     else if (fieldType == typeof(DateTime))
     {
         ProcessDateTime(m, value);
     }
     else if (fieldType == typeof(Date))
     {
         ProcessDateTime(m, value);
     }
     else if (fieldType == typeof(Time))
     {
         ProcessDateTime(m, value);
     }
     else if (fieldType.IsValueType)
     {
         ProcessValueType(value);
     }
     else
     {
         throw new WebException(string.Format("Out of scope of member {0}", m.MemberInfo.Name));
     }
 }
Esempio n. 25
0
 private void SetErrorMessage(MemberHandler fh, StringBuilder errMsg, bool isValid, string tableName)
 {
     if (errMsg.Length > _separatorTextLength) { errMsg.Length -= _separatorTextLength; }
     if (!isValid)
     {
         string n = (_includeClassName ? tableName + "." + fh.ShowString : fh.ShowString);
         _errorMessages[fh.Name] = string.Format(_invalidFieldText, n, errMsg);
     }
     IsValid &= isValid;
 }
Esempio n. 26
0
 protected void ProcessValueType(MemberHandler m)
 {
     _b.asp("TextBox", _id).attr("MaxLength", 20).attr("Columns", 20).end.over();
 }
Esempio n. 27
0
 private void ProcessHasAndBelongsToMany(IDbObject obj, MemberHandler f, ILazyLoading ho)
 {
     object obj2 = ho.Read();
     if (obj2 != null)
     {
         Util.TryEnumerate(obj2, RelationSave);
     }
     var relations = (IHasAndBelongsToManyRelations)ho;
     foreach (object obj3 in relations.SavedNewRelations)
     {
         SetManyToManyRelation(f.MemberType.GetGenericArguments()[0], Handler.GetKeyValue(obj), obj3);
     }
     foreach (object obj4 in relations.RemovedRelations)
     {
         RemoveManyToManyRelation(f.MemberType.GetGenericArguments()[0], Handler.GetKeyValue(obj), obj4);
     }
 }
Esempio n. 28
0
        private bool ValidateByteArrayField(byte[] field, MemberHandler fh, StringBuilder errMsg)
        {
            if (field == null)
            {
                if (fh.Is.AllowNull)
                {
                    return true;
                }
                errMsg.Append(_notAllowNullText).Append(_separatorText);
                return false;
            }
            bool isValid = true;
            if(fh.MaxLength > 0)
            {
                string errorText = string.IsNullOrEmpty(fh.LengthErrorMessage)
                                          ? _lengthText
                                          : fh.LengthErrorMessage;

                isValid &= IsValidField(field.Length, fh.MinLength, fh.MaxLength, errMsg, errorText);
            }
            return isValid;
        }
Esempio n. 29
0
 private static string GetCrossTableName(MemberHandler f, string unmappedMainTableName, string unmappedSlaveTableName)
 {
     string crossTableName;
     if (!string.IsNullOrEmpty(f.CrossTableName))
     {
         crossTableName = f.CrossTableName;
     }
     else
     {
         crossTableName = (unmappedMainTableName.CompareTo(unmappedSlaveTableName) > 0) 
             ? (unmappedSlaveTableName + "_" + unmappedMainTableName) 
             : (unmappedMainTableName + "_" + unmappedSlaveTableName);
     }
     return (NameMapper.Instance.Prefix + crossTableName);
 }
Esempio n. 30
0
        protected void ProcessDateTime(MemberHandler m)
        {
            _b.asp("TextBox", _id).attr("Columns", 23);

            if (m.Is.CreatedOn || m.Is.UpdatedOn)
            {
                _b.attr("Enabled", "False");
            }
            else
            {
                _b.attr("onclick", "getDateString(this, oCalendarEn)");
            }
            _b.end.over();
        }