private void gluPlanCuenta_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { try { if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Search) { //Instanciamos al formulario listado de plan de cuentas using (xfrmFinLisPlaCuenta frmFormulario = new xfrmFinLisPlaCuenta(true)) { frmFormulario.ShowDialog(); if (!frmFormulario.DrVarFila.Count.Equals(0) && frmFormulario.DrVarFila != null) { //Asignamos los valores obtenidos del listado int varPosicion = this.grvDetPlanCuenta.RowCount - 1; String varCccNombre = this.grvDetPlanCuenta.GetRowCellValue(varPosicion, "CccNombre").ToString(); clsCosDetPlanCuenta objFila = (clsCosDetPlanCuenta)this.grvDetPlanCuenta.GetRow(varPosicion); int varCdpLinea = 0; if (varCccNombre.Equals("")) { varCdpLinea = int.Parse(this.grvDetPlanCuenta.GetRowCellValue(varPosicion, "CdpLinea").ToString()); this.dtDetPlanCuenta.Remove(objFila); this.dtDetCenCosto.RemoveAll(p => p.CdpLinea == varCdpLinea); } varCdpLinea = (this.dtDetPlanCuenta.Count.Equals(0) ? 0 : this.dtDetPlanCuenta.Max <clsCosDetPlanCuenta>(p => p.CdpLinea)) + 1; foreach (clsFinPlaCuenta varFila in frmFormulario.DrVarFila) { if (dtDetPlanCuenta.Where <clsCosDetPlanCuenta>(p => p.CccCodigo == varFila.CueCodigo).Count().Equals(0)) { dtDetPlanCuenta.Add(new clsCosDetPlanCuenta(varCdpLinea, varFila.CueCodigo, 0, varFila.CueNombre, varFila.CueFormato)); dtDetCenCosto.Add(new clsCosDetCenCosto(varCdpLinea, 1, "", "", 0, false)); varCdpLinea++; } } grvDetPlanCuenta.RefreshData(); this.grvDetPlanCuenta.FocusedRowHandle = this.grvDetPlanCuenta.RowCount - 1; this.grvDetPlanCuenta.FocusedColumn = colCccNombre; this.grvDetPlanCuenta.FocusedColumn = colCccFormato; } } } } catch (Exception ex) { clsMensajesSistema.metMsgError(ex.Message); } }
private void smiEliminar_Click(object sender, EventArgs e) { try { if (this.grvDetPlanCuenta.IsFocusedView) { int varPosicionSiguiente = this.grvDetPlanCuenta.FocusedRowHandle + 1; int varCdpLinea = this.grvDetPlanCuenta.GetRowCellValue(varPosicionSiguiente, "CdpLinea") == null ? 1 : int.Parse(this.grvDetPlanCuenta.GetRowCellValue(varPosicionSiguiente, "CdpLinea").ToString()); clsCosDetPlanCuenta objFila = (clsCosDetPlanCuenta)this.grvDetPlanCuenta.GetRow(this.grvDetPlanCuenta.FocusedRowHandle); dtDetPlanCuenta.Remove(objFila); dtDetCenCosto.RemoveAll(p => p.CdpLinea == objFila.CdpLinea); if (dtDetPlanCuenta.Count == 0) { dtDetPlanCuenta.Add(new clsCosDetPlanCuenta(1, "", 0, "", "")); dtDetCenCosto.Add(new clsCosDetCenCosto(1, 1, "", "", 0, false)); } if (dtDetCenCosto != null) { this.grcDetCenCosto.DataSource = dtDetCenCosto.Where <clsCosDetCenCosto>(p => p.CdpLinea.Equals(varCdpLinea)); } this.grvDetPlanCuenta.RefreshData(); this.grvDetCenCosto.RefreshData(); } else if (this.grvDetCenCosto.IsFocusedView) { clsCosDetCenCosto objFila = (clsCosDetCenCosto)this.grvDetCenCosto.GetRow(this.grvDetCenCosto.FocusedRowHandle); dtDetCenCosto.Remove(objFila); if (dtDetCenCosto.Count <clsCosDetCenCosto>(p => p.CdpLinea == objFila.CdpLinea) == 0) { dtDetCenCosto.Add(new clsCosDetCenCosto(objFila.CdpLinea, 1, "", "", 0, false)); } if (dtDetCenCosto != null) { this.grcDetCenCosto.DataSource = dtDetCenCosto.Where <clsCosDetCenCosto>(p => p.CdpLinea.Equals(objFila.CdpLinea)); } this.grvDetCenCosto.RefreshData(); decimal varSuma = dtDetCenCosto.Where <clsCosDetCenCosto>(p => p.CdpLinea == objFila.CdpLinea).Sum <clsCosDetCenCosto>(p => p.CdePorcentaje); this.grvDetPlanCuenta.SetRowCellValue(this.grvDetPlanCuenta.FocusedRowHandle, colCdpPorcentaje, decimal.Parse(String.Format("{0:0.00}", varSuma))); } } catch (Exception ex) { clsMensajesSistema.metMsgError(ex.Message); } }