コード例 #1
0
        /// <summary>
        /// Tìm sách có sặn trong thư viện
        /// </summary>
        /// <param name="sDTO"></param>
        /// <returns></returns>
        public List <sachDTO> TimSach(sachDTO sDTO)
        {
            List <sachDTO> list   = new List <sachDTO>();
            List <sachDTO> result = new List <sachDTO>();

            string tensach    = sDTO.Tensach;
            string theloai    = sDTO.Theloai;
            string tacgia     = sDTO.Tacgia;
            string nhaxuatban = sDTO.Nxb;
            string masach;

            if (sDTO.Masach == -1)
            {
                masach = "";
            }
            else
            {
                masach = sDTO.Masach.ToString();
            }
            if (tensach == null)
            {
                tensach = "";
            }
            if (theloai == null)
            {
                theloai = "";
            }
            if (tacgia == null)
            {
                tacgia = "";
            }
            if (nhaxuatban == null)
            {
                nhaxuatban = "";
            }

            int max_masach_distance         = masach.ToString().Length / 2;
            int max_name_distance           = tensach.Length / 2;
            int max_author_distance         = tacgia.Length / 2;
            int max_publishcompany_distance = nhaxuatban.Length / 2;

            sachDAL saxDAL = new sachDAL();
            sachDTO temp   = new sachDTO();

            list = DanhSachSach();

            //if(masach != "")
            //if (saxDAL.isSach(sDTO.Masach,ref temp))
            //{
            //    result.Add(temp);
            //}

            if (masach != "")
            {
                if (saxDAL.isSach(sDTO.Masach))
                {
                    foreach (sachDTO sax in list)
                    {
                        if (sax.Masach == int.Parse(masach))
                        {
                            result.Add(sax);
                            return(result);
                        }
                    }
                }
            }

            if (tensach != "")
            {
                List <ResultItem> item = new List <ResultItem>();
                foreach (sachDTO sa in list)
                {
                    int check = TimKiemBUS.CheckisAvaiable(tensach, sa.Tensach);
                    if (check != -1)
                    {
                        ResultItem rItem;
                        rItem.mark = check;
                        rItem.sach = sa;
                        item.Add(rItem);
                    }
                }
                item.Sort((s1, s2) => s1.mark.CompareTo(s2.mark));
                foreach (ResultItem i in item)
                {
                    result.Add(i.sach);
                }
            }

            if (theloai != "")
            {
                foreach (sachDTO sach in list)
                {
                    if (sach.Theloai == theloai)
                    {
                        if (result.IndexOf(sach) == -1)
                        {
                            result.Add(sach);
                        }
                    }
                }
            }

            if (tacgia != "")
            {
                foreach (sachDTO sach in list)
                {
                    if (TimKiemBUS.CheckisAvaiable(tacgia, sach.Tacgia) != -1)
                    {
                        if (result.IndexOf(sach) == -1)
                        {
                            result.Add(sach);
                        }
                    }
                }
            }

            if (nhaxuatban != "")
            {
                foreach (sachDTO sach in list)
                {
                    if (Levenshtein_Distance.Distance(sach.Nxb, nhaxuatban) <= sach.Nxb.Length)
                    {
                        if (result.IndexOf(sach) == -1)
                        {
                            result.Add(sach);
                        }
                    }
                }
            }


            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Tìm đọc giả theo tên và số cmnd
        /// </summary>
        /// <param name="cmnd"> Mã số cmnd </param>
        /// <param name="name"> Họ tên bạn đọc </param>
        /// <returns></returns>
        public List <docgiaDTO> TimDocGia(string cmnd, string name)
        {
            //cmnd = cmnd.Replace(" ", "");
            if (cmnd == null)
            {
                cmnd = "";
            }
            if (name == null)
            {
                name = "";
            }
            List <docgiaDTO> result    = new List <docgiaDTO>();
            List <docgiaDTO> danhsach  = this.DanhSachDocGia();
            docgiaDAL        docgiaDAL = new docgiaDAL();


            if (cmnd != "")
            {
                if (docgiaDAL.isDocGia(int.Parse(cmnd)))
                {
                    foreach (docgiaDTO dg in danhsach)
                    {
                        if (dg.MaThe == int.Parse(cmnd))
                        {
                            result.Add(dg);
                            return(result);
                        }
                    }
                }
                else
                {
                    foreach (docgiaDTO dg in danhsach)
                    {
                        if (Levenshtein_Distance.Distance(dg.MaThe.ToString(), cmnd) <= (MAX_LEVENSTEIN_DISTANCE / 2))
                        {
                            if (result.IndexOf(dg) == -1)
                            {
                                result.Add(dg);
                            }
                        }
                    }
                }
            }

            if (name != "")
            {
                List <ResultItem> item = new List <ResultItem>();
                foreach (docgiaDTO dg in danhsach)
                {
                    int check = TimKiemBUS.CheckisAvaiable(name, dg.HoTen);
                    if (check != -1)
                    {
                        ResultItem rItem;
                        rItem.mark   = check;
                        rItem.docgia = dg;
                        item.Add(rItem);
                    }
                }
                item.Sort((s1, s2) => s1.mark.CompareTo(s2.mark));
                foreach (ResultItem i in item)
                {
                    result.Add(i.docgia);
                }
            }

            return(result);
        }