コード例 #1
0
 //lấy điểm trường dựa vào id
 public string GetDiemTruongByID(int truongid)
 {
     using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
     {
         return(db.Truongs.SingleOrDefault(x => x.ID == truongid).DiemChuan.ToString());
     }
 }
コード例 #2
0
 public ActionResult QuanLiDiemCacNam()
 {
     using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
     {
         List <DiemCacNam> diemcacnams = db.DiemCacNams.ToList();
         return(View(diemcacnams));
     }
 }
コード例 #3
0
 //từ bảng các năm lấy đc id viện,=> tên viện
 public string GetTenVienById(int id)
 {
     using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
     {
         Vien v = db.Viens.SingleOrDefault(x => x.Id == id);
         return(v.Ten);
     }
 }
コード例 #4
0
 public ActionResult QuanLiNganh_SoThich()
 {
     using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
     {
         List <Vien_SoThich> vien_sothichs = db.Vien_SoThich.ToList();
         return(View(vien_sothichs));
     }
 }
コード例 #5
0
 public ActionResult QuanLiSoThich()
 {
     using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
     {
         List <SoThich> sothichs = db.SoThiches.ToList();
         return(View(sothichs));
     }
 }
コード例 #6
0
 public ActionResult QuanLiTruong()
 {
     using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
     {
         List <Truong> truongs = db.Truongs.ToList();
         return(View(truongs));
     }
 }
コード例 #7
0
 // GET: Admin
 public ActionResult QuanLiNganh()
 {
     using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
     {
         List <Vien> viens = db.Viens.ToList();
         return(View(viens));
     }
 }
コード例 #8
0
        public ActionResult Index()
        {
            //Hiển thị Sở thích và điểm số của thí sinh
            List <SoThich> sothichs = new List <SoThich>();
            List <Truong>  truongs  = new List <Truong>();
            List <Khoi>    khois    = new List <Khoi>();

            using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
            {
                sothichs        = db.SoThiches.OrderBy(x => x.Ten).ToList();
                truongs         = db.Truongs.OrderBy(x => x.ID).ToList();
                khois           = db.Khois.OrderBy(x => x.ID).ToList();
                ViewBag.SoThich = new SelectList(sothichs, "Id", "Ten");
                ViewBag.Truong  = new SelectList(truongs, "ID", "Ten");
                ViewBag.Khoi    = new SelectList(khois, "ID", "Ten");

                return(View());
            }
        }
コード例 #9
0
 //từ ID Viện(ngành) lấy ra đc điểm các năm
 public double GetDiemByIdVien(int id, int nam)
 {
     using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
     {
         DiemCacNam diemcacnam = db.DiemCacNams.FirstOrDefault(x => x.IDVien == id);
         if (nam == 2014)
         {
             return(diemcacnam.Nam2014);
         }
         if (nam == 2015)
         {
             return(diemcacnam.Nam2015);
         }
         if (nam == 2016)
         {
             return(diemcacnam.Nam2016);
         }
         if (nam == 2017)
         {
             return(diemcacnam.Nam2017);
         }
         return(0);
     }
 }
コード例 #10
0
        public ActionResult Predict(int Id, string Diem, string truongID, string khoiID)
        {
            //if (Id.ToString()==null || Id.ToString()==null)
            //{
            //    ModelState.AddModelError("SoThichValidate","Vui lòng nhập sở thích!");
            //    return View("Index");
            //}
            //if (String.IsNullOrEmpty(Diem))
            //{
            //    ModelState.AddModelError("DiemValidate", "Vui lòng nhập điểm!");
            //    return View("Index");
            //}

            //lấy đc Id sở thích và điểm
            //double test = Convert.ToDouble("-3.5");
            //từ Id lấy sở thích
            using (HeTroGiupQuyetDinh1Entities db = new HeTroGiupQuyetDinh1Entities())
            {
                SoThich st = db.SoThiches.SingleOrDefault(x => x.Id == Id);
                //string t = GetTruongIDByTen(Truong);
                //List<Vien> viens = db.Viens.Where(x => x.TruongID == t.ID).ToList();
                //lấy số dòng của ma trận chính là số lượng viện trong bảng DiemCacNam
                int dong;
                //số cột chính là số thuộc tính: sở thích và chênh lệch 4 năm từ 2014->2017
                //int cot = 6; //ví dụ 5 cột thuộc tính và 1 cột phương án
                int cot = 6; //thử nghiệm
                //List<DiemCacNam> diemcacnams = db.DiemCacNams.Where(x=>x.Vien.TruongID.ToString()==truongID)
                //    .ToList();


                //List<DiemCacNam> diemcacnams = (from a in db.DiemCacNams
                //                                join b in db.Viens on a.IDVien equals b.Id
                //                                where a.Vien.TruongID.Equals(truongID)
                //                                where b.Khoi.ID.Equals(khoiID)
                //                                select a).ToList();

                string            diem        = "SELECT  * FROM dbo.DiemCacNam AS d,dbo.Vien AS v WHERE d.IDVien = v.Id AND v.TruongID = " + truongID + " AND v.KhoiID = " + khoiID;
                List <DiemCacNam> diemcacnams = db.DiemCacNams.SqlQuery(diem).ToList();

                dong = diemcacnams.Count();

                //ma trận quyết định
                //string[,] matrix = new string[dong+1, cot];

                //thêm 2 dòng: giá trị cao nhất và trọng số
                string[,] matrix = new string[dong + 3, cot];

                //fix hàng đầu tiên của ma trận:
                matrix[0, 0] = "Viện";
                matrix[0, 1] = st.Ten;
                matrix[0, 2] = "Chênh lệch năm 2014";
                matrix[0, 3] = "Chênh lệch năm 2015";
                matrix[0, 4] = "Chênh lệch năm 2016";
                matrix[0, 5] = "Chênh lệch năm 2017";

                matrix[dong + 1, 0] = "Giá trị cao nhất";
                matrix[dong + 2, 0] = "Trọng số";

                //cột viện: cột =0
                for (int i = 0; i < dong; i++)
                {
                    //lấy tên viện dựa vào ID của Viện
                    matrix[i + 1, 0] = GetTenVienById(diemcacnams[i].IDVien);

                    //cột 2
                    //từ sở thích và viện lấy ra đc điểm của sở thích đó theo viện( từ bảng viện_sở thích)
                    //Vien_SoThich v = (from a in db.Vien_SoThich
                    //                  join b in db.Viens on a.IdVien equals b.Id
                    //                  join c in db.SoThiches on a.IdSoThich equals c.Id
                    //                  where a.IdSoThich.Equals(st.Id) && a.IdVien.Equals(diemcacnams[i].IDVien)
                    //                  select a
                    //                  ).FirstOrDefault();
                    string       sql = "Select * from dbo.Vien_SoThich where IdVien=" + diemcacnams[i].IDVien + " and IdSoThich=" + st.Id;
                    Vien_SoThich v   = db.Vien_SoThich.SqlQuery(sql).SingleOrDefault();
                    if (v == null)
                    {
                        matrix[i + 1, 1] = "5";
                    }
                    else
                    {
                        matrix[i + 1, 1] = v.Diem.ToString();
                    }

                    //cột 3,4,5,6: chênh lệch năm 2014,15,16,17
                    //từ ID Viện lấy ra đc điểm năm 2014... của Viện đó==> độ chênh lệch

                    //mục tiêu là chênh lệch phải ít nhất lớn hơn điểm các năm
                    //matrix[i + 1, 2] = (Convert.ToDouble(Diem)-GetDiemByIdVien(diemcacnams[i].IDVien, 2014)).ToString();
                    //matrix[i + 1, 3] = (Convert.ToDouble(Diem)-GetDiemByIdVien(diemcacnams[i].IDVien, 2015)).ToString();
                    //matrix[i + 1, 4] = (Convert.ToDouble(Diem)-GetDiemByIdVien(diemcacnams[i].IDVien, 2016)).ToString();
                    //matrix[i + 1, 5] = (Convert.ToDouble(Diem)-GetDiemByIdVien(diemcacnams[i].IDVien, 2017)).ToString();

                    matrix[i + 1, 2] = ChuanHoaChenhLechDiem(Convert.ToDouble(Diem), GetDiemByIdVien(diemcacnams[i].IDVien, 2014)).ToString("0.####");
                    matrix[i + 1, 3] = ChuanHoaChenhLechDiem(Convert.ToDouble(Diem), GetDiemByIdVien(diemcacnams[i].IDVien, 2015)).ToString("0.####");
                    matrix[i + 1, 4] = ChuanHoaChenhLechDiem(Convert.ToDouble(Diem), GetDiemByIdVien(diemcacnams[i].IDVien, 2016)).ToString("0.####");
                    matrix[i + 1, 5] = ChuanHoaChenhLechDiem(Convert.ToDouble(Diem), GetDiemByIdVien(diemcacnams[i].IDVien, 2017)).ToString("0.####");
                }

                //thêm hàng giá trị cao nhất: Giá trị max mỗi cột
                matrix[dong + 1, 1] = GetMaxAColumn(matrix, 1);
                matrix[dong + 1, 2] = GetMaxAColumn(matrix, 2);
                matrix[dong + 1, 3] = GetMaxAColumn(matrix, 3);
                matrix[dong + 1, 4] = GetMaxAColumn(matrix, 4);
                matrix[dong + 1, 5] = GetMaxAColumn(matrix, 5);


                //thêm hàng trọng số
                matrix[dong + 2, 1] = 0.2.ToString();  //sở thích
                matrix[dong + 2, 2] = 0.15.ToString(); //năm 2014
                matrix[dong + 2, 3] = 0.15.ToString(); //năm 2015
                matrix[dong + 2, 4] = 0.2.ToString();  //năm 2016
                matrix[dong + 2, 5] = 0.3.ToString();  //năm 2017

                BangQuyetDinh bangquyetdinh = new BangQuyetDinh();
                bangquyetdinh.Matrix = matrix;

                bangquyetdinh.ChuanHoaMatrix         = ChuanHoa(matrix);
                bangquyetdinh.ChuanHoa_TrongSoMatrix = ChuanHoa_TrongSo(ChuanHoa(matrix));

                int dongchuanhoa = bangquyetdinh.ChuanHoa_TrongSoMatrix.GetLength(0); //số hàng: với 2 ngành là 5
                int cotchuanhoa  = bangquyetdinh.ChuanHoa_TrongSoMatrix.GetLength(1); //số cột là 6: có 2 ngành
                //từ bảng chuanhoa(matrix), thêm 2 dòng cho 2 phương án lí tưởng
                //getleng là 5, => hàng thứ 4

                //chú ý: mức độ quan trọng âm=> sẽ cộng 2 lần cột đó, khi tính S*

                //lí tưởng tốt
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 2, 1] = GetMaxAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 1);
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 2, 2] = GetMaxAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 2);
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 2, 3] = GetMaxAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 3);
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 2, 4] = GetMaxAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 4);
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 2, 5] = GetMaxAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 5);
                //lí tưởng xấu
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 1, 1] = GetMinAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 1);
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 1, 2] = GetMinAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 2);
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 1, 3] = GetMinAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 3);
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 1, 4] = GetMinAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 4);
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 1, 5] = GetMinAColumn(bangquyetdinh.ChuanHoa_TrongSoMatrix, 5);

                //đổi tên hàng lí tưởng xấu và tốt:
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 2, 0] = "Lí tưởng tốt(A*)";
                bangquyetdinh.ChuanHoa_TrongSoMatrix[matrix.GetLength(0) - 1, 0] = "Lí tưởng xấu(A-)";

                //khoảng cách với lí tưởng tốt và xấu: thêm 2 cột lí tưởng và 1 cột độ tương tự=>9
                string[,] matranlituong = new string[bangquyetdinh.ChuanHoa_TrongSoMatrix.GetLength(0), 9];
                //tên cột
                matranlituong[0, 6] = "Khảng cách tới A*(S*)";
                matranlituong[0, 7] = "Khoảng cách tới A-(S-)";
                matranlituong[0, 8] = "Phương án hợp lí C*";
                for (int i = 0; i < bangquyetdinh.ChuanHoa_TrongSoMatrix.GetLength(0); i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        matranlituong[i, j] = bangquyetdinh.ChuanHoa_TrongSoMatrix[i, j];
                    }
                }
                for (int i = 0; i < diemcacnams.Count(); i++)
                {
                    //so với tốt
                    //bangquyetdinh.ChuanHoa_TrongSoMatrix[i+1, 6] = GetKhoangCachToGiaiPhapLiTuong(bangquyetdinh.ChuanHoa_TrongSoMatrix,i+1, 2);
                    matranlituong[i + 1, 6] = GetKhoangCachToGiaiPhapLiTuong(bangquyetdinh.ChuanHoa_TrongSoMatrix, i + 1, 2);
                    //so với xấu
                    matranlituong[i + 1, 7] = GetKhoangCachToGiaiPhapLiTuong(bangquyetdinh.ChuanHoa_TrongSoMatrix, i + 1, 1);
                    //độ tương tự
                    matranlituong[i + 1, 8] = GetDoTuongTu(matranlituong, i + 1).ToString("0.####");
                }
                bangquyetdinh.Matranlituong = matranlituong;

                ///từ đây ta lấy đc độ tương tự tới phương án hợp lí
                //lấy giá trị max của cột C*
                //từ giá trị max => Tên viện
                double Cmax        = 0;
                string predictVien = "";
                string dongMax     = "";

                for (int i = 0; i < diemcacnams.Count; i++)
                {
                    if (Convert.ToDouble(matranlituong[i + 1, 8]) > Cmax)
                    {
                        Cmax        = Convert.ToDouble(matranlituong[i + 1, 8]);
                        predictVien = matranlituong[i + 1, 0];
                        dongMax     = (i + 1).ToString();
                    }
                }
                TempData["Yeucau"]  = "Yêu cầu trợ giúp: Trường " + GetTruongByID(Convert.ToInt16(truongID)) + ", Khối: " + db.Khois.SingleOrDefault(x => x.ID.ToString() == khoiID).Ten + ", Sở thích: " + st.Ten + " ," + Diem + " điểm";
                TempData["Predict"] = "Chọn ngành: " + predictVien;

                ViewBag.CMax    = Cmax;
                ViewBag.DongMax = dongMax;

                ViewBag.Dong = dong + 3; //số dòng=số lượng viện + thêm 3
                ViewBag.Cot  = cot;
                return(PartialView(bangquyetdinh));
            }
        }