Ejemplo n.º 1
0
        private void xfrmComManGenCodigoBarra_KeyDown(object sender, KeyEventArgs e)
        {
            try {
                if (e.KeyCode == Keys.Enter)
                {
                    //Validamos que se ha la operacion de insertar o modificar
                    if (!varOpeCodigo.Equals(1) && !varOpeCodigo.Equals(2))
                    {
                        return;
                    }
                    //Validamos que si no esta en la columna nro de impresion no pueda agregar una nueva linea
                    if (this.grvDetalle.FocusedColumn != colAtrDetNroImpresion)
                    {
                        return;
                    }
                    //Recuperamos la fila seleccionada
                    EntCOM_DETGENCODBARRA objFilaDetalle = (EntCOM_DETGENCODBARRA)this.grvDetalle.GetRow(this.grvDetalle.FocusedRowHandle);
                    int    varSecuencia    = objDetalle.Max(p => p.atrDetSecuencia);
                    int    varPosicionFila = this.grvDetalle.FocusedRowHandle;
                    object varFilaNueva    = this.grvDetalle.GetRowCellValue(this.grvDetalle.RowCount - 1, colAtrIteCodigo);

                    //Validamos que los campos ha sido debidamente ingresados
                    string varMensaje = objFilaDetalle.funValidarFila();
                    if (!varMensaje.Equals(""))
                    {
                        string varControl = varMensaje.Split(':')[0];
                        string varError   = varMensaje.Split(':')[1].Trim();
                        this.grvDetalle.SetColumnError(this.grvDetalle.Columns[varControl], varError);
                        this.grvDetalle.FocusedColumn = this.grvDetalle.Columns[varControl];
                        return;
                    }

                    if (varFilaNueva == null || varFilaNueva == DBNull.Value)
                    {
                        if (this.grvDetalle.RowCount - 1 == 0)
                        {
                            this.objDetalle.Add(new EntCOM_DETGENCODBARRA(0));
                        }
                    }
                    else if (this.grvDetalle.FocusedRowHandle == this.grvDetalle.RowCount - 1)
                    {
                        this.objDetalle.Add(new EntCOM_DETGENCODBARRA(varSecuencia));
                    }
                    if (varPosicionFila < 0)
                    {
                        this.grvDetalle.FocusedRowHandle = 0;
                        this.grvDetalle.FocusedColumn    = colAtrIteCodigo;
                    }
                    else
                    {
                        this.grvDetalle.FocusedRowHandle = varPosicionFila + 1;
                        this.grvDetalle.FocusedColumn    = colAtrIteCodigo;
                    }
                    //Refrescamos el detalle
                    this.grcDetalle.RefreshDataSource();
                }
            } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
Ejemplo n.º 2
0
 private void smiEliminar_Click(object sender, EventArgs e)
 {
     try {
         if (this.grvDetalle.IsFocusedView)
         {
             EntCOM_DETGENCODBARRA objFilaDetalle = (EntCOM_DETGENCODBARRA)this.grvDetalle.GetRow(this.grvDetalle.FocusedRowHandle);
             objDetalle.Remove(objFilaDetalle);
             this.grcDetalle.RefreshDataSource();
         }
     } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }