Beispiel #1
0
        private void buttonUsersDelete_Click(object sender, EventArgs e)
        {
            UIConfirmation confirmation = new UIConfirmation("Are you sure?", "Yes", "Cancel");

            confirmation.ShowDialog();

            if (dataGridUsers.SelectedRows.Count < 1)
            {
                UIError error1 = new UIError("Please select a user", "OK");
                error1.ShowDialog();
            }
            else if (dataGridUsers.SelectedRows.Count > 1)
            {
                UIError error2 = new UIError("Select only ONE user", "OK");
                error2.ShowDialog();
            }
            else
            {
                if (confirmation.isConfirmed)
                {
                    //DELETE ROW
                    foreach (DataGridViewCell oneCell in dataGridUsers.SelectedCells)
                    {
                        if (oneCell.Selected)
                        {
                            int rowIndex = oneCell.RowIndex;
                            selectedRow = dataGridUsers.Rows[rowIndex].Cells[0].Value.ToString();
                            log.RunQuery(2, "UserAccounts ", "", "username="******"\'" + selectedRow + "\'", "");
                            viewUsers();
                        }
                    }
                    dataGridUsers.CurrentCell.Selected = false;
                }
            }
        }
Beispiel #2
0
        private void buttonEditUserEdit_Click(object sender, EventArgs e)
        {
            UIConfirmation confirmation = new UIConfirmation("Are you sure?", "Yes", "Cancel");

            confirmation.ShowDialog();

            if (confirmation.isConfirmed)
            {
                //UPDATE DATABASE TO NEW VALUES
                string newUsername    = textEditUserUsername.Text;
                string newPassword    = textEditUserPassword.Text;
                string newPermissions = textEditUserPermissions.Text;

                if (textEditUserUsername.Text == "")
                {
                    newUsername = _username;
                }

                if (textEditUserPassword.Text == "")
                {
                    newPassword = _password;
                }

                if (textEditUserPermissions.Text == "")
                {
                    newPermissions = _permissions;
                }
                string queryString = "username="******"\'" + newUsername + "\'" + "," + "password ="******"\'" + newPassword + "\'" + "," + "permissions = " + "\'" + newPermissions + "\'";
                log.RunQuery(4, "UserAccounts", "", "username="******"\'" + _selectedRow + "\'", queryString);
                this.Close();
            }
        }
Beispiel #3
0
        private void buttonNewUserCreate_Click(object sender, EventArgs e)
        {
            UIConfirmation confirmation = new UIConfirmation("Create new User?", "Create", "Cancel");

            confirmation.ShowDialog();

            if (confirmation.isConfirmed)
            {
                //check if fields are empty
                if (textNewUserUsername.Text == "" || textNewUserPassword.Text == "" || textNewUserPermissions.Text == "")
                {
                    UIError error = new UIError("Please fill all fields", "OK");
                    error.ShowDialog();
                }
                else
                {
                    //INSERT new user into UserAccounts Table in DATABASE
                    string username    = textNewUserUsername.Text;
                    string password    = textNewUserPassword.Text;
                    string permissions = textNewUserPermissions.Text;
                    log.RunQuery(3, "UserAccounts", "username, password, permissions", "", "\'" + username + "\'" + "," + "\'" + password + "\'" + "," + "\'" + permissions + "\'");
                    this.Close();
                }
            }
        }
Beispiel #4
0
        private void buttonEditInventoryEdit_Click(object sender, EventArgs e)
        {
            UIConfirmation confirmation = new UIConfirmation("Are you sure?", "Yes", "Cancel");

            confirmation.ShowDialog();

            if (confirmation.isConfirmed)
            {
                //UPDATE DATABASE TO NEW VALUES
                string newCategory = textInventoryCategory.Text;
                string newItemName = textInventoryItem.Text;
                string newCost     = textInventoryCost.Text;
                string newPrice    = textInventoryPrice.Text;
                string newQty      = textInventoryQty.Text;

                if (textInventoryCategory.Text == "")
                {
                    newCategory = _itemCategory;
                }

                if (textInventoryItem.Text == "")
                {
                    newItemName = _itemName;
                }

                if (textInventoryCost.Text == "")
                {
                    newCost = _itemCost;
                }

                if (textInventoryPrice.Text == "")
                {
                    newPrice = _itemPrice;
                }

                if (textInventoryQty.Text == "")
                {
                    newQty = _itemQty;
                }

                string queryString = "category=" + "\'" + newCategory + "\'" + "," + "itemName =" + "\'" + newItemName + "\'" + "," + "costPerUnitBought = " + "\'" + newCost + "\'"
                                     + "," + "pricePerUnitSold = " + "\'" + newPrice + "\'"
                                     + "," + "quantity = " + "\'" + newQty + "\'";

                log.RunQuery(4, "Inventory", "", "itemID=" + "\'" + _itemID + "\'", queryString);
                this.Close();
            }
        }
Beispiel #5
0
        private void buttonPaymentConfirm_Click(object sender, EventArgs e)
        {
            //DATA VALIDATION
            Classes.DataValidation dataValidation = new Classes.DataValidation();
            bool amountIsValid = dataValidation.ValidateDouble(textPaymentAmount.Text);

            if (amountIsValid)
            {
                _amountPaid = Decimal.Parse(textPaymentAmount.Text);

                //check to see if amountPaid is greater than total
                if (_amountPaid >= _parentForm.SalesTotal)
                {
                    UIConfirmation confirmation = new UIConfirmation("Do you want to continue?", "Continue", "Cancel");
                    confirmation.ShowDialog();

                    if (confirmation.isConfirmed)
                    {
                        //Show change
                        UIChange change = new UIChange(this);
                        change.ShowDialog();
                        this.Close();

                        //INSERT into Sales table, dataTime & priceTotal
                        DateTime currentDateTime = DateTime.Now;
                        string   dateTime        = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                        string   priceTotal      = _parentForm.SalesTotal.ToString();
                        values = "\'" + dateTime + "\'" + "," + priceTotal;
                        log.RunQuery(3, "Sales", "dateTime, priceTotal", "", values);


                        //foreach row in dataGridSales, INSERT into ProductsSold (dateTime, productId, quantity)

                        foreach (DataRow dr in _parentForm.GetDataTable.Rows)
                        {
                            log.RunQuery(3, "ProductsSold", "datetime, itemid, quantity", "", "\'" + dateTime + "\', " + dr[5] + ", " + dr[2]);
                        }

                        //foreach row in dataGridSales, UPDATE Inventory table, quantity
                        foreach (DataRow dr in _parentForm.GetDataTable.Rows)
                        {
                            log.RunQuery(4, "Inventory", "", "itemid=" + dr[5], "quantity = quantity - " + dr[2]);
                        }

                        MySqlConnection sqlConn   = new MySqlConnection("datasource=35.198.212.34;port=3306;username=root;password=;database=dp2;sslmode=none");
                        MySqlCommand    callEvent = new MySqlCommand("call update_allRateOfSales();", sqlConn);
                        sqlConn.Open();

                        callEvent.ExecuteScalar();

                        callEvent = new MySqlCommand("call update_allDaysUntilDepletion();", sqlConn);

                        callEvent.ExecuteScalar();

                        callEvent = new MySqlCommand("call update_allDateToOrder();", sqlConn);

                        callEvent.ExecuteScalar();

                        sqlConn.Close();



                        //Clear dataGridSales
                        _parentForm.ClearData();
                    }
                }
                else
                {
                    UIError error = new UIError("Amount paid not sufficient", "OK");
                    error.ShowDialog();
                }
            }
            else
            {
                UIError error = new UIError("Please enter a valid amount", "OK");
                error.ShowDialog();
            }
        }