Beispiel #1
0
        private void bSave_Click(object sender, EventArgs e)
        {
            uint flags, datestamp;

            if (!uint.TryParse(tbDateStamp.Text, NumberStyles.AllowHexSpecifier, null, out datestamp))
            {
                MessageBox.Show("Invalid value specified for datestamp");
                return;
            }
            if (!uint.TryParse(tbFlags.Text, NumberStyles.AllowHexSpecifier, null, out flags))
            {
                MessageBox.Show("Invalid value specified for flags");
                return;
            }
            var grouptype = (uint)cmbGroupType.SelectedIndex;

            byte[] data;
            switch (cmbGroupType.SelectedIndex)
            {
            case 0:
                data = Encoding.ASCII.GetBytes(tbRecType.Text);
                break;

            case 2:
            case 3:
                uint block;
                if (!uint.TryParse(tbBlock.Text, out block))
                {
                    MessageBox.Show("Invalid value specified for block id");
                    return;
                }
                data = TypeConverter.i2h(block);
                break;

            case 4:
            case 5:
                short x, y;
                if (!short.TryParse(tbX.Text, out x))
                {
                    MessageBox.Show("Invalid value specified for x coord");
                    return;
                }
                if (!short.TryParse(tbY.Text, out y))
                {
                    MessageBox.Show("Invalid value specified for y coord");
                    return;
                }
                data = new byte[4];
                TypeConverter.ss2h(x, data, 2);
                TypeConverter.ss2h(y, data, 0);
                break;

            case 1:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
                uint parent;
                if (!uint.TryParse(tbParent.Text, NumberStyles.AllowHexSpecifier, null, out parent))
                {
                    MessageBox.Show("Invalid value specified for parent");
                    return;
                }
                data = TypeConverter.i2h(parent);
                break;

            default:
                MessageBox.Show("Sanity check failed; invalid group type");
                return;
            }
            gr.flags     = flags;
            gr.dateStamp = datestamp;
            gr.groupType = grouptype;
            gr.SetData(data);
        }