Ejemplo n.º 1
0
        private void btnregister_Click(object sender, EventArgs e)
        {
            //form data
            //retrieve data from textbox
            string name = txtname.Text;
            //combobox
            string gender = cbgender.SelectedItem.ToString();
            //radio button
            string membership = "";

            if (rbfree.Checked)
            {
                membership = rbfree.Text;
            }
            if (rbpaid.Checked)
            {
                membership = rbpaid.Text;
            }
            //checklistbox
            string shopping = "";

            foreach (var d in clbshop.CheckedItems)
            {
                shopping += d + ",";
            }
            //checkbox
            string cod = "";

            if (cbcod.Checked)
            {
                cod = "yes";
            }

            else
            {
                cod = "no";
            }
            string pass = txtpassword.Text;

            MessageBox.Show(name + "\n" + gender + "\n" + membership + "\n" + shopping + "\n" + cod + "\n" + pass);
            //insert data to db through entity framework

            RegisterShopping rs = new RegisterShopping();

            rs.Name               = name;
            rs.Gender             = gender;
            rs.Membership         = membership;
            rs.ShoppingPreference = shopping;
            rs.COD      = cod;
            rs.Password = pass;
            db.RegisterShoppings.Add(rs);
            var res = db.SaveChanges();

            if (res > 0)
            {
                MessageBox.Show("Data inserted");
            }
            this.registerShoppingTableAdapter.Fill(this.tRainingdbDataSet.RegisterShopping);
        }
Ejemplo n.º 2
0
        private void btnregister_Click(object sender, EventArgs e)
        {
            //form data
            string name = txtname.Text;

            string gender     = cbgender.SelectedItem.ToString();
            string membership = "";

            if (rbfree.Checked)
            {
                membership = rbfree.Text;
            }
            if (rbpaid.Checked)
            {
                membership = rbpaid.Text;
            }
            string preference = "";

            foreach (var d in clbshop.CheckedItems)
            {
                preference += d + ",";
            }
            string cod = "";

            if (cbcod.Checked)
            {
                cod = "Yes";
            }
            else
            {
                cod = "No";
            }
            string password = txtpassword.Text;

            MessageBox.Show(name + "\n" + gender + "\n" + membership + "\n" + preference + "\n" + cod + "\n" + password);

            //insert data to DB to entity frame work
            RegisterShopping rs = new RegisterShopping();

            rs.Name                = name;
            rs.Gender              = gender;
            rs.Membership          = membership;
            rs.Shopping_Preference = preference;
            rs.Cod      = cod;
            rs.Password = password;

            db.RegisterShoppings.Add(rs);
            var result = db.SaveChanges();

            if (result > 0)
            {
                MessageBox.Show("Data Inserted...");
            }
            this.registerShoppingTableAdapter.Fill(this.trainingDBDataSet.RegisterShopping);
        }