コード例 #1
0
        private void addItemBtn_Click(object sender, EventArgs e)
        {
            string itemCode = addItemCodeTxt.Text;
            string itemQty  = addItemQty.Text;

            List <MySqlParameter> paramList = new List <MySqlParameter>();

            paramList.Add(new MySqlParameter("@itemCode", itemCode));
            int returnedRowCount = DatabaseHandler.returnRowCount("SELECT*FROM STORE WHERE item_code=@itemCode", paramList);

            if (returnedRowCount != 0)
            {
                //Get Item Name from DB
                paramList.Clear();
                paramList.Add(new MySqlParameter("@itemCode", itemCode));
                string itemName = DatabaseHandler.returnOneValue("SELECT item_name as 'Item Name' from STORE where item_code=@itemCode", paramList, "Item Name");


                //Add to dataViewGrid4
                int index = dataGridView4.DisplayedRowCount(true);
                dataGridView4.Rows.Add();
                Console.WriteLine("In Add Btn: Current Index: " + index);
                dataGridView4.Rows[index - 1].Cells[0].Value = itemCode;
                dataGridView4.Rows[index - 1].Cells[1].Value = itemName;
                dataGridView4.Rows[index - 1].Cells[2].Value = itemQty;

                supplierComboBox.Enabled = false;
            }
            else
            {
                MessageBox.Show("Invalid Item Code!");
            }
        }
コード例 #2
0
        private void manualSubstractBtn_Click(object sender, EventArgs e)
        {
            List <MySqlParameter> paramList = new List <MySqlParameter>();

            paramList.Clear();
            paramList.Add(new MySqlParameter("@itemCode", manualProductId.Text));
            int returnedRowCount = DatabaseHandler.returnRowCount("SELECT * FROM STORE WHERE item_code = @itemCode", paramList);

            if (returnedRowCount == 1)
            {
                try
                {
                    List <MySqlParameter> paramList3 = new List <MySqlParameter>();
                    paramList3.Clear();
                    paramList3.Add(new MySqlParameter("@itemCode", manualProductId.Text));
                    paramList3.Add(new MySqlParameter("@value", manualQty.Text));
                    string queryGetQtyCondition = "SELECT IF(qty >= @value,'Yes','No') AS possibility FROM STORE WHERE item_code = @itemCode";
                    string possibility          = DatabaseHandler.returnOneValue(queryGetQtyCondition, paramList3, "possibility");
                    Console.WriteLine("String Possobility " + possibility);
                    if (string.Compare(possibility, "Yes") == 0)
                    {
                        Console.WriteLine("String Possobility Inside If ");
                        try
                        {
                            List <MySqlParameter> paramList2 = new List <MySqlParameter>();
                            paramList2.Clear();
                            paramList2.Add(new MySqlParameter("@itemQty", manualQty.Text));
                            paramList2.Add(new MySqlParameter("@itemCode", manualProductId.Text));
                            int responseChange = DatabaseHandler.insertOrDeleteRow("UPDATE STORE SET qty = qty - @itemQty WHERE item_code = @itemCode", paramList2);
                            if (responseChange == 1)
                            {
                                MessageBox.Show("Update Successful");
                            }
                            else
                            {
                                MessageBox.Show("Error Occured!");
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Error Occured!");
                        }
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show("Sorry, Invalid Item Code");
                }
            }
            else
            {
                MessageBox.Show("Sorry, Invalid Item Code");
            }
            populateGrid();
        }
コード例 #3
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            string itemCode;
            string itemQty;
            string itemName;

            try
            {
                itemCode = dataGridView5.SelectedRows[0].Cells["Item Code"].Value.ToString();
            }
            catch (Exception)
            {
                itemCode = null;
            }

            if (itemCode == null)
            {
                MessageBox.Show("Invalid Selection!");
            }
            else
            {
                itemQty = qtyTxt.Text;

                List <MySqlParameter> paramlist = new List <MySqlParameter>();
                paramlist.Clear();
                paramlist.Add(new MySqlParameter("@itemCode", itemCode));
                paramlist.Add(new MySqlParameter("@value", itemQty));
                string queryGetQtyCondition = "SELECT IF(qty >= @value,'Yes','No') AS possibility FROM STORE WHERE item_code = @itemCode";
                string possibility          = DatabaseHandler.returnOneValue(queryGetQtyCondition, paramlist, "possibility");

                if (string.Compare(possibility, "Yes") == 0)
                {
                    itemName = dataGridView5.SelectedRows[0].Cells["Item Name"].Value.ToString();


                    //Add to dataViewGrid4
                    int index = dataGridView4.DisplayedRowCount(true);
                    dataGridView4.Rows.Add();
                    Console.WriteLine("In Add Btn: Current Index: " + index);
                    dataGridView4.Rows[index - 1].Cells[0].Value = itemCode;
                    dataGridView4.Rows[index - 1].Cells[1].Value = itemName;
                    dataGridView4.Rows[index - 1].Cells[2].Value = itemQty;
                }
                else
                {
                    MessageBox.Show("Stocks aren't available for the quantity required!");
                }
            }
        }
コード例 #4
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            List <MySqlParameter> paramList = new List <MySqlParameter>();

            paramList.Add(new MySqlParameter("@username", usernameTxt.Text));
            paramList.Add(new MySqlParameter("@password", passwordTxt.Text));
            int returnedRowCount = DatabaseHandler.returnRowCount("SELECT*FROM USER WHERE username=@username and password=@password", paramList);

            if (returnedRowCount == 1)
            {
                GlobalLoginData.username = usernameTxt.Text;
                paramList.Clear();
                paramList.Add(new MySqlParameter("@username", usernameTxt.Text));
                GlobalLoginData.userRole = DatabaseHandler.returnOneValue("SELECT role FROM USER WHERE username = @username", paramList, "role");

                this.Hide();
                Dashboard dash = new Dashboard();
                dash.Show();
            }
            else
            {
                MessageBox.Show("Invalid Credentials, Please Try Again!");
            }
        }