//step 2 private void ChooseClient() { //this means that the user has completed this step once, //and that she wants to choose if create or use existing client once more if(this.TargetMember.InnerClient != null) { this.TargetMember.InnerClient = null; this.OnPrevious(); return; } bool new_client = this.NewClientButton.Active; if(new_client) { ClientWizard cw = new ClientWizard(); cw.SuccessEvent += (object target) => { this.TargetMember.InnerClient = (Client) target; this.OnNext(); }; cw.CancelEvent += () => this.Step -= 1; cw.TransientFor = this; cw.Run(); } else { this.Description = "Elija un método para seleccionar al cliente que será nuevo miembro del gimnasio"; this.ClearContentBox(); this.ClientByIdButton = new RadioButton(null, "Id de usuario:"); this.ClientSearchButton = new RadioButton(this.ClientByIdButton, "Buscar manualmente"); Button test_button= new Button("Comprobar"); SpinButton id_spin = new SpinButton(0, 5000, 1); id_spin.Value = this.ClientId; id_spin.TooltipText = "Número de cliente"; Button search_button = new Button("Clientes..."); Label empty_label = new Label(" "); Label empty_label2 = new Label(" "); Label info_label = new Label(); this.PackWidgetSingle(this.ClientByIdButton); this.PackWidgetPair(id_spin, test_button, true); this.PackWidgetSingle(this.ClientSearchButton); this.PackWidgetPair(empty_label, search_button, true); this.PackWidgetSingle(empty_label2); this.PackWidgetSingle(new HSeparator()); this.PackWidgetSingle(info_label); //connecting local buttons this.ClientByIdButton.Clicked += (object sender, EventArgs args) => { bool state = this.ClientByIdButton.Active; id_spin.Sensitive = state; test_button.Sensitive = state; search_button.Sensitive = !state; }; id_spin.Changed += (object sender, EventArgs args) => { int id; this.ClientId = (int.TryParse(id_spin.Text, out id) ? id : id_spin.ValueAsInt); //this.ClientId = id_spin.ValueAsInt; }; id_spin.Value = this.ClientId; test_button.Clicked += (object sender, EventArgs args) => { long id = this.ClientId; ClientModel m = new ClientModel(); if(m.ExistsById(id)) { IDataReader r = m.GetById(id); r.Read(); Client c = new Client(); c.Id = id; c.Name = (string) r["Name"]; c.Surname = (string) r["Surname"]; c.Address = (string) r["Address"]; c.Email = (string) r["Email"]; c.PhoneNumber = r["PhoneNumber"].ToString(); string s = c.ToString(); if(m.IsMember(c)) s += "\n(Ya es miembro)"; info_label.Text = s; } else { info_label.Text = "Número de cliente (" + id + ") no encontrado"; this.TargetMember.InnerClient = null; } }; search_button.Clicked += (object sender, EventArgs args) => { info_label.Text = "No implementado"; }; this.ClientByIdButton.Click(); this.ContentVBox.ShowAll(); id_spin.HasFocus = true; } }
private void NewClient(object sender, EventArgs args) { ClientWizard w = new ClientWizard(); w.SuccessEvent += (object c) => { Client client = (Client) c; ClientModel client_m = new ClientModel(); bool success = client_m.Insert(client); if(!success) GuiHelper.ShowError(w, "No se pudo completar la operación debido a un error interno"); }; w.Run(); }