コード例 #1
0
ファイル: Workplace.cs プロジェクト: paulusyeung/RT2020
        /// <summary>
        /// Loads a collection of Workplace objects from the database.
        /// </summary>
        /// <returns>A collection containing all of the Workplace objects in the database.</returns>
        public static WorkplaceCollection LoadCollection(string spName, SqlParameter[] parms)
        {
            WorkplaceCollection result = new WorkplaceCollection();

            using (SqlDataReader reader = SqlHelper.Default.ExecuteReader(spName, parms))
            {
                while (reader.Read())
                {
                    Workplace tmp = new Workplace();
                    tmp.LoadFromReader(reader);
                    result.Add(tmp);
                }
            }
            return(result);
        }
コード例 #2
0
        public void BtnDeleteSelectedWorkplace()
        {
            //If not found
            if (WorkplaceCollection.Where(x => x == SelectedWorkplace).Count() == 0)
            {
                return;
            }

            //Find the entryrow
            Workplace workplace = WorkplaceCollection.FirstOrDefault(x => x == SelectedWorkplace);

            //Delete from datagrid
            WorkplaceCollection.Remove(workplace);
            NotifyOfPropertyChange(() => WorkplaceCollection);

            // Archives the selected workplace
            using (var ctx = new DatabaseDir.Database())
            {
                ctx.Workplaces.First(x => x.Id == workplace.Id).Archived = true;
                ctx.SaveChanges();
            }
        }