Exemple #1
0
        public void UpdateDiem(Diem d)
        {
            string query = "UPDATE diem SET idsinhvien = '" + d.idsinhvien + "', idkhoahoc = '" + d.idkhoahoc + "', chuyen_can = '" + d.chuyen_can + "', giua_ki = '" + d.giua_ki + "', cuoi_ki = '" + d.cuoi_ki + "', trung_binh = '" + d.trung_binh + "' WHERE id = '" + d.id + "';";

            //open connection
            if (this.OpenConnection() == true)
            {
                //create command and assign the query and connection from the constructor
                MySqlCommand cmd = new MySqlCommand(query, connection);

                //Execute command
                cmd.ExecuteNonQuery();

                //close connection

                    CloseConnection();
                update();
            }
        }
Exemple #2
0
        public void InsertDiem(Diem d)
        {
            string query = "INSERT INTO diem (idsinhvien, idkhoahoc, chuyen_can, giua_ki, cuoi_ki, trung_binh) VALUES('"
                                       + d.idsinhvien + "','" + d.idkhoahoc + "','" + d.chuyen_can + "','" + d.giua_ki + "','" + d.cuoi_ki + "','" + d.trung_binh + "')";

            //open connection
            if (this.OpenConnection() == true)
            {
                //create command and assign the query and connection from the constructor
                MySqlCommand cmd = new MySqlCommand(query, connection);

                //Execute command
                cmd.ExecuteNonQuery();

                //close connection

                    CloseConnection();
                update();
            }
        }
Exemple #3
0
        public void DeleteDiem(Diem d)
        {
            string query = "DELETE FROM diem WHERE id='" + d.id.ToString() + "';";

            if (this.OpenConnection() == true)
            {
                try
                {
                    MySqlCommand cmd = new MySqlCommand(query, connection);
                    cmd.ExecuteNonQuery();

                }
                catch (MySqlException ex)
                {
                }
                finally
                {
                        CloseConnection();
                }
                update();
            }
        }
        public void Readhanle()
        {
            string str;

            try
            {
                while ((str = reader.ReadLine()) != null)
                {
                    Console.WriteLine(str);
                    string[] data = Regex.Split(str, "#@#");
                    if (data[0].Equals("Bang"))
                    {
                        if (data[1].Equals("Khoahoc"))
                        {
                            listKhoahoc(data[2]);
                        }
                        else if (data[1].Equals("Danghoc"))
                        {
                            listDanghoc(data[2]);
                        }
                        else if (data[1].Equals("Dahoc"))
                        {
                            listDahoc(data[2]);
                        }
                        else if (data[1].Equals("Dangki"))
                        {
                            listDangki(data[2]);
                        }
                        else if (data[1].Equals("Sinhvien"))
                        {
                            listSinhvien(data[2], data[3]);
                        }
                        else if (data[1].Equals("Diem"))
                        {
                            listDiem(data[2]);
                        }
                    }
                    else if (data[0].Equals("Dangky"))
                    {
                        int idkh = int.Parse(data[1]);
                        Console.WriteLine(sql.SelectDiem(sinhvien.id, idkh).Count);
                        if (sql.SelectDiem(sinhvien.id, idkh).Count > 0)
                        {
                            sql.DeleteDiem(sql.SelectDiem(sinhvien.id, idkh)[0]);
                            foreach (Khoahoc kh in sinhvien.dang_ki)
                            {
                                if (kh.id == idkh)
                                {
                                    if (kh.danh_sach.Count() < kh.max_danhsach)
                                    {
                                        kh.trang_thai = "OPEN";
                                    }
                                    sinhvien.dang_ki.Remove(kh);
                                    sql.UpdateSinhvien(sinhvien);
                                    kh.danh_sach.Remove(sinhvien);
                                    sql.UpdateKhoahoc(kh);
                                }
                            }
                        }
                        else
                        {
                            foreach (Khoahoc kh in sql.SearchKhoahoc(""))
                            {
                                if (kh.id == idkh && kh.trang_thai.Equals("OPEN"))
                                {
                                    Diem diem = new Diem(sinhvien.id, kh.id, 0, 0, 0, 0);
                                    sql.InsertDiem(diem);
                                    Console.WriteLine("**");
                                    kh.danh_sach.Add(sinhvien);
                                    if (kh.danh_sach.Count() >= kh.max_danhsach)
                                    {
                                        kh.trang_thai = "CLOSE";
                                    }
                                    sql.UpdateKhoahoc(kh);
                                    sinhvien.dang_ki.Add(kh);
                                    sql.UpdateSinhvien(sinhvien);
                                }
                            }
                        }
                        listKhoahoc(data[2]);
                        updatesv();
                    }
                    else if (data[0].Equals("Login"))
                    {
                        bool t = false;
                        foreach (Sinhvien sv in sql.SearchSinhvien(""))
                        {
                            if (int.Parse(data[1]) == sv.id && sv.password.Equals(data[2]))
                            {
                                sinhvien = sv;
                                listKhoahoc("");
                                t = true;
                            }
                        }
                        if (t == false)
                        {
                            send("LoginFail");
                            throw new Exception();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                writer.Close();
                reader.Close();
                stream.Close();
                Console.WriteLine(ex);
                Clientclose();
            }
        }