private async void btnanular_Click(object sender, RoutedEventArgs e)
        {
            DataRowView row = (DataRowView)((Button)e.Source).DataContext;

            decimal _not_id = Convert.ToDecimal(row["Not_Id"]);        // dg1.Rows[e.RowIndex].Cells["ven_id"].Value.ToString();
            string  _tipo   = (string)row["tipodoc"].ToString();       //dg1.Rows[e.RowIndex].Cells["tipodoc"].Value.ToString();
            string  _numdoc = (string)row["numdoc"].ToString();        //dg1.Rows[e.RowIndex].Cells["numdoc"].Value.ToString();
            //string _doc = (string)row["ven_id"].ToString();//dg1.Rows[e.RowIndex].Cells["ven_id"].Value.ToString();
            Boolean _anulado = (Boolean)row["anulado"];                // Convert.ToBoolean(dg1.Rows[e.RowIndex].Cells["anulado"].Value);
            //verificar si el documento paso las 72 horas de enviarse a la web service efact
            Boolean _valida = (Boolean)row["docu_vencido"];            // Convert.ToBoolean(dg1.Rows[e.RowIndex].Cells["docu_vencido"].Value);

            string _not_numero = (string)row["not_numero"].ToString(); //dg1.Rows[e.RowIndex].Cells["not_numero"].Value.ToString();

            //string _not_numero = dg1.Rows[e.RowIndex].Cells["not_numero"].Value.ToString();

            if (_anulado)
            {
                MessageBox.Show("!El documento de tipo : " + _tipo + " con numero : " + _numdoc + " no se puede anular, porque YA ESTA ANULADO...", Ent_Msg.msginfomacion, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            _valida = false;
            if (_valida)
            {
                MessageBox.Show("!El documento de tipo : " + _tipo + " con numero : " + _numdoc + " no se puede anular, porque no es de la fecha actual...", Ent_Msg.msginfomacion, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            var mySettings = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Si",
                NegativeButtonText    = "No",
                //FirstAuxiliaryButtonText = "Cancelar",
                ColorScheme = MetroDialogOptions.ColorScheme,
            };

            MessageDialogResult result = await this.ShowMessageAsync(Ent_Msg.msginfomacion, "¿Realmente desea anular el documento de tipo : " + _tipo + " con numero : " + _numdoc,
                                                                     MessageDialogStyle.AffirmativeAndNegative, mySettings);


            if (result == MessageDialogResult.Affirmative)
            {
                Mouse.OverrideCursor = Cursors.Wait;
                string _error = "";

                //Facturacion_Electronica.anular_facturacion_electronica(_doc, ref _error, "NC");


                //if (_error.Length == 0)
                //{
                var ProgressAlert = await this.ShowProgressAsync(Ent_Msg.msgcargando, "Anulando Nota de Credito N°:" + _numdoc); //show message

                ProgressAlert.SetIndeterminate();                                                                                //Infinite
                string _error_venta = await Task.Run(() => Dat_NotaCredito._anular_ncredito(_not_id, Ent_Global._bas_id_codigo));

                //string _error_venta =Dat_NotaCredito._anular_ncredito(_not_id, Ent_Global._bas_id_codigo);
                string _codigo_hashn = ""; string _url_pdf = "";


                if (_error_venta.Length == 0)
                {
                    await Task.Run(() => Facturacion_Electronica.ejecutar_factura_electronica("N", _not_id.ToString(), ref _codigo_hashn, ref _error, ref _url_pdf));


                    if (_error.Length == 0)
                    {
                        await Task.Run(() => Basico._enviar_webservice_xml());

                        Boolean  _tipoc_b    = chkactivar.IsChecked.Value;
                        DateTime _fechaini_b = Convert.ToDateTime(dtpdesde.Text);
                        DateTime _fechafin_b = Convert.ToDateTime(dtphasta.Text);
                        string   _doc_b      = txtdoc.Text;
                        //MessageBox.Show("!El documento de tipo : " + _tipo + " con numero : " + _numdoc + " Se Anulo con exito...", Ent_Msg.msginfomacion, MessageBoxButton.OK, MessageBoxImage.Information);
                        //consultar();
                        DataTable dt = await Task.Run(() => Dat_NotaCredito.dt_consulta_notacredito(_tipoc_b, _fechaini_b, _fechafin_b, _doc_b));

                        await ProgressAlert.CloseAsync();

                        dg1.ItemsSource = dt.DefaultView;
                        await this.ShowMessageAsync(Ent_Msg.msginfomacion, "!El documento de tipo : " + _tipo + " con numero : " + _numdoc + " Se Anulo con exito...");
                    }
                    else
                    {
                        await ProgressAlert.CloseAsync();

                        await this.ShowMessageAsync(Ent_Msg.msginfomacion, _error);

                        //MessageBox.Show(_error_venta, Ent_Msg.msginfomacion, MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    await ProgressAlert.CloseAsync();

                    await this.ShowMessageAsync(Ent_Msg.msginfomacion, _error_venta);
                }
                //}
                //else
                //{
                //    MessageBox.Show(_error, Ent_Msg.msginfomacion, MessageBoxButton.OK, MessageBoxImage.Error);
                //}
            }
            //}
            Mouse.OverrideCursor = null;
        }