Example #1
0
        private void EnterOwnerBtn_Click(object sender, EventArgs e)
        {
            SqlCommand    command;
            SqlDataReader dataReader;
            String        query;

            query = "Select * From LoginTable Where Username = '******' and Password = '******' and Type = 'Owner'";

            BookDBConn.Open();

            command    = new SqlCommand(query, BookDBConn);
            dataReader = command.ExecuteReader();

            if (dataReader.Read())
            {
                OwnerPage UserAccess = new OwnerPage();
                this.Hide();
                UserAccess.ShowDialog();
                this.Show();
            }
            else
            {
                MessageBox.Show("Username or Password are not valid!", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }


            BookDBConn.Close();
        }
Example #2
0
        private void BookStore_Load(object sender, EventArgs e)
        {
            SqlDataAdapter sda;
            String         query;
            DataTable      bookTable = new DataTable();

            query = "Select Title, Author, Genre, Publisher, ISBN, NumberOfPages, Price, Copies From Book";

            BookDBConn.Open();
            sda = new SqlDataAdapter(query, BookDBConn);
            sda.Fill(bookTable);
            BookInfoTable.DataSource = bookTable;
            BookDBConn.Close();
        }
Example #3
0
        private void TrackBtn_Click(object sender, EventArgs e)
        {
            String        q;
            SqlCommand    command;
            SqlDataReader sdr;

            if (TrackBtn.Text == "")
            {
                MessageBox.Show("Please enter a tracking number!", "No Tracking Number Entered!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            BookDBConn.Open();
            q       = "Select TrackingID From Sales Where TrackingID = '" + TrackingBox.Text + "'";
            command = new SqlCommand(q, BookDBConn);
            sdr     = command.ExecuteReader();
            if (!sdr.Read())
            {
                MessageBox.Show("The tracking number is invalid", TrackingBox.Text + " does not exists!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                BookDBConn.Close();
                return;
            }

            BookDBConn.Close();

            Random rand = new Random();
            int    ind  = rand.Next(6);

            if (Cities[ind] == "Toronto")
            {
                MessageBox.Show("The order has placed but not shipped yet", "Your order is at our warehouse in Toronto", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (Cities[ind] == "Ottawa")
            {
                MessageBox.Show("The order is already delivered, contact us if you haven't received it", "Your order is completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("The order is on the way, it is in " + Cities[ind] + " now", "Your order is shipped", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #4
0
        private void SearchBtn_Click(object sender, EventArgs e)
        {
            SqlDataAdapter sda;
            String         query;
            bool           sw        = false;
            DataTable      bookTable = new DataTable();

            query = "Select Title, Author, Genre, Publisher, ISBN, NumberOfPages, Price, Copies From Book Where ";

            if (AuthorBox.Text != "")
            {
                if (sw)
                {
                    query += "and ";
                }
                sw     = true;
                query += "Author = '" + AuthorBox.Text + "'";
            }

            if (TitleBox.Text != "")
            {
                if (sw)
                {
                    query += "and ";
                }
                sw     = true;
                query += "Title = '" + TitleBox.Text + "'";
            }

            if (GenreBox.Text != "")
            {
                if (sw)
                {
                    query += "and ";
                }
                sw     = true;
                query += "Genre = '" + GenreBox.Text + "'";
            }

            if (ISBNBox.Text != "")
            {
                if (sw)
                {
                    query += "and ";
                }
                sw     = true;
                query += "ISBN = '" + ISBNBox.Text + "'";
            }

            if (PublisherBox.Text != "")
            {
                if (sw)
                {
                    query += "and ";
                }
                sw     = true;
                query += "Publisher = '" + PublisherBox.Text + "'";
            }

            if (!sw)
            {
                MessageBox.Show("Please enter at least one field for search!", "Nothing to be searched", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            BookDBConn.Open();
            sda = new SqlDataAdapter(query, BookDBConn);
            sda.Fill(bookTable);
            BookInfoTable.DataSource = bookTable;
            BookDBConn.Close();
        }
Example #5
0
        private void CheckoutCartBtn_Click(object sender, EventArgs e)
        {
            DialogResult d = MessageBox.Show("Ready to go to checkout?", "Placing the order", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (d == DialogResult.Yes)
            {
                int    i;
                bool   sw = true;
                String query;

                Form3 addinfo = new Form3();
                this.Hide();
                addinfo.ShowDialog();
                this.Show();

                BookCart.Items.Clear();

                SqlCommand    command1;
                SqlCommand    command2;
                SqlDataReader dataReader;
                String        trackingNum = "";

                while (sw)
                {
                    Random rand = new Random();
                    trackingNum = "";

                    for (i = 0; i < 10; ++i)
                    {
                        trackingNum += rand.Next(10).ToString();
                    }

                    BookDBConn.Open();
                    query      = "Select * From Sales Where TrackingID = '" + trackingNum + "'";
                    command1   = new SqlCommand(query, BookDBConn);
                    dataReader = command1.ExecuteReader();
                    if (!dataReader.Read())
                    {
                        sw = false;
                    }
                    BookDBConn.Close();
                }

                for (i = 0; i < ISBNs.Count; ++i)
                {
                    BookDBConn.Open();
                    query      = "Select BookID, SoldCopies, Copies, WaitingTransfer From Book Where ISBN = '" + ISBNs[i] + "'";
                    command1   = new SqlCommand(query, BookDBConn);
                    dataReader = command1.ExecuteReader();

                    if (dataReader.Read())
                    {
                        int    nsc, nc, tc;
                        String bID;

                        bID = dataReader.GetValue(0).ToString();
                        nsc = Convert.ToInt32(dataReader.GetValue(1));
                        nc  = Convert.ToInt32(dataReader.GetValue(2));
                        tc  = Convert.ToInt32(dataReader.GetValue(3));

                        nsc += Copies[i];
                        tc  += Copies[i];
                        nc  -= Copies[i];

                        if (nc < 10)
                        {
                            MessageBox.Show("An order placed for book titled " + Titles[i] + " with ISBN = " + ISBNs[i], "Low on stock, placing order", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            nc += 50;
                        }

                        String upd, ins;

                        BookDBConn2.Open();
                        upd      = "UPDATE Book SET SoldCopies = " + nsc.ToString() + ", Copies = " + nc.ToString() + ", WaitingTransfer = " + tc.ToString() + " Where ISBN = '" + ISBNs[i] + "'";
                        command2 = new SqlCommand(upd, BookDBConn2);
                        command2.ExecuteNonQuery();
                        BookDBConn2.Close();

                        BookDBConn2.Open();
                        ins      = "INSERT INTO Sales (BookID, Copies, TrackingID, UserID) VALUES ('" + bID + "', " + Copies[i].ToString() + ", '" + trackingNum + "', '" + ID + "');";
                        command2 = new SqlCommand(ins, BookDBConn2);
                        command2.ExecuteNonQuery();
                        BookDBConn2.Close();
                    }

                    BookDBConn.Close();
                }


                MessageBox.Show("Your order has been placed, you can keep track of your order using this tracking number " + trackingNum, "Checkout was successful", MessageBoxButtons.OK, MessageBoxIcon.Information);

                SqlDataAdapter sda;
                DataTable      bookTable = new DataTable();

                BookDBConn.Open();

                query = "Select Title, Author, Genre, Publisher, ISBN, NumberOfPages, Price, Copies From Book";

                sda = new SqlDataAdapter(query, BookDBConn);
                sda.Fill(bookTable);
                BookInfoTable.DataSource = bookTable;
                BookDBConn.Close();
            }
        }