Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     Console.WriteLine(comboBox1.SelectedIndex);
     if (comboBox1.SelectedIndex == 0)
     {
         SearchNaturalClient snc = new SearchNaturalClient();
         this.Hide();
         snc.ShowDialog();
         this.Show();
         NaturalClient nc = snc.ClientSelected;
         if (nc != null)
         {
             textBox1.Text = nc.Dni;
             textBox3.Text = nc.Name + " " + nc.Surname;
         }
     }
     else
     {
         Console.WriteLine("Searching Legal Client");
         SearchLegalClient slc = new SearchLegalClient();
         this.Hide();
         slc.ShowDialog();
         this.Show();
         LegalClient lc = slc.SelectedClient;
         if (lc != null)
         {
             textBox1.Text = lc.RUC;
             textBox3.Text = lc.CompanyName;
         }
     }
 }
Esempio n. 2
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            string dni         = dniTextBox.Text;
            string name        = nameTextBox.Text;
            string surname     = lastnameTextBox.Text;
            string district    = districtTextBox.Text;
            string email       = emailTextBox.Text;
            string phoneNumber = phoneTextBox.Text;

            bool flagOK = true;

            if (!DataValidation.ValidField(Constants.DniRegex, dni, ref flagOK))
            {
                label4.ForeColor = Color.Red;
            }
            if (!DataValidation.ValidField(Constants.NameRegex, name, ref flagOK))
            {
                label6.ForeColor = Color.Red;
            }
            if (!DataValidation.ValidField(Constants.SurnameRegex, surname, ref flagOK))
            {
                label8.ForeColor = Color.Red;
            }
            if (!DataValidation.ValidField(Constants.PlaceRegex, district, ref flagOK))
            {
                label5.ForeColor = Color.Red;
            }
            if (!DataValidation.ValidField(Constants.PhoneRegex, phoneNumber, ref flagOK))
            {
                label7.ForeColor = Color.Red;
            }
            if (!DataValidation.ValidField(Constants.EmailRegex, email, ref flagOK))
            {
                label10.ForeColor = Color.Red;
            }

            if (flagOK)
            {
                NaturalClient nc = new NaturalClient();
                nc.Dni = dni; nc.Name = name; nc.Surname = surname; nc.Address = district; nc.Email = email; nc.PhoneNumber = phoneNumber;
                try {
                    naturalClientBL.addNaturalClient(nc);
                    MessageBox.Show("El cliente ha sido registrado", "Registro de cliente nuevo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dniTextBox.Clear();
                    nameTextBox.Clear();
                    lastnameTextBox.Clear();
                    districtTextBox.Clear();
                    emailTextBox.Clear();
                    phoneTextBox.Clear();
                }
                catch (Exception ex) {
                    MessageBox.Show("¡Existe un cliente con el mismo DNI!", "Error al añadir cliente", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Uno o más campos son incorrectos. Revise los campos en rojo.", "Error en registro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        public BindingList <NaturalClient> listNaturalClients(string dni, string name, string surname)
        {
            BindingList <NaturalClient> list = new BindingList <NaturalClient>();
            MySqlConnection             con  = new MySqlConnection(Constants.connectionString);

            con.Open();
            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection  = con;
            cmd.CommandText = "listNaturalClients";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            if (dni.Length == 0)
            {
                cmd.Parameters.Add("_dni", MySqlDbType.String).Value = DBNull.Value;
            }
            else
            {
                cmd.Parameters.Add("_dni", MySqlDbType.String).Value = dni;
            }

            if (name.Length == 0)
            {
                cmd.Parameters.Add("_name", MySqlDbType.String).Value = DBNull.Value;
            }
            else
            {
                cmd.Parameters.Add("_name", MySqlDbType.String).Value = name;
            }

            if (surname.Length == 0)
            {
                cmd.Parameters.Add("_surname", MySqlDbType.String).Value = DBNull.Value;
            }
            else
            {
                cmd.Parameters.Add("_surname", MySqlDbType.String).Value = surname;
            }

            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                NaturalClient nc = new NaturalClient();
                nc.Dni         = reader.GetString("Dni");
                nc.Name        = reader.GetString("Name");
                nc.Surname     = reader.GetString("Surname");
                nc.Address     = reader.GetString("Address");
                nc.PhoneNumber = reader.GetString("PhoneNumber");
                nc.Email       = reader.GetString("Email");
                nc.Points      = reader.GetInt32("Points");
                list.Add(nc);
            }
            con.Close();
            return(list);
        }
Esempio n. 4
0
        private void modifyClientButton_Click(object sender, EventArgs e)
        {
            NaturalClient nc = (NaturalClient)dataGridView1.CurrentRow.DataBoundItem;
            EditClient    ec = new EditClient(nc);

            this.Hide();
            ec.ShowDialog();
            dataGridView1.DataSource = naturalClientBL.listNaturalClients("", "", "");
            this.Show();
        }
Esempio n. 5
0
 public EditClient(NaturalClient nc)
 {
     InitializeComponent();
     naturalClientBL  = new NaturalClientBL();
     selectedClient   = nc;
     textBox1.Text    = Constants.CurrentUserText;
     textBox2.Text    = nc.Name;
     textBox3.Text    = nc.Surname;
     textBox4.Text    = nc.Address;
     textBox5.Text    = nc.PhoneNumber;
     textBox6.Text    = nc.Email;
     textBox2.Enabled = false;
     textBox3.Enabled = false;
     textBox4.Enabled = false;
     textBox5.Enabled = false;
     this.CenterToScreen();
 }
Esempio n. 6
0
        private void button1_Click_2(object sender, EventArgs e)
        {
            Console.WriteLine(comboBox1.SelectedIndex);
            if (comboBox1.SelectedIndex == 0)
            {
                SearchNaturalClient snc = new SearchNaturalClient();
                this.Hide();
                snc.ShowDialog();
                this.Show();
                NaturalClient nc = snc.ClientSelected;
                if (nc != null)
                {
                    textBox1.Text      = nc.Dni;
                    textBox3.Text      = nc.Name + " " + nc.Surname;
                    pointsTextBox.Text = nc.Points.ToString();

                    nc.IdPerson = naturalClientBL.searchNaturalClient(nc.Dni);

                    idClient = nc.IdPerson;
                    Console.WriteLine("ID del cliente natural: " + nc.IdPerson);
                }
            }
            else
            {
                Console.WriteLine("Searching Legal Client");
                SearchLegalClient slc = new SearchLegalClient();
                this.Hide();
                slc.ShowDialog();
                this.Show();
                LegalClient lc = slc.SelectedClient;
                if (lc != null)
                {
                    textBox1.Text      = lc.RUC;
                    textBox3.Text      = lc.CompanyName;
                    pointsTextBox.Text = lc.Points.ToString();

                    lc.IdPerson = legalClientBL.searchLegalClient(lc.RUC);
                    idClient    = lc.IdPerson;
                    Console.WriteLine("ID del cliente legal: " + lc.IdPerson);
                }
            }
        }
Esempio n. 7
0
        public void updateNaturalClient(NaturalClient nc)
        {
            MySqlConnection con = new MySqlConnection(Constants.connectionString);

            con.Open();
            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection  = con;
            cmd.CommandText = "updateInBDNaturalClient";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.Add("_address", MySqlDbType.String).Value     = nc.Address;
            cmd.Parameters.Add("_phoneNumber", MySqlDbType.String).Value = nc.PhoneNumber;
            cmd.Parameters.Add("_email", MySqlDbType.String).Value       = nc.Email;
            cmd.Parameters.Add("_name", MySqlDbType.String).Value        = nc.Name;
            cmd.Parameters.Add("_surname", MySqlDbType.String).Value     = nc.Surname;
            cmd.Parameters.Add("_dni", MySqlDbType.String).Value         = nc.Dni;

            cmd.ExecuteNonQuery();
            con.Close();
        }
Esempio n. 8
0
 public void updateNaturalClient(NaturalClient nc)
 {
     dataAccess.updateNaturalClient(nc);
 }
Esempio n. 9
0
 public void addNaturalClient(NaturalClient nc)
 {
     dataAccess.addNaturalClient(nc);
 }