Esempio n. 1
0
        public void TestPopulateDatabase(IApplicantDatabase appDatabase)
        {
            Applicant applicant1 = new Applicant("1910541231783", "Adrian", "Botez", 8, 8.75, 6, 7.75, 0.0);

            Applicant applicant2 = new Applicant("2342184593201", "Victor", "Rachieru", 7, 4.75, 4, 4.5, 0.0);

            Applicant applicant3 = new Applicant("1314541890188", "Marius", "Zavincu", 8, 9.75, 10, 6.75, 0.0);

            appDatabase.InsertRecord(applicant1);
            appDatabase.InsertRecord(applicant2);
            appDatabase.InsertRecord(applicant3);
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            decimal myDec;

            if (string.IsNullOrWhiteSpace(firstname.Text) ||
                string.IsNullOrWhiteSpace(lastname.Text) ||
                string.IsNullOrWhiteSpace(badgeNo.Text) ||
                string.IsNullOrWhiteSpace(bacGrade.Text) ||
                string.IsNullOrWhiteSpace(csGrade.Text) ||
                string.IsNullOrWhiteSpace(mathGrade.Text)
                )
            {
                MessageBox.Show("All fields must be field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (!decimal.TryParse(bacGrade.Text, out myDec))
            {
                MessageBox.Show("Baccalaureat grade must be a decimal.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (!decimal.TryParse(csGrade.Text, out myDec))
            {
                MessageBox.Show("Computer Science grade must be a decimal.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (!decimal.TryParse(mathGrade.Text, out myDec))
            {
                MessageBox.Show("Mathematics grade must be a decimal.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                string surname  = firstname.Text;
                string name     = lastname.Text;
                string cnp      = badgeNo.Text;
                string notaBac  = bacGrade.Text;
                string notaInfo = csGrade.Text;
                string notaMate = mathGrade.Text;
                string notaTest = testGrade.Text;
                Debug.Assert(Convert.ToInt32(bacGrade) <= 10, "Nota trebuie sa fie intre 5 si 10");
                Debug.Assert(Convert.ToInt32(bacGrade) > 5, "Nota trebuie sa fie intre 5 si 10");
                Debug.Assert(Convert.ToInt32(csGrade) <= 10, "Nota trebuie sa fie intre 5 si 10");
                Debug.Assert(Convert.ToInt32(csGrade) > 5, "Nota trebuie sa fie intre 5 si 10");
                Debug.Assert(Convert.ToInt32(mathGrade) <= 10, "Nota trebuie sa fie intre 5 si 10");
                Debug.Assert(Convert.ToInt32(mathGrade) > 5, "Nota trebuie sa fie intre 5 si 10");
                Debug.Assert(Convert.ToInt32(testGrade) <= 10, "Nota trebuie sa fie intre 5 si 10");
                Debug.Assert(Convert.ToInt32(testGrade) > 5, "Nota trebuie sa fie intre 5 si 10");
                Debug.Assert(Regex.IsMatch(firstname.Text, @"^[a-zA-Z]+$"), "Acest camp trebuie sa contina doar litere");
                Debug.Assert(Regex.IsMatch(lastname.Text, @"^[a-zA-Z]+$"), "Acest camp trebuie sa contina doar litere");
                Debug.Assert(Regex.IsMatch(firstname.Text, @"^[a-zA-Z]+$"), "Acest camp trebuie sa contina doar litere");
                Debug.Assert(Regex.IsMatch(badgeNo.Text, @"^[a-zA-Z0-9]+$"), "Acest camp trebuie sa contina doar litere si cifre");
                this.Hide();
                Applicant applicant = new Applicant(cnp, surname, name, Double.Parse(notaTest), Double.Parse(notaBac), Double.Parse(notaInfo), Double.Parse(notaMate), 0.0);
                Debug.Assert(applicant != null);
                appDatabase.InsertRecord(applicant);
                MessageBox.Show("Success!");
            }
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();

            fd.Filter = "txt files (*.txt)|*.txt";
            Stream myStream = null;

            if (fd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = fd.OpenFile()) != null)
                    {
                        using (StreamReader sr = new StreamReader(myStream))
                        {
                            String   line           = sr.ReadLine();
                            char[]   delimiterChars = { ',' };
                            string[] words          = line.Split(delimiterChars);
                            Console.Write(words.Length);
                            Debug.Assert(words.Length != 7, "numarul de atribute trebuie sa fie = 7");
                            if (words.Length == 7)
                            {
                                Debug.Assert(Convert.ToInt32(words[3]) <= 10, "Nota trebuie sa fie intre 5 si 10");
                                Debug.Assert(Convert.ToInt32(words[3]) > 5, "Nota trebuie sa fie intre 5 si 10");
                                Debug.Assert(Convert.ToInt32(words[4]) <= 10, "Nota trebuie sa fie intre 5 si 10");
                                Debug.Assert(Convert.ToInt32(words[4]) > 5, "Nota trebuie sa fie intre 5 si 10");
                                Debug.Assert(Convert.ToInt32(words[5]) <= 10, "Nota trebuie sa fie intre 5 si 10");
                                Debug.Assert(Convert.ToInt32(words[5]) > 5, "Nota trebuie sa fie intre 5 si 10");
                                Debug.Assert(Convert.ToInt32(words[6]) <= 10, "Nota trebuie sa fie intre 5 si 10");
                                Debug.Assert(Convert.ToInt32(words[6]) > 5, "Nota trebuie sa fie intre 5 si 10");
                                Debug.Assert(Regex.IsMatch(words[0], @"^[a-zA-Z]+$"), "Acest camp trebuie sa contina doar litere");
                                Debug.Assert(Regex.IsMatch(words[1], @"^[a-zA-Z]+$"), "Acest camp trebuie sa contina doar litere");

                                Debug.Assert(Regex.IsMatch(words[2], @"^[a-zA-Z0-9]+$"), "Acest camp trebuie sa contina doar litere si cifre");
                                Applicant app = new Applicant(words[0], words[1], words[2], Double.Parse(words[3]), Double.Parse(words[4]), Double.Parse(words[5]), Double.Parse(words[6]), 0.0);
                                appDatabase.InsertRecord(app);
                                MessageBox.Show("Success!");
                            }
                            else
                            {
                                MessageBox.Show("Bad file format");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }