private void bSave_Click(object sender, EventArgs e) { bSave.Focus(); uint flags, datestamp; if (!uint.TryParse(tbDateStamp.Text, NumberStyles.AllowHexSpecifier, null, out datestamp)) { tbDateStamp.Focus(); MessageBox.Show("Invalid value specified for datestamp"); return; } if (!uint.TryParse(tbFlags.Text, NumberStyles.AllowHexSpecifier, null, out flags)) { tbFlags.Focus(); MessageBox.Show("Invalid value specified for flags"); return; } var grouptype = (uint)cmbGroupType.SelectedIndex; byte[] data; switch (cmbGroupType.SelectedIndex) { case 0: if (tbRecType.TextLength != 4) { tbRecType.Focus(); MessageBox.Show("Invalid parent record type. Needs to be 4 characters!"); return; } data = new byte[4]; Encoding.CP1252.GetBytes(tbRecType.Text, 0, 4, data, 0); break; case 2: case 3: uint block; if (!uint.TryParse(tbBlock.Text, out block)) { tbBlock.Focus(); 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)) { tbX.Focus(); MessageBox.Show("Invalid value specified for x coord"); return; } if (!short.TryParse(tbY.Text, out y)) { tbY.Focus(); 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)) { tbParent.Focus(); MessageBox.Show("Invalid value specified for parent"); return; } data = TypeConverter.i2h(parent); break; default: cmbGroupType.Focus(); MessageBox.Show("Sanity check failed; invalid group type"); return; } gr.flags = flags; gr.dateStamp = datestamp; gr.groupType = grouptype; gr.SetData(data); gr.UpdateShortDescription(); this.DialogResult = DialogResult.OK; }
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.CP1252.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); }