コード例 #1
0
        private void SessionInfoUpdate(String userID, String pass)
        {
            SampleDataContext context = new SampleDataContext();
            User x = context.Users.SingleOrDefault(u => u.UserID == userID && u.Password == pass);

            Session["user"] = x;
        }
コード例 #2
0
        protected void UpdateProfile_Click(object sender, EventArgs e)
        {
            SampleDataContext context = new SampleDataContext();
            User user = (User)Session["user"];

            String   fname  = FnameTxt.Text;
            String   lname  = LnameTxt.Text;
            String   email  = EmailTxt.Text;
            DateTime bday   = DateTime.Parse(TextBoxDOB.Text);
            String   gender = GenderButtonList.SelectedValue;

            int age = DateTime.Now.Year - bday.Year;


            var userToUpdate = (from u in context.Users
                                where u.UserID == user.UserID
                                select u).First();


            userToUpdate.FirstName = fname;
            userToUpdate.LastName  = lname;
            userToUpdate.Email     = email;
            userToUpdate.BirthDate = bday;
            userToUpdate.Gender    = gender;
            userToUpdate.Age       = age;


            context.SubmitChanges();

            ResultText.Visible = true;
            SessionInfoUpdate(user.UserID, user.Password);
        }
コード例 #3
0
        protected void Sign_Click(object sender, EventArgs e)
        {
            String userID = idTxt.Text;
            String pass   = passText.Text;

            SampleDataContext context = new SampleDataContext();
            User x = context.Users.SingleOrDefault(u => u.UserID == userID && u.Password == pass);

            if (x != null)
            {
                Session["user"] = x;
                if (x.Type == "Admin")
                {
                    Response.Redirect("~/AddAdminShowUser.aspx");
                }
                if (x.Type == "User")
                {
                    Response.Redirect("~/UserProfile.aspx");
                }
                if (x.Type == "Doctor")
                {
                    Response.Redirect("~/DoctorProfile.aspx");
                }
            }
            else
            {
                Error.Visible = true;
            }
        }
コード例 #4
0
        private void loadUser()
        {
            SampleDataContext sContext = new SampleDataContext();
            List <User>       Users    = (from user in sContext.Users
                                          select user).ToList();

            GridView1.DataSource = Users;
            GridView1.DataBind();
        }
        protected void SignUp_Click(object sender, EventArgs e)
        {
            SampleDataContext context = new SampleDataContext();
            List <User>       uList   = context.Users.Where(u => u.UserID == UserIDTxt.Text).ToList();

            if (uList.Count <= 0)
            {
                String   fname  = FnameTxt.Text;
                String   lname  = LnameTxt.Text;
                String   uid    = UserIDTxt.Text;
                String   email  = EmailTxt.Text;
                DateTime bday   = DateTime.Parse(TextBoxDOB.Text);
                String   gender = GenderButtonList.SelectedValue;
                String   pass   = PassTxt.Text;
                int      age    = new DateTime((DateTime.Now - Convert.ToDateTime(bday)).Ticks).Year;



                User user = new User()
                {
                    FirstName = fname,
                    LastName  = lname,
                    UserID    = uid,
                    BirthDate = bday,
                    Age       = age,
                    Gender    = gender,
                    Password  = pass,
                    Type      = "User",
                    Email     = email
                };
                context.Users.InsertOnSubmit(user);
                context.SubmitChanges();



                String specialist = DropDownListSpecialist.SelectedValue;
                int    experience = Int32.Parse(ExperienceTxt.Text);

                Doctor doc = new Doctor()
                {
                    DocID      = user.id,
                    Specialist = specialist,
                    Experience = experience
                };

                context.Doctors.InsertOnSubmit(doc);
                context.SubmitChanges();

                ResultText.Visible = true;
                NameTaken.Visible  = false;
            }
            else
            {
                NameTaken.Visible  = true;
                ResultText.Visible = false;
            }
        }
コード例 #6
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Int32.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text);
            SampleDataContext sContext = new SampleDataContext();
            var user = sContext.Users.FirstOrDefault(s => s.id == id);

            if (user != null)
            {
                sContext.Users.DeleteOnSubmit(user);
                sContext.SubmitChanges();
            }
            loadUser();
        }
コード例 #7
0
        private void search(String wordToSearch, String key)
        {
            SampleDataContext context = new SampleDataContext();
            List <User>       Users   = new List <User>();

            switch (key)
            {
            case "Any":
                Users = context.Users.Where(u => u.FirstName.Contains(wordToSearch) ||
                                            u.LastName.Contains(wordToSearch) ||
                                            u.Age.ToString().Contains(wordToSearch) ||
                                            u.BirthDate.ToString().Contains(wordToSearch) ||
                                            u.Type.Contains(wordToSearch)).ToList();
                break;

            case "First Name":
                Users = context.Users.Where(u => u.FirstName.Contains(wordToSearch)).ToList();
                break;

            case "Last Name":
                Users = context.Users.Where(u => u.LastName.Contains(wordToSearch)).ToList();
                break;

            case "Age":
                Users = context.Users.Where(u => u.Age.ToString().Contains(wordToSearch)).ToList();
                break;

            case "Type":
                Users = context.Users.Where(u => u.Type.Contains(wordToSearch)).ToList();
                break;

            default:

                break;
            }
            if (wordToSearch == "")
            {
                Users = (from user in context.Users
                         select user).ToList().ToList();
            }

            GridView1.DataSource = Users;
            GridView1.DataBind();
        }
コード例 #8
0
        protected void ChangePassBtn_Click(object sender, EventArgs e)
        {
            SampleDataContext context = new SampleDataContext();
            User user = (User)Session["user"];

            if (changepassTxt.Text == user.Password)
            {
                var userToUpdate = (from u in context.Users
                                    where u.UserID == user.UserID
                                    select u).First();
                userToUpdate.Password = PassTxt.Text;
                context.SubmitChanges();
                ChangePassText.Visible = true;
                SessionInfoUpdate(user.UserID, userToUpdate.Password);
            }
            else
            {
                wrongpassTxt.Visible = false;
            }
        }