Beispiel #1
0
        public IDBObject ConvertToDBObject()
        {
            DB_Payee dbPay = new DB_Payee();

            dbPay.ID       = this.ID.ToString();
            dbPay.IsActive = this.IsActive;
            dbPay.Name     = this.Name;

            return(dbPay);
        }
Beispiel #2
0
        public void ConvertFromDBObject(IDBObject obj)
        {
            if (!(obj is DB_Payee))
            {
                return;
            }

            DB_Payee dbPay = obj as DB_Payee;

            this.ID       = Guid.Parse(dbPay.ID);
            this.IsActive = dbPay.IsActive;
            this.Name     = dbPay.Name;

            DataHelper.AddItem(this);
        }
Beispiel #3
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;
                }
            }
        }
Beispiel #4
0
        public static List <IDBObject> Convert <T>(DataSet ds)
        {
            List <IDBObject> objects = new List <IDBObject>();

            if (typeof(T).FullName == typeof(DB_Account).FullName)
            {
                foreach (DataRow row in ds.Tables["Account"].Rows)
                {
                    DB_Account acc = new DB_Account();
                    acc.ID          = row["ID"].ToString();
                    acc.IsActive    = bool.Parse(row["IsActive"].ToString());
                    acc.IsOffBudget = bool.Parse(row["IsOffBudget"].ToString());
                    acc.Name        = row["Name"].ToString();
                    acc.Note        = row["Note"].ToString();
                    acc.Type        = row["Type"].ToString();

                    objects.Add(acc);
                }
            }
            else if (typeof(T).FullName == typeof(DB_Entry).FullName)
            {
                foreach (DataRow row in ds.Tables["Entry"].Rows)
                {
                    DB_Entry ent = new DB_Entry();
                    ent.Account  = row["Account"].ToString();
                    ent.Category = row["Category"].ToString();
                    ent.Date     = row["Date"].ToString();
                    ent.ID       = row["ID"].ToString();
                    ent.Inflow   = decimal.Parse(row["Inflow"].ToString());
                    ent.Outflow  = decimal.Parse(row["Outflow"].ToString());
                    ent.Payee    = row["Payee"].ToString();

                    objects.Add(ent);
                }
            }
            else if (typeof(T).FullName == typeof(DB_Category).FullName)
            {
                foreach (DataRow row in ds.Tables["Category"].Rows)
                {
                    DB_Category cat = new DB_Category();
                    cat.ID = row["ID"].ToString();
                    cat.IsMasterCategory = bool.Parse(row["IsMasterCategory"].ToString());
                    cat.Name             = row["Name"].ToString();
                    cat.ParentCategory   = row["ParentCategory"].ToString();

                    objects.Add(cat);
                }
            }
            else if (typeof(T).FullName == typeof(DB_Payee).FullName)
            {
                foreach (DataRow row in ds.Tables["Payee"].Rows)
                {
                    DB_Payee pay = new DB_Payee();
                    pay.ID       = row["ID"].ToString();
                    pay.IsActive = bool.Parse(row["IsActive"].ToString());
                    pay.Name     = row["Name"].ToString();

                    objects.Add(pay);
                }
            }

            return(objects);
        }