예제 #1
0
        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            //them lop vao treeview
            this.Dispose();
            frmThemSinhVien frm = new frmThemSinhVien();

            frm.ShowDialog();
        }
예제 #2
0
        private void thêmSinhViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmThemSinhVien frm = new frmThemSinhVien();

            frm.ShowDialog();
        }
예제 #3
0
        private void thêmSinhViênToolStripMenuItem_Click(object sender, EventArgs e)
        {
            connect = cn.getConnect();
            connect.Open();
            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.Text;
            command.Connection  = connect;
            string   tmp     = "";
            TreeNode theNode = this.TvDanhSachLop.SelectedNode;

            if (theNode.Tag == "1")
            {
                string    str = "select MaLop,TenLop from Lop where TenLop= N'" + theNode.Text + "'";
                DataTable tb  = cn.getTable(str);
                // frm.txtLop.Text = tb.Rows[0]["TenLop"].ToString();
                // frm.txtLop.Enabled = false;

                // string text = tb.Rows[0]["TenLop"].ToString();
                do
                {
                    connect = cn.getConnect();
                    connect.Open();
                    frmThemSinhVien frm = new frmThemSinhVien(theNode.Text);
                    frm.Text = "Thêm sinh viên vào lớp " + theNode.Text;

                    frm.ShowDialog();

                    if (frm.DialogResult == DialogResult.OK)
                    {
                        sql = " insert into SinhVien values(@ma,@hoten,@malop,@ngay,@gt,@image,@nghi)";
                        SqlCommand cmd = new SqlCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.Connection  = connect;
                        cmd.CommandText = sql;

                        MemoryStream stream  = new MemoryStream();
                        int          width1  = Convert.ToInt32(frm.imgTrain.Width);
                        int          height1 = Convert.ToInt32(frm.imgTrain.Height);
                        int          width   = 148;
                        int          height  = 161;
                        Bitmap       bmp     = new Bitmap(width, height);
                        frm.imgTrain.DrawToBitmap(bmp, new Rectangle(0, 0, Width, Height));
                        bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        byte[] pic = stream.ToArray();

                        cmd.Parameters.Add("@ma", SqlDbType.Char).Value        = frm.txtMaSV.Text;
                        cmd.Parameters.Add("@hoten", SqlDbType.NVarChar).Value = frm.txtHoTen.Text;
                        cmd.Parameters.Add("@ngay ", SqlDbType.Date).Value     = Convert.ToDateTime(frm.txtNgaySinh.Text, new CultureInfo("vi-VN")).Date;
                        cmd.Parameters.Add("@gt", SqlDbType.NVarChar).Value    = frm.radNam.Checked == true ? "Nam" : "Nữ";
                        cmd.Parameters.Add("@malop", SqlDbType.NVarChar).Value = tb.Rows[0]["MaLop"];
                        cmd.Parameters.Add("@image", SqlDbType.Image).Value    = pic;
                        cmd.Parameters.Add("@nghi", SqlDbType.Int).Value       = 0;
                        int ret = -1;
                        try
                        {
                            ret = cmd.ExecuteNonQuery();
                            dataGridView1.DataSource = null;
                            // kiểm tra lớp đã điểm danh buổi nào hay chưa
                            // nếu chưa điểm danh=> chỉ thêm vào bảng SinhVien
                            // nếu lớp đã điểm danh => thêm vào bảng SinhVien và bảng DH_SV_LCN
                            // chèn vào table DH_SV_LCN
                            sql = "select* from DH_SV_LCN where MaLop='" + tb.Rows[0]["MaLop"] + "' and MaSV ='" + frm.txtMaSV.Text + "'";
                            SqlDataAdapter da  = new SqlDataAdapter(sql, connect);
                            DataTable      tb1 = new DataTable();
                            da.Fill(tb1);

                            // if (tb1.Rows.Count==0)
                            int days = MaxDate(tb.Rows[0]["MaLop"].ToString(), 1);
                            if (days > 0)
                            {
                                sql = "insert into DH_SV_LCN values(@malop,@masv,@ngay,@nghi)";
                                SqlCommand cmd2 = new SqlCommand();
                                cmd2.CommandType = CommandType.Text;
                                cmd2.Connection  = connect;
                                cmd2.CommandText = sql;
                                cmd2.Parameters.Add("@malop", SqlDbType.Char).Value = tb.Rows[0]["MaLop"];
                                cmd2.Parameters.Add("@masv", SqlDbType.Char).Value  = frm.txtMaSV.Text;
                                cmd2.Parameters.Add("@ngay", SqlDbType.Date).Value  = DateTime.Now;
                                cmd2.Parameters.Add("@nghi", SqlDbType.Int).Value   = days;
                                try
                                {
                                    cmd2.ExecuteNonQuery();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                            }
                            showListSV();
                            frm.clear();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            // MessageBox.Show("Sinh viên đã tồn tại!");
                        }
                    }

                    if (frm.DialogResult == DialogResult.Cancel)
                    {
                        break;
                    }
                } while (true);
            }
            else
            if (theNode.Tag == "2")
            {
                connect = cn.getConnect();
                connect.Open();
                string         sql = "select MaLop,TenLop from LopHocPhan where TenLop= N'" + theNode.Text + "'";
                DataTable      tb  = new DataTable();// cn.getTable(str);
                SqlDataAdapter da  = new SqlDataAdapter(sql, connect);
                da.Fill(tb);
                string text = tb.Rows[0]["MaLop"].ToString();
                do
                {
                    connect = cn.getConnect();
                    connect.Open();
                    frmThemSinhVienLHP frm = new frmThemSinhVienLHP(text); // truyen vao ma lop
                    frm.Text = "Thêm sinh viên vào lớp " + tb.Rows[0]["TenLop"].ToString();
                    frm.ShowDialog();
                    // frm.add();
                    if (frm.DialogResult == DialogResult.OK)
                    {
                        //nhap vap lop
                        sql = " insert into SV_LHP values(@malop,@masv)";
                        SqlCommand cmd = new SqlCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.Connection  = connect;
                        cmd.CommandText = sql;
                        cmd.CommandText = sql;
                        cmd.Parameters.Add("@malop", SqlDbType.Char).Value = tb.Rows[0]["MaLop"].ToString();
                        cmd.Parameters.Add("@masv", SqlDbType.Char).Value  = frm.txtMaSV.Text;


                        try
                        {
                            cmd.ExecuteNonQuery();
                            dataGridView1.DataSource = null;
                            // nhap vao table diem danh
                            sql = "select* from DH_SV_LHP where MaLop='" + tb.Rows[0]["MaLop"] + "' and MaSV ='" + frm.txtMaSV.Text + "'";
                            SqlDataAdapter da1 = new SqlDataAdapter(sql, connect);
                            DataTable      tb1 = new DataTable();
                            da1.Fill(tb1);
                            int days = MaxDate(tb.Rows[0]["MaLop"].ToString(), 2);
                            if (days > 0)
                            {
                                SqlCommand cmd2 = new SqlCommand();
                                cmd2.CommandType = CommandType.Text;
                                cmd2.Connection  = connect;
                                sql = "insert into DH_SV_LHP values(@malop,@masv,@ngay,@nghi)";
                                cmd2.CommandText = sql;
                                cmd2.Parameters.Add("@malop", SqlDbType.Char).Value = tb.Rows[0]["MaLop"];
                                cmd2.Parameters.Add("@masv", SqlDbType.Char).Value  = frm.txtMaSV.Text;
                                cmd2.Parameters.Add("@ngay", SqlDbType.Date).Value  = DateTime.Now;
                                cmd2.Parameters.Add("@nghi", SqlDbType.Int).Value   = days;
                                try
                                {
                                    cmd2.ExecuteNonQuery();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                            }

                            showListSV();
                            frm.clear();
                            frm.txtMaSV.Text = "";
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            //  MessageBox.Show("Sinh viên đã tồn tại!");
                        }
                    }
                    if (frm.DialogResult == DialogResult.Cancel)
                    {
                        break;
                    }
                } while (true);
                connect.Close();
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn lớp cần thêm sinh viên!", "Thông báo");
                return;
            }
        }