public static Phones getPhoneInfo(int codigoContacto, string telefono, string tipo) { Phones pInfoPhone = new Phones(); using (SqlConnection con = Connection.getConnection()) { if (tipo == "casa") { SqlCommand comand = new SqlCommand(); comand.Connection = con; comand.CommandType = System.Data.CommandType.StoredProcedure; comand.CommandText = "getPhoneHouse"; comand.Parameters.Add(new SqlParameter("@codigoContacto", System.Data.SqlDbType.Int)); comand.Parameters["@codigoContacto"].Value = codigoContacto; comand.Parameters.Add(new SqlParameter("@telefono", System.Data.SqlDbType.VarChar)); comand.Parameters["@telefono"].Value = telefono; SqlDataReader re = comand.ExecuteReader(); if (re.Read()) { pInfoPhone.codigo = Convert.ToInt32(re["c"]); pInfoPhone.Telefono = re["t"].ToString(); pInfoPhone.Tipo = "casa"; } else { pInfoPhone = null; } } else if (tipo == "celular") { SqlCommand comand = new SqlCommand(); comand.Connection = con; comand.CommandType = System.Data.CommandType.StoredProcedure; comand.CommandText = "getPhoneCellphone"; comand.Parameters.Add(new SqlParameter("@codigoContacto", System.Data.SqlDbType.Int)); comand.Parameters["@codigoContacto"].Value = codigoContacto; comand.Parameters.Add(new SqlParameter("@telefono", System.Data.SqlDbType.VarChar)); comand.Parameters["@telefono"].Value = telefono; SqlDataReader re = comand.ExecuteReader(); if (re.Read()) { pInfoPhone.codigo = Convert.ToInt32(re["c"]); pInfoPhone.Telefono = re["t"].ToString(); pInfoPhone.Tipo = "celular"; } else { pInfoPhone = null; } } else if (tipo == "trabajo") { SqlCommand comand = new SqlCommand(); comand.Connection = con; comand.CommandType = System.Data.CommandType.StoredProcedure; comand.CommandText = "getPhoneWork"; comand.Parameters.Add(new SqlParameter("@codigoContacto", System.Data.SqlDbType.Int)); comand.Parameters["@codigoContacto"].Value = codigoContacto; comand.Parameters.Add(new SqlParameter("@telefono", System.Data.SqlDbType.VarChar)); comand.Parameters["@telefono"].Value = telefono; SqlDataReader re = comand.ExecuteReader(); if (re.Read()) { pInfoPhone.codigo = Convert.ToInt32(re["c"]); pInfoPhone.Telefono = re["t"].ToString(); pInfoPhone.Tipo = "trabajo"; } else { pInfoPhone = null; } } con.Close(); } return(pInfoPhone); }
// boton registrar private void btnRegistrar_Click(object sender, EventArgs e) { // validar si los campos importantes ya fueron completados if (txtNombre.Text == string.Empty) { MessageBox.Show("El Nombre esta vacio", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtNombre.Focus(); } else if (txtApellido.Text == string.Empty) { MessageBox.Show("El Apellido esta vacio", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtApellido.Focus(); } else if (txtCorreo.Text == string.Empty) { MessageBox.Show("El Correo esta vacio", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtCorreo.Focus(); } else if (FilePathFotoDestiny == null) { MessageBox.Show("No se ha seleccionado una imagen", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning); btnAnadirImagen.Focus(); } else if (txtTrabajo.Text == txtCelular.Text || txtCelular.Text == txtCasa.Text || txtTrabajo.Text == txtCasa.Text) { MessageBox.Show("Los numeros de telefono a registrar son iguales", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning); } // si todos los campos fueron completados else { try { // validar si el contacto existe if (Contact.Validate(txtNombre.Text, txtApellido.Text)) { MessageBox.Show("Ya hay un Contacto Registrado con ese nombre y apellido", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Warning); } // si el contacto no existe else { Contact pInfoContact = new Contact(); pInfoContact.name = txtNombre.Text; pInfoContact.lastName = txtApellido.Text; pInfoContact.Email = txtCorreo.Text; pInfoContact.idImage = 0; MessageBox.Show(Contact.registerContact(pInfoContact), "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); pContact = Contact.getInfoContact(txtNombre.Text, txtApellido.Text); if (txtCasa.MaskCompleted) { if (Phones.validatePhoneDiff(0, txtCasa.Text)) { if (MessageBox.Show(Phones.getContactNameDiff(pContact.id, txtCasa.Text) + "\n ¿DESEA REGISTRAR EL NUMERO DE LA CASA?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Phones.addNewPhone(pContact.id, txtCasa.Text, "casa"); } } else { Phones.addNewPhone(pContact.id, txtCasa.Text, "casa"); } } if (txtCelular.MaskCompleted) { if (Phones.validatePhoneSame(pContact.id, txtCelular.Text)) { MessageBox.Show(Phones.getContactNameSame(pContact.id, txtCelular.Text), "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Question); } else { if (Phones.validatePhoneDiff(pContact.id, txtCelular.Text)) { if (MessageBox.Show(Phones.getContactNameDiff(pContact.id, txtCelular.Text) + "\n ¿DESEA REGISTRAR EL NUMERO DEL CELULAR?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Phones.addNewPhone(pContact.id, txtCelular.Text, "celular"); } } else { Phones.addNewPhone(pContact.id, txtCelular.Text, "celular"); } } } if (txtTrabajo.MaskCompleted) { if (Phones.validatePhoneSame(pContact.id, txtTrabajo.Text)) { MessageBox.Show(Phones.getContactNameSame(pContact.id, txtTrabajo.Text), "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Question); } else { if (Phones.validatePhoneDiff(pContact.id, txtTrabajo.Text)) { if (MessageBox.Show(Phones.getContactNameDiff(pContact.id, txtTrabajo.Text) + "\n ¿DESEA REGISTRAR EL NUMERO DEL TRABAJO?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Phones.addNewPhone(pContact.id, txtTrabajo.Text, "trabajo"); } } else { Phones.addNewPhone(pContact.id, txtTrabajo.Text, "trabajo"); } } } if (FilePathFotoDestiny != null) { File.Copy(FilePathFotoSource, FilePathFotoDestiny, true); Pictures.registerImage(FilePathFotoDestiny, pContact.id); } // pregunto al usuario si va a seguir en el mismo contacto if (MessageBox.Show("Desea seguir con el mismo contacto?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { // hago visible los comboxes para guardar los numeros del contacto. setVisibleTrueComboBoxes(); // hago visibles los pbes para poder anadir o modificar los numeros setVisibleTruePBforNumbers(); // se cargan los numeros ya registrados loadNumbers(); // se cargad las fotos loadImages(); } else { cleanEverything(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }