Example #1
0
 public override void AddData()
 {
     FormEditMember frm = new FormEditMember(m_connection);
     frm.LoadOrganizations();
     DialogResult res = frm.ShowDialog();
     if (res == DialogResult.OK)
     {
         try
         {
             string sql = @"INSERT INTO members
                 (ticket_number, fname, lname, mname, reg_date, nationality, birth_date, address, phone,
                  sign_date, foto, id_org, passport_sn, passport_number, passport_issuer, passport_date,
                  pension_card_number, pension_card_date, disability_group, disability_cause, point_system, welfare,
                  martial_status, education, speciality, employer, position, employer_last, position_last,
                  social_impact, affiliation_fee, affiliation_date, idcode, extra_injury,
                  family_members, org_relations, payments, welfare_assistance)
                 VALUES (@ticket_number, @fname, @lname, @mname, @reg_date, @nationality, @birth_date, @address, @phone,
                         @sign_date, @foto, @id_org, @passport_sn, @passport_number, @passport_issuer, @passport_date,
                         @pension_card_number, @pension_card_date, @disability_group, @disability_cause, @point_system, @welfare,
                         @martial_status, @education, @speciality, @employer, @position, @employer_last, @position_last,
                         @social_impact, @affiliation_fee, @affiliation_date, @idcode, @extra_injury,
                         @family_members, @org_relations, @payments, @welfare_assistance)";
             MySqlCommand cmd = new MySqlCommand(sql, m_connection);
             AddFormEditMemberSQLParams(cmd, frm);
             int rows_affected = cmd.ExecuteNonQuery();
             RefreshData(cmd.LastInsertedId);
         }
         catch (MySql.Data.MySqlClient.MySqlException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     frm.Close();
 }
Example #2
0
        public override void EditData()
        {
            DataGridViewRow row = dgMembers.CurrentRow;
            long id = Convert.ToInt64(row.Cells["id"].Value);

            FormEditMember frm = new FormEditMember(m_connection);
            frm.LoadOrganizations();

            try
            {
                string sql_select = @"SELECT * FROM members WHERE id=@id";
                MySqlCommand cmd_select = new MySqlCommand(sql_select, m_connection);
                cmd_select.Parameters.AddWithValue("@id", id);
                MySqlDataReader rdr = cmd_select.ExecuteReader();
                if (rdr.Read())
                {
                    LoadFormEditMemberFromSQL(frm, rdr);
                    rdr.Close();

                    DialogResult res = frm.ShowDialog();
                    if (res == System.Windows.Forms.DialogResult.OK)
                    {
                        string sql_update = @"UPDATE members SET
                         ticket_number=@ticket_number, fname=@fname, lname=@lname, mname=@mname, reg_date=@reg_date,
                         nationality=@nationality, birth_date=@birth_date, address=@address, phone=@phone, sign_date=@sign_date,
                         foto=@foto, id_org=@id_org, passport_sn=@passport_sn, passport_number=@passport_number,
                         passport_issuer=@passport_issuer, passport_date=@passport_date, pension_card_number=@pension_card_number,
                         pension_card_date=@pension_card_date, disability_group=@disability_group, disability_cause=@disability_cause,
                         point_system=@point_system, welfare=@welfare, martial_status=@martial_status, education=@education,
                         speciality=@speciality, employer=@employer, position=@position, employer_last=@employer_last,
                         position_last=@position_last, social_impact=@social_impact, affiliation_fee=@affiliation_fee,
                         affiliation_date=@affiliation_date, idcode=@idcode, extra_injury=@extra_injury,
                         family_members=@family_members, org_relations=@org_relations, payments=@payments,
                         welfare_assistance=@welfare_assistance
                        WHERE id=@id";
                        MySqlCommand cmd_update = new MySqlCommand(sql_update, m_connection);
                        cmd_update.Parameters.AddWithValue("@id", id);
                        AddFormEditMemberSQLParams(cmd_update, frm);
                        int rows_affected = cmd_update.ExecuteNonQuery();
                        RefreshData(id);
                    }
                }
                else
                    MessageBox.Show(String.Format("There is no member data with id={0}!", id), "Error");

            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                MessageBox.Show(ex.Message);
            }

            frm.Close();
        }