Exemple #1
0
        public void ConvertFromDBObject(IDBObject obj)
        {
            if (!(obj is DB_Category))
            {
                return;
            }

            DB_Category dbCat = obj as DB_Category;

            this.ID = Guid.Parse(dbCat.ID);
            this.IsMasterCategory = dbCat.IsMasterCategory;
            this.Name             = dbCat.Name;

            DataHelper.AddItem(this);

            if (!string.IsNullOrEmpty(dbCat.ParentCategory))
            {
                DB_Category parentDBCat = new DB_Category();
                parentDBCat.Load(dbCat.ParentCategory);
                ISaveable saveable = DataHelper.LoadedObjects.FirstOrDefault(lo => lo.ID.ToString() == parentDBCat.ID);
                if (saveable != null)
                {
                    Category parentCat = DataHelper.LoadedObjects.Where(lo => lo is Category).Cast <Category>().FirstOrDefault(lo => lo.ID.ToString() == parentDBCat.ID);
                    this.ParentCategory = parentCat;
                }
                else
                {
                    Category parentCat = new Category();
                    parentCat.ConvertFromDBObject(parentDBCat);
                    this.ParentCategory = parentCat;
                }
            }
        }
Exemple #2
0
        public void ConvertFromDBObject(IDBObject obj)
        {
            if (!(obj is DB_Entry))
            {
                return;
            }

            DB_Entry ent = obj as DB_Entry;

            this.Date    = DateTime.Parse(ent.Date);
            this.ID      = Guid.Parse(ent.ID);
            this.Inflow  = ent.Inflow;
            this.Outflow = ent.Outflow;

            DataHelper.AddItem(this);

            if (!string.IsNullOrEmpty(ent.Account))
            {
                DB_Account dbAcc = new DB_Account();
                dbAcc.Load(ent.Account);
                ISaveable saveable = DataHelper.LoadedObjects.FirstOrDefault(lo => lo.ID.ToString() == dbAcc.ID);
                if (saveable != null)
                {
                    Account acc = DataHelper.LoadedObjects.Where(lo => lo is Account).Cast <Account>().FirstOrDefault(lo => lo.ID.ToString() == dbAcc.ID);
                    this.Account = acc;
                }
                else
                {
                    Account acc = new Account();
                    acc.ConvertFromDBObject(dbAcc);
                    this.Account = acc;
                }
            }

            if (!string.IsNullOrEmpty(ent.Category))
            {
                DB_Category dbCat = new DB_Category();
                dbCat.Load(ent.Category);
                ISaveable saveable = DataHelper.LoadedObjects.FirstOrDefault(lo => lo.ID.ToString() == dbCat.ID);
                if (saveable != null)
                {
                    Category cat = DataHelper.LoadedObjects.Where(lo => lo is Category).Cast <Category>().FirstOrDefault(lo => lo.ID.ToString() == dbCat.ID);
                    this.Category = cat;
                }
                else
                {
                    Category cat = new Category();
                    cat.ConvertFromDBObject(dbCat);
                    this.Category = cat;
                }
            }

            if (!string.IsNullOrEmpty(ent.Payee))
            {
                DB_Payee dbPay = new DB_Payee();
                dbPay.Load(ent.Payee);
                ISaveable saveable = DataHelper.LoadedObjects.FirstOrDefault(lo => lo.ID.ToString() == dbPay.ID);
                if (saveable != null)
                {
                    Payee pay = DataHelper.LoadedObjects.Where(lo => lo is Payee).Cast <Payee>().FirstOrDefault(lo => lo.ID.ToString() == dbPay.ID);
                    this.Payee = pay;
                }
                else
                {
                    Payee pay = new Payee();
                    pay.ConvertFromDBObject(dbPay);
                    this.Payee = pay;
                }
            }
        }