Beispiel #1
0
        private void generate()
        {
            depreciation = new Depreciation(
                Cost,
                salvageValue,
                lifeSpan,
                DateProcured
                );

            lblTotal.Text        = Format.formatToPeso(depreciation.getTotal());
            lblDepreciation.Text = Format.formatToPeso(depreciation.getDepreciation());

            try
            {
                double percentage = depreciation.getPercentage();
                Math.Round(percentage, 0);
                Math.Round((decimal)percentage, 0);

                gPercentage.Value  = Convert.ToInt32(percentage);
                lblPercentage.Text = percentage.ToString("0.00") + "%";
                if (isLost == false)
                {
                    dgvBookValues.DataSource = depreciation.getBookValues();
                    dgvBookValues.ClearSelection();
                }
                else
                {
                    int    years = depreciation.getYearsBeetween();
                    double bookValue = 0.0, discount = 0.0;

                    if (years > lifeSpan)
                    {
                        lblYear.ForeColor = Color.Red;
                        lblYear.Text      = years + " (exceed the expected lifespan) ";
                    }
                    else
                    {
                        bookValue    = depreciation.getCurrentBookValue();
                        discount     = (bookValue * 0.1) + bookValue;
                        lblYear.Text = years.ToString();
                    }

                    lblBookValue.Text = Format.formatToPeso(bookValue);
                    lblPlusten.Text   = Format.formatToPeso(discount);
                }
            }
            catch (Exception) { }
        }
Beispiel #2
0
        private void initCurrentBookValue()
        {
            Database.set("SELECT tbldepreciation.depreciation_id,tblitem.date_procured,tblitem.price,tbldepreciation.depreciation FROM tblitem INNER JOIN tbldepreciation ON tblitem.depreciation_id = tbldepreciation.depreciation_id;");
            DataTable table = new DataTable();

            table = Database.executeResultSet();

            foreach (DataRow row in table.Rows)
            {
                String id           = row["depreciation_id"].ToString();
                String dateProcured = row["date_procured"].ToString();
                double cost         = double.Parse(row["price"].ToString());
                double deprec       = double.Parse(row["depreciation"].ToString());
                double percentage   = 0.0;
                double bookValue    = Depreciation.getCurrentBookValue(dateProcured, cost, deprec);

                if (bookValue <= 0)
                {
                    bookValue = 0.00;
                }

                percentage = (bookValue / cost) * 100;

                using (MySql.Data.MySqlClient.MySqlConnection con = Database.getConnection())
                {
                    try
                    {
                        con.Open();
                        String sql = "UPDATE tbldepreciation SET book_value = @bookValue,current_percent = @currentPercent WHERE depreciation_id = @id;";
                        MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand(sql, con);
                        command.Parameters.AddWithValue("@bookValue", bookValue);
                        command.Parameters.AddWithValue("@currentPercent", percentage.ToString("N2"));
                        command.Parameters.AddWithValue("@id", id);
                        command.ExecuteNonQuery();
                    }
                    catch (MySql.Data.MySqlClient.MySqlException exception)
                    {
                        System.Windows.Forms.MessageBox.Show(exception.Message);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }