protected void dgAdmin_ItemCommand(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Admin admin = new Admin();

            if (e.CommandName == "AddAdmin")
            {
                TextBox txtTempAdminID = (TextBox)e.Item.Cells[0].FindControl("txtAdminIDNew");
                TextBox txtTempName    = (TextBox)e.Item.Cells[1].FindControl("txtNameNew");
                Regex   adminregex     = new Regex(@"^\d{1,5}$");                          //only support up to 5 integer
                Match   checkadmin     = adminregex.Match(txtTempAdminID.Text);
                Regex   nameRegex      = new Regex(@"[a-zA-Z ]{1,30}$");                   //Only allow a-z,A-Z and space
                Match   checkname      = nameRegex.Match(txtTempName.Text);

                if (!checkadmin.Success)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'The Admin ID is not allowed. Please Admin ID is only up to 5 digit number.', 'error')</script>'");
                }
                else if (!checkname.Success)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'The Admin Name is not allowed. Admin name is only support character, space and up to 30 character only.', 'error')</script>'");
                }
                else if (txtTempName.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the Name!', 'error')</script>'");
                }
                else if (txtTempAdminID.Text.Trim() == "")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Please fill in the Admin ID!', 'error')</script>'");
                }
                else
                {
                    if (admin.Add(txtTempAdminID.Text, txtTempName.Text) == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'Cannot have the same duplicate Admin ID!', 'error')</script>'");
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Added!', text: 'Admin " + txtTempName.Text + " (" + txtTempAdminID.Text + ") is added successfully Your password is (holdDoc123)!', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'manageAdmin.aspx'; }});</script>'");
                    }
                }
            }

            else if (e.CommandName == "DeleteAdmin")
            {
                string id         = Session["ID"].ToString();
                Label  rowAdminID = (Label)e.Item.Cells[0].FindControl("lblAdminID");
                if (id == rowAdminID.Text)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Warning!', 'Hey, You cannot delete yourself!', 'error')</script>'");
                }
                else if (admin.DeleteAdmin(rowAdminID.Text) == false)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type='text/javascript'>swal('Error!', 'This admin record is deleted unsuccessfully', 'error')</script>'");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script type='text/javascript'>swal({title: 'Deleted!', text: 'This admin record is deleted successfully', type : 'success', confirmButtonText : 'OK'}, function (isConfirm) { if (isConfirm) { window.location.href = 'manageAdmin.aspx'; }});</script>'");
                }
            }
        }
Esempio n. 2
0
        public IActionResult Add(string user_name, string pwd)
        {
            Status <Dictionary <string, string> > status = new Status <Dictionary <string, string> >();
            Admin admin = new Admin();

            admin.Addtime = DateTime.Now;
            admin.Encrypt = Business.GenerateRandom();
            string upwd = Business.MD5Encrypt(pwd, admin.Encrypt);

            admin.Userpwd   = upwd;
            admin.Username  = user_name;
            admin.Logintime = DateTime.Now;
            admin.Guid      = Guid.NewGuid().ToString("N");
            status.Code     = 300;
            status.Msg      = "添加失败";
            if (admin.Add())
            {
                status.Code = 200;
                status.Msg  = "添加成功";
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("username", user_name);
                dic.Add("addtime", admin.Addtime.ToString("yyyy-mm-dd HH:mm:ss"));
                status.Data = dic;
            }
            return(Json(status));
        }
        private void add_Click(object sender, RoutedEventArgs e)
        {
            if (StudentID.Text.Trim() == "")
            {
                MessageBox.Show("Missing Student ID");
            }
            else if (CourseID.Text.Trim() == "")
            {
                MessageBox.Show("Missing Course ID");
            }
            else
            {
                C_taken temp = new C_taken();
                temp.sid = StudentID.Text.Trim();
                temp.cid = CourseID.Text.Trim();

                Admin.Add(temp);
                MessageBox.Show("Successfully Added");
                DialogResult = true;
            }
        }
Esempio n. 4
0
        private void Create_btn_Click(object sender, EventArgs e)
        {
            LibraryDBDataContext db = new LibraryDBDataContext();

            if (Username_TB.Text == "" || Password_TB.Text == "" || Repass_TB.Text == "")
            {
                MessageBox.Show("Please Enter Username and Passwords");
            }
            else if (User.LoadByUsername(Username_TB.Text) != null)
            {
                MessageBox.Show("UserName Exists!");
            }
            else if (Password_TB.Text != Repass_TB.Text)
            {
                MessageBox.Show("Passwords aren't identical!");
            }
            else if (FName_TB.Text == "" || SName_TB.Text == "")
            {
                MessageBox.Show("Please Enter Your Name!");
            }
            else if (Phone_TB.Text == "")
            {
                MessageBox.Show("Please Enter Your Phone Number!");
            }
            else if (Admin_CB.Checked && Admin_Panel.Visible && Salary_TB.Text == "")
            {
                MessageBox.Show("Please Enter Your Salary!");
            }
            else if (Admin_CB.Checked && Admin_Panel.Visible && Shift_TB.Text == "")
            {
                MessageBox.Show("Please Enter Your Shift!");
            }
            else
            {
                User u = new User();
                u.Username    = Username_TB.Text;
                u.Password    = Password_TB.Text;
                u.FName       = FName_TB.Text;
                u.SName       = SName_TB.Text;
                u.Birthdate   = Birthdate_Picker.Value.Date;
                u.Address     = Address_TB.Text;
                u.Email       = Email_TB.Text;
                u.PhoneNumber = Phone_TB.Text;
                u.NationalID  = NationalID_TB.Text;
                if (Admin_CB.Checked)
                {
                    if (Admin_Panel.Visible == true)
                    {
                        u.Rolename = RolesEnum.Admin;
                        Admin a = new Admin();
                        a.CopyInto(ref u);
                        a.Shift    = int.Parse(Shift_TB.Text);
                        a.Salary   = double.Parse(Salary_TB.Text);
                        a.HireDate = HireDate_DB.Value.Date;
                        a.Add();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Please Enter The Code First");
                    }
                }
                else
                {
                    Student s = new Student();
                    u.Rolename = RolesEnum.Student;
                    s.CopyInto(u);
                    s.University    = University_TB.Text;
                    s.University_ID = Uni_ID_TB.Text;
                    if (GPA_TB.Text != "")
                    {
                        s.GPA = double.Parse(GPA_TB.Text);
                    }
                    s.Add();
                    this.Close();
                }
            }
        }
Esempio n. 5
0
 public ActionResult Add(Admin u)
 {
     u.Add();
     return(View());
 }
Esempio n. 6
0
        static void Main(string[] args)
        {
            //Academy Management Application

            //The app will have users that can login and preform some actions

            //The user can choose one of the 3 roles and login // Console.WriteLine();

            //-Admin
            //-Trainer
            //-Student (has a current Subject, and Grades)

            //After logging in there should be different options for different roles

            //Admins can add/remove Trainers, Students and other Admins (can`t remove it self)

            //Trainer can choose between seeing all students and all subjects
            // - When choosing Students, all student names should appear
            // - When chosen a name, it should print all the subjects
            // - When choosing Subjects, all Subject names appear with how many students attend it next to it

            //Student are shown subjects that they are listening and a list of their grades
            #region Initializing Lists
            Admin adminOne   = new Admin("Bill", "Billsky");
            Admin adminTwo   = new Admin("Jane", "Doe");
            Admin adminThree = new Admin("Stefan", "Stefanoski");
            Admin adminFour  = new Admin("Jerry", "Tompson");

            List <Admin> admins = new List <Admin>()
            {
                adminOne, adminTwo, adminThree, adminFour
            };


            Trainer trainerOne   = new Trainer("John", "Brown");
            Trainer trainerTwo   = new Trainer("Stone", "Stonsky");
            Trainer trainerThree = new Trainer("Maria", "Campbel");
            Trainer trainerFour  = new Trainer("Angel", "Bozinovski");

            List <Trainer> trainers = new List <Trainer>()
            {
                trainerOne, trainerTwo, trainerThree, trainerFour
            };

            Student studentOne   = new Student("Angela", "Avramovska");
            Student studentTwo   = new Student("Pavle", "Nikolov");
            Student studentThree = new Student("Stefan", "Trajkov");
            Student studentFour  = new Student("Daniela", "Bozinova");

            List <Student> students = new List <Student>()
            {
                studentOne, studentTwo, studentThree, studentFour
            };

            Subjects subjectOne   = new Subjects("HTML/CSS");
            Subjects subjectTwo   = new Subjects("JavaScript");
            Subjects subjectThree = new Subjects("AdvancedJavaScript");
            Subjects subjectFour  = new Subjects("Basic C#");

            List <Subjects> subjects = new List <Subjects> {
                subjectOne, subjectTwo, subjectThree, subjectFour
            };


            studentOne.MySubject = new Dictionary <Subjects, int>();

            studentOne.MySubject.Add(subjectOne, 5);
            studentOne.MySubject.Add(subjectThree, 3);

            studentTwo.MySubject = new Dictionary <Subjects, int>();

            studentTwo.MySubject.Add(subjectOne, 4);
            studentTwo.MySubject.Add(subjectTwo, 5);
            studentTwo.MySubject.Add(subjectFour, 4);


            studentThree.MySubject = new Dictionary <Subjects, int>();

            studentThree.MySubject.Add(subjectOne, 5);
            studentThree.MySubject.Add(subjectFour, 5);
            studentThree.MySubject.Add(subjectThree, 5);

            studentFour.MySubject = new Dictionary <Subjects, int>();

            studentFour.MySubject.Add(subjectTwo, 3);
            studentFour.MySubject.Add(subjectOne, 5);

            var nameOfSubjectOne = subjectOne.NameOfSubject;
            int index            = 0;

            foreach (var student in students)
            {
                var listofsubjects = student.MySubject.Where(s => s.Key.NameOfSubject == nameOfSubjectOne).ToList();
                if (listofsubjects.Count != 0)
                {
                    index++;
                }
            }

            subjectOne.indicatiorOfStudents = index;

            var nameOfSubjectTwo = subjectTwo.NameOfSubject;
            int index2           = 0;

            foreach (var student in students)
            {
                var listofsubjects = student.MySubject.Where(s => s.Key.NameOfSubject == nameOfSubjectTwo).ToList();
                if (listofsubjects.Count != 0)
                {
                    index2++;
                }
            }

            subjectTwo.indicatiorOfStudents = index2;

            var nameOfSubjectThree = subjectThree.NameOfSubject;
            int index3             = 0;

            foreach (var student in students)
            {
                var listofsubjects = student.MySubject.Where(s => s.Key.NameOfSubject == nameOfSubjectThree).ToList();
                if (listofsubjects.Count != 0)
                {
                    index3++;
                }
            }

            subjectThree.indicatiorOfStudents = index3;

            var nameOfSubjectFour = subjectThree.NameOfSubject;
            int index4            = 0;

            foreach (var student in students)
            {
                var listofsubjects = student.MySubject.Where(s => s.Key.NameOfSubject == nameOfSubjectFour).ToList();
                if (listofsubjects.Count != 0)
                {
                    index4++;
                }
            }

            subjectFour.indicatiorOfStudents = index4;

            #endregion

            Console.WriteLine("Login on Academy Managemnt Application!");
            Console.WriteLine();

            Console.WriteLine("Press 1) for Admin");
            Console.WriteLine("Press 2) for Trainer");
            Console.WriteLine("Press 3) for Student");
            Console.WriteLine();

            try
            {
                int roleInput = Convert.ToInt32(Console.ReadLine());

                switch (roleInput)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine("Please enter your first name!");
                    string firstName = Console.ReadLine();
                    Console.WriteLine();

                    Console.WriteLine("Please enter your last name!");
                    string lastName = Console.ReadLine();
                    Console.WriteLine();

                    var currentAdmin = admins.Where(a => a.FirstName.ToLower().Trim() == firstName.ToLower().Trim() && a.LastName.ToLower().Trim() == lastName.ToLower().Trim()).ToList();

                    if (currentAdmin.Count == 0)
                    {
                        Console.WriteLine("There is no admin with that personal infos!");
                    }
                    else
                    {
                        //Admin

                        Console.WriteLine("If you want to add Admins/Trainers/Students press 1");
                        Console.WriteLine("If you want to remove Admins/Trainers/Students press 2");
                        Console.WriteLine();

                        try
                        {
                            int inputChoice = Convert.ToInt32(Console.ReadLine());
                            if (inputChoice == 1)
                            {
                                // Add in list
                                Admin.Add(admins, trainers, students);
                            }

                            else if (inputChoice == 2)
                            {
                                //Remove from list, but not it`s self

                                Admin.Remove(admins, trainers, students, firstName, lastName);
                            }
                            else
                            {
                                Console.WriteLine("Wrong input!");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }

                        //RemoveAdmins();
                    }

                    break;

                case 2:
                    //Trainer
                    Console.Clear();
                    Console.WriteLine("Please enter your first name!");
                    string firstNameTrainer = Console.ReadLine();
                    Console.WriteLine();

                    Console.WriteLine("Please enter your last name!");
                    string lastNameTrainer = Console.ReadLine();
                    Console.WriteLine();

                    var currentTrainer = trainers.Where(a => a.FirstName.ToLower().Trim() == firstNameTrainer.ToLower().Trim() && a.LastName.ToLower().Trim() == lastNameTrainer.ToLower().Trim()).ToList();

                    if (currentTrainer.Count == 0)
                    {
                        Console.WriteLine("There is no trainer with that personal infos!");
                    }
                    else
                    {
                        //Trainer

                        Console.WriteLine("If you want to see all Students -> press 1");
                        Console.WriteLine("If you want to see all Subjects -> press 2");
                        Console.WriteLine();

                        try
                        {
                            int inputChoice = Convert.ToInt32(Console.ReadLine());
                            if (inputChoice == 1)
                            {
                                //See all Students
                                foreach (var student in students)
                                {
                                    student.GetFullName();
                                }
                                Console.WriteLine();
                                Console.WriteLine("Write the first name of the student you want to search!");
                                Console.WriteLine();

                                string studentName = Console.ReadLine();

                                var studentInStudents = students.Where(s => s.FirstName.ToLower().Trim() == studentName.ToLower().Trim()).FirstOrDefault();

                                if (studentInStudents == null)
                                {
                                    Console.WriteLine("Wrong input of name!");
                                }
                                else
                                {
                                    Console.WriteLine($"{studentInStudents.FirstName} has attend to: ");
                                    Console.WriteLine();
                                    int number = 1;
                                    foreach (var subject in studentInStudents.MySubject)
                                    {
                                        Console.WriteLine($"{number}){subject.Key.NameOfSubject}");
                                        number++;
                                    }
                                }
                            }

                            else if (inputChoice == 2)
                            {
                                //See all Subjects
                                Console.WriteLine("All subjects:");

                                //When choosing Subjects, all Subject names appear with how many students attend it next to it


                                foreach (var subject in subjects)
                                {
                                    Console.WriteLine($"{subject.NameOfSubject} -> {subject.indicatiorOfStudents} students attend to it!");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Wrong input!");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    break;

                case 3:
                    //Student are shown subjects that they are listening and a list of their grades

                    Console.WriteLine("Please enter your first name!");
                    string firstNameStudent = Console.ReadLine();
                    Console.WriteLine();

                    Console.WriteLine("Please enter your last name!");
                    string lastNameStudent = Console.ReadLine();
                    Console.WriteLine();

                    var currentStudent = students.Where(a => a.FirstName.ToLower() == firstNameStudent.ToLower() && a.LastName.ToLower() == lastNameStudent.ToLower()).ToList();
                    Console.WriteLine();

                    if (currentStudent.Count == 0)
                    {
                        Console.WriteLine("There is no student with that personal infos!");
                    }
                    else
                    {
                        foreach (var student in currentStudent)
                        {
                            student.GetFullName();

                            foreach (var subject in student.MySubject)
                            {
                                Console.WriteLine($"Subject: {subject.Key.NameOfSubject} -> Grade: {subject.Value}");
                            }
                            Console.WriteLine();
                        }
                    }
                    break;

                default:
                    Console.WriteLine("Wrong input!");
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
Esempio n. 7
0
    /// <summary>
    /// 更新信息
    /// </summary>
    public void SaveData()
    {
        var msg      = "yes";
        var json     = Request["data"];
        var rows     = (ArrayList)PluSoft.Utils.JSON.Decode(json);
        var bllAdmin = new Admin();

        foreach (Hashtable row in rows)
        {
            var id       = row["UserID"] != null ? row["UserID"].ToString() : "";
            var password = row["Password"] == null ? "" : row["Password"].ToString();
            //根据记录状态,进行不同的增加、删除、修改操作
            var state = row["_state"] != null ? row["_state"].ToString() : "";
            if (state == "added" || id == "")           //新增:id为空,或_state为added
            {
                if (model != null)
                {
                    model.RealName   = row["RealName"] == null ? "" : row["RealName"].ToString();
                    model.CreateIP   = PageRequest.GetIP();
                    model.CreateTime = DateTime.Now;
                    model.Username   = row["Username"] == null ? "" : row["Username"].ToString();
                    model.IsPublic   = Utils.StrToInt(row["IsPublic"], 0);
                    model.RoleIDs    = row["RoleIDs"] == null ? "" : row["RoleIDs"].ToString();
                    model.State      = Utils.StrToInt(row["State"], 0);
                    model.OfficeTel  = row["OfficeTel"] == null ? "" : row["OfficeTel"].ToString();
                }

                var listrole = new List <Sys.Model.AdminRole>();
                if (!string.IsNullOrEmpty(model.RoleIDs))
                {
                    listrole = new AdminRole().GetList(-1, -1, "RoleId in (" + model.RoleIDs + ")", "createtime desc");
                }
                foreach (var sysRole in listrole)
                {
                    if (sysRole.RoleFlag != "")
                    {
                        model.RoleFlags += sysRole.RoleFlag + ",";
                    }
                    if (sysRole.RoleName != "")
                    {
                        model.RoleNames += sysRole.RoleName + ",";
                    }
                }
                if (model.RoleFlags != "")
                {
                    model.UserFlag = model.RoleFlags + "," + model.PlusFlag;
                }

                var modelPartent = BllAdmin.GetModel(Utils.StrToInt(row["ParentUserID"], 0));
                if (modelPartent != null)
                {
                    if (modelPartent.ParentUserIDs == "")
                    {
                        model.ParentUserIDs = modelPartent.UserId.ToString();
                    }
                    else
                    {
                        model.ParentUserIDs = modelPartent.ParentUserIDs + "," + modelPartent.UserId;
                    }
                    model.ParentUserID = modelPartent.UserId;
                }


                model.RoleNames = Utils.Strquotes(model.RoleNames);
                bllAdmin.Add(model, Utils.MD5(password));

                Response.Write(msg);
            }
            else if (state == "modified" || state == "") //更新:_state为空或modified
            {
                model = bllAdmin.GetModel(Utils.StrToInt(row["UserID"], 0));
                if (model != null)
                {
                    #region 基础字段
                    model.RealName     = row["RealName"] == null ? "" : row["RealName"].ToString();
                    model.CreateIP     = PageRequest.GetIP();
                    model.CreateTime   = DateTime.Now;
                    model.Username     = row["Username"] == null ? "" : row["Username"].ToString();
                    model.IsPublic     = Utils.StrToInt(row["IsPublic"], 0);
                    model.RoleIDs      = row["RoleIDs"] == null ? "" : row["RoleIDs"].ToString();
                    model.ParentUserID = Utils.StrToInt(row["ParentUserID"], 0);
                    model.State        = Utils.StrToInt(row["State"], 0);
                    model.OfficeTel    = row["OfficeTel"] == null ? "" : row["OfficeTel"].ToString();
                    #endregion
                    password = password == "" ? new Account().GetModel(model.UserId).Password : Utils.MD5(password);
                    #region 角色权限
                    var listrole = new List <Sys.Model.AdminRole>();
                    if (!string.IsNullOrEmpty(model.RoleIDs))
                    {
                        listrole = new AdminRole().GetList(-1, -1, "RoleId in (" + model.RoleIDs + ")", "createtime desc");
                    }

                    model.RoleFlags = "";
                    model.RoleNames = "";
                    foreach (var sysRole in listrole)
                    {
                        if (sysRole.RoleFlag != "")
                        {
                            model.RoleFlags += sysRole.RoleFlag + ",";
                        }
                        if (sysRole.RoleName != "")
                        {
                            model.RoleNames += sysRole.RoleName + ",";
                        }
                    }
                    if (model.RoleFlags != "")
                    {
                        model.UserFlag = model.RoleFlags + "," + model.PlusFlag;
                    }
                    #endregion



                    #region 账号层次修改
                    if (bllAdmin.GetList(-1, -1, "(CHARINDEX('" + Loginadmin.UserId + "',parentUserIDs)>0 or userid=" + Loginadmin.UserId + ") and parentUserID=" + model.UserId, "createtime desc").Count > 0)
                    {
                        if (model.ParentUserID > 0)
                        {
                            UpDtaeParentUserIds(model.UserId, model.ParentUserID);
                        }
                    }

                    #endregion

                    bllAdmin.Update(model, password);
                    Response.Write(msg);
                }
            }
        }
    }