public static bool addMembership(Membership m)
        {
            DBConnector dbcon = new DBConnector();

            try
            {
                if (dbcon.openConnection())
                {
                    MySqlCommand cmd = new MySqlCommand();
                    cmd.CommandText = "INSERT INTO membership (institute, post_name, method, member_id, contribution, begin_date, renewal_date, status, personal_payment, active_date_person, institutional_payment, active_date_insti, employee_idemployee) VALUES (N'" + m.institute + "', N'" + m.post_name + "', N'" + m.method + "', N'" + m.member_id + "', N'" + m.contribution + "', '" + m.getBegin_date().ToString("yyyy-MM-dd") + "', '" + m.getRenewal_date().ToString("yyyy-MM-dd") + "', N'" + m.status + "', " + m.personal_payment + ", '" + m.getActive_date_person().ToString("yyyy-MM-dd") + "', " + m.institutional_payment + ", '" + m.getActive_date_insti().ToString("yyyy-MM-dd") + "', " + Employee.employee_id + ")";
                    cmd.Connection = dbcon.connection;
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();

                    dbcon.closeConnection();
                    return true;
                }
                else
                {
                    dbcon.closeConnection();
                    return false;
                }

            }
            catch (MySqlException e)
            {
                int errorcode = e.Number;
                dbcon.closeConnection();
                return false;
            }
        }
예제 #2
0
        public void updateMembership()
        {
            Membership m = new Membership();

            m.mem_id = this.mem_id;
            m.contribution = this.member_contribution.Text;
            m.institute = this.member_institute.Text;
            m.member_id = this.member_id.Text;
            m.post_name = this.memebr_post_name.Text;
            m.method = this.member_method.Text;

            m.setBegin_date(this.member_begin_date_date.Value.Date);
            m.setRenewal_date(this.member_renewal_date.Value.Date);
            m.setActive_date_insti(this.member_active_date_insti_date.Value.Date);
            m.setActive_date_person(this.member_active_date_person_date.Value.Date);

            if (this.member_institutional_payment.Checked) { m.institutional_payment = true; }
            else { m.institutional_payment = false; }

            if (this.member_personal_payment.Checked) { m.personal_payment = true; }
            else { m.personal_payment = false; }

            bool state = MembershipHandler.updateMembership(m);

            Console.Write(state + "\n");
        }
        private void btnSave4_Click(object sender, EventArgs e)
        {
            Membership m = new Membership();

            m.contribution = member_contribution.Text;
            m.institute = member_institute.Text;
            m.member_id = member_id.Text;
            m.post_name = memebr_post_name.Text;
            m.method = member_method.Text;

            m.setBegin_date(member_begin_date_date.Value.Date);
            m.setRenewal_date(member_renewal_date.Value.Date);
            m.setActive_date_insti(member_active_date_insti_date.Value.Date);
            m.setActive_date_person(member_active_date_person_date.Value.Date);

            if (member_institutional_payment.Checked) { m.institutional_payment = true; }
            else { m.institutional_payment = false; }

            if (member_personal_payment.Checked) { m.personal_payment = true; }
            else { m.personal_payment = false; }

            m.status = member_status.Text;

            bool status = MembershipHandler.addMembership(m);

            if (status)
            {
                MessageBox.Show("Membership details added successfully...!");
                //btnSave4.Enabled = true;
                //btnSave5.Enabled = true;
            }
            else { MessageBox.Show("Failed to add membership details...!"); }
        }
        public static Membership getMembership()
        {
            //try
            //{

            DBConnector dbcon = new DBConnector();

            if (dbcon.openConnection())
            {

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

                MySqlDataReader reader = cmd.ExecuteReader();

                Membership mem = null;

                if (reader.Read())
                {
                    mem = new Membership();

                    mem.mem_id = int.Parse(reader["idmembership"].ToString());
                    mem.contribution = reader["contribution"].ToString();
                    mem.institute = reader["institute"].ToString();
                    mem.member_id = reader["member_id"].ToString();
                    mem.method = reader["method"].ToString();
                    mem.post_name = reader["post_name"].ToString();
                    mem.status = reader["status"].ToString();

                    mem.setBegin_date(Convert.ToDateTime(reader["begin_date"]));
                    mem.setRenewal_date(Convert.ToDateTime(reader["renewal_date"]));
                    mem.setActive_date_insti(Convert.ToDateTime(reader["active_date_insti"]));
                    mem.setActive_date_person(Convert.ToDateTime(reader["active_date_person"]));

                    if (reader["institutional_payment"].ToString() == "True") { mem.institutional_payment = true; }
                    else { mem.institutional_payment = false; }

                    if (reader["personal_payment"].ToString() == "True") { mem.personal_payment = true; }
                    else { mem.personal_payment = false; }

                }

                reader.Close();

                dbcon.closeConnection();

                return mem;
            }
            else
            {

                return null;
            }

            //}
            //catch (MySqlException e)
            //{
            //int errorcode = e.Number;
            //return null;
            //}
        }
        public static bool updateMembership(Membership m)
        {
            //try
            //{

            DBConnector dbcon = new DBConnector();

            if (dbcon.openConnection())
            {

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "UPDATE membership SET institute=N'" + m.institute + "', post_name=N'" + m.post_name + "', method=N'" + m.method + "', member_id=N'" + m.member_id + "', contribution=N'" + m.contribution + "', begin_date='" + m.getBegin_date().ToString("yyyy-MM-dd") + "', renewal_date='" + m.getRenewal_date().ToString("yyyy-MM-dd") + "', status=N'" + m.status + "', personal_payment=" + m.personal_payment + ", active_date_person='" + m.getActive_date_person().ToString("yyyy-MM-dd") + "', institutional_payment=" + m.institutional_payment + ", active_date_insti='" + m.getActive_date_insti().ToString("yyyy-MM-dd") + "' WHERE employee_idemployee=" + Employee.employee_id + " AND idmembership=" + m.mem_id;
                cmd.Connection = dbcon.connection;
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                dbcon.closeConnection();

                return true;
            }
            else
            {

                return false;
            }

            //}
            //catch (MySqlException e)
            //{
            //int errorcode = e.Number;
            //return false;
            //}
        }