コード例 #1
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            if (Session["Usuario"] == null)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "mykey", "CancelEdit();", true);
            }

            gsEgresosVarios_BuscarDetalleResult objEVDetalle;
            string idAgenda = "";

            try {
                if (!btnAgregar.Visible)
                {
                    AgendaWCFClient objAgendaWCF = new AgendaWCFClient();
                    if (txtNroRUC.Text.Length != 11)
                    {
                        throw new ArgumentException("El número RUC ingresado no es correcto");
                    }
                    if (string.IsNullOrEmpty(txtRazonSocial.Text))
                    {
                        throw new ArgumentException("Se debe ingresar la razón social del proveedor.");
                    }
                    idAgenda = objAgendaWCF.Agenda_RegistrarProveedor(((Usuario_LoginResult)Session["Usuario"]).idEmpresa,
                                                                      ((Usuario_LoginResult)Session["Usuario"]).codigoUsuario, txtNroRUC.Text, txtRazonSocial.Text.ToUpper());
                }

                objEVDetalle = new gsEgresosVarios_BuscarDetalleResult();
                if (Request.QueryString["objRecibo"] != "0")
                {
                    objEVDetalle = JsonHelper.JsonDeserialize <gsEgresosVarios_BuscarDetalleResult>(Request.QueryString["objRecibo"]);
                }
                else
                {
                    objEVDetalle = new gsEgresosVarios_BuscarDetalleResult();
                }

                if (string.IsNullOrEmpty(txtImporte.Text) || txtImporte.Value <= 0)
                {
                    throw new ArgumentException("Se debe ingresar un importe mayor 0 soles.");
                }
                objEVDetalle.Importe = (decimal)txtImporte.Value;
                if (cboTipoGasto.SelectedIndex < 0)
                {
                    throw new ArgumentException("Se debe seleccionar un tipo de gasto valido.");
                }
                objEVDetalle.ID_Item = cboTipoGasto.SelectedValue;
                objEVDetalle.Item    = cboTipoGasto.Text;
                if (acbTipoDocumento.Entries.Count <= 0)
                {
                    throw new ArgumentException("Se debe ingresar un tipo de documento valido.");
                }
                objEVDetalle.ID_Documento    = decimal.Parse(acbTipoDocumento.Text.Split('-')[0]);
                objEVDetalle.NombreDocumento = acbTipoDocumento.Text.Split('-')[1];
                if (acbProveedor.Entries.Count <= 0 && btnAgregar.Visible)
                {
                    throw new ArgumentException("Se debe ingresar un proveedor valido.");
                }
                if (btnAgregar.Visible)
                {
                    objEVDetalle.ID_Agenda = acbProveedor.Text.Split('-')[0];
                    objEVDetalle.Agenda    = acbProveedor.Text.Split('-')[1];
                }
                else
                {
                    objEVDetalle.ID_Agenda = idAgenda;
                    objEVDetalle.Agenda    = txtRazonSocial.Text;
                }
                if (string.IsNullOrEmpty(txtSerie.Text))
                {
                    throw new ArgumentException("Se debe ingresar una serie valida.");
                }
                objEVDetalle.Serie = txtSerie.Text;
                if (string.IsNullOrEmpty(txtNumero.Text))
                {
                    throw new ArgumentException("Se debe ingresar un número valido.");
                }
                objEVDetalle.Numero          = (decimal)txtNumero.Value;
                objEVDetalle.Observaciones   = txtComentario.Text;
                objEVDetalle.FechaEmision    = dpFecEmision.SelectedDate.Value;
                objEVDetalle.ImporteBaseIGV  = Convert.ToDecimal(txtImpBase.Value);
                objEVDetalle.ImporteIGV      = Convert.ToDecimal(txtIGV.Value);
                objEVDetalle.ImporteInafecto = Convert.ToDecimal(txtInafecto.Value);
                objEVDetalle.Estado          = 1;

                ScriptManager.RegisterStartupScript(Page, this.GetType(), "mykey", "CloseAndRebind(" + JsonHelper.JsonSerializer(objEVDetalle) + ");", true);
            }
            catch (Exception ex) {
                lblMensaje.Text     = "ERROR: " + ex.Message;
                lblMensaje.CssClass = "mensajeError";
            }
        }