private void iniciarsesionBtn_Click(object sender, EventArgs e) //iniciar sesion { try { //Leemos los datos de los TextBox string n = nombreBox.Text; string c = contraseñaBox.Text; //Si alguno de los dos campos está vacío no se puede registrar if (n == "" || c == "") { MessageBox.Show("Todos los campos son obligatorios"); } //No hay ningún campo nulo pero hay que hacer otras comprovaciones else { try { //Abrimos la base de datos baseops bbdd = new baseops(); bbdd.open(); //Busco si el usuario existe. Si no está registrado, no puede iniciar sesión if (bbdd.CompruebaUsuario(n) == false) { MessageBox.Show("Usuario no registrado. Registrese para iniciar sesión"); } //Sabemos que el usuario está registrado, pero hay que comprobar si la contraseña es la correcta else { if (bbdd.CompruebaContraseña(n, c) == true) //Contraseña correcta { //Hacemos que no se vea este form this.Hide(); //Abrimos el form principal Demo f1 = new Demo(); //Le pasamos el usuario que ha iniciado sesion f1.getusuario(nombreBox.Text); f1.ShowDialog(); //Cerramos este form this.Close(); } else //Contraseña incorrecta { MessageBox.Show("Contraseña incorrecta"); } } } catch { MessageBox.Show("No existe el usuario"); } } } catch { } }
private void buttonAddDemo_Click(object sender, EventArgs e) { bool last = false; // inital values for comboboxes String gend = "Male"; String yr = "5"; // check if last year if (comboBoxLast.SelectedIndex == 0) { last = true; } // check gender if (comboBoxGender.SelectedIndex == 1) { gend = "Female"; } else if (comboBoxGender.SelectedIndex == 2) { gend = "Other"; } // year of study if (comboBoxYear.SelectedIndex < 4) // else it is 5+ (inital value) { yr = (comboBoxYear.SelectedIndex + 1).ToString(); } // fill in multiline textboxes List <String> en = new List <string>(); en.AddRange(textBoxEnrolled.Lines); en.RemoveAll(String.IsNullOrWhiteSpace); List <String> ex = new List <string>(); ex.AddRange(textBoxPrevious.Lines); List <String> pr = new List <string>(); pr.AddRange(textBoxPreffered.Lines); bool fail = false; foreach (string s in en) { if (!Regex.Match(s.ToUpper(), "^(CGRD|COMP|STAT|MATH)\\d{3}-\\d{2}(A|B|T|S|C)").Success || s.Equals("") || s.Equals("\n")) { MessageBox.Show("Invalid Course: " + s + "\nFORMAT: \"COMP103-14A\""); fail = true; } } if (fail == false && (textBoxFirstName.Text == "" || textBoxFamilyName.Text == "")) { MessageBox.Show("Name fields cannot be blank"); fail = true; } if (fail == false && (textBoxEmail.Text == "" && textBoxPhone.Text == "")) { MessageBox.Show("At least one form of contact is required, either email or phone"); fail = true; } if (fail == false) { try { int.Parse(textBoxAge.Text); } catch (Exception exc) { MessageBox.Show("Age needs to be a number"); fail = true; } } // If invalid Paper Don't save if (fail) { return; } // Create new demo Demo d = new Demo(textBoxFirstName.Text, textBoxFamilyName.Text, textBoxPhone.Text, textBoxAge.Text, gend, textBoxUsername.Text, textBoxID.Text, textBoxSummer.Text, textBoxMajor.Text, textBoxDegree.Text, yr, last, textBoxEmail.Text, en, ex, pr, times); if (editing) // if the demo is being edited { d.updateDB(); // update demos attribute to database } else { Main.potentialDemos.Add(d); // add in demo to main form's list d.addToDB(); // add demo to database } mainForm.ListBoxPotentialDemos_Refresh(); mainForm.ListBoxPDHours_Refresh(); // update list box this.Close(); }