Beispiel #1
0
        private void butBuscar_Click(object sender, System.EventArgs e)
        {
            try
            {
                DsFactura ds;

                if (this.radioTipo.Checked)
                {
                    ds = BuscarPorTipo();
                }
                else
                {
                    ds = BuscarPorCodigo();
                }

                if (ds != null)
                {
                    this.butBuscar.Enabled = true;

                    IFactura             factura = FacturaFactory.GetFactura();
                    DsFactura.DatosRow[] drLista = (DsFactura.DatosRow[])ds.Datos.Select("UnidadNegocioID = " + this.UnidadNegocioID);
                    int total = drLista.Length;

                    if (total > 0)
                    {
                        DsFactura.DatosRow dr = drLista[0];
                        if (dr.EstadoFacturaID == (int)NegociosSisPackInterface.SisPack.EstadoFactura.Anulada)
                        {
                            /* La factura ya ha sido anulada */
                            Page.RegisterStartupScript("NoAnular", GenerarJavaScripts.MostrarMensaje("La factura se encuentra anulada."));
                            this.butConfirmar.Enabled = false;
                            return;
                        }

                        if (dr.AgenciaID != 0)
                        {
                            IAgencia agencia = AgenciaFactory.GetAgencia();
                            agencia.AgenciaID = dr.AgenciaID;
                            if (agencia.Consultar())
                            {
                                this.txtAgenciaID.Text = agencia.AgenciaID.ToString();
                                this.txtAgencia.Text   = agencia.RazonSocial.Trim();
                            }
                            agencia = null;
                        }

                        // Permitir anulacion de facturas de conceptos facturables.
                        this.txtGuiaID.Text                 = dr.IsGuiaIDNull() ? "" : dr.GuiaID.ToString();
                        this.txtFecha.Text                  = dr.FechaEmision.ToShortDateString().Trim();
                        this.txtImporte.Text                = Utiles.Formatos.Importe(dr.ImporteNeto + dr.ImporteIVA);
                        this.txtTipoImpresionGuiaID.Text    = dr.IsTipoImpresionGuiaIDNull()? "0": dr.TipoImpresionGuiaID.ToString().Trim();
                        this.txtFacturaID.Text              = dr.FacturaID.ToString().Trim();
                        this.txtClasificacionFactura.Text   = dr.ClasificacionFactura.Trim();
                        this.txtClasificacionFacturaID.Text = dr.ClasificacionFacturaID.ToString().Trim();

                        this.butConfirmar.Enabled = true;
                        this.butBuscar.Enabled    = false;
                        this.radioTipo.Enabled    = false;
                        this.radioCodigo.Enabled  = false;
                        dr = null;
                    }
                    else
                    {
                        string script = "<script language='javascript'>\n";
                        script += "alert('No se encontro la factura.');\n";
                        script += "</script>";

                        Page.RegisterStartupScript("scriptError", script);
                    }
                    factura = null;
                    drLista = null;
                }
            }
            catch (Exception ex)
            {
                butBuscar.Enabled = false;
                string mensaje = ex.Message;
                try
                {
                    mensaje = this.TraducirTexto(ex.Message);
                    if (mensaje == "" || mensaje == null)
                    {
                        mensaje = ex.Message;
                    }
                }
                catch (Exception)
                {
                    mensaje = ex.Message;
                }
                ((ErrorWeb)this.phErrores.Controls[0]).setMensaje(mensaje);
            }
        }