Ejemplo n.º 1
0
 private void BtnAddTag_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new CVDBContext())
     {
         Tags t = new Tags { Tag_Name = TxtbxTagFilter.Text };
         db.Tags.Add(t);
         db.Entry(t).State = EntityState.Added;
         db.SaveChanges();
     }
     FillTags();
 }
Ejemplo n.º 2
0
 private void BtnSearch_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new CVDBContext())
     {
         var query = from user in db.Users
                     join ud in db.User_Details on user.User_ID equals ud.User_ID
                     where user.First_Name.Contains(TxtBoxSearch.Text) ||
                     user.Last_Name.Contains(TxtBoxSearch.Text)
                     orderby user.Last_Name, user.First_Name, ud.Available, ud.Available_Date
                     select new { user.User_ID, user.First_Name, user.Last_Name, ud.Available, ud.Available_Date };
         dgContentList.ItemsSource = query.ToList();
     }
 }
Ejemplo n.º 3
0
 private void FillTags()
 {
     BtnAddTag.IsEnabled = false;
     TxtbxTagFilter.Text = "";
     using (var db = new CVDBContext())
     {
         var query = from tag in db.Tags
                     orderby tag.Tag_Name ascending
                     select tag.Tag_Name;
         LstBxTags.ItemsSource = query.ToList();
     }
 }
Ejemplo n.º 4
0
        private void BtnLogDelete_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new CVDBContext())
            {
                Logs LogToDelete = db.Logs.Find(LogID);
                db.Logs.Remove(LogToDelete);
                db.SaveChanges();
            }

            PopupEditLog.IsOpen = false;
            BtnNewLog.Content = "New Log";
            FillLogs();
        }
Ejemplo n.º 5
0
 private void BtnLogSave_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new CVDBContext())
     {
         if (LogID < 1)
         {
             Logs newLog = new Logs
             {
                 Event_ID = getEventID(CBLogEvents.SelectedValue.ToString()),
                 Lexicon_Handle_ID = 1,
                 Created = DateTime.Now,
                 User_ID = selectedUID,
                 Notes = TxtBxLogEntry.Text
             };
             db.Logs.Add(newLog);
             db.Entry(newLog).State = EntityState.Added;
         }
         else
         {
             Logs logToUpdate = db.Logs.Find(LogID);
             logToUpdate.Notes = TxtBxLogEntry.Text;
             db.Entry(logToUpdate).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
     PopupEditLog.IsOpen = false;
     BtnNewLog.Content = "New Log";
     FillLogs();
 }
Ejemplo n.º 6
0
        private void BtnSaveDetails_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new CVDBContext())
            {
                User_Details ud = db.User_Details.Find(selectedUID);

                ud.User_ID = selectedUID;
                ud.Modified = DateTime.Now;
                ud.Active = (bool)ChkActive.IsChecked;
                ud.Available = (bool)ChkAvailable.IsChecked;
                if ((bool)ChkAvailable.IsChecked)
                {
                    DPDetails.SelectedDate = null;
                }
                ud.Available_Date = DPDetails.SelectedDate;
                ud.Salary = GetNumber(TxtDetailsSalary.Text);

                db.Entry(ud).State = EntityState.Modified;

                txtbxtest.Text = ud.ToString();
                db.SaveChanges();
            }
            PopupDetails.IsOpen = false;
            dgContentList.UpdateGrid();
        }
Ejemplo n.º 7
0
 private void DGLogs_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (DGLogs.SelectedIndex >= 0)
     {
         var obj = DGLogs.SelectedItem;
         System.Type type = obj.GetType();
         LogID = (int)type.GetProperty("Log_ID").GetValue(obj, null);
         PopupEditLog.IsOpen = true;
         BtnNewLog.Content = "Close";
         using (var db = new CVDBContext())
         {
             Logs log = db.Logs.Find(LogID);
             var query = from ev in db.Log_Events
                         where ev.Event_ID == log.Event_ID
                         select ev.Event_Name;
             string tmp = query.FirstOrDefault();
             LblLogDate.Content = log.Created;
             LblLogWho.Content = log.GetLexiconHandle();
             CBLogEvents.SelectedItem = tmp;
             TxtBxLogEntry.Text = log.Notes;
         }
         BtnLogDelete.IsEnabled = true;
     }
 }
Ejemplo n.º 8
0
 public void FillJournals()
 {
     using (var db = new CVDBContext())
     {
         var query = from j in db.Journals
                     where j.User_ID == selectedUID
                     select new { Journal_ID = j.Journal_ID, Created = j.Created, Notes = j.Notes };
         var tmp = query.ToList();
         DGJournals.ItemsSource = tmp;
     }
 }
Ejemplo n.º 9
0
 public void FillLogs()
 {
     using (var db = new CVDBContext())
     {
         var query = from l in db.Logs
                     join e in db.Log_Events on l.Event_ID equals e.Event_ID
                     where l.User_ID == selectedUID
                     select new { Log_ID = l.Log_ID, Created = l.Created, Event = e.Event_Name };
         var tmp = query.ToList();
         DGLogs.ItemsSource = tmp;
     }
 }
Ejemplo n.º 10
0
 private void BtnJournalDelete_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new CVDBContext())
     {
         Journals JournalToDelete = db.Journals.Find(JournalID);
         db.Journals.Remove(JournalToDelete);
         db.SaveChanges();
     }
     PopupEditJournal.IsOpen = false;
     BtnNewJournal.Content = "New Entry";
     FillJournals();
 }
Ejemplo n.º 11
0
        private void BtnJournalSave_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new CVDBContext())
            {
                if (DGJournals.SelectedIndex < 0)
                {
                    Journals j = new Journals
                    {
                        Created = DateTime.Now,
                        User_ID = selectedUID,
                        Notes = TxtBxJournalEntry.Text,
                        Lexicon_Handle_ID = 1
                    };
                    db.Journals.Add(j);
                    db.Entry(j).State = EntityState.Added;
                }
                else
                {
                    Journals j = db.Journals.Find(JournalID);

                    j.Notes = TxtBxJournalEntry.Text;

                    db.Entry(j).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            PopupEditJournal.IsOpen = false;
            PopupJournal.IsOpen = true;
            BtnNewJournal.Content = "New Entry";
            FillJournals();
        }
Ejemplo n.º 12
0
 private void BtnNewJournal_Click(object sender, RoutedEventArgs e)
 {
     PopupEditJournal.IsOpen = PopupEditJournal.IsOpen == true ? false : true;
     BtnNewJournal.Content = PopupEditJournal.IsOpen == true ? "Close" : "New Entry";
     DGJournals.SelectedIndex = -1;
     DGJournals.SelectedItem = null;
     LblJournalDate.Content = DateTime.Now;
     string lhName = "";
     using (var db = new CVDBContext())
     {
         var query = from lh in db.Lexicon_Handles
                     where lh.Lexicon_Handle_ID == 1
                     select lh.First_Name + " " + lh.Last_Name;
         lhName = query.FirstOrDefault();
     }
     LblJournalWho.Content = lhName;
     TxtBxJournalEntry.Text = "";
     BtnJournalDelete.IsEnabled = false;
 }
Ejemplo n.º 13
0
        private void DGJournals_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DGJournals.SelectedIndex >= 0)
            {
                var obj = DGJournals.SelectedItem;
                System.Type type = obj.GetType();
                JournalID = (int)type.GetProperty("Journal_ID").GetValue(obj, null);

                using (var db = new CVDBContext())
                {
                    Journals journal = db.Journals.Find(JournalID);

                    LblJournalDate.Content = journal.Created;
                    LblJournalWho.Content = journal.GetLexiconHandle();
                    TxtBxJournalEntry.Text = journal.Notes;
                }
                BtnNewJournal.Content = "Close";
                PopupEditJournal.IsOpen = true;
            }
        }
Ejemplo n.º 14
0
 private void FillDetails(int id)
 {
     using (var db = new CVDBContext())
     {
         var ud = from u_d in db.User_Details
                  where u_d.User_ID == selectedUID
                  select u_d;
         ChkActive.IsChecked = ud.FirstOrDefault().Active;
         if ((bool)ChkAvailable.IsChecked)
         {
             ChkAvailable.IsChecked = ud.FirstOrDefault().Available;
             DPDetails.SelectedDate = null;
         }
         DPDetails.SelectedDate = ud.FirstOrDefault().Available_Date;
         TxtDetailsSalary.Text = AddSEK(ud.FirstOrDefault().Salary.ToString());
     }
 }
Ejemplo n.º 15
0
 private void LstBxTags_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (LstBxTags.SelectedItem != null)
     {
         string tmp = LstBxTags.SelectedItem.ToString();
         if (userTags.Contains(tmp))
         {
             //delete from database
             using (var db = new CVDBContext())
             {
                 var i = from tag in db.Tags
                         where tag.Tag_Name == tmp
                         select tag.Tag_ID;
                 int id = i.FirstOrDefault();
                 var query = from rel in db.User_Tag_REL
                             where rel.User_ID == selectedUID && rel.Tag_ID == id
                             select rel;
                 User_Tag_REL toDelete = query.FirstOrDefault();
                 db.User_Tag_REL.Remove(toDelete);
                 db.SaveChanges();
             }
             LblTags.Content = FillLabelTags(selectedUID);
             txtbxtest.Text = "deleted from database: " + tmp;
         }
         else
         {
             //save to database
             using (var db = new CVDBContext())
             {
                 var i = from tag in db.Tags
                         where tag.Tag_Name == tmp
                         select tag.Tag_ID;
                 int id = i.FirstOrDefault();
                 User_Tag_REL toAdd = new User_Tag_REL { User_ID = selectedUID, Tag_ID = id };
                 db.User_Tag_REL.Add(toAdd);
                 db.Entry(toAdd).State = EntityState.Added;
                 db.SaveChanges();
             }
             LblTags.Content = FillLabelTags(selectedUID);
             txtbxtest.Text = "saved to database: " + tmp;
         }
         Unselect();
     }
 }
Ejemplo n.º 16
0
 private void BtnNewLog_Click(object sender, RoutedEventArgs e)
 {
     PopupEditLog.IsOpen = PopupEditLog.IsOpen == true ? false : true;
     BtnNewLog.Content = PopupEditLog.IsOpen == true ? "Close" : "New Log";
     LblLogDate.Content = DateTime.Now;
     string lhName = "";
     using (var db = new CVDBContext())
     {
         var query = from lh in db.Lexicon_Handles
                     where lh.Lexicon_Handle_ID == 1
                     select lh.First_Name + " " + lh.Last_Name;
         lhName = query.FirstOrDefault();
     }
     LblLogWho.Content = lhName;
     TxtBxLogEntry.Text = "";
     BtnLogDelete.IsEnabled = false;
     using (var db = new CVDBContext())
     {
         var query = from le in db.Log_Events
                     select le;
         foreach (Log_Events le in query)
         {
             if (!CBLogEvents.Items.Contains(le.Event_Name))
                 CBLogEvents.Items.Add(le.Event_Name);
             if (!eventlist.ContainsKey(le.Event_ID))
             {
                 eventlist.Add(le.Event_ID, le.Event_Name);
             }
         }
     }
 }
Ejemplo n.º 17
0
 private string FillLabelTags(int uid)
 {
     LblTags.Content = "";
     using (var db = new CVDBContext())
     {
         var query = from rel in db.User_Tag_REL
                     join tag in db.Tags on rel.Tag_ID equals tag.Tag_ID
                     where rel.User_ID == uid
                     orderby tag.Tag_Name
                     select tag.Tag_Name;
         userTags = query.ToList();
     }
     if (userTags.Count > 0)
     {
         return string.Join(",", userTags).CapitalizeFirst();
     }
     else
     {
         return "";
     }
 }
Ejemplo n.º 18
0
        private void BtnYes_Click(object sender, RoutedEventArgs e)
        {
            using (CVDBContext db = new CVDBContext())
            {
                Users userToDelete = db.Users.Find(selectedUID);
                db.Users.Remove(userToDelete);
                db.SaveChanges();
            }
            //delete user, never to return!
            txtbxtest.Text = "Användare med id: " + selectedUID + " borttagen.";
            PopupDelete.IsOpen = false;
            dgContentList.SelectedIndex = -1;
            ShowHide();
            dgContentList.UpdateGrid();
            Page_default p = new Page_default();
            FrmContent.Navigate(p);

        }