コード例 #1
0
ファイル: UISalesTransaction.cs プロジェクト: AydinSopian/DP2
        private void buttonSalesIncrement_Click(object sender, EventArgs e)
        {
            int     tempQty      = Convert.ToInt32(dt.Rows[selectedRowIndex][2]);;
            decimal tempSubTotal = Convert.ToDecimal(dt.Rows[selectedRowIndex][4]);

            bool rowSelected  = dataGridSales.SelectedRows.Count == 1 && dt.Rows.Count != 0;
            bool canIncrement = tempQty != selectedItemInventoryQty;

            if (rowSelected && canIncrement)
            {
                tempSubTotal += Convert.ToDecimal(dt.Rows[selectedRowIndex][3]);
                tempQty++;

                dt.Rows[selectedRowIndex][2] = tempQty;
                dt.Rows[selectedRowIndex][4] = tempSubTotal;

                setPriceTotal();
            }
            else
            {
                if (!rowSelected)
                {
                    UIComponents.UIError errorMessage = new UIComponents.UIError("Please select a row to increment.", "Okay");
                    errorMessage.ShowDialog();
                }
                if (!canIncrement)
                {
                    UIComponents.UIError errorMessage = new UIComponents.UIError("Qty exceeds inventory quantity.", "Okay");
                    errorMessage.ShowDialog();
                }
            }
        }
コード例 #2
0
ファイル: UIUsers.cs プロジェクト: AydinSopian/DP2
        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;
                }
            }
        }
コード例 #3
0
        public void RunQuery(int queryId, string tables, string columns, string condition, string values)
        {
            qDirector = new QueryDirector(qFactory.CreateQueryBuilder(queryId));

            qDirector.MakeQuery(tables, columns, condition, values);

            query = qDirector.GetQuery;

            try
            {
                using (dbConnect)
                    using (command = new MySqlCommand(query, dbConnect))
                    {
                        dbConnect.Open();
                        command.ExecuteNonQuery();
                        dbConnect.Close();
                    }
            }
            catch (Exception e)
            {
                UIComponents.UIError error = new UIComponents.UIError("Error, could not connect to server", "OK");
                error.ShowDialog();
                MessageBox.Show(query);
            }
        }
コード例 #4
0
        /// <summary>
        /// Runs the requested query
        /// </summary>
        /// <param name="id"></param>
        /// <param name="tables"></param>
        /// <param name="columns"></param>
        /// <param name="condition"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public DataTable RunSelectQuery(string tables, string columns, string condition)
        {
            DataTable dt = new DataTable();

            qDirector = new QueryDirector(new SelectQueryBuilder());
            qDirector.MakeQuery(tables, columns, condition, "");

            query = qDirector.GetQuery;

            try
            {
                using (dbConnect)
                    using (command = new MySqlCommand(query, dbConnect))
                        using (adp = new MySqlDataAdapter(command))
                        {
                            dbConnect.Open();
                            adp.Fill(dt);
                            dbConnect.Close();
                        }

                return(dt);
            }
            catch (Exception e)
            {
                UIComponents.UIError error = new UIComponents.UIError("Error, could not connect to server", "OK");
                error.ShowDialog();
                MessageBox.Show(query);
            }

            return(null);
        }
コード例 #5
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();
                }
            }
        }
コード例 #6
0
ファイル: UISalesTransaction.cs プロジェクト: AydinSopian/DP2
 private void buttonSalesCheckout_Click(object sender, EventArgs e)
 {
     if (dt.Rows.Count != 0)
     {
         //Open payment window
         UIComponents.UIPayment paymentWindow = new UIComponents.UIPayment(this);
         paymentWindow.ShowDialog();
         _salesTotal = 0;
         setPriceTotal();
     }
     else
     {
         UIComponents.UIError errorMessage = new UIComponents.UIError("Please enter items", "Okay");
         errorMessage.ShowDialog();
     }
 }
コード例 #7
0
ファイル: UISalesTransaction.cs プロジェクト: AydinSopian/DP2
        private void buttonSalesDelete_Click(object sender, EventArgs e)
        {
            if (dataGridSales.SelectedRows.Count == 1 && dt.Rows.Count != 0)
            {
                _rowNum      = 0;
                _salesTotal -= Convert.ToDecimal(dt.Rows[selectedRowIndex][4]);
                dt.Rows[selectedRowIndex].Delete();
                setPriceTotal();

                foreach (DataRow r in dt.Rows)
                {
                    _rowNum++;
                    r[0] = _rowNum;
                }
            }
            else
            {
                UIComponents.UIError errorMessage = new UIComponents.UIError("Please select a row to delete.", "Okay");
                errorMessage.ShowDialog();
            }
        }
コード例 #8
0
ファイル: UISalesTransaction.cs プロジェクト: AydinSopian/DP2
        private bool ValidateEntry(DataRow validationRow)
        {
            bool isValid = false;

            _colItem         = validationRow[0].ToString();
            _colPricePerUnit = Convert.ToDecimal(validationRow[1]);
            int inventoryQty = Convert.ToInt32(validationRow[2]);

            Classes.DataValidation dataValidation = new Classes.DataValidation();

            bool qtyIsValidType = dataValidation.ValidateInteger(textSalesQty.Text);

            if (qtyIsValidType)
            {
                _colQty      = int.Parse(textSalesQty.Text);
                _colSubtotal = Convert.ToDecimal(_colQty) * _colPricePerUnit;
                bool qtyIsValidNum = _colQty <= inventoryQty;

                if (qtyIsValidNum)
                {
                    isValid = true;
                }
                else
                {
                    UIComponents.UIError errorMessage = new UIComponents.UIError("Qty exceeds inventory quantity.", "Okay");
                    errorMessage.ShowDialog();
                }
            }
            else
            {
                UIComponents.UIError errorMessage = new UIComponents.UIError("Invalid Input. Please try again.", "Okay");
                errorMessage.ShowDialog();
            }

            return(isValid);
        }
コード例 #9
0
ファイル: UIPayment.cs プロジェクト: AydinSopian/DP2
        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();
            }
        }