Beispiel #1
0
        //sign up button
        private void button2_Click(object sender, EventArgs e)
        {
            foreach (Control c in Controls)
            {
                if (c is TextBox)
                {
                    if (c.Text.Length == 0)
                    {
                        MessageBox.Show("All feilds are mandatory");
                        return;
                    }
                }
            }
            foreach (PictureBox c in Controls.OfType <PictureBox>())
            {
                if (c is PictureBox)
                {
                    if (c.ImageLocation == defaultImage)
                    {
                        MessageBox.Show("all images are mandatory");
                        return;
                    }
                }
            }

            student.Name     = textBox2.Text;
            student.Type     = "student";
            student.MobileNo = textBox3.Text;

            if (textBox4.Text != textBox5.Text)
            {
                MessageBox.Show("Password not mathcing!");
                return;
            }
            if (textBox4.Text.Length < 8)
            {
                MessageBox.Show("Password length must be of 8 or more!");
                return;
            }
            if (loginCredential.Find(n => n.UserName == textBox1.Text).CountDocuments() != 0)
            {
                MessageBox.Show("Username already exists!");
                return;
            }
            student.Gender = Controls.OfType <RadioButton>().First().Text;

            picture.UserName = user.UserName = student.UserName = textBox1.Text;
            user.Password    = textBox4.Text.GetHashCode();
            Directory.CreateDirectory(String.Format(@"C:\ProxyKiller\ProxyKiller\ProxyKiller\userPictures\{0}", user.UserName));
            for (int i = 0; i < 4; i++)
            {
                string filename = String.Format(@"C:\ProxyKiller\ProxyKiller\ProxyKiller\userPictures\{0}\{1}{2}.jpg", user.UserName, user.UserName, i);
                File.Copy(picture.ImageLocations[i], filename, true);
                picture.ImageLocations[i] = filename;
            }

            studentInfo.InsertOne(student);
            loginCredential.InsertOne(user);
            studentPicture.InsertOne(picture);

            textBox1.Text             = textBox2.Text = textBox3.Text = textBox4.Text = textBox5.Text = String.Empty;
            pictureBox1.ImageLocation = pictureBox2.ImageLocation = pictureBox3.ImageLocation = pictureBox4.ImageLocation = defaultImage;


            StudentForm s = StudentForm.GetInstance(user.UserName);

            MainContainer.LoadForm(s);
        }