Пример #1
0
        public async Task SuaBenhNhan(BenhNhan benhnhan)
        {
            Uri url = new Uri(new Routes().Route + benhnhan.mabn);

            Console.WriteLine("url sua: " + url);
            HttpClient client = new HttpClient();

            try
            {
                var data = JsonConvert.SerializeObject(benhnhan);
                Console.WriteLine(data);

                var content = new StringContent(data, Encoding.UTF8, "application/json");
                var res     = await client.PutAsync(url, content);

                var resMessage = await res.Content.ReadAsStringAsync();

                Console.WriteLine(resMessage);
                if (res.IsSuccessStatusCode)
                {
                    Toast.MakeText(this, "thành công", ToastLength.Short).Show();
                }
            }
            catch (Exception e)
            {
                Toast.MakeText(this, e.Message, ToastLength.Short).Show();
            }
        }
Пример #2
0
        public async Task ThemBenhNhan(BenhNhan benhnhan)
        {
            Uri        url    = new Uri(new Routes().Route);
            HttpClient client = new HttpClient();

            try
            {
                var data = JsonConvert.SerializeObject(benhnhan);
                Console.WriteLine(data);
                var content = new StringContent(data, Encoding.UTF8, "application/json");
                var res     = await client.PostAsync(url, content);

                var resMessage = await res.Content.ReadAsStringAsync();

                Toast.MakeText(Android.App.Application.Context, resMessage, ToastLength.Short).Show();
                Console.WriteLine(resMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.suabenhnhan_activity_layout1);
            // Create your application here
            //BenhNhan bn = JsonConvert.DeserializeObject<BenhNhan>(Intent.GetStringExtra("thongtinbenhnhan"));
            // Console.WriteLine("ahihi " + bn.mabn);
            btn_sua     = FindViewById <Button>(Resource.Id.btnSuaBN);
            btn_quayve  = FindViewById <Button>(Resource.Id.btnQuayVeSua);
            ed_mabn     = FindViewById <EditText>(Resource.Id.edMabnSua);
            ed_holot    = FindViewById <EditText>(Resource.Id.edHolotSua);
            ed_ten      = FindViewById <EditText>(Resource.Id.edTenSua);
            ed_ngaysinh = FindViewById <EditText>(Resource.Id.edNgaySinhSua);

            rd_gtnam  = FindViewById <RadioButton>(Resource.Id.rdNamSua);
            rd_gtnu   = FindViewById <RadioButton>(Resource.Id.rdNuSua);
            rd_gtkhac = FindViewById <RadioButton>(Resource.Id.rdKhacSua);

            BenhNhan bn = JsonConvert.DeserializeObject <BenhNhan>(Intent.GetStringExtra("thongtinbenhnhan"));

            ed_mabn.Text     = bn.mabn;
            ed_holot.Text    = bn.holot;
            ed_ten.Text      = bn.ten;
            ed_ngaysinh.Text = bn.ngaysinh;
            switch (bn.gioitinh)
            {
            case 0:
                rd_gtnu.Checked = true;
                break;

            case 1:
                rd_gtnam.Checked = true;
                break;

            default:
                rd_gtkhac.Checked = true;
                break;
            }

            DateTime ngay = DateTime.ParseExact(ed_ngaysinh.Text, "dd/MM/yyyy", null);

            ed_ngaysinh.Click += delegate
            {
                DatePickerDialog datePickerDialog = new DatePickerDialog(this, OnDateSet, ngay.Year, ngay.Month - 1, ngay.Day);
                datePickerDialog.DatePicker.MinDate = ngay.Millisecond;
                datePickerDialog.Show();
            };
            btn_quayve.Click += delegate
            {
                OnBackPressed();
            };
            btn_sua.Click += async delegate

            {
                var gioitinh = 1;
                if (rd_gtnu.Checked)
                {
                    gioitinh = 0;
                }
                else if (rd_gtkhac.Checked)
                {
                    gioitinh = 2;
                }
                if (ed_mabn.Text.Equals("") || ed_holot.Equals("") || ed_ten.Equals("") || ed_ngaysinh.Equals(""))
                {
                    Toast.MakeText(this, "Chưa nhập đủ thông tin", ToastLength.Short).Show();
                }
                BenhNhan benhnhan = new BenhNhan(ed_mabn.Text, ed_holot.Text, ed_ten.Text, ed_ngaysinh.Text, gioitinh);
                await SuaBenhNhan(benhnhan);


                //    MainActivity main = new MainActivity();

                // main.GetbenhNhanAdapter().NotifyDataSetChanged();
            };
        }
Пример #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.thembenhnhan_activity_layout);

            // Create your application here
            btn_them    = FindViewById <Button>(Resource.Id.btnThemBN);
            btn_quayve  = FindViewById <Button>(Resource.Id.btnQuayVe);
            btn_nhaplai = FindViewById <Button>(Resource.Id.btnNhapLai);
            ed_mabn     = FindViewById <EditText>(Resource.Id.edMabn);
            ed_holot    = FindViewById <EditText>(Resource.Id.edHolot);
            ed_ten      = FindViewById <EditText>(Resource.Id.edTen);
            ed_ngaysinh = FindViewById <EditText>(Resource.Id.edNgaySinh);
            DateTime homnay = DateTime.Today;

            ed_ngaysinh.Click += delegate
            {
                DatePickerDialog datePickerDialog = new DatePickerDialog(this, OnDateSet, homnay.Year, homnay.Month - 1, homnay.Day);
                datePickerDialog.DatePicker.MinDate = homnay.Millisecond;
                datePickerDialog.Show();
            };
            rd_gtnam           = FindViewById <RadioButton>(Resource.Id.rdNam);
            rd_gtnu            = FindViewById <RadioButton>(Resource.Id.rdNu);
            rd_gtkhac          = FindViewById <RadioButton>(Resource.Id.rdKhac);
            btn_nhaplai.Click += delegate
            {
                ed_mabn.Text     = "";
                ed_holot.Text    = "";
                ed_ten.Text      = "";
                ed_ngaysinh.Text = "";
            };
            btn_quayve.Click += delegate
            {
                OnBackPressed();
            };
            btn_them.Click += async delegate
            {
                try
                {
                    var mabn     = ed_mabn.Text;
                    var holot    = ed_holot.Text;
                    var ten      = ed_ten.Text;
                    var ngaysinh = ed_ngaysinh.Text;

                    var gioitinh = 1;
                    if (rd_gtnu.Checked)
                    {
                        gioitinh = 0;
                    }
                    else if (rd_gtkhac.Checked)
                    {
                        gioitinh = 2;
                    }
                    if (mabn.Equals("") || holot.Equals("") || ten.Equals("") || ngaysinh.Equals(""))
                    {
                        Toast.MakeText(this, "Chưa nhập đủ thông tin", ToastLength.Short).Show();
                    }
                    else
                    {
                        BenhNhan benhnhan = new BenhNhan(mabn, holot, ten, ngaysinh, gioitinh);
                        await ThemBenhNhan(benhnhan);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Lỗi khi thêm benhnhan " + e.Message);
                }
            };
        }