Example #1
0
        void MListview_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var mList = adapter.GetItemAtPosition(e.Position);

            if (mList.parkingStat != "" && mList.parkingStat != "Penalty issued")
            {
                Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Confirm Penalty");
                alert.SetMessage("Penalty for " + mList.carPlateNumber + "\n" +
                                 "" + "\n" +
                                 mList.parkingStat + "\n" +
                                 "Total Penalty: " + "RM " + 150 + "\n" +
                                 "" + "\n" +
                                 "");
                alert.SetPositiveButton("Yes", async(senderAlert, args) =>
                {
                    var parkingDialog = ProgressDialog.Show(this, "Please wait...",
                                                            "Creating new penalty...", true);

                    //Initializing the parking table
                    IMobileServiceTable <Penalty> penaltyTable = client.GetTable <Penalty>();
                    IMobileServiceTable <Parking> parkingTable = client.GetTable <Parking>();

                    var currentParking   = await parkingTable.LookupAsync(mList.parkingId);
                    DateTime startTime   = DateTime.Parse(Convert.ToString(currentParking.CreatedAt));
                    DateTime currentTime = DateTime.Now;
                    DateTime expectedEnd = startTime.AddHours(Convert.ToDouble(currentParking.ParkedHours));
                    TimeSpan timediff    = currentTime.Subtract(expectedEnd);

                    penalty.Email         = mList.email;
                    penalty.ParkingId     = mList.parkingId;
                    penalty.ExceededHours = timediff.ToString(@"hh\:mm");
                    penalty.TotaAmount    = 150;
                    //Inserting new parking to the Database
                    await penaltyTable.InsertAsync(penalty);

                    currentParking.HasPenalty = true;
                    await parkingTable.UpdateAsync(currentParking);

                    Android.App.AlertDialog.Builder alertSuccess = new Android.App.AlertDialog.Builder(this);
                    alertSuccess.SetTitle("Parking Area");
                    alertSuccess.SetMessage("Penalty is issued successful");
                    alertSuccess.SetPositiveButton("Ok", (senderAlertSucces, argsSuccess) =>
                    {
                        RefreshActivity();
                    });
                    Dialog dialogSuccess = alertSuccess.Create();
                    dialogSuccess.Show();
                });
                alert.SetNegativeButton("Cancel", (senderAlert, args) =>
                {
                    Toast.MakeText(this, "Cancelled!", ToastLength.Short).Show();
                });
                Dialog dialog = alert.Create();
                dialog.Show();
            }
            else if (mList.parkingStat == "Penalty issued")
            {
                Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Can not issue new penalty");
                alert.SetMessage("This parking has a penalty issued. Can not issue two penalties");
                alert.SetPositiveButton("Ok", (senderAlertSucces, argsSuccess) =>
                {
                });
                Dialog dialog = alert.Create();
                dialog.Show();
            }
            else
            {
                Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                alert.SetTitle("Parking is legal");
                alert.SetMessage("This parking is still within its legal parking session. "
                                 + "Can not issue penalty for this parking");
                alert.SetPositiveButton("Ok", (senderAlertSucces, argsSuccess) =>
                {
                });
                Dialog dialog = alert.Create();
                dialog.Show();
            }
        }