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; }