private void btnSave2_Click(object sender, EventArgs e)
        {
            CashBenefit cb = new CashBenefit();

            cb.approved_benefit = cash_approved_benefit.Text;
            cb.price = (float)Convert.ToDouble(cash_issued_price.Text);
            cb.setdate_issued(cash_issued_date.Value.Date);

            bool state = BenefitsHandler.addCashBenefit(cb);

            if (state)
            {
                MessageBox.Show("Employee Cash Benefit details added succesfully...!");

            }
            else
            {
                MessageBox.Show("Adding employee Cash Benefit details failed...!");
            }
        }
        public static bool addCashBenefit(CashBenefit cb)
        {
            DBConnector dbcon = new DBConnector();
                if (dbcon.openConnection())
                {
                    MySqlCommand cmd = new MySqlCommand();
                    cmd.CommandText = "INSERT INTO cash_benefit (approved_benefit, date_issued, price, employee_idemployee) VALUES (N'" + cb.approved_benefit + "', '" + cb.getdate_issued().ToString("yyyy-MM-dd") + "', " + cb.price + ", " + Employee.employee_id + ")";
                    cmd.Connection = dbcon.connection;
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();

                    dbcon.closeConnection();
                    return true;
                }
                else
                {
                    dbcon.closeConnection();
                    return false;
                }
        }
        public static CashBenefit getCashBenefit()
        {
            DBConnector dbcon = new DBConnector();

            if (dbcon.openConnection())
            {

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "SELECT * FROM cash_benefit WHERE employee_idemployee=" + Employee.employee_id;
                cmd.Connection = dbcon.connection;

                MySqlDataReader reader = cmd.ExecuteReader();

                CashBenefit cb = null;

                if (reader.Read())
                {
                    cb = new CashBenefit();

                    cb.cb_id = int.Parse(reader["idcash_benefit"].ToString());
                    cb.approved_benefit = reader["approved_benefit"].ToString();
                    cb.price = (float)Convert.ToDouble(reader["price"].ToString());
                    cb.setdate_issued(Convert.ToDateTime(reader["date_issued"]));
                }

                reader.Close();

                dbcon.closeConnection();

                return cb;
            }
            else
            {

                return null;
            }
        }
Ejemplo n.º 4
0
        public void updateBenefits()
        {
            CashBenefit cb = new CashBenefit();
            cb.cb_id = this.cb_id;
            cb.approved_benefit = this.cash_approved_benefit.Text;
            cb.price = (float)Convert.ToDouble(this.cash_issued_price.Text);
            cb.setdate_issued(this.cash_issued_date.Value.Date);
            bool state = BenefitsHandler.updateCashBenefit(cb);
            Console.Write(state + "\n");

            NonCashBenefit ncb = new NonCashBenefit();
            ncb.ncb_id = this.ncb_id;
            ncb.approved_benefit = this.noncash_approved_benefit.Text;
            ncb.price = (float)Convert.ToDouble(this.noncash_price.Text);
            ncb.amount = (float)Convert.ToDouble(this.noncash_quantity.Text);
            ncb.setdate_issued(this.noncash_issued_date.Value.Date);
            state = BenefitsHandler.updateNonCashBenefit(ncb);
            Console.Write(state + "\n");
        }
        public static bool updateCashBenefit(CashBenefit cb)
        {
            DBConnector dbcon = new DBConnector();

            if (dbcon.openConnection())
            {

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "UPDATE cash_benefit SET approved_benefit=N'" + cb.approved_benefit + "', date_issued='" + cb.getdate_issued().ToString("yyyy-MM-dd") + "', price=" + cb.price + " WHERE employee_idemployee=" + Employee.employee_id + " AND idcash_benefit=" + cb.cb_id;
                cmd.Connection = dbcon.connection;
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                dbcon.closeConnection();

                return true;
            }
            else
            {

                return false;
            }
        }