Beispiel #1
0
        static void Main(string[] args)
        {

            Console.WriteLine("Insert name, surname, GPA and your ID pls: ", "\n");
            int k = 0;
            Student[] information = new Student[100];
            
            while(1==1)
            {
                try
                {
                    string token = Console.ReadLine();
                    string[] info = token.Split(' ');
                    information[k] = new Student(info[0], info[1], double.Parse(info[2]), info[3]);
                    Console.WriteLine("If you want add one more student press Enter, if you dont want press escape");
                    ConsoleKeyInfo button = Console.ReadKey();
                    if (button.Key == ConsoleKey.Enter)
                    {
                        Console.WriteLine("Enter new information");
                        k++;
                    }
                    else
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadKey();
                }


            }
            Console.WriteLine("If you want whole list at all press 1 If you want to see only gpa press 2");
            ConsoleKeyInfo button1 = Console.ReadKey();
    
            if (button1.Key == ConsoleKey.NumPad1)
            {
                for (int i = 0; i <= k; i++)
                {
                    Console.WriteLine(information[i]);

                }
            }
                else if (button1.Key == ConsoleKey.NumPad2)
             {
                for (int i = 0; i <= k; i++)
                {
                    
                    Console.WriteLine( " ID: {0} GPA: {1}",information[i].ID,information[i].gpa);

                }
            }
            
            Console.ReadKey();
        }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();

            string query = "SELECT * FROM student";
            MySqlConnection myConnection = new MySqlConnection("server=localhost;user=root;password=root;database=xhz1;port=3306;");
            //MySqlCommand myCommand = new MySqlCommand(query, myConnection);
            //myConnection.Open();
            DataSet ds = MySqlHelper.ExecuteDataset(myConnection, query);
            //MySqlDataReader myDataReader = myCommand.ExecuteReader();

            //获取图片
            Image img = new Image();

            //新建一个student集合
            List<Student> StudentList = new List<Student>();
            foreach (DataTable dt in ds.Tables)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    byte[] by = (byte[])dr["image"];
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(by);
                    //System.IO.Stream ss =  System.IO.Stream;
                    //ms.CopyTo(ss);
                    System.Drawing.Image imgg = System.Drawing.Image.FromStream(ms,true);
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(imgg);
                    IntPtr hb = bmp.GetHbitmap();
                    System.Windows.Media.ImageSource wpfbitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hb, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    img.Source = wpfbitmap;
                    System.Windows.Media.ImageSource wpftooltip = wpfbitmap;
                    Student stu = new Student(dr["name"].ToString(), dr["number"].ToString(), wpfbitmap, wpftooltip);
                    StudentList.Add(stu);
                }
            }

            //新建一个student集合
            //List<Student> StudentList = null;
            //while (myDataReader.Read() == true)
            //{
            //    Student stu = new Student(myDataReader["name"].ToString(),myDataReader["number"].ToString());
            //    StudentList.Add(stu);
            //}
            //myDataReader.Close();
            myConnection.Close();

            this.student.ItemsSource = StudentList;
        }