/// <summary>
 /// Set Country
 /// </summary>
 /// <param name="country">country</param>
 public void SetCountry(MCountry country)
 {
     if (country != null)
     {
         _country = country;
     }
     else
     {
         _country = MCountry.GetDefault(GetCtx());
     }
     base.SetC_Country_ID(_country.GetC_Country_ID());
 }
Exemple #2
0
        /// <summary>
        /// Load active Countries (no summary).
        /// Set Default Language to Client Language
        /// </summary>
        /// <param name="ctx">Ctx</param>
        private static void LoadAllCountries(Ctx ctx)
        {
            MClient   client = MClient.Get(ctx);
            MLanguage lang   = MLanguage.Get(ctx, client.GetAD_Language());
            MCountry  usa    = null;
            //

            int countryID = Util.GetValueOfInt(ctx.Get("P|C_Country_ID"));

            s_countries = new CCache <String, MCountry>("C_Country", 250);
            String sql = "SELECT * FROM C_Country WHERE IsActive='Y' AND IsSummary='N'";

            try
            {
                DataSet ds = DataBase.DB.ExecuteDataset(sql, null, null);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow  dr = ds.Tables[0].Rows[i];
                    MCountry c  = new MCountry(ctx, dr, null);
                    s_countries.Add(c.GetC_Country_ID().ToString(), c);
                    //	Country code of Client Language
                    if (lang != null && lang.GetCountryCode().Equals(c.GetCountryCode()) && _default == null)
                    {
                        _default = c;
                    }
                    else if (countryID == c.GetC_Country_ID())
                    {
                        _default = c;
                    }
                    if (c.GetC_Country_ID() == 100)             //	USA
                    {
                        usa = c;
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            if (_default == null)
            {
                _default = usa;
            }
            _log.Fine("#" + s_countries.Size()
                      + " - Default=" + _default);
        }
 /// <summary>
 /// Standard Constructor
 /// </summary>
 /// <param name="ctx">context</param>
 /// <param name="C_Location_ID">id</param>
 /// <param name="trxName">transaction</param>
 public MLocation(Ctx ctx, int C_Location_ID, Trx trxName)
     : base(ctx, C_Location_ID, trxName)
 {
     if (C_Location_ID == 0)
     {
         MCountry defaultCountry = MCountry.GetDefault(GetCtx());
         SetCountry(defaultCountry);
         MRegion defaultRegion = MRegion.GetDefault(GetCtx());
         if (defaultRegion != null &&
             defaultRegion.GetC_Country_ID() == defaultCountry.GetC_Country_ID())
         {
             SetRegion(defaultRegion);
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Get Country (cached)
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="C_Country_ID">ID</param>
        /// <returns>Country</returns>
        public static MCountry Get(Ctx ctx, int C_Country_ID)
        {
            if (s_countries == null || s_countries.Count == 0)
            {
                LoadAllCountries(ctx);
            }
            String   key = C_Country_ID.ToString();
            MCountry c   = (MCountry)s_countries[key];

            if (c != null)
            {
                return(c);
            }
            c = new MCountry(ctx, C_Country_ID, null);
            if (c.GetC_Country_ID() == C_Country_ID)
            {
                s_countries.Add(key, c);
                return(c);
            }
            return(null);
        }
Exemple #5
0
 /**
  *  Parent Constructor
  *	@param country country
  *	@param regionName Region Name
  */
 public MRegion(MCountry country, String regionName)
     : base(country.GetCtx(), 0, country.Get_TrxName())
 {
     SetC_Country_ID(country.GetC_Country_ID());
     SetName(regionName);
 }