public static int empresa(constructorsistema add) { int retorno = 0; /*verificar existencia * true: * enviar mensaje verificando existencia * * false: * ingreso de datos a la base * * verificar insercion: * true: * enviar mensaje notificando el envio completado * false: * no se pudo ingresar, se envia mensaje * */ try { string query = "SELECT *FROM empresa WHERE nombre= binary ?nombre AND NIT=binary ?nit"; MySqlCommand select = new MySqlCommand(query, conexion.obtenerconexion()); select.Parameters.Add(new MySqlParameter("nombre", add.nombre)); select.Parameters.Add(new MySqlParameter("nit", add.NIT)); retorno = Convert.ToInt16(select.ExecuteScalar()); if (retorno >= 1) { MessageBox.Show("Un registro con estas credenciales ya existe"); } else { MySqlCommand cmdadd = new MySqlCommand(string.Format("INSERT INTO empresa(nombre,NIT,representante,logo,codigo_postal,correo_electronico,direccion)VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", add.nombre, add.NIT, add.representante, add.foto, add.codigo_postal, add.correo, add.direccion), conexion.obtenerconexion()); retorno = Convert.ToInt16(cmdadd.ExecuteNonQuery()); if (retorno >= 1) { MessageBox.Show("Registro ingresado", "Completado", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Registro no ingresado", "No Completado", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } return(retorno); } catch (Exception e) { MessageBox.Show("Peta" + e.Message); return(retorno); } }
private void btnguadar_Click(object sender, EventArgs e) { if (txtname.Text.Trim() == "" || txtit.Text.Trim() == "" || txtreplegal.Text.Trim() == "" || txtdireccion.Text.Trim() == "" || txtcod.Text.Trim() == "" || pctlogo.Image == null) { MessageBox.Show("Existen campos vacios", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (Email_Valido(txtcorreo.Text) == false) { errorProvider1.SetError(txtcorreo, " Ingrese un Email Válido"); txtcorreo.Focus(); return; } else { constructorsistema add = new constructorsistema(); add.nombre = txtname.Text; add.representante = txtreplegal.Text; add.NIT = txtit.Text; add.direccion = txtdireccion.Text; add.correo = txtcorreo.Text; add.codigo_postal = Convert.ToInt32(txtcod.Text); MemoryStream ms = new MemoryStream(); pctlogo.Image.Save(ms, ImageFormat.Jpeg); byte[] abyte = ms.ToArray(); string encoded = Convert.ToBase64String(abyte); add.foto = encoded; errorProvider1.Clear(); validar.Visible = true; if (registroempresa.empresa(add) >= 1) { Form user = new YourOwnWorkshop(); user.Show(); this.Hide(); } } }