/// <summary> /// Handles the click event for the "..." data source button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected override void btnDataSource_Click(object sender, EventArgs e) { if (ValidateToAddDataSource()) { NamedObjectCollection <Field> columnNamesInLower = new NamedObjectCollection <Field>(); int selectedIndex = 1; DataRowView item; string[] selectedFieldNames = new string[lbxLinkedFields.SelectedItems.Count]; for (int i = 0; i < lbxLinkedFields.Items.Count; i++) { item = (DataRowView)lbxLinkedFields.Items[i]; if (lbxLinkedFields.GetSelected(i)) { selectedFieldNames[selectedIndex - 1] = item[lbxLinkedFields.DisplayMember].ToString(); DataRow selectRow = item.Row; string fieldColumnName = (selectRow[ColumnNames.NAME].ToString()); string fieldStringID = (selectRow[ColumnNames.FIELD_ID].ToString()); if (DoesFieldNameExistInCollection(fieldColumnName, selectedFields) == false) { selectedFields.Add(page.GetView().GetFieldById(int.Parse(fieldStringID))); } selectedIndex++; } } CodesDialog codesDialog = new CodesDialog((TableBasedDropDownField)this.Field, this.MainForm, txtFieldName.Text, this.page, selectedFields); DialogResult result = codesDialog.ShowDialog(); if (result == DialogResult.OK) { if (!((string.IsNullOrEmpty(codesDialog.SourceTableName) && string.IsNullOrEmpty(codesDialog.TextColumnName)))) { txtDataSource.Text = codesDialog.SourceTableName + " :: " + codesDialog.TextColumnName; lbxLinkedFields.Enabled = true; lblSelectFields.Enabled = true; txtFieldName.Enabled = false; string dialogRelateCondition = codesDialog.relateCondition; if (string.IsNullOrEmpty(dialogRelateCondition)) { ((DDLFieldOfCodes)field).AssociatedFieldInformation = ((DDLFieldOfCodes)field).RelateConditionString; } else { ((DDLFieldOfCodes)field).AssociatedFieldInformation = dialogRelateCondition; } ((DDLFieldOfCodes)field).ShouldSort = codesDialog.ShouldSort; } else { txtDataSource.Text = string.Empty; field.SourceTableName = string.Empty; field.TextColumnName = string.Empty; lbxLinkedFields.Enabled = true; lbxLinkedFields.Visible = true; lblSelectFields.Enabled = true; lblSelectFields.Visible = true; ((DDLFieldOfCodes)field).AssociatedFieldInformation = string.Empty; } this.sourceTableName = codesDialog.SourceTableName; this.textColumnName = codesDialog.TextColumnName; btnOk.Enabled = true; } } else { ShowErrorMessages(); } }
/// <summary> /// Handles the click event for the "..." data source button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected override void btnDataSource_Click(object sender, EventArgs e) { if (ValidateToAddDataSource()) { NamedObjectCollection<Field> columnNamesInLower = new NamedObjectCollection<Field>(); int selectedIndex = 1; DataRowView item; string[] selectedFieldNames = new string[lbxLinkedFields.SelectedItems.Count]; for (int i = 0; i < lbxLinkedFields.Items.Count; i++) { item = (DataRowView)lbxLinkedFields.Items[i]; if (lbxLinkedFields.GetSelected(i)) { selectedFieldNames[selectedIndex - 1] = item[lbxLinkedFields.DisplayMember].ToString(); DataRow selectRow = item.Row; string fieldColumnName = (selectRow[ColumnNames.NAME].ToString()); string fieldStringID = (selectRow[ColumnNames.FIELD_ID].ToString()); if (DoesFieldNameExistInCollection(fieldColumnName, selectedFields) == false) { selectedFields.Add(page.GetView().GetFieldById(int.Parse(fieldStringID))); } selectedIndex++; } } CodesDialog codesDialog = new CodesDialog((TableBasedDropDownField)this.Field, this.MainForm, txtFieldName.Text, this.page, selectedFields); DialogResult result = codesDialog.ShowDialog(); if (result == DialogResult.OK) { if (!((string.IsNullOrEmpty(codesDialog.SourceTableName) && string.IsNullOrEmpty(codesDialog.TextColumnName)))) { txtDataSource.Text = codesDialog.SourceTableName + " :: " + codesDialog.TextColumnName; lbxLinkedFields.Enabled = true; lblSelectFields.Enabled = true; txtFieldName.Enabled = false; string dialogRelateCondition = codesDialog.relateCondition; if (string.IsNullOrEmpty(dialogRelateCondition)) { ((DDLFieldOfCodes)field).AssociatedFieldInformation = ((DDLFieldOfCodes)field).RelateConditionString; } else { ((DDLFieldOfCodes)field).AssociatedFieldInformation = dialogRelateCondition; } ((DDLFieldOfCodes)field).ShouldSort = codesDialog.ShouldSort; } else { txtDataSource.Text = string.Empty; field.SourceTableName = string.Empty; field.TextColumnName = string.Empty; lbxLinkedFields.Enabled = true; lbxLinkedFields.Visible = true; lblSelectFields.Enabled = true; lblSelectFields.Visible = true; ((DDLFieldOfCodes)field).AssociatedFieldInformation = string.Empty; } this.sourceTableName = codesDialog.SourceTableName; this.textColumnName = codesDialog.TextColumnName; btnOk.Enabled = true; } } else { ShowErrorMessages(); } }