private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (!txtAbono.Text.Equals("") && !txt_efectivo.Text.Equals(""))
            {
                if (new Seguridad().validar_numero(txtAbono.Text) && new Seguridad().validar_numero(txt_efectivo.Text))
                {
                    string comentario = txtComentario.Text;

                    DateTime fecha = DateTime.Now;
                    //double costo =  Convert.ToDouble(txt_efectivo.Text, culture);
                    double abono    = Convert.ToDouble(txtAbono.Text, culture);
                    double efectivo = Convert.ToDouble(txt_efectivo.Text, culture);
                    //System.Windows.MessageBox.Show("el restante es " + restante);
                    //System.Windows.MessageBox.Show("el abono es de " + abono);
                    double cambio = efectivo - abono;

                    if (efectivo >= abono && abono > 0)
                    {
                        // System.Windows.MessageBox.Show("abono es " + abono);
                        // System.Windows.MessageBox.Show("restante es " + restante);
                        if (abono <= restante && restante > 0.0)
                        {
                            Abonos_Membresia ab            = new Abonos_Membresia(bandera_online_offline);
                            bool             insertarAbono = ab.InsertarAbonoMembresia(fecha.ToString("yyyy/MM/dd"), abono.ToString(culture), comentario, id_membresia, paciente.id_paciente, paciente.clinica.id_clinica, alias);
                            if (insertarAbono)
                            {
                                //ab = new Abonos(!bandera_online_offline);
                                //ab.insertarAbono(id_paciente, id_motivo, fecha.ToString("yyyy/MM/dd"), abono.ToString(culture), comentario);
                                //System.Windows.Forms.MessageBox.Show("Se registro Correctamente", "Correcto", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //System.Windows.Forms.MessageBox.Show("El cambio es de " + cambio, "Correcto", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //System.Windows.Forms.MessageBox.Show("Se esta imprimiendo el recibo", "Correcto", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //imprimir_recibo(fecha.ToString("yyyy/MM/dd"), nombre, abono, motivo, restante, cambio);

                                imprimir_recibo();
                            }
                            else
                            {
                                // System.Windows.Forms.MessageBox.Show("No se pudo realizar el pago", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("El abono excede el precio del tratamiento", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                            //AGREGAR SI DESEA CONTINUAR
                        }
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Abono mayor que efectivo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        //AGREGAR SI DESEA CONTINUAR
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Solo se aceptan valores numericos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Favor de llenar los campos de abono y efectivo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /*MÉTODO PARA IMPRIMIR*/

        /*MÉTODO PARA IMPRIMIR*/

        private void Imprimir(object sender, PrintPageEventArgs e)
        {
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment = StringAlignment.Center;

            System.Drawing.Font font   = new System.Drawing.Font("Courier New", 12, System.Drawing.FontStyle.Bold);
            System.Drawing.Font titulo = new System.Drawing.Font("Courier New", 12, System.Drawing.FontStyle.Bold);
            System.Drawing.Font cuerpo = new System.Drawing.Font("Courier New", 9);
            System.Drawing.Font final  = new System.Drawing.Font("Courier New", 6);

            // MODIFICADORES DE FORMATO DE HOJA/
            float  margen_izquierdo        = 0;
            float  margen_superior         = 10;
            double margen_cuerpo           = 0.42; //DESPUES DEL TITULO
            double tamanio_hoja_horizontal = 3.6;
            // ----------------------------------/

            double cambio = (Convert.ToDouble(this.txt_efectivo.Text)) - (Convert.ToDouble(this.txtAbono.Text));

            System.Windows.MessageBox.Show("el cambio es :" + cambio);
            //double restante = this.restante - (Int32.Parse(this.txtAbono.Text));

            string           fecha_inicio       = DateTime.Now.ToString("d/M/yyyy");
            string           fecha_finalizacion = DateTime.Now.AddYears(1).ToString("d/M/yyyy");
            string           hora            = DateTime.Now.ToString("HH:mm:ss") + " hrs";
            Abonos_Membresia a               = new Abonos_Membresia(bandera_online_offline);
            double           restante_pagado = a.Restante(id_membresia);
            double           abonado_pagado  = a.Abonados(id_membresia, paciente.id_paciente, paciente.clinica.id_clinica);
            string           sucursal        = obtener_nombre_sucursal(paciente.clinica.id_clinica);
            int tamanio_rectangulo           = 13;

            System.Drawing.Image      imagen = System.Drawing.Image.FromFile(System.IO.Path.Combine(@System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, @"..\..\..\Assets\bs_ticket_imagen.bmp"));
            System.Drawing.RectangleF rect   = new System.Drawing.RectangleF(margen_izquierdo, margen_superior, centimetroAPixel(3.8), tamanio_rectangulo);//tamanio_hoja_horizontal en vez de 4
            RectangleF rImage = new RectangleF(38, margen_superior, 110, 110);

            e.Graphics.DrawImage(imagen, rImage);

            //e.Graphics.FillRectangle(Brushes.Red, rect); usarlo para cada recyangulo
            rect.Y      = (cuerpo.GetHeight(e.Graphics) * 7) + margen_superior;
            rect.Height = 15;
            e.Graphics.DrawString("BONITA SMILE", titulo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.X     = Convert.ToSingle(centimetroAPixel(margen_cuerpo));
            rect.Width = centimetroAPixel(tamanio_hoja_horizontal); //nuevo

            rect.Y                 = (cuerpo.GetHeight(e.Graphics) * 9) + margen_superior;
            rect.Height            = 30;
            stringFormat.Alignment = StringAlignment.Near;
            e.Graphics.DrawString("SUCURSAL: " + sucursal, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);


            rect.Y = (cuerpo.GetHeight(e.Graphics) * 11) + margen_superior;
            e.Graphics.DrawString("CLIENTE: " + paciente.nombre + " " + paciente.apellidos, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y      = (cuerpo.GetHeight(e.Graphics) * 13) + margen_superior;
            rect.Height = tamanio_rectangulo;
            e.Graphics.DrawString("FECHA: " + fecha_inicio, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 14) + margen_superior;
            e.Graphics.DrawString("HORA: " + hora, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 16) + margen_superior;
            e.Graphics.DrawString("MOTIVO: ", cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Height = 30;
            rect.Y      = (cuerpo.GetHeight(e.Graphics) * 18) + margen_superior;
            e.Graphics.DrawString("Abono de membresia", cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y      = (cuerpo.GetHeight(e.Graphics) * 20) + margen_superior;
            rect.Height = tamanio_rectangulo;
            e.Graphics.DrawString("PRECIO: $" + this.total, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 21) + margen_superior + 10;
            e.Graphics.DrawString("-------------------", cuerpo, new SolidBrush(Color.Black), rect, stringFormat);
            rect.Y = ((cuerpo.GetHeight(e.Graphics) * 21) + margen_superior + 10) + 5;
            e.Graphics.DrawString("-------------------", cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 23) + margen_superior - 5;
            e.Graphics.DrawString("-------------------", cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = ((cuerpo.GetHeight(e.Graphics) * 23) + margen_superior - 5) + 5;
            e.Graphics.DrawString("-------------------", cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = ((cuerpo.GetHeight(e.Graphics) * 24) + margen_superior);
            e.Graphics.DrawString("TOTAL: $" + this.total, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 25) + margen_superior;
            e.Graphics.DrawString("ABONO: $" + txtAbono.Text, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 26) + margen_superior;
            e.Graphics.DrawString("RECIBIDO: $" + txt_efectivo.Text, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 27) + margen_superior;
            e.Graphics.DrawString("CAMBIO: $" + cambio, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 29) + margen_superior - 5;
            e.Graphics.DrawString("-------------------", cuerpo, new SolidBrush(Color.Black), rect, stringFormat);
            rect.Y = ((cuerpo.GetHeight(e.Graphics) * 29) + margen_superior - 5) + 5;
            e.Graphics.DrawString("-------------------", cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 31) + margen_superior;
            e.Graphics.DrawString("ABONADO: " + abonado_pagado, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.Y = (cuerpo.GetHeight(e.Graphics) * 32) + margen_superior;
            e.Graphics.DrawString("RESTANTE: " + restante_pagado, cuerpo, new SolidBrush(Color.Black), rect, stringFormat);

            rect.X = Convert.ToSingle(centimetroAPixel(0.27));
            rect.Y = (cuerpo.GetHeight(e.Graphics) * 34) + margen_superior;
            //e.Graphics.DrawString("La fundación Doi Esperanza brinda una aportación del " + txt_Aportacion.Text + "% del total", final, new SolidBrush(Color.Black), rect, stringFormat);

            e.HasMorePages = false;
        }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            string id_membresia = "";

            if (!txtPrecio.Text.Equals("") && !txt_efectivo.Text.Equals(""))
            {
                if (new Seguridad().validar_numero(txtPrecio.Text) && new Seguridad().validar_numero(txt_efectivo.Text))
                {
                    double abono    = Convert.ToDouble(txtPrecio.Text, culture);
                    double efectivo = Convert.ToDouble(txt_efectivo.Text, culture);
                    if (efectivo > 0)
                    {
                        try
                        {
                            //MessageBox.Show(paciente.nombre);
                            bool inserto = new Membresia(bandera_online_offline).InsertarMembresia(paciente.id_paciente, datetimepicker1.Value.ToString("yyyy/MM/dd"), paciente.clinica.id_clinica, abono.ToString(culture), alias);
                            if (inserto)
                            {
                                List <MembresiaModel> lista = new Membresia(bandera_online_offline).MostrarMembresias(paciente.id_paciente, paciente.clinica.id_clinica);
                                foreach (var membresia in lista)
                                {
                                    id_membresia = membresia.id_membresia;
                                }

                                bool inserto2 = new Abonos_Membresia(bandera_online_offline).InsertarAbonoMembresia(DateTime.Now.ToString("yyyy/MM/dd"), efectivo.ToString(culture), "Primer pago para tener la membresia", id_membresia, paciente.id_paciente, paciente.clinica.id_clinica, alias);
                                if (inserto2)
                                {
                                    //System.Windows.Forms.MessageBox.Show("El paciente " + paciente.nombre + " " + paciente.apellidos + " es ahora miembro", "Se ingreso correctamente", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                    imprimir_recibo();

                                    Soc   socio = System.Windows.Application.Current.Windows.OfType <Soc>().FirstOrDefault();
                                    Admin admin = System.Windows.Application.Current.Windows.OfType <Admin>().FirstOrDefault();
                                    Recep recep = System.Windows.Application.Current.Windows.OfType <Recep>().FirstOrDefault();

                                    if (admin != null)
                                    {
                                        //MessageBox.Show(abono.ToString());
                                        admin.Main.Content = new Abonos_Mem(paciente, id_membresia, abono, alias);
                                    }
                                    else
                                    if (recep != null)
                                    {
                                        recep.Main3.Content = new Abonos_Mem(paciente, id_membresia, abono, alias);
                                    }
                                    else
                                    if (socio != null)
                                    {
                                        socio.Main4.Content = new Abonos_Mem(paciente, id_membresia, abono, alias);
                                    }
                                }


                                // -----------------------------------------------/
                                //inserto = new Paciente(!bandera_online_offline).actualizarMembresia(paciente);
                            }
                            else
                            {
                                // System.Windows.Forms.MessageBox.Show("No se pudo  Ingresar la membresia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Windows.Forms.MessageBox.Show("Se ha producido un error ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            this.DialogResult = DialogResult.OK;
                        }
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Abono mayor que efectivo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Cantidad no valida", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("LLene todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }