public bool Sync() { Member m = MemberModel.FromId(this.Id); if(m == null) return false; this.InnerClient = m.InnerClient; this.BirthDate = m.BirthDate; this.JoinDate = m.JoinDate; this.PaymentDay = m.PaymentDay; this.Height = m.Height; this.Weight = m.Weight; this.Gender = m.Gender; this.Pack = m.Pack; this.Active = m.Active; this.InnerContact = m.InnerContact; this.BinImage = m.BinImage; return true; }
//step 3 private void MemberInfo() { //if the member's inner client is null and the user has reached this //step, the user has chosen a client id instead of creating one... //and here we are verifying the info given before if(this.TargetMember.InnerClient == null) { ClientModel cm = new ClientModel(); bool error = false; string msg = ""; Client c = new Client(); c.Id = this.ClientId; if(!cm.ExistsById(c.Id)) { msg = "No se puede encontrar al número de cliente " + this.ClientId; error = true; } else if(cm.IsMember(c)) { msg = "El cliente elegido ya es un miembro del gimnasio"; error = true; } if(error) { GuiHelper.ShowError(this, msg); this.Step -= 1; return; } } //ok, let's continue if everything as expected: //if InnerClient == null, this.ClientId should hold //an integer pointing to an existing client :) if(!this.MemberInitialized) { this.MemberInitialized = true; this.TargetMember.Height = 1.0; this.TargetMember.Weight = 40.0; this.TargetMember.Gender = 'm'; this.TargetMember.BirthDate = DateTime.Today; Contact ctc = new Contact(); ctc.Name = ""; ctc.PhoneNumber = ""; this.TargetMember.InnerContact = ctc; this.TargetMember.PaymentDay = DateTime.Today.Day; this.TargetMember.JoinDate = DateTime.Today; this.TargetMember.Pack = 0; } this.ClearContentBox(); this.Description = "Información requerida del nuevo miembro"; Label l1 = new Label("Peso (Kg)"); Label l2 = new Label("Estatura (Mts)"); Label l3 = new Label("Sexo"); Label l4 = new Label("Nacimiento"); Label l5 = new Label("\nEn caso de accidente, contactar a la siguiente persona:\n"); Label l6 = new Label("Nombre"); Label l7 = new Label("Teléfono"); SpinButton weight_spin = new SpinButton(40, 200, 0.01); SpinButton height_spin = new SpinButton(1, 2.5, 0.01); ComboBox gender_combo = new ComboBox(new string[] {"Masculino", "Femenino"}); DateWidget dw = new DateWidget(); Entry contact_name_entry = new Entry(); Entry contact_phone_entry = new Entry(); weight_spin.Changed += (s, a) => { float weight; this.TargetMember.Weight = (float.TryParse(weight_spin.Text, out weight) ? weight : weight_spin.Value); }; height_spin.Changed += (s, a) => { float height; this.TargetMember.Height = (float.TryParse(height_spin.Text, out height) ? height : height_spin.Value); }; gender_combo.Changed += (s, a) => this.TargetMember.Gender = (gender_combo.Active == 0 ? 'm' : 'f'); contact_name_entry.Changed += (s, a) => this.TargetMember.InnerContact.Name = contact_name_entry.Text.Trim(); contact_phone_entry.Changed += (s, a) => this.TargetMember.InnerContact.PhoneNumber = contact_phone_entry.Text.Trim(); dw.Changed += (s, a) => this.TargetMember.BirthDate = dw.Date; this.PackWidgetPair(l1, weight_spin); this.PackWidgetPair(l2, height_spin); this.PackWidgetPair(l3, gender_combo); this.PackWidgetPair(l4, dw.Box); this.PackWidgetSingle(l5); this.PackWidgetPair(l6, contact_name_entry); this.PackWidgetPair(l7, contact_phone_entry); weight_spin.Value = this.TargetMember.Weight; height_spin.Value = this.TargetMember.Height; gender_combo.Active = (this.TargetMember.Gender == 'm' ? 0 : 1); dw.Date = this.TargetMember.BirthDate; contact_name_entry.Text = this.TargetMember.InnerContact.Name; contact_phone_entry.Text = this.TargetMember.InnerContact.PhoneNumber; this.ContentVBox.ShowAll(); }