Ejemplo n.º 1
0
        private void btnExtendReserve_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridOfBooks.SelectedRows.Count != 1)
                {
                    MessageBox.Show("لطفا کتاب مورد نظر را انتخاب کنید", "خطا");
                }
                else
                {
                    string Selected = "";
                    foreach (DataGridViewRow item in dataGridOfBooks.SelectedRows)
                    {
                        Selected = item.Cells[3].Value.ToString();
                    }
                    Guid codeBook      = Guid.Parse(Selected);
                    var  book          = booksRepo.FindBookByCode(codeBook);
                    var  user          = membersRepo.FindUserByUserName(lblUser.Text);
                    bool checkReserved = borrowedRepo.checkIfBookIsBorrowedByUser(user.MemberId, book.Code);
                    if (book.BookState != 0 && !checkReserved)
                    {
                        MessageBox.Show("کتاب جزو کتاب های امانت گرفته شده توسط شما نمیباشد", "خطا");
                    }
                    else
                    {
                        var foundBorrowedBooks = borrowedRepo.FindReservedBookBycodeAnduser(user.MemberId, book.Code);
                        borrowedRepo.DeliverBookToLib(book.Code, DateTime.Now);
                        var deadLine       = foundBorrowedBooks.DeadLineForBorrow;
                        var lastDayOfMonth = DateTime.DaysInMonth(deadLine.Year, deadLine.Month);
                        if (deadLine.Day + 10 > lastDayOfMonth)
                        {
                            deadLine = new DateTime(deadLine.Year, deadLine.Month + 1, 10 - (lastDayOfMonth - deadLine.Day));
                        }
                        else
                        {
                            deadLine = new DateTime(deadLine.Year, deadLine.Month, deadLine.Day + 10);
                        }

                        Borrowed borrowed = new Borrowed()
                        {
                            BookCode          = book.Code,
                            TimeOfBorrow      = DateTime.Now,
                            MemberId          = user.MemberId,
                            DeadLineForBorrow = deadLine
                        };
                        borrowedRepo.AddToBorrowed(borrowed);
                        MessageBox.Show("تمدید ثبت شد", "Success");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("لطفا کتاب مورد نظر را از امانات انتخاب کنید", "خطا");
            }
        }
Ejemplo n.º 2
0
        private void btnBorrow_Click(object sender, EventArgs e)
        {
            try
            {
                var     userNationalCode = txtNationalCode.Text.Replace(" ", "");
                Members member           = membersRepo.FindUserByNationalCode(userNationalCode);
                if (member == null)
                {
                    MessageBox.Show("عضوی با این کد ملی یافت نشد", "خطا");
                }
                if (dataGridStorageOfBooks.SelectedRows.Count != 1 || userNationalCode == "")
                {
                    MessageBox.Show("لطفا کتاب و کاربر را انتخاب کنید", "خطا");
                }
                else
                {
                    string Selected       = "";
                    var    deadLine       = DateTime.Now;
                    var    lastDayOfMonth = DateTime.DaysInMonth(deadLine.Year, deadLine.Month);
                    if (deadLine.Day + 15 > lastDayOfMonth)
                    {
                        deadLine = new DateTime(deadLine.Year, deadLine.Month + 1, 15 - (lastDayOfMonth - deadLine.Day));
                    }
                    else
                    {
                        deadLine = new DateTime(deadLine.Year, deadLine.Month, deadLine.Day + 15);
                    }
                    Guid codeBook = new Guid();
                    foreach (DataGridViewRow item in dataGridStorageOfBooks.SelectedRows)
                    {
                        Selected = item.Cells[6].Value.ToString();
                    }
                    codeBook = Guid.Parse(Selected);
                    Books book = booksRepo.FindBookByCode(codeBook);

                    if (book.BookState == 2 && member != null && book.BookCondition == 0)
                    {
                        borrowed = new Borrowed()
                        {
                            BookCode          = codeBook,
                            MemberId          = member.MemberId,
                            TimeOfBorrow      = DateTime.Now,
                            DeadLineForBorrow = deadLine
                        };
                        borrowedRepo.AddToBorrowed(borrowed);
                        booksRepo.ChangeBookState(codeBook, 0);
                        MessageBox.Show("کتاب با موفقیت ثبت شد", "Success");
                    }
                    else if (book.BookState == 0)
                    {
                        MessageBox.Show("این کتاب در امانت شخص دیگری می باشد");
                    }
                    else if (book.BookCondition != 0)
                    {
                        MessageBox.Show("این کتاب قابل امانت نمی باشد");
                    }
                    else if (book.BookState == 1)
                    {
                        bool check = reservationRepo.CheckIfBookIsReservedByUser(member.NationalCode, codeBook);
                        if (check)
                        {
                            borrowed = new Borrowed()
                            {
                                BookCode          = codeBook,
                                MemberId          = member.MemberId,
                                TimeOfBorrow      = DateTime.Now,
                                DeadLineForBorrow = deadLine
                            };
                            borrowedRepo.AddToBorrowed(borrowed);
                            booksRepo.ChangeBookState(codeBook, 0);
                            MessageBox.Show("کتاب با موفقیت ثبت شد", "Success");
                        }

                        else
                        {
                            MessageBox.Show("این کتاب قبلا توسط شخص دیگری رزرو شده است");
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }