private void creaNuevoId() { string sCad = "SELECT MAX(idtipocomponente) AS id FROM imagenes.cattipocomponentes "; Clases.cDatos oDat = new Clases.cDatos(); oComp.idtipocomponente = oDat.nuevoId(sCad) + 1; oDat = null; }
private void cmdAceptar_Click(object sender, EventArgs e) { if (txtItem.Text == "") { MessageBox.Show("FALTA el nombre del Item", "Inconsistencia en los Datos a Grabar "); this.txtItem.Focus(); return; } if (modo == "A") { // determina el nuevo id string sCad = " SELECT MAX( " + oCat.lista[2] + ") AS id FROM " + oCat.lista[0] + " "; Clases.cDatos oDat = new Clases.cDatos(); idItem = oDat.nuevoId(sCad) + 1; oDat = null; this.label2.Text = oCat.lista[2] ; Item = txtItem.Text.ToUpper(); oCat.id = idItem; oCat.nombreItem = Item; oCat.bcampo = chk1.Checked ? true : false; // Crea el nuevo Item en el Catalogo respectivo creaNuevoItem( ); } else if (modo == "M") { Item = txtItem.Text.ToUpper(); if (ItemAnterior != Item) modificaItem(); } }
// 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; }