public async void GetWorkDays()
        {
            TextView tvwMsg       = FindViewById <TextView>(Resource.Id.tvwMsgLeaveRecall);
            EditText edtRecallDt  = FindViewById <EditText>(Resource.Id.edtRecallDt);
            TextView tvwStDateRec = FindViewById <TextView>(Resource.Id.tvwStDateRec);

            //Call getworking Days
            if (tvwStDateRec.Text != "" && edtRecallDt.Text != "" && tvwStDateRec.Text != edtRecallDt.Text)
            {
                DateTime?StDate = new CommonMethodsClass().ConvertStringToDate(tvwStDateRec.Text);
                DateTime?EndDt  = new CommonMethodsClass().ConvertStringToDate(edtRecallDt.Text);

                if (EndDt > StDate)
                {
                    string restUrl1 = Values.ApiRootAddress + "LeaveRecall/GetWorkDays/?strFromDate=" + tvwStDateRec.Text + "&strToDate=" + edtRecallDt.Text + "&compId=" + new AppPreferences().GetValue(User.CompId);

                    tvwMsg.BasicMsg(Values.WaitingMsg);
                    dynamic response = await new DataApi().GetAsync(restUrl1);
                    tvwMsg.Text = "";

                    if (IsJsonObject(response))
                    {
                        SpentDays = (int)response + "";
                    }
                    else
                    {
                        tvwMsg.ErrorMsg((string)response);
                    }
                }
            }
        }
        //Used to Get Other Information
        private async void spnLeaveRec_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            TextView tvwMsg    = FindViewById <TextView>(Resource.Id.tvwMsgLeaveRecall);
            Spinner  spinner   = (Spinner)sender;
            Array    Leaveitem = leaveitemList.ToArray();

            if (e.Id != 0)
            {
                //tvwStrDtExt, tvwEndDtExt,  tvwRemainDaysExt
                TextView tvwLvTypeRec  = FindViewById <TextView>(Resource.Id.tvwLvTypeRec);
                TextView tvwStartDtRec = FindViewById <TextView>(Resource.Id.tvwStartDtRec);
                TextView tvwResumeRec  = FindViewById <TextView>(Resource.Id.tvwResumeRec);
                TextView tvwStDateRec  = FindViewById <TextView>(Resource.Id.tvwStDateRec);
                EditText edtRecallDt   = FindViewById <EditText>(Resource.Id.edtRecallDt);

                int    RqstId   = (int)double.Parse(Leaveitem.GetValue(e.Id - 1).ToString());
                string restUrl2 = Values.ApiRootAddress + "LeaveRecall/GetLeaveInfo/?compId=" + new AppPreferences().GetValue(User.CompId) + "&RqstNo=" + RqstId + "&EmpNo=" + new AppPreferences().GetValue(User.EmployeeNo);

                tvwMsg.BasicMsg(Values.WaitingMsg);
                dynamic response = await new DataApi().GetAsync(restUrl2);
                tvwMsg.Text = "";

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

                    tvwLvTypeRec.Text  = response[0]["LVDESC"];
                    tvwStartDtRec.Text = response[0]["FROMDT"];
                    tvwResumeRec.Text  = response[0]["RESUMEDATE"];
                    tvwStDateRec.Text  = response[0]["STARTDT"];

                    ENMBR       = response[0]["NMBR"].ToString();
                    EName       = response[0]["NAME"];
                    LvDesc      = response[0]["LVDESC"];
                    RqstNo      = response[0]["RQSTNUM"].ToString();
                    GRQSTID     = response[0]["GRQSTID"].ToString();
                    LvGrp       = response[0]["LVGRP"].ToString();
                    LevCode     = response[0]["LVCODE"];
                    OldDuration = response[0]["DURATN"].ToString();
                }
                else
                {
                    tvwMsg.ErrorMsg((string)response);
                }
            }
        }
        public async void LoadSpinner()
        {
            TextView tvwMsg = FindViewById <TextView>(Resource.Id.tvwMsgLeaveRecall);

            try
            {
                //To get Employee Leave To be Recalled from the web api asynchronously and Bind To The Spinner
                string restUrl = Values.ApiRootAddress + "LeaveRecall/GetEmployeeLv/?compId=" + new AppPreferences().GetValue(User.CompId) + "&EmployeeNo=" + new AppPreferences().GetValue(User.EmployeeNo);

                tvwMsg.BasicMsg(Values.LoadingMsg);
                dynamic response = await new DataApi().GetAsync(restUrl);
                tvwMsg.Text = "";

                bool success = DataApi.IsJsonObject(response);
                if (success)
                {
                    response = response["Values"];                 //get the values sent by the web api

                    StoreToPref(response);                         //store to preferences for future access
                    var     Leave        = GetLeaveType(response); //list to be used to populate spinner
                    var     LeaveAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, Leave);
                    Spinner spnLeaveRec  = FindViewById <Spinner>(Resource.Id.spnLeaveRec);
                    spnLeaveRec.Adapter       = LeaveAdapter;
                    spnLeaveRec.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spnLeaveRec_ItemSelected);
                    LeaveAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                }
                else
                {
                    tvwMsg.ErrorMsg((string)response);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
                tvwMsg.ErrorMsg(Values.ErrorMsg);
            }
        }
Exemplo n.º 4
0
        private async void BtnSubmitMedReq_Click(object sender, EventArgs e)
        {
            TextView tvwMsg  = FindViewById <TextView>(Resource.Id.tvwMsgMedReq);
            string   dateStr = FindViewById <EditText>(Resource.Id.edtDateMedReq).Text;

            try
            {
                DateTime?date      = new CommonMethodsClass().ConvertStringToDate(dateStr);
                string   reason    = FindViewById <EditText>(Resource.Id.edtReasonMedReq).Text;
                int      selection = (int)FindViewById <Spinner>(Resource.Id.spnHospitalMedReq).SelectedItemId;

                if (date != null && date > DateTime.Now && selection > 0 && reason.Length > 0)
                {
                    string restUrl = Values.ApiRootAddress + "MedicalRequest";
                    var    content = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        { "EmployeeNo", new AppPreferences().GetValue(User.EmployeeNo) },
                        { "HospitalId", spinnerHospCode[selection] },
                        { "DateStr", dateStr },
                        { "Reason", reason },
                        { "UserId", new AppPreferences().GetValue(User.UserId) },
                        { "CompId", new AppPreferences().GetValue(User.CompId) }
                    });

                    (sender as Button).Enabled = false;
                    tvwMsg.BasicMsg(Values.WaitingMsg);
                    dynamic response = await new DataApi().PostAsync(restUrl, content);
                    tvwMsg.Text = "";
                    (sender as Button).Enabled = true;

                    bool success = DataApi.IsJsonObject(response);
                    if (success)
                    {
                        if (response["Error"] == "")     //success
                        {
                            FindViewById <EditText>(Resource.Id.edtDateMedReq).Text   = "";
                            FindViewById <EditText>(Resource.Id.edtReasonMedReq).Text = "";
                            FindViewById <Spinner>(Resource.Id.spnHospitalMedReq).SetSelection(0);
                            tvwMsg.SuccessMsg("Record Saved Successfully");
                        }
                        else
                        {
                            tvwMsg.ErrorMsg((string)response["Error"]);
                        }
                    }
                    else
                    {
                        tvwMsg.ErrorMsg((string)response);
                    }
                }
                else
                {
                    if (date == null)
                    {
                        tvwMsg.ErrorMsg("Please select a leave date");
                    }
                    else if (date <= DateTime.Now)
                    {
                        tvwMsg.ErrorMsg("Please select a future date");
                    }
                    else if (selection == 0)
                    {
                        tvwMsg.ErrorMsg("Please select a hospital");
                    }
                    else
                    {
                        tvwMsg.ErrorMsg("Please enter your reason");
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Log();
                tvwMsg.ErrorMsg(Values.ErrorMsg);
            }
        }
Exemplo n.º 5
0
        //bool callFlag = true;       //to check double calls on older api levels to handle called event e.g. OnTextChanged especially for non-idempotent actions eg Post.

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

            TextView tvwMsg = FindViewById <TextView>(Resource.Id.tvwMsgMedReq);
            //set date textview
            EditText edtDateMedReq = FindViewById <EditText>(Resource.Id.edtDateMedReq);

            edtDateMedReq.Click += (s, e) =>
            {
                var              dateTimeNow = DateTime.Now;
                bool             flag        = true; //to check double calls on older android api levels
                DatePickerDialog datePicker  = new DatePickerDialog
                                                   (this,
                                                   (sender, eventArgs) =>
                {
                    if (flag)
                    {
                        edtDateMedReq.Text = eventArgs.Date.Day + "/" + eventArgs.Date.Month + "/" + eventArgs.Date.Year;
                        flag = !flag;
                        //callFlag = true;
                    }
                    //else callFlag = false;
                },
                                                   dateTimeNow.Year, dateTimeNow.Month - 1, dateTimeNow.Day + 1);
                datePicker.Show();
            };

            try
            {
                //to get the list of hospitals from the web api asynchronously
                string restUrl = Values.ApiRootAddress + "MedicalRequest/?compId=" + new AppPreferences().GetValue(User.CompId);

                tvwMsg.BasicMsg(Values.LoadingMsg);
                dynamic response = await new DataApi().GetAsync(restUrl);
                tvwMsg.Text = "";

                if (IsJsonObject(response))
                {
                    response = response["Values"];                                                           //get the values sent by the web api

                    spinnerHospCode = GetAttributeList(response, "CODE");                                    //save code values
                    List <string> hospitals       = GetAttributeList(response, "NAME", "Select a Hospital"); //list to be used to populate spinner
                    var           hospitalAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, hospitals);

                    Spinner spnHospital = FindViewById <Spinner>(Resource.Id.spnHospitalMedReq);
                    spnHospital.Adapter = hospitalAdapter;
                }
                else
                {
                    tvwMsg.ErrorMsg((string)response);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
                tvwMsg.ErrorMsg(Values.ErrorMsg);
            }

            //get submit button and subscribe to its click event
            Button btnSubmitMedReq = FindViewById <Button>(Resource.Id.btnSubmitMedReq);

            btnSubmitMedReq.Click += BtnSubmitMedReq_Click;
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        ////Used to get the Working Days based on the Dates selected
        //private async void GetWorkingDays()
        //{
        //    TextView tvwMsg = FindViewById<TextView>(Resource.Id.tvwMsgLeaveReq);
        //    TextView tvwDurationExt = FindViewById<TextView>(Resource.Id.tvwDurationExt);
        //    EditText edtStartDate = FindViewById<EditText>(Resource.Id.edtStartDate);
        //    EditText edtEndDate = FindViewById<EditText>(Resource.Id.edtExtendTo);
        //    string RemainingDays = FindViewById<TextView>(Resource.Id.tvwRemainDaysExt).Text;
        //    tvwMsg.Text = "";
        //    //Call getworking Days
        //    if (edtStartDate.Text != "" && edtEndDate.Text != "")
        //    {
        //        int StartDt = Convert.ToInt32(edtStartDate.Text.Replace("/", ""));
        //        int EndDt = Convert.ToInt32(edtEndDate.Text.Replace("/", ""));

        //        if (EndDt > StartDt)
        //        {
        //            string restUrl4 = Values.ApiRootAddress + "LeaveExtension/GetWorkDays/?strFromDate=" + edtStartDate.Text + "&strToDate=" + edtEndDate.Text + "&compId=" + new AppPreferences().GetValue(User.CompId);

        //            dynamic response = await new DataApi().GetAsync(restUrl4);
        //            int Days = (int)response;
        //            if (int.Parse(RemainingDays) >= Days)
        //            {
        //                tvwDurationExt.Text = (int)response + "";
        //            }
        //            else
        //            {
        //                tvwDurationExt.Text = "";
        //                tvwMsg.Text = "Day Applied For Cannot Be Greater Than Remaining Days";
        //            }
        //        }
        //    }
        //}

        //Used To Do variuos checks And To save the records
        private async void btnSubmitLeaveExt_Click(object sender, EventArgs e)
        {
            TextView tvwMsg = FindViewById <TextView>(Resource.Id.tvwMsgLeaveExt);

            tvwMsg.Text = "";

            string   resumeDatestr = FindViewById <TextView>(Resource.Id.tvwResumeDtExt).Text;
            DateTime?resumeDate    = new CommonMethodsClass().ConvertStringToDate(resumeDatestr);
            string   ExtendTo      = FindViewById <EditText>(Resource.Id.edtExtendTo).Text; //Get End Date
            DateTime?date          = new CommonMethodsClass().ConvertStringToDate(ExtendTo);

            string RemainingDays = FindViewById <TextView>(Resource.Id.tvwRemainDaysExt).Text;
            string Duration      = FindViewById <TextView>(Resource.Id.tvwDurationExt).Text;
            string reason        = FindViewById <EditText>(Resource.Id.edtReasonExt).Text;
            int    selection     = (int)FindViewById <Spinner>(Resource.Id.spnLeaveExt).SelectedItemId;


            //Get Seklected ID for the Leave

            if (date != null && date > resumeDate && selection > 0)
            {
                if (int.Parse(RemainingDays) >= int.Parse(Duration))
                {
                    try
                    {
                        string restUrl      = Values.ApiRootAddress + "LeaveExtension";
                        var    contentLeave = new FormUrlEncodedContent(new Dictionary <string, string>
                        {
                            { "ReqNo", RqstNo },
                            { "EmployeeNo", new AppPreferences().GetValue(User.EmployeeNo) },
                            { "AccountingYear", new AppPreferences().GetValue(User.AccountingYear) },
                            { "LeaveGrp", LvGrp },
                            { "LvCode", LevCode },
                            { "RemainingDays", RemainingDays },
                            { "Duration", Duration },
                            { "ToDate", ExtendTo },
                            { "Reason", reason },
                            { "UserId", new AppPreferences().GetValue(User.UserId) },
                            { "CompId", new AppPreferences().GetValue(User.CompId) },
                            { "RelOfficerId", (int)double.Parse(RelOfficerId) + "" },
                            { "PrevReqId", (int)double.Parse(PrevReqId) + "" }
                        });

                        (sender as Button).Enabled = false;
                        tvwMsg.BasicMsg(Values.WaitingMsg);
                        dynamic response = await new DataApi().PostAsync(restUrl, contentLeave);
                        tvwMsg.Text = "";
                        (sender as Button).Enabled = true;

                        bool success = IsJsonObject(response);
                        if (success)
                        {
                            if (response["Error"] == "")     //success
                            {
                                FindViewById <TextView>(Resource.Id.tvwStrDtExt).Text      = "";
                                FindViewById <TextView>(Resource.Id.tvwResumeDtExt).Text   = "";
                                FindViewById <TextView>(Resource.Id.tvwDurationExt).Text   = "";
                                FindViewById <TextView>(Resource.Id.tvwRemainDaysExt).Text = "";
                                FindViewById <EditText>(Resource.Id.edtExtendTo).Text      = "";
                                FindViewById <TextView>(Resource.Id.edtReasonExt).Text     = "";
                                FindViewById <Spinner>(Resource.Id.spnLeaveExt).SetSelection(0);
                                tvwMsg.SuccessMsg("Records Saved Successfully");
                            }
                            else
                            {
                                tvwMsg.ErrorMsg((string)response["Error"]);
                            }
                        }
                        else
                        {
                            tvwMsg.ErrorMsg((string)response);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.Log();
                        tvwMsg.ErrorMsg(Values.ErrorMsg);
                    }
                }
                else
                {
                    tvwMsg.ErrorMsg("Day Applied For Cannot Be Greater Than Remaining Days");
                }
            }

            else
            {
                if (date == null)
                {
                    tvwMsg.ErrorMsg("Please choose a valid Resumption Date");
                }
                else if (date <= resumeDate)
                {
                    tvwMsg.ErrorMsg("Extension date must be greater than previous resumption date");
                }
                else if (selection <= 0)
                {
                    tvwMsg.ErrorMsg("Please select a Leave Type");
                }
            }
        }
Exemplo n.º 8
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.LeaveExtension);

            //set date textview
            TextView tvwMsg      = FindViewById <TextView>(Resource.Id.tvwMsgLeaveExt);
            EditText edtExtendTo = FindViewById <EditText>(Resource.Id.edtExtendTo);

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

            try
            {
                //to get other parameters to compute number of days from the web api asynchronously
                string restUrl = Values.ApiRootAddress + "LeaveExtension/?compId=" + new AppPreferences().GetValue(User.CompId) + "&EmployeeNo=" + new AppPreferences().GetValue(User.EmployeeNo);

                tvwMsg.BasicMsg(Values.LoadingMsg);
                dynamic response = await new DataApi().GetAsync(restUrl);
                tvwMsg.Text = "";

                if (IsJsonObject(response))
                {
                    response = response["Values"];                 //get the values sent by the web api

                    StoreToPref(response, "LeaveExt");             //store to preferences for future access
                    var     Leave        = GetLeaveType(response); //list to be used to populate spinner
                    var     LeaveAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, Leave);
                    Spinner spnLeaveExt  = FindViewById <Spinner>(Resource.Id.spnLeaveExt);
                    spnLeaveExt.Adapter       = LeaveAdapter;
                    spnLeaveExt.ItemSelected += spnLeaveExt_ItemSelected;
                    LeaveAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                }
                else
                {
                    tvwMsg.ErrorMsg((string)response);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
                tvwMsg.ErrorMsg(Values.ErrorMsg);
            }
            //get submit button and subscribe to its click event
            Button btnSubmitLeaveExt = FindViewById <Button>(Resource.Id.btnSubmitLeaveExt);

            btnSubmitLeaveExt.Click += btnSubmitLeaveExt_Click;
        }
Exemplo n.º 9
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.TrainingRequestLayout);

            try
            {
                TextView tvwResultMsg = FindViewById <TextView>(Resource.Id.tvwMsgTrnReq);
                string   url          = Values.ApiRootAddress + "training/getTrainings?compId=" + new AppPreferences().GetValue(User.CompId);

                tvwResultMsg.BasicMsg(Values.LoadingMsg);
                dynamic json = await new DataApi().GetAsync(url);
                tvwResultMsg.Text = "";
                if (IsJsonObject(json))
                {
                    JsonValue TrainingResults = json["Training"];

                    List <string> lstTrainingCode = new List <string>();
                    lstTrainingCode.Add("Nothing");
                    List <string> lstTrainingDesc = new List <string>();
                    lstTrainingDesc.Add("Please Select");

                    for (int i = 0; i < TrainingResults.Count; i++)
                    {
                        lstTrainingCode.Add(TrainingResults[i]["TRAININGCODE"]);
                        lstTrainingDesc.Add(TrainingResults[i]["DESCRIPTION"]);

                        SelectedTraining obj = new SelectedTraining();

                        obj.TrainingCode     = TrainingResults[i]["TRAININGCODE"];
                        obj.Description      = TrainingResults[i]["DESCRIPTION"];
                        obj.Duration         = TrainingResults[i]["DURATION"];
                        obj.Type             = TrainingResults[i]["TYPE"];
                        obj.TrainingSerialNo = TrainingResults[i]["TRNSNO"];
                        obj.Venue            = TrainingResults[i]["VENUE"];

                        selectedTraining.Add(obj);
                    }
                    ;

                    Spinner spnrTrainings = FindViewById <Spinner>(Resource.Id.spnrTrainingCode);

                    ArrayAdapter <string> spinnerArrayAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, lstTrainingDesc);
                    //Use the ArrayAdapter you've set up to populate your spinner
                    spnrTrainings.Adapter = spinnerArrayAdapter;
                    //optionally pre-set spinner to an index
                    spnrTrainings.SetSelection(0);

                    spnrTrainings.ItemSelected += async(sender, e) =>
                    {
                        Spinner spinner = (Spinner)sender;

                        //save the CODE and SERIALNO of training selected
                        ISharedPreferences       prefs  = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
                        ISharedPreferencesEditor editor = prefs.Edit();
                        editor.PutString("TrainingCode", lstTrainingCode[e.Position]);

                        //var position = e.Position.Equals(0) ? 0 : e.Position - 1;
                        if (e.Position > 0)
                        {
                            editor.PutInt("TrainingSerialNo", selectedTraining[e.Position - 1].TrainingSerialNo);
                            editor.Apply();
                        }

                        if (mDatasource.Count > 0)
                        {
                            mDatasource.Clear();
                        }

                        AppPreferences appPrefs = new AppPreferences();
                        tvwResultMsg.BasicMsg(Values.LoadingMsg);
                        mDatasource = await Nominees(lstTrainingCode[e.Position], appPrefs.GetValue(User.EmployeeNo), appPrefs.GetValue(User.CompId));

                        tvwResultMsg.Text = "";
                        //mDatasource = await new GetNominees().Nominees(spinner.GetItemAtPosition(e.Position).ToString());
                        if (mDatasource.Count == 0 && spnrTrainings.SelectedItemPosition != 0)
                        {
                            tvwResultMsg.ErrorMsg("No Employee To Nominate");
                        }
                        else
                        {
                            tvwResultMsg.Text = "";
                        }

                        mAdapter            = new EmpDetailsAdapter(mDatasource);
                        mAdapter.ItemClick += (s, args) =>
                        {
                            //Toast.MakeText(this, "who's the BOSS now!", ToastLength.Short).Show();
                            //Toast.MakeText(this, "who's the BOSS now!" + mDatasource[position].name, ToastLength.Short).Show();

                            editor.PutString("SelectedName", mDatasource[args].name);
                            editor.PutInt("NomineeEmployeeNo", mDatasource[args].number);
                            editor.Apply();

                            FragmentTransaction transcation    = FragmentManager.BeginTransaction();
                            Dialogclass         ConfirmNominee = new Dialogclass();
                            ConfirmNominee.DialogClosed += (dlgSender, dlgEvent) =>
                            {
                                if (dlgEvent)
                                {
                                    mAdapter.empList.RemoveAt(args);
                                    mAdapter.NotifyItemRemoved(args);
                                }
                            };
                            ConfirmNominee.Show(transcation, "Dialog Fragment");
                        };

                        mRecyclerView  = (RecyclerView)FindViewById(Resource.Id.recyclerView1);
                        mLayoutManager = new LinearLayoutManager(this);
                        mRecyclerView.SetLayoutManager(mLayoutManager);
                        mRecyclerView.SetAdapter(mAdapter);

                        if (e.Position > 0)
                        {
                            Toast.MakeText(this, "Training Venue: " + selectedTraining[e.Position - 1].Venue + "\r\n" + "Training Duration: " + selectedTraining[e.Position - 1].Duration, ToastLength.Short).Show();
                        }
                    };
                }
                else
                {
                    tvwResultMsg.ErrorMsg((string)json);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
        }
        //Used to get the Working Days based on the Dates selected
        //private async void GetWorkingDays()
        //{
        //    TextView tvwMsg = FindViewById<TextView>(Resource.Id.tvwMsgLeaveReq);
        //    TextView tvwDurationExt = FindViewById<TextView>(Resource.Id.tvwDurationExt);
        //    EditText edtStartDate = FindViewById<EditText>(Resource.Id.edtStartDate);
        //    EditText edtEndDate = FindViewById<EditText>(Resource.Id.edtExtendTo);
        //    string RemainingDays = FindViewById<TextView>(Resource.Id.tvwRemainDaysExt).Text;
        //    tvwMsg.Text = "";
        //    //Call getworking Days
        //    if (edtStartDate.Text != "" && edtEndDate.Text != "")
        //    {
        //        int StartDt = Convert.ToInt32(edtStartDate.Text.Replace("/", ""));
        //        int EndDt = Convert.ToInt32(edtEndDate.Text.Replace("/", ""));

        //        if (EndDt > StartDt)
        //        {
        //            string restUrl4 = Values.ApiRootAddress + "LeaveRecall/GetWorkDays/?strFromDate=" + edtStartDate.Text + "&strToDate=" + edtEndDate.Text + "&compId=" + new AppPreferences().GetValue(User.CompId);

        //            dynamic response = await new DataApi().GetAsync(restUrl4);
        //            int Days = (int)response;
        //            if (int.Parse(RemainingDays) >= Days)
        //            {
        //                tvwDurationExt.Text = (int)response + "";
        //            }
        //            else
        //            {
        //                tvwDurationExt.Text = "";
        //                tvwMsg.Text = "Day Applied For Cannot Be Greater Than Remaining Days";
        //            }
        //        }
        //    }
        //}

        //Used To Do variuos checks And To save the records
        private async void btnSubmitLvRec_Click(object sender, EventArgs e)
        {
            TextView tvwMsg = FindViewById <TextView>(Resource.Id.tvwMsgLeaveRecall);

            string   edtRecallDt = FindViewById <EditText>(Resource.Id.edtRecallDt).Text; //Get End Date
            DateTime?date        = ConvertStringToDate(edtRecallDt);

            int    selection = (int)FindViewById <Spinner>(Resource.Id.spnLeaveRec).SelectedItemId;
            string RecallEmp = selection + "";

            if (date != null && date > DateTime.Now && selection > 0)
            {
                try
                {
                    string restUrl      = Values.ApiRootAddress + "LeaveRecall";
                    var    contentLeave = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        { "spentDays", SpentDays },
                        { "AccountingYear", new AppPreferences().GetValue(User.AccountingYear) },
                        { "LvCode", LevCode },
                        { "LvGrp", LvGrp },
                        { "RqstId", RqstNo },
                        { "RecallEmp", ENMBR },
                        { "UserId", new AppPreferences().GetValue(User.UserId) },
                        { "CompId", new AppPreferences().GetValue(User.CompId) },
                        { "GRqstID", GRQSTID },
                        { "OldDuration", OldDuration },
                        { "RecallDt", edtRecallDt }
                    });

                    (sender as Button).Enabled = false;
                    tvwMsg.BasicMsg(Values.WaitingMsg);
                    dynamic response = await new DataApi().PostAsync(restUrl, contentLeave);
                    tvwMsg.Text = "";
                    (sender as Button).Enabled = true;

                    bool success = DataApi.IsJsonObject(response);
                    if (success)
                    {
                        if (response["Error"] == "")     //success
                        {
                            FindViewById <TextView>(Resource.Id.tvwLvTypeRec).Text  = "";
                            FindViewById <TextView>(Resource.Id.tvwStartDtRec).Text = "";
                            FindViewById <TextView>(Resource.Id.tvwResumeRec).Text  = "";
                            FindViewById <EditText>(Resource.Id.edtRecallDt).Text   = "";
                            FindViewById <Spinner>(Resource.Id.spnLeaveRec).SetSelection(0);
                            LoadSpinner();
                            tvwMsg.SuccessMsg("Records Saved Successfully");
                        }
                        else
                        {
                            tvwMsg.ErrorMsg((string)response["Error"]);
                        }
                    }
                    else
                    {
                        tvwMsg.ErrorMsg((string)response);
                    }
                }
                catch (Exception ex)
                {
                    ex.Log();
                    tvwMsg.ErrorMsg(Values.ErrorMsg);
                }
            }
            else
            {
                if (date == null)
                {
                    tvwMsg.ErrorMsg("Please select a recall Date");
                }
                else if (date <= DateTime.Now)
                {
                    tvwMsg.ErrorMsg("Please select a future date");
                }
                else if (selection == 0)
                {
                    tvwMsg.ErrorMsg("Please select a employee");
                }
            }
        }
        //Used To Do variuos checks And To save the records
        private async void BtnSubmitLeaveReq_Click(object sender, EventArgs e)
        {
            TextView tvwMsg = FindViewById <TextView>(Resource.Id.tvwMsgLeaveReq);
            string   msg    = ValidEntries();

            if (msg == "")
            {
                string StartdateStr = FindViewById <EditText>(Resource.Id.edtStartDate).Text; // Get Start Date
                string EnddateStr   = FindViewById <EditText>(Resource.Id.edtEndDate).Text;   //Get End Date

                string Allowance;
                if (FindViewById <CheckBox>(Resource.Id.chkAllowance).Checked) //checkbox item
                {
                    Allowance = "Y";
                }
                else
                {
                    Allowance = "N";
                }

                Spinner spnRelOfficer = FindViewById <Spinner>(Resource.Id.spnReliefOfficer);             //findViewById(R.id.spinner);
                string  RemainingDays = FindViewById <TextView>(Resource.Id.tvwNoOfDaysleft).Text;
                string  Duration      = FindViewById <TextView>(Resource.Id.tvwNoOfDays).Text;
                string  reason        = FindViewById <EditText>(Resource.Id.edtReasonReq).Text;
                int     selection     = (int)FindViewById <Spinner>(Resource.Id.spnLeaveReq).SelectedItemId;

                string[] Leaveitem = leaveitemList.ToArray();
                string   LeaveCode = Leaveitem.GetValue(selection - 1).ToString();
                // GetActiveLeave(string compId, string LvCode, string EmployeeNo)
                //   string RunningLeave = "";
                string restUrl4 = Values.ApiRootAddress + "LeaveRequest/GetActiveLeave/?compId=" + new AppPreferences().GetValue(User.CompId) + "&LvCode=" + LeaveCode + "&EmployeeNo=" + new AppPreferences().GetValue(User.EmployeeNo);

                try
                {
                    (sender as Button).Enabled = false;
                    tvwMsg.BasicMsg(Values.WaitingMsg);
                    dynamic responseL = await new DataApi().GetAsync(restUrl4);
                    tvwMsg.Text = "";
                    (sender as Button).Enabled = true;

                    bool success = IsJsonObject(responseL);
                    if (success)
                    {
                        string RunningLeave = responseL + "";

                        if (RunningLeave.Length == 0)
                        {
                            string restUrl      = Values.ApiRootAddress + "LeaveRequest";
                            var    contentLeave = new FormUrlEncodedContent(new Dictionary <string, string>
                            {
                                { "EmployeeNo", new AppPreferences().GetValue(User.EmployeeNo) },
                                { "AccountingYear", new AppPreferences().GetValue(User.AccountingYear) },
                                { "LvCode", LeaveCode },
                                { "RemainingDays", RemainingDays },
                                { "Duration", Duration },
                                { "StartdateStr", StartdateStr },
                                { "EnddateStr", EnddateStr },
                                { "Reason", reason },
                                { "Allowance", Allowance },
                                { "UserId", new AppPreferences().GetValue(User.UserId) },
                                { "CompId", new AppPreferences().GetValue(User.CompId) },
                                { "ReliefOfficerID", new AppPreferences().GetValue((spnRelOfficer.SelectedItemId - 1) + "") },
                                { "ReliefOfficer", spnRelOfficer.SelectedItem.ToString() }
                            });

                            (sender as Button).Enabled = false;
                            tvwMsg.BasicMsg(Values.WaitingMsg);
                            dynamic response = await new DataApi().PostAsync(restUrl, contentLeave);
                            tvwMsg.Text = "";
                            (sender as Button).Enabled = true;

                            success = DataApi.IsJsonObject(response);
                            if (success)
                            {
                                if (response["Error"] == "")     //success
                                {
                                    FindViewById <TextView>(Resource.Id.tvwNoOfDays).Text     = "";
                                    FindViewById <TextView>(Resource.Id.tvwNoOfDaysleft).Text = "";
                                    FindViewById <EditText>(Resource.Id.edtStartDate).Text    = "";
                                    FindViewById <EditText>(Resource.Id.edtEndDate).Text      = "";
                                    FindViewById <TextView>(Resource.Id.edtReasonReq).Text    = "";
                                    FindViewById <Spinner>(Resource.Id.spnLeaveReq).SetSelection(0);
                                    FindViewById <Spinner>(Resource.Id.spnReliefOfficer).SetSelection(0);
                                    FindViewById <CheckBox>(Resource.Id.chkAllowance).Checked = false;
                                    FindViewById <CheckBox>(Resource.Id.chkAllowance).Enabled = false;
                                    tvwMsg.SuccessMsg("Records Saved Successfully");
                                }
                                else
                                {
                                    tvwMsg.ErrorMsg((string)response["Error"]);
                                }
                            }
                            else
                            {
                                tvwMsg.ErrorMsg((string)response);
                            }
                        }

                        else
                        {
                            tvwMsg.ErrorMsg(RunningLeave);
                        }
                    }
                    else
                    {
                        tvwMsg.ErrorMsg((string)responseL);
                    }
                }
                catch (Exception ex)
                {
                    ex.Log();
                    tvwMsg.ErrorMsg(Values.ErrorMsg);
                }
            }
            else
            {
                tvwMsg.ErrorMsg(msg);
            }
        }
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.LeaveRequest);

            //set date textview
            TextView tvwMsg       = FindViewById <TextView>(Resource.Id.tvwMsgLeaveReq);
            EditText edtStartDate = FindViewById <EditText>(Resource.Id.edtStartDate);

            edtStartDate.Text   = new CommonMethodsClass().ConvertDateToString(DateTime.Today);
            edtStartDate.Click += (s, e) =>
            {
                var dateTimeNow             = DateTime.Now;
                DatePickerDialog datePicker = new DatePickerDialog
                                                  (this,
                                                  (sender, eventArgs) =>
                {
                    edtStartDate.Text = eventArgs.Date.Day + "/" + eventArgs.Date.Month + "/" + eventArgs.Date.Year;
                    GetWorkDays();
                },
                                                  dateTimeNow.Year, dateTimeNow.Month - 1, dateTimeNow.Day);
                datePicker.Show();
            };
            EditText edtEndDate = FindViewById <EditText>(Resource.Id.edtEndDate);

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

            try
            {
                //to get other parameters to compute number of days from the web api asynchronously
                string restUrl = Values.ApiRootAddress + "LeaveRequest/?compId=" + new AppPreferences().GetValue(User.CompId) + "&EmployeeNo=" + new AppPreferences().GetValue(User.EmployeeNo);
                tvwMsg.BasicMsg(Values.LoadingMsg);
                dynamic response = await new DataApi().GetAsync(restUrl);
                tvwMsg.Text = "";

                if (IsJsonObject(response))
                {
                    response = response["Values"];                 //get the values sent by the web api

                    StoreToPref(response, "Leave");                //store to preferences for future access
                    var     Leave        = GetLeaveType(response); //list to be used to populate spinner
                    var     LeaveAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, Leave);
                    Spinner spnLeave     = FindViewById <Spinner>(Resource.Id.spnLeaveReq);
                    spnLeave.Adapter       = LeaveAdapter;
                    spnLeave.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spnLeave_ItemSelected);
                    LeaveAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                }
                else
                {
                    tvwMsg.ErrorMsg((string)response);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
                tvwMsg.ErrorMsg(Values.ErrorMsg);
            }

            try
            {
                //to get other parameters to compute number of days from the web api asynchronously
                // string urlMethod = "LeaveRequest" + "/" + "GetReliefOfficer";
                string restUrl2 = Values.ApiRootAddress + "LeaveRequest/GetReliefOfficer/?compId=" + new AppPreferences().GetValue(User.CompId) + "&LocationCode=" + new AppPreferences().GetValue(User.LocationCode) + "&Department=" + new AppPreferences().GetValue(User.DeptCode) + "&EmployeeNo=" + new AppPreferences().GetValue(User.EmployeeNo);

                tvwMsg.BasicMsg(Values.LoadingMsg);
                dynamic response = await new DataApi().GetAsync(restUrl2);
                tvwMsg.Text = "";

                if (IsJsonObject(response))
                {
                    response = response["Values"];                             //get the values sent by the web api

                    StoreToPref(response, "relief");                           //store to preferences for future access
                    var     ReliefOfficer        = GetReliefOfficer(response); //list to be used to populate spinner
                    var     ReliefOfficerAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, ReliefOfficer);
                    Spinner spnReliefOfficer     = FindViewById <Spinner>(Resource.Id.spnReliefOfficer);
                    spnReliefOfficer.Adapter = ReliefOfficerAdapter;
                }
                else
                {
                    tvwMsg.ErrorMsg((string)response);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
                tvwMsg.SuccessMsg(Values.ErrorMsg);
            }

            //get submit button and subscribe to its click event
            Button BtnSubmitLeaveReq = FindViewById <Button>(Resource.Id.btnSubmitLeaveReq);

            BtnSubmitLeaveReq.Click += BtnSubmitLeaveReq_Click;
        }
        public async void GetWorkDays()
        {
            string   RemainingDays = FindViewById <TextView>(Resource.Id.tvwNoOfDaysleft).Text;
            TextView tvwMsg        = FindViewById <TextView>(Resource.Id.tvwMsgLeaveReq);
            TextView tvwNoOfDays   = FindViewById <TextView>(Resource.Id.tvwNoOfDays);
            EditText tvwEndDate    = FindViewById <EditText>(Resource.Id.edtEndDate);
            string   startDate     = FindViewById <EditText>(Resource.Id.edtStartDate).Text;
            string   endDate       = FindViewById <EditText>(Resource.Id.edtEndDate).Text;

            DateTime?dateStart = ConvertStringToDate(startDate);
            DateTime?dateEnd   = ConvertStringToDate(endDate);

            if (dateStart != null && dateEnd != null && dateStart >= DateTime.Today && dateEnd > dateStart)
            {
                string restUrl4 = Values.ApiRootAddress + "LeaveRequest/GetWorkDays/?strFromDate=" + startDate + "&strToDate=" + endDate + "&compId=" + new AppPreferences().GetValue(User.CompId);

                tvwMsg.BasicMsg(Values.WaitingMsg);
                dynamic response = await new DataApi().GetAsync(restUrl4);
                tvwMsg.Text = "";

                if (IsJsonObject(response))
                {
                    int  Days = (int)response;
                    int  remDays;
                    bool validRemDays = int.TryParse(RemainingDays, out remDays);
                    if (validRemDays && remDays >= Days)
                    {
                        tvwNoOfDays.Text = (int)response + "";
                        tvwMsg.Text      = "";
                    }
                    else
                    {
                        tvwEndDate.Text  = "";
                        tvwNoOfDays.Text = "";
                        if (!validRemDays)
                        {
                            tvwMsg.ErrorMsg("Please select a leave type");
                        }
                        else
                        {
                            tvwMsg.ErrorMsg("Day Applied For Cannot Be Greater Than Remaining Days");
                        }
                    }
                }
                else
                {
                    tvwEndDate.Text  = "";
                    tvwNoOfDays.Text = "";
                    tvwMsg.ErrorMsg((string)response);
                }
            }
            else
            {
                tvwEndDate.Text  = "";
                tvwNoOfDays.Text = "";
                if (dateStart == null)
                {
                    tvwMsg.ErrorMsg("");
                }
                else if (dateEnd == null)
                {
                    tvwMsg.ErrorMsg("");
                }
                else if (dateStart < DateTime.Today)
                {
                    tvwMsg.ErrorMsg("Start date cannot be less than today's date");
                }
                else
                {
                    tvwMsg.ErrorMsg("End date must be greater than start date");
                }
            }
        }
        private async void btnSubmitAbsReq_Click(object sender, EventArgs e)
        {
            TextView tvwMsg    = FindViewById <TextView>(Resource.Id.tvwMsg);
            TextView tvwReason = FindViewById <TextView>(Resource.Id.edtReasonAbsReq);
            string   dateStr   = FindViewById <EditText>(Resource.Id.edtDateAbsReq).Text;
            DateTime?date      = ConvertStringToDate(dateStr);
            string   reason    = FindViewById <EditText>(Resource.Id.edtReasonAbsReq).Text;

            if (date != null && date > DateTime.Now && reason.Length > 0)
            {
                try
                {
                    string restUrl = Values.ApiRootAddress + "Absenteeism";
                    var    content = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        { "EmployeeNo", new AppPreferences().GetValue(User.EmployeeNo) },
                        { "DateStr", dateStr },
                        { "Reason", reason },
                        { "UserId", new AppPreferences().GetValue(User.UserId) },
                        { "CompId", new AppPreferences().GetValue(User.CompId) }
                    });

                    (sender as Button).Enabled = false;
                    tvwMsg.BasicMsg(Values.WaitingMsg);
                    dynamic response = await new DataApi().PostAsync(restUrl, content);
                    tvwMsg.Text = "";
                    (sender as Button).Enabled = true;

                    bool success = DataApi.IsJsonObject(response);
                    if (success)
                    {
                        if (response["Error"] == "")     //success
                        {
                            FindViewById <EditText>(Resource.Id.edtDateAbsReq).Text   = "";
                            FindViewById <EditText>(Resource.Id.edtReasonAbsReq).Text = "";
                            tvwMsg.SuccessMsg("Records Saved Successfully");
                        }
                        else
                        {
                            tvwMsg.ErrorMsg((string)response["Error"]);
                        }
                    }
                    else
                    {
                        tvwMsg.ErrorMsg((string)response);
                    }
                }
                catch (Exception ex)
                {
                    ex.Log();
                    tvwMsg.ErrorMsg(Values.ErrorMsg);
                }
            }
            else
            {
                if (date == null)
                {
                    tvwMsg.ErrorMsg("Please select a date");
                }
                else if (date <= DateTime.Now)
                {
                    tvwMsg.ErrorMsg("Please select a future time");
                }
                else
                {
                    tvwMsg.ErrorMsg("Please enter your reason");
                }
            }

            (sender as Button).Enabled = true;
        }