TagViewModel.cs 44.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
//==============================================================
//  Copyright (C) 2020  Inc. All rights reserved.
//
//==============================================================
//  Create by 种道洋 at 2020/1/2 10:04:50.
//  Version 1.0
//  种道洋
//==============================================================

using System;
using System.Collections.Generic;
using System.Text;
cdy816's avatar
cdy816 已提交
13
using System.Linq;
cdy816's avatar
cdy816 已提交
14 15 16
using System.Windows.Input;
using DBDevelopClientApi;
using DBInStudio.Desktop.ViewModel;
cdy816's avatar
cdy816 已提交
17
using Cdy.Tag;
18

cdy816's avatar
cdy816 已提交
19
namespace DBInStudio.Desktop
20 21 22 23
{
    /// <summary>
    /// 
    /// </summary>
cdy816's avatar
cdy816 已提交
24
    public class TagViewModel : ViewModelBase
25 26 27
    {

        #region ... Variables  ...
cdy816's avatar
cdy816 已提交
28 29 30
        private Cdy.Tag.Tagbase mRealTagMode;
        private Cdy.Tag.HisTag mHisTagMode;

31 32 33 34
        public static string[] mTagTypeList;
        public static string[] mRecordTypeList;
        public static string[] mCompressTypeList;
        public static string[] mReadWriteModeList;
cdy816's avatar
cdy816 已提交
35

cdy816's avatar
cdy816 已提交
36 37 38 39 40 41 42 43
        /// <summary>
        /// 
        /// </summary>
        public static Dictionary<string, string[]> Drivers;

        private string mDriverName;
        private string mRegistorName;

cdy816's avatar
cdy816 已提交
44
        private bool mHasHisTag;
45

cdy816's avatar
cdy816 已提交
46 47 48 49
        private CompressParameterModelBase mCompressParameterModel;

        private string[] mRegistorList;

50 51
        private ICommand mConvertEditCommand;

cdy816's avatar
cdy816 已提交
52 53
        private ICommand mConvertRemoveCommand;

cdy816's avatar
cdy816 已提交
54 55
        private bool mIsSelected;

56 57 58 59 60 61 62
        #endregion ...Variables...

        #region ... Events     ...

        #endregion ...Events...

        #region ... Constructor...
cdy816's avatar
cdy816 已提交
63 64 65 66 67 68
        /// <summary>
        /// 
        /// </summary>
        static TagViewModel()
        {
            InitEnumType();
cdy816's avatar
cdy816 已提交
69 70
            mCompressTypeList = new string[] 
            {
cdy816's avatar
cdy816 已提交
71
                Res.Get("NoneCompress"),
cdy816's avatar
cdy816 已提交
72 73 74 75
                Res.Get("LosslessCompress"),
                Res.Get("DeadAreaCompress"),
                Res.Get("SlopeCompress")
            };
cdy816's avatar
cdy816 已提交
76 77 78 79 80 81 82 83 84 85
        }

        public TagViewModel()
        {

        }

        public TagViewModel(Cdy.Tag.Tagbase realTag, Cdy.Tag.HisTag histag)
        {
            this.mRealTagMode = realTag;
cdy816's avatar
cdy816 已提交
86
            this.HisTagMode = histag;
cdy816's avatar
cdy816 已提交
87
            CheckLinkAddress();
cdy816's avatar
cdy816 已提交
88
        }
89 90 91 92

        #endregion ...Constructor...

        #region ... Properties ...
cdy816's avatar
cdy816 已提交
93 94 95 96 97 98

        /// <summary>
        /// 
        /// </summary>
        public bool IsChanged { get; set; }

cdy816's avatar
cdy816 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111
        /// <summary>
        /// 
        /// </summary>
        public bool IsSelected 
        { 
            get { return mIsSelected; } 
            set 
            { 
                mIsSelected = value; 
                OnPropertyChanged("IsSelected"); 
            }
        }

cdy816's avatar
cdy816 已提交
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
        /// <summary>
        /// 是否新建
        /// </summary>
        public bool IsNew { get; set; }

        /// <summary>
            /// 
            /// </summary>
        public CompressParameterModelBase CompressParameterModel
        {
            get
            {
                return mCompressParameterModel;
            }
            set
            {
                if (mCompressParameterModel != value)
                {
                    mCompressParameterModel = value;
                    OnPropertyChanged("CompressParameterModel");
                }
            }
        }


cdy816's avatar
cdy816 已提交
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 165 166 167 168
        /// <summary>
        /// 实时变量配置
        /// </summary>
        public Cdy.Tag.Tagbase RealTagMode
        {
            get
            {
                return mRealTagMode;
            }
            set
            {
                if (mRealTagMode != value)
                {
                    mRealTagMode = value;
                }
            }
        }

        /// <summary>
        /// 历史变量配置
        /// </summary>
        public Cdy.Tag.HisTag HisTagMode
        {
            get
            {
                return mHisTagMode;
            }
            set
            {
                if (mHisTagMode != value)
                {
                    mHisTagMode = value;
cdy816's avatar
cdy816 已提交
169
                    CheckRecordTypeParameterModel();
cdy816's avatar
cdy816 已提交
170
                }
cdy816's avatar
cdy816 已提交
171
                mHasHisTag = mHisTagMode != null;
cdy816's avatar
cdy816 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
            }
        }

        /// <summary>
        /// 名字
        /// </summary>
        public string Name
        {
            get
            {
                return mRealTagMode != null ? mRealTagMode.Name : string.Empty;
            }
            set
            {
                if (mRealTagMode != null && mRealTagMode.Name != value)
                {
                    mRealTagMode.Name = value;
cdy816's avatar
cdy816 已提交
189 190
                    IsChanged = true;
                    OnPropertyChanged("Name");
cdy816's avatar
cdy816 已提交
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
                }
            }
        }

        /// <summary>
        /// 描述
        /// </summary>
        public string Desc
        {
            get
            {
                return mRealTagMode != null ? mRealTagMode.Desc : string.Empty;
            }
            set
            {
                if (mRealTagMode != null && mRealTagMode.Desc != value)
                {
                    mRealTagMode.Desc = value;
cdy816's avatar
cdy816 已提交
209 210
                    IsChanged = true;
                    OnPropertyChanged("Desc");
cdy816's avatar
cdy816 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string[] TagTypeList
        {
            get
            {
                return mTagTypeList;
            }
        }

226 227 228 229 230 231 232 233 234 235 236 237
        /// <summary>
        /// 
        /// </summary>
        public string[] ReadWriteModeList
        {
            get
            {
                return mReadWriteModeList;
            }
        }


cdy816's avatar
cdy816 已提交
238 239 240 241 242 243 244 245 246 247 248
        /// <summary>
        /// 
        /// </summary>
        public string[] RecordTypeList
        {
            get
            {
                return mRecordTypeList;
            }
        }

cdy816's avatar
cdy816 已提交
249 250 251 252 253 254 255 256 257 258 259
        /// <summary>
        /// 
        /// </summary>
        public string[] CompressTypeList
        {
            get
            {
                return mCompressTypeList;
            }
        }

cdy816's avatar
cdy816 已提交
260 261 262 263 264 265 266
        /// <summary>
            /// 
            /// </summary>
        public string[] RegistorList
        {
            get
            {
cdy816's avatar
cdy816 已提交
267
                
cdy816's avatar
cdy816 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
                return mRegistorList;
            }
            set
            {
                if (mRegistorList != value)
                {
                    mRegistorList = value;
                }
                OnPropertyChanged("RegistorList");
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public string[] DriverList
        {
            get
            {
                if (Drivers != null)
                {
                    return Drivers.Keys.ToArray();
                }
                else
                {
                    return null;
                }
            }
        }


300

cdy816's avatar
cdy816 已提交
301 302 303 304 305 306 307 308 309 310 311 312 313 314
        /// <summary>
        /// 类型
        /// </summary>
        public int Type
        {
            get
            {
                return mRealTagMode != null ? (int)mRealTagMode.Type : -1;
            }
            set
            {
                if (mRealTagMode != null && (int)mRealTagMode.Type != value)
                {
                    ChangeTagType((Cdy.Tag.TagType)value);
cdy816's avatar
cdy816 已提交
315 316 317
                    IsChanged = true;
                    OnPropertyChanged("Type");
                    OnPropertyChanged("TypeString");
cdy816's avatar
cdy816 已提交
318
                    OnPropertyChanged("IsNumberTag");
cdy816's avatar
cdy816 已提交
319 320 321
                    OnPropertyChanged("Precision");
                    OnPropertyChanged("MaxValue");
                    OnPropertyChanged("MinValue");
cdy816's avatar
cdy816 已提交
322 323 324 325
                }
            }
        }

cdy816's avatar
cdy816 已提交
326 327 328 329 330 331 332 333 334 335 336
        /// <summary>
        /// 
        /// </summary>
        public string TypeString
        {
            get
            {
                return mRealTagMode.Type.ToString();
            }
        }

cdy816's avatar
cdy816 已提交
337 338 339 340 341 342 343 344 345 346 347 348 349 350
        /// <summary>
        /// 组
        /// </summary>
        public string Group
        {
            get
            {
                return mRealTagMode != null ? mRealTagMode.Group : string.Empty;
            }
            set
            {
                if (mRealTagMode != null && mRealTagMode.Group != value)
                {
                    mRealTagMode.Group = value;
cdy816's avatar
cdy816 已提交
351 352
                    IsChanged = true;
                    OnPropertyChanged("Group");
cdy816's avatar
cdy816 已提交
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
                }
            }
        }

        /// <summary>
        /// 关联外部地址
        /// </summary>
        public string LinkAddress
        {
            get
            {
                return mRealTagMode != null ? mRealTagMode.LinkAddress : string.Empty;
            }
            set
            {
                if (mRealTagMode != null && mRealTagMode.LinkAddress != value)
                {
                    mRealTagMode.LinkAddress = value;
cdy816's avatar
cdy816 已提交
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
                    IsChanged = true;
                    OnPropertyChanged("LinkAddress");
                }
            }
        }

        /// <summary>
            /// 
            /// </summary>
        public string DriverName
        {
            get
            {
                return mDriverName;
            }
            set
            {
                if (mDriverName != value)
                {
                    mDriverName = value;
cdy816's avatar
cdy816 已提交
391
                    mRegistorName = string.Empty;
cdy816's avatar
cdy816 已提交
392
                    IsChanged = true;
cdy816's avatar
cdy816 已提交
393 394 395 396 397 398 399 400 401 402
                    LinkAddress = DriverName + ":" + RegistorName;
                    if(Drivers!=null&&Drivers.ContainsKey(mDriverName))
                    {
                        RegistorList = Drivers[mDriverName];
                    }
                    else
                    {
                        RegistorList = null;
                    }
                    OnPropertyChanged("DriverName");
cdy816's avatar
cdy816 已提交
403
                    OnPropertyChanged("RegistorName");
cdy816's avatar
cdy816 已提交
404 405 406 407
                }
            }
        }

cdy816's avatar
cdy816 已提交
408 409 410
        /// <summary>
            /// 
            /// </summary>
cdy816's avatar
cdy816 已提交
411 412 413 414 415 416 417 418 419 420 421 422
        public string RegistorName
        {
            get
            {
                return mRegistorName;
            }
            set
            {
                if (mRegistorName != value)
                {
                    mRegistorName = value;
                    LinkAddress = DriverName + ":" + RegistorName;
cdy816's avatar
cdy816 已提交
423
                    IsChanged = true;
cdy816's avatar
cdy816 已提交
424 425 426 427 428 429 430 431 432
                    OnPropertyChanged("RegistorName");
                }
            }
        }


        /// <summary>
        /// 
        /// </summary>
cdy816's avatar
cdy816 已提交
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
        public bool HasHisTag
        {
            get
            {
                return mHasHisTag;
            }
            set
            {
                if (mHasHisTag != value)
                {
                    mHasHisTag = value;
                    if(!value)
                    {
                        mHisTagMode = null;
                    }
                    else
                    {
cdy816's avatar
cdy816 已提交
450
                        mHisTagMode = new Cdy.Tag.HisTag() { Id = this.mRealTagMode.Id,TagType=mRealTagMode.Type };
cdy816's avatar
cdy816 已提交
451
                    }
cdy816's avatar
cdy816 已提交
452 453
                    CheckRecordTypeParameterModel();
                    IsChanged = true;
cdy816's avatar
cdy816 已提交
454
                }
cdy816's avatar
cdy816 已提交
455 456 457 458 459
                OnPropertyChanged("RecordType");
                OnPropertyChanged("CompressCircle");
                OnPropertyChanged("CompressType");
                OnPropertyChanged("HasHisTag");
                OnPropertyChanged("IsTimerRecord");
cdy816's avatar
cdy816 已提交
460
                OnPropertyChanged("RecordTypeString");
cdy816's avatar
cdy816 已提交
461 462 463 464
            }
        }


cdy816's avatar
cdy816 已提交
465 466 467 468 469 470 471 472 473 474 475 476 477 478
        /// <summary>
        /// 
        /// </summary>
        public int RecordType
        {
            get
            {
                return mHisTagMode != null ? (int)mHisTagMode.Type : -1;
            }
            set
            {
                if (mHisTagMode != null && (int)mHisTagMode.Type != value)
                {
                    mHisTagMode.Type = (Cdy.Tag.RecordType)value;
cdy816's avatar
cdy816 已提交
479 480 481 482
                    IsChanged = true;
                    OnPropertyChanged("RecordType");
                    OnPropertyChanged("RecordTypeString");
                    OnPropertyChanged("IsTimerRecord");
cdy816's avatar
cdy816 已提交
483

cdy816's avatar
cdy816 已提交
484
                    
cdy816's avatar
cdy816 已提交
485 486 487 488
                }
            }
        }

cdy816's avatar
cdy816 已提交
489 490 491 492 493 494 495 496 497 498 499
        /// <summary>
        /// 
        /// </summary>
        public bool IsTimerRecord
        {
            get
            {
                return RecordType == (int)(Cdy.Tag.RecordType.Timer);
            }
        }

500 501 502 503 504 505 506
        /// <summary>
            /// 
            /// </summary>
        public string ConvertString
        {
            get
            {
507 508 509 510 511
                return mRealTagMode.Conveter != null ? mRealTagMode.Conveter.SeriseToString() : string.Empty;
            }
            set
            {
                ;
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
            }
        }

        /// <summary>
            /// 
            /// </summary>
        public IValueConvert Convert
        {
            get
            {
                return mRealTagMode.Conveter;
            }
            set
            {
                if (mRealTagMode.Conveter != value)
                {
                    mRealTagMode.Conveter = value;
cdy816's avatar
cdy816 已提交
529
                    IsChanged = true;
530
                }
531 532
                OnPropertyChanged("Convert");
                OnPropertyChanged("ConvertString");
533 534 535 536 537 538 539 540 541 542 543 544
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public ICommand ConvertEditCommand
        {
            get
            {
                if(mConvertEditCommand==null)
                {
545 546 547 548 549 550 551 552 553
                    mConvertEditCommand = new RelayCommand(() => {

                        ConvertEditViewModel cmm = new ConvertEditViewModel();
                        if (mRealTagMode.Conveter != null)
                            cmm.SetSelectConvert(mRealTagMode.Conveter.SeriseToString());
                        if(cmm.ShowDialog().Value)
                        {
                            Convert = cmm.CurrentSelectModel.Model;
                        }
554 555 556 557 558 559
                    });
                }
                return mConvertEditCommand;
            }
        }

cdy816's avatar
cdy816 已提交
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
        /// <summary>
        /// 
        /// </summary>
        public ICommand ConvertRemoveCommand
        {
            get
            {
                if(mConvertRemoveCommand==null)
                {
                    mConvertRemoveCommand = new RelayCommand(() => {
                        Convert = null;
                    },()=> { return Convert != null; });
                }
                return mConvertRemoveCommand;
            }
        }


578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594



        /// <summary>
        /// 
        /// </summary>
        public int ReadWriteMode
        {
            get
            {
                return (int)mRealTagMode.ReadWriteType;
            }
            set
            {
                if ((int)mRealTagMode.ReadWriteType != value)
                {
                    mRealTagMode.ReadWriteType = (Cdy.Tag.ReadWriteMode)value;
cdy816's avatar
cdy816 已提交
595
                    IsChanged = true;
596
                }
cdy816's avatar
cdy816 已提交
597 598
                OnPropertyChanged("ReadWriteMode");
                OnPropertyChanged("ReadWriteModeString");
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public double AllowMaxValue
        {
            get
            {
                return mRealTagMode is Cdy.Tag.NumberTagBase ? (mRealTagMode as Cdy.Tag.NumberTagBase).AllowMaxValue : 0;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public double AllowMinValue
        {
            get
            {
                return mRealTagMode is Cdy.Tag.NumberTagBase ? (mRealTagMode as Cdy.Tag.NumberTagBase).AllowMinValue : 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public double MaxValue
        {
            get
            {
                return mRealTagMode is Cdy.Tag.NumberTagBase ? (mRealTagMode as Cdy.Tag.NumberTagBase).MaxValue : 0;
            }
            set
            {
                if (mRealTagMode is Cdy.Tag.NumberTagBase)
                {
                    if (value <= AllowMaxValue)
                    {
                        (mRealTagMode as Cdy.Tag.NumberTagBase).MaxValue = value;
                    }
cdy816's avatar
cdy816 已提交
642
                    IsChanged = true;
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
                    OnPropertyChanged("MaxValue");
                }
            }
        }


        /// <summary>
            /// 
            /// </summary>
        public double MinValue
        {
            get
            {
                return mRealTagMode is Cdy.Tag.NumberTagBase ? (mRealTagMode as Cdy.Tag.NumberTagBase).MinValue : 0;
            }
            set
            {
                if (mRealTagMode is Cdy.Tag.NumberTagBase)
                {
                    if(value>=AllowMinValue)
                    (mRealTagMode as Cdy.Tag.NumberTagBase).MinValue = value;
cdy816's avatar
cdy816 已提交
664
                    IsChanged = true;
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
                    OnPropertyChanged("MinValue");
                }
            }
        }

        public bool IsNumberTag
        {
            get
            {
                return mRealTagMode is Cdy.Tag.NumberTagBase;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public byte Precision
        {
            get
            {
                return mRealTagMode is Cdy.Tag.FloatingTagBase ? (mRealTagMode as Cdy.Tag.FloatingTagBase).Precision : (byte)0;
            }
            set
            {
                if (mRealTagMode is Cdy.Tag.FloatingTagBase)
                {
                    (mRealTagMode as Cdy.Tag.FloatingTagBase).Precision = value;
cdy816's avatar
cdy816 已提交
693
                    IsChanged = true;
694 695 696 697 698 699 700 701 702 703 704 705 706
                    OnPropertyChanged("Precision");
                }
            }
        }

        public bool IsFloatingTag
        {
            get
            {
                return mRealTagMode is Cdy.Tag.FloatingTagBase;
            }
        }

cdy816's avatar
cdy816 已提交
707 708 709 710 711 712 713 714

        /// <summary>
        /// 
        /// </summary>
        public string RecordTypeString
        {
            get
            {
cdy816's avatar
cdy816 已提交
715
                return mHisTagMode!=null? Res.Get(mHisTagMode.Type.ToString()):string.Empty;
cdy816's avatar
cdy816 已提交
716 717 718
            }
        }

719 720 721 722 723 724 725 726 727 728 729 730
        /// <summary>
        /// 
        /// </summary>
        public string ReadWriteModeString
        {
            get
            {
                return Res.Get(((Cdy.Tag.ReadWriteMode)ReadWriteMode).ToString());
            }
        }


cdy816's avatar
cdy816 已提交
731

cdy816's avatar
cdy816 已提交
732 733 734 735 736 737 738 739 740 741 742 743 744 745
        /// <summary>
        /// 
        /// </summary>
        public int CompressType
        {
            get
            {
                return mHisTagMode != null ? mHisTagMode.CompressType : -1;
            }
            set
            {
                if (mHisTagMode != null && mHisTagMode.CompressType != value)
                {
                    mHisTagMode.CompressType = value;
cdy816's avatar
cdy816 已提交
746 747 748 749
                    IsChanged = true;
                    CheckRecordTypeParameterModel();

                    OnPropertyChanged("CompressType");
cdy816's avatar
cdy816 已提交
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public long CompressCircle
        {
            get
            {
                return mHisTagMode != null ? mHisTagMode.Circle : -1;
            }
            set
            {
                if (mHisTagMode != null && mHisTagMode.Circle != value)
                {
                    mHisTagMode.Circle = value;
cdy816's avatar
cdy816 已提交
768 769
                    IsChanged = true;
                    OnPropertyChanged("CompressCircle");
cdy816's avatar
cdy816 已提交
770 771 772 773 774 775
                }
            }
        }


        #endregion ...Properties....
776 777 778

        #region ... Methods    ...

cdy816's avatar
cdy816 已提交
779 780 781 782 783 784 785 786 787 788
        public void RefreshHisTag()
        {
            OnPropertyChanged("CompressType");
            OnPropertyChanged("CompressCircle");
            OnPropertyChanged("RecordType");
            OnPropertyChanged("RecordTypeString");
            OnPropertyChanged("IsTimerRecord");

        }

cdy816's avatar
cdy816 已提交
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
        /// <summary>
        /// 
        /// </summary>
        private void CheckLinkAddress()
        {
            if (string.IsNullOrEmpty(LinkAddress))
            {
                return;
            }
            else
            {
                string[] str = LinkAddress.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                mDriverName = str[0];
                if(str.Length>1)
                {
                    mRegistorName = LinkAddress.Substring(mDriverName.Length+1);
                }
cdy816's avatar
cdy816 已提交
806 807 808 809 810 811 812 813 814 815

                if (Drivers != null && Drivers.ContainsKey(mDriverName))
                {
                    RegistorList = Drivers[mDriverName];
                }
                else
                {
                    RegistorList = null;
                }

cdy816's avatar
cdy816 已提交
816 817 818
            }
        }

cdy816's avatar
cdy816 已提交
819 820 821 822 823 824
        /// <summary>
        /// 
        /// </summary>
        private static void InitEnumType()
        {
            mTagTypeList = Enum.GetNames(typeof(Cdy.Tag.TagType));
cdy816's avatar
cdy816 已提交
825 826
            mRecordTypeList = Enum.GetNames(typeof(Cdy.Tag.RecordType)).Select(e => Res.Get(e)).ToArray();
            mReadWriteModeList = Enum.GetNames(typeof(Cdy.Tag.ReadWriteMode)).Select(e=>Res.Get(e)).ToArray();
cdy816's avatar
cdy816 已提交
827 828
        }

cdy816's avatar
cdy816 已提交
829 830 831 832
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tagType"></param>
cdy816's avatar
cdy816 已提交
833 834 835
        private void ChangeTagType(Cdy.Tag.TagType tagType)
        {
            Cdy.Tag.Tagbase ntag = null;
cdy816's avatar
cdy816 已提交
836
            if (mHisTagMode == null) return;
cdy816's avatar
cdy816 已提交
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
            switch (tagType)
            {
                case Cdy.Tag.TagType.Bool:
                    ntag = new Cdy.Tag.BoolTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.Bool;
                    }
                    break;
                case Cdy.Tag.TagType.Byte:
                    ntag = new Cdy.Tag.ByteTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.Byte;
                    }
                    break;
                case Cdy.Tag.TagType.DateTime:
                    ntag = new Cdy.Tag.DateTimeTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.DateTime;
                    }
                    break;
                case Cdy.Tag.TagType.Double:
                    ntag = new Cdy.Tag.DoubleTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.Double;
                    }
                    break;
                case Cdy.Tag.TagType.Float:
                    ntag = new Cdy.Tag.FloatTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.Float;
                    }
                    break;
                case Cdy.Tag.TagType.Int:
                    ntag = new Cdy.Tag.IntTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.Int;
                    }
                    break;
                case Cdy.Tag.TagType.Long:
                    ntag = new Cdy.Tag.LongTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.Long;
                    }
                    break;
                case Cdy.Tag.TagType.Short:
                    ntag = new Cdy.Tag.ShortTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.Short;
                    }
                    break;
                case Cdy.Tag.TagType.String:
                    ntag = new Cdy.Tag.StringTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.String;
                    }
                    break;
                case Cdy.Tag.TagType.UInt:
                    ntag = new Cdy.Tag.UIntTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.UInt;
                    }
                    break;
                case Cdy.Tag.TagType.ULong:
                    ntag = new Cdy.Tag.ULongTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.ULong;
                    }
                    break;
                case Cdy.Tag.TagType.UShort:
                    ntag = new Cdy.Tag.UShortTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.UShort;
                    }
                    break;
cdy816's avatar
cdy816 已提交
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980

                case Cdy.Tag.TagType.IntPoint:
                    ntag = new Cdy.Tag.IntPointTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.IntPoint;
                    }
                    break;
                case Cdy.Tag.TagType.IntPoint3:
                    ntag = new Cdy.Tag.IntPoint3Tag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.IntPoint3;
                    }
                    break;
                case Cdy.Tag.TagType.UIntPoint:
                    ntag = new Cdy.Tag.UIntPointTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.UIntPoint;
                    }
                    break;
                case Cdy.Tag.TagType.UIntPoint3:
                    ntag = new Cdy.Tag.UIntPoint3Tag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.UIntPoint3;
                    }
                    break;
                case Cdy.Tag.TagType.LongPoint:
                    ntag = new Cdy.Tag.LongPointTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.LongPoint;
                    }
                    break;
                case Cdy.Tag.TagType.LongPoint3:
                    ntag = new Cdy.Tag.LongPoint3Tag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.LongPoint3;
                    }
                    break;
                case Cdy.Tag.TagType.ULongPoint:
                    ntag = new Cdy.Tag.ULongPointTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.ULongPoint;
                    }
                    break;
                case Cdy.Tag.TagType.ULongPoint3:
                    ntag = new Cdy.Tag.ULongPoint3Tag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.ULongPoint3;
                    }
                    break;

cdy816's avatar
cdy816 已提交
981 982 983 984 985 986 987
                default:
                    break;
            }
            if (ntag != null)
            {
                RealTagMode = ntag;
            }
cdy816's avatar
cdy816 已提交
988 989 990
            IsChanged = true;
        }

cdy816's avatar
cdy816 已提交
991 992 993
        /// <summary>
        /// 
        /// </summary>
cdy816's avatar
cdy816 已提交
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
        private void CheckRecordTypeParameterModel()
        {
            if(mHisTagMode==null)
            {
                CompressParameterModel = null;
                return;
            }
            switch (CompressType)
            {
                case 0:
                case 1:
                    CompressParameterModel = null;
                    break;
                case 2:
                    CompressParameterModel = new DeadAreaCompressParameterViewModel() { Parameters = HisTagMode.Parameters };
                    break;
                case 3:
                    CompressParameterModel = new SlopeCompressParameterViewModel() { Parameters = HisTagMode.Parameters };
                    break;
            }
            
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public TagViewModel Clone()
        {
            Cdy.Tag.Tagbase ntag = null;
            Cdy.Tag.HisTag htag = null;
            if(mHisTagMode != null)
            {
                htag = new Cdy.Tag.HisTag() { Id = mHisTagMode.Id, Circle = mHisTagMode.Circle, CompressType = mHisTagMode.CompressType, TagType = mHisTagMode.TagType, Type = mHisTagMode.Type };

                if (this.mHisTagMode.Parameters != null)
                {
                    htag.Parameters = new Dictionary<string, double>();
                    foreach(var vv in mHisTagMode.Parameters)
                    {
                        htag.Parameters.Add(vv.Key, vv.Value);
                    }
                }
            }

            switch (this.mRealTagMode.Type)
            {
                case Cdy.Tag.TagType.Bool:
cdy816's avatar
cdy816 已提交
1042
                    ntag = new Cdy.Tag.BoolTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group,Conveter = mRealTagMode.Conveter!=null?mRealTagMode.Conveter.Clone():null };
cdy816's avatar
cdy816 已提交
1043 1044
                    break;
                case Cdy.Tag.TagType.Byte:
cdy816's avatar
cdy816 已提交
1045
                    ntag = new Cdy.Tag.ByteTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1046 1047 1048

                    break;
                case Cdy.Tag.TagType.DateTime:
cdy816's avatar
cdy816 已提交
1049
                    ntag = new Cdy.Tag.DateTimeTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1050 1051 1052

                    break;
                case Cdy.Tag.TagType.Double:
cdy816's avatar
cdy816 已提交
1053
                    ntag = new Cdy.Tag.DoubleTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1054 1055 1056

                    break;
                case Cdy.Tag.TagType.Float:
cdy816's avatar
cdy816 已提交
1057
                    ntag = new Cdy.Tag.FloatTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1058 1059 1060

                    break;
                case Cdy.Tag.TagType.Int:
cdy816's avatar
cdy816 已提交
1061
                    ntag = new Cdy.Tag.IntTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1062 1063 1064

                    break;
                case Cdy.Tag.TagType.Long:
cdy816's avatar
cdy816 已提交
1065
                    ntag = new Cdy.Tag.LongTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1066 1067 1068

                    break;
                case Cdy.Tag.TagType.Short:
cdy816's avatar
cdy816 已提交
1069
                    ntag = new Cdy.Tag.ShortTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1070 1071 1072

                    break;
                case Cdy.Tag.TagType.String:
cdy816's avatar
cdy816 已提交
1073
                    ntag = new Cdy.Tag.StringTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1074 1075 1076

                    break;
                case Cdy.Tag.TagType.UInt:
cdy816's avatar
cdy816 已提交
1077
                    ntag = new Cdy.Tag.UIntTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1078 1079 1080

                    break;
                case Cdy.Tag.TagType.ULong:
cdy816's avatar
cdy816 已提交
1081
                    ntag = new Cdy.Tag.ULongTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1082 1083 1084

                    break;
                case Cdy.Tag.TagType.UShort:
cdy816's avatar
cdy816 已提交
1085
                    ntag = new Cdy.Tag.UShortTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group, Conveter = mRealTagMode.Conveter != null ? mRealTagMode.Conveter.Clone() : null };
cdy816's avatar
cdy816 已提交
1086

cdy816's avatar
cdy816 已提交
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
                    break;
                case Cdy.Tag.TagType.IntPoint:
                    ntag = new Cdy.Tag.IntPointTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.IntPoint;
                    }
                    break;
                case Cdy.Tag.TagType.IntPoint3:
                    ntag = new Cdy.Tag.IntPoint3Tag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.IntPoint3;
                    }
                    break;
                case Cdy.Tag.TagType.UIntPoint:
                    ntag = new Cdy.Tag.UIntPointTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.UIntPoint;
                    }
                    break;
                case Cdy.Tag.TagType.UIntPoint3:
                    ntag = new Cdy.Tag.UIntPoint3Tag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.UIntPoint3;
                    }
                    break;
                case Cdy.Tag.TagType.LongPoint:
                    ntag = new Cdy.Tag.LongPointTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.LongPoint;
                    }
                    break;
                case Cdy.Tag.TagType.LongPoint3:
                    ntag = new Cdy.Tag.LongPoint3Tag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.LongPoint3;
                    }
                    break;
                case Cdy.Tag.TagType.ULongPoint:
                    ntag = new Cdy.Tag.ULongPointTag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.ULongPoint;
                    }
                    break;
                case Cdy.Tag.TagType.ULongPoint3:
                    ntag = new Cdy.Tag.ULongPoint3Tag() { Id = this.mRealTagMode.Id, Name = mRealTagMode.Name, Desc = mRealTagMode.Desc, LinkAddress = mRealTagMode.LinkAddress, Group = mRealTagMode.Group };
                    if (mHisTagMode != null)
                    {
                        mHisTagMode.TagType = Cdy.Tag.TagType.ULongPoint3;
                    }
cdy816's avatar
cdy816 已提交
1143 1144 1145 1146
                    break;
                default:
                    break;
            }
cdy816's avatar
cdy816 已提交
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158

            if(IsNumberTag)
            {
                (ntag as NumberTagBase).MaxValue = (mRealTagMode as NumberTagBase).MaxValue;
                (ntag as NumberTagBase).MinValue = (mRealTagMode as NumberTagBase).MinValue;
            }

            if(IsFloatingTag)
            {
                (ntag as FloatingTagBase).Precision = (mRealTagMode as FloatingTagBase).Precision;
            }

cdy816's avatar
cdy816 已提交
1159
            return new TagViewModel(ntag,htag);
cdy816's avatar
cdy816 已提交
1160 1161
        }

cdy816's avatar
cdy816 已提交
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string SaveToCSVString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(mRealTagMode.Id+",");
            sb.Append(mRealTagMode.Name + ",");
            sb.Append(mRealTagMode.Desc + ",");
            sb.Append(mRealTagMode.Group + ",");
            sb.Append(mRealTagMode.Type + ",");
            sb.Append(mRealTagMode.LinkAddress + ",");
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
            sb.Append((int)mRealTagMode.ReadWriteType + ",");
            if (mRealTagMode.Conveter != null)
                sb.Append(mRealTagMode.Conveter.SeriseToString() + ",");
            else
            {
                sb.Append(",");
            }
            if (mRealTagMode is NumberTagBase)
            {
                sb.Append((mRealTagMode as NumberTagBase).MaxValue.ToString() + ",");
                sb.Append((mRealTagMode as NumberTagBase).MinValue.ToString() + ",");
            }
            else
            {
                sb.Append(",");
                sb.Append(",");
            }
            if (mRealTagMode is FloatingTagBase)
            {
                sb.Append((mRealTagMode as FloatingTagBase).Precision + ",");
            }
            else
            {
                sb.Append(",");
            }
            if (this.mHisTagMode!=null)
cdy816's avatar
cdy816 已提交
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
            {
                sb.Append(mHisTagMode.Type + ",");
                sb.Append(mHisTagMode.Circle + ",");
                sb.Append(mHisTagMode.CompressType + ",");
                if(mHisTagMode.Parameters!=null)
                {
                    foreach(var vv in mHisTagMode.Parameters)
                    {
                        sb.Append(vv.Key + ",");
                        sb.Append(vv.Value + ",");
                    }
                }
            }
            sb.Length = sb.Length > 0 ? sb.Length - 1 : sb.Length;
            return sb.ToString();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        public static TagViewModel LoadFromCSVString(string val)
        {
            string[] stmp = val.Split(new char[] { ',' });
            Cdy.Tag.TagType tp = (Cdy.Tag.TagType)Enum.Parse(typeof(Cdy.Tag.TagType),stmp[4]);
            var realtag = TagTypeExtends.GetTag(tp);

            realtag.Id = int.Parse(stmp[0]);
            realtag.Name = stmp[1];
            realtag.Desc = stmp[2];
            realtag.Group = stmp[3];
            realtag.LinkAddress = stmp[5];
1233 1234 1235 1236 1237
            realtag.ReadWriteType = (ReadWriteMode)(int.Parse(stmp[6]));
            if (stmp[7] != null)
            {
                realtag.Conveter = stmp[7].DeSeriseToValueConvert();
            }
cdy816's avatar
cdy816 已提交
1238

1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
            if (realtag is NumberTagBase)
            {
                (realtag as NumberTagBase).MaxValue = double.Parse(stmp[8], System.Globalization.NumberStyles.Any);
                (realtag as NumberTagBase).MinValue = double.Parse(stmp[9], System.Globalization.NumberStyles.Any);
            }

            if (realtag is FloatingTagBase)
            {
                (realtag as FloatingTagBase).Precision = byte.Parse(stmp[10]);
            }
            if (stmp.Length > 11)
cdy816's avatar
cdy816 已提交
1250 1251
            {
                Cdy.Tag.HisTag histag = new HisTag();
1252
                histag.Type = (Cdy.Tag.RecordType)Enum.Parse(typeof(Cdy.Tag.RecordType), stmp[11]);
cdy816's avatar
cdy816 已提交
1253

1254 1255
                histag.Circle = long.Parse(stmp[12]);
                histag.CompressType = int.Parse(stmp[13]);
cdy816's avatar
cdy816 已提交
1256 1257 1258 1259
                histag.Parameters = new Dictionary<string, double>();
                histag.TagType = realtag.Type;
                histag.Id = realtag.Id;

1260
                for (int i=14;i<stmp.Length;i++)
cdy816's avatar
cdy816 已提交
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
                {
                    string skey = stmp[i];
                    if(string.IsNullOrEmpty(skey))
                    {
                        break;
                    }
                    double dval = double.Parse(stmp[i + 1]);

                    if(!histag.Parameters.ContainsKey(skey))
                    {
                        histag.Parameters.Add(skey, dval);
                    }

                    i++;
                }
                return new TagViewModel(realtag, histag);
            }

            return new TagViewModel(realtag, null);


        }
cdy816's avatar
cdy816 已提交
1283

1284 1285 1286 1287 1288 1289
        #endregion ...Methods...

        #region ... Interfaces ...

        #endregion ...Interfaces...
    }
cdy816's avatar
cdy816 已提交
1290

cdy816's avatar
cdy816 已提交
1291 1292 1293 1294


    public class DatabaseViewModel : HasChildrenTreeItemViewModel
    {
cdy816's avatar
cdy816 已提交
1295

cdy816's avatar
cdy816 已提交
1296
        #region ... Variables  ...
cdy816's avatar
cdy816 已提交
1297

cdy816's avatar
cdy816 已提交
1298 1299 1300
        #endregion ...Variables...

        #region ... Events     ...
cdy816's avatar
cdy816 已提交
1301

cdy816's avatar
cdy816 已提交
1302 1303 1304 1305 1306 1307 1308
        #endregion ...Events...

        #region ... Constructor...

        #endregion ...Constructor...

        #region ... Properties ...
cdy816's avatar
cdy816 已提交
1309

cdy816's avatar
cdy816 已提交
1310 1311 1312
        #endregion ...Properties...

        #region ... Methods    ...
cdy816's avatar
cdy816 已提交
1313

cdy816's avatar
cdy816 已提交
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
        /// <summary>
        /// 
        /// </summary>
        /// <param name="oldName"></param>
        /// <param name="newName"></param>
        /// <returns></returns>
        public override bool OnRename(string oldName, string newName)
        {
            return base.OnRename(oldName, newName);
        }
cdy816's avatar
cdy816 已提交
1324

cdy816's avatar
cdy816 已提交
1325 1326 1327 1328 1329 1330 1331 1332
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override bool CanAddChild()
        {
            return false;
        }
cdy816's avatar
cdy816 已提交
1333 1334 1335 1336 1337

        public override void Dispose()
        {
            base.Dispose();
        }
cdy816's avatar
cdy816 已提交
1338 1339 1340 1341 1342 1343
        #endregion ...Methods...

        #region ... Interfaces ...

        #endregion ...Interfaces...
    }
cdy816's avatar
cdy816 已提交
1344 1345


1346
}