| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 | using System;using System.Collections.Generic;using System.Text;namespace FPER{    public class MskDeviceIDString    {        String mskId = "";        String dev_type = "M";     //M-중계기,I-IO보드        String inout_type = "I";   //입력회로-I,출력회로-O        int board_id = -1;    //통신보드        int comm_id = 1;  //1-front,2-back,3-io,4-keypad        int loop_no = -1;  //Loop No        int repeater_id = -1; //중계기 ID        int device_id = -1;   //회로ID        //MI-##-#-###-#  :M(구분 M-중계기,I-입력그룹)I,O(회로구분)-##(보드ID)-#(회로ID)        public MskDeviceIDString(String dev_s)        {            try            {                if (dev_s.Length == 13)                {                    this.mskId = dev_s;                    this.dev_type = dev_s.Substring(0, 1).ToUpper();                    this.inout_type = dev_s.Substring(1, 1).ToUpper();                    this.board_id = Util.StrToInt(dev_s.Substring(3, 2), 0);                    this.loop_no = Util.StrToInt(dev_s.Substring(6, 1), -1);                    this.repeater_id = Util.StrToInt(dev_s.Substring(8, 3), 0);                    this.device_id = Util.StrToInt(dev_s.Substring(12, 1), 0);                    if (dev_type.Equals("I")) comm_id = 3;                    if (!inout_type.Equals(code_InOutType.Input) && !inout_type.Equals(code_InOutType.Output))                    {                        throw new Exception("회로번호가 올바르지 않습니다. [입출력구분]");                    }                    if (board_id == 0 || board_id > 32)                    {                        throw new Exception("회로번호가 올바르지 않습니다. [통신보드ID]");                    }                    if (loop_no != 0 && loop_no != 1)                    {                        throw new Exception("회로번호가 올바르지 않습니다. [Loop No]");                    }                    if (repeater_id == 0 || repeater_id > 127)                    {                        throw new Exception("회로번호가 올바르지 않습니다. [중계기ID]");                    }                    if (device_id == 0)                    {                        throw new Exception("회로번호가 올바르지 않습니다. [회로ID]");                    }                }                else if (dev_s.Length == 9)                {                    this.mskId = dev_s;                    this.dev_type = dev_s.Substring(0, 1).ToUpper();                    this.inout_type = dev_s.Substring(2, 1).ToUpper();                    this.board_id = Util.StrToInt(dev_s.Substring(4, 2), 0);                    this.loop_no = 0;                    this.repeater_id = 0;                    this.device_id = Util.StrToInt(dev_s.Substring(7, 2), 0);                    if (dev_type.Equals("I")) comm_id = 3;                    if (!inout_type.Equals(code_InOutType.Input) && !inout_type.Equals(code_InOutType.Output))                    {                        throw new Exception("회로번호가 올바르지 않습니다. [입출력구분]");                    }                    if (board_id == 0)                    {                        throw new Exception("회로번호가 올바르지 않습니다. [I/O보드ID]");                    }                    if (device_id == 0)                    {                        throw new Exception("회로번호가 올바르지 않습니다. [회로ID]");                    }                }                else                {                    throw new Exception("회로번호가 올바르지 않습니다.");                }            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }        }        public MskDeviceIDString(int comm_id, int board_id, int loop_no, int repeater_id, int device_id, string inout_type)        {            try            {                this.comm_id = comm_id;                this.inout_type = inout_type;                this.board_id = board_id;                this.loop_no = loop_no;                this.repeater_id = repeater_id;                this.device_id = device_id;                if (comm_id == 3)                    this.dev_type = "I";                else if (comm_id == 1)                    this.dev_type = "M";                else if (comm_id == 2)                    this.dev_type = "M";                else if (comm_id == 4)                    this.dev_type = "키패드";                //if (!inout_type.Equals(code_InOutType.Input) && !inout_type.Equals(code_InOutType.Output))                //{                //    return;                //    //throw new Exception("회로번호가 올바르지 않습니다. [입출력구분]");                //}                if (this.comm_id == 1 || this.comm_id == 2)                {                    if (board_id == 0 || board_id > 32)                    {                        this.mskId = string.Format("Comm[{0}]", this.comm_id);                    }                    else                    {                        if (loop_no != 0 && loop_no != 1)                            this.mskId = string.Format("통신보드[{0}]", this.board_id);                        else                        {                            if (repeater_id == 0 || repeater_id > 127)                                this.mskId = string.Format("통신보드[{0}]-Loop[{1}]", this.board_id, this.loop_no);                            else                            {                                if (device_id == 0)                                    this.mskId = string.Format("통신보드[{0}]-Loop[{1}]-중계기[{2}]", this.board_id, this.loop_no, this.repeater_id);                                else                                {                                    if (!inout_type.Equals(code_InOutType.Input) && !inout_type.Equals(code_InOutType.Output))                                        this.mskId = string.Format("통신보드[{0}]-Loop[{1}]-중계기[{2}]-회로[{3}]", this.board_id, this.loop_no, this.repeater_id, this.device_id);                                    else                                    {                                        this.mskId = string.Format("{0}{1}-{2:00}-{3:0}-{4:000}-{5}", this.dev_type, this.inout_type, this.board_id                                            , this.loop_no, this.repeater_id, this.device_id);                                    }                                }                            }                        }                    }                    //if (device_id == 0)                    //{                    //    if (repeater_id == 0 || repeater_id > 127)                    //    {                    //        if (loop_no != 0 && loop_no != 1)                    //        {                    //            if (board_id == 0 || board_id > 32)                    //            {                    //                this.mskId = string.Format("Comm[{0}]", this.comm_id);                    //            }                    //            else                    //            {                    //                this.mskId = string.Format("통신보드[{0}]", this.board_id);                    //            }                    //        }                    //        else                    //        {                    //            this.mskId = string.Format("통신보드[{0}]-Loop[{1}]", this.board_id, this.loop_no);                    //        }                    //    }                    //    else                    //    {                    //        this.mskId = string.Format("통신보드[{0}]-Loop[{1}]-중계기[{2}]", this.board_id, this.loop_no, this.repeater_id);                    //    }                    //}                    //else                    //{                    //    this.mskId = string.Format("{0}{1}-{2:00}-{3:0}-{4:000}-{5}", this.dev_type, this.inout_type, this.board_id                    //        , this.loop_no, this.repeater_id, this.device_id);                    //}                }                else if (this.comm_id == 3)                {                    if (device_id == 0)                    {                        if (board_id == 0)                        {                            this.mskId = string.Format("IO보드 Comm[{0}]", this.comm_id);                        }                        else                        {                            this.mskId = string.Format("IO보드[{0}]", this.board_id);                        }                    }                    else                    {                        //I-A-12-##                        this.mskId = String.Format("{0}-{1}-{2:00}-{3:00}", this.dev_type, this.inout_type, this.board_id, this.device_id);                    }                }                else if (this.comm_id == 4)                {                    if (device_id == 0)                    {                        this.mskId = string.Format("키패드 Comm[{0}]", this.comm_id);                    }                    else                    {                        //I-A-12-##                        this.mskId = String.Format("키패드 번호[{0}]", this.device_id);                    }                }            }            catch (Exception ex)            {                Util.UErrorMessage(ex, 0, 0);            }        }        public int Board_id { get { return this.board_id; } }        public int Comm_id { get { return this.comm_id; } }        public int Loop_no { get { return this.loop_no; } }        public int Repeater_id { get { return this.repeater_id; } }        public int Device_id { get { return this.device_id; } }        public String Inout_type { get { return this.inout_type; } }        public String MskId { get { return this.mskId; } }    }}
 |