Exemplo n.º 1
0
        private void btnExpenditure_Click(object sender, EventArgs e)
        {
            frmExpenditure newForm = new frmExpenditure();

            newForm.Show();
            this.Hide();
        }
Exemplo n.º 2
0
        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to cancel? No changes will be saved.", "Confirmation", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                frmExpenditure newForm = new frmExpenditure();
                //newForm.clearDataGridView();
                //newForm.loadDataGridView();
                newForm.Show();
                this.Hide();
            }
        }
Exemplo n.º 3
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtAmount.Text) || string.IsNullOrWhiteSpace(txtDescription.Text))
            {
                MessageBox.Show("One or more fields are left empty. Please fill them up!", "Error");
                return;
            }

            double amount        = 0.0;
            bool   convertAmount = double.TryParse(txtAmount.Text, out amount);

            if (convertAmount == false)
            {
                MessageBox.Show("Please enter numbers in the Amount field!", "Error");
                return;
            }

            amount = Math.Round(amount, 2);
            string date        = dtpDate.Value.ToShortDateString();
            string description = txtDescription.Text;

            OleDbCommand    cmd = new OleDbCommand();
            OleDbConnection cn  = new OleDbConnection();

            cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Restaurant.accdb; Persist Security Info=False;";
            cmd.Connection      = cn;

            bool successful = false;

            try
            {
                //If loaded then UPDATE, if not loaded then INSERT
                if (loaded == true)
                {
                    string q = "UPDATE Cost SET costDesc='" + description + "', totalCost=" + amount + ", costDate='" + date + "' WHERE costID=" + costID;

                    cmd.CommandText = q;
                    cn.Open();

                    cmd.ExecuteNonQuery();

                    cn.Close();

                    MessageBox.Show("Record successfully edited! Returning to previous screen!", "Successful");
                    successful = true;
                }
                else
                {
                    string p = "SELECT Max(costID) FROM Cost";
                    cmd.CommandText = p;

                    cn.Open();

                    int maxId = 1;

                    if (cmd.ExecuteScalar() != DBNull.Value)
                    {
                        maxId = Convert.ToInt32(cmd.ExecuteScalar());
                        maxId = maxId + 1;
                    }

                    cn.Close();

                    string q = "INSERT INTO Cost(costID, costDesc, totalCost, costDate)" +
                               " VALUES(" + maxId + ",'" + description + "'," + amount + ",'" + date + "')";

                    cmd.CommandText = q;
                    cn.Open();

                    cmd.ExecuteNonQuery();

                    cn.Close();

                    MessageBox.Show("Record successfully added! Returning to previous screen!", "Successful");
                    successful = true;
                }
            }
            catch (Exception ex)
            {
                cn.Close();
                MessageBox.Show("Oops... Something went wrong. Please contact the admin to make sure everything's all right!", "Sorry");
            }

            if (successful == true)
            {
                frmExpenditure newForm = new frmExpenditure();
                newForm.Show();
                this.Hide();
            }
        }