Пример #1
0
        public MainWindow()
        {
            InitializeComponent();
            //Create first user, only when no other user exists in DB
            e_Tagebuch_Context DB = new e_Tagebuch_Context();

            if (!DB.Users.Any())
            {
                controlling con = new controlling();
                con.Create_User("User", "Password");
            }

            //Create all possible types
            string[] Types = new string[] { "Work", "Family", "Holidays", "Birthday", "School" };
            foreach (string typeName in Types)
            {
                if (!DB.Types.Any(t => t.Name == typeName))
                {
                    DB.Types.Add(new Type()
                    {
                        Name = typeName
                    });
                }
            }
            DB.SaveChanges();
        }
Пример #2
0
 public User Check_Credential(string t_Username, string t_Password)
 {
     using (var DB = new e_Tagebuch_Context())
     {
         return(DB.Users.FirstOrDefault(u => u.Username == t_Username && u.Password == t_Password));
     }
 }
Пример #3
0
        //the names of the methods should be selfexplaining  ;)
        public Diary Get_DiaryFromEntry(int t_EntryID)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();
            int diaryID           = DB.Entries.FirstOrDefault(e => e.EntryID == t_EntryID).Diary_id;

            return(DB.Diaries.FirstOrDefault(d => d.DiaryID == diaryID));
        }
Пример #4
0
        public void Save_types(int t_EntryID, string[] t_typ)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();
            var    entry          = DB.Entries.FirstOrDefault(e => e.EntryID == t_EntryID);
            string type           = string.Join(",", t_typ);

            entry.Type = type;
            DB.SaveChanges();
        }
Пример #5
0
        public string[] Get_types(int t_EntryID)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();
            var entry             = DB.Entries.FirstOrDefault(e => e.EntryID == t_EntryID);

            if (entry.Type != null)
            {
                return(entry.Type.Split(','));
            }
            return(null);
        }
Пример #6
0
        public List <Entry> Get_AllEntries(int t_DiaryID)
        {
            List <Entry> AllEntries = new List <Entry>();

            using (var DB = new e_Tagebuch_Context())
            {
                //Get list of all entries
                AllEntries = DB.Entries.Where(e => e.Diary_id == t_DiaryID).ToList();
            }
            return(AllEntries);
        }
Пример #7
0
        public List <String> Get_AllDiaries(int t_UserID)
        {
            List <String> AllDiaries = new List <String>();

            using (var DB = new e_Tagebuch_Context())
            {
                //Get list of all entries
                AllDiaries = DB.Diaries.Where(d => d.user_id == t_UserID).Select(d => d.Name).ToList();
            }
            return(AllDiaries);
        }
Пример #8
0
        public User Create_User(string t_User, string t_Pw)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();
            var newUser           = DB.Users.Add(new User()
            {
                Username = t_User,
                Password = t_Pw
            });

            DB.SaveChanges();
            return(newUser);
        }
Пример #9
0
        public Boolean Check_MoreThan(int t_DiaryID)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();
            var Entries           = DB.Entries.Where(e => e.Diary_id == t_DiaryID);

            if (Entries.Count() >= 100)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #10
0
        public bool Remove_Entry(int t_EntryID)
        {
            bool returnValue = true;

            try
            {
                e_Tagebuch_Context DB = new e_Tagebuch_Context();
                DB.Entries.Remove(DB.Entries.FirstOrDefault(e => e.EntryID == t_EntryID));
                DB.SaveChanges();
            } catch
            {
                returnValue = false;
            }

            return(returnValue);
        }
Пример #11
0
        public void Save_Entry(int t_ID, string t_Name, DateTime t_Date, string t_Text, string t_Picture)
        {
            using (var DB = new e_Tagebuch_Context())
            {
                //Get entry
                var entry = DB.Entries.FirstOrDefault(e => e.EntryID == t_ID);

                //set current values
                entry.Name    = t_Name;
                entry.Date    = t_Date.Date;
                entry.Text    = t_Text;
                entry.Picture = t_Picture;

                //Save
                DB.SaveChanges();
            }
        }
Пример #12
0
        public int Create_Entry(string t_Name, int t_DiaryID)
        {
            int id = -1;

            using (var DB = new e_Tagebuch_Context())
            {
                //Create entry
                var newEntry = DB.Entries.Add(new Entry()
                {
                    Name     = t_Name,
                    Diary_id = t_DiaryID,
                    Date     = DateTime.Now.Date
                });
                DB.SaveChanges();
                id = newEntry.EntryID;
            }
            return(id);
        }
Пример #13
0
        public frmSearchWindow(int t_DiaryID)
        {
            DiaryID = t_DiaryID;
            InitializeComponent();
            //Add types to combobox
            e_Tagebuch_Context con = new e_Tagebuch_Context();

            foreach (var typ in con.Types)
            {
                cmbType.Items.Add(typ.Name);
            }

            //Set Current Diary in GUI
            var diary = con.Diaries.FirstOrDefault(d => d.DiaryID == DiaryID);

            txtTagebuch.Text = diary.Name;

            Update_EntryView();
        }
Пример #14
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //create a instance of controlling
            controlling con = new controlling();

            //Get id of the diary
            if (cmbDiaries.SelectedItem != null)
            {
                e_Tagebuch_Context DB = new e_Tagebuch_Context();
                var diary             = DB.Diaries.FirstOrDefault(d => d.Name == cmbDiaries.SelectedItem.ToString());
                con.Show_SearchWindow(diary.DiaryID);
                this.Close
                    ();
            }
            else
            {
                MessageBox.Show("No diary is selected", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Пример #15
0
        public int Create_Diary(string t_Name, int t_ID)
        {
            int id = -1;

            using (var DB = new e_Tagebuch_Context())
            {
                //Get UserID
                var user = DB.Users.FirstOrDefault(u => u.UserID == t_ID);
                //Create Diary
                var newDiary = DB.Diaries.Add(new Diary()
                {
                    Name    = t_Name,
                    user_id = user.UserID
                });
                DB.SaveChanges();
                id = newDiary.DiaryID;
            }
            return(id);
        }
Пример #16
0
        public frmEditor(int t_EntryID)
        {
            EntryID = t_EntryID;
            InitializeComponent();
            //Fill form elements
            e_Tagebuch_Context con = new e_Tagebuch_Context();
            var entry = con.Entries.FirstOrDefault(e => e.EntryID == EntryID);

            txtName.Text       = entry.Name;
            txtMain.Text       = entry.Text;
            lblPicPath.Content = entry.Picture;
            if (entry.Date == null)
            {
                dpDatepicker.SelectedDate = DateTime.Now;
            }
            else
            {
                dpDatepicker.SelectedDate = entry.Date;
            }
        }
Пример #17
0
        public List <Entry> Search_Entries(string t_SearchMethod, string t_Value)
        {
            var foundEntries      = new List <Entry>();
            e_Tagebuch_Context DB = new e_Tagebuch_Context();

            if (t_SearchMethod == "Name")
            {
                foundEntries = DB.Entries.Where(e => e.Name == t_Value).ToList();
            }
            else if (t_SearchMethod == "Date")
            {
                DateTime date = DateTime.Parse(t_Value).Date;
                foundEntries = DB.Entries.Where(e => e.Date == date).ToList();
            }
            else if (t_SearchMethod == "Type")
            {
                foundEntries = DB.Entries.Where(e => e.Type.Contains(t_Value)).ToList();
            }

            return(foundEntries);
        }
Пример #18
0
        public List <object> Get_EmptyDays(DateTime t_From, DateTime t_To)
        {
            var foundEntries      = new List <object>();
            e_Tagebuch_Context DB = new e_Tagebuch_Context();

            //Date range (Source of the code: https://stackoverflow.com/questions/1847580/how-do-i-loop-through-a-date-range)
            IEnumerable <DateTime> EachDay(DateTime from, DateTime thru)
            {
                for (var day = from.Date; day.Date <= thru.Date; day = day.AddDays(1))
                {
                    yield return(day);
                }
            }

            foreach (DateTime day in EachDay(t_From, t_To))
            {
                if (!DB.Entries.Any(e => e.Date == day))
                {
                    var value = new { Name = "Empty day", Date = day };
                    foundEntries.Add(value);
                }
            }
            return(foundEntries);
        }
Пример #19
0
        public bool Diary_Exist(string t_Name)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();

            return(DB.Diaries.Any(d => d.Name == t_Name));
        }
Пример #20
0
        public string Get_DiaryUser(int t_DiaryID)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();

            return(Get_UserName(DB.Diaries.FirstOrDefault(d => d.DiaryID == t_DiaryID).user_id));
        }
Пример #21
0
        public string Get_UserName(int t_UserID)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();

            return(DB.Users.FirstOrDefault(u => u.UserID == t_UserID).Username);
        }
Пример #22
0
        public int Get_UserID(string t_UserName)
        {
            e_Tagebuch_Context DB = new e_Tagebuch_Context();

            return(DB.Users.FirstOrDefault(u => u.Username == t_UserName).UserID);
        }