Exemple #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.MembersTabLayoutMain);



            //Create Member table
            string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "appdb.db3");
            var    db     = new SQLiteConnection(dpPath);

            db.CreateTable <MembersTable>();
            MembersTable tbl = new MembersTable();


            //var data = db.Table<MembersTable>();
            //var data1 = data.Where(x => x.id == 1).FirstOrDefault();
            //if (data1.id != null)
            //{
            //    db.Delete(data1);
            //    Toast.MakeText(this, "Delete Successfully", ToastLength.Short).Show();
            //}

            // Get our button from the layout resource,
            // and attach an event to it
            viewpager = FindViewById <Android.Support.V4.View.ViewPager>(Resource.Id.viewpager);

            var toolbar = FindViewById <V7Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);

            //SupportActionBar.SetIcon(Resource.Drawable.Icon);

            SupportActionBar.SetDisplayHomeAsUpEnabled(false);
            SupportActionBar.SetDisplayShowTitleEnabled(false);
            SupportActionBar.SetHomeButtonEnabled(false);

            if (viewpager.Adapter == null)
            {
                setupViewPager(viewpager);
            }
            else
            {
                viewpager.Adapter.NotifyDataSetChanged();
            }

            //var fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
            //fab.Click += (sender, e) => {
            //    // Show a snackbar
            //    Snackbar.Make(fab, "Here's a snackbar!", Snackbar.LengthLong).SetAction("Action",
            //        v => Console.WriteLine("Action handler")).Show();
            //};

            var tabLayout = FindViewById <TabLayout>(Resource.Id.tabs);

            tabLayout.SetupWithViewPager(viewpager);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var v = inflater.Inflate(Resource.Layout.MemberRegisterLayout, container, false);

            txtName            = v.FindViewById <EditText>(Resource.Id.txtMemberName);
            datePickerBirthDay = v.FindViewById <DatePicker>(Resource.Id.datePickerBirthday);
            radioGroupGend     = v.FindViewById <RadioGroup>(Resource.Id.radioGroupGender);
            radioGendReset     = v.FindViewById <RadioButton>(Resource.Id.radioButtonMale);
            radioGroupPreg     = v.FindViewById <RadioGroup>(Resource.Id.radioGroupPregnancy);
            radioPregReset     = v.FindViewById <RadioButton>(Resource.Id.radioButtonYes);
            txtDiseases        = v.FindViewById <EditText>(Resource.Id.txtDiseases);


            Button button = v.FindViewById <Button>(Resource.Id.btnMemberReg);

            button.Click += delegate
            {
                try
                {
                    string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "appdb.db3");
                    var    db     = new SQLiteConnection(dpPath);
                    // db.CreateTable<MembersTable>();
                    MembersTable tbl = new MembersTable();
                    tbl.name     = txtName.Text;
                    tbl.birthday = datePickerBirthDay.DateTime.ToString();
                    //RadioGroup use check Gender.
                    RadioButton checkedGender = v.FindViewById <RadioButton>(radioGroupGend.CheckedRadioButtonId);
                    if (checkedGender.Text == "Female")
                    {
                        tbl.gender = checkedGender.Text;
                    }
                    else
                    {
                        tbl.gender = checkedGender.Text;
                    }
                    //RadioGroup use Check Pregnat or not.
                    RadioButton checkedPreg = v.FindViewById <RadioButton>(radioGroupPreg.CheckedRadioButtonId);
                    if (checkedPreg.Text == "Yes")
                    {
                        tbl.pregnancy = checkedPreg.Text;
                    }
                    else
                    {
                        tbl.pregnancy = checkedPreg.Text;
                    }
                    tbl.diseases = txtDiseases.Text;


                    //SET MALE CHECKED THEN PREGNANCY RADIO GROUP ENABLE FALSE CODE SECTION
                    //if (radioGendReset.Checked == true)
                    //    radioGroupPreg.Enabled = false;
                    //else
                    //    radioGroupPreg.Enabled = true;

                    db.Insert(tbl);
                    Toast.MakeText(this.Activity, "Record Added Successfully...,", ToastLength.Short).Show();

                    //Reset all inputs for defalt value
                    txtName.Text           = "";
                    radioGendReset.Checked = true;
                    radioPregReset.Checked = true;
                    txtDiseases.Text       = "";
                    radioGroupPreg.Enabled = true;
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this.Activity, ex.ToString(), ToastLength.Short);
                }
            };


            return(v);
        }