public void adaugaCont(string user, string password, int clasa) { if (user != "" && password != "" && !verificaUser(user)) { try { using (var db = new EntityFBio()) { Account account = new Account(); account.User = user; account.Password = password; account.ClassId = clasa; db.Accounts.Add(account); if (db.SaveChanges() != 0) { MessageBox.Show("Cont creat cu succes(user= "******")"); } } } catch (Exception ex) { MessageBox.Show("A aparut o eroare la baza de date, contactati developerul cat mai rapid."); } } else { MessageBox.Show("User/Parola prea scurte sau User existent"); } }
public bool isAdmin(string user) { using (var db = new EntityFBio()) { return((db.Accounts.Where(s => s.User == user).Select(s => s.Class.ClassName).FirstOrDefault() == "Admin") ? true : false); } }
public void adaugaTest(string nume) { if (nume != "" && !verificaTest(nume)) { try { using (var db = new EntityFBio()) { Test test = new Test(); test.Name = nume; db.Tests.Add(test); db.SaveChanges(); MessageBox.Show("Testul cu numele " + nume + ", id " + test.Id + " a fost adaugat in baza de date"); } } catch (Exception ex) { MessageBox.Show("A aparut o eroare la baza de date, contactati developerul cat mai rapid."); } } else { MessageBox.Show("Testul cu numele " + nume + " exista deja in baza de date."); } }
private void button1_Click(object sender, EventArgs e) { using (var db = new EntityFBio()) { DialogResult x = MessageBox.Show("Esti sigur ca doresti sa adaugi imaginea in baza de date?", "", MessageBoxButtons.YesNo); if (x == DialogResult.Yes) { EntityFramework.Image image = new EntityFramework.Image(); image.Url = pictureBox1.ImageLocation.ToString(); image.Name = textBox2.Text; db.Images.Add(image); if (db.SaveChanges() == 1) { MessageBox.Show("Imaginea a fost adaugata in baza de date"); } else { MessageBox.Show("Imaginea nu a fost adaugata in baza de date"); } } else { MessageBox.Show("Imaginea nu a fost adaugata in baza de date"); } } }
public void adaugaTest(string nume, List <Question> enunturi) { if (nume != "" && !verificaTest(nume)) { try { using (var db = new EntityFBio()) { Test test = new Test(); test.Name = nume; db.Tests.Add(test); db.SaveChanges(); string enunt = ""; foreach (var x in enunturi) { enunt += x.Id + ", "; db.QuestionTests.Add(new QuestionTest { QuestionId = x.Id, TestId = test.Id }); } db.SaveChanges(); MessageBox.Show("Testul cu numele " + nume + ", id " + test.Id + " care contine enunturile cu id:" + enunt + " a fost creeat si introdus cu succes in baza de date"); } } catch (Exception ex) { MessageBox.Show("A aparut o eroare la baza de date, contactati developerul cat mai rapid."); } } else { MessageBox.Show("Testul cu numele " + nume + " exista deja in baza de date."); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedItem.ToString() != "Toate") { using (var db = new EntityFBio()) { int classId = db.Classes.Where(s => s.ClassName == comboBox1.SelectedItem.ToString()).FirstOrDefault().Id; populateList(classId); } } else { listBox1.Items.Clear(); listBox1.Items.Add("Nume\t\tTest\t\tPunctaj"); string Mark = ""; string Test = ""; string User = ""; using (var db = new EntityFBio()) { foreach (var x in db.Results) { AccountTest accountTest = db.AccountTests.Where(s => s.Id == x.AccountTestId).Select(s => s).FirstOrDefault(); User = accountTest.Account.User; Test = accountTest.Test.Name; Mark = x.Mark.ToString(); listBox1.Items.Add(User + "\t\t" + Test + "\t\t" + Mark); } } } }
public string getClasa(string user) { using (var db = new EntityFBio()) { var x = db.Accounts.FirstOrDefault(s => s.User == user); return(x.Class.ClassName); } }
public int returneazaID(string user) { using (var db = new EntityFBio()) { int id = db.Accounts.Where(s => s.User == user).Select(s => s.Id).FirstOrDefault(); return(id); } }
public void schimbaParola(string user, string password) { using (var db = new EntityFBio()) { var x = db.Accounts.FirstOrDefault(s => s.User == user); x.Password = password; db.SaveChanges(); } }
public bool verificaCont(string user, string password) { using (var db = new EntityFBio()) { var cont = db.Accounts.Where(s => s.User == user).Select(s => s).FirstOrDefault(); return((cont.Password == password) ? true : false); } return(false); }
public string GetTest(string clasa) { using (var db = new EntityFBio()) { //var x = db.Classes.FirstOrDefault(s => s.ClassName == clasa); //return db.Tests.Where(s => s.ClassId == x.Id).Select(s => s.Name).FirstOrDefault(); return(db.Classes.Where(x => x.ClassName == clasa).Select(x => x.Test.Name).FirstOrDefault()); } }
private void afiseazaEnunturi() { using (var db = new EntityFBio()) { var query = from x in db.Questions select x; foreach (var x in query) { checkedListBox1.Items.Add(x.Id + "\t" + x.Level + " \t " + x.QuestionText); } } }
private void fetchComboBox() { using (var db = new EntityFBio()) { foreach (var x in db.Images) { comboBox1.Items.Add(x.Name); urls[k] = x.Url; names[k++] = x.Name; } } }
private void button1_Click(object sender, EventArgs e) { using (var db = new EntityFBio()) { string test, clasa; clasa = functii.getClasa(user); test = functii.GetTest(clasa); Testare visa = new Testare(user, test, false); Hide(); visa.Closed += (s, args) => Close(); visa.Show(); } }
private void fetchComboBox2() { comboBox1.Items.Clear(); using (var db = new EntityFBio()) { var query = from x in db.Tests select x; foreach (var x in query) { comboBox1.Items.Add(x.Name); } } comboBox1.Items.Add("Test Nou"); }
public AdaugareElev() { InitializeComponent(); using (var db = new EntityFBio()) { foreach (var x in db.Classes) { if (x.ClassName != "Admin") { comboBox1.Items.Add(x.ClassName); } } } }
public List <Question> getQuestions(Test test) { List <Question> Questions = new List <Question>(); using (EntityFBio db = new EntityFBio()) { var QuestionsTests = db.QuestionTests.Where(s => s.TestId == test.Id).Select(s => s); foreach (var x in QuestionsTests) { Questions.Add(db.Questions.FirstOrDefault(s => s.Id == x.QuestionId)); } } return(Questions); }
private void fetchComboBox() { comboBox1.Items.Add("Toate"); using (var db = new EntityFBio()) { foreach (var x in db.Classes) { if (x.ClassName != "Admin") { comboBox1.Items.Add(x.ClassName); } } } }
public bool verificaTest(string nume) { using (var db = new EntityFBio()) { if (db.Tests.Any(s => (s.Name == nume))) { return(true); } else { return(false); } } }
public bool verificaUser(string user) { using (var db = new EntityFBio()) { if (db.Accounts.Any(s => (s.User == user))) { return(true); } else { return(false); } } }
public Exersare(string str) { InitializeComponent(); user = str; using (var db = new EntityFBio()) { foreach (var x in db.Tests) { if (x.Exersare == 1) { comboBox1.Items.Add(x.Name); } } } }
public bool faraEnunturi(Test test) { using (var db = new EntityFBio()) { int x = 0; foreach (var y in db.QuestionTests) { if (y.TestId == test.Id) { x++; } } return((x > 0) ? false : true); } }
private void button1_Click(object sender, EventArgs e) { using (var db = new EntityFBio()) { //var query = db.Tests.Where(x => x.Name == comboBox1.SelectedItem.ToString()); //foreach (var x in query) // x.ClassId = db.Classes.FirstOrDefault(y => y.ClassName == comboBox2.SelectedItem.ToString()).Id; var query = db.Classes.Where(x => x.ClassName == comboBox2.SelectedItem.ToString()); foreach (var x in query) { x.TestId = db.Tests.FirstOrDefault(y => y.Name == comboBox1.SelectedItem.ToString()).Id; } db.SaveChanges(); MessageBox.Show("Testul a fost adaugat cu succes."); } }
private void button1_Click(object sender, EventArgs e) { string username = textBox1.Text, parola = textBox2.Text; int clasa = 0; if (checkBox1.Checked) { clasa = 1; } using (var db = new EntityFBio()) { clasa = db.Classes.Where(s => s.ClassName == comboBox1.SelectedItem.ToString()).FirstOrDefault().Id; } FunctiiPublice login = new FunctiiPublice(); login.adaugaCont(username, parola, clasa); Close(); }
public void adaugaEnunt(int dificultate, string cerinta, int tip, string raspuns, string var1, string var2, string var3, string var4) { using (var db = new EntityFBio()) { Question intrebare = new Question(); if (tip == 0) { intrebare.Type = 0; intrebare.QuestionText = cerinta; intrebare.Answer = raspuns; intrebare.choice1 = var1; intrebare.choice2 = var2; intrebare.choice3 = var3; intrebare.choice4 = var4; } else if (tip == 1) { intrebare.Type = 1; intrebare.QuestionText = cerinta; intrebare.Answer = raspuns; } else if (tip == 2) { intrebare.Type = 2; intrebare.QuestionText = cerinta; intrebare.Answer = raspuns; intrebare.choice1 = var1; intrebare.choice2 = var2; intrebare.choice3 = var3; intrebare.choice4 = var4; } intrebare.Level = dificultate; db.Questions.Add(intrebare); db.SaveChanges(); if (tip == 0) { MessageBox.Show("Item-ul cu enuntul: " + cerinta + ", raspunsul " + raspuns + " si cu variantele de raspuns: \n-" + var1 + "\n-" + var2 + "\n-" + var3 + "\n-" + var4 + "\n a fost adaugat in baza de date"); } else { MessageBox.Show("Item-ul cu enuntul:" + cerinta + ", raspunsul " + raspuns + "\n a fost adaugat in baza de date"); } } }
public bool clearTest(Test test) { using (var db = new EntityFBio()) { var query = db.QuestionTests.Where(s => s.TestId == test.Id).Select(s => s); foreach (var x in query) { db.QuestionTests.Remove(x); } if (db.SaveChanges() != 0) { return(true); } else { return(false); } } }
private void populateList(int classId) { listBox1.Items.Clear(); listBox1.Items.Add("Nume\t\tTest\t\tPunctaj"); string Mark = ""; string Test = ""; string User = ""; using (var db = new EntityFBio()) { foreach (var x in db.Results) { AccountTest accountTest = db.AccountTests.Where(s => s.Id == x.AccountTestId).Select(s => s).FirstOrDefault(); User = accountTest.Account.User; Test = accountTest.Test.Name; Mark = x.Mark.ToString(); if (accountTest.Account.ClassId == classId) { listBox1.Items.Add(User + "\t\t" + Test + "\t\t" + Mark); } } } }
private void finalizareTest() { using (var db = new EntityFBio()) { double punctaj = 90.0 / numarEnunturi; decimal rezultatul = (decimal)punctaj * corecte + 10; rezultatul = Math.Round(rezultatul, 2); if (!exersare) { AccountTest accountTest = new AccountTest(); accountTest.UserId = User.Id; accountTest.TestId = Test.Id; db.AccountTests.Add(accountTest); db.SaveChanges(); db.Results.Add(new Result { Mark = rezultatul, AccountTestId = accountTest.Id }); db.SaveChanges(); } MessageBox.Show("Rezultat: " + rezultatul + " puncte"); } abandon = 1; }
private void button1_Click(object sender, EventArgs e) { List <Question> Questions = new List <Question>(); using (var db = new EntityFBio()) { var query = db.Tests.Where(x => x.Name == comboBox1.SelectedItem.ToString()); foreach (var x in query) { if (faraEnunturi(x)) { for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { char delimiter = '\t'; string[] words = checkedListBox1.Items[i].ToString().Split(delimiter); int id = int.Parse(words[0]); Question en = db.Questions.FirstOrDefault(s => s.Id == id); Questions.Add(en); } } foreach (var y in Questions) { db.QuestionTests.Add(new QuestionTest { QuestionId = y.Id, TestId = x.Id }); } } else { string enunturile = ""; foreach (var xy in Questions) { enunturile += xy.QuestionText + ", "; } string enunturiExistente = ""; char[] delimiterChar = { ',', ' ' }; string[] words = enunturile.Split(delimiterChar); foreach (string s in words) { var qn = db.Questions.Where(c => c.Id.ToString() == s).Select(c => c); foreach (var y in qn) { enunturiExistente += y.QuestionText + "\n"; } } DialogResult box = MessageBox.Show("Testul contine deja enunturi. Doriti sa le stergeti - YES? Doriti sa le suprascrieti? - NO\n" + enunturiExistente, "INFO", MessageBoxButtons.YesNo); if (box == DialogResult.Yes) { //stergeEnunturi clearTest(x); for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { char delimiter = '\t'; string[] word = checkedListBox1.Items[i].ToString().Split(delimiter); int id = int.Parse(word[0]); Question enunt = db.Questions.Where(s => s.Id == id).Select(s => s).FirstOrDefault(); Questions.Add(enunt); } } foreach (var y in Questions) { db.QuestionTests.Add(new QuestionTest { QuestionId = y.Id, TestId = x.Id }); } } else { for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.GetItemChecked(i)) { char delimiter = '\t'; string[] word = checkedListBox1.Items[i].ToString().Split(delimiter); int id = int.Parse(word[0]); Question enunt = db.Questions.Where(s => s.Id == id).Select(s => s).FirstOrDefault(); Questions.Add(enunt); } } foreach (var y in Questions) { db.QuestionTests.Add(new QuestionTest { QuestionId = y.Id, TestId = x.Id }); } } } } try { if (checkBox1.Checked) { query.FirstOrDefault().Exersare = 1; } db.SaveChanges(); MessageBox.Show("Testul a fost adaugat in baza de date"); } catch (Exception ex) { MessageBox.Show("A aparut o eroare la baza de date, verificati ca enunturile sa nu se suprapuna la un singur test (un enunt, o singura data intr-un test)"); } } }
public Testare(string user, string tes, bool exersareB) { InitializeComponent(); test = tes; u = user; exersare = exersareB; using (var db = new EntityFBio()) { Test = db.Tests.FirstOrDefault(s => s.Name == tes); Questions = functii.getQuestions(Test); User = db.Accounts.FirstOrDefault(s => s.User == u); } WindowState = FormWindowState.Maximized; FormBorderStyle = FormBorderStyle.None; Bounds = Screen.PrimaryScreen.Bounds; numarEnunturi = Questions.Count; for (int i = 0; i < 200; i++) { raspunse[i] = 0; } //BUTOANE int yx = 70, xy = 350; butonRaspuns1.Parent = this; butonRaspuns2.Parent = this; butonRaspuns1.Location = new Point(1263, 780); butonRaspuns2.Location = new Point(1263, 780); butonRaspuns1.Size = new Size(250, 65); butonRaspuns2.Size = new Size(250, 65); butonRaspuns1.Anchor = AnchorStyles.Right; butonRaspuns2.Anchor = AnchorStyles.Right; butonRaspuns1.Font = labelCerinta.Font; butonRaspuns2.Font = labelCerinta.Font; butonRaspuns1.Font = new Font(butonRaspuns1.Font.FontFamily, 20); butonRaspuns2.Font = new Font(butonRaspuns2.Font.FontFamily, 20); butonRaspuns1.Text = "Raspunde"; butonRaspuns2.Text = "Raspunde"; butonRaspuns1.ForeColor = Color.FromArgb(250, 242, 200); butonRaspuns2.ForeColor = Color.FromArgb(245, 142, 107); butonRaspuns2.Click += (s, args) => { for (int i = 0; i < 4; i++) { if (radioButtonsImg[i].Checked) { if (pictureBoxes[i].ImageLocation == Questions[lastID].Answer) { corecte++; } radioButtonsImg[i].Checked = false; numarRaspunse++; Questions[lastID].Answered = true; if (numarRaspunse < numarEnunturi) { // afiseazaEnunt(Enunturi[numarRaspunse++].id); afiseazaEnunt(getID()); } else { DialogResult rez = MessageBox.Show("Doriti sa incheiati testul?", "Confirm", MessageBoxButtons.YesNoCancel); if (rez == DialogResult.Yes) { finalizareTest(); Close(); } } } } }; campRaspuns.Parent = this; campRaspuns.Text = ""; campRaspuns.Location = new Point(25, 400); campRaspuns.Anchor = AnchorStyles.Left; campRaspuns.Font = labelCerinta.Font; campRaspuns.Font = new Font(campRaspuns.Font.FontFamily, 20); campRaspuns.Size = new Size(470, 61); campRaspuns.BackColor = Color.FromArgb(199, 209, 175); campRaspuns.ForeColor = Color.FromArgb(245, 142, 107); butonRaspuns.Parent = this; butonRaspuns.Location = new Point(1263, 780); butonRaspuns.Size = new Size(250, 65); butonRaspuns.Anchor = AnchorStyles.Right; butonRaspuns1.Font = labelCerinta.Font; butonRaspuns1.Font = new Font(butonRaspuns1.Font.FontFamily, 20); butonRaspuns.Text = "Raspunde"; butonRaspuns.ForeColor = butonRaspuns1.ForeColor; var margin = butonRaspuns1.Margin; margin.Left = 50; margin.Right = 50; butonRaspuns.ForeColor = Color.FromArgb(245, 142, 107); butonRaspuns1.ForeColor = Color.FromArgb(245, 142, 107); butonRaspuns1.Margin = margin; butonRaspuns.Margin = margin; campRaspuns.Margin = margin; campRaspuns.Update(); butonRaspuns.Update(); butonRaspuns1.Update(); butonRaspuns2.Update(); for (int i = 0; i < 4; i++) { checkboxs[i] = new RadioButton(); checkboxs[i].Parent = this; checkboxs[i].Size = new Size(1650, 55); checkboxs[i].Location = new Point(yx, xy += 70); //tableLayoutPanel1.Controls.Add(checkboxs[i], 0, i+1); checkboxs[i].Anchor = AnchorStyles.Left; checkboxs[i].Margin = margin; checkboxs[i].Update(); } yx = -75; xy = 600; for (int i = 0; i < 4; i++) { radioButtonsImg[i] = new RadioButton { Parent = this, Size = new Size(55, 55), Location = new Point(yx += 325, xy), //tableLayoutPanel1.Controls.Add(radioButtonsImg[i], i+1, 1); Text = (i + 1).ToString() }; radioButtonsImg[i].Anchor = AnchorStyles.Left; radioButtonsImg[i].Margin = margin; radioButtonsImg[i].Update(); } xy = 300; yx = -190; for (int i = 0; i < 4; i++) { pictureBoxes[i] = new PictureBox { Parent = this, Size = new Size(275, 275), Location = new Point(yx += 325, xy), ImageLocation = "", SizeMode = PictureBoxSizeMode.StretchImage }; pictureBoxes[i].Anchor = AnchorStyles.Left; pictureBoxes[i].Margin = margin; pictureBoxes[i].Update(); } pictureBoxes[0].Click += (s, args) => { VizualizeazaImagine vizualizeazaImagine = new VizualizeazaImagine(pictureBoxes[0].ImageLocation); vizualizeazaImagine.Ownerr = this; vizualizeazaImagine.Show(); vizualizeazaImagine.FormClosed += (s1, args2) => { Activate(); }; }; pictureBoxes[1].Click += (s, args) => { VizualizeazaImagine vizualizeazaImagine = new VizualizeazaImagine(pictureBoxes[1].ImageLocation); vizualizeazaImagine.Ownerr = this; vizualizeazaImagine.Show(); vizualizeazaImagine.FormClosed += (s1, args2) => { Activate(); }; }; pictureBoxes[2].Click += (s, args) => { VizualizeazaImagine vizualizeazaImagine = new VizualizeazaImagine(pictureBoxes[2].ImageLocation); vizualizeazaImagine.Ownerr = this; vizualizeazaImagine.Show(); vizualizeazaImagine.FormClosed += (s1, args2) => { Activate(); }; }; pictureBoxes[3].Click += (s, args) => { VizualizeazaImagine vizualizeazaImagine = new VizualizeazaImagine(pictureBoxes[3].ImageLocation); vizualizeazaImagine.Ownerr = this; vizualizeazaImagine.Show(); vizualizeazaImagine.FormClosed += (s1, args2) => { Activate(); }; }; WindowState = FormWindowState.Normal; FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; Bounds = Screen.PrimaryScreen.Bounds; Activate(); butonRaspuns.Click += (s, args) => { for (int i = 0; i < 4; i++) { if (checkboxs[i].Checked) { if (checkboxs[i].Text.ToLower() == Questions[lastID].Answer.ToLower()) { corecte++; } checkboxs[i].Checked = false; numarRaspunse++; Questions[lastID].Answered = true; if (numarRaspunse < numarEnunturi) { // afiseazaEnunt(Enunturi[numarRaspunse++].id); afiseazaEnunt(getID()); } else { DialogResult rez = MessageBox.Show("Doriti sa incheiati testul?", "Confirm", MessageBoxButtons.YesNoCancel); if (rez == DialogResult.Yes) { finalizareTest(); Close(); } } } } }; butonRaspuns1.Click += (s, args) => { butonRaspuns.Hide(); campRaspuns.Hide(); if (campRaspuns.Text.ToLower() == Questions[lastID].Answer.ToLower()) { corecte++; } campRaspuns.Text = ""; numarRaspunse++; Questions[lastID].Answered = true; if (numarRaspunse < numarEnunturi) { // afiseazaEnunt(Enunturi[numarRaspunse++].id); afiseazaEnunt(getID()); } else { DialogResult rez = MessageBox.Show("Doriti sa incheiati testul?", "Confirm", MessageBoxButtons.YesNoCancel); if (rez == DialogResult.Yes) { finalizareTest(); Close(); } } }; // afiseazaEnunt(Enunturi[numarRaspunse++].id); afiseazaEnunt(getID()); }