Exemplo n.º 1
0
        private async void BtnScan_Click(object sender, EventArgs e)
        {
            //var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
            var          scanner = new ZXing.Mobile.MobileBarcodeScanner();
            ApiFunctions apiGet  = new ApiFunctions();
            //options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
            //	ZXing.BarcodeFormat.CODE_93, ZXing.BarcodeFormat.CODE_39
            //};

            var options = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                TryHarder       = true,
                PossibleFormats = new List <ZXing.BarcodeFormat>
                {
                    ZXing.BarcodeFormat.CODE_39
                }
            };
            var result = await scanner.Scan(options);

            if (result != null)
            {
                string id;
                id = result.Text;
                id = id.Remove(0, 2);
                id = id.Remove(id.Length - 1);
                //Toast.MakeText(this, id, ToastLength.Long).Show();
                string    url = "http://theblackcat102.nctu.me:5000/NCTU/api/v1.1/students/" + id.ToString();
                JsonValue pay = await apiGet.FetchStudentAsync(url);

                if (apiGet.GotPay(pay))
                {
                    Toast.MakeText(this, id + ",有繳學聯會費喔", ToastLength.Long).Show();
                }
                else
                {
                    Toast.MakeText(this, id + ",沒有繳學聯會費!!", ToastLength.Long).Show();
                }
            }
        }
Exemplo n.º 2
0
        private async void testBtn_Click(object sender, EventArgs e)
        {
            var    sqlLiteFilePath = GetFileStreamPath("") + "/db_user.db";
            string TARGETURL       = "http://theblackcat102.nctu.me:5000/NCTU/api/v1.1/payOnly";
            string result          = null;

            DatabaseFunctions dbFunc = new DatabaseFunctions();
            ApiFunctions      apiGet = new ApiFunctions();

            if (File.Exists(sqlLiteFilePath))
            {
                File.Delete(sqlLiteFilePath);
            }
            dbFunc.createDB(sqlLiteFilePath);
            Console.WriteLine("Database created");

            result = await apiGet.parseData(TARGETURL);             //must be used in threading pool otherwise add async to function

            ProgressDialog progress;

            progress = ProgressDialog.Show(this, "Loading", "Please Wait...", true);
            await Task.Factory.StartNew(
                () =>
            {
                if (result != null && result.Length >= 50)
                {
                    dbFunc.buildDB(result, sqlLiteFilePath);
                }
            }).ContinueWith(
                t =>
            {
                if (progress != null)
                {
                    progress.Hide();
                }
            }, TaskScheduler.FromCurrentSynchronizationContext()
                );
        }