コード例 #1
0
        private void ReservedBooks_Click(object sender, EventArgs e)
        {
            UpdateGrid();
            var user = membersRepo.FindUserByUserName(lblUser.Text);
            List <Reservations> foundBooksReserved = new List <Reservations>();

            foundBooksReserved = reservationRepo.GetAllReservatiosByUser(user.NationalCode);
            List <Books> foundBooks = new List <Books>();

            try
            {
                foreach (var item in foundBooksReserved)
                {
                    foundBooks.Add(booksRepo.FindBookByCode(item.BookCode));
                }
            }
            catch (Exception)
            {
                //foundBooks = null;
            }
            var results = (from a in foundBooks
                           select new
            {
                نام = a.AuthorName + "  " + a.AuthorFName,
                موضوع = a.Subject,
                عنوان = a.Title,
                کدکتاب = a.Code
            }).ToList();

            dataGridOfBooks.DataSource = results;
        }
コード例 #2
0
 public void InitializeEdit()
 {
     try
     {
         Guid code = Guid.Parse(lblCodeBook.Text);
         var  book = booksRepository.FindBookByCode(code);
         txtAuthorName.Text  = book.AuthorName;
         txtAuthorFname.Text = book.AuthorFName;
         txtBookName.Text    = book.Title;
         txtSubject.Text     = book.Subject;
         txtPrice.Text       = book.Price;
     }
     catch (Exception)
     {
     }
 }
コード例 #3
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)
            {
            }
        }