Example #1
0
        public ClientesAdd(Tables.Client client = null)
        {
            InitializeComponent();

            sqlClient = new Sql.Client();

            if (client != null)
            {
                idClient        = client.Id;
                clientName.Text = client.Name;
                Adress.Text     = client.Street;
                District.Text   = client.District;
                Number.Text     = client.Number.ToString();
                Complement.Text = client.Complement;
                Telephone.Text  = client.Telephone;
                Reference.Text  = client.Reference;
            }

            Loaded += ClientesAdd_Loaded;

            Number.PreviewTextInput += (sender, e) => e.Handled = new Regex("[^0-9]").IsMatch(e.Text);

            clientName.GotFocus += delegate { clientName.SelectAll(); };
            Adress.GotFocus     += delegate { Adress.SelectAll(); };
            District.GotFocus   += delegate { District.SelectAll(); };
            Number.GotFocus     += delegate { Number.SelectAll(); };
            Complement.GotFocus += delegate { Complement.SelectAll(); };
            Telephone.GotFocus  += delegate { Complement.SelectAll(); };
            Reference.GotFocus  += delegate { Reference.SelectAll(); };

            clientName.PreviewKeyDown += (sender, e) => { if (e.Key == Key.Enter)
                                                          {
                                                              Adress.Focus();
                                                          }
            };
            Adress.PreviewKeyDown += (sender, e) => { if (e.Key == Key.Enter)
                                                      {
                                                          Number.Focus();
                                                      }
            };
            Number.PreviewKeyDown += (sender, e) => { if (e.Key == Key.Enter)
                                                      {
                                                          District.Focus();
                                                      }
            };
            District.PreviewKeyDown += (sender, e) => { if (e.Key == Key.Enter)
                                                        {
                                                            Complement.Focus();
                                                        }
            };
            Complement.PreviewKeyDown += (sender, e) => { if (e.Key == Key.Enter)
                                                          {
                                                              Telephone.Focus();
                                                          }
            };
            Telephone.PreviewKeyDown += (sender, e) => { if (e.Key == Key.Enter)
                                                         {
                                                             Reference.Focus();
                                                         }
            };
            Reference.PreviewKeyDown += (sender, e) => { if (e.Key == Key.Enter)
                                                         {
                                                             SaveBtn_Click(null, null);
                                                         }
            };

            SaveBtn.Click  += SaveBtn_Click;
            ClearBtn.Click += ClearBtn_Click;
        }