Example #1
0
 ///<summary>Create a new bill for a reservation</summary>
 private void btnOrderCreateInvoice_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult result = MessageBox.Show("Luodaanko valitulle varaukselle lasku?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (result == DialogResult.Yes)
         {
             int varaus_id = Convert.ToInt32(dgOrder.SelectedCells[0].Value);
             BillingUtils.CreateInvoice(varaus_id);
             BillingUtils.RefreshDataGridView(dgvBilling);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Odottamaton virhe. Laskun luonti ei onnistunut.", "Virhe", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #2
0
        ///<summary>Changes the tab to "laskut" and selects the row which has the parameter (varaus_id) reservation</summary>
        public static void GoToCreatedInvoice(int varaus_id)
        {
            rentCottage.tcMain.SelectedIndex = 5;
            BillingUtils.RefreshDataGridView(rentCottage.dgvBilling);

            //Search for the row which has the created bill
            int rowIndex = -1;

            foreach (DataGridViewRow row in rentCottage.dgvBilling.Rows)
            {
                if (row.Cells[1].Value.ToString().Equals(varaus_id.ToString()))
                {
                    rowIndex = row.Index;
                    break;
                }
            }
            //Select the row
            rentCottage.dgvBilling.CurrentCell = rentCottage.dgvBilling.Rows[rowIndex].Cells[0];
        }
Example #3
0
        private void btnBookAddResirvation_Click(object sender, EventArgs e) // new book adding
        {
            if (tbBookCustomerEmail.Text == "" || tbBookCustomerPhone.Text == "" || tbBookCustomerName.Text == "" ||
                tbBookCustomerLastname.Text == "" || tbBookCustomerPostnumber.Text == "" || tbBookCustomerPostOffice.Text == "" ||
                tbBookCustomerAddress.Text == "")
            {
                MessageBox.Show("Kaikki asiakastiedot pitäisi olla täyetty.", "Tiedot puuttuu", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return; // If some customer data not specified, cancel action
            }
            string queryCustomer, services = "\n\nLisäpalvelut:\n";

            if (customerid != 0) //If customer finded, update it
            {
                PostUtils.CheckPostal(tbBookCustomerPostnumber.Text, tbBookCustomerPostOffice.Text);

                ConnectionUtils.OpenConnection();
                MySqlCommand command = new MySqlCommand("SELECT toimipaikka FROM posti WHERE postinro='" +
                                                        tbBookCustomerPostnumber.Text + "'", ConnectionUtils.connection);
                tbBookCustomerPostOffice.Text = command.ExecuteScalar().ToString();
                ConnectionUtils.CloseConnection();

                queryCustomer = "START TRANSACTION; " +
                                "UPDATE asiakas SET etunimi='" + tbBookCustomerName.Text + "', sukunimi='" + tbBookCustomerLastname.Text + "', " +
                                "lahiosoite='" + tbBookCustomerAddress.Text + "', postinro='" + tbBookCustomerPostnumber.Text + "', " +
                                "email='" + tbBookCustomerEmail.Text + "', puhelinnro='" + tbBookCustomerPhone.Text + "' " +
                                "WHERE asiakas_id='" + customerid + "'; " +
                                "COMMIT;";
            }
            else // if customer not finded, add new
            {
                PostUtils.CheckPostal(tbBookCustomerPostnumber.Text, tbBookCustomerPostOffice.Text);
                queryCustomer = "START TRANSACTION; " +
                                "INSERT INTO asiakas(asiakas_id,postinro,etunimi,sukunimi,lahiosoite,email,puhelinnro) " +
                                "VALUES(default,'" + tbBookCustomerPostnumber.Text + "','" + tbBookCustomerName.Text +
                                "','" + tbBookCustomerLastname.Text + "','" + tbBookCustomerAddress.Text +
                                "','" + tbBookCustomerEmail.Text + "','" + tbBookCustomerPhone.Text + "'); " +
                                "COMMIT;";
            }
            foreach (DataGridViewRow row in dgvBookServices.Rows) // Get services
            {
                if (Convert.ToInt32(row.Cells["kpl"].Value) != 0)
                {
                    services += row.Cells["nimi"].Value.ToString() + " - " + row.Cells["kpl"].Value.ToString() + "kpl\n";
                }
            }
            if (services == "\n\nLisäpalvelut:\n") // If all services are 0, erase services
            {
                services = "";
            }
            // Book/order overview window
            DialogResult res = MessageBox.Show("\t\tYhteenveto \n\nMökki tiedot:" +
                                               "\nAlue: \t\t" + lblBookAlue.Text +
                                               "\nMökki ID: \t" + lblBookCottageId.Text +
                                               "\nMajoitusaika: \t" + lblBookBookingDateFrom.Text + " - " + lblBookBookingDateTo.Text + " " + lblBookDays.Text +
                                               "\nOsoite: \t\t" + lblBookCottageAddress.Text +
                                               "\n\nAsiakas tiedot: " + "\nNimi: \t\t" + tbBookCustomerName.Text + " " + tbBookCustomerLastname.Text +
                                               "\nOsoite: \t\t" + tbBookCustomerAddress.Text + ", " + tbBookCustomerPostnumber.Text + ", " + tbBookCustomerPostOffice.Text +
                                               "\nSähköposti: \t" + tbBookCustomerEmail.Text +
                                               "\nPuhelinnumero: \t" + tbBookCustomerPhone.Text +
                                               services +
                                               "\n\nSumma yhteensä: " + lblBookPriceFull.Text, "Yhteenveto", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (res == DialogResult.OK)
            {
                try
                {
                    ConnectionUtils.OpenConnection();
                    MySqlCommand command1 = new MySqlCommand(queryCustomer, ConnectionUtils.connection);
                    command1.ExecuteNonQuery(); // 1. add/update customer
                    string queryBook = MakeQueryBook();

                    ConnectionUtils.OpenConnection();
                    MySqlCommand command2 = new MySqlCommand(queryBook, ConnectionUtils.connection);
                    command2.ExecuteNonQuery(); // 2. get added/updated customer ID and make book
                    ConnectionUtils.CloseConnection();

                    ConnectionUtils.OpenConnection();
                    MySqlCommand command = new MySqlCommand("SELECT varaus_id FROM varaus WHERE asiakas_id LIKE '" +
                                                            customerid + "' AND mokki_mokki_id LIKE '" + lblBookCottageId.Text + "' AND varattu_alkupvm LIKE '" +
                                                            lblBookBookingDateFrom.Text + "%' AND varattu_loppupvm LIKE '" + lblBookBookingDateTo.Text + "%' ", ConnectionUtils.connection);
                    varausid = Convert.ToInt32(command.ExecuteScalar()); // get just added order ID
                    ConnectionUtils.CloseConnection();

                    if (services != "") // if services exists
                    {
                        string queryServices = MakeQueryServices();
                        ConnectionUtils.OpenConnection();
                        MySqlCommand command3 = new MySqlCommand(queryServices, ConnectionUtils.connection);
                        command3.ExecuteNonQuery(); // 3. get added order ID and add services to data table
                        ConnectionUtils.CloseConnection();
                        this.Close();
                    }
                    BillingUtils.CreateInvoice(varausid); // Make new billing
                    DialogResult result = MessageBox.Show("Varaus lisätty. Uusi lasku lisätty järjestelmään. Varaus id: " + varausid +
                                                          " \nSiirrytäänkö laskuun?", "Prosessi onnistui", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        BillingUtils.GoToCreatedInvoice(varausid);
                    }
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Tapahtunut virhe, yritä uudelleen. Virhe: \n\n\n" + ex, "Virhe", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (res == DialogResult.Cancel)
            {
            }
        }
Example #4
0
        ///<summary>All button events occurring on the "Laskut" tab.</summary>
        private void btnBilling_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            //Search for an invoice
            if (btn == btnBillingSearch)
            {
                PopulateDGVBilling();
            }

            //Update the state of payment of a selected invoice
            else if (btn == btnBillingPaid || btn == btnBillingNotPaid)
            {
                try
                {
                    string paymentDate;
                    if (btn == btnBillingPaid)
                    {
                        DateTime myDateTime = DateTime.Now;
                        paymentDate = myDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                        paymentDate = "'" + paymentDate + "'";
                    }
                    else
                    {
                        paymentDate = "NULL";
                    }

                    int selectedRow = dgvBilling.CurrentCell.RowIndex;
                    int lasku_id    = Convert.ToInt32(dgvBilling.SelectedCells[0].Value);
                    BillingUtils.SetPaymentState(lasku_id, paymentDate);
                    BillingUtils.RefreshDataGridView(dgvBilling);
                    dgvBilling.ClearSelection();
                    dgvBilling.CurrentCell = dgvBilling.Rows[selectedRow].Cells[0];
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Odottamaton virhe. Laskun maksutilanteen päivitys epäonnistui.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            //Delete a selected invoice
            else if (btn == btnBillingDelete)
            {
                DialogResult result = MessageBox.Show("Halutko varmasti poistaa valitun laskun?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    int lasku_id = Convert.ToInt32(dgvBilling.SelectedCells[0].Value);
                    BillingUtils.DeleteSelectedInvoice(lasku_id);
                    BillingUtils.RefreshDataGridView(dgvBilling);
                    dgvBilling.ClearSelection();
                }
            }

            //Create a PDF document of a selected bill
            else if (btn == btnBillingPDF)
            {
                try
                {
                    int lasku_id = Convert.ToInt32(dgvBilling.SelectedCells[0].Value);
                    BillingUtils.CreatePdfDocument(lasku_id);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("PDF:n muodostaminen epäonnistui. Onko aiempi lasku vielä auki?", "Virhe", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            //Show all invoices
            else if (btn == btnBillingShowAll)
            {
                txtboxBillingCustomerID.Text = "";
                txtboxBillingEmail.Text      = "";
                txtboxBillingInvoiceID.Text  = "";
                txtboxBillingLastname.Text   = "";
                txtboxBillingOrderID.Text    = "";
                txtboxBillingPhone.Text      = "";
                txtboxBillingSurname.Text    = "";
                cbBillingPaid.SelectedIndex  = 2;
                PopulateDGVBilling();
            }
        }