Truyen2U.Net quay lại rồi đây! Các bạn truy cập Truyen2U.Com. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

asp.dkmh

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

using System.Security.Cryptography;

namespace Bton

{

    public partial class thigiuaki : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

        }

        public string GetMD5(string chuoi)

        {

            string str_md5 = "";

            byte[] mang = System.Text.Encoding.UTF8.GetBytes(chuoi);

            MD5CryptoServiceProvider my_md5 = new MD5CryptoServiceProvider();

            mang = my_md5.ComputeHash(mang);

            foreach (byte b in mang)

            {

                str_md5 += b.ToString("X2");

            }

            return str_md5;

        }

        protected void chkSelectAll_CheckedChanged

                              (object sender, EventArgs e)

        {

            CheckBox chkAll =

            (CheckBox)grimonhoc.HeaderRow.FindControl("chkSelectAll");

            if (chkAll.Checked == true)

            {

                foreach (GridViewRow gvRow in grimonhoc.Rows)

                {

                    CheckBox chkSel = (CheckBox)gvRow.FindControl("chkCheckItem");

                    chkSel.Checked = true;

                }

            }

            else

            {

                foreach (GridViewRow gvRow in grimonhoc.Rows)

                {

                    CheckBox chkSel = (CheckBox)gvRow.FindControl("chkCheckItem");

                    chkSel.Checked = false;

                }

            }

        }

        protected void btndangnhap_Click(object sender, EventArgs e)

        {

            SqlConnection cnn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\QLSV.mdf;Integrated Security=True;User Instance=True");

            cnn.Open();

            txtmahoa.Text = GetMD5(txtmatkhau.Text);

            SqlDataAdapter da = new SqlDataAdapter("Select * from NGUOIDUNG where TENDN = '" + txttendn.Text + "' AND MATKHAU = '" + txtmahoa.Text + "'",cnn);

            DataTable tb = new DataTable();

            da.Fill(tb);

            if (tb.Rows.Count > 0)

            {

                lblthongbao.Text = "Bạn đã đăng nhập thành công!";

                SqlCommand cmd = new SqlCommand("select * from SINHVIEN Where MASV ='" + txttendn.Text + "'", cnn);

                    SqlDataReader read;

                    read = cmd.ExecuteReader();

                     read.Read();

                    lbltensv.Text=read["MASV"].ToString();

                    lblgioitinh.Text=read["GIOITINH"].ToString();

                    lbldiachi.Text=read["DIACHI"].ToString();

                    lblngaysinh.Text=read["NGAYSINH"].ToString();

                    read.Close();

                    SqlCommand cm = new SqlCommand();

                    cm.Connection = cnn;

                    cm.CommandType = CommandType.Text;

                    cm.CommandText = "Select DIEMTBTL from DIEMTINCHI WHERE MASV = '" + txttendn.Text + "'";

                    float diem = (System.Int32)cm.ExecuteScalar();

                    lbldiemtbtichluy.Text = diem.ToString();

                    SqlDataAdapter ct = new SqlDataAdapter("SELECT * FROM MONHOCMOI", cnn);

                    DataSet ds = new DataSet();

                    //dataset ds = new dataset();

                    ct.Fill(ds);//đổ dữ liệu từ adapter vào dataset

                    //gridview gv= new gridview();

                    //da.Fill(ds, "MONHOC");

                    grimonhoc.DataSource = ds.Tables[0];

                    //gv.datasource=ds.table["MONHOC"]

                    grimonhoc.DataBind();

        }

            else

                lblthongbao.Text = "Đăng nhập thất bại!";

        }

        protected void btndangky_Click(object sender, EventArgs e)

        {

            double count = 0;

            float diemtl = float.Parse(lbldiemtbtichluy.Text);

            for (int i=0; i < grimonhoc.Rows.Count; i++)

            {

                GridViewRow row = grimonhoc.Rows[i];

                bool kt = ((CheckBox)grimonhoc.Rows[i].Cells[0].FindControl("chkCheckItem")).Checked;

                if (kt) count += double.Parse(row.Cells[4].Text);

                {

                    lblsotc.Text = count.ToString();

                }

            }

                if ((diemtl >= 2.5) && (count > 25))

                {

                    lblthongbaodk.Text = "Bạn đã đăng ký vượt quá số tín chỉ!";

                }

                else if ((diemtl >= 2.0) && (diemtl < 2.5) && (count > 20))

                {

                    lblthongbaodk.Text = "Bạn đã đăng ký vượt quá số tín chỉ!";

                }

                else if ((diemtl < 2.0) && (count > 14))

                {

                    lblthongbaodk.Text = "Bạn đã đăng ký vượt quá số tín chỉ!";

                }

                else

                {

                    lblthongbaodk.Text = "<li>" + "<B>" + "Đăng ký môn học thành công" + "</B>";

                }

            }

        }

    }

Bạn đang đọc truyện trên: Truyen2U.Com

Tags: