예제 #1
0
        /*  Load Regions (cached)
         *	@param ctx context
         */
        private static void LoadAllRegions(Ctx ctx)
        {
            s_regions = new CCache <String, MRegion>("C_Region", 100);
            String sql = "SELECT * FROM C_Region WHERE IsActive='Y'";

            try
            {
                DataSet stmt = DataBase.DB.ExecuteDataset(sql, null, null);
                for (int i = 0; i < stmt.Tables[0].Rows.Count; i++)
                {
                    DataRow rs = stmt.Tables[0].Rows[i];
                    MRegion r  = new MRegion(ctx, rs, null);
                    s_regions.Add(r.GetC_Region_ID().ToString(), r);
                    if (r.IsDefault())
                    {
                        s_default = r;
                    }
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, sql, e);
            }
            _log.Fine(s_regions.Count + " - default=" + s_default);
        }
 /**
  *  Get Region
  *	@return region
  */
 public MRegion GetRegion()
 {
     if (_region == null && GetC_Region_ID() != 0)
     {
         _region = MRegion.Get(GetCtx(), GetC_Region_ID());
     }
     return(_region);
 }
예제 #3
0
 /**
  *	Return Regions as Array
  *  @param ctx context
  *  @return MCountry Array
  */
 //@SuppressWarnings("unchecked")
 public static MRegion[] GetRegions(Ctx ctx)
 {
     if (s_regions == null || s_regions.Count == 0)
     {
         LoadAllRegions(ctx);
     }
     MRegion[] retValue = new MRegion[s_regions.Count];
     retValue = s_regions.Values.ToArray();
     Array.Sort(retValue, new MRegion(ctx, 0, null));
     return(retValue);
 }
 /// <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);
         }
     }
 }
예제 #5
0
 /// <summary>
 /// Is the region valid in the country
 /// </summary>
 /// <param name="C_Region_ID">region</param>
 /// <returns>true if valid</returns>
 public bool IsValidRegion(int C_Region_ID)
 {
     if (C_Region_ID == 0 ||
         GetC_Country_ID() == 0 ||
         !IsHasRegion())
     {
         return(false);
     }
     MRegion[] regions = MRegion.GetRegions(GetCtx(), GetC_Country_ID());
     for (int i = 0; i < regions.Length; i++)
     {
         if (C_Region_ID == regions[i].GetC_Region_ID())
         {
             return(true);
         }
     }
     return(false);
 }
 /**
  *  Set Region
  *	@param region
  */
 public void SetRegion(MRegion region)
 {
     _region = region;
     if (region == null)
     {
         base.SetC_Region_ID(0);
     }
     else
     {
         base.SetC_Region_ID(_region.GetC_Region_ID());
         if (_region.GetC_Country_ID() != GetC_Country_ID())
         {
             log.Info("Region(" + region + ") C_Country_ID=" + region.GetC_Country_ID()
                      + " - From  C_Country_ID=" + GetC_Country_ID());
             SetC_Country_ID(region.GetC_Country_ID());
         }
     }
 }
예제 #7
0
        /**
         *  Get Country (cached)
         *  @param ctx context
         *	@param C_Region_ID ID
         *	@return Country
         */
        public static MRegion Get(Ctx ctx, int C_Region_ID)
        {
            if (s_regions == null || s_regions.Count == 0)
            {
                LoadAllRegions(ctx);
            }
            String  key = C_Region_ID.ToString();
            MRegion r   = (MRegion)s_regions[key];

            if (r != null)
            {
                return(r);
            }
            r = new MRegion(ctx, C_Region_ID, null);
            if (r.GetC_Region_ID() == C_Region_ID)
            {
                s_regions.Add(key, r);
                return(r);
            }
            return(null);
        }
예제 #8
0
        /**
         *	Return Array of Regions of Country
         *  @param ctx context
         *  @param C_Country_ID country
         *  @return MRegion Array
         */
        //@SuppressWarnings("unchecked")
        public static MRegion[] GetRegions(Ctx ctx, int C_Country_ID)
        {
            if (s_regions == null || s_regions.Count == 0)
            {
                LoadAllRegions(ctx);
            }
            List <MRegion> list = new List <MRegion>();
            //iterator it = s_regions.Values.iterator();
            IEnumerator it = s_regions.Values.GetEnumerator();

            while (it.MoveNext())
            {
                MRegion r = (MRegion)it.Current;
                if (r.GetC_Country_ID() == C_Country_ID)
                {
                    list.Add(r);
                }
            }
            //  Sort it
            MRegion[] retValue = new MRegion[list.Count];
            retValue = list.ToArray();
            Array.Sort(retValue, new MRegion(ctx, 0, null));
            return(retValue);
        }
 /**
  *  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));
     }
 }
 /// <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);
 }