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(); } }
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()); }
protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); try { SetContentView(Resource.Layout.UserProfile); //get data from API AppPreferences appPref = new AppPreferences(); string uri = Values.ApiRootAddress + "UserProfile/GetBasicDetails?compId=" + appPref.GetValue(User.CompId) + "&empNo=" + appPref.GetValue(User.EmployeeNo); Toast.MakeText(this, Values.LoadingMsg, ToastLength.Short).Show(); dynamic json = await new DataApi().GetAsync(uri); if (IsJsonObject(json)) { JsonValue basicDetailsData = json["BasicDetails"]; JsonValue qualificationsData = json["Qualifications"]; JsonValue profCredentialsData = json["ProfessionalCredentials"]; JsonValue employeeTypeData = json["EmployeeType"]; JsonValue reportToData = json["ReportTo"]; ExpandableListView expListView = FindViewById <ExpandableListView>(Resource.Id.expdLstVw1); //Bind list List <string> parentList = GenerateParents(); Dictionary <string, List <string> > childDictionaryList = GenerateChildItems(parentList, basicDetailsData, qualificationsData, profCredentialsData, employeeTypeData, reportToData); MyExpandableListAdapter listAdapter = new MyExpandableListAdapter(this, parentList, childDictionaryList); expListView.SetAdapter(listAdapter); expListView.ExpandGroup(0); expListView.ExpandGroup(1); expListView.ExpandGroup(2); expListView.ExpandGroup(3); expListView.ExpandGroup(4); } else { Toast.MakeText(this, (string)json, ToastLength.Long).Show(); } } catch (Exception ex) { ex.Log(); Toast.MakeText(this, Values.ErrorMsg, ToastLength.Long).Show(); } }