Exemple #1
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            //first check if we have enough qty

            if (charger_quantity < 0)
            {
                lbLoan_Status.Text      = "Excuse! this item is out of stock !";
                lbLoan_Status.ForeColor = Color.Red;
            }
            else if (camera_quantity < 0)
            {
                lbLoan_Status.Text      = " Excuse! this item is out of stock !";
                lbLoan_Status.ForeColor = Color.Red;
            }
            else if (googles_quantiy < 0)
            {
                lbLoan_Status.Text      = "Excuse! this item is out of stock !";
                lbLoan_Status.ForeColor = Color.Red;
            }
            else if (bicycle_quantity < 0)
            {
                lbLoan_Status.Text      = "Excuse! this item is out of stock !";
                lbLoan_Status.ForeColor = Color.Red;
            }

            else
            {
                try
                {
                    if (lbRfid_Status.Text != "")
                    {
                        dataHelper = new Mysql();

                        List <string> itemsToLoan = new List <string>();
                        foreach (string item in lb_Receipt_info.Items)
                        {
                            itemsToLoan.Add(item);
                        }

                        string status = dataHelper.LoanItemToVisitor(rfid_Code, itemsToLoan, total_Price);

                        if (status == "Check your balance")
                        {
                            lbLoan_Status.Text      = "Not enough balance !";
                            lbLoan_Status.ForeColor = Color.Red;
                            List <string> items = new List <string>();
                            foreach (string item in lb_Receipt_info.Items)
                            {
                                items.Add(item);
                            }
                            foreach (string item in items)
                            {
                                lb_Receipt_info.SelectedItem = item;
                                btnRemove.PerformClick();
                            }
                        }
                        else if (status == "There is no user")
                        {
                            lbLoan_Status.Text      = "Invalid User !";
                            lbLoan_Status.ForeColor = Color.Red;
                            List <string> items = new List <string>();
                            foreach (string item in lb_Receipt_info.Items)
                            {
                                items.Add(item);
                            }
                            foreach (string item in items)
                            {
                                lb_Receipt_info.SelectedItem = item;
                                btnRemove.PerformClick();
                            }
                        }
                        else if (status == "added")
                        {
                            lblLoanStatus.Text = "Successfully Loaned!";
                            //MessageBox.Show("Successfully Loaned!");
                            lblLoanStatus.ForeColor = Color.Green;
                            lb_Receipt_info.Items.Clear();
                            //MessageBox.Show(" sellected item has successfully loaned");
                        }
                        else
                        {
                            // string status = dataHelper.LoanItemToVisitor(rfid_Code, itemsToLoan, total_Price);
                            MessageBox.Show($"{status}");
                            lblLoanStatus.Text      = "Something happened , please try again !";
                            lblLoanStatus.ForeColor = Color.Red;
                        }
                        lbRfid_Status.Text = "";
                        total_Price        = 0;
                        lbPrice.Text       = "";
                    }
                    else
                    {
                        lblLoanStatus.Text      = "Please Scan the Visitor's RFID Chip first !";
                        lblLoanStatus.ForeColor = Color.Red;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }