private void btnCreate_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtName.Text.Trim())) { MMCDlgHelper.ShowWarning("Enter a valid name"); return; } _dto = new AttributeConsumerServiceDto { Name = txtName.Text, Index = (int)nudIndex.Value, Attributes = GetAttributes(), IsDefault = chkDefault.Checked }; DialogResult = DialogResult.OK; Close(); }
public override void AwakeFromNib() { base.AwakeFromNib(); IsUpdated = false; //Events this.BtnAdd.Activated += (object sender, EventArgs e) => { if (string.IsNullOrEmpty(TxtName.StringValue)) { UIErrorHelper.ShowAlert("Name has invalid value", "Alert"); } else if (string.IsNullOrEmpty(TxtIndex.StringValue)) { UIErrorHelper.ShowAlert("Index has invalid value", "Alert"); } else if (ChDefault.StringValue == "1" && DefaultSet && (AttributeConsumerServiceDto != null && !AttributeConsumerServiceDto.IsDefault)) { UIErrorHelper.ShowAlert("Multiple attribute consumer services chosen as default", "Alert"); } else { AttributeConsumerServiceDto = new AttributeConsumerServiceDto { Name = TxtName.StringValue, Index = TxtIndex.IntValue, IsDefault = ChDefault.StringValue == "1", Attributes = (AttributeTableView.DataSource as AttributeDataSource).Entries }; IsUpdated = true; this.Close(); NSApplication.SharedApplication.StopModalWithCode(0); } }; this.BtnAddAttribute.Activated += (object sender, EventArgs e) => { if (string.IsNullOrEmpty(TxtAttributeName.StringValue)) { UIErrorHelper.ShowAlert("Attribute name cannot be empty", "Alert"); return; } if (string.IsNullOrEmpty(TxtFriendlyName.StringValue)) { UIErrorHelper.ShowAlert("Attribute friendly name cannot be empty", "Alert"); return; } if (string.IsNullOrEmpty(TxtNameFormat.StringValue)) { UIErrorHelper.ShowAlert("Attribute name format cannot be empty", "Alert"); return; } var attributeDto = new AttributeDto { Name = TxtAttributeName.StringValue, FriendlyName = TxtFriendlyName.StringValue, NameFormat = TxtNameFormat.StringValue }; TxtAttributeName.StringValue = string.Empty; TxtFriendlyName.StringValue = string.Empty; TxtNameFormat.StringValue = string.Empty; _attributes.Add(attributeDto); AttributeTableView.DataSource = new AttributeDataSource { Entries = _attributes }; AttributeTableView.ReloadData(); }; this.BtnRemoveAttribute.Activated += (object sender, EventArgs e) => { if (AttributeTableView.SelectedRow > -1) { _attributes.RemoveAt((int)AttributeTableView.SelectedRow); AttributeTableView.DataSource = new AttributeDataSource { Entries = _attributes }; AttributeTableView.ReloadData(); } }; this.BtnClose.Activated += (object sender, EventArgs e) => { this.Close(); NSApplication.SharedApplication.StopModalWithCode(0); }; if (AttributeConsumerServiceDto != null) { TxtName.StringValue = AttributeConsumerServiceDto.Name; _attributes = AttributeConsumerServiceDto.Attributes; ChDefault.StringValue = AttributeConsumerServiceDto.IsDefault ? "1" : "0"; TxtIndex.IntValue = AttributeConsumerServiceDto.Index; } InitializeAttributes(); }