protected void btnGuardar_Click(object sender, EventArgs e) { int num = 0; long num2 = 0L; int num3 = 0; string str = ""; str = this.txtNroComprobante.Text.ToString(); DataTable table = Consulta.DatosAbonos(str, this.hiddidcobranza.Value.ToString()); if ((table.Rows.Count > 0) && (table != null)) { num = Convert.ToInt32(table.Rows[0]["docuno"].ToString()); num2 = Convert.ToInt64(table.Rows[0]["montoabono"].ToString()); DateTime time = Convert.ToDateTime(table.Rows[0]["fpago"].ToString()); string str2 = this.txtFechaPago.Text.ToString().Substring(0, 2); string str3 = this.txtFechaPago.Text.ToString().Substring(3, 2); string str4 = this.txtFechaPago.Text.ToString().Substring(6, 4); if (Convert.ToDateTime(string.Concat(new object[] { str3, '-', str2, '-', str4 })) > time) { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Fecha ingresada no puede ser mayor a la fecha pago \x00faltimo cheque, ingrese fecha v\x00e1lida');</script>"); } else { DataTable table2 = Consulta.DatosMCH(str, this.hiddidcobranza.Value.ToString()); if (table2 != null && table2.Rows.Count > 0) { long num5 = 0L; long num6 = Convert.ToInt64(this.txtMontoAbono.Text.ToString()); num3 = Convert.ToInt32(table2.Rows[0]["nroch"].ToString()); num5 = Convert.ToInt64(table2.Rows[0]["sumaabono"].ToString()) + num6; if (num5 > num2) { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Monto ingresado sumado es mayor al monto a pagar');</script>"); } else if ((num == 1) && (num5 < num2)) { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Monto ingresado no puede ser menor al monto a pagar para un cheque');</script>"); } else if ((num3 > num) && (num5 < num2)) { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Acaba de ingresar m\x00e1s cheques del total de : " + num.ToString() + " que corresponde');</script>"); } else if ((num3 >= num) && (num5 < num2)) { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Ya ingreso el total de cheques : " + num.ToString() + " que corresponde, pero falta abono para completar el total a pagar');</script>"); } else if ((num3 == num) && (num5 < num2)) { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Ya ingreso el total de cheques : " + num.ToString() + " que corresponde, pero falta abono para completar el total a pagar');</script>"); } else { if (num5 == num2) { num3++; if ((num3 < num) && (num3 != 0)) { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Se ingresaron menos cheques a la cantidad total de " + num.ToString() + " cheques a ingresar');</script>"); return; } } if (num5 < num2) { num3++; if (num3 == num) { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Monto ingresado es menor, por lo tanto no cuadra con monto a pagar y este es el \x00faltimo cheque a ingresar');</script>"); return; } } Transaccion.InsertaAbonoMCH(this.hiddidcobranza.Value.ToString(), this.txtNroComprobante.Text, this.txtFechaPago.Text, this.txtNroCheque.Text, this.txtSerie.Text, this.txtMontoAbono.Text, this.Session["Usuario"].ToString()); string str6 = "pagoAbonoSub.aspx?Codigo=" + this.hiddidcobranza.Value.ToString(); this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Datos guardados correctamente');location.href='" + str6.ToString() + "';</script>"); } } } } else { this.Page.RegisterClientScriptBlock("Mensaje", "<script>alert('Comprobante no v\x00e1lido, ingrese uno v\x00e1lido');</script>"); } }