public static bool KiemTraKhoiC(ThiSinh ts)
 {
     if (ts.diem.ContainsKey("Văn") && ts.diem.ContainsKey("Sử") && ts.diem.ContainsKey("Địa"))
     {
         return(true);
     }
     return(false);
 }
 public static bool KiemTraKhoiD(ThiSinh ts)
 {
     if (ts.diem.ContainsKey("Toán") && ts.diem.ContainsKey("Văn") && ts.diem.ContainsKey("Anh"))
     {
         return(true);
     }
     return(false);
 }
 public static bool KiemTraKhoiA(ThiSinh ts)
 {
     if (ts.diem.ContainsKey("Toán") && ts.diem.ContainsKey("Hóa") && ts.diem.ContainsKey("Lí"))
     {
         return(true);
     }
     return(false);
 }
Beispiel #4
0
        void DocFileExcel(string url)
        {
            Excel.Application xlApp       = new Excel.Application();
            Excel.Workbook    xlWorkbook  = xlApp.Workbooks.Open(url);
            Excel._Worksheet  xlWorksheet = xlWorkbook.Sheets[1];
            Excel.Range       xlRange     = xlWorksheet.UsedRange;
            int rowCount    = xlRange.Rows.Count;
            int columnCount = xlRange.Columns.Count;

            kt = new KyThi();
            for (int i = 2; i <= rowCount; i++)
            {
                //Xet ma lop truoc
                string lop  = xlRange.Cells[i, ThongTin.Lop].Value().ToString();
                string maso = xlRange.Cells[i, ThongTin.Ma].Value().ToString();
                string sbd  = xlRange.Cells[i, ThongTin.SBD].Value().ToString();
                lan = int.Parse(xlRange.Cells[i, ThongTin.Lan].Value().ToString());
                nam = int.Parse(xlRange.Cells[i, ThongTin.Nam].Value().ToString());
                string ho       = xlRange.Cells[i, ThongTin.Ho].Value().ToString();
                string ten      = xlRange.Cells[i, ThongTin.Ten].Value().ToString();
                string ngaysinh = xlRange.Cells[i, ThongTin.NgaySinh].Value().ToString();
                string dangky   = xlRange.Cells[i, ThongTin.DangKy].Value().ToString();
                if (!kt.dsLop.ContainsKey(lop))
                {
                    kt.dsLop.Add(lop, new LopHoc(lop));
                    ThiSinh ts = new ThiSinh(maso, sbd, lop, dangky, ho, ten, ngaysinh);

                    #region Kiem tra mon thi
                    if (xlRange.Cells[i, Mon.Anh] != null && xlRange.Cells[i, Mon.Anh].Value2 != null)
                    {
                        ts.diem.Add("Anh", double.Parse(xlRange.Cells[i, Mon.Anh].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Anh"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Anh", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Dia] != null && xlRange.Cells[i, Mon.Dia].Value2 != null)
                    {
                        ts.diem.Add("Địa", double.Parse(xlRange.Cells[i, Mon.Dia].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Địa"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Địa", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.GDCD] != null && xlRange.Cells[i, Mon.GDCD].Value2 != null)
                    {
                        ts.diem.Add("GDCD", double.Parse(xlRange.Cells[i, Mon.GDCD].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("GDCD"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("GDCD", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Hoa] != null && xlRange.Cells[i, Mon.Hoa].Value2 != null)
                    {
                        ts.diem.Add("Hóa", double.Parse(xlRange.Cells[i, Mon.Hoa].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Hóa"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Hóa", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Li] != null && xlRange.Cells[i, Mon.Li].Value2 != null)
                    {
                        ts.diem.Add("Lí", double.Parse(xlRange.Cells[i, Mon.Li].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Lí"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Lí", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Sinh] != null && xlRange.Cells[i, Mon.Sinh].Value2 != null)
                    {
                        ts.diem.Add("Sinh", double.Parse(xlRange.Cells[i, Mon.Sinh].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Sinh"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Sinh", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Su] != null && xlRange.Cells[i, Mon.Su].Value2 != null)
                    {
                        ts.diem.Add("Sử", double.Parse(xlRange.Cells[i, Mon.Su].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Sử"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Sử", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Toan] != null && xlRange.Cells[i, Mon.Toan].Value2 != null)
                    {
                        ts.diem.Add("Toán", double.Parse(xlRange.Cells[i, Mon.Toan].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Toán"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Toán", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Van] != null && xlRange.Cells[i, Mon.Van].Value2 != null)
                    {
                        ts.diem.Add("Văn", double.Parse(xlRange.Cells[i, Mon.Van].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Văn"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Văn", true);
                        }
                    }
                    #endregion
                    kt.dsLop[lop].dsThiSinh.Add(maso, ts);
                }
                else
                {
                    ThiSinh ts = new ThiSinh(maso, sbd, lop, dangky, ho, ten, ngaysinh);
                    #region Kiem tra mon thi
                    if (xlRange.Cells[i, Mon.Anh] != null && xlRange.Cells[i, Mon.Anh].Value2 != null)
                    {
                        ts.diem.Add("Anh", double.Parse(xlRange.Cells[i, Mon.Anh].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Anh"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Anh", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Dia] != null && xlRange.Cells[i, Mon.Dia].Value2 != null)
                    {
                        ts.diem.Add("Địa", double.Parse(xlRange.Cells[i, Mon.Dia].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Địa"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Địa", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.GDCD] != null && xlRange.Cells[i, Mon.GDCD].Value2 != null)
                    {
                        ts.diem.Add("GDCD", double.Parse(xlRange.Cells[i, Mon.GDCD].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("GDCD"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("GDCD", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Hoa] != null && xlRange.Cells[i, Mon.Hoa].Value2 != null)
                    {
                        ts.diem.Add("Hóa", double.Parse(xlRange.Cells[i, Mon.Hoa].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Hóa"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Hóa", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Li] != null && xlRange.Cells[i, Mon.Li].Value2 != null)
                    {
                        ts.diem.Add("Lí", double.Parse(xlRange.Cells[i, Mon.Li].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Lí"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Lí", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Sinh] != null && xlRange.Cells[i, Mon.Sinh].Value2 != null)
                    {
                        ts.diem.Add("Sinh", double.Parse(xlRange.Cells[i, Mon.Sinh].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Sinh"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Sinh", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Su] != null && xlRange.Cells[i, Mon.Su].Value2 != null)
                    {
                        ts.diem.Add("Sử", double.Parse(xlRange.Cells[i, Mon.Su].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Sử"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Sử", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Toan] != null && xlRange.Cells[i, Mon.Toan].Value2 != null)
                    {
                        ts.diem.Add("Toán", double.Parse(xlRange.Cells[i, Mon.Toan].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Toán"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Toán", true);
                        }
                    }
                    if (xlRange.Cells[i, Mon.Van] != null && xlRange.Cells[i, Mon.Van].Value2 != null)
                    {
                        ts.diem.Add("Văn", double.Parse(xlRange.Cells[i, Mon.Van].Value().ToString().Replace(',', '.')));
                        if (!kt.dsLop[lop].dsMonThi.ContainsKey("Văn"))
                        {
                            kt.dsLop[lop].dsMonThi.Add("Văn", true);
                        }
                    }
                    #endregion
                    kt.dsLop[lop].dsThiSinh.Add(maso, ts);
                }
            }


            //Giai phong
            // Đóng Workbook.
            xlWorkbook.Close(false);
            // Đóng application.
            xlApp.Quit();
            //Khử hết đối tượng
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkbook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);

            //Xac dinh lop
            cmbLop.Items.Clear();
            foreach (var item in kt.dsLop)
            {
                cmbLop.Items.Add(item.Key);
            }
        }