Ejemplo n.º 1
0
        public static RangeGroup Load(Guid Id)
        {
            bool success = false;
            RangeGroup result = new RangeGroup ();

            QueryBuilder qb = new QueryBuilder (QueryBuilderType.Select);
            qb.Table (DatabaseTableName);
            qb.Columns
                (
                    "id",
                    "createtimestamp",
                    "updatetimestamp",
                    "name",
                    "rangeids",
                    "countrycodeids",
                    "costpriceids",
                    "retailpriceids"
                );

            qb.AddWhere ("id", "=", Id);

            Query query = Runtime.DBConnection.Query (qb.QueryString);

            if (query.Success)
            {
                if (query.NextRow ())
                {
                    result._id = query.GetGuid (qb.ColumnPos ("id"));
                    result._createtimestamp = query.GetInt (qb.ColumnPos ("createtimestamp"));
                    result._updatetimestamp = query.GetInt (qb.ColumnPos ("updatetimestamp"));
                    result._name = query.GetString (qb.ColumnPos ("name"));
                    result._rangeids = SNDK.Convert.StringToList<Guid> (query.GetString (qb.ColumnPos ("rangeids")));
                    result._countrycodeids = SNDK.Convert.StringToList<Guid> (query.GetString (qb.ColumnPos ("countrycodeids")));
                    result._costpriceids = SNDK.Convert.StringToList<Guid> (query.GetString (qb.ColumnPos ("costpriceids")));
                    result._retailpriceids = SNDK.Convert.StringToList<Guid> (query.GetString (qb.ColumnPos ("retailpriceids")));

                    success = true;
                }
            }

            query.Dispose ();
            query = null;
            qb = null;

            if (!success)
            {
                throw new Exception (string.Format (Strings.Exception.RangeGroupLoad, Id));
            }

            return result;
        }
Ejemplo n.º 2
0
        public static RangeGroup FromXmlDocument(XmlDocument xmlDocument)
        {
            Hashtable item = (Hashtable)SNDK.Convert.FromXmlDocument (xmlDocument);

            RangeGroup result;

            if (item.ContainsKey ("id"))
            {
                try
                {
                    result = RangeGroup.Load (new Guid ((string)item["id"]));
                }
                catch
                {
                    result = new RangeGroup ();
                    result._id = new Guid ((string)item["id"]);
                }
            }
            else
            {
                result = new RangeGroup ();
            }

            if (item.ContainsKey ("name"))
            {
                result._name = (string)item["name"];
            }

            if (item.ContainsKey ("ranges"))
            {
                result._rangeids.Clear ();
                foreach (XmlDocument range in (List<XmlDocument>)item["ranges"])
                {
                    result._rangeids.Add (Range.FromXmlDocument (range).Id);
                }
            }

            if (item.ContainsKey ("countrycodes"))
            {
                result._countrycodeids.Clear ();
                foreach (XmlDocument countrycode in (List<XmlDocument>)item["countrycodes"])
                {
                    result._countrycodeids.Add (CountryCode.FromXmlDocument (countrycode).Id);
                }
            }

            if (item.ContainsKey ("costprices"))
            {
                result._temp_costprices = new List<RangePrice> ();
                foreach (XmlDocument rangeprice in (List<XmlDocument>)item["costprices"])
                {
                    result._temp_costprices.Add (RangePrice.FromXmlDocument (rangeprice));
                }
            }

            if (item.ContainsKey ("retailprices"))
            {
                result._temp_retailprices = new List<RangePrice> ();
                foreach (XmlDocument rangeprice in (List<XmlDocument>)item["retailprices"])
                {
                    result._temp_retailprices.Add (RangePrice.FromXmlDocument (rangeprice));
                }
            }

            return result;
        }