Exemplo n.º 1
0
        /**
         * Event Handlers
         */
        private void AccountPlanForm_Load(object sender, EventArgs e)
        {
            // connect to DB
            cn = getSGBDConnection();
            if (!verifySGBDConnection())
            {
                return;
            }

            // get all account plans
            SqlCommand    cmd    = new SqlCommand("SELECT * FROM ACCOUNT_PLAN", cn);
            SqlDataReader reader = cmd.ExecuteReader();

            listBox1.Items.Clear();

            // load account plans
            while (reader.Read())
            {
                AccountPlan ap = new AccountPlan();
                ap.PlanCode            = reader["name"].ToString();
                ap.BenefitsDescription = reader["benefits_description"].ToString();
                listBox1.Items.Add(ap);
            }

            // close connection to BD
            cn.Close();

            // show first ACCOUNT_PLAN
            currentListEntry = 0;
            showEntry();
        }
Exemplo n.º 2
0
        private void submitEntry(AccountPlan ap)
        {
            if (!verifySGBDConnection())
            {
                return;
            }
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "INSERT ACCOUNT_PLAN (name, benefits_description) " +
                              "VALUES (@PlanCode, @BenefitsDescription) ";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@PlanCode", ap.PlanCode);
            cmd.Parameters.AddWithValue("@BenefitsDescription", ap.BenefitsDescription);
            cmd.Connection = cn;

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to update contact in database. \n ERROR MESSAGE: \n" + ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
Exemplo n.º 3
0
        /**
         * ACCOUNT_PLAN Data Handling Helper Functions
         */
        private bool saveAccountPlan()
        {
            AccountPlan ap = new AccountPlan();

            try
            {
                ap.PlanCode            = txtCode.Text;
                ap.BenefitsDescription = txtBenefits.Text;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
            if (adding)
            {
                submitEntry(ap);
                listBox1.Items.Add(ap);
            }
            else
            {
                updateAccountPlan(ap);
                listBox1.Items[currentListEntry] = ap;
            }
            return(true);
        }
Exemplo n.º 4
0
        /**
         * Interaction Helper Functions
         */
        // form field's content related
        private void showEntry()
        {
            if (listBox1.Items.Count == 0 | currentListEntry < 0)
            {
                return;
            }
            AccountPlan ap = new AccountPlan();

            ap               = (AccountPlan)listBox1.Items[currentListEntry];
            txtCode.Text     = ap.PlanCode;
            txtBenefits.Text = ap.BenefitsDescription;
            //txtNumAccounts.Text = 0;
        }
Exemplo n.º 5
0
        private void updateAccountPlan(AccountPlan ap)
        {
            int rows = 0;

            if (!verifySGBDConnection())
            {
                return;
            }
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "UPDATE ACCOUNT_PLAN " +
                              "SET benefits_description = @BenefitsDescription " +
                              "WHERE name = @PlanCode";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@PlanCode", ap.PlanCode);
            cmd.Parameters.AddWithValue("@BenefitsDescription", ap.BenefitsDescription);
            cmd.Connection = cn;

            try
            {
                rows = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to update contact in database. \n ERROR MESSAGE: \n" + ex.Message);
            }
            finally
            {
                if (rows == 1)
                {
                    MessageBox.Show("Update OK");
                }
                else
                {
                    MessageBox.Show("Update NOT OK");
                }

                cn.Close();
            }
        }