public async Task <string> PostMedical(Appraisee appraisee, dynamic response, string status, string comment) { string restUrl = Values.ApiRootAddress + "Approval"; var content = new FormUrlEncodedContent(new Dictionary <string, string> { { "EmployeeNo", new AppPreferences().GetValue(User.EmployeeNo) }, { "RequestId", appraisee.RequestId + "" }, { "Reason", comment }, { "UserName", new AppPreferences().GetValue(User.UserId) }, { "CompanyCode", new AppPreferences().GetValue(User.CompId) }, { "ApproveeNo", (int)response[0]["REQ_EMP_ID"] + "" }, { "Status", status }, { "AlertId", appraisee.Alertid + "" }, { "RequestType", appraisee.ApprovalType }, { "RequestNo", (string)response[0]["REQ_NO"] } }); FindViewById <TextView>(Resource.Id.tvwWkvMsg).BasicMsg(Values.WaitingMsg); response = await new DataApi().PostAsync(restUrl, content); FindViewById <TextView>(Resource.Id.tvwWkvMsg).Text = ""; bool success = DataApi.IsJsonObject(response); if (success) { return(response["Error"]); } else { return((string)response); } }
//action to take befor user logs in private async Task <object[]> PreLoginActions(string compId, string userId, string empNo) { object[] status = await DeviceRegistered(this); if ((bool)status[0]) { string restUrl = Values.ApiRootAddress + "Notification/PostPreLogin"; var content = new FormUrlEncodedContent(new Dictionary <string, string> { { "CompId", compId }, { "EmpNo", empNo }, { "UserId", userId }, { "DeviceId", FirebaseInstanceId.Instance.Token } }); dynamic response = await new DataApi().PostAsync(restUrl, content); if (DataApi.IsJsonObject(response)) { response = response["Values"]; //generate notification(s) if (response.Count > 0) { CreateNotification(response); } } else { status[1] = (string)response; } } return(status); }
protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Absenteeism); // Create your application here Button btnSubmitAbsReq = FindViewById <Button>(Resource.Id.btnSubmitAbsReq); btnSubmitAbsReq.Click += btnSubmitAbsReq_Click; //set date textview TextView tvwMsg = FindViewById <TextView>(Resource.Id.tvwMsg); TextView tvwReason = FindViewById <TextView>(Resource.Id.edtReasonAbsReq); EditText edtDateAbsReq = FindViewById <EditText>(Resource.Id.edtDateAbsReq); edtDateAbsReq.Click += (s, e) => { var dateTimeNow = DateTime.Now; DatePickerDialog datePicker = new DatePickerDialog (this, (sender, eventArgs) => { edtDateAbsReq.Text = eventArgs.Date.Day + "/" + eventArgs.Date.Month + "/" + eventArgs.Date.Year; }, dateTimeNow.Year, dateTimeNow.Month - 1, dateTimeNow.Day); datePicker.Show(); }; tvwMsg.ErrorMsg((string)(await DataApi.NetworkAccessStatus())[1]); }
//check the registration status of device public async Task <object[]> DeviceRegistered(Activity callingActivity) { object[] values = new object[2]; values[0] = true; int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(callingActivity); if (resultCode == ConnectionResult.Success && !string.IsNullOrEmpty(FirebaseInstanceId.Instance.Token)) { values[1] = ""; } else { if (resultCode != ConnectionResult.Success) { if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode)) { values[1] = "From Google Play Service: " + GoogleApiAvailability.Instance.GetErrorString(resultCode); } else { values[1] = "This device does not support google play services"; //t = new Timer(3000); do not terminate app //t.Elapsed += (s, e) => { Finish(); t.Dispose(); }; //t.Start(); } } else { values[0] = false; if ((bool)(await DataApi.NetworkAccessStatus())[0]) { values[1] = "Google Play Service Initializing. Please try again later"; } else { values[1] = "Connect to the internet to initialize device"; } } } return(values); }
public async Task <string> PostTraining(Appraisee appraisee, dynamic response, string status, string comment) { string restUrl = Values.ApiRootAddress + "Approval"; int outInt; string approveeNo = response[0]["Employee No"].ToString(); approveeNo = int.TryParse(approveeNo, out outInt) ? approveeNo : approveeNo.Remove(approveeNo.Length - 2); string serialNo = response[0]["SrNo"].ToString(); serialNo = int.TryParse(serialNo, out outInt) ? serialNo : serialNo.Remove(serialNo.Length - 2); var content = new FormUrlEncodedContent(new Dictionary <string, string> { { "EmployeeNo", new AppPreferences().GetValue(User.EmployeeNo) }, { "RequestId", appraisee.RequestId + "" }, { "Reason", comment }, { "UserName", new AppPreferences().GetValue(User.UserId) }, { "CompanyCode", new AppPreferences().GetValue(User.CompId) }, { "ApproveeNo", approveeNo }, { "Status", status }, { "AlertId", appraisee.Alertid + "" }, { "RequestType", appraisee.ApprovalType }, { "SerialNo", serialNo }, { "ProgramCode", (string)response[0]["Training"] } }); FindViewById <TextView>(Resource.Id.tvwWkvMsg).BasicMsg(Values.WaitingMsg); response = await new DataApi().PostAsync(restUrl, content); FindViewById <TextView>(Resource.Id.tvwWkvMsg).Text = ""; bool success = DataApi.IsJsonObject(response); if (success) { return(response["Error"]); } else { return((string)response); } }
public async Task <string> PostLeave(Appraisee appraisee, dynamic response, string status, string comment) { string restUrl = Values.ApiRootAddress + "Approval"; var content = new FormUrlEncodedContent(new Dictionary <string, string> { { "EmployeeNo", new AppPreferences().GetValue(User.EmployeeNo) }, { "RequestId", appraisee.RequestId + "" }, { "Reason", comment }, { "UserName", new AppPreferences().GetValue(User.UserId) }, { "CompanyCode", new AppPreferences().GetValue(User.CompId) }, { "ApproveeNo", (int)response[0]["EmpNo"] + "" }, { "Status", status }, { "AlertId", appraisee.Alertid + "" }, { "RequestType", appraisee.ApprovalType }, { "RequestNo", response[0]["Rqst_No"].ToString() }, { "ProcessFrom", DateTime.Parse((string)response[0]["StrtDt"]).ToString("dd-MMM-yyyy") }, { "ProcessTo", DateTime.Parse((string)response[0]["EndDt"]).ToString("dd-MMM-yyyy") }, { "DayStart", DateTime.Parse((string)response[0]["StrtDt"]).ToString("dd-MMM-yyyy") }, { "DayEnd", DateTime.Parse((string)response[0]["EndDt"]).ToString("dd-MMM-yyyy") }, { "DayDiff", (int)response[0]["NoOfDays"] + "" } }); FindViewById <TextView>(Resource.Id.tvwWkvMsg).BasicMsg(Values.WaitingMsg); response = await new DataApi().PostAsync(restUrl, content); FindViewById <TextView>(Resource.Id.tvwWkvMsg).Text = ""; bool success = DataApi.IsJsonObject(response); // || response.ToString() == Values.ServerErrorMsg; if (success) { return(response["Error"]); } else { return((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); } }
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); } }
//void LoadWebView() //{ // var webView = FindViewById<WebView>(Resource.Id.webView1); // string url = Values.ApiRootAddress.Substring(0, Values.ApiRootAddress.Length - 4); // webView.LoadUrl(url + "WebViewPage.html"); // webView.SetWebChromeClient(new WebChromeClient()); // webView.Settings.JavaScriptEnabled = true; // webView.Settings.DomStorageEnabled = true; //} private async void BtnSubmit_Click(object sender, EventArgs e) { EditText edtUserId = FindViewById <EditText>(Resource.Id.edtUserId); EditText edtPassword = FindViewById <EditText>(Resource.Id.edtPassword); TextView tvwMsg = FindViewById <TextView>(Resource.Id.tvwMsg); if (edtUserId.Text.Trim().Length > 0 && edtPassword.Text.Length > 0) { try { tvwMsg.SetTextColor(Color.White); tvwMsg.Text = Values.WaitingMsg; string encryptedPassword = new Encryption().EncryptText(edtPassword.Text); string restUrl = Values.ApiRootAddress + "Login"; var content = new FormUrlEncodedContent(new Dictionary <string, string> { { "UserId", edtUserId.Text.Trim() }, { "Password", encryptedPassword } }); dynamic response = await new DataApi().PostAsync(restUrl, content); // await result from data api asynchroonously bool success = DataApi.IsJsonObject(response); //valid result if (success) { //check content length if (response["Error"] == "") { object[] status = await PreLoginActions((string)response["CompId"], edtUserId.Text.Trim().ToUpper(), response["EmployeeNo"].ToString()); if ((bool)status[0]) { if ((string)status[1] != "") { Toast.MakeText(this, (string)status[1], ToastLength.Short).Show(); //show any warning available } SaveToPreferences(response, edtUserId.Text.Trim().ToUpper(), encryptedPassword); StartActivity(typeof(HomeActivity)); //go to the home page } else { tvwMsg.ErrorMsg((string)status[1]); } } else { tvwMsg.ErrorMsg((string)response["Error"]); //error from the server response body } } else { tvwMsg.ErrorMsg((string)response); //error communicating with server } } catch (Exception ex) { ex.Log(); tvwMsg.ErrorMsg(Values.ErrorMsg); //standard exception messag } } else { if (edtUserId.Text.Length == 0) { tvwMsg.ErrorMsg("Please Enter Your Username"); } else { tvwMsg.ErrorMsg("Please Enter Your Password"); } } }
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); } }
public override Dialog OnCreateDialog(Bundle savedInstanceState) { //get the selected name from shared preference ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context); var Name = prefs.GetString("SelectedName", ""); var view = Activity.LayoutInflater.Inflate(Resource.Layout.TrainingNominateDialog, null); TextView tvMessage = view.FindViewById <TextView>(Resource.Id.textView2); TextView tvwResultMsg = Activity.FindViewById <TextView>(Resource.Id.tvwMsgTrnReq); AlertDialog.Builder alert = new AlertDialog.Builder(Activity); alert.SetTitle("Confirm selection"); string Message = "are you nominating " + Name + " for the training?"; //alert.SetMessage(Message); tvMessage.Text = Message; string uri = Values.ApiRootAddress + "training/SaveNominee"; alert.SetPositiveButton("Nominate", async(senderAlert, args) => { AppPreferences appPrefs = new AppPreferences(); var NominateUser = new FormUrlEncodedContent(new Dictionary <string, string> { { "CompanyCode", appPrefs.GetValue(User.CompId) }, // "CO000001", { "TrainingCode", prefs.GetString("TrainingCode", "") }, { "TrainingSerialNo", prefs.GetInt("TrainingSerialNo", 0) + "" }, // 1, { "NomineeEmployeeNo", prefs.GetInt("NomineeEmployeeNo", 0) + "" }, //43, { "ReqEmployeeNo", appPrefs.GetValue(User.EmployeeNo) }, // 694, { "Reason", view.FindViewById <EditText>(Resource.Id.edtTxtReason).Text }, { "Username", appPrefs.GetValue(User.UserId) } }); tvwResultMsg.Text = Values.WaitingMsg; dynamic json = await new DataApi().PostAsync(uri, NominateUser); tvwResultMsg.Text = ""; if (DataApi.IsJsonObject(json)) { if (json != null) { if (json["status"] == 0) { DialogClosed?.Invoke(this, true); tvwResultMsg.SuccessMsg((string)json["message"]); } else { tvwResultMsg.ErrorMsg((string)json["message"]); } //Toast.MakeText(new Activity(), json["message"].ToString(), ToastLength.Short).Show(); } } else { tvwResultMsg.ErrorMsg((string)json); } Dismiss(); }); alert.SetNegativeButton("Cancel", (senderAlert, args) => { Dismiss(); //Toast.MakeText(Activity, "Cancelled!", ToastLength.Short).Show(); }); alert.SetView(view); return(alert.Create()); }
//to test validity of DataApi response as JSON object protected virtual bool IsJsonObject(dynamic response) { return(DataApi.IsJsonObject(response)); }
protected static Bitmap bmp; //in memory storage for user's profile picture protected async override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); base.SetContentView(Resource.Layout.BaseLayout); TextView tvw = FindViewById <TextView>(Resource.Id.tvwWelcome); tvw.Text = "Welcome " + new AppPreferences().GetValue(User.Name); ImageView ProfileImage = FindViewById <ImageView>(Resource.Id.profileImage); ProfileImage.Click += (sender, e) => { FragmentTransaction ft = FragmentManager.BeginTransaction(); MyDialogFragment newFragment = new MyDialogFragment(this); // Pass it with the Bundle class Bundle bundle = new Bundle(); using (MemoryStream stream = new MemoryStream()) { bmp?.Compress(Bitmap.CompressFormat.Jpeg, 100, stream); byte[] picByte = stream.ToArray(); bundle.PutByteArray("imgId", picByte); } newFragment.Arguments = bundle; newFragment.Show(ft, "dialog"); //show the Fragment newFragment.imageChanged += async(s, bmpEv) => { //convert bitmap to stream and send using (MemoryStream stream = new MemoryStream()) { bmpEv.Compress(Bitmap.CompressFormat.Jpeg, 100, stream); byte[] imageByte = stream.ToArray(); try { string uri = Values.ApiRootAddress + "UserProfile/PutImage?empNo=" + new AppPreferences().GetValue(User.EmployeeNo) + "&empName=" + new AppPreferences().GetValue(User.UserId) + "&compId=" + new AppPreferences().GetValue(User.CompId); Toast.MakeText(this, Values.WaitingMsg, ToastLength.Short).Show(); dynamic json = await new DataApi().PutAsync(uri, new ByteArrayContent(imageByte)); bool success = DataApi.IsJsonObject(json); if (success) { if (json["ErrorStatus"] == 0) { bmp = bmpEv; ProfileImage.SetImageBitmap(bmp); Toast.MakeText(this, "Uploaded successfully", ToastLength.Short).Show(); } else { Toast.MakeText(this, "Upload failed", ToastLength.Short).Show(); } } else { Toast.MakeText(this, (string)json, ToastLength.Short).Show(); } } catch (Exception ex) { ex.Log(); Toast.MakeText(this, "An error occured while uploading picture", ToastLength.Short).Show(); } } }; }; if (bmp == null) { byte[] picByte = await GenerateProfilePic(); bmp = BitmapFactory.DecodeByteArray(picByte, 0, picByte.Length); ProfileImage.SetImageBitmap(bmp); //if the asynchronous call completes late } else { ProfileImage.SetImageBitmap(bmp); } } 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); } }
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; }