private void okBtn_Click(object sender, EventArgs e) { if (!NamingGuidance.CheckMappedPropertyName(tbNewName.Text.Trim(), true)) { tbNewName.SelectAll(); tbNewName.Focus(); return; } if (MaxPropertyLength > 0 && tbNewName.Text.Trim().Length > MaxPropertyLength) { MessageBox.Show("The new name is too long! Maximum " + MaxPropertyLength.ToString() + " characters.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!string.IsNullOrEmpty(NameSuffix) && !tbNewName.Text.Trim().EndsWith(NameSuffix, false, null)) { MessageBox.Show(string.Format("The new name is missing the suffix (\"{0}\")!", NameSuffix), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } NewName = tbNewName.Text.Trim(); DialogResult = DialogResult.OK; }
public void AddPropertiesToPropertyMap(List <Property> properties) { bool tooLongPropertiesAdded = false; int sequence = 1; if (PropertyMap.MappedProperties.Count > 0) { sequence = PropertyMap.MappedProperties.Max(p => p.Sequence) + 1; } foreach (Property property in properties) { MappedProperty mappedProperty = new MappedProperty(); mappedProperty.Source = null; mappedProperty.Target = property; string name = UseColumnNames && property.StorageInfo != null ? property.StorageInfo.ColumnName : property.Name; if (NameUpperCase) { name = name.ToUpper(); } // Check lengths if (MaxPropertyLength > 0 && (name.Length + NameSuffix.Length) > MaxPropertyLength) { tooLongPropertiesAdded = true; mappedProperty.Name = name.Substring(0, MaxPropertyLength - NameSuffix.Length) + NameSuffix; } else { mappedProperty.Name = name + NameSuffix; } mappedProperty.Sequence = sequence++; mappedProperty.PropertyMap = PropertyMap; mappedProperty.IsSearchable = true; // If storageinfo is not set then it's custom mappedProperty.IsCustom = property.StorageInfo == null; PropertyMap.MappedProperties.Add(mappedProperty); } if (tooLongPropertiesAdded) { MessageBox.Show("One or more properties was added that was longer than " + MaxPropertyLength.ToString() + " characters.\n" + "The names of these properties has been cut to maximum length.\n" + "Check the names of the properties if they are usable before saving.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnOK_Click(object sender, EventArgs e) { // First check if there are any MappedProperties with the same name. var props = (from prop in PropertyMap.MappedProperties select prop.Name).Distinct(); if (props.Count() != PropertyMap.MappedProperties.Count) { MessageBox.Show("One or more MappedProperties has the same name. Names must be unique.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check if there are any properties that is passed the maximum length if (MaxPropertyLength > 0) { // Get all properties that has a name length that is over the max property length IList <string> list = PropertyMap.MappedProperties.Select(p => p.Name).Where(name => name.Length > MaxPropertyLength).ToList(); if (list.Count > 0) { string txtList = list.Aggregate((current, next) => current + ",\n\t" + next); MessageBox.Show("You need to cut down the following field(s) to a maximum of " + MaxPropertyLength.ToString() + " characters!\n" + "Fields that are too long:\n\t" + txtList, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (DoSaveMapWhenExit) { // Save all MappedProperties try { dialogService.SaveAndDeleteMappedPropertiesInMap(PropertyMap, deletedList); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } DialogResult = DialogResult.OK; }