private void signalComboBox_SelectedIndexChanged(object sender, EventArgs e) { try { HourGlass.Enabled = true; SignalModel signalModel = awbDropListTree.SelectedSignalModel; if (signalModel != null) { var signal = signalModel.Signal; //signalComboBox.SelectedItem as dbSignal; if (signal != null) { //---------------------------------------------------// //--- Find "name" in data grid and set it's value ---// //---------------------------------------------------// foreach (DataGridViewRow row in signalAttributes.Rows) { if (row.IsNewRow) { continue; } var name = row.Cells[0].Value as string; var type = row.Cells[1].Value as string; var value = row.Cells[2].Value as string; if ("type".Equals(name)) { row.Cells[1].Value = edtName.Text; break; } } signalAttributes.Rows.Clear(); if (string.IsNullOrEmpty(edtName.Text)) { edtName.Text = signal.name; } var dao = new SignalDAO(); dbSignal dataSignal = dao.getSignal(signal.name, signalModel.SignalNameSpace); string xmlns = signalModel.SignalNameSpace; XmlSchemaComplexType complexType; XmlSchemaElement element = null; SchemaManager.GetComplexType(xmlns, signal.name, out complexType); if (complexType == null) { SchemaManager.GetElement(xmlns, signal.name, out element); } if (complexType != null || element != null) { signalAttributes.Rows.Clear(); List <XmlSchemaAttribute> schemaAttributes = complexType != null ? SchemaManager.GetAttributes(complexType) : SchemaManager.GetAttributes(element); List <dbSignalAttribute> dbAttributes = dao.getAllSignalAttributes(signal.name, signalModel.SignalNameSpace); var foundAttributes = new Dictionary <string, dbSignalAttribute>(); foreach (dbSignalAttribute attribute in dbAttributes) { foundAttributes.Add(attribute.attributeName, attribute); object value = null; try { if (_signalFunctionType != null) { PropertyInfo pi = _signalFunctionType.GetType().GetProperty(attribute.attributeName); if (pi != null) { value = pi.GetValue(_signalFunctionType, null); } } } catch (Exception err) { LogManager.Error(err); } int idx = signalAttributes.Rows.Add(new[] { attribute.attributeName, attribute.type, value }); signalAttributes.Rows[idx].Tag = attribute; } //-----------------------------------------------------------------------------// //--- Check the database for each of the attributes found in the schema. If ---// //--- the attribute does not exist in the database the add it. ---// //-----------------------------------------------------------------------------// signalAttributes.Rows.Clear(); foreach (XmlSchemaAttribute attribute in schemaAttributes) { string name = attribute.Name; if (!foundAttributes.ContainsKey(name)) { var dbSignalAttribute = new dbSignalAttribute(); dbSignalAttribute.signalId = dataSignal.signalId; dbSignalAttribute.attributeName = name; dbSignalAttribute.defaultValue = attribute.DefaultValue; dbSignalAttribute.fixedValue = attribute.FixedValue; if (attribute.AttributeSchemaType != null) { dbSignalAttribute.type = attribute.AttributeSchemaType.Name; } dbSignalAttribute.DataState = BASEBean.eDataState.DS_ADD; dbSignalAttribute.save(); int idx = signalAttributes.Rows.Add(new[] { name, dbSignalAttribute.type, null }); signalAttributes.Rows[idx].Tag = attribute; } } } } } } finally { HourGlass.Enabled = false; } }