Database.cs 5.0 KB
Newer Older
cdy816's avatar
cdy816 已提交
1 2
using Cdy.Tag;
using System;
cdy816's avatar
cdy816 已提交
3 4 5 6 7 8 9 10 11 12 13
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DBDevelopService.Controllers
{
    public class Database
    {
        public string Name { get; set; }
        public string Desc { get; set; }
    }
cdy816's avatar
cdy816 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

    /// <summary>
    /// 
    /// </summary>
    public class TagGroup
    {
        public string Name { get; set; }

        public string Parent { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class WebApiTag
    {
        /// <summary>
        /// 
        /// </summary>
cdy816's avatar
cdy816 已提交
33
        public WebApiRealTag RealTag { get; set; }
cdy816's avatar
cdy816 已提交
34 35 36 37 38 39 40

        /// <summary>
        /// 
        /// </summary>
        public Cdy.Tag.HisTag HisTag { get; set; }
    }

cdy816's avatar
cdy816 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    public class WebApiRealTag
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Type { get; set; }
        public string Group { get; set; }
        public string Desc { get; set; }
        public string LinkAddress { get; set; }
        public int ReadWriteType { get; set; }
        public string Convert { get; set; }
        public double MaxValue { get; set; }
        public double MinValue { get; set; }
        public byte Precision { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="realtag"></param>
        /// <returns></returns>
        public static WebApiRealTag CreatFromTagbase(Tagbase realtag)
        {
            WebApiRealTag tag = new WebApiRealTag();
            tag.CloneFromRealTag(realtag);
            return tag;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="realtag"></param>
        public void CloneFromRealTag(Tagbase realtag)
        {
            this.Id = realtag.Id;
            this.Name = realtag.Name;
            this.Type = (byte)realtag.Type;
            this.Group = realtag.Group;
            this.Desc = realtag.Desc;
            this.LinkAddress = realtag.LinkAddress;
            this.ReadWriteType = (int)realtag.ReadWriteType;
            this.Convert = realtag.Conveter != null ? realtag.Conveter.SeriseToString() : "";
            if(realtag is NumberTagBase)
            {
                this.MaxValue = (realtag as NumberTagBase).MaxValue;
                this.MinValue = (realtag as NumberTagBase).MinValue;
            }
            if(realtag is FloatingTagBase)
            {
                this.Precision = (realtag as FloatingTagBase).Precision;
            }
        }

        public Tagbase ConvertToTagbase()
        {
            Cdy.Tag.Tagbase re = null;
            switch (this.Type)
            {
                case (int)(Cdy.Tag.TagType.Bool):
                    re = new Cdy.Tag.BoolTag();
                    break;
                case (int)(Cdy.Tag.TagType.Byte):
                    re = new Cdy.Tag.ByteTag();
                    break;
                case (int)(Cdy.Tag.TagType.DateTime):
                    re = new Cdy.Tag.DateTimeTag();
                    break;
                case (int)(Cdy.Tag.TagType.Double):
                    re = new Cdy.Tag.DoubleTag();
                    break;
                case (int)(Cdy.Tag.TagType.Float):
                    re = new Cdy.Tag.FloatTag();
                    break;
                case (int)(Cdy.Tag.TagType.Int):
                    re = new Cdy.Tag.IntTag();
                    break;
                case (int)(Cdy.Tag.TagType.UInt):
                    re = new Cdy.Tag.UIntTag();
                    break;
                case (int)(Cdy.Tag.TagType.ULong):
                    re = new Cdy.Tag.ULongTag();
                    break;
                case (int)(Cdy.Tag.TagType.UShort):
                    re = new Cdy.Tag.UShortTag();
                    break;
                case (int)(Cdy.Tag.TagType.Long):
                    re = new Cdy.Tag.LongTag();
                    break;
                case (int)(Cdy.Tag.TagType.Short):
                    re = new Cdy.Tag.ShortTag();
                    break;
                case (int)(Cdy.Tag.TagType.String):
                    re = new Cdy.Tag.StringTag();
                    break;
            }
            if (re != null)
            {
                re.Name = this.Name;
                re.LinkAddress = this.LinkAddress;
                re.Group = this.Group;
                re.Desc = this.Desc;
                re.Id = (int)this.Id;
                re.ReadWriteType = (Cdy.Tag.ReadWriteMode)this.ReadWriteType;
                if (!string.IsNullOrEmpty(this.Convert))
                {
                    re.Conveter = this.Convert.DeSeriseToValueConvert();
                }
                if (re is Cdy.Tag.NumberTagBase)
                {
                    (re as Cdy.Tag.NumberTagBase).MaxValue = this.MaxValue;
                    (re as Cdy.Tag.NumberTagBase).MinValue = this.MinValue;
                }

                if (re is Cdy.Tag.FloatingTagBase)
                {
                    (re as Cdy.Tag.FloatingTagBase).Precision = (byte)this.Precision;
                }
            }

            return re;
        }


    }


cdy816's avatar
cdy816 已提交
165

cdy816's avatar
cdy816 已提交
166
}