///////////////////do mình làm theo mô hình 3 lớp
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace QLSinhVienCNTT
{
class Connect
{
public string con()
{
try
{
string t="";
t = @"Data Source=.;Initial Catalog=QLSINHVIEN;Integrated Security=True";
return t;
}
catch(SqlException ex1)
{
throw new Exception("Kết nối CSDL thất bại " + ex1);
}
}
}
}
////////////////////////////////
Code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QLSinhVienCNTT
{
class ClssKetQua:Connect
{
protected SqlConnection conn;
public ClssKetQua()
{
string sql = con();
conn = new SqlConnection(sql);
conn.Open();
}
public DataTable GetKQ()
{
string sql = "Select * From KETQUA";
SqlDataAdapter da = new SqlDataAdapter(sql,conn);
DataTable bd = new DataTable();
da.Fill(bd);
conn.Close();
return bd;
}
}
}
/////////////////////////bạn vào form chitietsv viết dựa theo code này
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace QLSinhVienCNTT
{
public partial class QLXEL : Form
{
public QLXEL()
{
InitializeComponent();
sv = new ClssKetQua();
}
ClssKetQua sv = new ClssKetQua();
int vitri=0;
DataTable db = new DataTable();
private void btnThoatXL_Click(object sender, EventArgs e)
{
this.Close();
}
public void LoadData()
{
db = sv.GETDIEM();
DataRow r = db.Rows[vitri];
txttimkiem.Text = r[0].ToString() ;
txtDiemHthi.Text = r[1].ToString();
}
private void BindingText()
{
txttimkiem.DataBindings.Add("TEXT",dgvXL.DataSource,"MSSV");
txtDiemHthi.DataBindings.Add("TEXT", dgvXL.DataSource, "DIEM");
}
private void XoaBinding()
{
txttimkiem.DataBindings.Clear();
txtDiemHthi.DataBindings.Clear();
}
private void QLXEL_Move(object sender, EventArgs e)
{
this.SuspendLayout();
this.Location = new System.Drawing.Point(0, 0);
this.ResumeLayout();
}
private void btntimkiem_Click(object sender, EventArgs e)
{
ClssKetQua sv = new ClssKetQua();
DataTable db = sv.GetDMKQ(txttimkiem.Text);
if (db.Rows.Count > 0)
{
dgvXL.DataSource = db;
}
else
MessageBox.Show("Không có tồn tại sinh viên trên", "Thông Báo");
}
private void QLXEL_Load(object sender, EventArgs e)
{
txttimkiem.Focus();
ClssKetQua kq=new ClssKetQua ();
LoadData();
dgvXL.DataSource = kq.GETDIEM();
XoaBinding(); BindingText();
float a = float.Parse(txtDiemHthi.Text);
if (a >= 9)
{
label2.Text = "Xuất sắc";
}
else if (a >= 8)
{
label2.Text = "Giỏi";
}
else if (a >= 7)
{
label2.Text = "Khá";
}
else if (a >= 6)
{
label2.Text = "Trung Bình Khá";
}
else if (a >= 5)
{
label2.Text = "Trung Bình";
}
else if (a >= 4)
{
label2.Text = "Yếu";
}
else label2.Text = "Kém";
}
private void dgvXL_CellClick(object sender, DataGridViewCellEventArgs e)
{
float a = float.Parse(txtDiemHthi.Text);
if (a >=9)
{
label2.Text = "Xuất sắc";
}
else if (a >= 8 )
{
label2.Text = "Giỏi";
}
else if (a >= 7 )
{
label2.Text = "Khá";
}
else if (a >= 6 )
{
label2.Text = "Trung Bình Khá";
}
else if (a >= 5 )
{
label2.Text = "Trung Bình";
}
else if (a >= 4 )
{
label2.Text = "Yếu";
}
else label2.Text = "Kém";
}
}
}
////////////////////////////////////////////