Exemplo n.º 1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                db       = new TODOEntities();
                dataGrid = myDataGrid2;
                int      list_id       = (dataGrid.SelectedItem as ITEM_INFO).list_id;
                string   item_name     = (dataGrid.SelectedItem as ITEM_INFO).item_name;
                DateTime creation_date = (myDataGrid2.SelectedItem as ITEM_INFO).creation_date;

                var deletedItem = db.ITEM_INFO.Where(
                    d => d.list_id == list_id && d.item_name == item_name && d.creation_date == creation_date)
                                  .Single();

                db.ITEM_INFO.Remove(deletedItem);
                db.SaveChanges();
                isExpired();
                dataGrid.ItemsSource = db.ITEM_INFO.Where(a => a.list_id == list_id).ToList();
            }

            catch (Exception)
            {
                MessageBox.Show("You have to pick an item to delete");
            }
        }
Exemplo n.º 2
0
        private void btnChange_Click(object sender, RoutedEventArgs e)
        {
            string itemStatus = (sender as Button).Tag.ToString();

            if (itemStatus != "Expired")
            {
                db       = new TODOEntities();
                dataGrid = myDataGrid2;
                int      list_id       = (dataGrid.SelectedItem as ITEM_INFO).list_id;
                string   item_name     = (dataGrid.SelectedItem as ITEM_INFO).item_name;
                DateTime creation_date = (myDataGrid2.SelectedItem as ITEM_INFO).creation_date;

                foreach (var item in db.ITEM_INFO)
                {
                    if (item.item_name == item_name && item.list_id == list_id && item.creation_date == creation_date)
                    {
                        if (item.item_status == "Complete")
                        {
                            item.item_status = "Not Complete";
                        }
                        else if (item.item_status == "Not Complete")
                        {
                            item.item_status = "Complete";
                        }
                    }
                }

                db.SaveChanges();
                dataGrid.ItemsSource = db.ITEM_INFO.Where(a => a.list_id == list_id).ToList();
            }
            else
            {
                MessageBox.Show("You can't change status of expired.");
            }
        }
Exemplo n.º 3
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     db = new TODOEntities();
     isExpired();
     dataGrid             = myDataGrid2;
     dataGrid.ItemsSource = db.ITEM_INFO.Where(a => a.list_id == list_id).ToList();
 }
Exemplo n.º 4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                db = new TODOEntities();

                USER_INFO newUser = new USER_INFO()
                {
                    mail_adress   = txtMail.Text,
                    username      = txtNick.Text,
                    full_name     = txtName.Text,
                    surname       = txtSurname.Text,
                    user_password = txtPass.Text
                };
                db.USER_INFO.Add(newUser);
                db.SaveChanges();

                MessageBox.Show("You've just registrated !");

                this.Hide();
            }

            catch (Exception)
            {
                MessageBox.Show("The fields can not be blank.");
            }
        }
Exemplo n.º 5
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            string filterName = txtSearch.Text;

            db                   = new TODOEntities();
            dataGrid             = myDataGrid2;
            dataGrid.ItemsSource = db.ITEM_INFO.Where(a => a.item_name == filterName && a.list_id == list_id).ToList();
        }
Exemplo n.º 6
0
        public static void isExpired()
        {
            TODOEntities db;

            db = new TODOEntities();

            foreach (var item in db.ITEM_INFO)
            {
                if (item.item_deadline < DateTime.Now)
                {
                    item.item_status = "Expired";
                }
            }
            db.SaveChanges();
        }
Exemplo n.º 7
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            string filter = cmbFilter.Text;

            db       = new TODOEntities();
            dataGrid = myDataGrid2;
            if (filter == "Expired" || filter == "Complete" || filter == "Not Completed")
            {
                dataGrid.ItemsSource = db.ITEM_INFO.Where(f => f.item_status == filter && f.list_id == list_id).ToList();
            }
            else
            {
                dataGrid.ItemsSource = db.ITEM_INFO.Where(a => a.list_id == list_id).ToList();
            }
        }
Exemplo n.º 8
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                db = new TODOEntities();
                ITEM_INFO newItem = new ITEM_INFO()
                {
                    item_name     = txtName.Text,
                    item_desc     = txtDesc.Text,
                    item_deadline = datePicker.SelectedDate,
                    creation_date = DateTime.Now,
                    item_status   = "Not Completed",
                    list_id       = list_id
                };

                db.ITEM_INFO.Add(newItem);
                try
                {
                    db.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
                ItemPage.isExpired();
                ItemPage.dataGrid.ItemsSource = db.ITEM_INFO.Where(a => a.list_id == list_id).ToList();
                this.Hide();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException)
            {
                MessageBox.Show("Wrong");
            }
        }
Exemplo n.º 9
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            db       = new TODOEntities();
            dataGrid = myDataGrid;

            int list_id     = (dataGrid.SelectedItem as LIST_INFO).list_id;
            var deletedList = db.LIST_INFO.Where(d => d.list_id == list_id).Single();

            db.LIST_INFO.Remove(deletedList);
            foreach (var item in db.ITEM_INFO)
            {
                if (item.list_id == list_id)
                {
                    db.ITEM_INFO.Remove(item);
                }
            }

            db.SaveChanges();
            dataGrid.ItemsSource = db.LIST_INFO.Where(a => a.list_owner == myUser).ToList();
        }
Exemplo n.º 10
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (txtList.Text == "")
            {
                MessageBox.Show("Name of the list can not be empty.");
            }
            else
            {
                db = new TODOEntities();
                LIST_INFO newList = new LIST_INFO()
                {
                    list_name  = txtList.Text,
                    list_owner = myUser
                };

                db.LIST_INFO.Add(newList);
                db.SaveChanges();
                UserPage.dataGrid.ItemsSource = db.LIST_INFO.Where(a => a.list_owner == myUser).ToList();
                this.Hide();
            }
        }
Exemplo n.º 11
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            int    flag   = 0;
            string myUser = "";

            db = new TODOEntities();
            foreach (var user in db.USER_INFO)
            {
                if (user.username == txtName.Text && user.user_password == txtPass.Text)
                {
                    flag   = 1;
                    myUser = user.username;
                }
            }
            if (flag == 1)
            {
                UserPage userPage = new UserPage(myUser);
                userPage.ShowDialog();
            }
            else
            {
                MessageBox.Show("You entered wrong informations");
            }
        }
Exemplo n.º 12
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     db                   = new TODOEntities();
     dataGrid             = myDataGrid;
     dataGrid.ItemsSource = db.LIST_INFO.Where(a => a.list_owner == myUser).ToList();
 }