コード例 #1
0
ファイル: studentac.cs プロジェクト: BAARTeam/BAAR1
        public async Task <BarcodeScanReturn> StartBarcodeScanner()
        {
            MobileBarcodeScanner.Initialize(Application);

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();
            var result  = await scanner.Scan();

            try
            {
                string[] Results = result.ToString().Split('*');
                Console.WriteLine("Returned Data " + Results[1]);
                string            Contra  = (string)MainActivity.MakeRequest3("data", Results[1]);
                string            Name    = Contra.GetStringOut("lastfirst");
                string            Email1  = Contra.GetStringOut("guardianemail");
                string            Email2  = Contra.GetStringOut("guardianemail_2");
                string            Email3  = Contra.GetStringOut("stud_email");
                BarcodeScanReturn Student = new BarcodeScanReturn(Name, Results[1], Email1, Email2, Email3);
                AllReturned.Add(Student);
                return(Student);
            }
            catch
            {
                string[]          Results = result.ToString().Split(' ');
                BarcodeScanReturn Staff   = new BarcodeScanReturn((Results[2] + ", " + Results[1]), " ", null, null, null);
                AllReturned.Add(Staff);
                return(Staff);
            }
        }
コード例 #2
0
ファイル: studentac.cs プロジェクト: BAARTeam/BAAR1
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Window.RequestFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.student);

            try
            {
                BarcodeScanReturn Returned = await StartBarcodeScanner();

                Console.WriteLine(Returned.StudentName);
                string[] Name = SplitName(Returned.StudentName);
                Returned.FirstName = Name[0];
                Returned.LastName  = Name[1];
                CreateStudentTicket((Name[0] + " " + Name[1]), Returned.StudentNumber.ToString());
            }
            catch
            {
                Console.WriteLine("Pressed Back When Scanning Barcode");
                Intent MainPage = new Intent(this, typeof(MainActivity));
                StartActivity(MainPage);
            }


            FindViewById <LinearLayout>(Resource.Id.Root).SetBackgroundColor(Color.Argb(255, 0, 9, 26));

            FindViewById <Button>(Resource.Id.AddTicket).SetTextColor(Color.White);
            FindViewById <Button>(Resource.Id.EmailButton).SetTextColor(Color.White);

            Button EmailButton = FindViewById <Button>(Resource.Id.EmailButton);

            EmailButton.Click += (sender, e) =>
            {
                for (int i = 0; i < NumberOfTickets; i++)
                {
                    string EmailBehaviour = LayoutSpinner[i + 1][0].SelectedItem.ToString();
                    string EmailBuilding  = LayoutSpinner[i + 1][1].SelectedItem.ToString();
                    string EmailLocation  = LayoutSpinner[i + 1][2].SelectedItem.ToString();

                    Thread EmailThread = new Thread(new ThreadStart(new EmailInfo(AllReturned[i].FirstName, AllReturned[i].PrimaryEmailAddress, AllReturned[i].SecondaryAddress, AllReturned[i].StudentAddress, EmailLocation, EmailBehaviour).BackgroundEmail));
                    EmailThread.Start();

                    var thisinfo = JsonConvert.SerializeObject(new
                    {
                        LogDateTime        = DateTime.Now,
                        District           = "KentISD",
                        Building           = EmailBuilding,
                        Student_ID         = AllReturned[i].StudentNumber,
                        Student_First_Name = AllReturned[i].FirstName,
                        Student_Last_Name  = AllReturned[i].LastName,
                        Behavior           = EmailBehaviour,
                        Behavior_Location  = EmailLocation,
                        Staff_Login_ID     = Login.StaffUserName
                    });


                    // POST a JSON string
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://goingpro.azurewebsites.net/api/Behavior_Log");
                    request.Method      = "POST";
                    request.ContentType = @"application/json";
                    request.Accept      = @"application/json";

                    var dataStream = new StreamWriter(request.GetRequestStream());

                    using (dataStream)
                    {
                        dataStream.Write(thisinfo);
                        dataStream.Flush();
                        dataStream.Close();
                    }

                    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                    {
                        if (response.StatusCode != HttpStatusCode.Created)
                        {
                            Console.WriteLine("Error fetching data.  Server returned status code " + response.StatusCode);
                        }
                        else
                        {
                            Toast.MakeText(this, "Information Saved", ToastLength.Long);
                        }
                    }
                }

                Toast.MakeText(this, "Email Sent", ToastLength.Long).Show();
                Intent MainPage = new Intent(this, typeof(MainActivity));
                StartActivity(MainPage);
            };


            Button TicketButton = FindViewById <Button>(Resource.Id.AddTicket);

            TicketButton.Click += async(sender, e) =>
            {
                try
                {
                    BarcodeScanReturn Thing = await StartBarcodeScanner();

                    string[] SecondaryName = SplitName(Thing.StudentName);
                    Thing.FirstName = SecondaryName[0];
                    Thing.LastName  = SecondaryName[1];
                    CreateStudentTicket(SecondaryName[0] + " " + SecondaryName[1], Thing.StudentNumber);
                }
                catch
                {
                    Toast.MakeText(this, "Invalid Barcode Scanned", ToastLength.Long).Show();
                    Console.WriteLine("Woah Something Went Wrong When Scanning Barcode either that is not a valid barcode or there is no connection.");
                }
            };
        }