Exemplo n.º 1
0
        public List <Byte> Create_identifier(Class_type classType, bool is_complex, int tag)
        {
            List <Byte> identifier = new List <byte>();
            Byte        byte_z     = 0;
            int         temp       = (int)classType;

            switch (temp)
            {
            case 0:
                byte_z += 0;
                break;

            case 1:
                byte_z += 64;
                break;

            case 2:
                byte_z += 128;
                break;

            case 3:
                byte_z += 192;
                break;

            default:
                byte_z += 0;
                break;
            }
            if (is_complex)
            {
                byte_z += 32;
            }

            if (tag > 30)
            {
                byte_z += 31;
                identifier.Add(byte_z);
                while (tag - 127 > 0)
                {
                    identifier.Add(255);
                    tag -= 127;
                }
                byte_z = (byte)tag;
                identifier.Add(byte_z);
            }
            else
            {
                byte_z += (byte)tag;
                identifier.Add(byte_z);
            }
            return(identifier);
        }
Exemplo n.º 2
0
        public Block(string[] values, DataBase d)
        {
            FlatStyle = FlatStyle.Flat;
            code      = values[0];
            name      = values[2];
            if ("WCLPS".Contains(values[1].ToUpper()))
            {
                type = (Class_type)Enum.Parse(typeof(Class_type), values[1].ToUpper());
            }
            teacher    = values[3];
            day        = values[4].ToLower();
            week       = (values[7].ToUpper().Equals("TP") ? Week_type.TP : (values[7].ToUpper().Equals("TN") ? Week_type.TN : Week_type.O));
            startTime  = new Time(values[5]);
            endTime    = new Time(values[6]);
            clump_type = values[8];
            if (values.Length > 9 && values[9] != null)
            {
                if (values[9].Length == 0)
                {
                    clump_number = 0;
                }
                else
                {
                    clump_number = int.Parse(values[9]);
                }
            }
            if (values.Length > 10 && values[10] != null)
            {
                if (values[10].Length == 0)
                {
                    group_capacity = 9999;
                }
                else
                {
                    group_capacity = int.Parse(values[10]);
                }
            }
            if (values.Length > 11 && values[11] != null)
            {
                if (values[11].Length == 0)
                {
                    group_taken = 0;
                }
                else
                {
                    group_taken = int.Parse(values[11]);
                }
            }


            SetColors();
            BackColor    = Color_Deactivated;
            TextMain     = code;
            TextMain    += "\n" + name;
            TextMain    += "\n" + teacher;
            TextType     = type.ToString();
            TextWeek     = (week == Week_type.O ? "" : week.ToString());
            TextBottLeft = (group_capacity == 9999 ? "" : group_taken.ToString() + "/" + group_capacity.ToString() + Environment.NewLine) +
                           (clump_type == "" ? "" : clump_type + "_" + clump_number.ToString());
            Left   = 53;
            Top    = ToDayNumber(day) * 900 + (startTime.Hour - 6) * 60 + startTime.Minute;
            Height = (endTime.Hour * 60 + endTime.Minute) - (startTime.Hour * 60 + startTime.Minute);
            Width  = Form1.brickWidth - 6;
            Name   = code;

            data   = d;
            Click += new EventHandler(OnClick);
            FlatAppearance.BorderColor = Color_Activated.Add(-30, -30, -30);
            Cursor = Cursors.Hand;

            if (group_capacity - group_taken <= 0)
            {
                BackColor = Color.LightGray;
                FlatAppearance.BorderSize = 0;
                ForeColor = Color.Gray;
                font      = new Font(font, FontStyle.Strikeout);
                Enabled   = false;
            }
        }
Exemplo n.º 3
0
        public List <Byte> Create_content_after_validation()
        {
            List <Byte> data       = new List <byte>();
            List <Byte> length     = new List <byte>();
            List <Byte> identifier = new List <byte>();
            List <Byte> data_frame = new List <byte>();
            int         tag        = 0;
            char        data_type;
            bool        is_complex;
            string      value;
            Class_type  class_type = Class_type.universal;
            Node        leaf       = tree_list.Find_OID(OID);

            if (leaf == null)
            {
                Console.WriteLine("Nie znaleziono elementu o takim OID. Czyszczenie wektora.");
                data_frame.Clear();
                return(data_frame);
            }
            Validator valid = new Validator(leaf);

            data_type = valid.Validate_data_type();
            bool repeat = true;

            switch (data_type)
            {
            case '1':
                tag   = 2;
                value = "";
                while (!valid.Validate_int(value))
                {
                    Console.WriteLine("Wprowadź prawidłową wartość integer: ");
                    value = Console.ReadLine();
                }
                Int32.TryParse(value, out int x);
                data = Code_integer(x);
                break;

            case '2':
                tag = 4;
                do
                {
                    Console.WriteLine("Wprowadź tekst: ");
                    value = Console.ReadLine();
                } while (repeat = !valid.Validate_string(value));
                data = Code_string(value);
                break;

            case '3':
                data.Clear();
                tag = 5;
                break;

            case '4':
                is_complex = true;
                tag        = 16;
                data       = Code_sequences();
                break;

            case '5':
                tag = 6;
                break;

            default:
                Console.WriteLine("Nieprawidłowy typ danych.");
                break;
            }
            if (data_type != '4')
            {
                is_complex = false;
            }

            else
            {
                is_complex = true;
            }

            length     = Create_length(data.Count);
            identifier = Create_identifier(class_type, is_complex, tag);
            if (data_frame.Count == 0)
            {
                data_frame = identifier;
            }
            else
            {
                data_frame.InsertRange(data_frame.Count, identifier);
            }
            data_frame.InsertRange(data_frame.Count, length);
            data_frame.InsertRange(data_frame.Count, data);
            return(data_frame);
        }