Example #1
0
        public JsonResult sendMail(string strOrderID)
        {
            List <FPT_CIR_HOLDING_GET_ALL_Result> list = le.FPT_CIR_HOLDING_GET_ALL().ToList();

            strOrderID = strOrderID.Trim();
            strOrderID = strOrderID.Substring(0, strOrderID.LastIndexOf(','));
            string[] orderArr = strOrderID.Split(',');
            foreach (string item in orderArr)
            {
                CIR_HOLDING order    = le.CIR_HOLDING.Where(a => a.ID.ToString() == item).First();
                string      date     = Convert.ToDateTime(order.TimeOutDate).ToString("dd/MM/yyyy");
                CIR_PATRON  patron   = le.CIR_PATRON.Where(a => a.Code == order.PatronCode).First();
                string      name     = patron.FirstName + " " + patron.MiddleName + " " + patron.LastName;
                DateTime    dateTime = DateTime.Now.AddDays(7);
                le.ExcuteSQL("update CIR_HOLDING set CheckMail=1, InTurn=1, TimeOutDate='" + dateTime.ToString() + "' where id =" + item);
                string bookname = "";
                foreach (FPT_CIR_HOLDING_GET_ALL_Result temp in list)
                {
                    if (temp.ID.ToString().Equals(item))
                    {
                        bookname = temp.BOOKNAME;
                        bookname = format.getContent(bookname.Split('$'), "a");
                        break;
                    }
                }
                sendmail(patron.Email, name, date, bookname);
            }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
Example #2
0
        /*
         * Status ID:
         * 1. Inturn False, CheckMail False: patron register to borrow, but library is out of books, when book is available,
         * librarian will notify patron via Mail
         * 2. Inturn False, CheckMail True: when book is available, librarian will notify patron via Mail but patron has not
         * got the book
         * 3. Inturn True, CheckMail True: book is available to borrow
         * 4. Inturn True, CheckMail False: patron register to borrow successfully and can get the book
         */
        private int SetStatusId(CIR_HOLDING holding)
        {
            int statusId = 0;

            if (!Convert.ToBoolean(holding.InTurn) && !holding.CheckMail)
            {
                statusId = 1;
            }
            else if (!Convert.ToBoolean(holding.InTurn) && holding.CheckMail)
            {
                statusId = 2;
            }
            else if (Convert.ToBoolean(holding.InTurn) && holding.CheckMail)
            {
                statusId = 3;
            }
            else
            {
                statusId = 4;
            }

            return(statusId);
        }
        public PartialViewResult CheckInByDKCB(
            int intType,
            int intAutoPaid,
            string strCopyNumbers,
            string strCheckInDate,
            string strPatronCode
            )
        {
            string CopyNumber = strCopyNumbers.Trim();
            int    success    = -1;

            if (!sessionpcode.Equals(""))
            {
                Getpatrondetail(sessionpcode);
            }
            else
            {
                ViewBag.PatronDetail = null;
            }
            if (db.HOLDINGs.Where(a => a.CopyNumber == CopyNumber).Count() == 0)
            {
                ViewBag.message = "ĐKCB không đúng";
            }
            else if (db.CIR_LOAN.Where(a => a.CopyNumber == CopyNumber).Count() == 0)
            {
                ViewBag.message = "ĐKCB chưa được ghi mượn";
            }
            else
            {
                string patroncode = db.CIR_LOAN.Where(a => a.CopyNumber == CopyNumber).First().CIR_PATRON.Code;
                success = db.SP_CHECKIN((int)Session["UserID"], intType, intAutoPaid, CopyNumber, strCheckInDate,
                                        new ObjectParameter("strTransIDs", typeof(string)),
                                        new ObjectParameter("strPatronCode", typeof(string)),
                                        new ObjectParameter("intError", typeof(int)));
                if (success == -1)
                {
                    ViewBag.CurrentCheckin = null;
                    ViewBag.message        = "Ghi trả thất bại";
                }
                else
                {
                    int    lastid    = db.CIR_LOAN_HISTORY.Max(a => a.ID);
                    int    id        = db.CIR_LOAN_HISTORY.Where(b => b.ID == lastid).First().ItemID;
                    String fieldcode = "245";
                    ViewBag.message        = "";
                    ViewBag.CurrentCheckin = new CurrentCheckIn
                    {
                        Title        = f.OnFormatHoldingTitle(db.FIELD200S.Where(a => a.ItemID == id).Where(a => a.FieldCode == fieldcode).First().Content),
                        Copynumber   = db.CIR_LOAN_HISTORY.Where(a => a.ID == lastid).First().CopyNumber,
                        CheckOutDate = db.CIR_LOAN_HISTORY.Where(a => a.ID == lastid).First().CheckOutdate.ToString("dd/MM/yyyy"),
                        CheckInDate  = db.CIR_LOAN_HISTORY.Where(a => a.ID == lastid).First().CheckInDate.ToString("dd/MM/yyyy"),
                        OverdueFine  = db.CIR_LOAN_HISTORY.Where(a => a.ID == lastid).First().OverdueFine.ToString()
                    };
                    sessionpcode = patroncode;
                }
                Getpatrondetail(patroncode);
                HOLDING holding = db.HOLDINGs.Where(a => a.CopyNumber == CopyNumber).First();


                if (db.CIR_HOLDING.Where(a => a.ItemID == holding.ItemID).Count() != 0)
                {
                    if (db.CIR_HOLDING.Where(a => (a.ItemID == holding.ItemID) && (a.InTurn == false) && (a.CheckMail == false)).Count() != 0)
                    {
                        CIR_HOLDING cIR_HOLDING = db.CIR_HOLDING.Where(a => (a.ItemID == holding.ItemID) && (a.InTurn == false) && (a.CheckMail == false)).OrderByDescending(x => x.CreatedDate).First();
                        CIR_PATRON  cIR_PATRON  = db.CIR_PATRON.Where(a => a.Code == cIR_HOLDING.PatronCode).First();
                        ViewBag.message = "Bạn đọc " + cIR_PATRON.FirstName + " " + cIR_PATRON.MiddleName + " " + cIR_PATRON.LastName + " .Mã SV:" + cIR_PATRON.Code + " đang đợi mượn cuốn này!";
                    }
                }
                if (db.CIR_PATRON_LOCK.Where(a => a.PatronCode == patroncode).Count() == 0)
                {
                    ViewBag.active = 1;
                }
                else
                {
                    ViewBag.active = 0;
                }
            }
            if (db.CIR_PATRON_LOCK.Where(a => a.PatronCode == strPatronCode).Count() == 0)
            {
                ViewBag.active = 1;
            }
            else
            {
                ViewBag.active = 0;
            }

            return(PartialView("_checkinByDKCB"));
        }
        public PartialViewResult CheckInByDKCBs(
            string strPatronCode,
            int intType,
            int intAutoPaid,
            string[] strCopyNumbers,
            string strCheckInDate
            )
        {
            string pcode   = strPatronCode.Trim();
            int    success = -1;

            if (strCopyNumbers != null)
            {
                foreach (string CopyNumber in strCopyNumbers)
                {
                    success = db.SP_CHECKIN((int)Session["UserID"], intType, intAutoPaid, CopyNumber, strCheckInDate,
                                            new ObjectParameter("strTransIDs", typeof(string)),
                                            new ObjectParameter("strPatronCode", typeof(string)),
                                            new ObjectParameter("intError", typeof(int)));
                }
            }
            Getpatrondetail(sessionpcode);
            //FPT_SP_UNLOCK_PATRON_CARD_LIST("'" + strPatronCode + "'");
            if (db.CIR_PATRON_LOCK.Where(a => a.PatronCode == strPatronCode).Count() == 0)
            {
                ViewBag.active = 1;
            }
            else
            {
                ViewBag.active = 0;
            }
            if (success == -1)
            {
                ViewBag.message        = "Ghi trả thất bại";
                ViewBag.CurrentCheckin = null;
            }
            else
            {
                int    lastid    = db.CIR_LOAN_HISTORY.Max(a => a.ID);
                int    id        = db.CIR_LOAN_HISTORY.Where(b => b.ID == lastid).First().ItemID;
                String fieldcode = "245";
                ViewBag.message        = "";
                ViewBag.CurrentCheckin = new CurrentCheckIn
                {
                    Title        = f.OnFormatHoldingTitle(db.FIELD200S.Where(a => a.ItemID == id).Where(a => a.FieldCode == fieldcode).First().Content),
                    Copynumber   = db.CIR_LOAN_HISTORY.Where(a => a.ID == lastid).First().CopyNumber,
                    CheckOutDate = db.CIR_LOAN_HISTORY.Where(a => a.ID == lastid).First().CheckOutdate.ToString("dd/MM/yyyy"),
                    CheckInDate  = db.CIR_LOAN_HISTORY.Where(a => a.ID == lastid).First().CheckInDate.ToString("dd/MM/yyyy"),
                    OverdueFine  = db.CIR_LOAN_HISTORY.Where(a => a.ID == lastid).First().OverdueFine.ToString()
                };
                string messageOrder = "";
                foreach (string item in strCopyNumbers)
                {
                    HOLDING holding = db.HOLDINGs.Where(a => a.CopyNumber == item).First();
                    //check this book is on exist in table order
                    if (db.CIR_HOLDING.Where(a => a.ItemID == holding.ItemID).Count() != 0)
                    {
                        if (db.CIR_HOLDING.Where(a => (a.ItemID == holding.ItemID) && (a.InTurn == false) && (a.CheckMail == false)).Count() != 0)
                        {
                            CIR_HOLDING cIR_HOLDING = db.CIR_HOLDING.Where(a => (a.ItemID == holding.ItemID) && (a.InTurn == false) && (a.CheckMail == false)).OrderByDescending(x => x.CreatedDate).First();
                            CIR_PATRON  cIR_PATRON  = db.CIR_PATRON.Where(a => a.Code == cIR_HOLDING.PatronCode).First();
                            ITEM        temp        = db.ITEMs.Where(a => a.ID == cIR_HOLDING.ItemID).First();
                            messageOrder = messageOrder + "Mã SV:" + cIR_PATRON.Code + " đang đợi mượn tài liệu " + temp.Code + "\n";
                        }
                    }
                }
                ViewBag.message = messageOrder;
            }
            return(PartialView("_checkinByDKCB"));
        }
        //Register to borrow book
        public ActionResult RegisterToBorrowBook(int userID, int itemID, int type)
        {
            if (type == 1)
            {
                string patronCode    = "";
                int    waitingBookId = 1;
                using (var dbContext = new OpacEntities())
                {
                    patronCode = (from t in dbContext.CIR_PATRON where t.ID == userID select t.Code).FirstOrDefault();
                    var lastIndex = dbContext.CIR_HOLDING.ToList().LastOrDefault();

                    if (lastIndex != null)
                    {
                        waitingBookId = lastIndex.ID + 1;
                    }
                }

                DateTime currentTime = DateTime.Now;
                DateTime getBookTime = currentTime.AddDays(7);

                CIR_HOLDING waitingBook = new CIR_HOLDING()
                {
                    ID          = waitingBookId,
                    ItemID      = itemID,
                    CheckMail   = false,
                    InTurn      = true,
                    CreatedDate = currentTime,
                    TimeOutDate = getBookTime,
                    PatronCode  = patronCode
                };

                dao.RegisterToBorrow(waitingBook);
            }
            else
            {
                string patronCode    = "";
                int    waitingBookId = 1;
                using (var dbContext = new OpacEntities())
                {
                    patronCode = (from t in dbContext.CIR_PATRON where t.ID == userID select t.Code).FirstOrDefault();
                    var lastIndex = dbContext.CIR_HOLDING.ToList().LastOrDefault();

                    if (lastIndex != null)
                    {
                        waitingBookId = lastIndex.ID + 1;
                    }
                }

                DateTime currentTime = DateTime.Now;

                CIR_HOLDING waitingBook = new CIR_HOLDING()
                {
                    ID          = waitingBookId,
                    ItemID      = itemID,
                    CheckMail   = false,
                    InTurn      = false,
                    CreatedDate = currentTime,
                    PatronCode  = patronCode
                };

                dao.RegisterToBorrow(waitingBook);
            }

            TempData["BorrowSuccess"] = "Đặt mượn sách thành công!";

            return(RedirectToAction("RegisterToBorrowBookPage", "InformationPatron"));
        }