public int creaItem() { int x; string scad = "INSERT INTO imagenes.personas ( nombres, apellidos, cedula, cargo, ubica, idubica ) " + " VALUES ( '" + nombres + "', '" + apellidos + "', '" + cedula + "', '" + cargo + "', '" + ubica + "', '" + idubica + "' )"; Clases.cDatos oDat = new Clases.cDatos(); x = oDat.ejecutarComando(scad); return x; }
// Falta refrescar el ListView con los cambios en los datos, para tipocomponente private void cmdAceptar_Click(object sender, EventArgs e) { int retorno; string scad = "" ; Clases.cDatos oDat = new Clases.cDatos(); // valida datos if (oComp.componente == "") { MessageBox.Show("FALTA ESPECIFICAR COMPONENTE .."); txtComponente.Focus(); return; } if (oComp.tipocomponente == "") { MessageBox.Show("FALTA ESPECIFICAR EL TIPO DEL COMPONENTE .."); txtTipoComponente.Focus(); return; } if (oComp.marca == "") { MessageBox.Show("FALTA ESPECIFICAR MARCA DEL COMPONENTE .."); txtMarca.Focus(); return; } if (txtSerie.Text != "") oComp.serie = txtSerie.Text.ToUpper(); else oComp.serie = ""; oComp.seriecse = txtSerieCSE.Text.ToUpper(); oComp.valormedida = int.Parse(txtValor.Text); if (modo == "A") { // crea el idparte secuencial consecutivo scad = "SELECT MAX(idparte) AS id FROM imagenes.componentes "; oComp.idparte = oDat.nuevoId(scad) + 1; // Llena el listView lvItem = new ListViewItem(oComp.componente); // ToString().TrimEnd()); lvItem.SubItems.Add(oComp.tipocomponente); lvItem.SubItems.Add(oComp.marca); lvItem.SubItems.Add(oComp.serie); lvItem.SubItems.Add(oComp.seriecse); lvItem.SubItems.Add(oComp.magnitud ); lvItem.SubItems.Add(oComp.valormedida.ToString() ); lvItem.SubItems.Add(oComp.medida); lvItem.Tag = oComp.idparte.ToString(); // lvItem.ImageKey = "si"; lsComponentes.Items.Add(lvItem); // Graba el componente scad = "INSERT INTO imagenes.componentes ( idcomponente, componente, marca, serie, idequipo, idparte, " + " tipocomponente, idmarca, seriecse, idtipocomponente, magnitud,valormedida, medida, idmagnitud, idmedida ) " + " VALUES ( '" + oComp.idcomponente + "', '" + oComp.componente + "', '" + oComp.marca + "', '" + oComp.serie + "', '" + oComp.idequipo + "', '" + oComp.idparte + "', '" + oComp.tipocomponente + "', '" + oComp.idmarca + "', '" + oComp.seriecse + "', '" + oComp.idtipocomponente + "', '" + oComp.magnitud + "', '" + oComp.valormedida + "', '" + oComp.medida + "', '" + oComp.idmagnitud + "', '" + oComp.idmedida + "' );"; retorno = oDat.ejecutarComando(scad); oDat = null; actualizadtComponentes(); // if (MessageBox.Show("Desea Grabar otro Componente del equipo ? ", "COMPONENTES DEL EQUIPO ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) ; initComponente(); } else if (modo == "M") // Modificar { //oComp.serie = txtSerie.Text; //oComp.seriecse = txtSerieCSE.Text; int valor = int.Parse( txtValor.Text ); scad = "UPDATE imagenes.componentes SET marca = '" + oComp.marca + "', idmarca = '" + oComp.idmarca + "', serie = '" + oComp.serie + "', seriecse = '" + oComp.seriecse + "', tipocomponente = '" + oComp.tipocomponente + "', idtipocomponente = '" + oComp.idtipocomponente + "', magnitud = '" + oComp.magnitud + "', valormedida = '" + oComp.valormedida + "', " + " medida = '" + oComp.medida + "', idmagnitud = '" + oComp.idmagnitud + "', idmedida = '" + oComp.idmedida + "' "+ " WHERE idparte = '" + nTag + "' ;"; int x = oDat.ejecutarComando(scad); if (x == 1) // grabar componente ok { // Actualiza el ListView for (int i = 0; i < lsComponentes.Items.Count; i++) { lvItem = lsComponentes.Items[i]; if (int.Parse(lvItem.Tag.ToString()) == nTag) { // Sustituir los items lvItem.SubItems[0].Text = oComp.componente; lvItem.SubItems[1].Text = oComp.tipocomponente; lvItem.SubItems[2].Text = oComp.marca; lvItem.SubItems[3].Text = oComp.serie; lvItem.SubItems[4].Text = oComp.seriecse; lvItem.SubItems[5].Text = oComp.magnitud; lvItem.SubItems[6].Text = oComp.valormedida.ToString(); lvItem.SubItems[7].Text = oComp.medida; } } actualizadtComponentes(); } initComponente(); } oDat = null; }
private void cmdEliminar_Click(object sender, EventArgs e) { int x; if (indice > -1) { // Borra el componente registrado en la BD y lo quita del listview String scad = "DELETE FROM imagenes.componentes WHERE idparte = '" + nTag + "' "; Clases.cDatos oDat = new Clases.cDatos(); x = oDat.ejecutarComando(scad); lsComponentes.Items.RemoveAt(indice); // Eliminar del dtComponentes for (int i = 0; i < dtComponentes.Rows.Count; i++) { if (int.Parse(dtComponentes.Rows[i]["idparte"].ToString()) == nTag) { dtComponentes.Rows.RemoveAt(i); break; } } dtComponentes.AcceptChanges(); } }
private void elimina(String campo) { // elimina elementos de catalogos simples string scad = ""; string sCampo; int i; int resultado; if (MessageBox.Show("SEGURO DE ELIMINAR ESTE ITEM ? ", "ELIMINAR ITEM DE CATALOGO", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.No) return; if (dtCatalogo.Rows.Count > 0) { i = gridView1.FocusedRowHandle; fila = gridView1.GetDataRow(i); if (campo == "cedula") { sCampo = fila[campo].ToString(); scad = "DELETE FROM " + catal + " WHERE " + campo + " = '" + sCampo + "' "; } else { idItem = int.Parse(fila[campo].ToString()); scad = "DELETE FROM " + catal + " WHERE " + campo + " = '" + idItem + "' "; } Clases.cDatos oDat = new Clases.cDatos(); resultado = oDat.ejecutarComando(scad); if (resultado == 1) // ok { dtCatalogo.Rows.RemoveAt(i); dtCatalogo.AcceptChanges(); gridView1.RefreshData(); } oDat = null; } }
private void creaNuevoItem() { Clases.cDatos oDat = new Clases.cDatos(); int x; string sCad= ""; // Graba id y descripcion en el parametro con el nombre de la tabla. if(numCat == 1) sCad = "INSERT INTO " + oCat.lista[0] + " ( " + oCat.lista[2] + ", " + oCat.lista[3] + ") " + " values( '" + idItem + "', '" + Item + "' )"; else if(numCat == 2) // graba id, item e idforaneo sCad = "INSERT INTO " + oCat.lista[0] + " ( " + oCat.lista[2] + ", " + oCat.lista[3] + ", " + oCat.lista[4] + ") " + " values( '" + idItem + "', '" + Item + "', '" + oCat.idForaneo + "' )"; else if (numCat == 3) // graba id, item y campo Boolean (bpartes/brepite) sCad = "INSERT INTO " + oCat.lista[0] + " ( " + oCat.lista[2] + ", " + oCat.lista[3] + ", " + oCat.lista[4] + ") " + " values( '" + idItem + "', '" + Item + "', '" + oCat.bcampo + "' )"; x = oDat.ejecutarComando(sCad); if(x != 0) this.DialogResult = DialogResult.Yes; else this.DialogResult = DialogResult.No; }