public SortedList <FIO, PupilDay> GetPupilList(DateTime date) { var outList = new SortedList <FIO, PupilDay> (); foreach (var pupil in this._pupils) { var pupilDayEntry = pupil.Value.FirstOrDefault(p => p.Key.Equals(date)); PupilDay pupilDay; if (pupilDayEntry.Value == null) { pupilDay = new PupilDay { IsDiscount = pupil.Key.IsDiscount } } ; else { pupilDay = new PupilDay { IsDiscount = pupilDayEntry.Value.IsDiscount, Payment = pupilDayEntry.Value.Payment, Presence = pupilDayEntry.Value.Presence, Comment = pupilDayEntry.Value.Comment } }; var key = new FIO { FirstName = pupil.Key.FirstName, IsDiscount = pupil.Key.IsDiscount, LastName = pupil.Key.LastName }; outList.Add(key, pupilDay); } return(outList); }
public bool Pay(DateTime date, FIO fio, decimal payment) { if (this._pupils.ContainsKey(fio)) { var pupil = this._pupils [fio]; if (pupil.ContainsKey(date)) { var pupilDay = pupil [date]; pupilDay.Payment = payment; } else { pupil.Add(date, new PupilDay { Payment = payment, Presence = true, IsDiscount = this._pupils.First(pupilItem => pupilItem.Key.Equals(fio)).Key.IsDiscount }); } return(true); } else { return(false); } }
public decimal GetAmount(DateTime date, FIO fio) { if (_pupils.ContainsKey(fio) && this._pupils[fio].ContainsKey(date)) { return(this._pupils[fio][date].Payment); } return(0); }
public bool Equals(FIO fio) { if (fio == null) { return(false); } return(this.FirstName.Equals(fio.FirstName) && this.LastName.Equals(fio.LastName)); }
public bool RemovePupil(FIO fio) { if (fio == null) { return(false); } else if (_pupils.ContainsKey(fio)) { _pupils.Remove(fio); return(true); } return(false); }
private void menu_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) { var class1 = ClassItem.Instance; var menu = (Spinner)sender; var pupil = (string)menu.GetItemAtPosition(e.Position); var pupilSplittedName = pupil.Split('|'); this._currentPupil = new FIO { FirstName = pupilSplittedName[1].Trim(), LastName = pupilSplittedName[0].Trim() }; var amount = FindViewById <EditText>(Resource.Id.amount); if (this._currentPupil != null && this._dateTime != null) { amount.Text = class1.GetAmount(this._dateTime, this._currentPupil).ToString(); } }
public bool AddOrEditPupil(FIO fioOld, FIO fioNew) { if (_pupils.Keys.Any(fio => fio.Equals(fioNew) && fioNew != null && fio.IsDiscount == fioNew.IsDiscount)) { return(false); } if (fioOld == null) { if (!_pupils.ContainsKey(fioNew)) { _pupils.Add(fioNew, new SortedList <DateTime, PupilDay> ()); return(true); } else { return(false); } } else if (_pupils.ContainsKey(fioOld)) { var tmpfio = _pupils.Keys.FirstOrDefault(fio => fio.Equals(fioOld)); if (tmpfio == default(FIO)) { return(false); } else { var tmpPupilDays = _pupils[tmpfio]; _pupils.Remove(tmpfio); _pupils.Add(fioNew, tmpPupilDays); return(true); } } else { return(false); } }
public static void Merge(this FIO fioOld, FIO fioNew) { fioOld.FirstName = fioNew.FirstName; fioOld.LastName = fioNew.LastName; fioOld.IsDiscount = fioNew.IsDiscount; }
protected override void OnCreate(Bundle bundle) { var class1 = ClassItem.Instance; base.OnCreate(bundle); SetContentView(Resource.Layout.AddOrEditPupil); var menu = FindViewById <Spinner>(Resource.Id.menu); menu.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(menu_ItemSelected); var pupilList = class1.GetPupilList(DateTime.Today); var pupilArray = new List <string>(); foreach (var item in pupilList) { pupilArray.Add(string.Format("{0} | {1} | {2}", item.Key.LastName, item.Key.FirstName, item.Key.IsDiscount ? "л" : "")); } var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, pupilArray.ToArray()); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); menu.Adapter = adapter; Button oK = FindViewById <Button> (Resource.Id.oK); oK.Click += delegate { FIO old = null; var edit = FindViewById <CheckBox>(Resource.Id.edit); if (edit.Checked) { old = new FIO(); var pupil = (string)menu.SelectedItem; var pupilSplittedName = pupil.Split('|'); old.LastName = pupilSplittedName[0].Trim(); old.FirstName = pupilSplittedName[1].Trim(); if (pupilSplittedName.Length == 3) { old.IsDiscount = pupilSplittedName[2].Trim() == "л"; } } ClassItem.Instance.AddOrEditPupil(old, new FIO { FirstName = FindViewById <EditText>(Resource.Id.firstName).Text, LastName = FindViewById <EditText>(Resource.Id.lastName).Text, IsDiscount = FindViewById <CheckBox>(Resource.Id.isDiscount).Checked }); Finish(); }; Button cancel = FindViewById <Button> (Resource.Id.cancel); cancel.Click += delegate { Finish(); }; var lastName = FindViewById <EditText>(Resource.Id.lastName); lastName.FocusChange += (object sender, View.FocusChangeEventArgs e) => { var currentSender = sender as EditText; if (e.HasFocus && currentSender != null) { if (currentSender.Text == "Фамилия") { currentSender.Text = string.Empty; } // if((FindViewById<EditText>(Resource.Id.lastName)).Text != "Фамилия" // || (FindViewById<EditText>(Resource.Id.firstName)).Text != "Имя") // { // var edit = FindViewById<CheckBox>(Resource.Id.edit); // edit.Checked = !edit.Checked; // } } }; var firstName = FindViewById <EditText>(Resource.Id.firstName); firstName.FocusChange += (object sender, View.FocusChangeEventArgs e) => { var currentSender = sender as EditText; if (e.HasFocus && currentSender != null) { if (currentSender.Text == "Имя") { currentSender.Text = string.Empty; } // if((FindViewById<EditText>(Resource.Id.lastName)).Text != "Фамилия" // || (FindViewById<EditText>(Resource.Id.firstName)).Text != "Имя") // { // var edit = FindViewById<CheckBox>(Resource.Id.edit); // edit.Checked = !edit.Checked; // } } }; }