Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public static bool ById(CustomFieldDef def, int id)
 {
     return(def.Id == id);
 }
Esempio n. 3
0
 public OrgCustomField(CustomFieldDef def, Organization org)
 {
     m_def = def;
     m_org = org;
 }