Example #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);
        }
 /**
  *  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());
         }
     }
 }
Example #3
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);
        }