Exemplo n.º 1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            MY_DB      mydb = new MY_DB();
            User       user = new User();
            SqlCommand cmd  = new SqlCommand("SELECT user_id, fname, lname, birthdate, gender, phone, address, picture, selected_courses FROM listUser WHERE user_id=@id", mydb.getConnection);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(idBox.Text);
            SqlDataAdapter adpt  = new SqlDataAdapter();
            DataTable      table = new DataTable();

            adpt.SelectCommand = cmd;
            adpt.Fill(table);

            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < selectedCourseListBox.Items.Count; i++)
                {
                    int courseID = course.getCourseId(selectedCourseListBox.Items[i].ToString());
                    if (user.addCourse(Convert.ToInt32(idBox.Text), courseID, 0, ""))
                    {
                        MessageBox.Show("Saved " + selectedCourseListBox.Items[i].ToString());
                    }
                }
                selectedCourseListBox.Items.Clear();
                mydb.closeConnection();
            }
            else
            {
                MessageBox.Show("This ID is not available!!!", "Error");
                mydb.closeConnection();
            }
            if (user.selectedCourse(Convert.ToInt32(idBox.Text)))
            {
            }
        }
Exemplo n.º 2
0
        private void staticResult_Load(object sender, EventArgs e)
        {
            Result         result = new Result();
            MY_DB          mydb   = new MY_DB();
            SqlCommand     cmd    = new SqlCommand("SELECT label, avg_grade FROM course", mydb.getConnection);
            SqlDataAdapter adpt   = new SqlDataAdapter(cmd);
            DataTable      table  = new DataTable();

            adpt.Fill(table);
            int locationX = 39;
            int locationY = 141;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                Label course = new Label();
                course.Text      = table.Rows[i][0].ToString() + ": " + table.Rows[i][1].ToString();
                course.Font      = new Font("Microsoft Sans Serif", 20);
                course.ForeColor = Color.White;
                course.Location  = new Point(locationX, locationY);
                locationY       += 40;
                course.Size      = new Size(400, 40);
                Controls.Add(course);
            }

            passLabel.Text += " " + result.getPassPercent() + "%";
            failLabel.Text += " " + (100 - result.getPassPercent()) + "%";
        }
Exemplo n.º 3
0
        private void btnDelNV_Click(object sender, EventArgs e)
        {
            DialogResult traloi;

            traloi = MessageBox.Show("Bạn thực sự muốn xóa?", "Trả lời", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (traloi == DialogResult.OK)
            {
                MY_DB mydb = new MY_DB();
                mydb.openConnection();
                SqlTransaction objTrans = null;
                using (SqlConnection objConn = mydb.getConnection)
                {
                    objTrans = objConn.BeginTransaction();
                    SqlCommand dlDV = new SqlCommand("update DatVe set MaNV=NULL where MaNV=" + txtMaNV.Text, mydb.getConnection, objTrans);
                    SqlCommand dlDN = new SqlCommand("delete from DangNhap where MaNV=" + txtMaNV.Text, mydb.getConnection, objTrans);
                    SqlCommand dlNV = new SqlCommand("delete from NhanVien where MaNV=" + txtMaNV.Text, mydb.getConnection, objTrans);
                    try
                    {
                        dlDV.ExecuteNonQuery();
                        dlDN.ExecuteNonQuery();
                        dlNV.ExecuteNonQuery();

                        objTrans.Commit();
                        MessageBox.Show("Da xoa nhan vien" + txtMaNV.Text);
                    }
                    catch (Exception ex)
                    {
                        objTrans.Rollback();
                        MessageBox.Show(ex.Message);
                    }
                    mydb.closeConnection();
                }
            }
        }
Exemplo n.º 4
0
        private void btXeMay_Click(object sender, EventArgs e)
        {
            pictureBoxVienOto.Visible   = false;
            pictureBoxVienXeDap.Visible = false;
            pictureBoxVienXeMay.Visible = true;
            Oto.Checked    = false;
            XeMay.Checked  = true;
            XeDap.Checked  = false;
            txtGioGui.Text = DateTime.Now.ToString("HH:mm:ss");
            if (btXeMayTrong.Text != "0")
            {
                MY_DB          db      = new MY_DB();
                KhachHang      student = new KhachHang();
                SqlDataAdapter da      = new SqlDataAdapter();
                DataTable      dt      = new DataTable();
                SqlCommand     cmd     = new SqlCommand("select * from BAIXE", db.getConnection);
                da.SelectCommand = cmd;
                da.Fill(dt);
                bool kt = false;
                int  i = 0, j = 4;

                while (j < 8 && kt == false)
                {
                    while (i < dt.Rows.Count && kt == false)
                    {
                        if (dt.Rows[i][j].ToString() == "0")
                        {
                            switch (j)
                            {
                            case 4:
                                btKhuVuc.Text = "D." + (i + 1);
                                kt            = true;
                                break;

                            case 5:
                                btKhuVuc.Text = "E." + (i + 1);
                                kt            = true;
                                break;

                            case 6:
                                btKhuVuc.Text = "F." + (i + 1);
                                kt            = true;
                                break;

                            case 7:
                                btKhuVuc.Text = "G." + (i + 1);
                                kt            = true;
                                break;
                            }
                        }
                        i++;
                    }
                    j++;
                }
            }
            else
            {
                MessageBox.Show("Đã hết chỗ trống");
            }
        }
Exemplo n.º 5
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            int    r     = dgv_HopDong.CurrentCell.RowIndex;
            string strHD = dgv_HopDong.Rows[r].Cells[0].Value.ToString();

            DialogResult traloi;

            traloi = MessageBox.Show("Bạn thực sự muốn xóa?", "Trả lời", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (traloi == DialogResult.OK)
            {
                MY_DB mydb = new MY_DB();
                mydb.openConnection();
                SqlTransaction objTrans = null;
                using (SqlConnection objConn = mydb.getConnection)
                {
                    objTrans = objConn.BeginTransaction();
                    SqlCommand dlHSX = new SqlCommand($"update HangSanXuat set MaHD=NULL  where MaHD=N'{txtMaHD.Text.Trim()}'", mydb.getConnection, objTrans);
                    SqlCommand dlPHD = new SqlCommand($"delete from PhimHopDong where MaHD=  N'{txtMaHD.Text.Trim()}'", mydb.getConnection, objTrans);
                    try
                    {
                        dlHSX.ExecuteNonQuery();
                        dlPHD.ExecuteNonQuery();
                        objTrans.Commit();
                        MessageBox.Show("Da xoa hop dong" + txtMaHD.Text);
                    }
                    catch (Exception ex)
                    {
                        objTrans.Rollback();
                        MessageBox.Show(ex.Message);
                    }
                    mydb.closeConnection();
                }
            }
        }
Exemplo n.º 6
0
        private void buttonAddMember_Click(object sender, EventArgs e)
        {
            MY_DB          db      = new MY_DB();
            SqlDataAdapter adapter = new SqlDataAdapter();

            System.Data.DataTable table   = new System.Data.DataTable();
            SqlCommand            command = new SqlCommand("Select * From Member WHERE @ID= Id", db.getConnection);

            command.Parameters.Add("@ID", SqlDbType.VarChar).Value = txtId.Text;
            adapter.SelectCommand = command;
            adapter.Fill(table);
            if ((table.Rows.Count) > 0)
            {
                MessageBox.Show("Trùng ID rồi!!!", " Nhập lại ID.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string   id       = txtId.Text;
                string   fname    = txtFirstname.Text;
                string   lname    = txtLastname.Text;
                DateTime bdate    = dateTimePicker1.Value;
                string   phone    = txtPhone.Text;
                string   adrs     = txtAddress.Text;
                string   gender   = "Male";
                string   username = (string)comboBox1.SelectedValue;
                if (radioButtonFemale.Checked)
                {
                    gender = "Female";
                }

                MemoryStream pic = new MemoryStream();

                if (verif())
                {
                    pictureBoxMember.Image.Save(pic, pictureBoxMember.Image.RawFormat);
                    if (AccountDAO.Instance.GetAccountByUserName(username) != null)
                    {
                        if (member.InsertMember(id, fname, lname, gender, bdate, adrs, phone, pic, username))
                        {
                            Refresh();
                            Clear();
                            MessageBox.Show("Thêm thành công");
                        }
                        else
                        {
                            MessageBox.Show("Error", "Add Member", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Sai tên tài khoản hoặc chưa tạo tài khoản!");
                    }
                }
                else
                {
                    MessageBox.Show("Empty Fields", "Add Member", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 7
0
        private void resetButton_Click(object sender, EventArgs e)
        {
            MY_DB      db  = new MY_DB();
            SqlCommand cmd = new SqlCommand("SELECT user_id, fname, lname, birthdate, gender, phone, address, picture, selected_courses FROM listUser", db.getConnection);

            listUserDataGrid.DataSource = user.userList();
            totalUserLabel.Text         = "Total User: " + user.getStudents(cmd).Rows.Count.ToString();
        }
Exemplo n.º 8
0
        public static int getInit()
        {
            MY_DB          mydb  = new MY_DB();
            SqlCommand     cmd   = new SqlCommand("SELECT init FROM initial", mydb.getConnection);
            SqlDataAdapter adpt  = new SqlDataAdapter(cmd);
            DataTable      table = new DataTable();

            adpt.Fill(table);

            return(Convert.ToInt32(table.Rows[0][0]));
        }
Exemplo n.º 9
0
        public static int getManagerFine()
        {
            MY_DB      mydb = new MY_DB();
            SqlCommand cmd  = new SqlCommand("SELECT pay_fines FROM manager_salary WHERE manager_id=@id", mydb.getConnection);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value = ManagerID;
            SqlDataAdapter adpt  = new SqlDataAdapter(cmd);
            DataTable      table = new DataTable();

            adpt.Fill(table);

            return(Convert.ToInt32(table.Rows[0][0]));
        }
Exemplo n.º 10
0
        private void ManageUser_Load(object sender, EventArgs e)
        {
            MY_DB      db  = new MY_DB();
            SqlCommand cmd = new SqlCommand("SELECT user_id, fname, lname, birthdate, gender, phone, address, picture, selected_courses FROM listUser", db.getConnection);

            listUserDataGrid.DataSource = user.userList();
            totalUserLabel.Text         = "Total User: " + user.getStudents(cmd).Rows.Count.ToString();
            DataGridViewImageColumn imgColumn = new DataGridViewImageColumn();

            imgColumn             = (DataGridViewImageColumn)listUserDataGrid.Columns[7];
            imgColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
            listUserDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
Exemplo n.º 11
0
        private void KTChoTrong()
        {
            MY_DB          db      = new MY_DB();
            KhachHang      student = new KhachHang();
            SqlDataAdapter da      = new SqlDataAdapter();
            DataTable      dt      = new DataTable();
            SqlCommand     cmd     = new SqlCommand("select * from BAIXE", db.getConnection);

            da.SelectCommand = cmd;
            da.Fill(dt);
            int countOto = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = 1; j < 4; j++)
                {
                    if (dt.Rows[i][j].ToString() == "1")
                    {
                        countOto++;
                    }
                }
            }
            int countXeMay = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = 4; j < 8; j++)
                {
                    if (dt.Rows[i][j].ToString() == "1")
                    {
                        countXeMay++;
                    }
                }
            }
            int countXeDap = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = 8; j < 10; j++)
                {
                    if (dt.Rows[i][j].ToString() == "1")
                    {
                        countXeDap++;
                    }
                }
            }
            txtOtoTrong.Text  = (60 - countOto).ToString();
            btXeDapTrong.Text = (60 - countXeDap).ToString();
            btXeMayTrong.Text = (60 - countXeMay).ToString();
        }
Exemplo n.º 12
0
        public static void setInitDatabase()
        {
            MY_DB      mydb = new MY_DB();
            SqlCommand cmd  = new SqlCommand("UPDATE initial SET init = @init", mydb.getConnection);

            cmd.Parameters.Add("@init", System.Data.SqlDbType.Int).Value = init;

            mydb.openConnection();

            if (cmd.ExecuteNonQuery() == 0)
            {
                mydb.closeConnection();
            }
            else
            {
                mydb.closeConnection();
            }
        }
Exemplo n.º 13
0
        private void AverageGrade_Load(object sender, EventArgs e)
        {
            MY_DB  mydb   = new MY_DB();
            Score  score  = new Score();
            Course course = new Course();

            SqlCommand     cmd   = new SqlCommand("SELECT course.label AS Course, CAST(AVG(score.student_score) AS FLOAT(2)) AS 'Avarage Score' FROM course, score WHERE course.id = score.course_id GROUP BY course.label", mydb.getConnection);
            DataTable      table = new DataTable();
            SqlDataAdapter adpt  = new SqlDataAdapter(cmd);

            adpt.Fill(table);

            if (course.avgGrade())
            {
            }

            avgGradeGrid.DataSource          = table;
            avgGradeGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
Exemplo n.º 14
0
        private void signUpButton_Click(object sender, EventArgs e)
        {
            MY_DB      db  = new MY_DB();
            SqlCommand cmd = new SqlCommand("INSERT INTO account (username, password, Id) VALUES (@username, @password, @id)", db.getConnection);

            cmd.Parameters.Add("@id", System.Data.SqlDbType.Int).Value           = Convert.ToInt32(IDBox.Text);
            cmd.Parameters.Add("@username", System.Data.SqlDbType.VarChar).Value = textBoxUser.Text;
            cmd.Parameters.Add("@password", System.Data.SqlDbType.VarChar).Value = textBoxPass.Text;
            db.openConnection();
            if (cmd.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("You Have Sign Up Successfully");
                db.closeConnection();
            }
            else
            {
                db.closeConnection();
            }
        }
        bool check_sys()
        {
            // Kiểm tra ID và User đã có trên hệ thống chưa
            MY_DB db = new MY_DB();

            SqlDataAdapter adapter  = new SqlDataAdapter();
            DataTable      table    = new DataTable();
            SqlCommand     commmand = new SqlCommand("SELECT * FROM dbo.users WHERE uid = @Id OR username = @Username", db.GetConnection);

            commmand.Parameters.Add("@Id", SqlDbType.Int).Value         = Convert.ToInt32(textBoxIDUser.Text);
            commmand.Parameters.Add("@Username", SqlDbType.NChar).Value = textBoxUsername.Text.Trim();
            adapter.SelectCommand = commmand;
            adapter.Fill(table);
            if (table.Rows.Count > 0)// Đã có id hoặc user trên hệ thống
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 16
0
        private void searchButton_Click(object sender, EventArgs e)
        {
            MY_DB db = new MY_DB();

            try
            {
                int        id  = Convert.ToInt32(enterIDBox.Text);
                SqlCommand cmd = new SqlCommand("SELECT user_id, fname, lname, birthdate, gender, phone, address, picture, selected_courses FROM listUser WHERE user_id = @id", db.getConnection);
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
                listUserDataGrid.DataSource = user.getStudents(cmd);

                IDBox.Text      = listUserDataGrid.CurrentRow.Cells[0].Value.ToString();
                fnameBox.Text   = listUserDataGrid.CurrentRow.Cells[1].Value.ToString();
                lnameBox.Text   = listUserDataGrid.CurrentRow.Cells[2].Value.ToString();
                birthDate.Value = (DateTime)listUserDataGrid.CurrentRow.Cells[3].Value;
                if (listUserDataGrid.CurrentRow.Cells[4].Value.ToString().Equals("Female"))
                {
                    femaleRadio.Checked = true;
                }
                else
                {
                    maleRadio.Checked = true;
                }
                phoneNumbBox.Text = listUserDataGrid.CurrentRow.Cells[5].Value.ToString();
                addressBox.Text   = listUserDataGrid.CurrentRow.Cells[6].Value.ToString();
                byte[] pic;
                pic = (byte[])listUserDataGrid.CurrentRow.Cells[7].Value;
                MemoryStream picture = new MemoryStream(pic);
                pictureBox.Image = Image.FromStream(picture);

                totalUserLabel.Text = "Total User: "******"SELECT user_id, fname, lname, birthdate, gender, phone, address, picture, selected_courses FROM listUser", db.getConnection);
                listUserDataGrid.DataSource = user.userList();
                totalUserLabel.Text         = "Total User: " + user.getStudents(cmd).Rows.Count.ToString();
            }
        }
Exemplo n.º 17
0
        private void availableCourseRefresh()
        {
            availableCourseListBox.Items.Clear();

            User  user = new User();
            MY_DB mydb = new MY_DB();

            SqlCommand cmd = new SqlCommand("SELECT * FROM course WHERE semester=@semester", mydb.getConnection);

            cmd.Parameters.Add("@semester", SqlDbType.Int).Value = semesterBox.Value;
            DataTable      allCourseTable = new DataTable();
            SqlDataAdapter adpt           = new SqlDataAdapter();

            adpt.SelectCommand = cmd;
            adpt.Fill(allCourseTable);

            DataTable selectedCourseTable = new DataTable();

            try
            {
                selectedCourseTable = user.getSelectedcourse(Convert.ToInt32(idBox.Text));
                for (int i = 0; i < allCourseTable.Rows.Count; i++)
                {
                    int count = 0;
                    //if Selected Course == All Course count increase
                    for (int j = 0; j < selectedCourseTable.Rows.Count; j++)
                    {
                        if (allCourseTable.Rows[i].ItemArray[0].ToString() == selectedCourseTable.Rows[j].ItemArray[0].ToString())
                        {
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        availableCourseListBox.Items.Add(allCourseTable.Rows[i].ItemArray[1].ToString());
                    }
                }
            } catch
            {
            }
        }
Exemplo n.º 18
0
        private void fAdmin_Load(object sender, EventArgs e)
        {
            MY_DB          myDB    = new MY_DB();
            SqlCommand     command = new SqlCommand("select Id, FirstName, LastName, Gender, BirthDate, Address, Phone , Picture, username  from Member", myDB.getConnection);
            SqlDataAdapter adap    = new SqlDataAdapter(command);

            System.Data.DataTable table = new System.Data.DataTable();
            adap.Fill(table);

            dataGridViewNhansu.DataSource = table;
            DataGridViewImageColumn picCol = new DataGridViewImageColumn();

            picCol             = (DataGridViewImageColumn)dataGridViewNhansu.Columns[7];
            picCol.ImageLayout = DataGridViewImageCellLayout.Stretch;
            dataGridViewNhansu.RowTemplate.Height = 60;

            comboBox1.DataSource    = AccountDAO.Instance.GetAccountNoMember();
            comboBox1.DisplayMember = "userName";
            comboBox1.ValueMember   = "userName";
            comboBox1.SelectedItem  = null;
        }
Exemplo n.º 19
0
        private void courseListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            MY_DB mydb = new MY_DB();

            try
            {
                SqlCommand cmd = new SqlCommand("SELECT * FROM course WHERE label = @label", mydb.getConnection);
                cmd.Parameters.Add("@label", SqlDbType.NVarChar).Value = courseListBox.SelectedItem.ToString();
                SqlDataAdapter adpt = new SqlDataAdapter();
                adpt.SelectCommand = cmd;
                DataTable table = new DataTable();
                adpt.Fill(table);
                IDBox.Text          = table.Rows[0].ItemArray[0].ToString();
                labelBox.Text       = table.Rows[0].ItemArray[1].ToString();
                periodNumb.Value    = Convert.ToInt32(table.Rows[0].ItemArray[2]);
                descriptionBox.Text = table.Rows[0].ItemArray[3].ToString();
                semesterBox.Value   = Convert.ToInt32(table.Rows[0].ItemArray[4]);
            } catch
            {
            }
        }
Exemplo n.º 20
0
        //Check xem xe gửi Loại Gì
        private void btOto_Click(object sender, EventArgs e)
        {
            Oto.Checked   = true;
            XeMay.Checked = false;
            XeDap.Checked = false;
            //SqlCommand cmd = new SqlCommand("select * from BAIXE");

            //baixe.dgvBaiXe.DataSource = kh.getCus(cmd);
            //for(int i = 0; i < 20;i++)
            //    for (int j = 0; i < 3; j ++ )
            //    {
            //        if (Convert.ToInt32(baixe.dgvBaiXe.Rows[i].Cells[j].Value) == 0)
            //            btKhuVuc.Text = ".....";
            //    }
            MY_DB          db      = new MY_DB();
            KhachHang      student = new KhachHang();
            SqlDataAdapter da      = new SqlDataAdapter();
            DataTable      dt      = new DataTable();
            SqlCommand     cmd     = new SqlCommand("select * from BAIXE", db.getConnection);

            //cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = txtUsername.Text;
            //cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = txtPassword.Text;
            da.SelectCommand = cmd;
            da.Fill(dt);

            int i = 0;

            while (i < dt.Rows.Count)
            {
                for (int j = 1; j < 4; j++)
                {
                    if (dt.Rows[i][j].ToString() == "0")
                    {
                        switch (j)
                        {
                        case 1:
                            btKhuVuc.Text = "A." + (i + 1);
                            i             = 30;
                            j             = 4;
                            break;

                        case 2:
                            btKhuVuc.Text = "B." + (i + 1);
                            j             = 4;
                            i             = 30;
                            break;

                        case 3:
                            btKhuVuc.Text = "C." + (i + 1);
                            j             = 4;
                            i             = 30;
                            break;
                        }
                    }
                }
                i++;
            }

            //if (txtUsername.Text == dt.Rows[i]["username"].ToString() && txtPassword.Text == dt.Rows[i]["password"].ToString())
            //this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 21
0
        private void button_Click(object sender, EventArgs e)
        {
            hideSubMenu();
            subjectSelected = (sender as Button).Text;
            int ID = id;

            textBoxSubject.Text = subjectSelected;
            if (logged_in)
            {
                try
                {
                    MY_DB   db      = new MY_DB();
                    Student student = new Student();
                    Count   count   = new Count();

                    MySqlDataAdapter adapter = new MySqlDataAdapter();

                    MySqlCommand command = new MySqlCommand("SELECT `nota`,`date`,`teza` FROM `grades` WHERE `elev`=@id AND `materie`=@mat");
                    command.Parameters.Add("@id", MySqlDbType.Int32).Value    = ID;
                    command.Parameters.Add("@mat", MySqlDbType.VarChar).Value = subjectSelected;
                    dataGridView1.ReadOnly = true;
                    DataGridViewImageColumn picCol = new DataGridViewImageColumn();
                    dataGridView1.RowTemplate.Height = 40;
                    dataGridView1.DataSource         = student.getStudents(command);
                    dataGridView1.AllowUserToAddRows = false;


                    string average = "SELECT AVG(nota) FROM `grades` WHERE `elev`='" + id + "' AND `materie`='" + subjectSelected + "' AND `teza`=false";
                    string result  = count.execCount(average);

                    string test    = "SELECT COUNT(*) FROM `grades` WHERE `elev`='" + id + "' AND `materie`='" + subjectSelected + "' AND `teza`=false";
                    string testare = count.execCount(test);
                    if (Convert.ToInt32(testare) == 0)
                    {
                        textBoxMedie.Text = "Note insuficiente";
                        textBoxNote.Text  = "0";
                    }
                    else
                    {
                        try
                        {
                            string cautaTeza  = "SELECT `nota` FROM `grades` WHERE `elev`='" + id + "' AND `materie`='" + subjectSelected + "' AND `teza`=true";
                            string TezaGasita = count.execCount(cautaTeza);
                            int    ValTeza    = Convert.ToInt32(TezaGasita);
                            test    = "SELECT COUNT(*) FROM `grades` WHERE `elev`='" + id + "' AND `materie`='" + subjectSelected + "' AND `teza`=true";
                            testare = count.execCount(test);
                            if (Convert.ToInt32(testare) > 1)
                            {
                                textBoxMedie.Text = "EROARE TEZE";
                            }
                            else if (Convert.ToInt32(testare) == 1)
                            {
                                double number = Convert.ToDouble(result);
                                number *= 3;
                                number += ValTeza;
                                number /= 4;

                                textBoxMedie.Text = number.ToString();
                                textBoxNote.Text  = count.totalGrades(subjectSelected, id.ToString());
                            }
                        }
                        catch
                        {
                            textBoxMedie.Text = result;
                            textBoxNote.Text  = count.totalGrades(subjectSelected, id.ToString());
                        }
                    }
                }
                catch
                {
                }
                try
                {
                    MY_DB   db      = new MY_DB();
                    Student student = new Student();

                    MySqlDataAdapter adapter = new MySqlDataAdapter();

                    MySqlCommand command = new MySqlCommand("SELECT `data`,`motivat` FROM `absente` WHERE `elev`=@id AND `materie`=@mat");
                    command.Parameters.Add("@id", MySqlDbType.Int32).Value    = ID;
                    command.Parameters.Add("@mat", MySqlDbType.VarChar).Value = subjectSelected;
                    dataGridView2.ReadOnly = true;
                    DataGridViewImageColumn picCol = new DataGridViewImageColumn();
                    dataGridView2.RowTemplate.Height = 40;
                    dataGridView2.DataSource         = student.getStudents(command);
                    dataGridView2.AllowUserToAddRows = false;
                }
                catch
                {
                }
            }
        }
Exemplo n.º 22
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = null;
            dataGridView2.DataSource = null;
            password            = textBoxPassword.Text;
            textBoxMedie.Text   = "";
            textBoxSubject.Text = "";
            textBoxNote.Text    = "";
            id = Convert.ToInt32(textBoxID.Text);

            MY_DB db = new MY_DB();

            MySqlDataAdapter adapter = new MySqlDataAdapter();
            DataTable        table   = new DataTable();
            MySqlCommand     command = new MySqlCommand("SELECT * FROM `student` INNER JOIN `users` ON student.id=users.id WHERE `users.id`= @id AND `users.password`= @pass", db.getConnection);

            command.Parameters.Add("@id", MySqlDbType.Int32).Value     = id;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = password;
            adapter.SelectCommand = command;
            try
            {
                adapter.Fill(table);
                if (table.Rows.Count > 0)
                {
                    logged_in = true;
                    //----------------------------Visible interface
                    dataGridView1.Visible   = true;
                    dataGridView2.Visible   = true;
                    textBoxSubject.Visible  = true;
                    panelSubject.Visible    = true;
                    panel3.Visible          = true;
                    textBoxMedie.Visible    = true;
                    label5.Visible          = true;
                    label4.Visible          = true;
                    textBoxNote.Visible     = true;
                    panel2.Visible          = false;
                    textBoxID.Visible       = false;
                    textBoxPassword.Visible = false;
                    label1.Visible          = false;
                    buttonLogin.Visible     = false;
                    labelID.Visible         = false;

                    string nume = table.Rows[0][1].ToString() + " " + table.Rows[0][2].ToString();
                    textBoxName.Text = nume;
                    textBoxClassroomLoggedIn.Text = "Clasa " + table.Rows[0]["clasa"].ToString();

                    byte[]       pic     = (byte[])table.Rows[0]["picture"];
                    MemoryStream picture = new MemoryStream(pic);
                    pictureBoxStudentImage.Image = Image.FromStream(picture);
                }
                else
                {
                    MessageBox.Show("ID sau parolă greșită.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    logged_in = false;
                    string nume = "Please login";
                    textBoxName.Text = nume;
                    textBoxClassroomLoggedIn.Text = "Classroom #";
                    textBoxID.Text               = "";
                    textBoxPassword.Text         = "";
                    pictureBoxStudentImage.Image = Properties.Resources.defaultAvatar;
                }
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                string temp = "Eroare! " + ex.Message.ToString();
                if (temp == "Eroare! Unable to connect to any of the specified MySQL hosts.")
                {
                    MessageBox.Show("Nu se poate face conexiunea la server!", "Eroare!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Eroare! " + ex.Message.ToString());
                }
                logged_in = false;
                string nume = "Please login";
                textBoxName.Text = nume;
            }
        }