/**
  *  Get Country Line
  *  @param local if true only foreign country is returned
  *  @return country or null
  */
 public String GetCountry(bool local)
 {
     if (local && GetC_Country_ID() == MCountry.GetDefault(GetCtx()).GetC_Country_ID())
     {
         return(null);
     }
     return(GetCountryName());
 }
 /// <summary>
 /// Set C_Country_ID
 /// </summary>
 /// <param name="C_Country_ID"></param>
 public new void SetC_Country_ID(int C_Country_ID)
 {
     if (GetC_Country_ID() != C_Country_ID)
     {
         SetRegion(null);
     }
     SetCountry(MCountry.Get(GetCtx(), C_Country_ID));
 }
 /**
  *  Print Address Reverse Order
  *	@return true if reverse depending on country
  */
 public bool IsAddressLinesReverse()
 {
     //	Local
     if (GetC_Country_ID() == MCountry.GetDefault(GetCtx()).GetC_Country_ID())
     {
         return(GetCountry().IsAddressLinesLocalReverse());
     }
     return(GetCountry().IsAddressLinesReverse());
 }
示例#4
0
 /// <summary>
 /// Return Countries as Array
 /// </summary>
 /// <param name="ctx">context</param>
 /// <returns>MCountry Array</returns>
 ///@SuppressWarnings("unchecked")
 public static MCountry[] GetCountries(Ctx ctx)
 {
     if (s_countries == null || s_countries.Count == 0)
     {
         LoadAllCountries(ctx);
     }
     MCountry[] retValue = new MCountry[s_countries.Count];
     retValue = s_countries.Values.ToArray();
     Array.Sort(retValue, new MCountry(ctx, 0, null));
     return(retValue);
 }
 /// <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());
 }
 /// <summary>
 /// Get Country
 /// </summary>
 public MCountry GetCountry()
 {
     if (_country == null)
     {
         if (GetC_Country_ID() != 0)
         {
             _country = MCountry.Get(GetCtx(), GetC_Country_ID());
         }
         else
         {
             _country = MCountry.GetDefault(GetCtx());
         }
     }
     return(_country);
 }
 /// <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);
         }
     }
 }
示例#8
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);
        }
示例#9
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);
        }
 /**
  *  Set C_Region_ID
  *	@param C_Region_ID region
  */
 public new void SetC_Region_ID(int C_Region_ID)
 {
     if (C_Region_ID == 0)
     {
         SetRegion(null);
     }
     //	Country defined
     else if (GetC_Country_ID() != 0)
     {
         MCountry cc = GetCountry();
         if (cc.IsValidRegion(C_Region_ID))
         {
             base.SetC_Region_ID(C_Region_ID);
         }
         else
         {
             SetRegion(null);
         }
     }
     else
     {
         SetRegion(MRegion.Get(GetCtx(), C_Region_ID));
     }
 }
示例#11
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);
 }
        /**
         *	Parse according Ctiy/Postal/Region according to displaySequence.
         *	@C@ - City		@R@ - Region	@P@ - Postal  @A@ - PostalAdd
         *  @param c country
         *  @return parsed String
         */
        private String ParseCRP(MCountry c)
        {
            if (c == null)
            {
                return("CountryNotFound");
            }
            bool          local  = GetC_Country_ID() == MCountry.GetDefault(GetCtx()).GetC_Country_ID();
            String        inStr  = local ? c.GetDisplaySequenceLocal() : c.GetDisplaySequence();
            StringBuilder outStr = new StringBuilder();

            String token;
            int    i = inStr.IndexOf("@");

            while (i != -1)
            {
                outStr.Append(inStr.Substring(0, i));                   // up to @
                inStr = inStr.Substring(i + 1, inStr.Length - (i + 1)); // from first @

                int j = inStr.IndexOf("@");                             // next @
                if (j < 0)
                {
                    token = "";                                                                 //	no second tag
                    j     = i + 1;
                }
                else
                {
                    token = inStr.Substring(0, j);
                }
                //	Tokens
                if (token.Equals("C"))
                {
                    if (GetCity() != null)
                    {
                        outStr.Append(GetCity());
                    }
                }
                else if (token.Equals("R"))
                {
                    if (GetRegion() != null)                                    //	we have a region
                    {
                        outStr.Append(GetRegion().GetName());
                    }
                    else if (base.GetRegionName() != null && base.GetRegionName().Length > 0)
                    {
                        outStr.Append(base.GetRegionName());    //	local region name
                    }
                }
                else if (token.Equals("P"))
                {
                    if (GetPostal() != null)
                    {
                        outStr.Append(GetPostal());
                    }
                }
                else if (token.Equals("A"))
                {
                    String add = GetPostal_Add();
                    if (add != null && add.Length > 0)
                    {
                        outStr.Append("-").Append(add);
                    }
                }
                else
                {
                    outStr.Append("@").Append(token).Append("@");
                }

                inStr = inStr.Substring(j + 1, inStr.Length - (j + 1)); // from second @
                i     = inStr.IndexOf("@");
            }
            outStr.Append(inStr);                                               // add the rest of the string

            //	Print Region Name if entered and not part of pattern
            if (c.GetDisplaySequence().IndexOf("@R@") == -1 &&
                base.GetRegionName() != null && base.GetRegionName().Length > 0)
            {
                outStr.Append(" ").Append(base.GetRegionName());
            }

            String retValue = Utility.Util.Replace(outStr.ToString(), "\\n", "\n");

            log.Finest("parseCRP - " + c.GetDisplaySequence() + " -> " + retValue);
            return(retValue);
        }
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="country">mandatory country</param>
 /// <param name="region">optional region</param>
 public MLocation(MCountry country, MRegion region)
     : base(country.GetCtx(), 0, country.Get_TrxName())
 {
     SetCountry(country);
     SetRegion(region);
 }