protected void gridMovCajaChica_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { dsMovCajaChica.dtMovCajaChicaDataTable dt = new dsMovCajaChica.dtMovCajaChicaDataTable(); dsMovCajaChica.dtMovCajaChicaRow row = dt.NewdtMovCajaChicaRow(); row.movimientoID = int.Parse(this.gridMovCajaChica.DataKeys[e.RowIndex]["movimientoID"].ToString()); TextBox txt = (TextBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[7].Controls[0]); TextBox txt2 = (TextBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[8].Controls[0]); row.cargo = txt.Text.Length > 0 ? double.Parse(txt.Text) : 0; row.abono = txt2.Text.Length > 0 ? double.Parse(txt2.Text) : 0; row.catalogoMovBancoInternoID = int.Parse(((DropDownList)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[5].FindControl("drpdlCatalogo"))).SelectedValue); row.subCatalogoMovBancoInternoID = int.Parse(((DropDownList)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[6].FindControl("drpSubCatalogo"))).SelectedValue); row.cobrado = (((CheckBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[13].Controls[1])).Checked); row.facturaOlarguillo = (((TextBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[11].Controls[0])).Text); row.fecha = DateTime.Parse(Utils.converttoLongDBFormat((((TextBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[3].FindControl("txtFecha"))).Text))); row.nombre = (((TextBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[4].Controls[0])).Text); row.numCabezas = ((TextBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[12].Controls[0])).Text.Length > 0 ? double.Parse(((TextBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[12].Controls[0])).Text) : 0; row.Observaciones = ((TextBox)(this.gridMovCajaChica.Rows[e.RowIndex].Cells[10].Controls[0])).Text; row.updateTS = Utils.Now; row.userID = int.Parse(this.Session["userID"].ToString()); string sError = ""; if (dbFunctions.updateMovementdeCajaChica(ref row, row.movimientoID, ref sError, row.userID)) { SqlConnection conn = new SqlConnection(myConfig.ConnectionInfo); SqlCommand comm = new SqlCommand(); try { conn.Open(); comm.Connection = conn; comm.CommandText = "SELECT MovimientosCuentasBanco.cuentaID, MovimientoOrigen.movbanID FROM MovimientosCaja INNER JOIN MovimientoOrigen ON MovimientosCaja.movOrigenID = MovimientoOrigen.movOrigenID INNER JOIN MovimientosCuentasBanco ON MovimientoOrigen.movbanID = MovimientosCuentasBanco.movbanID where (MovimientoOrigen.movimientoID = @movID)"; comm.Parameters.Clear(); comm.Parameters.Add("@movID", SqlDbType.Int).Value = row.movimientoID; dsMovBanco.dtMovBancoDataTable table = new dsMovBanco.dtMovBancoDataTable(); dsMovBanco.dtMovBancoRow rowban = table.NewdtMovBancoRow(); SqlDataReader reader = comm.ExecuteReader(); if (reader.HasRows && reader.Read()) //EL ORIGEN FUE UN MOV BANCO { rowban.nombre = row.nombre; rowban.fecha = row.fecha; if (row.cargo > 0) { rowban.abono = row.cargo; rowban.cargo = row.abono; } else { rowban.cargo = row.abono; rowban.abono = row.cargo; } // = "TRASPASO DE UNA CUENTA DE BANCO"; rowban.catalogoMovBancoInternoID = row.catalogoMovBancoInternoID; rowban.subCatalogoMovBancoInternoID = row.IssubCatalogoMovBancoInternoIDNull() ? -1 : row.subCatalogoMovBancoInternoID; rowban.numCabezas = 0; rowban.facturaOlarguillo = ""; //rowCajaChica.bodegaID = int.Parse(this.ddlCajaDestino.SelectedValue); //Logger.Instance.LogMessage(Logger.typeLogMessage.INFO, Logger.typeUserActions.UPDATE, this.UserID, "Se encontró un movimiento destino para actualizar", this.Request.Url.ToString()); int iMovToUpt = int.Parse(reader["movbanID"].ToString()); rowban.movBanID = iMovToUpt; rowban.cuentaID = int.Parse(reader["cuentaID"].ToString()); if (!dbFunctions.updateMovementdeBanco(ref rowban, rowban.movBanID, ref sError, row.userID, rowban.cuentaID)) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.UPDATE, this.UserID, "No se pudo actualizar cuentaID: " + rowban.cuentaID + " movID: " + rowban.movBanID, this.Request.Url.ToString()); } } else { //CHECK IF THERE IS AT LEAST A MOV CAJA CHICA. conn.Close(); conn.Open(); comm.Connection = conn; comm.CommandText = "SELECT MovimientoOrigen.movimientoID FROM MovimientosCaja INNER JOIN MovimientoOrigen ON MovimientosCaja.movOrigenID = MovimientoOrigen.movOrigenID where (MovimientoOrigen.movimientoID = @movID)"; comm.Parameters.Clear(); comm.Parameters.Add("@movID", SqlDbType.Int).Value = row.movimientoID; SqlDataReader readermov = comm.ExecuteReader(); if (readermov.HasRows && readermov.Read()) { //Logger.Instance.LogMessage(Logger.typeLogMessage.INFO, Logger.typeUserActions.UPDATE, this.UserID, "Se encontró un movimiento caja chica destino para actualizar", this.Request.Url.ToString()); int iMovToUpt = int.Parse(readermov["movimientoID"].ToString()); row.movimientoID = iMovToUpt; //rowCajaChica = int.Parse(reader["cuentaID"].ToString()); if (!dbFunctions.updateMovementdeCajaChica(ref row, row.movimientoID, ref sError, this.UserID)) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.UPDATE, this.UserID, "No se pudo actualizar el mov caja chica: " + row.movimientoID.ToString(), this.Request.Url.ToString()); } } } } catch (System.Exception ex) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.UPDATE, this.UserID, "Error obteniendo mov origen ex: " + ex.Message, this.Request.Url.ToString()); } finally { conn.Close(); } } this.gridMovCajaChica.EditIndex = -1; this.reloadGridView(); } catch (Exception ex) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.UPDATE, int.Parse(this.Session["userID"].ToString()), "EL ERROR SE DIO CUANDO SE TRATABA DE MODIFICAR EL MOV DE BANCAJA CHICA. LA EXC FUE: " + ex.Message, this.Request.Url.ToString()); } }
protected void cmdAceptar_Click(object sender, EventArgs e) { try { dsMovCajaChica.dtMovCajaChicaDataTable tablaaux = new dsMovCajaChica.dtMovCajaChicaDataTable(); dsMovCajaChica.dtMovCajaChicaRow dtRowainsertar = tablaaux.NewdtMovCajaChicaRow(); dtRowainsertar.nombre = this.txtNombre.Text; dtRowainsertar.fecha = DateTime.Parse(Utils.converttoLongDBFormat(this.txtFecha.Text)); dtRowainsertar.cargo = this.cmbTipodeMov.SelectedIndex == 0 ? double.Parse(this.txtMonto.Text) : 0f; dtRowainsertar.abono = this.cmbTipodeMov.SelectedIndex == 1 ? double.Parse(this.txtMonto.Text) : 0f; dtRowainsertar.storeTS = DateTime.Parse(Utils.getNowFormattedDate()); dtRowainsertar.updateTS = DateTime.Parse(Utils.getNowFormattedDate()); dtRowainsertar.Observaciones = this.txtObser.Text; dtRowainsertar.catalogoMovBancoInternoID = int.Parse(this.drpdlCatalogoInterno.SelectedValue); if (this.drpdlSubcatologointerna.SelectedIndex > 0) { dtRowainsertar.subCatalogoMovBancoInternoID = int.Parse(this.drpdlSubcatologointerna.SelectedValue); } dtRowainsertar.numCabezas = this.txtNumCabezas.Text.Length > 0 ? double.Parse(this.txtNumCabezas.Text) : 0f; dtRowainsertar.facturaOlarguillo = this.txtNumFacturaoLarguillo.Text; dtRowainsertar.bodegaID = int.Parse(this.ddlBodegas.SelectedValue); dtRowainsertar.Bodega = this.ddlBodegas.SelectedItem.Text; String serror = ""; if (dbFunctions.insertMovCajaChica(ref dtRowainsertar, ref serror, this.UserID, int.Parse(this.ddlIdCiclo.SelectedValue), this.chkboxAnticipo.Checked, int.Parse(this.drpdlProductor.SelectedValue), ref listBoxAgregadas, int.Parse(this.drpdlTipoAnticipo.SelectedValue), this.txtInteresAnual.Text.Length > 0 ? float.Parse(this.txtInteresAnual.Text) : 0f, this.txtInteresmoratorio.Text.Length > 0 ? float.Parse(this.txtInteresmoratorio.Text) : 0f, DateTime.Parse(Utils.converttoLongDBFormat(this.txtFechaLimite.Text)), this.drpdlProductor.SelectedIndex > 0 ? this.drpdlProductor.SelectedItem.Text : "")) { String sNewMov = dtRowainsertar.movimientoID.ToString(); if (this.lblNotadeVentaID.Text != "") { SqlConnection conInsertNota = new SqlConnection(myConfig.ConnectionInfo); string sqlInsert = "insert into Pagos_NotaVenta (fecha, notadeventaID, movimientoID) VALUES(@fecha, @notadeventaID, @movimientoID)"; SqlCommand cmdInsert = new SqlCommand(sqlInsert, conInsertNota); conInsertNota.Open(); try { cmdInsert.Parameters.Clear(); cmdInsert.Parameters.Add("@fecha", SqlDbType.DateTime).Value = dtRowainsertar.fecha; cmdInsert.Parameters.Add("@notadeventaID", SqlDbType.Int).Value = int.Parse(this.lblNotadeVentaID.Text); cmdInsert.Parameters.Add("@movimientoID", SqlDbType.Int).Value = dtRowainsertar.movimientoID; int numregistros = cmdInsert.ExecuteNonQuery(); if (numregistros != 1) { throw new Exception("ERROR AL INSERTAR RELACION NV - PAGOS. LA DB REGRESÓ QUE SE ALTERARON " + numregistros.ToString() + "REGISTROS"); } Logger.Instance.LogUserSessionRecord(Logger.typeModulo.NOTAVENTA, Logger.typeUserActions.UPDATE, this.UserID, "SE INSERTÓ UN PAGO A LA NOTA DE VENTA " + this.lblNotadeVentaID.Text + " EL MOV FUE: " + dtRowainsertar.movimientoID.ToString()); } catch (Exception ex) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.UPDATE, this.UserID, "ERROR AL INSERTAR UN PAGO A LA NOTA: " + this.lblNotadeVentaID.Text + ". EX " + ex.Message, this.Request.Url.ToString()); } } if (this.lblNotadeCompraID.Text != "") { SqlConnection conInsertNota = new SqlConnection(myConfig.ConnectionInfo); string sqlInsert = "insert into Pagos_NotaCompra (fecha, notadecompraID, movimientoID) VALUES(@fecha, @notadecompraID, @movimientoID)"; SqlCommand cmdInsert = new SqlCommand(sqlInsert, conInsertNota); conInsertNota.Open(); try { cmdInsert.Parameters.Clear(); cmdInsert.Parameters.Add("@fecha", SqlDbType.DateTime).Value = dtRowainsertar.fecha; cmdInsert.Parameters.Add("@notadecompraID", SqlDbType.Int).Value = int.Parse(this.lblNotadeCompraID.Text); cmdInsert.Parameters.Add("@movimientoID", SqlDbType.Int).Value = dtRowainsertar.movimientoID; int numregistros = cmdInsert.ExecuteNonQuery(); if (numregistros != 1) { throw new Exception("ERROR AL INSERTAR RELACION NV - PAGOS. LA DB REGRESÓ QUE SE ALTERARON " + numregistros.ToString() + "REGISTROS"); } Logger.Instance.LogUserSessionRecord(Logger.typeModulo.NOTACOMPRA, Logger.typeUserActions.UPDATE, this.UserID, "SE INSERTÓ UN PAGO A LA NOTA DE COMPRA " + this.lblNotadeVentaID.Text + " EL MOV DE CAJA CHICA FUE: " + dtRowainsertar.movimientoID.ToString()); } catch (Exception ex) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.UPDATE, this.UserID, "ERROR AL INSERTAR UN PAGO A LA NOTA (CAJA CHICA): " + this.lblNotadeVentaID.Text + ". EX " + ex.Message, this.Request.Url.ToString()); } } if (this.drpdlCatalogoInterno.SelectedIndex != null && this.drpdlGrupoCatalogos.SelectedItem.Text.IndexOf("TRASPASOS") > -1) { //si es un traspaso entonces verificar el destino if (this.drpdlCatalogoInterno.SelectedItem != null && this.drpdlCatalogoInterno.SelectedItem.Text.IndexOf("CAJA CHICA") > -1) { dtRowainsertar.movimientoID = -1; dtRowainsertar.bodegaID = int.Parse(this.ddlCajaDestino.SelectedValue); double fMonto; fMonto = dtRowainsertar.cargo; dtRowainsertar.cargo = dtRowainsertar.abono; dtRowainsertar.abono = fMonto; int cicloID = int.Parse(this.ddlCicloDestino.SelectedValue); if (dbFunctions.insertMovCajaChica(ref dtRowainsertar, ref serror, this.UserID, cicloID, false, -1, ref this.listBoxAgregadas, -1, 0, 0, Utils.Now, "")) { //if the mov destino were successfully added then add the relation with the mov origen SqlConnection connOrigen = new SqlConnection(myConfig.ConnectionInfo); SqlCommand commOrigen = new SqlCommand(); commOrigen.CommandText = "INSERT INTO MOVIMIENTOORIGEN(movimientoID) VALUES(@movimientoID);select movimientoID = SCOPE_IDENTITY();"; try { commOrigen.Connection = connOrigen; connOrigen.Open(); commOrigen.Parameters.Add("movimientoID", SqlDbType.Int).Value = int.Parse(sNewMov); int movorigenid = int.Parse(commOrigen.ExecuteScalar().ToString()); commOrigen.CommandText = "update movimientosCaja set movOrigenID = @movOrigenID where movimientoID = @movimientoID"; commOrigen.Parameters.Clear(); commOrigen.Parameters.Add("movOrigenID", SqlDbType.Int).Value = movorigenid; commOrigen.Parameters.Add("movimientoID", SqlDbType.Int).Value = dtRowainsertar.movimientoID; commOrigen.ExecuteNonQuery(); } catch (System.Exception ex) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.INSERT, this.UserID, "Error en mov de origen :" + ex.Message + " stack: " + Environment.StackTrace, this.Request.Url.ToString()); } finally { connOrigen.Close(); } } } else { ////insert the mov de banco destino //es a otra cuenta de banco dsMovBanco.dtMovBancoRow rowBanco = new dsMovBanco.dtMovBancoDataTable().NewdtMovBancoRow(); rowBanco.conceptoID = 7;// dtRowainsertar.conceptoID; rowBanco.nombre = dtRowainsertar.nombre; rowBanco.fecha = dtRowainsertar.fecha; //dats de cheque rowBanco.numCheque = 0; rowBanco.chequeNombre = ""; rowBanco.facturaOlarguillo = ""; rowBanco.numCabezas = 0; rowBanco.catalogoMovBancoInternoID = dtRowainsertar.catalogoMovBancoInternoID; rowBanco.subCatalogoMovBancoInternoID = dtRowainsertar.IssubCatalogoMovBancoInternoIDNull() ? -1 : dtRowainsertar.subCatalogoMovBancoInternoID; rowBanco.catalogoMovBancoFiscalID = rowBanco.catalogoMovBancoInternoID; rowBanco.subCatalogoMovBancoFiscalID = dtRowainsertar.IssubCatalogoMovBancoInternoIDNull() ? -1 : dtRowainsertar.subCatalogoMovBancoInternoID; if (dtRowainsertar.cargo > 0) { rowBanco.abono = dtRowainsertar.cargo; rowBanco.cargo = 0; } else { rowBanco.cargo = dtRowainsertar.abono; rowBanco.abono = dtRowainsertar.cargo; } String serrorBanco = ""; rowBanco.cuentaID = int.Parse(this.ddlCuentaDestino.SelectedValue); ListBox tempLB = new ListBox(); if (dbFunctions.insertMovementdeBanco(ref rowBanco, ref serrorBanco, this.UserID, rowBanco.cuentaID, false, -1, ref tempLB, -1, 0f, 0f, Utils.Now, -1, "")) { //if the mov destino were successfully added then add the relation with the mov origen SqlConnection connOrigen = new SqlConnection(myConfig.ConnectionInfo); SqlCommand commOrigen = new SqlCommand(); commOrigen.CommandText = "INSERT INTO MOVIMIENTOORIGEN(movimientoID) VALUES(@movimientoID);select movimientoID = SCOPE_IDENTITY();"; try { commOrigen.Connection = connOrigen; connOrigen.Open(); commOrigen.Parameters.Add("movimientoID", SqlDbType.Int).Value = int.Parse(sNewMov); int movorigenid = int.Parse(commOrigen.ExecuteScalar().ToString()); commOrigen.CommandText = "update movimientosCuentasBanco set movOrigenID = @movOrigenID where movbanID = @movbanID"; commOrigen.Parameters.Clear(); commOrigen.Parameters.Add("movOrigenID", SqlDbType.Int).Value = movorigenid; commOrigen.Parameters.Add("movbanID", SqlDbType.Int).Value = rowBanco.movBanID; commOrigen.ExecuteNonQuery(); } catch (System.Exception ex) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.INSERT, this.UserID, "Error en mov de origen :" + ex.Message, this.Request.Url.ToString()); } finally { connOrigen.Close(); } } //end insert the mov de banco destino } } this.panelagregar.Visible = false; this.panelMensaje.Visible = true; this.lblMensajetitle.Text = myConfig.StrFromMessages("EXITO"); this.txtIDDetails.Text = sNewMov; // this.DetailsView1.DataSource = tablaaux; this.DetailsView1.DataBind(); this.imagenbien.Visible = true; this.imagenmal.Visible = false; this.limpiacampos(); this.lblMensajeOperationresult.Text = string.Format(myConfig.StrFromMessages("MOVCAJAADDEDEXITO"), sNewMov); this.lblMensajeException.Text = ""; //BORRAMOS PORQUE NO HAY EXcEPTION this.lblReminder.Visible = true; Logger.Instance.LogUserSessionRecord(Logger.typeModulo.MOVIMIENTOSDECAJACHICA, Logger.typeUserActions.INSERT, int.Parse(this.Session["USERID"].ToString()), "AGREGÓ EL MOVIMIENTO DE CAJA CHICA NÚMERO: " + dtRowainsertar.movimientoID.ToString()); } else { this.panelagregar.Visible = false; this.panelMensaje.Visible = true; this.lblMensajetitle.Text = myConfig.StrFromMessages("FALLO"); this.lblMensajeOperationresult.Text = string.Format(myConfig.StrFromMessages("MOVCAJAADDEDFAILED"), dtRowainsertar.movimientoID.ToString()); this.lblMensajeException.Text = ""; //BORRAMOS PORQUE NO HAY EXcEPTION Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.INSERT, int.Parse(this.Session["USERID"].ToString()), serror, this.Request.Url.ToString()); } } catch (Exception ex) { Logger.Instance.LogMessage(Logger.typeLogMessage.CRITICAL, Logger.typeUserActions.INSERT, this.UserID, "ERROR AL INSERTAR MOVIMIENTO DE CAJA. EX : " + ex.Message, this.Request.Url.ToString()); } }