private void AllCustomFieldDefs_ListChanged(object sender, ListChangedEventArgs e) { // If we have dirty custom fields we'll need to preserve those values. RobotList <OrgCustomField> mydefs = OrgCustomField.GetOrgCustomFields(this); foreach (OrgCustomField new_cf in mydefs) { OrgCustomField old_cf = m_customFields.Find( delegate(OrgCustomField checkObj, int id) { return(checkObj.Def.Id == id); }, new_cf.Def.Id); if (old_cf == null) { continue; } new_cf.Value = old_cf.Value; } m_customFields = mydefs; NotifyPropertyChanged("CustomFields"); }
public static RobotList <OrgCustomField> GetOrgCustomFields(Organization org) { RobotList <OrgCustomField> rval = new RobotList <OrgCustomField>(); SqlConnection cn = new SqlConnection(Helpers.CnnStr()); SafeDataReader dr = null; SqlTransaction tr; SqlCommand cmd; cn.Open(); tr = cn.BeginTransaction(IsolationLevel.ReadCommitted); try { cmd = cn.CreateCommand(); cmd.Transaction = tr; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "usp_GetOrgCustomFields"; cmd.Parameters.AddWithValue("@org_id", org.Id); dr = new SafeDataReader(cmd.ExecuteReader()); while (dr.Read()) { int defId = dr.GetInt32(dr.GetOrdinal("def_id")); CustomFieldDef def = CustomFieldDef.AllDefs.Find(CustomFieldDef.ById, defId); if (def == null) { continue; } OrgCustomField cf = new OrgCustomField(def, org); cf.DoLoad(dr); rval.Add(cf); } dr.Close(); tr.Commit(); } catch { tr.Rollback(); throw; } finally { if ((dr != null) && !dr.IsClosed) { dr.Close(); } cn.Close(); } /* * Make sure all the currently defined custom field definitions * are listed. */ foreach (CustomFieldDef def in CustomFieldDef.AllDefs) { OrgCustomField cf = rval.Find( delegate(OrgCustomField obj, CustomFieldDef p) { return(obj.Def == p); }, def); if (cf == null) { cf = new OrgCustomField(def, org); rval.Add(cf); } } return(rval); }