protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Absenteeism);

            // Create your application here
            Button btnSubmitAbsReq = FindViewById <Button>(Resource.Id.btnSubmitAbsReq);

            btnSubmitAbsReq.Click += btnSubmitAbsReq_Click;
            //set date textview
            TextView tvwMsg        = FindViewById <TextView>(Resource.Id.tvwMsg);
            TextView tvwReason     = FindViewById <TextView>(Resource.Id.edtReasonAbsReq);
            EditText edtDateAbsReq = FindViewById <EditText>(Resource.Id.edtDateAbsReq);

            edtDateAbsReq.Click += (s, e) =>
            {
                var dateTimeNow             = DateTime.Now;
                DatePickerDialog datePicker = new DatePickerDialog
                                                  (this,
                                                  (sender, eventArgs) => { edtDateAbsReq.Text = eventArgs.Date.Day + "/" + eventArgs.Date.Month + "/" + eventArgs.Date.Year; },
                                                  dateTimeNow.Year, dateTimeNow.Month - 1, dateTimeNow.Day);
                datePicker.Show();
            };

            tvwMsg.ErrorMsg((string)(await DataApi.NetworkAccessStatus())[1]);
        }
Пример #2
0
        //check the registration status of device
        public async Task <object[]> DeviceRegistered(Activity callingActivity)
        {
            object[] values = new object[2];
            values[0] = true;

            int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(callingActivity);

            if (resultCode == ConnectionResult.Success && !string.IsNullOrEmpty(FirebaseInstanceId.Instance.Token))
            {
                values[1] = "";
            }
            else
            {
                if (resultCode != ConnectionResult.Success)
                {
                    if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode))
                    {
                        values[1] = "From Google Play Service: " + GoogleApiAvailability.Instance.GetErrorString(resultCode);
                    }
                    else
                    {
                        values[1] = "This device does not support google play services";
                        //t = new Timer(3000);                                  do not terminate app
                        //t.Elapsed += (s, e) => { Finish(); t.Dispose(); };
                        //t.Start();
                    }
                }
                else
                {
                    values[0] = false;
                    if ((bool)(await DataApi.NetworkAccessStatus())[0])
                    {
                        values[1] = "Google Play Service Initializing. Please try again later";
                    }
                    else
                    {
                        values[1] = "Connect to the internet to initialize device";
                    }
                }
            }

            return(values);
        }
Пример #3
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.WorkListLayout);

            if (!User.IsValidUser())
            {
                StartActivity(typeof(MainActivity));
                return;
            }

            TextView tvwMainMsg = FindViewById <TextView>(Resource.Id.tvwWkvMsg);

            (GetSystemService(NotificationService) as NotificationManager).Cancel(0);       //cancel all related notifications

            try
            {
                string restUrl = Values.ApiRootAddress + "Approval?compId=" + new AppPreferences().GetValue(User.CompId) + "&empNo=" +
                                 new AppPreferences().GetValue(User.EmployeeNo);
                tvwMainMsg.BasicMsg(Values.LoadingMsg);
                dynamic response = await new DataApi().GetAsync(restUrl);
                tvwMainMsg.Text = "";

                bool success = DataApi.IsJsonObject(response);
                if (success)
                {
                    if (response["Error"] == "")
                    {
                        response = response["Values"];

                        List <object> appraisees = new List <object>();
                        for (int i = 0; i < response.Count; i++)
                        {
                            Appraisee appraisee = new Appraisee();
                            appraisee.SerialNo     = i + 1;
                            appraisee.Message      = response[i]["Description"];
                            appraisee.ApprovalType = response[i]["Approval_Type"];
                            appraisee.SentBy       = response[i]["Created By"];
                            appraisee.DateSent     = response[i]["Date"];
                            appraisee.Alertid      = response[i]["Alert_Id"];
                            appraisee.RequestId    = response[i]["REQUEST"] ?? 0;

                            appraisees.Add(appraisee);
                        }

                        tvwMainMsg.SuccessMsg("Outstanding Approvals: " + appraisees.Count);

                        adapter            = new ApprovalAdapter(appraisees);
                        adapter.ItemClick += async(sender, position) =>
                        {
                            try
                            {
                                Appraisee appraisee = (Appraisee)adapter[position];

                                //check for internet access
                                object[] networkStatus = await DataApi.NetworkAccessStatus();

                                if (!(bool)networkStatus[0])
                                {
                                    tvwMainMsg.ErrorMsg((string)networkStatus[1]);
                                    return;
                                }

                                if (appraisee.ApprovalType == "Medical")
                                {
                                    restUrl = Values.ApiRootAddress + "Approval/GetMedicalRequest?compId=" + new AppPreferences().GetValue(User.CompId) + "&empNo=" +
                                              new AppPreferences().GetValue(User.EmployeeNo) + "&accYear=" + new AppPreferences().GetValue(User.AccountingYear) + "&reqId=" +
                                              appraisee.RequestId;

                                    response = await new DataApi().GetAsync(restUrl);

                                    if (response["Error"] == "")
                                    {
                                        response = response["Values"];

                                        var view = LayoutInflater.Inflate(Resource.Layout.MedApprovalDialogLayout, null);

                                        AlertDialog dialog = new AlertDialog.Builder(this).Create();
                                        dialog.SetTitle("MEDICAL APPROVAL");

                                        view.FindViewById <TextView>(Resource.Id.tvwMedEmpName).Text  = response[0]["HEMP_EMPLYE_NAME"];
                                        view.FindViewById <TextView>(Resource.Id.tvwMedReqDate).Text  = response[0]["Date"];
                                        view.FindViewById <TextView>(Resource.Id.tvwMedHospital).Text = response[0]["HOSP_NAME"];
                                        view.FindViewById <TextView>(Resource.Id.tvwMedLimBal).Text   = response[0]["LIMITBAL"];
                                        view.FindViewById <TextView>(Resource.Id.tvwMedUsed).Text     = response[0]["USED"];
                                        view.FindViewById <TextView>(Resource.Id.tvwMedReason).Text   = response[0]["REQ_REASON"];

                                        dialog.SetView(view);

                                        dialog.SetButton("Approve", async(s, e) =>
                                        {
                                            try
                                            {
                                                string comment = view.FindViewById <EditText>(Resource.Id.edtMedComment).Text;

                                                string status = await PostMedical(appraisee, response, "A", comment);
                                                CompleteTask(status, adapter, position, dialog, tvwMainMsg);
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.Log();
                                                tvwMainMsg.ErrorMsg(Values.ErrorMsg);
                                            }
                                        });

                                        dialog.SetButton2("Reject", async(s, e) =>
                                        {
                                            try
                                            {
                                                string comment = view.FindViewById <EditText>(Resource.Id.edtMedComment).Text;

                                                string status = await PostMedical(appraisee, response, "D", comment);
                                                CompleteTask(status, adapter, position, dialog, tvwMainMsg);
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.Log();
                                                tvwMainMsg.ErrorMsg(Values.ErrorMsg);
                                            }
                                        });

                                        dialog.SetButton3("Cancel", (s, e) =>
                                        {
                                            dialog.Dismiss();
                                            tvwMainMsg.SuccessMsg("Outstanding Approvals: " + adapter.ItemCount);
                                        });

                                        dialog.Show();
                                    }
                                    else
                                    {
                                        tvwMainMsg.ErrorMsg((string)response["Error"]);
                                    }
                                }

                                else if (appraisee.ApprovalType == "Leave")
                                {
                                    restUrl = Values.ApiRootAddress + "Approval/GetLeaveRequest?compId=" + new AppPreferences().GetValue(User.CompId) + "&empNo=" +
                                              new AppPreferences().GetValue(User.EmployeeNo) + "&reqId=" + appraisee.RequestId;

                                    tvwMainMsg.BasicMsg(Values.WaitingMsg);
                                    response        = await new DataApi().GetAsync(restUrl);
                                    tvwMainMsg.Text = "";

                                    if (response["Error"] == "")
                                    {
                                        response = response["Values"];

                                        var view = LayoutInflater.Inflate(Resource.Layout.LvlApprovalDialogLayout, null);

                                        AlertDialog dialog = new AlertDialog.Builder(this).Create();
                                        dialog.SetTitle("LEAVE APPROVAL");

                                        view.FindViewById <TextView>(Resource.Id.tvwLvlEmpName).Text   = response[0]["EmpName"];
                                        view.FindViewById <TextView>(Resource.Id.tvwLvlEmpNo).Text     = (int)response[0]["EmpNo"] + "";
                                        view.FindViewById <TextView>(Resource.Id.tvwLvlDesc).Text      = response[0]["LvDesc"];
                                        view.FindViewById <TextView>(Resource.Id.tvwLvlStartDate).Text = response[0]["StrtDt"];
                                        view.FindViewById <TextView>(Resource.Id.tvwLvlEndDate).Text   = response[0]["EndDt"];
                                        view.FindViewById <TextView>(Resource.Id.tvwLvlNoOfDays).Text  = (int)response[0]["NoOfDays"] + "";
                                        view.FindViewById <TextView>(Resource.Id.tvwLvlReason).Text    = response[0]["Reason"];

                                        dialog.SetView(view);

                                        dialog.SetButton("Approve", async(s, e) =>
                                        {
                                            try
                                            {
                                                string comment = view.FindViewById <EditText>(Resource.Id.edtLvlComment).Text;

                                                string status = await PostLeave(appraisee, response, "A", comment);
                                                CompleteTask(status, adapter, position, dialog, tvwMainMsg);
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.Log();
                                                tvwMainMsg.ErrorMsg(Values.ErrorMsg);
                                            }
                                        });

                                        dialog.SetButton2("Reject", async(s, e) =>
                                        {
                                            try
                                            {
                                                string comment = view.FindViewById <EditText>(Resource.Id.edtLvlComment).Text;

                                                string status = await PostLeave(appraisee, response, "D", comment);
                                                CompleteTask(status, adapter, position, dialog, tvwMainMsg);
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.Log();
                                                tvwMainMsg.ErrorMsg(Values.ErrorMsg);
                                            }
                                        });

                                        dialog.SetButton3("Cancel", (s, e) =>
                                        {
                                            dialog.Dismiss();
                                            tvwMainMsg.SuccessMsg("Outstanding Approvals: " + adapter.ItemCount);
                                        });

                                        dialog.Show();
                                    }
                                    else
                                    {
                                        tvwMainMsg.ErrorMsg((string)response["Error"]);
                                    }
                                }

                                else if (appraisee.ApprovalType == "Training")
                                {
                                    restUrl = Values.ApiRootAddress + "Approval/GetTrainingRequest?compId=" + new AppPreferences().GetValue(User.CompId) + "&empNo=" +
                                              new AppPreferences().GetValue(User.EmployeeNo) + "&reqId=" + appraisee.RequestId;

                                    tvwMainMsg.BasicMsg(Values.WaitingMsg);
                                    response        = await new DataApi().GetAsync(restUrl);
                                    tvwMainMsg.Text = "";

                                    if (response["Error"] == "")
                                    {
                                        response = response["Values"];

                                        var view = LayoutInflater.Inflate(Resource.Layout.TrnApprovalDialogLayout, null);

                                        AlertDialog dialog = new AlertDialog.Builder(this).Create();
                                        dialog.SetTitle("TRAINING APPROVAL");

                                        view.FindViewById <TextView>(Resource.Id.tvwTrnEmpName).Text = response[0]["Employee Name"];
                                        view.FindViewById <TextView>(Resource.Id.tvwTrnDesc).Text    = response[0]["Training Description"];
                                        view.FindViewById <TextView>(Resource.Id.tvwTrnReason).Text  = response[0]["Reason"];
                                        view.FindViewById <TextView>(Resource.Id.tvwTrnNomBy).Text   = response[0]["Nominating Emp Name"];

                                        dialog.SetView(view);

                                        dialog.SetButton("Approve", async(s, e) =>
                                        {
                                            try
                                            {
                                                string comment = view.FindViewById <EditText>(Resource.Id.edtTrnComment).Text;

                                                string status = await PostTraining(appraisee, response, "A", comment);
                                                CompleteTask(status, adapter, position, dialog, tvwMainMsg);
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.Log();
                                                tvwMainMsg.ErrorMsg(Values.ErrorMsg);
                                            }
                                        });

                                        dialog.SetButton2("Reject", async(s, e) =>
                                        {
                                            try
                                            {
                                                string comment = view.FindViewById <EditText>(Resource.Id.edtTrnComment).Text;

                                                string status = await PostTraining(appraisee, response, "D", comment);
                                                CompleteTask(status, adapter, position, dialog, tvwMainMsg);
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.Log();
                                                tvwMainMsg.ErrorMsg(Values.ErrorMsg);
                                            }
                                        });

                                        dialog.SetButton3("Cancel", (s, e) =>
                                        {
                                            dialog.Dismiss();
                                            tvwMainMsg.SuccessMsg("Outstanding Approvals: " + adapter.ItemCount);
                                        });

                                        dialog.Show();
                                    }
                                    else
                                    {
                                        tvwMainMsg.ErrorMsg((string)response["Error"]);
                                    }
                                }

                                else
                                {
                                    tvwMainMsg.ErrorMsg("Request type not provisioned");        //should not happen for mobile (handles only 3 approvals)
                                }
                            }
                            catch (Exception ex)
                            {
                                ex.Log();
                                tvwMainMsg.ErrorMsg(Values.ErrorMsg);
                            }
                        };

                        RecyclerView recyclerView = (RecyclerView)FindViewById(Resource.Id.rvwWorkListViewer);
                        recyclerView.SetLayoutManager(new LinearLayoutManager(this));
                        recyclerView.SetAdapter(adapter);
                    }
                    else
                    {
                        tvwMainMsg.ErrorMsg((string)response["Error"]);
                    }
                }
                else
                {
                    tvwMainMsg.ErrorMsg((string)response);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
                tvwMainMsg.ErrorMsg(Values.ErrorMsg);
            }
        }