Example #1
0
        public FieldCoordinate(XField xCoord, YField yCoord)
        {
            XCoord = xCoord;
            YCoord = yCoord;

            hashCode = new { xCoord, yCoord }.GetHashCode();
        }
        void ReleaseDesignerOutlets()
        {
            if (XField != null)
            {
                XField.Dispose();
                XField = null;
            }

            if (YField != null)
            {
                YField.Dispose();
                YField = null;
            }

            if (WidthField != null)
            {
                WidthField.Dispose();
                WidthField = null;
            }

            if (HeightField != null)
            {
                HeightField.Dispose();
                HeightField = null;
            }
        }
 public void SetProperties(XField xField, Field field)
 {
     if (field is TField typedField)
     {
         SetProperties(xField, typedField);
     }
 }
Example #4
0
        private static string XCoordToString(XField xCoord)
        {
            switch (xCoord)
            {
            case XField.A: return("a");

            case XField.B: return("b");

            case XField.C: return("c");

            case XField.D: return("d");

            case XField.E: return("e");

            case XField.F: return("f");

            case XField.G: return("g");

            case XField.H: return("h");

            case XField.I: return("i");
            }

            return("error");
        }
 public static string BuildField(XField field)
 {
     return(string.Format("{0} {1} {2} {3} {5} {4}",
                          field.name,
                          field.type.ToString(),
                          string.IsNullOrEmpty(field.length) ? "" : string.Format("({0})", field.length),
                          field.nulo ? "NULL" : "NOT NULL",
                          field.unique ? "UNIQUE" : "",
                          string.IsNullOrEmpty(field.defVal) ? "" : string.Format("DEFAULT {0}", field.defVal)));
 }
        public JField ConvertField(XField field, ParentObjectInfo parentInfo)
        {
            if (field.ID == null)
            {
                throw new Exception("Объект field не может быть преобразован в JField");
            }

            if (string.IsNullOrEmpty(parentInfo.CardVersion))
            {
                throw new Exception("У поля " + field.Alias + " отсутствует версия (карточки)");
            }

            if (parentInfo.CardLibID == null || parentInfo.CardLibID == Guid.Empty)
            {
                throw new Exception("У поля " + field.Alias + " отсутствует идентификатор библиотеки карточек");
            }

            if (parentInfo.CardID == null || parentInfo.CardID == Guid.Empty)
            {
                throw new Exception("У поля " + field.Alias + " отсутствует идентификатор карточки");
            }

            if (parentInfo.SectionID == null || parentInfo.SectionID == Guid.Empty)
            {
                throw new Exception("У поля " + field.Alias + " отсутствует идентификатор секции");
            }

            var version = new JFieldVersion
            {
                SystemVersion = parentInfo.SystemVersion,
                Version       = parentInfo.CardVersion,
                FieldType     = field.Type,
                RefType       = field.RefType,
                RefSection    = field.RefSection,
                DefaultValue  = field.DefaultValue,
                EnumValues    = field.Enum != null?field.Enum.Select(t => $"{t.Alias}[{t.Value}]").ToArray() : new string[0],
            };

            var jField = new JField
            {
                ID              = field.ID,
                Alias           = field.Alias,
                Name            = GetRuName(field.Names),
                CardLibID       = parentInfo.CardLibID,
                CardID          = parentInfo.CardID,
                ParentSectionID = parentInfo.SectionID,
                Versions        = new List <JFieldVersion> {
                    version
                }
            };

            return(jField);
        }
        private static bool GetBackgroundColor(XField xField, out Color value)
        {
            XAttribute attribute = xField.Attribute(ColumnNames.BACKGROUND_COLOR);

            if (attribute == null || attribute.Value == "")
            {
                value = Color.Empty;
                return(false);
            }
            value = Color.FromArgb((int)attribute);
            return(true);
        }
        private static bool TryGetOptions(XField xField, out List <string> value)
        {
            string options = (string)xField.Attribute(ColumnNames.LIST);
            int    index   = options.IndexOf(OptionsSeparator);

            if (index != -1)
            {
                options = options.Substring(0, index);
            }
            value = options.Split(Constants.LIST_SEPARATOR).ToList();
            return(true);
        }
        protected override bool TryGetValue(XField xField, out TProperty value)
        {
            XAttribute attribute = xField.Attribute(AttributeName);

            if (attribute == null || attribute.Value == "")
            {
                value = default(TProperty);
                return(false);
            }
            value = (TProperty)Converter.ConvertFromString(attribute.Value);
            return(true);
        }
 public void SetProperty(XField xField, TField field)
 {
     try
     {
         if (TryGetValue(xField, out TProperty value))
         {
             Property.SetValue(field, value);
         }
     }
     catch (Exception ex)
     {
         throw new FieldMappingException(xField, Property.Name, ex);
     }
 }
 public void SetProperties(XField xField, TField field)
 {
     foreach (IFieldMapping <TField> mapping in Mappings)
     {
         try
         {
             mapping.SetProperty(xField, field);
         }
         catch (FieldMappingException ex)
         {
             OnError(ex);
         }
     }
 }
Example #12
0
        protected void AddPage(Page page, XView xView)
        {
            View view = page.GetView();

            Progress?.Report($"Adding page: {view.Name}/{page.Name}");
            XPage xPage = XPage.Create(page);

            xView.Add(xPage);
            foreach (DataRow field in GetFields(page))
            {
                string fieldName = field.Field <string>(ColumnNames.NAME);
                Progress?.Report($"Adding field: {view.Name}/{page.Name}/{fieldName}");
                xPage.Add(XField.Create(field));
            }
        }
Example #13
0
        private Field InstantiateField(XField xField, Page page)
        {
            View view = page.GetView();

            Progress?.Report($"Adding field: {view.Name}/{page.Name}/{xField.Name}");
            Field field = xField.Instantiate(page);

            if (context.FieldNameGenerator.Exists(field.Name))
            {
                field.Name = context.FieldNameGenerator.MakeUnique(field.Name);
                Progress?.Report($"Renamed field: {field.Name}");
            }
            MapSourceTableName(field as TableBasedDropDownField);
            MapRelatedViewId(field as RelatedViewField);
            field.SaveToDb();
            context.FieldIdMap[xField.FieldId] = field.Id;
            return(field);
        }
        private static bool TryGetFont(XField xField, string propertyName, out Font value)
        {
            ICollection <string> keys = new string[] {
                "Family",
                "Size",
                "Style"
            };
            IDictionary <string, XAttribute> attributes = keys.ToDictionary(
                key => key,
                key => xField.Attribute($"{propertyName}{key}"));

            if (attributes.Values.Any(attribute => attribute == null || attribute.Value == ""))
            {
                value = null;
                return(false);
            }
            FontFamily family = new FontFamily((string)attributes["Family"]);
            float      size   = (float)attributes["Size"];
            FontStyle  style  = (FontStyle)Enum.Parse(typeof(FontStyle), (string)attributes["Style"]);

            value = new Font(family, size, style);
            return(true);
        }
 protected abstract bool TryGetValue(XField xField, out TProperty value);
Example #16
0
        /// <summary>单线程</summary>
        public void Single()
        {
            Random rnd = new Random((Int32)DateTime.Now.Ticks);

            //选择数据库
            Int32 n = DAL.ConnStrs.Count;

            n = ID % n;
            Int32 m = 0;

            foreach (String item in DAL.ConnStrs.Keys)
            {
                if (m == n)
                {
                    Dal = DAL.Create(item);
                    break;
                }
                m++;
            }

            //测试数据库
            String dbName = Session.DatabaseName;

            Boolean dbExist = (Boolean)MetaData.SetSchema(DDLSchema.DatabaseExist, dbName);

            if (dbExist)
            {
                XTrace.WriteLine("删除数据库:{0}", dbName);
                MetaData.SetSchema(DDLSchema.DropDatabase, dbName);
            }

            //创建数据库
            //if (!dbExist)
            {
                XTrace.WriteLine("创建数据库:{0}", dbName);
                MetaData.SetSchema(DDLSchema.CreateDatabase, dbName, null);
            }

            //创建数据表
            XTable table = new XTable();

            table.Name        = "xtest";
            table.DbType      = DatabaseType.Access;
            table.Columns     = new List <XField>();
            table.Description = "测试表";

            //检查数据表
            if ((Boolean)MetaData.SetSchema(DDLSchema.TableExist, table.Name))
            {
                XTrace.WriteLine("删除数据表:{0}", table.Name);
                MetaData.SetSchema(DDLSchema.DropTable, table.Name);
            }

            //创建字段
            #region 创建字段
            XField field = table.CreateField();
            field.ID          = table.Columns.Count + 1;
            field.Name        = "ID";
            field.DataType    = typeof(Int32);
            field.Identity    = true;
            field.PrimaryKey  = true;
            field.Description = "编号";
            table.Columns.Add(field);

            field             = table.CreateField();
            field.ID          = table.Columns.Count + 1;
            field.Name        = "Name";
            field.DataType    = typeof(String);
            field.Length      = 55;
            field.Nullable    = false;
            field.Description = "名称";
            table.Columns.Add(field);

            field             = table.CreateField();
            field.ID          = table.Columns.Count + 1;
            field.Name        = "ParentID";
            field.DataType    = typeof(Int32);
            field.Nullable    = false;
            field.Default     = "99";
            field.Description = "父编号";
            table.Columns.Add(field);

            field             = table.CreateField();
            field.ID          = table.Columns.Count + 1;
            field.Name        = "Value";
            field.DataType    = typeof(Double);
            field.Scale       = 10;
            field.Nullable    = false;
            field.Default     = "1.8";
            field.Description = "值";
            table.Columns.Add(field);

            field             = table.CreateField();
            field.ID          = table.Columns.Count + 1;
            field.Name        = "OccurTime";
            field.DataType    = typeof(DateTime);
            field.Nullable    = false;
            field.Default     = "now()";
            field.Description = "时间";
            table.Columns.Add(field);

            field             = table.CreateField();
            field.ID          = table.Columns.Count + 1;
            field.Name        = "IsEnable";
            field.DataType    = typeof(Boolean);
            field.Nullable    = false;
            field.Default     = "1";
            field.Description = "有效";
            table.Columns.Add(field);

            field             = table.CreateField();
            field.ID          = table.Columns.Count + 1;
            field.Name        = "Description";
            field.DataType    = typeof(String);
            field.Length      = 5000;
            field.Nullable    = true;
            field.Default     = "无";
            field.Description = "描述";
            table.Columns.Add(field);

            XTrace.WriteLine("创建数据表:{0}", table.Name);
            MetaData.SetSchema(DDLSchema.CreateTable, table);
            #endregion

            //插入数据
            Int32 dataMax = rnd.Next(100, 300);
            XTrace.WriteLine("插入数据:{0}", dataMax);
            String sql = String.Empty;
            //是否使用事务
            Boolean EnableTran = rnd.Next(0, 2) == 0;
            if (EnableTran)
            {
                XTrace.WriteLine("使用事务!");
                Dal.BeginTransaction();
            }
            StringBuilder sb        = new StringBuilder();
            Boolean       debug_old = DbSession.ShowSQL;
            DAL.Debug = false;
            for (int i = 0; i < dataMax; i++)
            {
                String name = "测试" + i.ToString("0000");
                sb.Append("无" + i + " ");
                String des = sb.ToString();
                Int32  pid = i % 99;

                if (pid == 0)
                {
                    sql = String.Format("Insert into {2}(Name, Description) values('{0}','{1}')", name, des, table.Name);
                }
                else if (i % 29 == 0)
                {
                    sql = String.Format("Insert into {2}(Name, ParentID) values('{0}',{1})", name, pid, table.Name);
                }
                else
                {
                    sql = String.Format("Insert into {3}(Name, ParentID, Description) values('{0}',{1},'{2}')", name, pid, des, table.Name);
                }

                Int64 n2 = Dal.InsertAndGetIdentity(sql, table.Name);
                if (i + 1 != n2)
                {
                    throw new Exception("插入返回编号不匹配!");
                }
            }
            DAL.Debug = debug_old;
            if (EnableTran)
            {
                Dal.Commit();
            }

            //查询
            XTrace.WriteLine("查询测试!");

            XTrace.WriteLine("普通分页测试!");
            DataSet ds = Dal.Select("select * from xtest", 33, 44, "ID", "test");
            if (ds.Tables[0].Rows.Count != 44)
            {
                throw new Exception("查询返回记录数不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[0]["ID"] != 33 + 1)
            {
                throw new Exception("查询返回记录不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[43]["ID"] != 33 + 44)
            {
                throw new Exception("查询返回记录不匹配!");
            }

            ds = Dal.Select("select * from xtest order by name", 33, 44, "ID", "test");
            if (ds.Tables[0].Rows.Count != 44)
            {
                throw new Exception("查询返回记录数不匹配!");
            }
            if ((String)ds.Tables[0].Rows[0]["name"] != "测试" + (33).ToString("0000"))
            {
                throw new Exception("查询返回记录不匹配!");
            }
            if ((String)ds.Tables[0].Rows[43]["name"] != "测试" + (33 + 44 - 1).ToString("0000"))
            {
                throw new Exception("查询返回记录不匹配!");
            }

            XTrace.WriteLine("自增数字分页测试!");
            ds = Dal.Select("select * from xtest", 33, 44, "ID asc", "test");
            if (ds.Tables[0].Rows.Count != 44)
            {
                throw new Exception("查询返回记录数不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[0]["ID"] != 33 + 1)
            {
                throw new Exception("查询返回记录不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[43]["ID"] != 33 + 44)
            {
                throw new Exception("查询返回记录不匹配!");
            }

            ds = Dal.Select("select * from xtest order by id", 33, 44, "ID asc", "test");
            if (ds.Tables[0].Rows.Count != 44)
            {
                throw new Exception("查询返回记录数不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[0]["ID"] != 33 + 1)
            {
                throw new Exception("查询返回记录不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[43]["ID"] != 33 + 44)
            {
                throw new Exception("查询返回记录不匹配!");
            }

            ds = Dal.Select("select * from xtest order by id", 33, 44, "ID", "test");
            if (ds.Tables[0].Rows.Count != 44)
            {
                throw new Exception("查询返回记录数不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[0]["ID"] != 33 + 1)
            {
                throw new Exception("查询返回记录不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[43]["ID"] != 33 + 44)
            {
                throw new Exception("查询返回记录不匹配!");
            }

            ds = Dal.Select("select * from xtest order by id desc", 33, 44, "ID", "test");
            if (ds.Tables[0].Rows.Count != 44)
            {
                throw new Exception("查询返回记录数不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[0]["ID"] != dataMax - 33)
            {
                throw new Exception("查询返回记录不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[43]["ID"] != dataMax - 33 - 44 + 1)
            {
                throw new Exception("查询返回记录不匹配!");
            }

            ds = Dal.Select("select * from xtest order by id desc", 33, 44, "ID asc", "test");
            if (ds.Tables[0].Rows.Count != 44)
            {
                throw new Exception("查询返回记录数不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[0]["ID"] != dataMax - 33)
            {
                throw new Exception("查询返回记录不匹配!");
            }
            if ((Int32)ds.Tables[0].Rows[43]["ID"] != dataMax - 33 - 44 + 1)
            {
                throw new Exception("查询返回记录不匹配!");
            }

            ds = Dal.Select("select * from xtest order by name", 33, 44, "ID unknown", "test");
            if (ds.Tables[0].Rows.Count != 44)
            {
                throw new Exception("查询返回记录数不匹配!");
            }
            if ((String)ds.Tables[0].Rows[0]["name"] != "测试" + (33).ToString("0000"))
            {
                throw new Exception("查询返回记录不匹配!");
            }
            if ((String)ds.Tables[0].Rows[43]["name"] != "测试" + (33 + 44 - 1).ToString("0000"))
            {
                throw new Exception("查询返回记录不匹配!");
            }

            //n = Dal.SelectCount("select * from xtest", 33, 44, "ID desc", "test");
            //if (n != 44) throw new Exception("查询返回记录数不匹配!");

            //更新
            XTrace.WriteLine("更新测试!");
            n   = (Int32)ds.Tables[0].Rows[0]["ParentID"];
            sql = "Update xtest set ParentID=998877 where ID=33+1";
            Dal.Execute(sql, "test");

            ds = Dal.Select("select * from xtest", 33, 44, "ID", "xtest");
            m  = (Int32)ds.Tables[0].Rows[0]["ParentID"];
            if (m != 998877)
            {
                throw new Exception("更新失败!");
            }

            //删除
            dataMax = rnd.Next(50, 100);
            XTrace.WriteLine("删除测试!" + dataMax);
            n = Dal.SelectCount("select * from xtest", "xtest");
            XTrace.WriteLine("删除前" + n);

            for (int i = 0; i < dataMax; i++)
            {
                sql = String.Format("Delete from xtest where id={0}", i + 1);
                Dal.Execute(sql, "test");
            }

            m = Dal.SelectCount("select * from xtest", "xtest");
            XTrace.WriteLine("删除后" + m);
            if (m != n - dataMax)
            {
                throw new Exception("删除失败!");
            }

            //新增字段
            field             = table.CreateField();
            field.ID          = table.Columns.Count + 1;
            field.Name        = "Extend";
            field.DataType    = typeof(String);
            field.Length      = 99;
            field.Default     = "没有";
            field.Description = "扩展";

            XTrace.WriteLine("新增字段:{0}", field);
            MetaData.SetSchema(DDLSchema.AddColumn, table.Name, field);

            //修改字段
            field.Length = 555;
            XTrace.WriteLine("修改字段:{0}", field);
            MetaData.SetSchema(DDLSchema.AlterColumn, table.Name, field);

            //删除字段
            XTrace.WriteLine("删除字段:{0}", field);
            MetaData.SetSchema(DDLSchema.DropColumn, table.Name, field.Name);

            //删除数据表
            XTrace.WriteLine("删除数据表:{0}", table.Name);
            MetaData.SetSchema(DDLSchema.DropTable, table.Name);
            if ((Boolean)MetaData.SetSchema(DDLSchema.TableExist, table.Name))
            {
                throw new Exception("删除表失败!");
            }

            //删除数据库
            //if (!dbExist)
            {
                XTrace.WriteLine("删除数据库:{0}", Dal.ConnName);
                MetaData.SetSchema(DDLSchema.DropDatabase, Dal.ConnName);
            }
        }
 public FieldMappingException(XField xField, string propertyName, Exception inner)
     : base(null, inner)
 {
     XField       = xField;
     PropertyName = propertyName;
 }
 private static bool TryGetPromptFont(XField xField, out Font value)
 {
     return(TryGetFont(xField, nameof(RenderableField.PromptFont), out value));
 }
 protected override bool TryGetValue(XField xField, out TProperty value)
 {
     return(Delegate(xField, out value));
 }