Пример #1
0
        private int TotalBookStockValidation(GalaxyEntities context)
        {
            var TotalStockCount = from x in context.Books.Where(x => x.BookID == txBookID.Text) select x.TotalStock;
            int i = TotalStockCount.Single();

            return(i);
        }
        private void btnUpfM_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();
            Member         c   = new Member();

            try
            {
                // Validate ID to be existing
                if (txmemberID.Text.Length == 5 && txmemberID.Text.Substring(0, 1) == "M")
                {
                    if (Convert.ToInt32(txmemberID.Text.Substring(1, 4)) >= 1000 && Convert.ToInt32(txmemberID.Text.Substring(1, 4)) <= ctx.Members.Count() + 999)
                    {
                        // Identify member record
                        c            = ctx.Members.Where(x => x.MemberID == txmemberID.Text).First();
                        c.FineAmount = Convert.ToDouble(txFine.Text);
                        ctx.SaveChanges();
                        MessageBox.Show("Successful update!");
                        btnclr_Click(sender, e);
                    }
                }
                else
                {
                    MessageBox.Show("Not an existing MemberID!");
                }
            }
            catch (Exception a)
            {
                a = new InvalidInputException("Please ensure that details of member is correct.");
                MessageBox.Show(a.Message);
            }
        }
Пример #3
0
        private void btnSure_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();

            if (txID.Text.Length == 3 && txID.Text.Substring(0, 1) == "S")
            {
                if (Convert.ToInt32(txID.Text.Substring(1, 2)) >= 1 && Convert.ToInt32(txID.Text.Substring(1, 2)) <= ctx.Staffs.Count())
                {
                    Staff c = ctx.Staffs.Where(x => x.StaffID == txID.Text).First();
                    txName.Text     = c.Name;
                    txPassword.Text = c.Password;
                    txPhoneNo.Text  = c.PhoneNumber.ToString();
                    txPosition.Text = c.Position;
                    txUserName.Text = c.Username;
                    txAddress.Text  = c.Address;
                    txEmail.Text    = c.EmailAddress;
                }
                else
                {
                    MessageBox.Show("This format of input is right but this staff is not existing! You can add a new one!");
                }
            }
            else
            {
                MessageBox.Show("You input the wrong format! You can check the notice and input again!");
            }
        }
        public frm11BookSearchForStaff() : base()
        {
            InitializeComponent();
            context = new GalaxyEntities();

            // Set search filters
            cbxSearchBy.DataSource = new List <string> {
                "Book ID", "Title", "Publisher", "Author", "Book Category", "Location",
                "Price", "Total Stock", "Number Borrowed", "Availability"
            };

            // Display all books
            gvSearchResult.DataSource = context.Books.Select(x => new {
                x.BookID,
                x.Title,
                x.Publisher,
                x.Author,
                x.BookCategory,
                x.Location,
                x.Price,
                x.TotalStock,
                x.NumberBorrowed,
                x.Availability
            }).ToList();
        }
Пример #5
0
 private void frmBookAdd_Load(object sender, EventArgs e)
 {
     context = new GalaxyEntities();
     GenerateBookID();
     cbxCategory.SelectedIndex = 0;
     cbxFloor.SelectedIndex    = 0;
 }
Пример #6
0
        private int ExtensionCount(GalaxyEntities context)
        {
            var         count = from x in context.Transactions where x.MemberID == txMemberID.Text && x.BookID == txBookID.Text select x;
            Transaction c     = count.First();
            int         i     = c.ExtensionCount;

            return(i);
        }
Пример #7
0
        private void Extension(GalaxyEntities context)
        {
            Transaction t = context.Transactions.Where(x => x.BookID == txBookID.Text && x.MemberID == txMemberID.Text).FirstOrDefault();

            t.IssueDate       = DateTime.Today.Date;
            t.DueDate         = DateTime.Now.AddDays(10);
            t.ExtensionCount += 1;
            context.SaveChanges();
        }
 public frmSearchCustomer()
 {
     InitializeComponent();
     context = new GalaxyEntities();
     cbxSearchBy.DataSource  = searchByList;
     btnRetrieve.Enabled     = false;
     btnSearch.Enabled       = false;
     txSearchDetail.ReadOnly = true;
 }
 private void frmBookSearchForStaff_Load(object sender, EventArgs e)
 {
     context       = new GalaxyEntities();
     gv.DataSource = context.Books.Select(x => new { x.BookID, x.Title, x.Publisher, x.Author, x.BookCategory, x.Location, x.Price,
                                                     x.TotalStock, x.NumberBorrowed, x.Availability }).ToList();
     cbxSearchBy.SelectedIndex = 0;
     txInput.Text   = "";
     selectedBookID = "";
 }
Пример #10
0
        private void frm8BookInformation_Load(object sender, EventArgs e)
        {
            context = new GalaxyEntities();
            tempID  = "";

            // View first book
            position = 0;
            bookList = context.Books.ToList();
            b        = bookList[position];
            displayDetails();
            displayHistory();
        }
Пример #11
0
        public frmTemplateSearch()
        {
            InitializeComponent();

            // Display default filter for user to search by
            cbxSearchBy.SelectedIndex = 0;

            // Set viewing preference for grid view
            gvSearchResult.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;


            txSearchDetail.Text = "";
            selectedID          = "";
            context             = new GalaxyEntities();
        }
Пример #12
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();
            Staff          c   = ctx.Staffs.Where(x => x.StaffID == txID.Text).First();

            c.Name         = txName.Text;
            c.Password     = txPassword.Text;
            c.PhoneNumber  = txPhoneNo.Text;
            c.Position     = txPosition.Text;
            c.Username     = txUserName.Text;
            c.Address      = txAddress.Text;
            c.EmailAddress = txEmail.Text;
            ctx.SaveChanges();

            MessageBox.Show("Information successfully updated!");
        }
Пример #13
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();

            if (txID.Text.Length == 3 && txID.Text.Substring(0, 1) == "S" && Convert.ToInt32(txID.Text.Substring(1, 2)) >= 1 && Convert.ToInt32(txID.Text.Substring(1, 2)) <= ctx.Staffs.Count())
            {
                Staff c = ctx.Staffs.Where(x => x.StaffID == txID.Text).First();
                ctx.Staffs.Remove(c);
                ctx.SaveChanges();

                MessageBox.Show("Staff successfully deleted!");
            }
            else
            {
                MessageBox.Show("This staff is not existing! You may input the wrong StaffID, please check and input again!");
            }
        }
Пример #14
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            username = Username_txt.Text;
            string password = Password_text.Text;

            Username_txt.Text.Trim();

            using (GalaxyEntities context = new GalaxyEntities())
            {
                var user = context.Staffs.FirstOrDefault(u => u.Username == username);
                if (user != null)
                {
                    if (user.Password == password)
                    {
                        this.Hide();
                        //this.DialogResult = DialogResult.OK;
                        //proceed to new form =
                        frm6BorrowBook f = new frm6BorrowBook();
                        //frmTemplate temp = new frmTemplate();
                        //temp.LbUserName = username;
                        f.Name = user.Name;

                        f.Location = this.Location;
                        f.ShowDialog();
                        this.Close();

                        //label4.Text = "Login successful";
                        //if (user.Username == "Venkat") {
                        //    checkBoss = true;
                        //}
                    }
                    else
                    {
                        label4.Text = "Wrong password";
                    }
                }
                else
                {
                    label4.Text = "No User Called " + username + " found";
                }
            }
        }
Пример #15
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();


            if (txID.Text.Length == 3 && txID.Text.Substring(0, 1) == "S" && Convert.ToInt32(txID.Text.Substring(1, 2)) >= 1 && Convert.ToInt32(txID.Text.Substring(1, 2)) <= ctx.Staffs.Count())
            {
                bool check = false;
                foreach (Staff x in ctx.Staffs.ToList())
                {
                    if (txID.Text == x.StaffID)
                    {
                        check = true;
                        break;
                    }
                }
                if (check == false)
                {
                    Staff c = new Staff();
                    c.StaffID      = txID.Text;
                    c.Name         = txName.Text;
                    c.Password     = txPassword.Text;
                    c.PhoneNumber  = txPhoneNo.Text;
                    c.Position     = txPosition.Text;
                    c.Username     = txUserName.Text;
                    c.Address      = txAddress.Text;
                    c.EmailAddress = txEmail.Text;
                    ctx.Staffs.Add(c);
                    ctx.SaveChanges();

                    MessageBox.Show("Staff successfully added!");
                }
                else
                {
                    MessageBox.Show("Existed Member ID, please set other ID!!");
                }
            }
            else
            {
                MessageBox.Show("You may input the wrong StaffID, please check and input again!");
            }
        }
Пример #16
0
        private void btnExtension_Click(object sender, EventArgs e)
        {
            using (GalaxyEntities context = new GalaxyEntities())
            {
                txMemberID.Text.Trim();
                txBookID.Text.Trim();

                if (UsernamePasswordisValid(context))
                {
                    if (TotalBorrowCount(context))
                    {
                        int i        = ExtensionCount(context);
                        var Lecturer = LecturerValidation(context);

                        if (i < 3)
                        {
                            Extension(context);
                            var Display = context.Transactions.Where
                                              (x => x.BookID == txBookID.Text && x.MemberID == txMemberID.Text).Select(x => new { x.TransactionID, x.BookID, x.MemberID, x.ReturnDate, x.IssueDate, x.DueDate, x.ExtensionCount, x.LoanStatus, x.Remarks });

                            GV.DataSource = Display.ToList(); // DataGridView
                        }
                        else
                        {
                            txSuccess.Text = "Extension Limit Reached";
                        }
                    }
                    else
                    {
                        txSuccess.Text = "Wrong Input!";
                    }
                }
                else
                {
                    txSuccess.Text = "Wrong Input!";
                }
            }
        }
        public frmCustomerInformation()
        {
            InitializeComponent();

            context = new GalaxyEntities();

            btnBorrow.Enabled   = false;
            btnPay.Enabled      = false;
            btnRetrieve.Enabled = false;
            btnUpdate.Enabled   = false;
            btnReturn.Enabled   = false;
            btnConfirm.Enabled  = false;
            btnCancel.Enabled   = false;
            btnAdd.Enabled      = true;

            groupBoxReadOnly(true);

            // Display first customer by default
            position    = 0;
            membersList = context.Members.ToList();
            m           = membersList[position];
            display(m);
        }
        private void btnRetrieve_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();

            if (txmemberID.Text.Length == 5 && txmemberID.Text.Substring(0, 1) == "M")
            {
                if (Convert.ToInt32(txmemberID.Text.Substring(1, 4)) >= 1000 && Convert.ToInt32(txmemberID.Text.Substring(1, 4)) <= ctx.Members.Count() + 999)
                {
                    Member c = ctx.Members.Where(x => x.MemberID == txmemberID.Text).First();
                    txmemberID.Text = c.MemberID.ToString();
                    txName.Text     = c.Name.ToString();
                    txCategory.Text = c.MemberCategory.ToString();
                    txFine.Text     = c.FineAmount.ToString();
                }
                else
                {
                    MessageBox.Show("This format of input is right but this member is not existing!");
                }
            }
            else
            {
                MessageBox.Show("You input the wrong format! You can check the notice and input again!");
            }
        }
 public frm4BooksDetailForMember()
 {
     InitializeComponent();
     context = new GalaxyEntities();
 }
Пример #20
0
 private void frmRetrieve_Load(object sender, EventArgs e)
 {
     context      = new GalaxyEntities();
     selectedBook = new Book();
 }
Пример #21
0
 //methods
 private IQueryable <Member> LecturerValidation(GalaxyEntities context)
 {
     return(context.Members.Where(x => x.MemberID == txMemberID.Text && x.MemberCategory == "Lecturer"));
 }
Пример #22
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            using (GalaxyEntities context = new GalaxyEntities()) {
                txMemberID.Text.Trim();
                txBookID.Text.Trim();

                if (txMemberID.Text.Length == 5 && txMemberID.Text.Substring(0, 1) == "M" &&
                    Convert.ToDouble(txMemberID.Text.Substring(1, 4)) >= 1000 && Convert.ToDouble(txMemberID.Text.Substring(1, 4)) <= context.Members.Count() + 999)
                {
                    if (txBookID.Text.Length == 5 && txBookID.Text.Substring(0, 1) == "G" && Convert.ToDouble(txBookID.Text.Substring(1, 4)) >= 1 && Convert.ToDouble(txBookID.Text.Substring(1, 4)) <= context.Books.Count())
                    {
                        int i = TotalBookStockValidation(context);

                        if (i > 0)
                        {
                            var count    = context.Transactions.Where(x => x.MemberID == txMemberID.Text && x.LoanStatus == "Borrowed").Count();
                            var Lecturer = context.Members.Where(x => x.MemberID == txMemberID.Text && x.MemberCategory == "Lecturer");

                            if (count <= 3)
                            {
                                Transaction t = new Transaction();
                                t.TransactionID = (context.Transactions.Count() + 1);
                                t.BookID        = txBookID.Text;
                                t.MemberID      = txMemberID.Text;
                                t.IssueDate     = DateTime.Today.Date;
                                t.DueDate       = DateTime.Now.AddDays(10);
                                t.LoanStatus    = "";
                                context.Transactions.Add(t);
                                context.SaveChanges();

                                DateTime r = DateTime.Today;

                                Transaction t1 = context.Transactions.Where
                                                     (x => x.MemberID == txMemberID.Text && x.BookID == txBookID.Text).First();
                                if (Lecturer != null) //Lecturers loan duration is 20 compared to 10
                                {
                                    t1.DueDate = DateTime.Today.Date.AddDays(20);
                                }
                                else
                                {
                                    t1.DueDate = DateTime.Now.AddDays(10);
                                }
                                Book b1 = new Book();
                                b1 = context.Books.Where(x => x.BookID == txBookID.Text).First();
                                b1.NumberBorrowed += 1;
                                b1.TotalStock     -= 1;
                                Member a = new Member();
                                a = context.Members.Where(x => x.MemberID == txMemberID.Text).First();
                                a.CurrentBorrowing += 1;
                                t.LoanStatus        = "Borrowed";
                                context.SaveChanges();
                                GV.DataSource = context.Transactions.Where(x => x.LoanStatus == "Borrowed" && x.MemberID == txMemberID.Text).
                                                Select(x => new { x.TransactionID, x.BookID, x.MemberID, x.ReturnDate, x.IssueDate, x.DueDate, x.ExtensionCount, x.LoanStatus, x.Remarks }).
                                                ToList();
                            }
                            else
                            {
                                txSuccess.Text = "Borrowing Limit Reached";
                            }
                        }
                        else
                        {
                            txSuccess.Text = "Book Currently Unavailable!";
                        }
                    }
                    else
                    {
                        txSuccess.Text = "Wrong input!";
                    }
                }
                else
                {
                    txSuccess.Text = "Wrong Input!";
                }
            }
        }
Пример #23
0
 private void frmBookModify_Load(object sender, EventArgs e)
 {
     context = new GalaxyEntities();
     readOnlyFields();
 }
Пример #24
0
 private bool TotalBorrowCount(GalaxyEntities context)
 {
     return(txBookID.Text.Length == 5 && txBookID.Text.Substring(0, 1) == "G" && Convert.ToDouble(txBookID.Text.Substring(1, 4)) >= 1 && Convert.ToDouble(txBookID.Text.Substring(1, 4)) <= context.Books.Count());
 }
Пример #25
0
 private bool UsernamePasswordisValid(GalaxyEntities context)
 {
     return(txMemberID.Text.Length == 5 && txMemberID.Text.Substring(0, 1) == "M" &&
            Convert.ToInt32(txMemberID.Text.Substring(1, 4)) >= 1000 && Convert.ToInt32(txMemberID.Text.Substring(1, 4)) <= context.Members.Count() + 999);
 }