private void frmSetExams_FormClosing(object sender, FormClosingEventArgs e) { this.Hide(); frmAdmin fa = new frmAdmin(); fa.Show(); }
private void btn_close_Click(object sender, EventArgs e) { this.Hide(); frmAdmin fa = new frmAdmin(); fa.Show(); }
private void button1_Click(object sender, EventArgs e) { if (!SetExams.Any() || !grades.Any()) { MessageBox.Show("Įrašykite egzaminų įvertinimus."); return; } else if (SetExams.Count != lstBox_Exams.Items.Count) { MessageBox.Show("Įrašykite visų egzaminų įvertinimus."); return; } SqlConnection con = new SqlConnection(connectionStr); SqlCommand cmd = new SqlCommand("", con); try { for (int i = 0; i < SetExams.Count(); i++) { cmd.CommandText = $"UPDATE tbl_Dalykai SET {SetExams[i]} = {grades[i]} WHERE Id = {Id}"; con.Open(); cmd.ExecuteScalar(); con.Close(); } this.Hide(); MessageBox.Show("Sėkmingai įrašyti egzaminai"); frmAdmin fa = new frmAdmin(); fa.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//btn_Login Click event private void btn_Login_Click_1(object sender, EventArgs e) { //checking if information is entered if (txt_Username.Text == "" || txt_Password.Text == "") { MessageBox.Show("Įrašykite informaciją!"); return; } try { //Creating sql connection SqlConnection con = new SqlConnection(connectionStr); SqlCommand cmd = new SqlCommand("Select * from tbl_LoginInfo where UserName=@username and Password=@password", con); //Adding reference cmd.Parameters.AddWithValue("@username", txt_Username.Text); cmd.Parameters.AddWithValue("@password", txt_Password.Text); //Opening connection con.Open(); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapt.Fill(ds); con.Close(); int count = ds.Tables[0].Rows.Count; //If count is equal to 1, then show Main form if (count == 1) { MessageBox.Show("Sėkmingai prisijungta!"); this.Hide(); if (txt_Username.Text == "Admin") { frmAdmin fmA = new frmAdmin(); fmA.Show(); } else { string surname = Convert.ToString(ds.Tables[0].Rows[0]["Surname"]); int id = Convert.ToInt32(ds.Tables[0].Rows[0]["Id"]); string personalID = Convert.ToString(ds.Tables[0].Rows[0]["PersonalID"]); string fullName = txt_Username.Text + " " + surname; FrmMain fm = new FrmMain(fullName, personalID); fm.Text = fullName; fm.DisplayExams(id); fm.Show(); } } else { MessageBox.Show("Prisijungimas nesėkmingas. Patikrinkite įvestą informaciją."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btn_Add_Click(object sender, EventArgs e) { //Checking if given textboxes aren't empty if (!(txt_UserName.Text == "" && txt_Surname.Text == "" && txt_personalID.Text == "" && txt_Password.Text == "")) { if (txt_personalID.Text.Length == 11) { if (lstbx_exams.CheckedIndices.Count >= 2 && lstbx_exams.CheckedIndices.Count <= 5) { try { int id; SqlConnection con = new SqlConnection(connectionStr); //Finding biggest Id SqlCommand cmd = new SqlCommand("SELECT MAX(Id) FROM tbl_LoginInfo", con); cmd.Connection = con; con.Open(); //saving id id = Convert.ToInt32(cmd.ExecuteScalar()) + 1; //inserting new value cmd.CommandText = $"INSERT INTO tbl_LoginInfo (Id, UserName, Password, PersonalID, Surname) VALUES ({id}, " + $"'{txt_UserName.Text}', '{txt_Password.Text}', '{txt_personalID.Text}', '{txt_Surname.Text}')"; cmd.ExecuteNonQuery(); con.Close(); //Getting a list of selected exams List <string> checkeditems = lstbx_exams.CheckedItems.Cast <object>() .Select(item => item.ToString()).ToList(); try { con.Open(); cmd.CommandText = $"INSERT tbl_Dalykai (Id) VALUES ({id})"; cmd.ExecuteNonQuery(); foreach (var item in checkeditems) { if (item == "Lietuvių k.") { cmd.CommandText = $"UPDATE tbl_Dalykai SET Lietuviu = 101 WHERE Id = {id}"; } else if (item == "Anglų k.") { cmd.CommandText = $"UPDATE tbl_Dalykai SET Anglu = 101 WHERE Id = {id}"; } else if (item == "Informacinės technologijos") { cmd.CommandText = $"UPDATE tbl_Dalykai SET IT = 101 WHERE Id = {id}"; } else { cmd.CommandText = $"UPDATE tbl_Dalykai SET {item} = 101 WHERE Id = {id}"; } cmd.ExecuteNonQuery(); } con.Close(); } catch (Exception er) { MessageBox.Show(er.Message); } MessageBox.Show("Moksleivis sėkmingai pridėtas!"); frmAdmin fa = new frmAdmin(); this.Hide(); fa.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Prašome parinkti ne mažiau nei 2 ir ne daugiau kaip 5 egzaminus!"); } } else { MessageBox.Show("Asmens kodas turi turėti 11 skaitmenų!"); } } else { MessageBox.Show("Prašome įrašyti visą informaciją!"); } }