Ejemplo n.º 1
0
        private void gridUsers_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
        {
            var user = new t_Users();

            user.userid   = uid;
            user.username = uname;
            user.userpass = upass;
            user.usertype = utype;
            e.NewObject   = user;

            db.t_Users.Add(user);
        }
Ejemplo n.º 2
0
        private void gridUsers_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Delete)
                {
                    string sMessageBoxText = "Do you want to continue?";
                    string sCaption        = "Delete User";

                    MessageBoxButton btnMessageBox = MessageBoxButton.YesNo;
                    MessageBoxImage  icnMessageBox = MessageBoxImage.Warning;

                    MessageBoxResult rsltMessageBox = MessageBox.Show(sMessageBoxText, sCaption, btnMessageBox, icnMessageBox);

                    switch (rsltMessageBox)
                    {
                    case MessageBoxResult.Yes:
                        foreach (var data in gridUsers.SelectedItems)
                        {
                            t_Users myData     = data as t_Users;
                            var     deleteuser = db.t_Users.Where(u => u.userid == myData.userid).FirstOrDefault();
                            db.t_Users.Remove(deleteuser);
                            db.SaveChanges();
                        }
                        break;

                    case MessageBoxResult.No:
                        /* ... */
                        break;
                    }
                }

                else
                {
                    return;
                }
            }
            catch { }
        }
Ejemplo n.º 3
0
        private void gridUsers_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            if (e.EditAction == GridViewEditAction.Cancel)
            {
                return;
            }
            if (e.EditOperationType == GridViewEditOperationType.Insert)
            {
                try
                {
                    db.SaveChanges();
                    binddatagrid();
                }
                catch { MessageBox.Show("already exist"); }
            }
            else if (e.EditOperationType == GridViewEditOperationType.Edit)
            {
                try
                {
                    foreach (var data in gridUsers.SelectedItems)
                    {
                        t_Users myData = data as t_Users;
                        uid   = myData.userid;
                        uname = myData.username;
                        upass = myData.userpass;
                        utype = myData.usertype;

                        t_Users us = db.t_Users.First(p => p.userid == uid);
                        us.username = uname;
                        us.userpass = upass;
                        us.usertype = utype;
                        db.SaveChanges();
                        binddatagrid();
                    }
                }
                catch { }
            }
        }
Ejemplo n.º 4
0
        void login()
        {
            try
            {
                t_Users newuser = new t_Users();
                var     user    = db.t_Users.Where(i => i.username == this.username.Text && i.userpass == this.userpass.Password).FirstOrDefault();

                if (user == null)
                {
                    MessageBox.Show("Unable to Login, incorrect credentials.");
                }
                else
                {
                    MainForm UserMain = new MainForm();
                    UserMain.adminusers.Text = username.Text;
                    UserMain.Show();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }