Beispiel #1
0
 public bool Update(Client c)
 {
     string sql = "Update " + this.TableName + " set Name = @p0, ";
     sql += "Surname = @p1, Address = @p2, PhoneNumber = @p3, Email = @p4 ";
     sql += "where " + this.IdName + " = @p5";
     return this.DoNonQuery(sql, c.Name, c.Surname, c.Address, c.PhoneNumber, c.Email, c.Id) > 0;
 }
Beispiel #2
0
 public ClientWizard()
 {
     this.WelcomeHeader = "Bienvenido al asistente para alta de clientes";
     this.NextEvent += this.OnNext;
     this.PreviousEvent += this.OnPrevious;
     this.Step = 0;
     this.InnerClient = new Client();
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
        public static Client FromId(long id)
        {
            ClientModel cm = new ClientModel();
            IDataReader r = cm.GetById(id);
            Client c = null;
            if(r.Read())
            {
                c = new Client();
                c.Name = (string) r["Name"];
                c.Surname = (string) r["Surname"];
                c.Address = (string) r["Address"];
                c.PhoneNumber = r["PhoneNumber"].ToString();
                c.Email = (string) r["Email"];
                return c;
            }

            return c;
        }
Beispiel #5
0
 public bool Update(Client c, string attr, object update)
 {
     return this.UpdateById(c.Id, attr, update);
 }
Beispiel #6
0
 public bool IsMember(Client c)
 {
     string sql = "select count(*) from Member where Id = @p0";
     return ((long) this.DoScalar(sql, c.Id)) > 0;
 }
Beispiel #7
0
 public bool Insert(Client c)
 {
     return this.Insert(null, c.Name, c.Surname, c.Address, c.PhoneNumber, c.Email);
 }
Beispiel #8
0
 public bool Exists(Client c)
 {
     string sql = "select count(*) from " + this.TableName;
     sql += " where Name = @p0 and Surname = @p1";
     return (((long) this.DoScalar(sql, c.Name, c.Surname)) > 0 ? true : false);
 }
Beispiel #9
0
        private void SelectCurrent(object sender, EventArgs args)
        {
            this.ClearForm();
            this.PhotoButton.Sensitive = true;
            this.PhotoButton.Relief = ReliefStyle.None;
            //default client info
            Client c = (Client) this.MembersNodeView.NodeSelection.SelectedNode;
            this.CurrentClient = c;
            Member m = new Member();
            m.Id = c.Id;
            m.Sync();
            c = m.InnerClient;

            //client info
            this.ActiveCheck.Active = m.Active;
            this.IdLabel.Text = c.Id.ToString("0000");
            this.NameEntry.Text = c.Name;
            this.SurnameEntry.Text = c.Surname;
            this.AddressEntry.Text = c.Address;
            this.PhoneEntry.Text = c.PhoneNumber;
            this.EmailEntry.Text = c.Email;

            //member info
            this.WeightSpin.Value = m.Weight;
            this.HeightSpin.Value = m.Height;
            this.GenderCombo.Active = m.Gender == 'm' ? 0 : 1;
            this.BirthdayWidget.Date = m.BirthDate;
            this.ContactNameEntry.Text = !string.IsNullOrEmpty(m.InnerContact.Name) ? m.InnerContact.Name : "";
            this.ContactPhoneEntry.Text = !string.IsNullOrEmpty(m.InnerContact.PhoneNumber) ? m.InnerContact.PhoneNumber : "";
            if(m.BinImage != null && m.BinImage.Length > 0)
            {
                foreach(Widget widget in this.PhotoButton.Children)
                    this.PhotoButton.Remove(widget);

                int h = this.PhotoButton.Allocation.Height;
                int w = this.PhotoButton.Allocation.Width;
                Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(m.BinImage);

                double x_scale = (double) w / pixbuf.Width;
                double y_scale = (double) h / pixbuf.Height;
                double scale = Math.Min(x_scale, y_scale);
                pixbuf = pixbuf.ScaleSimple((int) (pixbuf.Width * scale), (int) (pixbuf.Height * scale), Gdk.InterpType.Bilinear);
                this.PhotoButton.Add(new Gtk.Image(pixbuf));
                this.PhotoButton.ShowAll();
            }

            //payment info
            this.PaymentDaySpin.Value = m.PaymentDay;
            this.SinceWidget.Date = m.JoinDate;
            PackModel pm = new PackModel();
            IDataReader reader = pm.GetById(m.Pack);
            if(reader.Read())
            {
                string name = (string) reader["Name"];
                long packs = pm.Count();
                for(int i = 0; i < packs; i++)
                {
                    this.PackCombo.Active = i;
                    string text = this.PackCombo.ActiveText;
                    if(name == text)
                        break;
                }
            }

            //conf
            this.EditButton.Sensitive = true;
        }
Beispiel #10
0
        private void SelectClient(Client c)
        {
            NodeStore store = this.MembersNodeView.NodeStore;
            TreeNode node = null;
            bool found = false;

            for(int i = 0; ; i++)
            {
                TreePath path = new TreePath(i.ToString());
                node = (TreeNode) store.GetNode(path);
                Client temp = (Client) node;

                if(temp == null)
                    break;

                else if(temp.Id == c.Id)
                {
                    found = true;
                    break;
                }
            }

            if(found)
            {
                this.MembersNodeView.NodeSelection.SelectNode(node);
                this.MembersNodeView.HasFocus = true;
            }
        }
Beispiel #11
0
        private void FillNodeView(IDataReader reader)
        {
            NodeStore store = new NodeStore(typeof(Client));
            Client c = null;

            while(reader.Read())
            {
                c = new Client();
                c.Id = (long) reader["Id"];
                c.Name = (string) reader["Name"];
                c.Surname = (string) reader["Surname"];
                c.Address = (string) reader["Address"];
                c.PhoneNumber = (string) reader["PhoneNumber"];
                c.Email = (string) reader["Email"];

                store.AddNode(c);
            }

            this.MembersNodeView.NodeStore = store;
            this.MembersNodeView.ShowAll();
        }
Beispiel #12
0
 private void SelectCurrent(object sender, EventArgs args)
 {
     this.CurrentClient = (Client) this.ClientsNodeView.NodeSelection.SelectedNode;
     Client c = this.CurrentClient;
     this.IdLabel.Text = c.Id.ToString("0000");
     this.NameEntry.Text = c.Name;
     this.SurnameEntry.Text = c.Surname;
     this.AddressEntry.Text = c.Address;
     this.PhoneEntry.Text = c.PhoneNumber;
     this.EmailEntry.Text = c.Email;
     this.EditButton.Sensitive = true;
 }
Beispiel #13
0
        //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;
            }
        }
Beispiel #14
0
        private void Summary()
        {
            this.ClearContentBox();
            this.Description = "Se dará de alta al siguiente nuevo miembro del gimnasio";
            this.NextLabel = "Aceptar";

            Gtk.Image img = null;
            if(this.TargetMember.BinImage != null)
            {
                Pixbuf pixbuf;
                pixbuf = new Pixbuf(this.TargetMember.BinImage);
                double s = 0.4;
                pixbuf = pixbuf.ScaleSimple((int) (pixbuf.Width * s), (int) (pixbuf.Height * s), InterpType.Bilinear);
                img = new Gtk.Image(pixbuf);
            }

            ClientModel cm = new ClientModel();
            Client client = null;
            bool new_client = (this.TargetMember.InnerClient == null ? false : true);
            if(!new_client)
            {
                IDataReader r = cm.GetById(this.ClientId);
                r.Read();
                client = new Client();
                client.Id = this.ClientId;
                client.Name = (string) r["Name"];
                client.Surname = (string) r["Surname"];
                client.Address = (string) r["Address"];
                client.PhoneNumber = ((decimal) r["PhoneNumber"]).ToString();
                client.Email = (string) r["Email"];
                this.TargetMember.InnerClient = client;
            }

            else
            {
                client = this.TargetMember.InnerClient;
                client.Id = -1;
            }

            PackModel pm = new PackModel();
            IDataReader pr = pm.GetById(this.TargetMember.Pack);
            pr.Read();
            string p_name = (string) pr["Name"];
            double p_price = (float) pr["Price"];
            string str_pay = string.Empty;
            str_pay += "Fecha de ingreso: " + this.TargetMember.JoinDate.ToString("dd/MM/yyyy");
            str_pay += "\nDía de pago: " + this.TargetMember.PaymentDay + " de cada mes";
            str_pay += "\nInscrito a : " + p_name + " (" + string.Format("{0:C}", p_price) + " mensuales)";

            string ct_str = string.Empty;
            if(this.TargetMember.InnerContact != null)
            {
                ct_str += "Contacto en caso de lesión\n";
                ct_str += "Nombre: " + this.TargetMember.InnerContact.Name + "\n";
                ct_str += "Teléfono: " + this.TargetMember.InnerContact.PhoneNumber;
            }

            if(img != null)
                this.PackWidgetSingle(img);
            this.PackWidgetSingle(new Label(client.ToString()));
            this.PackWidgetSingle(new Label(this.TargetMember.ToString()));
            this.PackWidgetSingle(new Label(str_pay));
            this.PackWidgetSingle(new Label(ct_str));

            this.ContentVBox.ShowAll();
        }
Beispiel #15
0
        //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();
        }