Ejemplo n.º 1
0
        private void LoadCustomFields()
        {
            m_customFields = new RobotList <OrgCustomField>();

            //m_customFields = OrgCustomField.GetOrgCustomFields(this);
            //CustomFieldDef.AllDefs.ListChanged += AllCustomFieldDefs_ListChanged;
        }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        public static RobotList <Contact> GetOrganizationContacts(Organization o)
        {
            RobotList <Contact> rval = new RobotList <Contact>();
            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_GetOrganizationContacts";

                cmd.Parameters.AddWithValue("@org_id", o.Id);

                dr = new SafeDataReader(cmd.ExecuteReader());

                while (dr.Read())
                {
                    Contact c = new Contact(o);
                    c.DoLoad(dr);
                    rval.Add(c);
                }

                dr.Close();
                tr.Commit();
            }
            catch
            {
                if ((dr != null) && !dr.IsClosed)
                {
                    dr.Close();
                }

                tr.Rollback();
                throw;
            }
            finally
            {
                if ((dr != null) && !dr.IsClosed)
                {
                    dr.Close();
                }

                cn.Close();
            }

            return(rval);
        }
Ejemplo n.º 4
0
        private static RobotList <Country> GetCountries()
        {
            RobotList <Country> rval = new RobotList <Country>();
            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_GetCountryList";

                dr = new SafeDataReader(cmd.ExecuteReader());

                while (dr.Read())
                {
                    Country c = new Country();
                    c.DoLoad(dr);
                    rval.Add(c);
                }

                dr.Close();
                tr.Commit();
            }
            catch
            {
                if ((dr != null) && !dr.IsClosed)
                {
                    dr.Close();
                }

                tr.Rollback();
                throw;
            }
            finally
            {
                if ((dr != null) && !dr.IsClosed)
                {
                    dr.Close();
                }

                cn.Close();
            }

            return(rval);
        }
Ejemplo n.º 5
0
        protected static RobotList <Organization> LoadList(SafeDataReader dr)
        {
            RobotList <Organization> rval = new RobotList <Organization>();

            while (dr.Read())
            {
                Organization o = new Organization();
                o.Load(dr);
                rval.Add(o);
            }

            return(rval);
        }
Ejemplo n.º 6
0
        public RobotList <ItemTy> FindAll <ParamTy>(FindDelegate <ParamTy> func, ParamTy p)
        {
            RobotList <ItemTy> rval = new RobotList <ItemTy>();

            foreach (ItemTy i in this)
            {
                if (func(i, p))
                {
                    rval.Add(i);
                }
            }

            return(rval);
        }
Ejemplo n.º 7
0
        public static RobotList <Organization> GetActiveOrganizations()
        {
            RobotList <Organization> rval = new RobotList <Organization>();
            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_GetActiveOrganizations";

                dr   = new SafeDataReader(cmd.ExecuteReader());
                rval = LoadList(dr);

                dr.Close();
                tr.Commit();
            }
            catch (Exception ex)
            {
                tr.Rollback();
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if ((dr != null) && !dr.IsClosed)
                {
                    dr.Close();
                }

                cn.Close();
            }

            return(rval);
        }
Ejemplo n.º 8
0
        public RobotList <ItemTy> FindAll <ParamTy>(string PropName, ParamTy p)
        {
            RobotList <ItemTy> rval = new RobotList <ItemTy>();
            Type         t          = typeof(ItemTy);
            PropertyInfo pi         = t.GetProperty(PropName);

            if (pi == null)
            {
                throw new Exception("Invalid property name: " + PropName);
            }

            if (pi.PropertyType.IsArray)
            {
                string msg = String.Format("Property {0} is an array type.",
                                           PropName);
                throw new Exception(msg);
            }

            if (pi.PropertyType != typeof(ParamTy))
            {
                throw new Exception("Property not of type: " +
                                    typeof(ParamTy).Name);
            }

            foreach (ItemTy i in this)
            {
                ParamTy objVal = (ParamTy)pi.GetValue(i, null);

                if (objVal.Equals(p))
                {
                    rval.Add(i);
                }
            }

            return(rval);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 private void LoadContacts()
 {
     m_contacts = Contact.GetOrganizationContacts(this);
 }
Ejemplo n.º 11
0
 private void LoadAddresses()
 {
     m_addresses = Address.GetOrganizationAddresses(this);
 }