Пример #1
0
 public void CompleteTask(string status, ApprovalAdapter adp, int position, AlertDialog dlg, TextView tvwMsg)
 {
     if (status == "")
     {
         adp.Remove(position);
         dlg.Dismiss();
         tvwMsg.SuccessMsg(Values.SuccessMsg);
     }
     else
     {
         dlg.Dismiss();
         tvwMsg.ErrorMsg(status);
     }
 }
Пример #2
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);
            }
        }