private void Load_Click(object sender, RoutedEventArgs e) { datgr.IsEnabled = true; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.ShowDialog(); dbname = dlg.FileName; SQLiteConnection m_dbConnection; m_dbConnection = new SQLiteConnection("Data Source=" + dbname + ";Version=3;"); m_dbConnection.Open(); string sql = "SELECT * FROM student, info WHERE student.unicid = info.unicid"; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { SStudent stud = new SStudent(); stud.Fio = reader["fio"].ToString(); stud.Unicid = int.Parse(reader["unicid"].ToString()); stud.Math = int.Parse(reader["math"].ToString()); stud.Phys = int.Parse(reader["phys"].ToString()); slist.Add(stud); } datgr.ItemsSource = slist; datgr.Items.Refresh(); m_dbConnection.Close(); }
static void Main(string[] args) { SStudent s1 = new SStudent(); s1.Id = 21; s1.Name = "shohag"; Console.WriteLine("student1 id={0}", s1.Id); Console.WriteLine("student1 name={0}", s1.Name); Console.WriteLine("student1 passmark={0}", s1.Passmark); }
static void Main(string[] args) { SStudent[] students = new SStudent[10]; Random rnd = new Random(); int n; for (int i = 0; i < 10; i++) { students[i].fio = ("Sname" + i ); students[i].phys = rnd.Next(2, 6); students[i].math = rnd.Next(2, 6); } n = int.Parse(Console.ReadLine()); switch (n) { case 1: { list(ref students); break; } case 2: { goodmark(ref students); break; } case 3: { onebad(students); break; } default: { Console.WriteLine("Error"); break; } } Console.ReadKey(); }
private void Add_Click(object sender, RoutedEventArgs e) { if (dbname != "" && unicidbox.Text != "" && mathbox.Text != "" && namebox.Text != "" && physbox.Text != "") { SQLiteConnection m_dbConnection; m_dbConnection = new SQLiteConnection("Data Source=" + dbname + ";Version=3;"); m_dbConnection.Open(); string sql4 = "SELECT unicid FROM student"; SQLiteCommand command = new SQLiteCommand(sql4, m_dbConnection); command.ExecuteNonQuery(); try { string sql = "INSERT INTO student (unicid, fio) VALUES (" + unicidbox.Text + ",'" + namebox.Text + "')"; command = new SQLiteCommand(sql, m_dbConnection); command.ExecuteNonQuery(); string sql2 = "INSERT INTO info (unicid, math, phys) VALUES (" + unicidbox.Text + "," + mathbox.Text + "," + physbox.Text + ")"; command = new SQLiteCommand(sql2, m_dbConnection); command.ExecuteNonQuery(); SStudent stud = new SStudent(); stud.Fio = namebox.Text; stud.Unicid = int.Parse(unicidbox.Text); stud.Math = int.Parse(mathbox.Text); stud.Phys = int.Parse(physbox.Text); slist.Add(stud); datgr.ItemsSource = null; datgr.ItemsSource = slist; datgr.Items.Refresh(); m_dbConnection.Close(); } catch (Exception) { MessageBox.Show("Error: Invalid ID"); }; } else { if (unicidbox.Text == "") { MessageBox.Show("Incorrect value of ID"); } else if (namebox.Text == "") { MessageBox.Show("Incorrect Name"); } else if (mathbox.Text == "") { MessageBox.Show("Incorrect value of Math"); } else if (physbox.Text == "") { MessageBox.Show("Incorrect value of Phys"); } } }