private void BtnAddTag_Click(object sender, EventArgs e) { MasterForm master = (this.Parent.Parent as MasterForm); try { string tagName = this.txtCreateTagName.Text.Trim(); string status = ""; if (tagExists(tagName)) { status = "A tag with this name already exists." + Environment.NewLine; } else if (String.IsNullOrEmpty(status = DBTag.Validate(tagName))) { object result = DBTag.InsertTag(tagName); if (result != null) { status = "Tag \"" + tagName + "\" has been added successfully" + Environment.NewLine; RadioButton rbTemp = new RadioButton() { Text = tagName, Tag = Int32.Parse(result.ToString()) }; rbTemp.CheckedChanged += Tag_CheckedChanged; this.tlpTagsPanel.Controls.Add(rbTemp); } } master.SetStatus(status); } catch (Exception ex) { master.SetStatus("Error! Failed to add tag: " + ex.Message); } }
private void BtnUpdateTag_Click(object sender, EventArgs e) { MasterForm master = (this.Parent.Parent as MasterForm); string tagName = this.txtEditTagName.Text.Trim(); try { string status = ""; if (this.txtEditTagName.Tag != null) { if (this.tagExists(tagName)) { status += "A tag with this name already exists." + Environment.NewLine; } else if (String.IsNullOrEmpty(status = DBTag.Validate(tagName))) { if (DBTag.UpdateTag(Int32.Parse(this.txtEditTagName.Tag.ToString()), tagName)) { status += "Tag \"" + this.rbSelectedTag.Text + "\" has been updated successfully" + Environment.NewLine; rbSelectedTag.Text = tagName; } } } else { status += "A tag must be selected." + Environment.NewLine; } master.SetStatus(status); } catch (Exception ex) { master.SetStatus("Error! Failed to update tag: " + ex.Message); } }