Ejemplo n.º 1
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                object Item = DataGrid1.SelectedItem;
                if (Item != null)
                {
                    var        Text = (DataGrid1.SelectedCells[0].Column.GetCellContent(Item) as TextBlock).Text;
                    Login_User z    = c.Login_User.ToList().FirstOrDefault(c => c.ID == (Convert.ToInt32(Text)));

                    z.UserName = UserName.Text;
                    z.Password = Password.Text;
                    if (Position.SelectedIndex == 0)
                    {
                        z.position_id = 1;
                    }
                    else if (Position.SelectedIndex == 1)
                    {
                        z.position_id = 2;
                    }
                    else if (Position.SelectedIndex == 2)
                    {
                        z.position_id = 3;
                    }
                    //===========================================
                    if (z.position_id == 1)
                    {
                        Position.SelectedIndex = 0;
                        z.Position             = "Manager";
                    }
                    if (z.position_id == 2)
                    {
                        Position.SelectedIndex = 1;
                        z.Position             = "Instructor";
                    }
                    if (z.position_id == 3)
                    {
                        Position.SelectedIndex = 2;
                        z.Position             = "Student";
                    }
                    //z.position_id = int.Parse(Position_Id.Text);

                    c.SaveChanges();
                    MessageBox.Show("Login user updated successfully", "successfully completed", MessageBoxButton.OK, MessageBoxImage.Information);

                    loadedLoginUser();
                }
            }
            catch (Exception E)
            {
                MessageBox.Show("Some invalid input!! please try again", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            object Item = DataGrid1.SelectedItem;

            if (Item != null)
            {
                var        Text = (DataGrid1.SelectedCells[0].Column.GetCellContent(Item) as TextBlock).Text;
                Login_User z    = c.Login_User.ToList().FirstOrDefault(c => c.ID == (Convert.ToInt32(Text)));
                c.Login_User.Remove(z);
                c.SaveChanges();
                loadedLoginUser();
            }
        }
Ejemplo n.º 3
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            object Item = DataGrid1.SelectedItem;

            if (Item != null)
            {
                var        Text = (DataGrid1.SelectedCells[0].Column.GetCellContent(Item) as TextBlock).Text;
                Login_User z    = c.Login_User.ToList().FirstOrDefault(c => c.ID == (Convert.ToInt32(Text)));

                z.UserName = UserName.Text;
                z.Password = Password.Text;
                if (Position.SelectedIndex == 0)
                {
                    z.position_id = 1;
                }
                else if (Position.SelectedIndex == 1)
                {
                    z.position_id = 2;
                }
                else if (Position.SelectedIndex == 2)
                {
                    z.position_id = 3;
                }
                //===========================================
                if (z.position_id == 1)
                {
                    Position.SelectedIndex = 0;
                    z.Position             = "Manager";
                }
                if (z.position_id == 2)
                {
                    Position.SelectedIndex = 1;
                    z.Position             = "Instructor";
                }
                if (z.position_id == 3)
                {
                    Position.SelectedIndex = 2;
                    z.Position             = "Student";
                }
                //z.position_id = int.Parse(Position_Id.Text);

                c.SaveChanges();
                loadedLoginUser();
            }
        }
Ejemplo n.º 4
0
 private void Delete_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         object Item = DataGrid1.SelectedItem;
         if (Item != null)
         {
             var        Text = (DataGrid1.SelectedCells[0].Column.GetCellContent(Item) as TextBlock).Text;
             Login_User z    = c.Login_User.ToList().FirstOrDefault(c => c.ID == (Convert.ToInt32(Text)));
             c.Login_User.Remove(z);
             c.SaveChanges();
             MessageBox.Show("Login user Deleted successfully", "successfully completed", MessageBoxButton.OK, MessageBoxImage.Information);
             UserName.Text          = "";
             Password.Text          = "";
             Position.SelectedIndex = -1;
             loadedLoginUser();
         }
     }
     catch (Exception E)
     {
         MessageBox.Show("Some invalid input!! please try again", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (datebick.SelectedDate != null && name.Text != "" && salary.Text != "" && datebick.SelectedDate != null && user.Text != "" && pass.Text != "" && cmb1.SelectedIndex != -1)
                {
                    var branchid   = ((Branch)cmb1.SelectedValue);
                    int branch_id1 = branchid.Branch_Id;

                    string   Name             = name.Text;
                    DateTime date             = datebick.SelectedDate.Value.Date;
                    float    instructorsalary = float.Parse(salary.Text);

                    string username = user.Text;
                    string password = pass.Text;
                    var    query    = context.Login_User.Where(c => c.UserName == username).FirstOrDefault();
                    if (query == null)
                    {
                        var login = new Login_User
                        {
                            UserName    = username,
                            Password    = password,
                            Position    = "instructor",
                            position_id = 2
                        };


                        context.Login_User.Add(login);
                        context.SaveChanges();
                        var instructor = new Instructor
                        {
                            Instructor_Name     = Name,
                            Instructor_HireDate = date,
                            Instructor_Salary   = instructorsalary,
                            isdeleted           = false,
                            login_id            = login.ID,
                            Branch_Id           = branch_id1,
                            Manager_Id          = user_id
                        };
                        context.Instructors.Add(instructor);
                        context.SaveChanges();
                        MessageBox.Show("instructor added successfully", "successfully completed", MessageBoxButton.OK, MessageBoxImage.Information);
                        name.Text          = "";
                        salary.Text        = "";
                        user.Text          = "";
                        pass.Text          = "";
                        cmb1.SelectedIndex = 0;
                    }
                    else
                    {
                        MessageBox.Show("this username added before!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("Please , Fill all fields First.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception E)
            {
                MessageBox.Show("Some invalid input!! please try again", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (birth.SelectedDate != null && name.Text != "" && code.Text != "" && username.Text != "" && passwordtxt.Text != "" && cmb1.SelectedIndex != -1 && cmb2.SelectedIndex != -1 && cmb3.SelectedIndex != -1)
                {
                    var branchid   = ((Branch)cmb1.SelectedValue);
                    int branch_id1 = branchid.Branch_Id;

                    var trackid   = ((Track)cmb2.SelectedValue);
                    int track_id1 = trackid.Track_Id;


                    var intakeid   = ((Intake)cmb3.SelectedValue);
                    int intake_id1 = intakeid.Intake_Id;


                    string   Name = name.Text;
                    DateTime date;


                    date = birth.SelectedDate.Value.Date;


                    string code1 = code.Text;

                    string user  = username.Text;
                    string pass  = passwordtxt.Text;
                    var    query = context.Login_User.Where(c => c.UserName == user).FirstOrDefault();
                    if (query == null)
                    {
                        var query2 = context.Students.Where(c => c.student_code == code1).FirstOrDefault();

                        if (query2 == null)
                        {
                            var login = new Login_User
                            {
                                UserName    = user,
                                Password    = pass,
                                Position    = "student",
                                position_id = 3
                            };


                            context.Login_User.Add(login);
                            context.SaveChanges();
                            var student = new Student
                            {
                                Student_Name      = Name,
                                Student_BirthDate = date,
                                isdeleted         = false,
                                student_code      = code1,
                                login_id          = login.ID,
                                Branch_Id         = branch_id1,
                                Track_Id          = track_id1,
                                Intake_Id         = intake_id1
                            };
                            context.Students.Add(student);
                            context.SaveChanges();
                            MessageBox.Show("student added successfully", "Successfully Completed", MessageBoxButton.OK, MessageBoxImage.Information);
                            name.Text          = "";
                            code.Text          = "";
                            username.Text      = "";
                            passwordtxt.Text   = "";
                            cmb1.SelectedIndex = 0;
                            cmb2.SelectedIndex = 0;
                            cmb3.SelectedIndex = 0;
                        }
                        else
                        {
                            MessageBox.Show("this student  code added before!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show("this username added before!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("Please , Fill all the fields first.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception E)
            {
                MessageBox.Show("Some invalid input!! please try again", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }