unit principal;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Menus, Vcl.ImgList,//ffunciones,
  Vcl.StdCtrls, Vcl.ComCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.Imaging.jpeg,
  Vcl.Mask, Vcl.DBCtrls,datos, Vcl.ExtDlgs,BDE, Data.DB, ZAbstractRODataset,
  ZDataset, ZAbstractDataset, Vcl.DBLookup, Vcl.CheckLst, frxClass,
  frxExportPDF, frxDBSet,consultasinformes,excel2000,comobj, Xml.xmldom,
  Xml.XMLIntf, Xml.Win.msxmldom, Xml.XMLDoc, frxExportBaseDialog, shellapi;


type
  TMENU = class(TForm)
    menuprincipal: TMainMenu;
    Centros1: TMenuItem;
    Clientes1: TMenuItem;
    Alumnos1: TMenuItem;
    Cobros1: TMenuItem;
    Pagos1: TMenuItem;
    Biblioteca1: TMenuItem;
    Libros1: TMenuItem;
    Prestamos1: TMenuItem;
    Pagosprofesores1: TMenuItem;
    Salidascaja1: TMenuItem;
    Recibos1: TMenuItem;
    Facturas1: TMenuItem;
    Datosgenerales1: TMenuItem;
    Cursos1: TMenuItem;
    Grupos1: TMenuItem;
    Empleados1: TMenuItem;
    DatosGenerales2: TMenuItem;
    Datosgenerales3: TMenuItem;
    Pbotones: TPanel;
    btAlumnos: TButton;
    ImageList1: TImageList;
    btCursos: TButton;
    btRecibos: TButton;
    btGrupos: TButton;
    btEmpleados: TButton;
    btClientes: TButton;
    pprincipal: TPanel;
    Panel2: TPanel;
    PAlumnos: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    Label1: TLabel;
    todosalumnos: TCheckBox;
    tbuscaralumnos: TEdit;
    DBGrid1: TDBGrid;
    Palumnosdatos: TPanel;
    Panel7: TPanel;
    Label35: TLabel;
    btAcancelar: TButton;
    btAmodificar: TButton;
    btAborrar: TButton;
    btAnuevo: TButton;
    btAguardar: TButton;
    Panel8: TPanel;
    PageControl1: TPageControl;
    Notas: TTabSheet;
    Label2: TLabel;
    DBEdit1: TDBEdit;
    Image3: TImage;
    Image4: TImage;
    Panel9: TPanel;
    Label3: TLabel;
    DBEdit2: TDBEdit;
    Label4: TLabel;
    DBEdit3: TDBEdit;
    Label5: TLabel;
    DBEdit4: TDBEdit;
    Label6: TLabel;
    DBEdit5: TDBEdit;
    LEedad: TLabel;
    Label7: TLabel;
    DBMemo1: TDBMemo;
    DBMemo2: TDBMemo;
    Label8: TLabel;
    Bevel1: TBevel;
    Label9: TLabel;
    DBEdit6: TDBEdit;
    Label10: TLabel;
    DBEdit7: TDBEdit;
    StaticText1: TStaticText;
    DBRadioGroup1: TDBRadioGroup;
    Label11: TLabel;
    DBEdit8: TDBEdit;
    Label12: TLabel;
    DBEdit9: TDBEdit;
    Label13: TLabel;
    DBEdit10: TDBEdit;
    Label14: TLabel;
    DBEdit11: TDBEdit;
    Label15: TLabel;
    DBEdit12: TDBEdit;
    Label16: TLabel;
    DBEdit13: TDBEdit;
    Label17: TLabel;
    DBEdit14: TDBEdit;
    Label18: TLabel;
    DBEdit15: TDBEdit;
    Label19: TLabel;
    DBEdit16: TDBEdit;
    Label20: TLabel;
    DBEdit17: TDBEdit;
    Label21: TLabel;
    DBEdit18: TDBEdit;
    Bevel2: TBevel;
    StaticText2: TStaticText;
    DBLookupComboBox1: TDBLookupComboBox;
    Label22: TLabel;
    DBEdit19: TDBEdit;
    Label23: TLabel;
    Label24: TLabel;
    DBEdit20: TDBEdit;
    Label25: TLabel;
    DBEdit21: TDBEdit;
    Label26: TLabel;
    DBEdit22: TDBEdit;
    Label27: TLabel;
    DBEdit23: TDBEdit;
    Panel10: TPanel;
    Label28: TLabel;
    DBEdit24: TDBEdit;
    btAsalir: TButton;
    MenubtAimagen: TPopupMenu;
    Cargar1: TMenuItem;
    Capturar1: TMenuItem;
    DBEdit25: TDBEdit;
    Label29: TLabel;
    DBEdit26: TDBEdit;
    Label30: TLabel;
    OpenPictureDialog1: TOpenPictureDialog;
    PAImagenes: TPanel;
    imgfoto2: TImage;
    DBNavigator1: TDBNavigator;
    btAimagen: TButton;
    btAokimagen: TButton;
    btactivarcamara: TButton;
    btdesactivarcamara: TButton;
    imgfoto: TImage;
    panelfoto: TPanel;
    Panel6: TPanel;
    gcrpagado: TDBCheckBox;
    Panel3: TPanel;
    DBGrid3: TDBGrid;
    Panel11: TPanel;
    btAscancelar: TButton;
    btAsmodificar: TButton;
    BtAsborrar: TButton;
    btAsnuevo: TButton;
    btAsguardar: TButton;
    PEstudiosAlumno: TPanel;
    comboasistirgrupos: TDBLookupComboBox;
    DBEdit27: TDBEdit;
    DBEdit28: TDBEdit;
    DBEdit29: TDBEdit;
    DBEdit30: TDBEdit;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label36: TLabel;
    DBEdit31: TDBEdit;
    Label37: TLabel;
    DBRadioGroup2: TDBRadioGroup;
    Label38: TLabel;
    DBEdit32: TDBEdit;
    PEmpleados: TPanel;
    Panel13: TPanel;
    Panel14: TPanel;
    Label39: TLabel;
    todosempleados: TCheckBox;
    tbuscarempleados: TEdit;
    DBGrid4: TDBGrid;
    Panel15: TPanel;
    Panel16: TPanel;
    PageControl2: TPageControl;
    TabSheet2: TTabSheet;
    DBGrid5: TDBGrid;
    TabSheet3: TTabSheet;
    Panel17: TPanel;
    DBGrid6: TDBGrid;
    Panel18: TPanel;
    bticancelar: TButton;
    btimodificar: TButton;
    btiborrar: TButton;
    btinuevo: TButton;
    btiguardar: TButton;
    pgruposempleados: TPanel;
    Label42: TLabel;
    Label43: TLabel;
    Label44: TLabel;
    comboimpartirgrupos: TDBLookupComboBox;
    DBEdit33: TDBEdit;
    DBEdit34: TDBEdit;
    TabSheet5: TTabSheet;
    Panel20: TPanel;
    Label47: TLabel;
    btecancelar: TButton;
    btemodificar: TButton;
    bteborrar: TButton;
    btenuevo: TButton;
    bteguardar: TButton;
    btesalir: TButton;
    Panel21: TPanel;
    Pempleadosdatos: TPanel;
    Label48: TLabel;
    Label49: TLabel;
    Label50: TLabel;
    Label51: TLabel;
    Bevel3: TBevel;
    Label56: TLabel;
    Label57: TLabel;
    Label58: TLabel;
    Label59: TLabel;
    Label60: TLabel;
    Label61: TLabel;
    Label62: TLabel;
    Label63: TLabel;
    Label65: TLabel;
    Label75: TLabel;
    DBEdit39: TDBEdit;
    DBEdit40: TDBEdit;
    DBEdit41: TDBEdit;
    DBEdit42: TDBEdit;
    DBEdit44: TDBEdit;
    StaticText3: TStaticText;
    DBRadioGroup4: TDBRadioGroup;
    DBEdit46: TDBEdit;
    DBEdit47: TDBEdit;
    DBEdit48: TDBEdit;
    DBEdit49: TDBEdit;
    DBEdit50: TDBEdit;
    DBEdit51: TDBEdit;
    DBEdit53: TDBEdit;
    DBEdit63: TDBEdit;
    peimagenes: TPanel;
    Imagee: TImage;
    imgfotoe: TImage;
    DBNavigator2: TDBNavigator;
    btEimagen: TButton;
    btEoKimagen: TButton;
    Button20: TButton;
    Button21: TButton;
    panelfotoe: TPanel;
    Bevel4: TBevel;
    StaticText4: TStaticText;
    Label54: TLabel;
    DBEdit52: TDBEdit;
    Label55: TLabel;
    DBEdit54: TDBEdit;
    Bevel5: TBevel;
    DBRadioGroup5: TDBRadioGroup;
    DBEdit43: TDBEdit;
    DBEdit55: TDBEdit;
    Label52: TLabel;
    Label53: TLabel;
    StaticText5: TStaticText;
    Menubteimagen: TPopupMenu;
    MenuItem1: TMenuItem;
    MenuItem2: TMenuItem;
    btactivarcamarae: TButton;
    DBEdit45: TDBEdit;
    Pcursos: TPanel;
    Panel22: TPanel;
    DBGrid7: TDBGrid;
    Panel23: TPanel;
    Label64: TLabel;
    todoscursos: TCheckBox;
    tbuscarcursos: TEdit;
    Panel24: TPanel;
    Panel25: TPanel;
    PageControl3: TPageControl;
    TabSheet7: TTabSheet;
    Panel26: TPanel;
    DBGrid9: TDBGrid;
    TabSheet8: TTabSheet;
    Panel29: TPanel;
    Label73: TLabel;
    btccancelar: TButton;
    btcmodificar: TButton;
    btcborrar: TButton;
    btcnuevo: TButton;
    btcguardar: TButton;
    btcsalir: TButton;
    Panel30: TPanel;
    Button29: TButton;
    Pcursosdatos: TPanel;
    Label74: TLabel;
    Label76: TLabel;
    Label77: TLabel;
    Label79: TLabel;
    Label80: TLabel;
    Label82: TLabel;
    Label83: TLabel;
    Label84: TLabel;
    DBEdit62: TDBEdit;
    DBEdit64: TDBEdit;
    DBEdit65: TDBEdit;
    DBEdit67: TDBEdit;
    DBRadioGroup7: TDBRadioGroup;
    DBEdit69: TDBEdit;
    DBEdit70: TDBEdit;
    DBEdit71: TDBEdit;
    DBEdit80: TDBEdit;
    DBGrid8: TDBGrid;
    Label41: TLabel;
    DBEdit36: TDBEdit;
    panelnotas: TPanel;
    Panel19: TPanel;
    btNotascancelar: TButton;
    btNotasModificar: TButton;
    btNotasguardar: TButton;
    Panelnotas2: TPanel;
    Label87: TLabel;
    Label45: TLabel;
    Label46: TLabel;
    Label86: TLabel;
    DBEdit35: TDBEdit;
    DBEdit37: TDBEdit;
    DBEdit38: TDBEdit;
    DBEdit72: TDBEdit;
    DBEdit73: TDBEdit;
    DBEdit74: TDBEdit;
    Label89: TLabel;
    DBEdit75: TDBEdit;
    DBEdit76: TDBEdit;
    DBEdit77: TDBEdit;
    DBEdit78: TDBEdit;
    DBEdit79: TDBEdit;
    DBEdit81: TDBEdit;
    DBEdit82: TDBEdit;
    DBEdit83: TDBEdit;
    Label98: TLabel;
    Label100: TLabel;
    Label101: TLabel;
    Label99: TLabel;
    btsesiones: TButton;
    PSesiones: TPanel;
    Panel36: TPanel;
    DBGrid13: TDBGrid;
    Panel37: TPanel;
    Panel38: TPanel;
    Panel39: TPanel;
    Panel41: TPanel;
    Label91: TLabel;
    btscancelar: TButton;
    btsborrar: TButton;
    btsmodificar: TButton;
    btsguardar: TButton;
    btssalir: TButton;
    Panel42: TPanel;
    Button28: TButton;
    psesionesdatos: TPanel;
    Label93: TLabel;
    Label94: TLabel;
    Label95: TLabel;
    Label96: TLabel;
    hinicio: TDBEdit;
    hfin: TDBEdit;
    comboprofesores: TDBLookupComboBox;
    Label90: TLabel;
    DBGrid14: TDBGrid;
    DBEdit86: TDBEdit;
    DBMemo3: TDBMemo;
    fechasesion: TDateTimePicker;
    PageControl5: TPageControl;
    TabSheet10: TTabSheet;
    Panel40: TPanel;
    DBGrid15: TDBGrid;
    PageControl6: TPageControl;
    TabSheet12: TTabSheet;
    Panel1: TPanel;
    Panel45: TPanel;
    Panel46: TPanel;
    btSnotascancelar: TButton;
    btSnotasmodificar: TButton;
    btSnotasguardar: TButton;
    panelnotassesiones: TPanel;
    Bevel6: TBevel;
    Label107: TLabel;
    Label108: TLabel;
    Label109: TLabel;
    Label110: TLabel;
    Label111: TLabel;
    Label112: TLabel;
    Label113: TLabel;
    Label114: TLabel;
    Label115: TLabel;
    Label116: TLabel;
    Label117: TLabel;
    DBEdit95: TDBEdit;
    DBEdit96: TDBEdit;
    DBEdit97: TDBEdit;
    DBEdit98: TDBEdit;
    DBEdit99: TDBEdit;
    DBEdit100: TDBEdit;
    DBEdit101: TDBEdit;
    DBEdit102: TDBEdit;
    DBEdit103: TDBEdit;
    DBEdit104: TDBEdit;
    DBEdit105: TDBEdit;
    DBEdit106: TDBEdit;
    DBEdit107: TDBEdit;
    DBEdit108: TDBEdit;
    DBGrid16: TDBGrid;
    qgrupoalumnos: TZReadOnlyQuery;
    dsqgrupoalumnos: TDataSource;
    qgrupoalumnosnombre_completo: TWideStringField;
    qgrupoalumnosid: TIntegerField;
    qgrupoalumnoside: TIntegerField;
    qgrupoalumnosida: TIntegerField;
    qgrupoalumnosidg: TIntegerField;
    qgrupoalumnosfechainicio: TDateField;
    qgrupoalumnosfechafin: TDateField;
    qgrupoalumnosfechabaja: TDateField;
    qgrupoalumnosmotivo_baja: TWideStringField;
    qgrupoalumnosdevoluciones: TSmallintField;
    qgrupoalumnosimporte_abono: TFloatField;
    qgrupoalumnosfecha_abono: TDateField;
    qgrupoalumnoscurso: TWideStringField;
    qgrupoalumnosnombre: TWideStringField;
    Panel43: TPanel;
    Label92: TLabel;
    Edit2: TEdit;
    Label97: TLabel;
    Button22: TButton;
    MaskEdit1: TMaskEdit;
    qempleados: TZQuery;
    qempleadosusuario: TWideStringField;
    qempleadospassword: TWideStringField;
    qempleadostipo_acceso: TIntegerField;
    qempleadosid: TIntegerField;
    qempleadoside: TIntegerField;
    btsfin: TButton;
    btsinicio: TButton;
    pavisos: TPanel;
    DBGrid17: TDBGrid;
    Timer1: TTimer;
    Panel44: TPanel;
    Label102: TLabel;
    DBGrid18: TDBGrid;
    qgrupoalumnosedad: TIntegerField;
    qgrupoalumnosfecha_nacimiento: TDateField;
    qgrupoalumnosob_medicas: TWideStringField;
    DBGrid19: TDBGrid;
    avisos: TZQuery;
    dsavisos: TDataSource;
    avisoside: TIntegerField;
    avisosidp: TIntegerField;
    avisosidg: TIntegerField;
    avisosfecha: TDateField;
    avisoscomentario: TWideStringField;
    Pclientes: TPanel;
    Panel48: TPanel;
    Panel49: TPanel;
    Label103: TLabel;
    todosclientes: TCheckBox;
    tbuscarclientes: TEdit;
    DBGrid21: TDBGrid;
    Panel50: TPanel;
    Panel51: TPanel;
    PageControl7: TPageControl;
    TabSheet14: TTabSheet;
    Panel58: TPanel;
    Label133: TLabel;
    btclcancelar: TButton;
    btclmodificar: TButton;
    btclborrar: TButton;
    btClnuevo: TButton;
    btclguardar: TButton;
    btclsalir: TButton;
    Panel59: TPanel;
    pclientesdatos: TPanel;
    Label134: TLabel;
    Label135: TLabel;
    Label136: TLabel;
    Label137: TLabel;
    Label142: TLabel;
    Label143: TLabel;
    Label147: TLabel;
    Label148: TLabel;
    Label149: TLabel;
    Label151: TLabel;
    Label161: TLabel;
    DBEdit125: TDBEdit;
    DBEdit126: TDBEdit;
    DBEdit127: TDBEdit;
    DBEdit128: TDBEdit;
    DBEdit130: TDBEdit;
    DBEdit131: TDBEdit;
    DBRadioGroup8: TDBRadioGroup;
    DBEdit135: TDBEdit;
    DBEdit136: TDBEdit;
    DBEdit137: TDBEdit;
    DBEdit139: TDBEdit;
    DBEdit148: TDBEdit;
    Bevel9: TBevel;
    Label138: TLabel;
    Label140: TLabel;
    Label141: TLabel;
    Label144: TLabel;
    DBEdit129: TDBEdit;
    DBEdit132: TDBEdit;
    DBEdit133: TDBEdit;
    DBEdit134: TDBEdit;
    DBEdit138: TDBEdit;
    Label139: TLabel;
    Label146: TLabel;
    DBLookupComboBox3: TDBLookupComboBox;
    Label150: TLabel;
    Panel47: TPanel;
    Panel60: TPanel;
    DBGrid25: TDBGrid;
    Panel61: TPanel;
    Label145: TLabel;
    Panel63: TPanel;
    Panel62: TPanel;
    Label152: TLabel;
    DBGrid26: TDBGrid;
    PGrupos: TPanel;
    Panel53: TPanel;
    DBGrid23: TDBGrid;
    Panel54: TPanel;
    Label104: TLabel;
    todosgrupos: TCheckBox;
    tbuscargrupo: TEdit;
    Panel55: TPanel;
    Panel56: TPanel;
    PageControl8: TPageControl;
    TabSheet15: TTabSheet;
    Panel64: TPanel;
    Label105: TLabel;
    btgcancelar: TButton;
    btgmodificar: TButton;
    btGborrar: TButton;
    btGnuevo: TButton;
    btgguardar: TButton;
    btgsalir: TButton;
    Panel65: TPanel;
    pgruposdatos: TPanel;
    Label106: TLabel;
    Label118: TLabel;
    Label119: TLabel;
    Label120: TLabel;
    Label121: TLabel;
    Label122: TLabel;
    Label123: TLabel;
    DBEdit87: TDBEdit;
    DBEdit88: TDBEdit;
    DBEdit90: TDBEdit;
    DBRadioGroup3: TDBRadioGroup;
    DBEdit91: TDBEdit;
    DBEdit92: TDBEdit;
    DBEdit94: TDBEdit;
    Label66: TLabel;
    DBEdit56: TDBEdit;
    DBLookupComboBox2: TDBLookupComboBox;
    Label67: TLabel;
    DBLookupComboBox4: TDBLookupComboBox;
    Label68: TLabel;
    DBEdit57: TDBEdit;
    Label69: TLabel;
    DBEdit58: TDBEdit;
    listadatos: TCheckListBox;
    listabuscar: TCheckListBox;
    Label70: TLabel;
    DBEdit59: TDBEdit;
    Label71: TLabel;
    DBEdit60: TDBEdit;
    Label72: TLabel;
    DBEdit61: TDBEdit;
    Label78: TLabel;
    DBEdit66: TDBEdit;
    Label81: TLabel;
    DBEdit68: TDBEdit;
    Label124: TLabel;
    DBEdit93: TDBEdit;
    Label125: TLabel;
    DBEdit111: TDBEdit;
    Label126: TLabel;
    DBEdit112: TDBEdit;
    Label127: TLabel;
    DBEdit113: TDBEdit;
    Label128: TLabel;
    DBEdit114: TDBEdit;
    TabSheet6: TTabSheet;
    DBGrid27: TDBGrid;
    listadatos2: TCheckListBox;
    DBGrid24: TDBGrid;
    Label85: TLabel;
    DBEdit89: TDBEdit;
    Precibos: TPanel;
    Panel12: TPanel;
    Panel27: TPanel;
    Label129: TLabel;
    todosclientesrecibos: TCheckBox;
    tbuscarclientesrecibos: TEdit;
    DBGrid10: TDBGrid;
    Panel28: TPanel;
    Panel31: TPanel;
    precibosdatos: TPanel;
    Label130: TLabel;
    Label131: TLabel;
    Label132: TLabel;
    Label153: TLabel;
    Label154: TLabel;
    Label166: TLabel;
    DBEdit115: TDBEdit;
    DBEdit119: TDBEdit;
    DBEdit145: TDBEdit;
    Panel67: TPanel;
    Panel68: TPanel;
    Label171: TLabel;
    btrcancelar: TButton;
    btrmodificar: TButton;
    btrborrar: TButton;
    btRnuevo: TButton;
    btrguardar: TButton;
    btrsalir: TButton;
    DBGrid28: TDBGrid;
    Panel34: TPanel;
    DBGrid11: TDBGrid;
    Panel35: TPanel;
    Label169: TLabel;
    Panel33: TPanel;
    Panel66: TPanel;
    Label170: TLabel;
    DBGrid12: TDBGrid;
    Panel52: TPanel;
    RadioGroup1: TRadioGroup;
    Sdelcliente: TRadioButton;
    SSincobrar: TRadioButton;
    Sdomiciliados: TRadioButton;
    Label155: TLabel;
    DBEdit120: TDBEdit;
    DBLookupComboBox5: TDBLookupComboBox;
    DBLookupComboBox6: TDBLookupComboBox;
    DBLookupComboBox7: TDBLookupComboBox;
    Label156: TLabel;
    DBEdit116: TDBEdit;
    DBEdit117: TDBEdit;
    Label157: TLabel;
    DBEdit118: TDBEdit;
    Label158: TLabel;
    DBLookupComboBox8: TDBLookupComboBox;
    Label159: TLabel;
    Label160: TLabel;
    DBEdit121: TDBEdit;
    DBCheckBox1: TDBCheckBox;
    DBCheckBox2: TDBCheckBox;
    chkpagado: TDBCheckBox;
    Button1: TButton;
    Button2: TButton;
    Label162: TLabel;
    DBEdit122: TDBEdit;
    informe: TfrxReport;
    informedb: TfrxDBDataset;
    frxPDFExport1: TfrxPDFExport;
    Button3: TButton;
    edconcepto: TEdit;
    Label163: TLabel;
    edfecha: TMaskEdit;
    Label164: TLabel;
    qgrupos: TZReadOnlyQuery;
    qgruposid: TIntegerField;
    qgruposide: TIntegerField;
    qgruposidcurso: TIntegerField;
    qgruposnombre: TWideStringField;
    qgrupospreciomensual: TFloatField;
    qalumnos: TZReadOnlyQuery;
    qalumnoside: TIntegerField;
    qalumnosida: TIntegerField;
    qalumnosdescuento: TFloatField;
    qalumnosidc: TIntegerField;
    qclientes: TZReadOnlyQuery;
    qclienteside: TIntegerField;
    qclientesid: TIntegerField;
    qclientesidfp: TIntegerField;
    qaux: TZReadOnlyQuery;
    edimporte: TEdit;
    Label165: TLabel;
    qauxdomiciliado: TIntegerField;
    dsqgrupos: TDataSource;
    qgrupos2id: TIntegerField;
    qgrupos2ide: TIntegerField;
    qgrupos2idcurso: TIntegerField;
    qgrupos2idaula: TIntegerField;
    qgrupos2curso: TWideStringField;
    qgrupos2nombre: TWideStringField;
    qgrupos2fechainicio: TDateField;
    qgrupos2fechafin: TDateField;
    qgrupos2preciototal: TFloatField;
    qgrupos2preciomensual: TFloatField;
    qgrupos2num_dias: TIntegerField;
    qgrupos2dias: TWideStringField;
    qgrupos2horainicio: TTimeField;
    qgrupos2horafin: TTimeField;
    qgrupos2horassemanales: TIntegerField;
    qgrupos2masdias: TWideStringField;
    qgrupos2horainicio2: TTimeField;
    qgrupos2horafin2: TTimeField;
    qgrupos2plazas: TIntegerField;
    qgrupos2activo: TIntegerField;
    qgrupos2fechabaja: TDateField;
    qgrupos2motivobaja: TWideStringField;
    qgrupos2documentacion: TBlobField;
    qgrupos2plazas_ocupadas: TIntegerField;
    qgrupos2plazas_libres: TIntegerField;
    qgrupos2aula: TWideStringField;
    qgrupos2profesor: TWideStringField;
    qgrupos2: TZReadOnlyQuery;
    Label168: TLabel;
    DBEdit123: TDBEdit;
    DBLookupComboBox9: TDBLookupComboBox;
    DBRadioGroup6: TDBRadioGroup;
    btimprimir: TButton;
    Empleados2: TMenuItem;
    Partesdeasistencia1: TMenuItem;
    Sesiones1: TMenuItem;
    DatosGenerales4: TMenuItem;
    Estadisticas1: TMenuItem;
    Button4: TButton;
    btestadisticas: TButton;
    dsfaltas: TDataSource;
    qaux2: TZReadOnlyQuery;
    btverdatos: TButton;
    sesionimagen: TImage;
    DBNavigator3: TDBNavigator;
    qimagen: TZReadOnlyQuery;
    qimagenid: TIntegerField;
    qimagenide: TIntegerField;
    qimagenidalumno: TIntegerField;
    qimagenidempleado: TIntegerField;
    qimagenidlibro: TWideStringField;
    qimagenimagen: TBlobField;
    qimagentipo: TWideStringField;
    qimagenarchivo: TWideStringField;
    dsqimagen: TDataSource;
    Label88: TLabel;
    Button5: TButton;
    MenuBoletines: TPopupMenu;
    MenuItem3: TMenuItem;
    N2Evaluacin1: TMenuItem;
    YoungLearners2: TMenuItem;
    Normal1: TMenuItem;
    YoungLearners1: TMenuItem;
    Normal2: TMenuItem;
    DBMemo4: TDBMemo;
    btAactualizar: TButton;
    btCactualizar: TButton;
    btCractualizar: TButton;
    Button9: TButton;
    btGactualizar: TButton;
    btRactualizar: TButton;
    Button12: TButton;
    DBMemo5: TDBMemo;
    Label172: TLabel;
    DBEdit85: TDBEdit;
    DBEdit109: TDBEdit;
    DBEdit124: TDBEdit;
    DBEdit140: TDBEdit;
    DBEdit141: TDBEdit;
    DBEdit142: TDBEdit;
    ExportardatosdeAlumnos1: TMenuItem;
    SaveDialog1: TSaveDialog;
    Label173: TLabel;
    DBMemo6: TDBMemo;
    DBMemo7: TDBMemo;
    Label175: TLabel;
    DBText1: TDBText;
    DBText2: TDBText;
    Label176: TLabel;
    DBText3: TDBText;
    Label177: TLabel;
    DBText4: TDBText;
    Label178: TLabel;
    Label179: TLabel;
    Button6: TButton;
    RadioButton1: TRadioButton;
    Panel32: TPanel;
    Button7: TButton;
    edmaterial: TCheckBox;
    qgrupoalumnoscorreo_alumno: TWideStringField;
    todosempgrupos: TCheckBox;
    XMLDocument1: TXMLDocument;
    qcursos2: TZReadOnlyQuery;
    dsqcursos2: TDataSource;
    qcursos2id: TIntegerField;
    qcursos2ide: TIntegerField;
    qcursos2nombre: TWideStringField;
    qcursos2fechainicio: TDateField;
    qcursos2fechafin: TDateField;
    qcursos2precio_material: TFloatField;
    qcursos2activo: TIntegerField;
    qcursos2precio_curso: TFloatField;
    qcursos2precio_mes: TFloatField;
    qcursos2anyo_escolar: TWideStringField;
    DBLookupComboBox10: TDBLookupComboBox;
    Label180: TLabel;
    DBEdit84: TDBEdit;
    DBEdit110: TDBEdit;
    DBEdit143: TDBEdit;
    DBEdit144: TDBEdit;
    DBEdit146: TDBEdit;
    DBEdit147: TDBEdit;
    Listadodealumnosquepromocionan1: TMenuItem;
    DBMemo8: TDBMemo;
    Label181: TLabel;
    Label182: TLabel;
    DBMemo9: TDBMemo;
    chktodos: TCheckBox;
    cursos2: TMenuItem;
    Planesdeestudios1: TMenuItem;
    dsqalumnos: TDataSource;
    dsalumnos: TDataSource;
    Label167: TLabel;
    GRIDTODOSALUMNOS: TDBGrid;
    documentacion: TTabSheet;
    Panel57: TPanel;
    Panel69: TPanel;
    Label40: TLabel;
    Button8: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button19: TButton;
    Panel70: TPanel;
    DBGrid2: TDBGrid;
    Memo2: TMemo;
    Button10: TButton;
    OpenDialog2: TOpenDialog;
    Panel71: TPanel;
    Panel72: TPanel;
    Label174: TLabel;
    Button11: TButton;
    Button13: TButton;
    Button14: TButton;
    Button18: TButton;
    Button23: TButton;
    Panel73: TPanel;
    DBGrid20: TDBGrid;
    Memo1: TMemo;
    Button24: TButton;
    Estadisticas2: TMenuItem;
    Panel74: TPanel;
    Label183: TLabel;
    DBEdit149: TDBEdit;
    combotutor: TDBLookupComboBox;
    Label184: TLabel;
    qtutores: TZReadOnlyQuery;
    dsqtutores: TDataSource;
    qtutoresid: TIntegerField;
    qtutoreside: TIntegerField;
    qtutoresnif: TWideStringField;
    qtutoresnombre: TWideStringField;
    qtutoresapellidos: TWideStringField;
    qtutoresnombre_completo: TWideStringField;
    qtutoresdireccion: TWideStringField;
    qtutorespoblacion: TWideStringField;
    qtutorescp: TWideStringField;
    qtutoresprovincia: TWideStringField;
    qtutorestelefono1: TWideStringField;
    qtutorestelefono2: TWideStringField;
    qtutoresemail: TWideStringField;
    qtutoresentidad: TWideStringField;
    qtutorescc: TWideStringField;
    qtutoressalario: TFloatField;
    qtutoresprecio_km: TFloatField;
    qtutoresprecio_hx: TFloatField;
    qtutoresactivo: TIntegerField;
    qtutoresusuario: TWideStringField;
    qtutorespassword: TWideStringField;
    qtutorestipo_acceso: TIntegerField;
    qtutoresseleccionado: TIntegerField;
    colorempleados: TColorBox;
    Label185: TLabel;
    Niveles1: TMenuItem;
    procedure todosalumnosClick(Sender: TObject);
    procedure btAlumnosClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure btAsalirClick(Sender: TObject);
    procedure Capturar1Click(Sender: TObject);
    procedure Cargar1Click(Sender: TObject);
    procedure tbuscaralumnosEnter(Sender: TObject);
    procedure btAnuevoClick(Sender: TObject);
    procedure btAguardarClick(Sender: TObject);
    procedure btAcancelarClick(Sender: TObject);
    procedure btAborrarClick(Sender: TObject);
    procedure btAmodificarClick(Sender: TObject);
    procedure DBEdit24Exit(Sender: TObject);
    procedure btAimagenClick(Sender: TObject);
    procedure btdesactivarcamaraClick(Sender: TObject);
    procedure btactivarcamaraClick(Sender: TObject);
    procedure btAokimagenClick(Sender: TObject);
    procedure tbuscaralumnosExit(Sender: TObject);
    procedure btAscancelarClick(Sender: TObject);
    procedure btAsnuevoClick(Sender: TObject);
    procedure BtAsborrarClick(Sender: TObject);
    procedure btAsmodificarClick(Sender: TObject);
    procedure tbuscarempleadosEnter(Sender: TObject);
    procedure tbuscarempleadosExit(Sender: TObject);
    procedure btEmpleadosClick(Sender: TObject);
    procedure todosempleadosClick(Sender: TObject);
    procedure btEimagenClick(Sender: TObject);
    procedure btEoKimagenClick(Sender: TObject);
    procedure btesalirClick(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure btactivarcamaraeClick(Sender: TObject);
    procedure btenuevoClick(Sender: TObject);
    procedure bteborrarClick(Sender: TObject);
    procedure btemodificarClick(Sender: TObject);
    procedure bteguardarClick(Sender: TObject);
    procedure btecancelarClick(Sender: TObject);
    procedure DBGrid5DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure todoscursosClick(Sender: TObject);
    procedure tbuscarcursosEnter(Sender: TObject);
    procedure tbuscarcursosExit(Sender: TObject);
    procedure btCursosClick(Sender: TObject);
    procedure btcnuevoClick(Sender: TObject);
    procedure btcborrarClick(Sender: TObject);
    procedure btcmodificarClick(Sender: TObject);
    procedure btcguardarClick(Sender: TObject);
    procedure btcsalirClick(Sender: TObject);
    procedure btinuevoClick(Sender: TObject);
    procedure btiborrarClick(Sender: TObject);
    procedure btimodificarClick(Sender: TObject);
    procedure btiguardarClick(Sender: TObject);
    procedure btNotascancelarClick(Sender: TObject);
    procedure btNotasModificarClick(Sender: TObject);
    procedure btNotasguardarClick(Sender: TObject);
    procedure btAsguardarClick(Sender: TObject);
    procedure DBEdit32Exit(Sender: TObject);
    procedure DBGrid3DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure btsesionesClick(Sender: TObject);
    procedure btsmodificarClick(Sender: TObject);
    procedure btsguardarClick(Sender: TObject);
    procedure DBGrid15DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DBGrid15CellClick(Column: TColumn);
    procedure Button22Click(Sender: TObject);
    procedure btsinicioClick(Sender: TObject);
    procedure btsfinClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure DBGrid5CellClick(Column: TColumn);
    procedure qgrupoalumnosCalcFields(DataSet: TDataSet);
    procedure btSnotasmodificarClick(Sender: TObject);
    procedure btSnotasguardarClick(Sender: TObject);
    procedure btSnotascancelarClick(Sender: TObject);
    procedure avisosBeforePost(DataSet: TDataSet);
    procedure btClientesClick(Sender: TObject);
    procedure btGruposClick(Sender: TObject);
    procedure btRecibosClick(Sender: TObject);
    procedure todosclientesClick(Sender: TObject);
    procedure btclcancelarClick(Sender: TObject);
    procedure btclguardarClick(Sender: TObject);
    procedure btclmodificarClick(Sender: TObject);
    procedure tbuscarclientesEnter(Sender: TObject);
    procedure tbuscarclientesExit(Sender: TObject);
    procedure btClnuevoClick(Sender: TObject);
    procedure btclborrarClick(Sender: TObject);
    procedure DBGrid25DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure btclsalirClick(Sender: TObject);
    procedure DBGrid22CellClick(Column: TColumn);
    procedure DBGrid22DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DBGrid25DblClick(Sender: TObject);
    procedure todosgruposClick(Sender: TObject);
    procedure tbuscargrupoEnter(Sender: TObject);
    procedure tbuscargrupoExit(Sender: TObject);
    procedure btGnuevoClick(Sender: TObject);
    procedure btgmodificarClick(Sender: TObject);
    procedure DBGrid27DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure listabuscarClick(Sender: TObject);
    procedure DBEdit58Enter(Sender: TObject);
    procedure listadatos2Click(Sender: TObject);
    procedure listadatosClick(Sender: TObject);
    procedure listadatosExit(Sender: TObject);
    procedure listadatos2Exit(Sender: TObject);
    procedure DBGrid24DblClick(Sender: TObject);
    procedure tbuscaralumnosChange(Sender: TObject);
    procedure tbuscarclientesChange(Sender: TObject);
    procedure tbuscarcursosChange(Sender: TObject);
    procedure tbuscargrupoChange(Sender: TObject);
    procedure DBGrid8DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure btgsalirClick(Sender: TObject);
    procedure btgcancelarClick(Sender: TObject);
    procedure btGborrarClick(Sender: TObject);
    procedure btgguardarClick(Sender: TObject);
    procedure DBGrid28CellClick(Column: TColumn);
    procedure DBGrid28DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure btRnuevoClick(Sender: TObject);
    procedure btrborrarClick(Sender: TObject);
    procedure btrmodificarClick(Sender: TObject);
    procedure btrguardarClick(Sender: TObject);
    procedure DBEdit117Enter(Sender: TObject);
    procedure DBEdit118Enter(Sender: TObject);
    procedure DBEdit119Exit(Sender: TObject);
    procedure DBEdit116Enter(Sender: TObject);
    procedure DBLookupComboBox5Exit(Sender: TObject);
    procedure SdelclienteClick(Sender: TObject);
    procedure StodosClick(Sender: TObject);
    procedure SSincobrarClick(Sender: TObject);
    procedure SdomiciliadosClick(Sender: TObject);
    procedure tbuscarclientesrecibosEnter(Sender: TObject);
    procedure tbuscarclientesrecibosExit(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure btrsalirClick(Sender: TObject);
    procedure btssalirClick(Sender: TObject);
    procedure DBEdit27Enter(Sender: TObject);
    procedure DBEdit28Enter(Sender: TObject);
    procedure bticancelarClick(Sender: TObject);
    procedure btimprimirClick(Sender: TObject);
    procedure btsborrarClick(Sender: TObject);
    procedure DBGrid26DblClick(Sender: TObject);
    procedure DBGrid22DblClick(Sender: TObject);
    procedure Grupos1Click(Sender: TObject);
    procedure Empleados1Click(Sender: TObject);
    procedure DatosGenerales2Click(Sender: TObject);
    procedure Sesiones1Click(Sender: TObject);
    procedure DatosGenerales4Click(Sender: TObject);
    procedure Recibos1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure btestadisticasClick(Sender: TObject);
    procedure qfaltasAfterPost(DataSet: TDataSet);
    procedure DBGrid17DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DBGrid17CellClick(Column: TColumn);
    procedure btverdatosClick(Sender: TObject);
    procedure DBGrid9DblClick(Sender: TObject);
    procedure DBGrid18DblClick(Sender: TObject);
    procedure dsqimagenDataChange(Sender: TObject; Field: TField);
    procedure YoungLearners1Click(Sender: TObject);
    procedure YoungLearners2Click(Sender: TObject);
    procedure btCactualizarClick(Sender: TObject);
    procedure btAactualizarClick(Sender: TObject);
    procedure Normal2Click(Sender: TObject);
    procedure Normal1Click(Sender: TObject);
    procedure btGactualizarClick(Sender: TObject);
    procedure ExportardatosdeAlumnos1Click(Sender: TObject);
    procedure Datosgenerales3Click(Sender: TObject);
    procedure btRactualizarClick(Sender: TObject);
    procedure btrcancelarClick(Sender: TObject);
    procedure DBCheckBox1Click(Sender: TObject);
    procedure dsqgrupoalumnosDataChange(Sender: TObject; Field: TField);
    procedure DBEdit66Exit(Sender: TObject);
    procedure DBEdit58Exit(Sender: TObject);
    procedure DBLookupComboBox2Exit(Sender: TObject);
    procedure DBEdit66Enter(Sender: TObject);
    procedure DBGrid23DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DBGrid28TitleClick(Column: TColumn);
    procedure Button6Click(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure DBEdit120Exit(Sender: TObject);
    procedure todosempgruposClick(Sender: TObject);
    procedure DBEdit29Exit(Sender: TObject);
    procedure DBEdit27Exit(Sender: TObject);
    procedure DBEdit28Exit(Sender: TObject);
    procedure DBEdit30Exit(Sender: TObject);
    procedure DBEdit27KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure DBEdit28KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure DBEdit29KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure DBEdit30KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Listadodealumnosquepromocionan1Click(Sender: TObject);
    procedure Datosgenerales1Click(Sender: TObject);
    procedure chktodosClick(Sender: TObject);
    procedure Facturas1Click(Sender: TObject);
    procedure cursos2Click(Sender: TObject);
    procedure Planesdeestudios1Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure dsqalumnosDataChange(Sender: TObject; Field: TField);
    procedure Button19Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Estadisticas2Click(Sender: TObject);
    procedure DBEdit120KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBEdit145KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBEdit145Exit(Sender: TObject);
    procedure DBEdit120Change(Sender: TObject);
    procedure DBEdit145Change(Sender: TObject);
    procedure DBEdit5Exit(Sender: TObject);
    procedure DBGrid24DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DBEdit30Change(Sender: TObject);
    procedure DBEdit29Change(Sender: TObject);
    procedure DBEdit28Change(Sender: TObject);
    procedure Button24Click(Sender: TObject);
    procedure Button23Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure chkpagadoClick(Sender: TObject);
    procedure Libros1Click(Sender: TObject);
    procedure Prestamos1Click(Sender: TObject);
    procedure imgfoto2DblClick(Sender: TObject);
    procedure Partesdeasistencia1Click(Sender: TObject);
    procedure Niveles1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);

  private
    { Private declarations }
    hWndC,hWndC2 : THandle;
    procedure SetResolution(Width, Height: integer);

  public
    { Public declarations }
    procedure ExportaraExcel(FileNameXLS, SheetName: String; DBGrid: TDBGrid; ProgressBarXls: TProgressBar = nil);
    procedure AppMessage(var Msg: Tmsg; var Handled:Boolean);
  end;

var
  MENU: TMENU;
  tprinter:string;
  tprinter2,filtro:string;
  nuevorecibo,recibo,cliente,centro:integer;
const
  WM_CAP_START                    = WM_USER;
  WM_CONNECT           = WM_USER + 10;
  WM_DISCONNECT        = WM_USER + 11;
  WM_SAVEDIB                  = WM_USER + 25;
  WM_GET_VIDEOFORMAT          = WM_USER + 44;
  WM_SET_VIDEOFORMAT          = WM_USER + 45;
  WM_SET_PREVIEW              = WM_USER + 50;
  WM_SET_OVERLAY              = WM_USER + 51;
  WM_SET_PREVIEWRATE          = WM_USER + 52;
  WM_SET_SCALE                = WM_USER + 53;
  rojo=$00AAAAFF;
  amarillo=$00B9FFFF;
  verde=$00C7FBAA;
  azul=$00FFFFBB;

function capCreateCaptureWindowA(lpszWindowName: PCHAR; dwStyle, x, y, nWidth, nHeight: integer; ParentWin: HWND; nId: integer): HWND; stdcall external 'AVICAP32.DLL';

implementation

{$R *.dfm}

uses ESTGRUPOS, ESTSESIONES, DATOS2, promocionan, EMPRESAS, ffacturas, fplanes,
  datosalumnos, festadisticas, frecibos_s, flibros, fprestamos,
  fpartes_asistencia, fniveles;

{procedure CambiarControl(Sender: TObject;Abajo:boolean);
var max,n,toactual,toorden:integer;
    anterior,siguiente,primero,ultimo:integer;
    toanterior,tosiguiente,toprimero,toultimo:integer;
begin

    if not(((Sender as tform).activecontrol)is tdbedit) then exit;

    toactual:=((Sender as tform).activecontrol).taborder;
    max:=(Sender as tform).componentcount;

    toanterior:=-1;
    tosiguiente:=max;
    toprimero:=max;
    toultimo:=-1;

    for n:=0 to max-1 do
       if (((Sender as tform).components[n])is tdbedit) then
         if (((((Sender as tform).components[n])as tdbedit).tabstop)
// anyado la siguiente linea porque cuando el control esta deshabilitado
// e intenta acceder me da error.
           and ((((Sender as tform).components[n])as tdbedit).enabled))
         then
         begin

             toorden:=(((Sender as tform).components[n] as twincontrol).taborder);
             if toorden>toultimo then
             begin
                 ultimo:=n;
                 toultimo:=toorden;
             end;

             if toorden<toprimero then
             begin
                 primero:=n;
                 toprimero:=toorden;
             end;

             if (toorden>toactual) and (toorden<tosiguiente) then
             begin
                 siguiente:=n;
                 tosiguiente:=toorden;
             end;

             if (toorden<toactual) and (toorden>toanterior) then
             begin
                 anterior:=n;
                 toanterior:=toorden;
             end;
         end;

         if abajo then
             if tosiguiente<max then (((Sender as tform).components[siguiente]) as TWinControl).setfocus
                               else if toprimero<max then (((Sender as tform).components[primero]) as TWinControl).setfocus;

         if not abajo then
             if toanterior>-1 then (((Sender as tform).components[anterior]) as TWinControl).setfocus
                               else if toultimo>-1 then (((Sender as tform).components[ultimo]) as TWinControl).setfocus;

end;

}
{function Tmenu.MostrarModal(ClaseVentana:TFormClass):integer;
begin
    with ClaseVentana.Create(Self) do
    try
       result:=Showmodal;
    finally
       Free;
    end;
end;   }
procedure TMENU.tbuscaralumnosChange(Sender: TObject);
BEGIN
  {
END;
var palumno:string;
    pactivo:integer;
begin
    if tbuscaralumnos.text<>'' then
    begin
        palumno:='%'+tbuscaralumnos.Text+'%';
    end else palumno:='%';
    if todosalumnos.Checked then pactivo:=1 else pactivo:=0;
    dmalumnos.qalumnos.Prepare;
    dmalumnos.qalumnos.ParamByName('PCENTRO').AsInteger:=centro;
    dmalumnos.qalumnos.ParamByName('PACTIVO').AsInteger:=pactivo;
    dmalumnos.qalumnos.ParamByName('PALUMNO').Asstring:=palumno;
    dmalumnos.qalumnos.REFRESH;}
end;

procedure TMENU.tbuscaralumnosEnter(Sender: TObject);
begin
   tbuscaralumnos.Text:='';
end;

procedure TMENU.tbuscaralumnosExit(Sender: TObject);
{begin
    if tbuscaralumnos.text<>'' then
    begin
        dm.filtro:='%'+tbuscaralumnos.Text+'%';
    end else dm.filtro:='';
    if todosalumnos.Checked then dm.vertodos:=1 else dm.vertodos:=0;
    dm.qalumnos.Close;
    dm.qalumnos.open;}
var palumno,pactivo:string;
begin
    if tbuscaralumnos.text<>'' then
    begin
        palumno:='%'+tbuscaralumnos.Text+'%';
    end else palumno:='%';
    if todosalumnos.Checked then pactivo:='%' else pactivo:='1';
    dmalumnos.qalumnos.Prepare;
    dmalumnos.qalumnos.ParamByName('PCENTRO').AsInteger:=centro;
    dmalumnos.qalumnos.ParamByName('PACTIVO').Asstring:=pactivo;
    dmalumnos.qalumnos.ParamByName('PALUMNO').Asstring:=palumno;
    dmalumnos.qalumnos.REFRESH;

end;

procedure TMENU.tbuscarclientesChange(Sender: TObject);
begin
    if tbuscarclientes.text<>'' then
    begin
        dm.filtro:='%'+tbuscarclientes.Text+'%';

    end else dm.filtro:='';
    if todosclientes.Checked then dm.vertodos:=1 else dm.vertodos:=0;
    dm.qclientes.Close;
    dm.qclientes.open;
end;

procedure TMENU.tbuscarclientesEnter(Sender: TObject);
begin
    tbuscarclientes.Text:='';
end;

procedure TMENU.tbuscarclientesExit(Sender: TObject);
begin
    if tbuscarclientes.text<>'' then
    begin
        dm.filtro:='%'+tbuscarclientes.Text+'%';
        if todosclientes.Checked then dm.vertodos:=1 else dm.vertodos:=0;
        dm.qclientes.Close;
        dm.qclientes.open;
    end;
end;

procedure TMENU.tbuscarcursosChange(Sender: TObject);
begin
    if tbuscarcursos.text<>'' then
    begin
        dm.filtro:='%'+tbuscarcursos.Text+'%';
    end else
    begin
        dm.filtro:='';
    end;
    if todoscursos.Checked then dm.vertodos:=1 else dm.vertodos:=0;
    dm.qcursos.Close;
    dm.qcursos.open;

end;

procedure TMENU.tbuscarcursosEnter(Sender: TObject);
begin
   tbuscarcursos.Text:='';
end;

procedure TMENU.tbuscarcursosExit(Sender: TObject);
begin
    if tbuscarcursos.text<>'' then
    begin
        dm.filtro:='%'+tbuscarcursos.Text+'%';
        if todoscursos.Checked then dm.vertodos:=1 else dm.vertodos:=0;
        dm.qcursos.Close;
        dm.qcursos.open;
    end else
    begin
        dm.filtro:='';
        if todoscursos.Checked then dm.vertodos:=1 else dm.vertodos:=0;
        dm.qcursos.Close;
        dm.qcursos.open;
    end;

end;

procedure TMENU.tbuscarempleadosEnter(Sender: TObject);
begin
   tbuscarempleados.Text:='';
end;

procedure TMENU.tbuscarempleadosExit(Sender: TObject);
begin
    if tbuscarempleados.text<>'' then
    begin
        dm.filtro:='%'+tbuscarempleados.Text+'%';
        if todosempleados.Checked then dm.vertodos:=1 else dm.vertodos:=0;
        dm.qempleados.Close;
        dm.qempleados.open;
    end else
    begin
        dm.filtro:='';
        if todosempleados.Checked then dm.vertodos:=1 else dm.vertodos:=0;
        dm.qempleados.Close;
        dm.qempleados.open;
    end;

end;

procedure TMENU.tbuscargrupoChange(Sender: TObject);
begin
    if tbuscargrupo.text<>'' then
    begin
        dm.filtro:='%'+tbuscargrupo.Text+'%';
    end else
    begin
        dm.filtro:='';
    end;
    if todosgrupos.Checked then dm.vertodos:=1 else dm.vertodos:=0;
    dm.qgruposp.Close;
    dm.qgruposp.open;

end;

procedure TMENU.tbuscargrupoEnter(Sender: TObject);
begin
   tbuscargrupo.Text:='';
end;

procedure TMENU.tbuscargrupoExit(Sender: TObject);
begin
    if tbuscargrupo.text<>'' then
    begin
        dm.filtro:='%'+tbuscargrupo.Text+'%';
        if todosgrupos.Checked then dm.vertodos:=1 else dm.vertodos:=0;
        dm.qgruposp.Close;
        dm.qgruposp.open;
    end else
    begin
        dm.filtro:='';
        if todosgrupos.Checked then dm.vertodos:=1 else dm.vertodos:=0;
        dm.qgruposp.Close;
        dm.qgruposp.open;
    end;
end;

procedure TMENU.Timer1Timer(Sender: TObject);
begin
    dmalumnos.qfaltas.OPEN;
    try
       dmalumnos.qfaltas.Refresh;
    except
       timer1.Enabled:=false;
       showmessage('¡¡¡ LA CONEXION CON EL SERVIDOR SE HA INTERRUMPIDO, PULSE ACEPTAR PARA VOLVER A CONECTAR ¡¡¡');
       dm.dbjolly.Connected:=false;
       try
         dm.dbjolly.Connected:=true;
         dmalumnos.qfaltas.Refresh;
       finally

         timer1.Enabled:=true;
       end;
    end;
end;

procedure TMENU.todosalumnosClick(Sender: TObject);
begin
    dmalumnos.qalumnos.refresh;
end;

procedure TMENU.todosclientesClick(Sender: TObject);
begin
    if todosclientes.Checked=true then
    begin
        dm.vertodos:=1;
        dm.qclientes.Close;
        dm.qclientes.SQL.Clear;
        dm.qclientes.SQL.add('select * from clientes order by nombre_completo asc');
        dm.qclientes.Open;
    end else
    begin
        dm.vertodos:=0;
        dm.qclientes.Close;
        dm.qclientes.SQL.Clear;
        dm.qclientes.SQL.add('select * from clientes where activo=1 order by nombre_completo asc');
        dm.qclientes.Open;
    end;
end;

procedure TMENU.todoscursosClick(Sender: TObject);
begin
    if todoscursos.Checked=true then
    begin
        dm.vertodos:=1;
        dm.qcursos.Close;
        dm.qcursos.Open;
    end else
    begin
        dm.vertodos:=0;
        dm.qcursos.Close;
        dm.qcursos.Open;
    end;

end;

procedure TMENU.todosempgruposClick(Sender: TObject);
begin
    if todosempgrupos.Checked=true then
    begin
        dm.vertodosempgrupos:=0;
        dm.empleados.Close;
        dm.empleados.Open;
    end else
    begin
        dm.vertodosempgrupos:=1;
        dm.empleados.Close;
        dm.empleados.Open;
    end;

end;

procedure TMENU.todosempleadosClick(Sender: TObject);
begin
    if todosempleados.Checked=true then
    begin
        dm.vertodos:=1;
        dm.qempleados.Close;
        dm.qempleados.SQL.Clear;
        dm.qempleados.SQL.add('select * from empleados order by nombre_completo asc');
        dm.qempleados.Open;
    end else
    begin
        dm.vertodos:=0;
        dm.qempleados.Close;
        dm.qempleados.SQL.Clear;
        dm.qempleados.SQL.add('select * from empleados where activo=1 order by nombre_completo asc');
        dm.qempleados.Open;
    end;

end;

procedure TMENU.todosgruposClick(Sender: TObject);
begin
    if todosgrupos.Checked=true then
    begin
      if tbuscargrupo.text<>'' then
      begin
        dm.vertodos:=1;
        dm.filtro:='%'+tbuscargrupo.Text+'%';
        dm.qgruposp.Close;
        dm.qgruposp.Open;
      end else
         begin
          dm.vertodos:=1;
          dm.qgruposp.Close;
          dm.qgruposp.Open;
         end;
    end else
    begin
      if tbuscargrupo.text<>'' then
      begin
          dm.vertodos:=0;
          dm.filtro:='%'+tbuscargrupo.Text+'%';
          dm.qgruposp.Close;
          dm.qgruposp.Open;
      end else
      begin
          dm.vertodos:=0;
          dm.qgruposp.Close;
          dm.qgruposp.Open;
      end;

    end;

end;

procedure TMENU.YoungLearners1Click(Sender: TObject);
var nota:real;
begin
dminf.qboletin.Close;
qaux.SQL.Clear;
qaux.SQL.Add('delete from boletin');
qaux.ExecSQL;
dminf.qboletin.Open;
dm.notas.close;
dm.notas.Open;
dm.qgrupoalumnos2.first;

while not dm.qgrupoalumnos2.Eof do
begin
  dm.notas.Filtered:=false;
  dm.notas.Filter:='ida='+dm.qgrupoalumnos2id.AsString+' and ide='+inttostr(centro)+' and idg='+dm.qgruposid.AsString;
  dm.notas.Filtered:=true;
  dminf.qboletin.Append;
  dminf.qboletingrupo.Value:=dm.qgruposnombre.asstring;
  dminf.qboletinprofesor.Value:=qtutoresnombre_completo.AsString;//dm.qgruposprofesor.AsString;
  dminf.qboletinalumno.Value:=dm.qgrupoalumnos2nombre_completo.AsString;
  dminf.qboletinfechaeval1.value:=dm.notasfechaeval1.asdatetime;
  dminf.qboletinlistening1.value:=dm.notaslistening1.asfloat;
  nota:=dminf.qboletinlistening1.asfloat;
  if (nota=0) then dminf.qboletinimglist1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist1.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist1.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist1.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist1.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist1.value:='c:\formagest\documentos\5oreja.bmp';
  dminf.qboletinspeaking1.value:=dm.notasspeaking1.asfloat;
  nota:=dminf.qboletinspeaking1.asfloat;
  if (nota=0) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading1.value:=dm.notasreading1.asfloat;
  nota:=dminf.qboletinreading1.asfloat;
  if (nota=0) then dminf.qboletinimgread1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread1.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread1.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread1.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread1.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread1.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting1.value:=dm.notaswriting1.asfloat;
  nota:=dminf.qboletinwriting1.asfloat;
  if (nota=0) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary1.value:=dm.notasvocabulary1.asfloat;
  nota:=dminf.qboletinvocabulary1.asfloat;
  if (nota=0) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo1.value:=dm.notasdesarrollo1.asfloat;
  nota:=dminf.qboletindesarrollo1.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletinfechaeval2.value:=dm.notasfechaeval2.asdatetime;
  dminf.qboletinlistenig2.value:=dm.notaslistenig2.asfloat;
  nota:=dminf.qboletinlistenig2.asfloat;
  if (nota=0) then dminf.qboletinimglist2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist2.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist2.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist2.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist2.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist2.value:='c:\formagest\documentos\5oreja.bmp';

  dminf.qboletinspeaking2.value:=dm.notasspeaking2.asfloat;
  nota:=dminf.qboletinspeaking2.asfloat;
  if (nota=0) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading2.value:=dm.notasreading2.asfloat;
  nota:=dminf.qboletinreading2.asfloat;
  if (nota=0) then dminf.qboletinimgread2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread2.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread2.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread2.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread2.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread2.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting2.value:=dm.notaswriting2.asfloat;
  nota:=dminf.qboletinwriting2.asfloat;
  if (nota=0) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary2.value:=dm.notasvocabulary2.asfloat;
  nota:=dminf.qboletinvocabulary2.asfloat;
  if (nota=0) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo2.value:=dm.notasdesarrollo2.asfloat;
  nota:=dminf.qboletindesarrollo2.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletinobservaciones.value:=dm.notasobservaciones.AsString;
  dminf.qboletinnota1eval.value:=dm.notasnota1eval.Asfloat;
  dminf.qboletinnota2eval.value:=dm.notasnota2eval.Asfloat;
  dminf.qboletinnotafinal.value:=dm.notasnotafinal.Asfloat;
  dminf.qboletin.Post;
  dm.qgrupoalumnos2.Next;
end;
   dm.notas.Filtered:=false;

    dminf.qboletin.Open;
    informedb.Datasource:=dminf.dsqboletin;
    informe.Report.Clear;
    informe.LoadFromFile('c:\formagest\informes\boletinyoung_1.fr3');
//    informes.Report.FileName:=TMES.Text+' ' + qjornalestrabajador.asstring;
    informe.PrintOptions.Printer:=tprinter2;
    informe.ShowReport();
    informe.Clear;



end;

procedure TMENU.avisosBeforePost(DataSet: TDataSet);
begin
    avisoscomentario.Value:=dm.qalumnosnombre_completo.asstring+' '+avisoscomentario.AsString;
end;

procedure TMENU.btAborrarClick(Sender: TObject);
begin
    dmalumnos.alumnos.Delete;
    dmalumnos.alumnos.Refresh;
end;

procedure TMENU.btAcancelarClick(Sender: TObject);
begin
    dmalumnos.alumnos.cancel;
    dmalumnos.alumnos.MasterSource:=dmalumnos.dsqalumnos;
    palumnosdatos.Enabled:=false;
    PAImagenes.Visible:=true;

end;

procedure TMENU.btAguardarClick(Sender: TObject);
begin
    if not dmalumnos.qalumnos.active then dmalumnos.qalumnos.open;

    dmalumnos.alumnos.Post;
    dmalumnos.alumnos.Filtered:=false;
    dmalumnos.alumnos.Filter:='';
    dmalumnos.alumnos.Filtered:=true;
    dmalumnos.alumnos.Refresh;
    pestudiosalumno.visible:=false;
    palumnosdatos.Enabled:=false;
    PAImagenes.Visible:=true;
end;

procedure TMENU.btAimagenClick(Sender: TObject);
var
  PanelDC: HDC;
  Jpg : TJPEGImage;
  bmp : Tbitmap;
  imagen : TPicture;
  ext:string;
//  imagen : TJPEGImage;

begin
{
if (Sender as TButton).Caption ='Seleccione opción' then
begin
  btaimagen.Dragging; //('MenubtAimangen');
end;
if (Sender as TButton).Caption ='Cargar imagen' then
begin

if (Sender as TButton).Caption ='Cargar imagen' then
begin  }
  if OpenPictureDialog1.Execute then
  begin
//    imagen := TJPEGImage.Create;
    imagen := TPicture.Create;
    bmp:= TBitmap.Create;
    jpg:=TJPEGImage.Create;

    try

      ext:= ExtractFileExt(openpicturedialog1.FileName);
      if (ext='.jpg') or (ext='jpeg') then
      begin
        imgfoto.Picture.LoadFromFile(OpenPictureDialog1.FileName);//'c:\formagest\imagenes\'+dm.alumnosid.asstring+'.bmp');
        btAokimagen.Visible:=true;
      end else
      begin
          imgfoto.Picture.LoadFromFile(OpenPictureDialog1.FileName);//'c:\formagest\imagenes\'+dm.alumnosid.asstring+'.bmp');
          btAokimagen.Visible:=true;
      end;
      imgfoto.Visible:=true;
    finally
      imagen.Free;
    end;
  end;
end;
{if (Sender as TButton).Caption ='Capturar imagen' then
begin
    if not Assigned(imgfoto.Picture.Bitmap) then
    begin
        imgfoto.Picture.Bitmap := TBitmap.Create;
    end
      else
      begin
        imgfoto.Picture.Bitmap.Free;
        imgfoto.picture.Bitmap := TBitmap.Create;
//        imgfoto.Stretch:=true;
      end;
      imgfoto.Height:=120;
      imgfoto.Width:=120;
      imgfoto.Picture.Bitmap.Height := 120;
      imgfoto.Picture.Bitmap.Width  := 120;
      PanelDC := GetDC(Panelfoto.Handle);
      try
        BitBlt(imgfoto.Picture.Bitmap.Canvas.Handle,
          0,0,Panelfoto.Width, Panelfoto.Height, PanelDC, 0,0, SRCCOPY);
      imgfoto.Picture.Bitmap.SaveToFile('c:\formagest\imagenes\'+dm.alumnosid.asstring+'.bmp');

      finally

        ReleaseDC(Handle, PanelDC);
        btAokimagen.Visible:=true;

      end;
end;

end;}

procedure TMENU.btAmodificarClick(Sender: TObject);
begin
    dmalumnos.alumnos.Edit;
    palumnosdatos.Enabled:=true;
    PAImagenes.Visible:=false;
    dbedit2.SetFocus;
end;

procedure TMENU.btAnuevoClick(Sender: TObject);
begin
    dmalumnos.alumnos.MasterSource:=nil;
    dmalumnos.alumnos.Append;
    dmalumnos.alumnoside.value:=centro;
    palumnosdatos.Enabled:=true;
    pAimagenes.visible:=false;
    dbedit2.SetFocus;

end;

procedure TMENU.btAsalirClick(Sender: TObject);
begin
//   dm.dbjolly.Connected:=false;
   palumnos.Visible:=false;
   pprincipal.Visible:=true;
end;

procedure TMENU.BtAsborrarClick(Sender: TObject);
begin
    dmalumnos.asistir.Prepare;
    dmalumnos.asistir.ParamByName('PID').AsInteger:=dmalumnos.qasistiralumnoid.AsInteger;
    if not dmalumnos.asistir.Active then dmalumnos.asistir.Open else   dmalumnos.asistir.Refresh;;
    dmalumnos.asistir.Delete;
//    dmalumnos.qasistiralumno.Refresh;
end;

procedure TMENU.btAscancelarClick(Sender: TObject);
begin
    dmalumnos.asistir.cancel;
//    dmalumnos.asistir.MasterSource:=dmalumnos.dsqasistiralumno;
    pestudiosalumno.visible:=false;
    palumnosdatos.Enabled:=false;

end;

procedure TMENU.btAsguardarClick(Sender: TObject);
begin
    dmalumnos.asistir.Post;
//    dmalumnos.asistir.MasterSource:=dmalumnos.dsqasistiralumno;
//    dmalumnos.asistir.Refresh;
    dmalumnos.qasistiralumno.Refresh;
    dmalumnos.notas.Refresh;
    pestudiosalumno.visible:=false;
    pestudiosalumno.Enabled:=false;
end;

procedure TMENU.btAsmodificarClick(Sender: TObject);
begin
    dmalumnos.asistir.Prepare;
    dmalumnos.asistir.ParamByName('PID').AsInteger:=dmalumnos.qasistiralumnoid.AsInteger;
    if not dmalumnos.asistir.Active then dmalumnos.asistir.Open else  dmalumnos.asistir.Refresh;;
    if not dmalumnos.qgrupos.Active then dmalumnos.qgrupos.Open;
    dmalumnos.asistir.Edit;
    pestudiosalumno.visible:=true;
    pestudiosalumno.Enabled:=true;
    comboasistirgrupos.SetFocus;

end;

procedure TMENU.btAsnuevoClick(Sender: TObject);
begin
    dmalumnos.qgrupos.Open;
    dmalumnos.asistir.Open;
    pestudiosalumno.visible:=true;
    pestudiosalumno.Enabled:=true;
    dmalumnos.asistir.Append;
    dmalumnos.asistiride.value:=centro;
    dmalumnos.asistirida.Value:=dmalumnos.alumnosid.AsInteger;

//    comboasistirgrupos.DataSource:=dsqgrupos;
    comboasistirgrupos.SetFocus;

end;

procedure TMENU.btcborrarClick(Sender: TObject);
begin
   dm.cursos.Delete;
end;

procedure TMENU.btcguardarClick(Sender: TObject);
begin
    if not dm.qcursos.active then dm.qcursos.open;
    dm.cursos.Post;
    pcursosdatos.Enabled:=false;
end;

procedure TMENU.btclborrarClick(Sender: TObject);
begin
   dm.clientes.Delete;
   dm.qclientes.Refresh;
end;

procedure TMENU.btclcancelarClick(Sender: TObject);
begin
    dm.clientes.cancel;
    dm.clientes.MasterSource:=dm.dsqclientes;
    pclientesdatos.Enabled:=false;
end;

procedure TMENU.btclguardarClick(Sender: TObject);
var idcliente:string;
begin

    idcliente:=dm.clientesnif.Asstring;
    dm.clientes.Post;
    dm.clientes.Filtered:=false;
    dm.clientes.Filter:='';
    dm.clientes.Filtered:=true;
    dm.clientes.MasterSource:=dm.dsqclientes;
    dm.clientes.close;
    dm.clientes.Open;
    dm.qclientes.close;
    dm.qclientes.Open;
    pclientesdatos.Enabled:=false;
    dm.qclientes.Locate('nif',idcliente,[locaseinsensitive,lopartialkey]);
end;

procedure TMENU.btclmodificarClick(Sender: TObject);
begin
    dm.clientes.Edit;
    pclientesdatos.Enabled:=true;
    dbedit138.SetFocus;
end;

procedure TMENU.btClnuevoClick(Sender: TObject);
begin
    dm.clientes.MasterSource:=nil;
    dm.clientes.Append;
    dm.clienteside.value:=centro;
    pclientesdatos.Enabled:=true;
    dbedit138.SetFocus;
end;

procedure TMENU.btcmodificarClick(Sender: TObject);
begin
    dm.cursos.Edit;
    pcursosdatos.Enabled:=true;
    dbedit64.SetFocus;
end;

procedure TMENU.btcnuevoClick(Sender: TObject);
begin
    dm.cursos.MasterSource:=nil;
    dm.cursos.Append;
    dm.cursoside.value:=centro;
    pcursosdatos.Enabled:=true;
    dbedit64.SetFocus;
end;

procedure TMENU.btcsalirClick(Sender: TObject);
begin
//   dm.dbjolly.Connected:=false;
   pcursos.Visible:=false;
   pprincipal.Visible:=true;

end;

procedure TMENU.btinuevoClick(Sender: TObject);
begin
    dm.qgruposp.close;
    dm.qgruposp.open;
    if not dm.impartir.Active then dm.impartir.Open;
    dm.impartir.MasterSource:=nil;
    dm.impartir.Append;
    dm.impartiridp.Value:=dm.qempleadosid.asinteger;
    dm.impartiride.value:=centro;
    pgruposempleados.Visible:=true;
    pgruposempleados.Enabled:=true;
    comboimpartirgrupos.SetFocus;
end;

procedure TMENU.btiguardarClick(Sender: TObject);
begin
//    if not dm.qempleados.active then dm.qempleados.open;
    if dm.impartir.state in [dsinsert] then
    begin
        dm.impartiridg.Value:=dm.qgrupospid.AsInteger;
        dm.impartir.Post;
    end else
    begin
        dm.impartiridg.Value:=dm.qgrupospid.AsInteger;
        dm.impartirfechainicio.Value:=dm.qgrupospfechainicio.AsDateTime;
        dm.impartirfechafin.Value:=dm.qgrupospfechafin.AsDateTime;
        dm.impartir.Post;
    end;
//    dm.grupos.open;
//    dm.grupos.Filtered:=false;
//    dm.grupos.Filter:='';
//    dm.grupos.Filtered:=true;
//    dm.grupos.Refresh;
//    dm.qimpartirgrupo.Refresh;
    pgruposempleados.Visible:=false;
    pgruposempleados.Enabled:=false;
end;

procedure TMENU.btrsalirClick(Sender: TObject);
begin
//   dm.dbjolly.Connected:=false;
   precibos.Visible:=false;
   pprincipal.Visible:=true;
end;

procedure TMENU.btGactualizarClick(Sender: TObject);
var grupo:string;
begin
   grupo:=dm.qgrupospid.asstring;
   dm.qgruposp.Refresh;
   dm.qgrupoalumnos2.Refresh;
   dm.qgruposp.locate('id',grupo,[locaseinsensitive,lopartialkey]);
end;

procedure TMENU.btRactualizarClick(Sender: TObject);
begin
   dm.qreciboscliente.open;
   dm.qreciboscliente.Locate('id',recibo,[locaseinsensitive,lopartialkey]);
   dm.qclientes.Locate('id',cliente,[locaseinsensitive,lopartialkey]);

 end;

procedure TMENU.Button10Click(Sender: TObject);
var  archivo:string;
begin

//    savedialog1.FileName:=archivo;
//    savedialog1.Execute();
//    archivo:=savedialog1.FileName;
//    dm.doc_tmparchivo.SaveToFile(archivo);
  //  borrarficheros('c:\agrigest\tmp\');

    archivo:=dmalumnos.qdocumentosalnomarchivo.AsString;
    deletefile('c:\formagest\tmp\*.*');
    dmalumnos.qdocumentosalarchivo.SaveToFile('c:\formagest\tmp\'+archivo);
    ShellExecute(Handle,nil,PChar('c:\formagest\tmp\'+archivo),'','',SW_SHOWNORMAL);
end;

procedure TMENU.Button11Click(Sender: TObject);
begin
  dmalumnos.qdocumentosemp.Delete;
end;

procedure TMENU.Button13Click(Sender: TObject);
var ext,nomarchivo:string;
    ruta:widestring;
    origen,destino:pwidechar;
    x:integer;
begin
  if opendialog2.Execute then
  begin
    try
    finally
       if opendialog2.Files.Count=1 then
       begin
          qaux.SQL.Clear;
          qaux.SQL.Add('delete from documentos_tmp ');
          qaux.ExecSQL;
          ext:= ExtractFileExt(opendialog2.FileName);
          nomarchivo:= extractfilename(opendialog2.FileName);
          ruta:=extractfilepath(opendialog2.FileName)+nomarchivo;
          origen:=pwidechar(ruta);
          ruta:='c:\formagest\tmp\'+nomarchivo;
          destino:=pwidechar(ruta);
          CopyFileEx(origen,destino, nil, nil, nil, 0);
          dm.documentos_tmp.Open;
          dm.documentos_tmp.Append;
          dm.documentos_tmpidp.Value:=dm.empleadosid.AsInteger;
          dm.documentos_tmpfecha.Value:=date();
          dm.documentos_tmpide.Value:=dm.empleadoside.AsInteger;
          dm.documentos_tmpnomarchivo.Value:=nomarchivo;
          dm.documentos_tmpdescripcion.Value:=nomarchivo;
          dm.documentos_tmpextension.Value:=ext;
          dm.documentos_tmparchivo.LoadFromFile('c:\formagest\tmp\'+nomarchivo);
          dm.documentos_tmp.Post;
          qaux.SQL.Clear;
          qaux.SQL.Add('insert into documentos (ide,fecha,descripcion,archivo,nomarchivo,extension,ida,idc,idp,idplan,idcurso) (select ide,fecha,descripcion,archivo,nomarchivo,extension,ida,idc,idp,idplan,idcurso from documentos_tmp)');
          qaux.ExecSQL;
          qaux.SQL.Clear;
          qaux.SQL.Add('delete from documentos_tmp ');
          qaux.ExecSQL;
          dm.documentos.Close;
          dm.documentos.Prepare;
          dm.documentos.ParamByName('PALUMNO').Asstring:='%';
          dm.documentos.ParamByName('PEMPRESA').AsInteger:=dm.empleadoside.AsInteger;
          dm.documentos.ParamByName('PCLIENTE').Asstring:='%';
          dm.documentos.ParamByName('PPROFESOR').Asstring:=dm.empleadosid.Asstring;
          dm.documentos.ParamByName('PPLAN').Asstring:='%';
          dm.documentos.ParamByName('PCURSO').Asstring:='%';
          dm.documentos.open;
          dmalumnos.qdocumentosemp.Prepare;
          dmalumnos.qdocumentosemp.refresh;
          panel37.Visible:=true;
       end else
       begin
          memo2.Clear;
          memo2.Lines.AddStrings(opendialog2.files);
          for x := 0 to opendialog2.Files.Count-1 do
            begin
                qaux.SQL.Clear;
                qaux.SQL.Add('delete from documentos_tmp ');
                qaux.ExecSQL;
                dm.documentos_tmp.Open;
                dm.documentos_tmp.Append;
                ext:= ExtractFileExt(memo2.Lines[x]);
                nomarchivo:= extractfilename(memo2.Lines[x]);
                ruta:=extractfilepath(opendialog2.FileName)+nomarchivo;
                origen:=pwidechar(ruta);
                ruta:='c:\formagest\tmp\'+nomarchivo;
                destino:=pwidechar(ruta);
                CopyFileEx(origen,destino, nil, nil, nil, 0);
                dm.documentos_tmpidp.Value:=dm.empleadosid.Asinteger;
                dm.documentos_tmpfecha.Value:=date();
                dm.documentos_tmpide.Value:=dm.empleadoside.AsInteger;
                dm.documentos_tmpnomarchivo.Value:=nomarchivo;
                dm.documentos_tmpdescripcion.Value:=nomarchivo;
                dm.documentos_tmpextension.Value:=ext;
                dm.documentos_tmparchivo.LoadFromFile('c:\formagest\tmp\'+nomarchivo);
                dm.documentos_tmp.Post;
                qaux.SQL.Clear;
                qaux.SQL.Add('insert into documentos (ide,fecha,descripcion,archivo,nomarchivo,extension,ida,idc,idp,idplan,idcurso) (select ide,fecha,descripcion,archivo,nomarchivo,extension,ida,idc,idp,idplan,idcurso from documentos_tmp)');
                qaux.ExecSQL;
                qaux.SQL.Clear;
                qaux.SQL.Add('delete from documentos_tmp ');
                qaux.ExecSQL;
                dm.documentos.Close;
                dm.documentos.Prepare;
                dm.documentos.ParamByName('PALUMNO').Asstring:='%';
                dm.documentos.ParamByName('PEMPRESA').AsInteger:=dm.empleadoside.AsInteger;
                dm.documentos.ParamByName('PCLIENTE').Asstring:='%';
                dm.documentos.ParamByName('PPROFESOR').Asstring:=dm.empleadosid.Asstring;                dm.documentos.ParamByName('PPLAN').Asstring:='%';
                dm.documentos.ParamByName('PCURSO').Asstring:='%';
                dm.documentos.open;
                dmalumnos.qdocumentosemp.Prepare;
                dmalumnos.qdocumentosemp.refresh;
                panel37.Visible:=true;
            end;
       end;
    end;
  end;
//  principal.borrarficheros ('c:\agrigest\tmp\');

end;

procedure TMENU.Button14Click(Sender: TObject);
begin
  dmalumnos.qdocumentosal.Post;
end;

procedure TMENU.Button15Click(Sender: TObject);
var ext,nomarchivo:string;
    ruta:widestring;
    origen,destino:pwidechar;
    x:integer;
begin
  if opendialog2.Execute then
  begin
    try
    finally
       if opendialog2.Files.Count=1 then
       begin
          qaux.SQL.Clear;
          qaux.SQL.Add('delete from documentos_tmp ');
          qaux.ExecSQL;
          ext:= ExtractFileExt(opendialog2.FileName);
          nomarchivo:= extractfilename(opendialog2.FileName);
          ruta:=extractfilepath(opendialog2.FileName)+nomarchivo;
          origen:=pwidechar(ruta);
          ruta:='c:\formagest\tmp\'+nomarchivo;
          destino:=pwidechar(ruta);
          CopyFileEx(origen,destino, nil, nil, nil, 0);
          dm.documentos_tmp.Open;
          dm.documentos_tmp.Append;
          dm.documentos_tmpida.Value:=dmalumnos.alumnosid.AsInteger;
          dm.documentos_tmpfecha.Value:=date();
          dm.documentos_tmpide.Value:=dmalumnos.alumnoside.AsInteger;
          dm.documentos_tmpnomarchivo.Value:=nomarchivo;
          dm.documentos_tmpdescripcion.Value:=nomarchivo;
          dm.documentos_tmpextension.Value:=ext;
          dm.documentos_tmparchivo.LoadFromFile('c:\formagest\tmp\'+nomarchivo);
          dm.documentos_tmp.Post;
          qaux.SQL.Clear;
          qaux.SQL.Add('insert into documentos (ide,fecha,descripcion,archivo,nomarchivo,extension,ida,idc,idp,idplan,idcurso) (select ide,fecha,descripcion,archivo,nomarchivo,extension,ida,idc,idp,idplan,idcurso from documentos_tmp)');
          qaux.ExecSQL;
          qaux.SQL.Clear;
          qaux.SQL.Add('delete from documentos_tmp ');
          qaux.ExecSQL;
          dmalumnos.qdocumentosal.Prepare;
          dmalumnos.qdocumentosal.refresh;
          panel37.Visible:=true;
       end else
       begin
          memo2.Clear;
          memo2.Lines.AddStrings(opendialog2.files);
          for x := 0 to opendialog2.Files.Count-1 do
            begin
                qaux.SQL.Clear;
                qaux.SQL.Add('delete from documentos_tmp ');
                qaux.ExecSQL;
                dm.documentos_tmp.Open;
                dm.documentos_tmp.Append;
                ext:= ExtractFileExt(memo2.Lines[x]);
                nomarchivo:= extractfilename(memo2.Lines[x]);
                ruta:=extractfilepath(opendialog2.FileName)+nomarchivo;
                origen:=pwidechar(ruta);
                ruta:='c:\formagest\tmp\'+nomarchivo;
                destino:=pwidechar(ruta);
                CopyFileEx(origen,destino, nil, nil, nil, 0);
                dm.documentos_tmpida.Value:=qempleadosid.Asinteger;
                dm.documentos_tmpfecha.Value:=date();
                dm.documentos_tmpide.Value:=qempleadoside.AsInteger;
                dm.documentos_tmpnomarchivo.Value:=nomarchivo;
                dm.documentos_tmpdescripcion.Value:=nomarchivo;
                dm.documentos_tmpextension.Value:=ext;
                dm.documentos_tmparchivo.LoadFromFile('c:\formagest\tmp\'+nomarchivo);
                dm.documentos_tmp.Post;
                qaux.SQL.Clear;
                qaux.SQL.Add('insert into documentos (ide,fecha,descripcion,archivo,nomarchivo,extension,ida,idc,idp,idplan,idcurso) (select ide,fecha,descripcion,archivo,nomarchivo,extension,ida,idc,idp,idplan,idcurso from documentos_tmp)');
                qaux.ExecSQL;
                qaux.SQL.Clear;
                qaux.SQL.Add('delete from documentos_tmp ');
                qaux.ExecSQL;
                dm.documentos.Close;
                dm.documentos.Prepare;
                dm.documentos.ParamByName('PALUMNO').Asstring:=dmalumnos.alumnosid.Asstring;
                dm.documentos.ParamByName('PEMPRESA').AsInteger:=dmalumnos.alumnoside.AsInteger;
                dm.documentos.ParamByName('PCLIENTE').Asstring:='%';
                dm.documentos.ParamByName('PPROFESOR').Asstring:='%';
                dm.documentos.ParamByName('PPLAN').Asstring:='%';
                dm.documentos.ParamByName('PCURSO').Asstring:='%';
                dm.documentos.open;
                dmalumnos.qdocumentosal.Prepare;
                dmalumnos.qdocumentosal.refresh;
                panel37.Visible:=true;
            end;
       end;
    end;
  end;
//  principal.borrarficheros ('c:\agrigest\tmp\');
end;

procedure TMENU.Button16Click(Sender: TObject);
begin
  dmalumnos.qdocumentosal.Post;
end;

procedure TMENU.Button17Click(Sender: TObject);
begin
  dmalumnos.qdocumentosal.Cancel;
end;

procedure TMENU.Button18Click(Sender: TObject);
begin
  dmalumnos.qdocumentosemp.Cancel;
end;

procedure TMENU.Button19Click(Sender: TObject);
begin
   dmalumnos.qdocumentosal.Edit;
end;

procedure TMENU.Button1Click(Sender: TObject);
var i:integer;
begin
   if dbgrid28.Selectedrows.Count>0 then
   begin
     for i := 0 to dbgrid28.Selectedrows.Count - 1 do
     begin
       if dbgrid28.DataSource=dm.dsqreciboscliente then
       begin
         dm.qreciboscliente.GotoBookmark (pointer (dbgrid28.selectedrows[i]));
         dm.recibos.Edit;
         dm.recibospagado.Value:=1;
         if dm.recibosfechacobro.AsString='' then dm.recibosfechacobro.Value:=date();
         dm.recibosentrega.Value:=dm.recibosimportefinal.AsFloat;
         dm.recibos.post;
       end;
       if dbgrid28.DataSource=dm.dsqreciboscliente2 then
       begin
         dm.qreciboscliente2.GotoBookmark (pointer (dbgrid28.selectedrows[i]));
         dm.recibos.edit;
         dm.recibospagado.Value:=1;
         if dm.recibosfechacobro.AsString='' then dm.recibosfechacobro.Value:=date();
         dm.recibosentrega.Value:=dm.recibosimportefinal.AsFloat;
         dm.recibos.post;
       end;
     end;
     dm.qreciboscliente.Refresh;
     dm.qreciboscliente2.Refresh;
   end else
         begin
           btrmodificar.Click;
           dm.recibospagado.Value:=1;
           if dm.recibosfechacobro.AsString='' then dm.recibosfechacobro.Value:=date();
           dm.recibosentrega.Value:=dm.recibosimportefinal.AsFloat;
           dbedit122.Visible:=true;
           label162.Visible:=true;
           dbedit122.SetFocus;
         end;
end;

procedure TMENU.btsfinClick(Sender: TObject);
 var ahora:tdatetime;
begin
   ahora:=now;
   dm.sesiones.Edit;
   dm.sesioneshora_fin.Value:=strtotime(timetostr(ahora));
   dm.sesiones.Post

end;

procedure TMENU.btsborrarClick(Sender: TObject);
begin
   dm.sesiones.Delete;
end;

procedure TMENU.btsesionesClick(Sender: TObject);
begin
   pprincipal.Visible:=false;
   psesiones.Visible:=true;
   psesiones.BringToFront;
   pprincipal.SendToBack;
   dm.qempleados.Open;
   dm.qimpartiractivo.Open;
   dm.sesiones.Open;
   dm.sesiones_alumnos.Open;
   qgrupoalumnos.Open;
   dm.notas.Close;
   dm.notas.MasterSource:=dsqgrupoalumnos;
   dm.notas.Open;
   qcursos2.Open;
   comboprofesores.SetFocus;
end;

procedure TMENU.btAlumnosClick(Sender: TObject);
begin
   pprincipal.Visible:=false;
   palumnos.Visible:=true;
   palumnos.BringToFront;
   pprincipal.SendToBack;
   dmalumnos.qalumnos.close;
   dmalumnos.qalumnos.Prepare;
   dmalumnos.qalumnos.ParamByName('PCENTRO').AsInteger:=centro;
   dmalumnos.qalumnos.ParamByName('PACTIVO').AsInteger:=1;
   dmalumnos.qalumnos.ParamByName('PALUMNO').Asstring:='%';
   dmalumnos.qalumnos.open;
   dmalumnos.qdocumentosal.close;
   dmalumnos.notas.close;
   dmalumnos.asistir.close;
   tbuscaralumnos.SetFocus;
   todosalumnos.checked:=true;
   todosalumnos.checked:=false;
//   dmalumnos.qniveles.Open;
end;

procedure TMENU.btsguardarClick(Sender: TObject);
var ahora: tdatetime;
    anyo,mes,dia:word;
    fecha:string;
begin
//   ahora:=now;
   dm.sesioneside.Value:=dm.qimpartiractivoide.AsInteger;
   dm.sesionesidp.Value:=dm.qempleadosid.AsInteger;
   dm.sesionesidg.Value:=dm.qimpartiractivoidg.AsInteger;
   dm.sesionesfecha.Value:=fechasesion.Date;
//   dm.sesioneshora_inicio.Value:=strtotime(timetostr(ahora));
   dm.sesiones.Post;
   dm.sesiones_alumnos.Refresh;
   psesionesdatos.Enabled:=false;
   fechasesion.Visible:=false;

end;

procedure TMENU.Button22Click(Sender: TObject);
var i:integer;
begin
  qempleados.Close;
  qempleados.SQL.Clear;
  qempleados.SQL.Add('select ide,id,usuario,password,tipo_acceso from empleados where activo=1 and usuario='+''''+edit2.text+'''');
  qempleados.Open;
  if qempleados.RecordCount=1 then
  begin
  centro:=qempleadoside.Asinteger;
  if qempleadospassword.AsString=maskedit1.text then
  begin
     if qempleadostipo_acceso.AsInteger=1 then
     begin
        pbotones.Visible:=true;
        panel43.Visible:=false;
        pavisos.Visible:=true;

        btsmodificar.Visible:=true;
        hinicio.ReadOnly:=false;
        hfin.ReadOnly:=false;
         for I := 0 to (menuprincipal.Items.Count-1) do
         begin
            menuprincipal.Items[i].Enabled:=TRUE;
         end;
     end;
     if qempleadostipo_acceso.AsInteger=0 then
     begin
        menuprincipal.Items[0].Enabled:=TRUE;
        menuprincipal.Items[0].Items[0].Enabled:=FALSE;
        menuprincipal.Items[0].Items[2].Enabled:=FALSE;
        menuprincipal.Items[0].Items[3].Enabled:=FALSE;
        menuprincipal.Items[0].Items[1].Items[1].Enabled:=TRUE;
        menuprincipal.Items[0].Items[1].Items[0].Enabled:=FALSE;
        btsesiones.Click;
        dm.qempleados.Close;
        dm.qempleados.Filter:='id='+qempleadosid.AsString;
        dm.qempleados.Filtered:=true;
        dm.qempleados.Open;
        comboprofesores.KeyValue:=qempleadosid.AsString;
        dbgrid15.Columns[4].Visible:=false;
        btsmodificar.Visible:=false;
        btestadisticas.Visible:=false;
        btsborrar.Visible:=false;
        btsguardar.Visible:=false;
        btscancelar.Visible:=false;
        hinicio.ReadOnly:=true;
        hfin.ReadOnly:=true;
//        comboprofesores.Enabled:=false;
        panel43.Visible:=false;
     end;


  end else
       begin
           showmessage('PASSWORD INCORRECTO');
           edit2.Text:='';
           maskedit1.Text:='';
           edit2.SetFocus;
       end;

  end else
       begin
           showmessage('EL USUARIO NO EXISTE');
           edit2.Text:='';
           maskedit1.Text:='';
           edit2.SetFocus;
       end;
       timer1.Enabled:=true;
end;

procedure TMENU.Button23Click(Sender: TObject);
begin
   dmalumnos.qdocumentosemp.Edit;
end;

procedure TMENU.Button24Click(Sender: TObject);
var  archivo:string;
begin

//    savedialog1.FileName:=archivo;
//    savedialog1.Execute();
//    archivo:=savedialog1.FileName;
//    dm.doc_tmparchivo.SaveToFile(archivo);
  //  borrarficheros('c:\agrigest\tmp\');

    archivo:=dmalumnos.qdocumentosempnomarchivo.AsString;
    deletefile('c:\formagest\tmp\*.*');
    dmalumnos.qdocumentosemparchivo.SaveToFile('c:\formagest\tmp\'+archivo);
    ShellExecute(Handle,nil,PChar('c:\formagest\tmp\'+archivo),'','',SW_SHOWNORMAL);
end;

procedure TMENU.btssalirClick(Sender: TObject);
begin
//   dm.dbjolly.Connected:=false;
   psesiones.Visible:=false;
   pprincipal.Visible:=true;
end;

procedure TMENU.Button2Click(Sender: TObject);
var recibo:string;
     i:integer;
begin
   if dbgrid28.Selectedrows.Count>0 then
   begin
     qaux.SQL.Clear;
     qaux.SQL.Add('update cobros set seleccionado=0 where seleccionado=1');
     qaux.ExecSQL;
     for i := 0 to dbgrid28.Selectedrows.Count - 1 do
     begin
       if dbgrid28.DataSource=dm.dsqreciboscliente then
       begin
         dm.qreciboscliente.GotoBookmark (pointer (dbgrid28.selectedrows[i]));
         qaux.SQL.Clear;
         qaux.SQL.Add('update cobros set seleccionado=1 where id='+dm.qrecibosclienteid.asstring);
         qaux.ExecSQL;
       end;
       if dbgrid28.DataSource=dm.dsqreciboscliente2 then
       begin
         dm.qreciboscliente2.GotoBookmark (pointer (dbgrid28.selectedrows[i]));
         qaux.SQL.Clear;
         qaux.SQL.Add('update cobros set seleccionado=1 where id='+dm.qreciboscliente2id.asstring);
         qaux.ExecSQL;
       end;
     end;
    dminf.qinfrecibo.close;
    dminf.qinfrecibo.SQL.Clear;
    dminf.qinfrecibo.SQL.Add('select c.*,cli.nif,cli.nombre_completo as nomcliente,a.nombre_completo as nomalumno,g.nombre as nomgrupo from cobros c,clientes cli,alumnos a,grupos g');
    dminf.qinfrecibo.SQL.Add(' where c.ide=cli.ide and c.idc=cli.id and c.ide=a.ide and c.ida=a.id and ');
    dminf.qinfrecibo.SQL.Add(' c.ide=g.ide and c.idg=g.id and cli.ide=a.ide and cli.id=a.idc and c.seleccionado=1');
    dminf.qinfrecibo.Open;

    if dminf.qinfrecibo.RecordCount=0 then
    begin
        recibo:=dm.recibosid.Asstring;
        dminf.qinfrecibo.close;
        dminf.qinfrecibo.SQL.Clear;
        dminf.qinfrecibo.SQL.Add('select c.*,cli.nif,cli.nombre_completo as nomcliente,a.nombre_completo as nomalumno,g.nombre as nomgrupo from cobros c,clientes cli,alumnos a,grupos g');
        dminf.qinfrecibo.SQL.Add(' where c.ide=cli.ide and c.idc=cli.id and c.ide=a.ide and c.ida=a.id and ');
        dminf.qinfrecibo.SQL.Add(' c.ide=g.ide and c.idg=g.id and cli.ide=a.ide and cli.id=a.idc and c.id='+recibo);
        dminf.qinfrecibo.Open;
    end;

    informedb.Datasource:=dminf.dsqinfrecibo;
    informe.Report.Clear;
    informe.LoadFromFile('c:\formagest\informes\tiquet.fr3');

//    informes.Report.FileName:=TMES.Text+' ' + qjornalestrabajador.asstring;
    informe.PrintOptions.Printer:=tprinter;
    informe.ShowReport();

    informe.Clear;
   end else
         begin
           showmessage('¡¡¡ ATENCION DEBE SELECCIONAR AL MENOS UN RECIBO ¡¡¡');
         end;


     qaux.SQL.Clear;
     qaux.SQL.Add('update cobros set seleccionado=0 where seleccionado=1');
     qaux.ExecSQL;
     dm.qreciboscliente.Refresh;
     dm.qreciboscliente2.Refresh;


end;

procedure TMENU.btsinicioClick(Sender: TObject);
var ahora: tdatetime;
    anyo,mes,dia:word;
    fecha:string;
begin
    fechasesion.Date:=date();
    fechasesion.Visible:=true;
    psesionesdatos.Enabled:=true;
    dm.sesiones.Append;
    ahora:=now;
    dm.sesioneshora_inicio.Value:=strtotime(timetostr(ahora));
    dm.sesioneside.Value:=dm.qimpartiractivoide.AsInteger;
    dm.sesionesidp.Value:=dm.qempleadosid.AsInteger;
    dm.sesionesidg.Value:=dm.qimpartiractivoidg.AsInteger;
    dm.sesionesfecha.Value:=fechasesion.Date;
//   dm.sesioneshora_inicio.Value:=strtotime(timetostr(ahora));
    dm.sesiones.Post;
    dm.sesiones.Refresh;
    dm.sesiones_alumnos.Refresh;
    psesionesdatos.Enabled:=false;
    fechasesion.Visible:=false;

end;

procedure TMENU.btSnotascancelarClick(Sender: TObject);
begin
    dm.notas.Cancel;
    panelnotassesiones.enabled:=false;
end;

procedure TMENU.btSnotasguardarClick(Sender: TObject);
begin
    panelnotassesiones.Enabled:=false;
    dm.notas.Post;
    dm.notas.Refresh;
end;

procedure TMENU.btSnotasmodificarClick(Sender: TObject);
begin
    panelnotassesiones.Enabled:=true;
    dm.notas.Edit;
    dbedit95.SetFocus;
end;

procedure TMENU.btCursosClick(Sender: TObject);
begin
   pprincipal.Visible:=false;
   pcursos.Visible:=true;
   pcursos.BringToFront;
   pprincipal.SendToBack;
   dm.qcursos.close;
   dm.qcursos.open;
   dm.cursos.close;
   dm.cursos.open;
   dm.qgrupocurso.close;
   dm.qgrupocurso.open;
   dm.qgrupoalumnos.close;
   dm.qgrupoalumnos.open;
   tbuscarcursos.SetFocus;
   todoscursos.checked:=true;
   todoscursos.checked:=false;


end;

procedure TMENU.btclsalirClick(Sender: TObject);
begin
//   dm.dbjolly.Connected:=false;
   pclientes.Visible:=false;
   pprincipal.Visible:=true;
end;

procedure TMENU.Button3Click(Sender: TObject);
begin
    qgrupos.Open;
    while not qgrupos.Eof do
    begin
        qalumnos.Close;
        qalumnos.SQL.Clear;
        qalumnos.SQL.Add('select a.ide,a.ida,al.idc,al.descuento from asistir a,alumnos al where al.automatico=1 and a.fechabaja is null and a.ide=al.ide and a.ida=al.id');
        qalumnos.SQL.Add(' and a.ide='+inttostr(centro)+' and a.idg='+qgruposid.asstring);
        qalumnos.Open;
        if qalumnos.RecordCount>0 then
        begin
           while not qalumnos.Eof do
           begin
             qclientes.close;
             qclientes.sql.clear;
             qclientes.sql.add('select ide,id,idfp from clientes where ide='+inttostr(centro)+' and id='+qalumnosidc.asstring);
             qclientes.Open;
             dm.recibos.MasterSource:=nil;
             dm.recibos.Append;
             dm.recibospagado.Value:=0;
             dm.reciboside.Value:=qalumnoside.AsInteger;
             dm.recibosidc.Value:=qalumnosidc.AsInteger;
             dm.recibosida.Value:=qalumnosida.AsInteger;
             dm.recibosidg.Value:=qgruposid.AsInteger;
             dm.recibosfecharecibo.Value:=strtodate(edfecha.Text);
             dm.recibosconcepto.Value:=edconcepto.Text;
             if edimporte.Text='' then
             begin
                 if edmaterial.Checked then dm.recibosmaterial.Value:=1 else dm.recibosmaterial.Value:=0;
                 dm.recibosimporte.Value:=qgrupospreciomensual.AsFloat;
                 dm.recibosdescuento.Value:=qalumnosdescuento.Asinteger;
                 dm.recibosimportefinal.Value:=qgrupospreciomensual.AsFloat-((qgrupospreciomensual.AsFloat*qalumnosdescuento.AsFloat)/100);
             end else
             begin
                 if edmaterial.Checked then dm.recibosmaterial.Value:=1 else dm.recibosmaterial.Value:=0;
                 dm.recibosimporte.Value:=strtofloat(edimporte.text);
                 dm.recibosdescuento.Value:=0;
                 dm.recibosimportefinal.Value:=strtofloat(edimporte.text);
             end;
             dm.recibosforma_pago.value:=qclientesidfp.AsInteger;
             qaux.SQL.Clear;
             qaux.SQL.Add('select domiciliado from formas_pago where ide='+inttostr(centro)+' and id='+dm.recibosforma_pago.asstring);
             qaux.Open;
             dm.recibosdomiciliado.Value:=qauxdomiciliado.asinteger;

             dm.recibos.Post;
             qalumnos.Next;
           end;
        end;
        qgrupos.Next;
    end;
    dm.recibos.MasterSource:=dm.dsqreciboscliente;
    dm.qreciboscliente.Refresh;
    qgrupos.Close;

end;

procedure TMENU.Button4Click(Sender: TObject);
begin
    festgrupos := Tfestgrupos.Create(nil);
    try
       festgrupos.showmodal;
    finally
      festgrupos.Free;
    end;

end;

procedure TMENU.Button6Click(Sender: TObject);
var dia,mes,anyo:word;
    tfecha:string;
begin
    if edfecha.Text<>'  /  /  ' then
    begin
       decodedate(strtodate(edfecha.Text),anyo,mes,dia);
       tfecha:=''''+floattostr(anyo)+'-'+floattostr(mes)+'-'+floattostr(dia)+'''';
       qaux.SQL.Clear;
       qaux.SQL.Add('update cobros set seleccionado=0');
       qaux.ExecSQL;
       qaux.SQL.Clear;
       qaux.SQL.Add('update cobros set seleccionado=1 where fecharecibo='+tfecha);
       qaux.ExecSQL;
       edfecha.Clear;
    end;
    dm.qreciboscliente2.refresh;
    dm.qreciboscliente.refresh;
end;

procedure TMENU.Button7Click(Sender: TObject);
var profesor,grupo:string;
begin
    profesor:=dm.qgruposprofesor.AsString;
    grupo:=dm.qgruposid.AsString;
    dminf.qgruposalumnos.close;
    dminf.qgruposalumnos.SQL.Clear;
    dminf.qgruposalumnos.SQL.Add('select p.id as idprofesor,p.nombre_completo as nomprofesor,g.nombre as nomgrupo,al.nombre as nomalumno,al.apellidos,al.fecha_nacimiento,al.ob_medicas,al.correo_alumno,cl.email from impartir i,grupos g, asistir a,alumnos al, empleados p,clientes cl where');
    dminf.qgruposalumnos.SQL.Add(' al.ide=cl.ide and al.idc=cl.id and a.ide=al.ide and a.ide=p.ide and a.ida=al.id and a.idg=g.id and g.id=i.idg ');
    dminf.qgruposalumnos.SQL.Add(' and i.idp=p.id and g.activo=1 and a.fechabaja is null and g.id='+''''+grupo+''''+' and p.nombre_completo='+''''+profesor+'''');
    dminf.qgruposalumnos.SQL.Add(' order by p.nombre_completo,g.id,al.apellidos,al.nombre');
    dminf.qgruposalumnos.Open;


    informedb.Datasource:=dminf.dsgruposalumnos;
    informe.Report.Clear;
    informe.LoadFromFile('c:\formagest\informes\gruposalumnos.fr3');

//    informes.Report.FileName:=TMES.Text+' ' + qjornalestrabajador.asstring;
    informe.PrintOptions.Printer:=tprinter2;
    informe.ShowReport();
    informe.Clear;


end;

procedure TMENU.Button8Click(Sender: TObject);
begin
  dmalumnos.qdocumentosal.Delete;
end;

procedure TMENU.btAactualizarClick(Sender: TObject);
begin
    dmalumnos.qalumnos.close;
    dmalumnos.qalumnos.Open;
end;

procedure TMENU.btCactualizarClick(Sender: TObject);
begin
    dm.qclientes.Refresh;
    dm.clientes.Refresh;
    dm.qalumnosclientes.Refresh;
    dm.qgruposclientes.Refresh;
    dm.qreciboscliente.Refresh;
end;

procedure TMENU.btverdatosClick(Sender: TObject);
begin
//    pagecontrol5.Visible:=not pagecontrol5.visible;
    pagecontrol6.Visible:=not pagecontrol6.visible;
    if pagecontrol6.Visible=true then btverdatos.Caption:='Ocultar datos' else btverdatos.Caption:='Ver datos'

end;

procedure TMENU.btestadisticasClick(Sender: TObject);
begin
    festsesiones.showmodal;
end;

procedure TMENU.btgsalirClick(Sender: TObject);
begin
//   dm.dbjolly.Connected:=false;
   pgrupos.Visible:=false;
   pprincipal.Visible:=true;

end;

procedure TMENU.btRecibosClick(Sender: TObject);
begin
    recibos_s := Trecibos_s.Create(nil);
    try
      recibos_s.showmodal();
    finally
      recibos_s.Free;
    end;
//   dm.dbjolly.Connected:=false;
{   dm.filtro:='';
   tbuscarclientesrecibos.Text:='';
   pprincipal.Visible:=false;
   precibos.Visible:=true;
   precibos.BringToFront;
   pprincipal.SendToBack;
   dm.empresa.close;
   dm.qgrupos.close;
   dm.grupos.close;
   dm.qclientes.close;
   dm.clientes.close;
   dm.qalumnosclientes.close;
   dm.qgruposclientes.close;
   dm.qalumnos.close;
   dm.formaspago.close;
   dm.recibos.close;
   dm.qreciboscliente.close;
   dm.qreciboscliente2.Close;

   dm.empresa.Open;
   dm2.qclientes.open;
   dm2.qalumnosclientes.open;
   dm2.qgruposclientes.open;
   dm.recibos.Open;  }
   ///////////////
   {   dm.recibos.prepare;
   dm.recibos.ParamByName('PRECIBO').AsInteger:=-10000;
   dm.recibos.Open;
   dm2.qclientes.prepare;
   dm2.qclientes.ParamByName('PEMPRESA').AsInteger:=dm.reciboside.AsInteger;
   dm2.qclientes.ParamByName('PCLIENTE').AsInteger:=dm.recibosidc.AsInteger;
   dm2.qclientes.open;

   dm2.qalumnosclientes.prepare;
   dm2.qalumnosclientes.ParamByName('PEMPRESA').AsInteger:=dm.reciboside.AsInteger;
   dm2.qalumnosclientes.ParamByName('PCLIENTE').AsInteger:=dm.recibosidc.AsInteger;
   dm2.qalumnosclientes.open;

   dm2.qgruposclientes.prepare;
   dm2.qgruposclientes.ParamByName('PEMPRESA').AsInteger:=dm.reciboside.AsInteger;
   dm2.qgruposclientes.ParamByName('PCLIENTE').AsInteger:=dm.recibosidc.AsInteger;
   dm2.qgruposclientes.ParamByName('PGRUPO').Asstring:=dm.recibosidg.Asstring;
   dm2.qgruposclientes.ParamByName('PALUMNO').Asstring:=dm.recibosida.Asstring;

}       //////////////////////
{   dm.qclientes.Open;
   dm.qgrupos.Open;
   dm.grupos.Open;
   dm.clientes.Open;
   dm.qalumnosclientes.Open;
   dm.qgruposclientes.Open;
   dm.qalumnos.Open;
   dm.formaspago.open;
   dm.qreciboscliente.open;
   dm.qreciboscliente2.Open;

   pagecontrol8.TabIndex:=0;
   Sdelcliente.Checked:=true; }
   //recibos.show;
end;

procedure TMENU.btrguardarClick(Sender: TObject);
var recibo:integer;
begin
    dm.recibosdomiciliado.Value:=dm.formaspagodomiciliado.asinteger;
    cliente:=dm.recibosidc.AsInteger;

    dm.recibos.Post;
    recibo:=dm.recibosid.AsInteger;
//    dm.recibos.last;
    dm.qreciboscliente2.Refresh;
    dm.qreciboscliente.Refresh;
    dm.qreciboscliente2.Locate('id',recibo,[locaseinsensitive]);
    dm.qreciboscliente.Locate('id',recibo,[locaseinsensitive]);
    if nuevorecibo=1 then dm.recibos.MasterSource:=dm.dsqreciboscliente;
    if nuevorecibo=2 then dm.recibos.MasterSource:=dm.dsqreciboscliente2;
    recibo:=dm.recibosid.AsInteger;
    dbedit122.Visible:=false;
    label162.Visible:=false;
    precibosdatos.Enabled:=false;
    btRactualizar.Click;
end;

procedure TMENU.btrmodificarClick(Sender: TObject);
begin
    if dm.recibos.MasterSource=dm.dsqreciboscliente then nuevorecibo:=1;
    if dm.recibos.MasterSource=dm.dsqreciboscliente2 then nuevorecibo:=2;
    if dm.qreciboscliente2.Active=false then dm.qreciboscliente2.Open;
    recibo:=dm.recibosid.AsInteger;
    cliente:=dm.recibosidc.AsInteger;
    dm.recibos.Edit;
    precibosdatos.Enabled:=true;
    dbedit145.SetFocus;
end;

procedure TMENU.btRnuevoClick(Sender: TObject);
begin
//    if dm.recibos.MasterSource=dm.dsqreciboscliente then nuevorecibo:=1;
//    if dm.recibos.MasterSource=dm.dsqreciboscliente2 then nuevorecibo:=2;
     nuevorecibo:=1;

//    recibo:=dm.qrecibosclienteid.AsInteger;
//    cliente:=dm.qrecibosclienteidc.AsInteger;
    dm.recibos.MasterSource:=nil;
    dm.recibos.Append;

//    dm.qreciboscliente.Close;
    dm.recibosdomiciliado.Value:=0;
    dm.recibosmaterial.Value:=0;
    dm.recibospagado.Value:=0;
    dm.reciboside.value:=centro;
    dm.recibosidc.Value:=dm.qclientesid.AsInteger;

    precibosdatos.Enabled:=true;
    dbedit145.SetFocus;
end;

procedure TMENU.btGnuevoClick(Sender: TObject);
begin
    dm.grupos.MasterSource:=nil;
    dm.grupos.Append;
    dm.gruposide.value:=centro;
    pgruposdatos.Enabled:=true;
    dbedit88.SetFocus;
end;

procedure TMENU.btGruposClick(Sender: TObject);
begin
   pprincipal.Visible:=false;
   pgrupos.Visible:=true;
   pgrupos.BringToFront;
   pprincipal.SendToBack;
   dm.qgruposp.Close;
   dm.qgruposp.Open;
   dm.qgrupos.close;
   dm.qgrupos.open;
   dm.grupos.close;
   dm.grupos.open;
   dm.qaulas.close;
   dm.qaulas.open;
   dm.qgrupoalumnos2.close;
   dm.qgrupoalumnos2.open;
   dm.qcursos.close;
   dm.qcursos.open;;
   dm.cursos.close;
   dm.cursos.open;
   dm.notas.close;
   dm.notas.MasterSource:=dm.dsqgrupoalumnos2;
   dm.notas.Open;
   qtutores.Open;

   pagecontrol8.TabIndex:=0;
   filtro:='';

end;

procedure TMENU.btEmpleadosClick(Sender: TObject);
begin
   pprincipal.Visible:=false;
   pempleados.Visible:=true;
   pempleados.BringToFront;
   pprincipal.SendToBack;
//   dmalumnos.qdocumentosemp.close;
   dm.qempleados.Open;
   dm.empleados.Open;
   dm.impartir.Open;
   dm.qimpartirgrupo.Open;
   dm.vertodos:=0;
   dm.vertodosempgrupos:=1;
   dm.filtro:='';
   dm.filtrolista:='';
   dm.qgruposp.close;
   dm.qgruposp.Open;
//   dm.imagenes_empleados.Open;
//   dm.img.Open;
   tbuscarempleados.SetFocus;
end;

procedure TMENU.btClientesClick(Sender: TObject);
begin
   pprincipal.Visible:=false;
   pclientes.Visible:=true;
   pclientes.BringToFront;
   pprincipal.SendToBack;
   dm.qalumnos.Open;
   dm.alumnos.Open;
   dm.descuentos.Open;
   dm.qclientes.Open;
   dm.clientes.Open;
   dm.qgruposclientes.Open;
   dm.qalumnosclientes.Open;
   //dm.qreciboscliente.Open;
//   dm.imagenes_alumnos.Open;
//   dm.img.Open;
//   dm.notas.MasterSource:=dm.dsqasistiralumno;
//   dm.notas.Open;
//   dm.asistir.Open;
//   avisos.Open;
   dm.formaspago.Open;
   tbuscarclientes.SetFocus;
   todosclientes.checked:=true;
   todosclientes.checked:=false;
end;

procedure TMENU.btimodificarClick(Sender: TObject);
begin
    dm.impartir.Edit;
    pgruposempleados.Visible:=true;
    pgruposempleados.Enabled:=true;
//    dm.grupos.Filtered:=false;
//    dm.grupos.Filter:='activo=1';
//    dm.grupos.Filtered:=true;
//    dm.grupos.Refresh;
    comboimpartirgrupos.SetFocus;
end;

procedure TMENU.btimprimirClick(Sender: TObject);
var profesor:string;
begin
    profesor:=dm.empleadosid.AsString;
    dminf.qgruposalumnos.close;
    dminf.qgruposalumnos.SQL.Clear;
    dminf.qgruposalumnos.SQL.Add('select p.id as idprofesor,p.nombre_completo as nomprofesor,g.nombre as nomgrupo,al.nombre as nomalumno,al.apellidos,al.fecha_nacimiento,al.ob_medicas from impartir i,grupos g, asistir a,alumnos al, empleados p where');
    dminf.qgruposalumnos.SQL.Add(' a.ide=al.ide and a.ide=p.ide and a.ida=al.id and a.idg=g.id and g.id=i.idg ');
    dminf.qgruposalumnos.SQL.Add(' and i.idp=p.id and g.activo=1 and a.fechabaja is null and p.id='+profesor);
    dminf.qgruposalumnos.SQL.Add(' order by p.nombre_completo,g.id,al.apellidos,al.nombre');
    dminf.qgruposalumnos.Open;


    informedb.Datasource:=dminf.dsgruposalumnos;
    informe.Report.Clear;
    informe.LoadFromFile('c:\formagest\informes\gruposalumnos.fr3');

//    informes.Report.FileName:=TMES.Text+' ' + qjornalestrabajador.asstring;
    informe.PrintOptions.Printer:=tprinter2;
    informe.ShowReport();
    informe.Clear;

end;

procedure TMENU.btiborrarClick(Sender: TObject);
begin
   if not dm.impartir.Active then dm.impartir.Open;
   dm.impartir.Delete;
end;

procedure TMENU.bticancelarClick(Sender: TObject);
begin
    dm.impartir.cancel;
    dm.impartir.MasterSource:=dm.dsqimpartir;
    pgruposempleados.Visible:=false;
    pgruposempleados.Enabled:=false;
end;

procedure TMENU.btAokimagenClick(Sender: TObject);
var  imagen : TBitmap;
     imagen2: tPicture;
     archivo:TMemorystream;
     ext: string;
begin
    begin
       dmalumnos.imagenes_alumnos.Append;
       dmalumnos.imagenes_alumnosidalumno.Value:=dmalumnos.qalumnosid.Asinteger;
       dmalumnos.imagenes_alumnoside.Value:=dmalumnos.qalumnoside.AsInteger;
       dmalumnos.imagenes_alumnosimagen.LoadFromFile(openpicturedialog1.FileName);
       ext:=ExtractFileExt(openpicturedialog1.FileName);
       dmalumnos.imagenes_alumnostipo.Value:=ext;//ExtractFileExt(openpicturedialog1.FileName);//'.bmp';
       dmalumnos.imagenes_alumnos.Post;
       If not DirectoryExists('c:\formagest\tmp') then CreateDir('c:\formagest\tmp');
       Deletefile('c:\formagest\tmp\empimg'+ext);
       imgfoto2.Picture:=nil;
       dmalumnos.imagenes_alumnosimagen.savetofile('c:\formagest\tmp\empimg'+ext);
       imgfoto2.Picture.LoadFromFile('c:\formagest\tmp\empimg'+ext);
      end;
//    btAimagen.Caption:='Seleccione opción';
    panelfoto.Visible:=false;
    imgfoto.Visible:=false;
    btdesactivarcamara.Click;
//    btAokimagen.Visible:=false;
    dmalumnos.imagenes_alumnos.Refresh;

end;

procedure TMENU.btactivarcamaraClick(Sender: TObject);
begin
    Panelfoto.Width:= 120;
    Panelfoto.Height:= 120;
    hWndC := capCreateCaptureWindowA('Ventana de captura', WS_CHILD or WS_VISIBLE ,0, 0,Panelfoto.Height,Panelfoto.Width,Panelfoto.Handle,0);

      if hWndC <> 0 then
      begin
        SendMessage(hWndC, WM_CONNECT, 0, 0);
        SendMessage(hWndC, WM_SET_SCALE, 1, 0);
        SendMessage(hWndC, WM_SET_PREVIEWRATE, 20, 0);
        SendMessage(hWndC, WM_SET_OVERLAY, 1, 0);
        SendMessage(hWndC, WM_SET_PREVIEW, 1, 0);
        SetResolution(Panelfoto.Height,Panelfoto.Width);

      end;
end;

procedure TMENU.btactivarcamaraeClick(Sender: TObject);
begin
    Panelfotoe.Width:= 120;
    Panelfotoe.Height:= 120;
    hWndC := capCreateCaptureWindowA('Ventana de captura', WS_CHILD or WS_VISIBLE ,0, 0,Panelfotoe.Height,Panelfotoe.Width,Panelfotoe.Handle,0);

      if hWndC <> 0 then
      begin
        SendMessage(hWndC, WM_CONNECT, 0, 0);
        SendMessage(hWndC, WM_SET_SCALE, 1, 0);
        SendMessage(hWndC, WM_SET_PREVIEWRATE, 20, 0);
        SendMessage(hWndC, WM_SET_OVERLAY, 1, 0);
        SendMessage(hWndC, WM_SET_PREVIEW, 1, 0);
        SetResolution(Panelfotoe.Height,Panelfotoe.Width);

      end;
end;

procedure TMENU.btdesactivarcamaraClick(Sender: TObject);
begin
  if hWndC <> 0 then
  begin
    SendMessage(hWndC, WM_DISCONNECT, 0, 0);
  end;

end;

procedure TMENU.bteborrarClick(Sender: TObject);
begin
    dm.empleados.Delete;
end;

procedure TMENU.btecancelarClick(Sender: TObject);
begin
    dm.sesiones.cancel;
    psesionesdatos.Enabled:=false;
end;

procedure TMENU.bteguardarClick(Sender: TObject);
begin
    if not dm.qempleados.active then dm.qempleados.open;

    dm.empleados.Post;

    pempleadosdatos.Enabled:=false;
    PeImagenes.Visible:=true;
end;

procedure TMENU.btEimagenClick(Sender: TObject);
var
  PanelDC: HDC;
  Jpg : TJPEGImage;
  bmp : Tbitmap;
  imagen : TPicture;
  ext:string;
//  imagen : TJPEGImage;

begin

if (Sender as TButton).Caption ='Seleccione opción' then
begin
  bteimagen.Dragging; //('MenubtAimangen');
end;
if (Sender as TButton).Caption ='Cargar imagen' then
begin

  if OpenPictureDialog1.Execute then
  begin
//    imagen := TJPEGImage.Create;
    imagen := TPicture.Create;
    bmp:= TBitmap.Create;
    jpg:=TJPEGImage.Create;

    try

      ext:= ExtractFileExt(openpicturedialog1.FileName);
      if (ext='.jpg') or (ext='jpeg') then
      begin
{        jpg.LoadFromFile(OpenPictureDialog1.FileName);
        jpg.scale:=jshalf;
        jpg.CompressionQuality:=10;
        jpg.dibneeded;
        jpg.Compress;
        jpg.SaveToFile('c:\formagest\imagenes\'+dm.alumnosid.asstring+'.jpg');
        imagen.LoadFromFile(OpenPictureDialog1.FileName);//'c:\formagest\imagenes\'+dm.alumnosid.asstring+'.jpg');
        Bmp.Width:= Imagen.Width;
        Bmp.Height:= Imagen.Height;
        Bmp.Canvas.StretchDraw(canvas.ClipRect,bmp);// draw(0,0,Imagen.Graphic);//
        bmp.Assign(imagen.Graphic);
        Bmp.SaveToFile('c:\formagest\imagenes\'+dm.alumnosid.asstring+'.bmp'); }
        imgfotoe.Picture.LoadFromFile(OpenPictureDialog1.FileName);//'c:\formagest\imagenes\'+dm.alumnosid.asstring+'.bmp');
        bteokimagen.Visible:=true;
      end else
      begin
{          imagen.LoadFromFile(OpenPictureDialog1.FileName);
          Bmp.Width:= Imagen.Width;
          Bmp.Height:= Imagen.Height;
          Bmp.Canvas.StretchDraw(canvas.ClipRect,bmp);// draw(0,0,Imagen.Graphic);//
          bmp.Assign(imagen.Graphic);
          Bmp.SaveToFile('c:\formagest\imagenes\'+dm.alumnosid.asstring+'.bmp');}
          imgfotoe.Picture.LoadFromFile(OpenPictureDialog1.FileName);//'c:\formagest\imagenes\'+dm.alumnosid.asstring+'.bmp');
          bteokimagen.Visible:=true;
      end;
      imgfotoe.Visible:=true;
      {      dm.imagenes_alumnos.Append;
      dm.imagenes_alumnoside.Value:=dm.alumnoside.Asinteger;
      dm.imagenes_alumnosidalumno.Value:=dm.alumnosid.Asinteger;
      dm.imagenes_alumnosimagen.Assign(imagen);
      dm.imagenes_alumnos.Post;}
    finally
      imagen.Free;
    end;
  end;
end;
if (Sender as TButton).Caption ='Capturar imagen' then
begin
    if not Assigned(imgfotoe.Picture.Bitmap) then
    begin
        imgfotoe.Picture.Bitmap := TBitmap.Create;
    end
      else
      begin
        imgfotoe.Picture.Bitmap.Free;
        imgfotoe.picture.Bitmap := TBitmap.Create;
//        imgfoto.Stretch:=true;
      end;
      imgfotoe.Height:=120;
      imgfotoe.Width:=120;
      imgfotoe.Picture.Bitmap.Height := 120;
      imgfotoe.Picture.Bitmap.Width  := 120;
      PanelDC := GetDC(Panelfotoe.Handle);
      try
        BitBlt(imgfotoe.Picture.Bitmap.Canvas.Handle,
          0,0,Panelfotoe.Width, Panelfotoe.Height, PanelDC, 0,0, SRCCOPY);
      imgfotoe.Picture.Bitmap.SaveToFile('c:\formagest\imagenes\'+dm.empleadosid.asstring+'.bmp');

      finally

        ReleaseDC(Handle, PanelDC);
        btEokimagen.Visible:=true;

      end;
end;

end;


procedure TMENU.btemodificarClick(Sender: TObject);
begin
    dm.empleados.Edit;
    pempleadosdatos.Enabled:=true;
    PeImagenes.Visible:=false;
    dbedit36.SetFocus;
end;

procedure TMENU.btenuevoClick(Sender: TObject);
begin
    dm.empleados.MasterSource:=nil;
    dm.empleados.Append;
    dm.empleadoside.value:=centro;
    pempleadosdatos.Enabled:=true;
    peimagenes.visible:=false;
    dbedit36.SetFocus;
end;

procedure TMENU.btEoKimagenClick(Sender: TObject);
var  imagen : TBitmap;
     imagen2: tPicture;
     archivo:TMemorystream;
     ext: string;
begin
    imagen := TBitmap.Create;
    imagen2:= tPicture.Create;
    archivo:= tMemorystream.Create;
    try
//      imagen.LoadFromFile('c:\FORMAGEST\IMAGENES\'+dm.alumnosid.AsString+'.bmp');
      archivo.loadFromFile(OpenPictureDialog1.FileName);
      ext:= ExtractFileExt(openpicturedialog1.FileName);
      imagen2.loadFromFile(OpenPictureDialog1.FileName);
      imgfotoe.Picture.LoadFromFile(OpenPictureDialog1.FileName);
      imgfotoe.Visible:=true;
      dmalumnos.imagenes_alumnos.Open;
      dmalumnos.imagenes_alumnos.append;
      dmalumnos.imagenes_alumnoside.Value:=dm.empleadoside.Asinteger;
      dmalumnos.imagenes_alumnosidalumno.Value:=dm.empleadosid.Asinteger;
      dmalumnos.imagenes_alumnosimagen.LoadFromFile(OpenPictureDialog1.FileName);
      dmalumnos.imagenes_alumnostipo.value:=ext;
      dmalumnos.imagenes_alumnos.Post;
      dmalumnos.imagenes_alumnos.Refresh;
      dmalumnos.imagenes_alumnos.Last;

    finally
      imagen.Free;
    end;
//    bteimagen.Caption:='Seleccione opción';
    panelfotoe.Visible:=false;
    imgfotoe.Visible:=false;
    btdesactivarcamara.Click;
    bteokimagen.Visible:=false;

end;

procedure TMENU.btesalirClick(Sender: TObject);
begin
//   dm.dbjolly.Connected:=false;
   pempleados.Visible:=false;
   pprincipal.Visible:=true;
end;

procedure TMENU.btGborrarClick(Sender: TObject);
var grupo:string;
begin
   grupo:=dm.qgrupospid.asstring;
   dm.grupos.Delete;
   dm.qgruposp.Refresh;
   dm.qgrupoalumnos2.Refresh;
   dm.qgruposp.locate('id',grupo,[locaseinsensitive,lopartialkey]);

end;

procedure TMENU.btgcancelarClick(Sender: TObject);
begin
    dm.grupos.cancel;
    pgruposdatos.Enabled:=false;
    listadatos.Visible:=false;
    listadatos2.Visible:=false;

end;

procedure TMENU.btgguardarClick(Sender: TObject);
var grupo:string;
begin
    if not dm.qgrupos.active then dm.qgrupos.open;
    dm.gruposidcurso.Value:=dm.cursosid.AsInteger;
    dm.grupos.Post;
    grupo:=dm.gruposid.asstring;
    if dm.grupos.Mastersource=nil then dm.grupos.MasterSource:=dm.dsqgruposp;
    pgruposdatos.Enabled:=false;
    listadatos.Visible:=false;
    listadatos2.Visible:=false;
//   grupo:=dm.qgrupospid.asstring;
   dm.qgruposp.Refresh;
   dm.qgrupoalumnos2.Refresh;
   dm.qgruposp.locate('id',grupo,[locaseinsensitive,lopartialkey]);

end;

procedure TMENU.btgmodificarClick(Sender: TObject);
begin
    dm.grupos.Edit;
    pgruposdatos.Enabled:=true;
    dbedit88.SetFocus;
end;

procedure TMENU.btNotascancelarClick(Sender: TObject);
begin
    dmalumnos.notas.Cancel;
    panelnotas2.enabled:=false;
end;

procedure TMENU.btNotasguardarClick(Sender: TObject);
begin
    panelnotas2.Enabled:=false;
    dmalumnos.notas.Post;
    dmalumnos.notas.Refresh;
end;

procedure TMENU.btNotasModificarClick(Sender: TObject);
begin
    panelnotas2.Enabled:=true;
    dmalumnos.notas.Edit;
    dbedit35.SetFocus;
end;

procedure TMENU.btrborrarClick(Sender: TObject);
begin
   qaux.Close;
   qaux.SQL.Clear;
   qaux.SQL.Add('select * from cobros where seleccionado=1');
   qaux.Open;
   if qaux.RecordCount>0 then
   begin
       qaux.Close;
       qaux.SQL.Clear;
       qaux.SQL.Add('delete from cobros where seleccionado=1');
       qaux.execsql;
   end else
   begin
       if sdelcliente.checked then
       begin
           qaux.Close;
           qaux.SQL.Clear;
           qaux.SQL.Add('delete from cobros where id='+dm.qrecibosclienteid.AsString);
           qaux.execsql;
       end else
       begin
           qaux.Close;
           qaux.SQL.Clear;
           qaux.SQL.Add('delete from cobros where id='+dm.qreciboscliente2id.AsString);
           qaux.execsql;
       end;

   end;

//   dm.recibos.Delete;
   dm.qreciboscliente.Refresh;
   dm.qreciboscliente2.Refresh;
end;

procedure TMENU.btrcancelarClick(Sender: TObject);
begin

    dm.recibos.cancel;
    btRactualizar.Click;
    dm.qclientes.Locate('id',cliente,[locaseinsensitive,lopartialkey]);
    if nuevorecibo=1 then dm.recibos.MasterSource:=dm.dsqreciboscliente;
    if nuevorecibo=2 then dm.recibos.MasterSource:=dm.dsqreciboscliente2;
    dm.qreciboscliente.CLOSE;
    dm.qreciboscliente.Open;
    dm.qreciboscliente.Locate('id',recibo,[locaseinsensitive,lopartialkey]);

    dm.qreciboscliente2.Locate('id',recibo,[locaseinsensitive,lopartialkey]);
    dm.recibos.MasterFields:='id;ide';
    dm.recibos.LinkedFields:='id;ide';
    dm.recibos.Open;

    precibosdatos.Enabled:=false;

end;

procedure TMENU.btsmodificarClick(Sender: TObject);
begin
    fechasesion.Date:=dm.sesionesfecha.AsDateTime;
    fechasesion.Visible:=true;

    psesionesdatos.Enabled:=true;
    dm.sesiones.edit;

end;

procedure TMENU.Capturar1Click(Sender: TObject);
begin
    btAimagen.Caption:='Capturar imagen';
    panelfoto.Visible:=true;
    imgfoto.Visible:=true;
    btactivarcamara.Click;
end;

procedure TMENU.Cargar1Click(Sender: TObject);
begin
   btAimagen.Caption:='Cargar imagen';
   btAimagen.Click;
end;

procedure TMENU.chktodosClick(Sender: TObject);
var observaciones:string;
begin
    if chktodos.Checked then
    begin
      observaciones:=''''+'JUSTIFICADA MASIVAMENTE EL '+DATETOSTR(DATE)+'''';
      qaux.SQL.Clear;
      qaux.SQL.Add('update sesiones_alumnos set f_justificada=1,OBSERVACIONES='+OBSERVACIONES+' where f_justificada=0');
      qaux.ExecSQL;
      chktodos.Checked:=false;
    end;
end;

procedure TMENU.cursos2Click(Sender: TObject);
begin
    btcursos.Click;
end;

procedure TMENU.listabuscarClick(Sender: TObject);
var x:integer;
    filtrolista:string;
begin
   filtrolista:='';
   dm.filtrolista:='';
   for x :=0 to listabuscar.Items.Count-1 do
   begin
      if listabuscar.Checked[x] then
      begin

         if filtrolista='' then filtrolista:=filtrolista+'(dias like ('+''''+'%'+listabuscar.Items[x]+'%'+''''+')'

         else filtrolista:=filtrolista+'  or dias like ('+''''+'%'+listabuscar.Items[x]+'%'+''''+')'

      end;

   end;
   if filtrolista<>'' then filtrolista:=filtrolista+')';
     if filtrolista<>'' then dm.filtrolista:=filtrolista;
     dm.qgruposp.Close;
     dm.qgruposp.open;
end;

procedure TMENU.listadatos2Click(Sender: TObject);
var dias:string;
    x:integer;
begin
    for x:=0 to listadatos2.Items.Count-1 do
    begin
        if listadatos2.Checked[x] then if dias='' then dias:=listadatos2.Items[x] else dias:=dias+','+listadatos2.Items[x];
    end;
    dm.gruposmasdias.Value:=dias;
end;

procedure TMENU.listadatos2Exit(Sender: TObject);
begin
    listadatos2.Visible:=false;
    DBEDIT68.SetFocus;
end;

procedure TMENU.listadatosClick(Sender: TObject);
var dias:string;
    x:integer;
begin
    for x:=0 to listadatos.Items.Count-1 do
    begin
        if listadatos.Checked[x] then if dias='' then dias:=listadatos.Items[x] else dias:=dias+','+listadatos.Items[x];
    end;
    dm.gruposdias.Value:=dias;
end;

procedure TMENU.listadatosExit(Sender: TObject);
begin
    listadatos.Visible:=false;
    dbedit59.SetFocus;
end;

procedure TMENU.Listadodealumnosquepromocionan1Click(Sender: TObject);
begin
    fpromocionan := Tfpromocionan.Create(nil);
    try
      fpromocionan.showmodal();
    finally
      fpromocionan.Free;
    end;
end;

procedure TMENU.Datosgenerales1Click(Sender: TObject);
begin
    fempresas := Tfempresas.Create(nil);
    try
      fempresas.showmodal();
    finally
      fempresas.Free;
    end;
end;

procedure TMENU.DatosGenerales2Click(Sender: TObject);
begin
    btclientes.Click;
end;

procedure TMENU.Datosgenerales3Click(Sender: TObject);
begin
    btalumnos.Click;
end;

procedure TMENU.DatosGenerales4Click(Sender: TObject);
begin
    btempleados.Click;
end;

procedure TMENU.DBCheckBox1Click(Sender: TObject);
begin
   if dm.recibos.State in [dsedit,dsinsert] then
   begin
       if dbcheckbox1.Checked then
       begin
         qaux2.SQL.Clear;
         qaux2.SQL.Add('select precio_material from cursos where ide=:PIDE and id=:PID');
         qaux2.prepare;
         qaux2.ParamByName('PIDE').asinteger:=dm.qgruposclienteside.AsInteger;
         qaux2.ParamByName('PID').asinteger:=dm.qgruposclientesidcurso.AsInteger;
         qaux2.Open;
         dm.recibosimporte.Value:=qaux2.fields[0].asfloat;
       end else dm.recibosimporte.Value:=dm.qgruposclientespreciomensual.asfloat;
   end;
end;

procedure TMENU.chkpagadoClick(Sender: TObject);
begin
  if dm.recibos.State  in [dsedit,dsinsert] then
    if chkpagado.Checked then dm.recibosfechacobro.Value:=date() else dbedit120.SetFocus;

end;

procedure TMENU.DBEdit116Enter(Sender: TObject);
begin
   if (dbedit116.Text='') and (not dbcheckbox1.Checked) then dm.recibosimporte.Value:=dm.qgruposclientespreciomensual.asfloat;
end;

procedure TMENU.DBEdit24Exit(Sender: TObject);
begin
   btaguardar.SetFocus;
end;

procedure TMENU.DBEdit27Enter(Sender: TObject);
begin
    dmalumnos.asistirfechainicio.editmask   := '!99/99/99;1;_';
    dmalumnos.asistirfechainicio.Value:=dmalumnos.qgruposfechainicio.AsDateTime;
end;

procedure TMENU.DBEdit27Exit(Sender: TObject);
begin
    If DBEdit27.Text = '  /  /  ' then
    begin
      dmalumnos.asistirfechainicio.EditMask   := '';
      dmalumnos.asistirfechainicio.OnValidate := nil;
      DBEdit27.Text := '';
    end;

    dmalumnos.asistirfechainicio.editmask   := '!99/99/99;1;_';
    dmalumnos.asistirfechainicio.OnValidate := dm.asistirfechainiciovalidate;
end;

procedure TMENU.DBEdit27KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    If (Key = VK_BACK) or (Key = VK_DELETE) then
    If DBEdit27.Text = '  /  /  ' then
    begin
      dmalumnos.asistirfechainicio.EditMask   := '';
      dmalumnos.asistirfechainicio.OnValidate := nil;
      DBEdit27.Text := '';
    end;
end;

procedure TMENU.DBEdit28Change(Sender: TObject);
begin
    If DBEdit28.Text = '' then
    begin
    dmalumnos.asistirfechafin.editmask   := '!99/99/99;1;_';
//    dmalumnos.asistirfechafin.OnValidate := dmalumnos.asistirfechafinvalidate;
    end;
end;

procedure TMENU.DBEdit28Enter(Sender: TObject);
begin
//    dmalumnos.asistirfechafin.Value:=qgrupos2fechafin.AsDateTime;
    dmalumnos.asistirfechafin.editmask   := '!99/99/99;1;_';

end;

procedure TMENU.DBEdit28Exit(Sender: TObject);
begin
    If DBEdit28.Text = '  /  /  ' then
    begin
      dmalumnos.asistirfechafin.EditMask   := '';
      dmalumnos.asistirfechafin.OnValidate := nil;
      DBEdit28.Text := '';
    end;
    dmalumnos.asistirfechafin.editmask   := '!99/99/99;1;_';
    dmalumnos.asistirfechafin.OnValidate := dm.asistirfechafinvalidate;
end;

procedure TMENU.DBEdit28KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    If (Key = VK_BACK) or (Key = VK_DELETE) then
    If DBEdit28.Text = '  /  /  ' then
    begin
      dmalumnos.asistirfechafin.EditMask   := '';
      dmalumnos.asistirfechafin.OnValidate := nil;
      DBEdit28.Text := '';
    end;
end;

procedure TMENU.DBEdit29Change(Sender: TObject);
begin
    If DBEdit29.Text = '' then
    begin
    dmalumnos.asistirfechabaja.editmask   := '!99/99/99;1;_';
   // dmalumnos.asistirfechabaja.OnValidate := dmalumnos.asistirfechabajavalidate;
    end;
end;

procedure TMENU.DBEdit29Exit(Sender: TObject);
begin
    dmalumnos.asistirfechabaja.EditMask   := '';
    dmalumnos.asistirfechabaja.OnValidate := nil;
    DBEdit29.Text := '';
    dmalumnos.asistirfechabaja.editmask   := '!99/99/99;1;_';
//    dmalumnos.asistirfechabaja.OnValidate := dm.asistirfechabajavalidate;
end;

procedure TMENU.DBEdit29KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    If (Key = VK_BACK) or (Key = VK_DELETE) then
    If DBEdit29.Text = '  /  /  ' then
    begin
      dmalumnos.asistirfechabaja.EditMask   := '';
      dmalumnos.asistirfechabaja.OnValidate := nil;
      DBEdit29.Text := '';
    end;
end;

procedure TMENU.DBEdit117Enter(Sender: TObject);
begin
   if dbedit117.Text='' then dm.recibosdescuento.Value:=dm.qalumnosclientesdescuento.asinteger;
end;

procedure TMENU.DBEdit118Enter(Sender: TObject);
begin
    dm.recibosimportefinal.Value:=dm.recibosimporte.AsFloat-((dm.recibosimporte.AsFloat*dm.recibosdescuento.AsFloat)/100);
    dm.recibosentrega.Value:=dm.recibosimportefinal.AsFloat;
end;

procedure TMENU.DBEdit119Exit(Sender: TObject);
begin
    dm.recibosconcepto.Value:=dm.recibosconcepto.asstring;//+' '+dm.qalumnosclientesnombre_completo.AsString;
end;

procedure TMENU.DBEdit120Change(Sender: TObject);
begin
    If DBEdit120.Text = '' then
    begin
    dm.recibosfechacobro.editmask   := '!99/99/99;1;_';
    dm.recibosfechacobro.OnValidate := dm.recibosfechacobrovalidate;
    end;
end;

procedure TMENU.DBEdit120Exit(Sender: TObject);
begin
    If DBEdit120.Text = '  /  /  ' then
    begin
      dm.recibosfechacobro.EditMask   := '';
      dm.recibosfechacobro.OnValidate := nil;
      DBEDIT120.Text:='';
    end;

    dm.recibosfechacobro.editmask   := '!99/99/99;1;_';
    dm.recibosfechacobro.OnValidate := dm.recibosfechacobrovalidate;
end;

procedure TMENU.DBEdit120KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    If (Key = VK_BACK) or (Key = VK_DELETE) then
    If DBEdit120.Text = '  /  /  ' then
    begin
      dm.recibosfechacobro.EditMask   := '';
      dm.recibosfechacobro.OnValidate := nil;
      DBEdit120.Text := '';

    end;
end;

procedure TMENU.DBEdit145Change(Sender: TObject);
begin
    If DBEdit145.Text = '' then
    begin
    dm.recibosfecharecibo.editmask   := '!99/99/99;1;_';
    dm.recibosfecharecibo.OnValidate := dm.recibosfecharecibovalidate;
    end;
end;

procedure TMENU.DBEdit145Exit(Sender: TObject);
begin
    If DBEdit145.Text = '  /  /  ' then
    begin
      dm.recibosfecharecibo.EditMask   := '';
      dm.recibosfecharecibo.OnValidate := nil;
      DBEDIT145.Text:='';
    end;

    dm.recibosfecharecibo.editmask   := '!99/99/99;1;_';
    dm.recibosfecharecibo.OnValidate := dm.recibosfecharecibovalidate;
end;

procedure TMENU.DBEdit145KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    If (Key = VK_BACK) or (Key = VK_DELETE) then
    If DBEdit145.Text = '  /  /  ' then
    begin
      dm.recibosfecharecibo.EditMask   := '';
      dm.recibosfecharecibo.OnValidate := nil;
      DBEdit145.Text := '';
    end;
end;

procedure TMENU.DBEdit30Change(Sender: TObject);
begin
    If DBEdit30.Text = '' then
    begin
    dmalumnos.asistirfecha_abono.editmask   := '!99/99/99;1;_';
 //   dmalumnos.asistirfecha_abono.OnValidate := dmalumnos.asistirfecha_abonovalidate;
    end;
end;

procedure TMENU.DBEdit30Exit(Sender: TObject);
begin
    If DBEdit30.Text = '  /  /  ' then
    begin
      dmalumnos.asistirfecha_abono.EditMask   := '';
      dmalumnos.asistirfecha_abono.OnValidate := nil;
      DBEdit30.Text := '';
    end;
    dmalumnos.asistirfecha_abono.editmask   := '!99/99/99;1;_';
//    dmalumnos.asistirfecha_abono.OnValidate := dmalumnos.asistirfecha_abonovalidate;
end;

procedure TMENU.DBEdit30KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    If (Key = VK_BACK) or (Key = VK_DELETE) then
    If DBEdit30.Text = '  /  /  ' then
    begin
      dmalumnos.asistirfecha_abono.EditMask   := '';
      dmalumnos.asistirfecha_abono.OnValidate := nil;
      DBEdit30.Text := '';
    end;
end;

procedure TMENU.DBEdit32Exit(Sender: TObject);
begin
  btasguardar.setfocus;
end;

procedure TMENU.DBEdit58Enter(Sender: TObject);
var x,y:integer;
  dia,dias:string;
begin
   dia:='';
   dias:=dm.gruposdias.AsString;
   if length(dias)>0 then
   begin
       for x := 1 to length(dias) do
       begin
         if dias[x]<>',' then
         begin
          dia:=dia+dias[x];
         end;
         if (dias[x]=',') or (x=length(dias)) then
         begin
             for y := 0 to listadatos.Items.Count-1 do
             begin
                if listadatos.Items[y]=dia then listadatos.Checked[y]:=true;
             end;
             dia:='';
         end;
       end;
   end;
   listadatos.Visible:=true;
end;

procedure TMENU.DBEdit58Exit(Sender: TObject);
begin
//   listadatos.Visible:=false;
//   dbedit59.SetFocus;
end;

procedure TMENU.DBEdit5Exit(Sender: TObject);
begin
    LEedad.Caption:='Edad: '+inttostr(trunc((date()-dmalumnos.alumnosfecha_nacimiento.AsDateTime)/365))+' años';
end;

procedure TMENU.DBEdit66Enter(Sender: TObject);
var x,y:integer;
  dia,dias:string;
begin
   dia:='';
   dias:=dm.gruposmasdias.AsString;
   if length(dias)>0 then
   begin
       for x := 1 to length(dias) do
       begin
         if dias[x]<>',' then
         begin
          dia:=dia+dias[x];
         end;
         if (dias[x]=',') or (x=length(dias)) then
         begin
             for y := 0 to listadatos.Items.Count-1 do
             begin
                if listadatos2.Items[y]=dia then listadatos2.Checked[y]:=true;
             end;
             dia:='';
         end;
       end;
   end;
   listadatos2.Visible:=true;
end;

procedure TMENU.DBEdit66Exit(Sender: TObject);
begin
//   listadatos2.Visible:=false;
//   dbedit68.SetFocus;
end;

procedure TMENU.DBGrid15CellClick(Column: TColumn);
begin
    if column.Field.FieldName ='asiste' then
    begin
       if dm.sesiones_alumnosasiste.asinteger=1 then
       begin
         dm.sesiones_alumnos.Edit;
         dm.sesiones_alumnosasiste.Value:=0;
         dm.sesiones_alumnos.Post;
         dbgrid15.SelectedIndex:=1;
       end else
             begin
               dm.sesiones_alumnos.Edit;
               dm.sesiones_alumnosasiste.Value:=1;
               dm.sesiones_alumnos.Post;
               dm.sesiones_alumnos.Refresh;
               dbgrid15.SelectedIndex:=1;
             end;
    end;
    if column.Field.FieldName ='f_justificada' then
    begin
       if dm.sesiones_alumnosf_justificada.asinteger=1 then
       begin
         dm.sesiones_alumnos.Edit;
         dm.sesiones_alumnosf_justificada.Value:=0;
         dm.sesiones_alumnos.Post;
         dbgrid15.SelectedIndex:=1;
       end else
             begin
               dm.sesiones_alumnos.Edit;
               dm.sesiones_alumnosf_justificada.Value:=1;
               dm.sesiones_alumnos.Post;
               dm.sesiones_alumnos.Refresh;
               dbgrid15.SelectedIndex:=1;
             end;
    end;


end;

procedure TMENU.DBGrid15DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[boolean] of Integer =
 (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
    if dm.sesiones_alumnosasiste.Asinteger=0 then
    begin
        DBGrid15.Canvas.brush.Color := rojo;
    end;
    DBGrid15.DefaultDrawColumnCell(Rect, DataCol, Column, State);
// dibujar check

if (gdFocused in State) then
begin
    if (Column.Field.FieldName = 'asiste') then
     begin
       gcrpagado.Left := Rect.Left + DBGrid15.Left + 2;
       gcrpagado.Top := Rect.Top + DBGrid15.top + 2;
       gcrpagado.Width := Rect.Right - Rect.Left;
       gcrpagado.Height := Rect.Bottom - Rect.Top;
       gcrpagado.Visible := True;
     end;
    if (Column.Field.FieldName = 'f_justificada') then
     begin
       gcrpagado.Left := Rect.Left + DBGrid15.Left + 2;
       gcrpagado.Top := Rect.Top + DBGrid15.top + 2;
       gcrpagado.Width := Rect.Right - Rect.Left;
       gcrpagado.Height := Rect.Bottom - Rect.Top;
       gcrpagado.Visible := True;
     end;

end else
     begin
       if (Column.Field.FieldName = 'asiste') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
//         DrawState := ISChecked[Column.Field.Asboolean];
         DBGrid15.Canvas.FillRect(Rect);
         DrawFrameControl(DBGrid15.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;
       if (Column.Field.FieldName = 'f_justificada') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
//         DrawState := ISChecked[Column.Field.Asboolean];
         DBGrid15.Canvas.FillRect(Rect);
         DrawFrameControl(DBGrid15.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);

       end;
end;
end;

procedure TMENU.DBGrid17CellClick(Column: TColumn);
begin
    if column.Field.FieldName ='f_justificada' then
    begin
       if dmalumnos.qfaltasf_justificada.asinteger=0 then
       begin
         dmalumnos.qfaltas.Edit;
         dmalumnos.qfaltasf_justificada.Value:=1;
         dmalumnos.qfaltas.Post;
         dbgrid17.SelectedIndex:=1;
       end
    end;
    dmalumnos.qfaltas.Refresh;
end;

procedure TMENU.DBGrid17DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[boolean] of Integer =
 (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
// dibujar check

begin
if (gdFocused in State) then
begin
    if (Column.Field.FieldName = 'f_justificada') then
     begin
       gcrpagado.Left := Rect.Left + DBGrid17.Left + 2;
       gcrpagado.Top := Rect.Top + DBGrid17.top + 2;
       gcrpagado.Width := Rect.Right - Rect.Left;
       gcrpagado.Height := Rect.Bottom - Rect.Top;
       gcrpagado.Visible := True;
     end;

end else
     begin
       if (Column.Field.FieldName = 'f_justificada') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
//         DrawState := ISChecked[Column.Field.Asboolean];
         DBGrid15.Canvas.FillRect(Rect);
         DrawFrameControl(DBGrid17.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);

       end;
end;

end;

procedure TMENU.DBGrid18DblClick(Sender: TObject);
begin
    pempleados.sendtoback;
    palumnos.Visible:=true;
    palumnos.BringToFront;
    tbuscaralumnos.Text:=dm.qgrupoalumnosnombre_completo.AsString;
end;

procedure TMENU.DBGrid22CellClick(Column: TColumn);
begin
{    if column.Field.FieldName ='pagado' then
    begin
       if dm.qrecibosalumnopagado.asinteger=1 then
       begin
         dm.qrecibosalumno.Edit;
         dm.qrecibosalumnopagado.Value:=0;
         dm.qrecibosalumno.Post;
         dbgrid22.selectedIndex:=1;
       end else
             begin
               dm.qrecibosalumno.Edit;
               dm.qrecibosalumnopagado.Value:=1;
               dm.qrecibosalumno.Post;
               dm.qrecibosalumno.Refresh;
               dbgrid22.SelectedIndex:=1;
             end;
    end;
    if column.Field.FieldName ='domiciliado' then
    begin
       if dm.qrecibosalumnodomiciliado.asinteger=1 then
       begin
         dm.qrecibosalumno.Edit;
         dm.qrecibosalumnodomiciliado.Value:=0;
         dm.qrecibosalumno.Post;
         dbgrid22.selectedIndex:=1;
       end else
             begin
               dm.qrecibosalumno.Edit;
               dm.qrecibosalumnodomiciliado.Value:=1;
               dm.qrecibosalumno.Post;
               dm.qrecibosalumno.Refresh;
               dbgrid22.SelectedIndex:=1;
             end;
    end;
    if column.Field.FieldName ='material' then
    begin
       if dm.qrecibosalumnomaterial.asinteger=1 then
       begin
         dm.qrecibosalumno.Edit;
         dm.qrecibosalumnomaterial.Value:=0;
         dm.qrecibosalumno.Post;
         dbgrid22.selectedIndex:=1;
       end else
             begin
               dm.qrecibosalumno.Edit;
               dm.qrecibosalumnomaterial.Value:=1;
               dm.qrecibosalumno.Post;
               dm.qrecibosalumno.Refresh;
               dbgrid22.SelectedIndex:=1;
             end;
    end;
          }
end;

procedure TMENU.DBGrid22DblClick(Sender: TObject);
begin
    pclientes.sendtoback;
    precibos.Visible:=true;
    tbuscarclientesrecibos.Text:=dm.qclientesnombre_completo.AsString;
end;

procedure TMENU.DBGrid22DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[Boolean] of Integer =
 (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
{    if dm.qrecibosclientepagado.Asinteger=0 then
    begin
        DBgrid22.Canvas.brush.Color := rojo;
    end;
    DBgrid22.DefaultDrawColumnCell(Rect, DataCol, Column, State);
// dibujar check

if (gdFocused in State) then
begin
    if (Column.Field.FieldName = 'pagado') then
     begin
       gcrpagado.Left := Rect.Left + DBgrid22.Left + 2;
       gcrpagado.Top := Rect.Top + DBgrid22.top + 2;
       gcrpagado.Width := Rect.Right - Rect.Left;
       gcrpagado.Height := Rect.Bottom - Rect.Top;
       gcrpagado.Visible := True;
     end;
    if (Column.Field.FieldName = 'domiciliado') then
    begin
      gcrpagado.Left := Rect.Left + DBgrid22.Left + 2;
      gcrpagado.Top := Rect.Top + DBgrid22.top + 2;
      gcrpagado.Width := Rect.Right - Rect.Left;
      gcrpagado.Height := Rect.Bottom - Rect.Top;
      gcrpagado.Visible := True;
    end;
    if (Column.Field.FieldName = 'material') then
    begin
      gcrpagado.Left := Rect.Left + DBgrid22.Left + 2;
      gcrpagado.Top := Rect.Top + DBgrid22.top + 2;
      gcrpagado.Width := Rect.Right - Rect.Left;
      gcrpagado.Height := Rect.Bottom - Rect.Top;
      gcrpagado.Visible := True;
    end;

end else
     begin
       if (Column.Field.FieldName = 'pagado') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
      //   DrawState := ISChecked[Column.Field.Asboolean];
         DBgrid22.Canvas.FillRect(Rect);
         DrawFrameControl(DBgrid22.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;
       if (Column.Field.FieldName = 'domiciliado') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
      //   DrawState := ISChecked[Column.Field.Asboolean];
         DBgrid22.Canvas.FillRect(Rect);
         DrawFrameControl(DBgrid22.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;
       if (Column.Field.FieldName = 'material') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
      //   DrawState := ISChecked[Column.Field.Asboolean];
         DBgrid22.Canvas.FillRect(Rect);
         DrawFrameControl(DBgrid22.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;
     end;}
end;

procedure TMENU.DBGrid23DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
    if dm.qgrupospplazas_libres.Asinteger<=0 then
    begin
        DBGrid23.Canvas.brush.Color := rojo;
    end else DBGrid23.Canvas.brush.Color := verde;
    DBGrid23.DefaultDrawColumnCell(Rect, DataCol, Column, State);

end;

procedure TMENU.DBGrid24DblClick(Sender: TObject);
begin
    PGRUPOS.SendToBack;
    palumnos.Visible:=true;
    palumnos.BringToFront;
    dmalumnos.qalumnos.Open;
    tbuscaralumnos.SetFocus;
    tbuscaralumnos.Text:=dm.qgrupoalumnos2nombre_completo.AsString;
    dbgrid1.setfocus;
end;

procedure TMENU.DBGrid24DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
    if dm.qgrupoalumnos2fechabaja.AsString<>'' then
    begin
        DBGrid24.Canvas.brush.Color := rojo;
    end;
    DBGrid24.DefaultDrawColumnCell(Rect, DataCol, Column, State);

end;

procedure TMENU.DBGrid25DblClick(Sender: TObject);
begin
    pclientes.sendtoback;
    palumnos.Visible:=true;
    palumnos.BringToFront;
    tbuscaralumnos.Text:=dm.qalumnosclientesnombre_completo.AsString;
end;

procedure TMENU.DBGrid25DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[Boolean] of Integer =
 (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
    if dm.qalumnosclientesactivo.Asinteger=0 then
    begin
        DBGrid25.Canvas.brush.Color := rojo;
    end;
    DBGrid25.DefaultDrawColumnCell(Rect, DataCol, Column, State);
// dibujar check

if (gdFocused in State) then
begin
    if (Column.Field.FieldName = 'activo') then
     begin
       gcrpagado.Left := Rect.Left + DBGrid25.Left + 2;
       gcrpagado.Top := Rect.Top + DBGrid25.top + 2;
       gcrpagado.Width := Rect.Right - Rect.Left;
       gcrpagado.Height := Rect.Bottom - Rect.Top;
       gcrpagado.Visible := True;
     end;
end else
     begin
       if (Column.Field.FieldName = 'activo') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
      //   DrawState := ISChecked[Column.Field.Asboolean];
         DBGrid25.Canvas.FillRect(Rect);
         DrawFrameControl(DBGrid25.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;

     end;



end;

procedure TMENU.DBGrid26DblClick(Sender: TObject);
begin
    pclientes.sendtoback;
    pgrupos.Visible:=true;
    tbuscargrupo.Text:=dm.qgruposclientesnomgrupo.AsString;
end;

procedure TMENU.DBGrid27DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
    if dm.qgruposplazas_libres.Asinteger<=0 then
    begin
        DBGrid27.Canvas.brush.Color := rojo;
    end else DBGrid27.Canvas.brush.Color := verde;
    DBGrid27.DefaultDrawColumnCell(Rect, DataCol, Column, State);

end;

procedure TMENU.DBGrid28CellClick(Column: TColumn);
var id,id2:string;
    posicion:integer;
begin
{    id:=dm.qrecibosclienteid.AsString;
    id2:=dm.qreciboscliente2id.AsString;
    posicion:=dbgrid28.DataSource.DataSet.RecNo;
    if column.Field.FieldName ='pagado' then
    begin
       if dbgrid28.DataSource=dm.dsqreciboscliente then
       begin
           if dm.qrecibosclientepagado.asinteger=1 then
           begin
             qaux.Close;
             qaux.SQL.Clear;
             qaux.SQL.Add('update cobros set pagado=0 where id='+dm.qrecibosclienteid.AsString);
             qaux.ExecSQL;
             dbgrid28.selectedIndex:=1;
           end else
                 begin
                   qaux.Close;
                   qaux.SQL.Clear;
                   qaux.SQL.Add('update cobros set pagado=1 where id='+dm.qrecibosclienteid.AsString);
                   qaux.ExecSQL;
                   dbgrid28.SelectedIndex:=1;
                 end;
       end else
           begin
           if (dm.qreciboscliente2pagado.asinteger=1) then
           begin
             qaux.Close;
             qaux.SQL.Clear;
             qaux.SQL.Add('update cobros set pagado=0 where id='+dm.qreciboscliente2id.AsString);
             qaux.ExecSQL;
             dbgrid28.selectedIndex:=1;
           end else
                 begin
                   qaux.Close;
                   qaux.SQL.Clear;
                   qaux.SQL.Add('update cobros set pagado=1 where id='+dm.qreciboscliente2id.AsString);
                   qaux.ExecSQL;
                   dbgrid28.SelectedIndex:=1;
                 end;
           end;
    end;
{    if column.Field.FieldName ='seleccionado' then
    begin
       if dbgrid28.DataSource=dm.dsqreciboscliente then
       begin
           if dm.qrecibosclienteseleccionado.asinteger=1 then
           begin
               qaux.Close;
               qaux.SQL.Clear;
               qaux.SQL.Add('update cobros set seleccionado=0 where id='+dm.qrecibosclienteid.AsString);
               qaux.ExecSQL;
               dbgrid28.selectedIndex:=1;
           end else
                 begin
                   qaux.Close;
                   qaux.SQL.Clear;
                   qaux.SQL.Add('update cobros set seleccionado=1 where id='+dm.qrecibosclienteid.AsString);
                   qaux.ExecSQL;
                   dbgrid28.SelectedIndex:=1;
                 end;
       end else
       begin
           if (dm.qreciboscliente2.Active) and  (dm.qreciboscliente2seleccionado.asinteger=1) then
                begin
                   qaux.Close;
                   qaux.SQL.Clear;
                   qaux.SQL.Add('update cobros set seleccionado=0 where id='+dm.qreciboscliente2id.AsString);
                   qaux.ExecSQL;
                   dbgrid28.selectedIndex:=1;
                 end else
                      begin
                         qaux.Close;
                         qaux.SQL.Clear;
                         qaux.SQL.Add('update cobros set seleccionado=1 where id='+dm.qreciboscliente2id.AsString);
                         qaux.ExecSQL;
                         dbgrid28.SelectedIndex:=1;
                      end;
                 end;
       end;
    if column.Field.FieldName ='domiciliado' then
    begin
    if dbgrid28.DataSource=dm.dsqreciboscliente then
       begin
           if dm.qrecibosclientedomiciliado.asinteger=1 then
           begin
               qaux.Close;
               qaux.SQL.Clear;
               qaux.SQL.Add('update cobros set domiciliado=0 where id='+dm.qrecibosclienteid.AsString);
               qaux.ExecSQL;
             dbgrid28.selectedIndex:=1;
           end else
                 begin
                   qaux.Close;
                   qaux.SQL.Clear;
                   qaux.SQL.Add('update cobros set domiciliado=1 where id='+dm.qrecibosclienteid.AsString);
                   qaux.ExecSQL;
                   dbgrid28.SelectedIndex:=1;
                 end;
       end else
       begin
           if (dm.qreciboscliente2.Active) and  (dm.qreciboscliente2domiciliado.asinteger=1) then
           begin
             qaux.Close;
             qaux.SQL.Clear;
             qaux.SQL.Add('update cobros set domiciliado=0 where id='+dm.qreciboscliente2id.AsString);
             qaux.ExecSQL;
             dbgrid28.selectedIndex:=1;
           end else
                 begin
                   qaux.Close;
                   qaux.SQL.Clear;
                   qaux.SQL.Add('update cobros set domiciliado=1 where id='+dm.qreciboscliente2id.AsString);
                   qaux.ExecSQL;
                   dbgrid28.SelectedIndex:=1;
                 end;
       end;
    end;
    if column.Field.FieldName ='material' then
    begin
       if dbgrid28.DataSource=dm.dsqreciboscliente then
       begin
           if dm.qrecibosclientematerial.asinteger=1 then
           begin
             qaux.Close;
             qaux.SQL.Clear;
             qaux.SQL.Add('update cobros set material=0 where id='+dm.qrecibosclienteid.AsString);
             qaux.ExecSQL;
             dbgrid28.selectedIndex:=1;
           end else
                 begin
                   qaux.Close;
                   qaux.SQL.Clear;
                   qaux.SQL.Add('update cobros set material=1 where id='+dm.qrecibosclienteid.AsString);
                   qaux.ExecSQL;
                   dbgrid28.SelectedIndex:=1;
                 end;

       end else
       begin
           if dm.qreciboscliente2material.asinteger=1 then
           begin
               qaux.Close;
               qaux.SQL.Clear;
               qaux.SQL.Add('update cobros set material=0 where id='+dm.qreciboscliente2id.AsString);
               qaux.ExecSQL;
               dbgrid28.selectedIndex:=1;
           end else
                 begin
                   qaux.Close;
                   qaux.SQL.Clear;
                   qaux.SQL.Add('update cobros set material=1 where id='+dm.qreciboscliente2id.AsString);
                   qaux.ExecSQL;
                   dbgrid28.SelectedIndex:=1;
                 end;
       end;
    end;
    dm.qreciboscliente2.Refresh;
    dm.qreciboscliente.Refresh;
    dm.qreciboscliente.Locate('id',id,[locaseinsensitive]);
    dm.qreciboscliente2.Locate('id',id2,[locaseinsensitive]);
}
end;

procedure TMENU.DBGrid28DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[Boolean] of Integer =
 (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
//    dm.recibos.MasterSource:=nil;
if dm.qreciboscliente2.Active=false then dm.qreciboscliente2.Open;
    if dbgrid28.DataSource=dm.dsqreciboscliente then
        begin
        if dm.qrecibosclientepagado.Asinteger=0 then
        begin
            DBgrid28.Canvas.brush.Color := rojo;
        end;
        DBgrid28.DefaultDrawColumnCell(Rect, DataCol, Column, State);
        if dm.qrecibosclienteseleccionado.Asinteger=1 then
        begin
            DBgrid28.Canvas.brush.Color := amarillo;
        end;
        DBgrid28.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
    if dbgrid28.DataSource=dm.dsqreciboscliente2 then
        begin
        if dm.qreciboscliente2pagado.Asinteger=0 then
        begin
            DBgrid28.Canvas.brush.Color := rojo;
        end;
        DBgrid28.DefaultDrawColumnCell(Rect, DataCol, Column, State);
        if dm.qreciboscliente2seleccionado.Asinteger=1 then
        begin
            DBgrid28.Canvas.brush.Color := amarillo;
        end;
        DBgrid28.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;

// dibujar check

if (gdFocused in State) then
begin

    if (Column.Field.FieldName = 'pagado') then
     begin
       gcrpagado.Left := Rect.Left + DBgrid28.Left + 2;
       gcrpagado.Top := Rect.Top + DBgrid28.top + 2;
       gcrpagado.Width := Rect.Right - Rect.Left;
       gcrpagado.Height := Rect.Bottom - Rect.Top;
       gcrpagado.Visible := True;
     end;

    if (Column.Field.FieldName = 'domiciliado') then
    begin
      gcrpagado.Left := Rect.Left + DBgrid28.Left + 2;
      gcrpagado.Top := Rect.Top + DBgrid28.top + 2;
      gcrpagado.Width := Rect.Right - Rect.Left;
      gcrpagado.Height := Rect.Bottom - Rect.Top;
      gcrpagado.Visible := True;
    end;
    if (Column.Field.FieldName = 'material') then
    begin
      gcrpagado.Left := Rect.Left + DBgrid28.Left + 2;
      gcrpagado.Top := Rect.Top + DBgrid28.top + 2;
      gcrpagado.Width := Rect.Right - Rect.Left;
      gcrpagado.Height := Rect.Bottom - Rect.Top;
      gcrpagado.Visible := True;
    end;

end else
     begin
       
       if (Column.Field.FieldName = 'pagado') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
      //   DrawState := ISChecked[Column.Field.Asboolean];
         DBgrid28.Canvas.FillRect(Rect);
         DrawFrameControl(DBgrid28.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;

       if (Column.Field.FieldName = 'domiciliado') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
      //   DrawState := ISChecked[Column.Field.Asboolean];
         DBgrid28.Canvas.FillRect(Rect);
         DrawFrameControl(DBgrid28.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;
       if (Column.Field.FieldName = 'material') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
      //   DrawState := ISChecked[Column.Field.Asboolean];
         DBgrid28.Canvas.FillRect(Rect);
         DrawFrameControl(DBgrid28.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;

     end;
//    if nuevorecibo=1 then dm.recibos.MasterSource:=dm.dsqreciboscliente;
//    if nuevorecibo=2 then dm.recibos.MasterSource:=dm.dsqreciboscliente2;


end;

procedure TMENU.DBGrid28TitleClick(Column: TColumn);
var
  st,ST2:ZAbstractRODataset.TSortType;
begin
    if dbgrid28.DataSource=dm.dsqreciboscliente then
    begin
      st:=dm.qreciboscliente.SortType;
      dm.qreciboscliente.SortedFields:='PAGADO,'+Column.FieldName;
      If st = stAscending then dm.qreciboscliente.SortType:=stDescending else dm.qreciboscliente.SortType:=stAscending;
      dm.dsqreciboscliente.DataSet.First;
    end;
    if dbgrid28.DataSource=dm.dsqreciboscliente2 then
    begin
      st:=dm.qreciboscliente2.SortType;
      dm.qreciboscliente2.SortedFields:='PAGADO,'+Column.FieldName;
      If st = stAscending then dm.qreciboscliente2.SortType:=stDescending else dm.qreciboscliente2.SortType:=stAscending;
      dm.dsqreciboscliente2.DataSet.First;
    end;
end;

procedure TMENU.DBGrid3DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[Boolean] of Integer =
 (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
 DrawRect: TRect;
begin
if (gdFocused in State) then
begin
    if (Column.Field.FieldName = 'devoluciones') then
     begin
       gcrpagado.Left := Rect.Left + DBGrid3.Left + 2;
       gcrpagado.Top := Rect.Top + DBGrid3.top + 2;
       gcrpagado.Width := Rect.Right - Rect.Left;
       gcrpagado.Height := Rect.Bottom - Rect.Top;
       gcrpagado.Visible := True;
     end;
end else
     begin
       if (Column.Field.FieldName = 'devoluciones') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
      //   DrawState := ISChecked[Column.Field.Asboolean];
         DBGrid3.Canvas.FillRect(Rect);
         DrawFrameControl(DBGrid3.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;
    end;
end;

procedure TMENU.DBGrid5CellClick(Column: TColumn);
begin
    if column.Field.FieldName ='pagado' then
    begin
       if dm.qrecibosempleadospagado.asinteger=1 then
       begin
         dm.qrecibosempleados.Edit;
         dm.qrecibosempleadospagado.Value:=0;
         dm.qrecibosempleados.Post;
         dbgrid5.SelectedIndex:=1;
       end else
             begin
               dm.qrecibosempleados.Edit;
               dm.qrecibosempleadospagado.Value:=1;
               dm.qrecibosempleados.Post;
               dbgrid5.SelectedIndex:=1;
             end;
    end;

end;

procedure TMENU.DBGrid5DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
const IsChecked : array[Boolean] of Integer =
 (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
  DrawState: Integer;
  DrawRect: TRect;
begin
    if dm.qrecibosempleadospagado.Asinteger=0 then
    begin
        DBGrid5.Canvas.brush.Color := rojo;
    end;
    DBGrid5.DefaultDrawColumnCell(Rect, DataCol, Column, State);
// dibujar check

if (gdFocused in State) then
begin
    if (Column.Field.FieldName = 'pagado') then
     begin
       gcrpagado.Left := Rect.Left + DBGrid5.Left + 2;
       gcrpagado.Top := Rect.Top + DBGrid5.top + 2;
       gcrpagado.Width := Rect.Right - Rect.Left;
       gcrpagado.Height := Rect.Bottom - Rect.Top;
       gcrpagado.Visible := True;
     end;

end else
     begin
       if (Column.Field.FieldName = 'pagado') then
       begin
         DrawRect:=Rect;
         InflateRect(DrawRect,-1,-1);
         if column.Field.Asinteger=0  then DrawState := ischecked[false];
         if column.Field.Asinteger=1  then DrawState := ischecked[true];
        // DrawState := ISChecked[Column.Field.Asboolean];
         DBGrid5.Canvas.FillRect(Rect);
         DrawFrameControl(DBGrid5.Canvas.Handle, DrawRect,
         DFC_BUTTON, DrawState);
       end;
     end;
end;

procedure TMENU.DBGrid8DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
    if dm.qgrupocursoplazas_libres.Asinteger<=0 then
    begin
        DBGrid8.Canvas.brush.Color := rojo;
    end else DBGrid8.Canvas.brush.Color := verde;
    DBGrid8.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

procedure TMENU.DBGrid9DblClick(Sender: TObject);
begin
    pcursos.sendtoback;
    palumnos.Visible:=true;
    palumnos.BringToFront;
    tbuscaralumnos.Text:=dm.qgrupoalumnosnombre_completo.AsString;
end;

procedure TMENU.DBLookupComboBox2Exit(Sender: TObject);
begin
    if dm.grupos.State in [dsedit,dsinsert] then
       dm.gruposcurso.Value:=dm.qcursosanyo_escolar.AsString;
end;

procedure TMENU.DBLookupComboBox5Exit(Sender: TObject);
begin
    dm.recibosforma_pago.Value:=dm.clientesidfp.AsInteger;
end;

procedure TMENU.dsqalumnosDataChange(Sender: TObject; Field: TField);
begin
//    pagecontrol1.ActivePageIndex:=0;
end;

procedure TMENU.dsqgrupoalumnosDataChange(Sender: TObject; Field: TField);
begin
  if qgrupoalumnos.RecordCount>0 then
  begin
      qimagen.Close;
      qimagen.SQL.Clear;
      qimagen.SQL.Add('select * from imagenes where ide='+inttostr(centro)+' and (tipo='+''''+'.jpg'+''''+' or tipo='+''''+'.jpeg'+''''+' or tipo='+''''+'.bmp'+''''+') and idalumno='+qgrupoalumnosida.asstring+' order by id desc');
      qimagen.Open;
  end;
end;

procedure TMENU.dsqimagenDataChange(Sender: TObject; Field: TField);
var img:TPicture;
//    blob: TblobStream;
    Jpg : TJPEGImage;
    bmp : Tbitmap;
    imagen : TPicture;
    ext:string;
begin
    if qimagen.RecordCount>0 then
    begin
        sesionimagen.Picture:=nil;
        ext:=qimagentipo.AsString;
        qimagenimagen.savetofile('c:\formagest\temp'+ext);
        if (ext='.jpg') or (ext='.jpeg') then
        begin
           imagen := TPicture.Create;
           bmp:= TBitmap.Create;
           imagen.LoadFromFile('c:\formagest\temp'+ext);//'c:\formagest\imagenes\'+dm.alumnosid.asstring+'.jpg');
           Bmp.Width:= Imagen.Width;
           Bmp.Height:= Imagen.Height;
//           Bmp.Canvas.StretchDraw(canvas.ClipRect,bmp);// draw(0,0,Imagen.Graphic);//
           bmp.Assign(imagen.Graphic);
           Bmp.SaveToFile('c:\formagest\temp.bmp');
           bmp.Free;
           bmp:=nil;
           imagen.Graphic:=nil;
        end;

        if (ext='.jpg') or (ext='.jpeg') or (ext='.bmp') then
        begin
            sesionimagen.Picture:=nil;
            sesionimagen.Picture.LoadFromFile('c:\formagest\temp'+ext);
        end;
    end;
    if qimagen.RecordCount=0 then
    begin
        sesionimagen.Picture:=nil;
    end;
if FileExists('c:\formagest\temp.bmp') then
begin
    DeleteFile('c:\formagest\temp.bmp');

end;
if FileExists('c:\formagest\temp'+ext) then
begin
    DeleteFile('c:\formagest\temp'+ext);
end;
//    imagen.Free;
//    bmp.free;

end;

procedure TMENU.YoungLearners2Click(Sender: TObject);
var nota:real;
begin
dminf.qboletin.Close;
qaux.SQL.Clear;
qaux.SQL.Add('delete from boletin');
qaux.ExecSQL;
dminf.qboletin.Open;
dm.notas.close;
dm.notas.Open;
dm.qgrupoalumnos2.first;

while not dm.qgrupoalumnos2.Eof do
begin
  dm.notas.Filtered:=false;
  dm.notas.Filter:='ida='+dm.qgrupoalumnos2id.AsString+' and ide='+inttostr(centro)+' and idg='+dm.qgruposid.AsString;
  dm.notas.Filtered:=true;
  dminf.qboletin.Append;
  dminf.qboletingrupo.Value:=dm.qgruposnombre.asstring;
  dminf.qboletinprofesor.Value:=qtutoresnombre_completo.AsString;//dm.qgruposprofesor.AsString;dm.qgruposprofesor.AsString;
  dminf.qboletinalumno.Value:=dm.qgrupoalumnos2nombre_completo.AsString;
  dminf.qboletinfechaeval1.value:=dm.notasfechaeval1.asdatetime;
  dminf.qboletinlistening1.value:=dm.notaslistening1.asfloat;
  nota:=dminf.qboletinlistening1.asfloat;
  if (nota=0) then dminf.qboletinimglist1.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist1.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist1.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist1.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist1.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist1.value:='c:\formagest\documentos\5oreja.bmp';
  dminf.qboletinspeaking1.value:=dm.notasspeaking1.asfloat;
  nota:=dminf.qboletinspeaking1.asfloat;
  if (nota=0) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading1.value:=dm.notasreading1.asfloat;
  nota:=dminf.qboletinreading1.asfloat;
  if (nota=0) then dminf.qboletinimgread1.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread1.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread1.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread1.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread1.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread1.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting1.value:=dm.notaswriting1.asfloat;
  nota:=dminf.qboletinwriting1.asfloat;
  if (nota=0) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary1.value:=dm.notasvocabulary1.asfloat;
  nota:=dminf.qboletinvocabulary1.asfloat;
  if (nota=0) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\noevaluado2.bmp'; //'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo1.value:=dm.notasdesarrollo1.asfloat;
  nota:=dminf.qboletindesarrollo1.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletinfechaeval2.value:=dm.notasfechaeval2.asdatetime;
  dminf.qboletinlistenig2.value:=dm.notaslistenig2.asfloat;
  nota:=dminf.qboletinlistenig2.asfloat;
  if (nota=0) then dminf.qboletinimglist2.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist2.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist2.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist2.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist2.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist2.value:='c:\formagest\documentos\5oreja.bmp';

  dminf.qboletinspeaking2.value:=dm.notasspeaking2.asfloat;
  nota:=dminf.qboletinspeaking2.asfloat;
  if (nota=0) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading2.value:=dm.notasreading2.asfloat;
  nota:=dminf.qboletinreading2.asfloat;
  if (nota=0) then dminf.qboletinimgread2.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread2.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread2.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread2.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread2.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread2.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting2.value:=dm.notaswriting2.asfloat;
  nota:=dminf.qboletinwriting2.asfloat;
  if (nota=0) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary2.value:=dm.notasvocabulary2.asfloat;
  nota:=dminf.qboletinvocabulary2.asfloat;
  if (nota=0) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo2.value:=dm.notasdesarrollo2.asfloat;
  nota:=dminf.qboletindesarrollo2.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletinlistening3.value:=dm.notaslistening3.asfloat;
  nota:=dminf.qboletinlistening3.asfloat;
  if (nota=0) then dminf.qboletinimglist3.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist3.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist3.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist3.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist3.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist3.value:='c:\formagest\documentos\5oreja.bmp';
  dminf.qboletinspeaking3.value:=dm.notasspeaking3.asfloat;
  nota:=dminf.qboletinspeaking3.asfloat;
  if (nota=0) then dminf.qboletinimgspeak3.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak3.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak3.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak3.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak3.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak3.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading3.value:=dm.notasreading3.asfloat;
  nota:=dminf.qboletinreading3.asfloat;
  if (nota=0) then dminf.qboletinimgread3.value:='c:\formagest\documentos\noevaluado.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread3.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread3.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread3.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread3.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread3.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting3.value:=dm.notaswriting3.asfloat;
  nota:=dminf.qboletinwriting3.asfloat;
  if (nota=0) then dminf.qboletinimgwrit3.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit3.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit3.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit3.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit3.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit3.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary3.value:=dm.notasvocabulary3.asfloat;
  nota:=dminf.qboletinvocabulary3.asfloat;
  if (nota=0) then dminf.qboletinimgvocab3.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab3.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab3.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab3.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab3.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab3.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo3.value:=dm.notasdesarrollo3.asfloat;
  nota:=dminf.qboletindesarrollo3.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr3.value:='c:\formagest\documentos\noevaluado2.bmp';//'c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr3.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr3.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr3.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr3.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr3.value:='c:\formagest\documentos\5ok.bmp';


  dminf.qboletinobservaciones2.value:=dm.notasobservaciones2.AsString;
  dminf.qboletinnota1eval.value:=dm.notasnota1eval.Asfloat;
  dminf.qboletinnota2eval.value:=dm.notasnota2eval.Asfloat;
  dminf.qboletinnotafinal.value:=dm.notasnotafinal.Asfloat;
  dminf.qboletin.Post;
  dm.qgrupoalumnos2.Next;
end;

   dm.notas.Filtered:=false;

    dminf.qboletin.Open;
    informedb.Datasource:=dminf.dsqboletin;
    informe.Report.Clear;
    informe.LoadFromFile('c:\formagest\informes\boletinyoung_2.fr3');
//    informes.Report.FileName:=TMES.Text+' ' + qjornalestrabajador.asstring;
    informe.PrintOptions.Printer:=tprinter2;
    informe.ShowReport();
    informe.Clear;


end;

procedure TMENU.Empleados1Click(Sender: TObject);
begin
    btempleados.Click;
end;

procedure TMENU.Estadisticas2Click(Sender: TObject);
begin
    estadisticas := Testadisticas.Create(nil);
    try
      estadisticas.showmodal();
    finally
      estadisticas.Free;
    end;
end;

procedure TMENU.ExportardatosdeAlumnos1Click(Sender: TObject);
var  archivo:string;
     //pgb:tprogressbar;
begin
    btalumnos.Click;
    dminf.qtodosalumnos.Close;
    dminf.qtodosalumnos.Open;
    savedialog1.FileName:='DatosAlumnos.xlsx';
    savedialog1.Execute();
    archivo:=savedialog1.FileName;
//    archivo:='c:\formagest\profesoresgrupo.xlsx';
    try
    Exportaraexcel(archivo,'ALUMNOS',gridtodosalumnos);
    finally
      showmessage('Los datos han sido exportados correctamente a '+archivo);
    end;

end;

procedure TMENU.tbuscarclientesrecibosEnter(Sender: TObject);
begin
    tbuscarclientesrecibos.Text:='';
end;

procedure TMENU.tbuscarclientesrecibosExit(Sender: TObject);
begin
    if tbuscarclientesrecibos.text<>'' then
    begin
        dm.filtro:='%'+tbuscarclientesrecibos.Text+'%';

    end else dm.filtro:='';
    if todosclientesrecibos.Checked then dm.vertodos:=1 else dm.vertodos:=0;
    dm.qclientes.Close;
    dm.qclientes.open;
end;

procedure TMENU.Facturas1Click(Sender: TObject);
begin
    facturas := Tfacturas.Create(nil);
    try
      facturas.showmodal();
    finally
      facturas.Free;
    end;
end;

procedure TMENU.FormCreate(Sender: TObject);
var
  I: Integer;
begin
   Application.OnMessage :=  AppMessage;
   gcrpagado.DataField := 'pagado';
   gcrpagado.Visible := False;
   gcrpagado.SendToBack;
   gcrpagado.Color := 0;//DBGrid2.Color;
   gcrpagado.Caption := '';

   //explained later in the article
   gcrpagado.ValueChecked := '0';
   gcrpagado.ValueUnChecked := '1';
   for I := 0 to (menuprincipal.Items.Count-1) do
   begin
      menuprincipal.Items[i].Enabled:=false;
   end;
   nuevorecibo:=1;
end;

procedure TMENU.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
    if (activecontrol is tdbgrid) then
    begin
        if Key = 13 then Key :=9;
    end;
end;

procedure TMENU.FormKeyPress(Sender: TObject; var Key: Char);
begin
    if not (activecontrol is tdbMemo) then
    begin
      key:=upcase(key);

    end;
    if (key='.') and (activecontrol is tdbedit) then
    begin
       key:=','
    end;
    if (key='.') and (activecontrol is tdbgrid) then
    begin
        key:=',';
    end;
    if (activecontrol is tdbgrid) then
    begin
        if Key = #13 then Key :=#9;
    end;

    if (key=#13) then
    begin
        Perform(WM_NextDLGCtl,0,0);
        key:=#0;
    end;

    if (key ='.')
    //and (DMGS.CDSQ_mdalbaran.State in [dsedit,dsinsert])
    and (activecontrol is tdbedit)
    then
      if (activecontrol is tdbedit) then
          key := ',';
    if (ActiveControl=nil) and (key=#13) then
    begin
        Perform(WM_NextDLGCtl, 0, 0);
        key:=#0;
    end;
{    if (key = #13) and not (ActiveControl is TButton) and not (ActiveControl is TDBGrid) then
    begin
      Perform(WM_NextDLGCtl, 0, 0);
      key:=#0;
      // ANTERIORMENTE SE CONTROLABA AQUI CUANDO SE HACIA EL ".POST" PERO EN ESTA UNIDAD SE HACE
      // EN DBEDIT8.EXIT.
    end;
}
   if (key = #13) then
    begin
//       if dbgrid1.Focused then
     IF (ACTIVECONTROL IS TDBGRID) THEN
       begin
        if dbgrid1.SelectedIndex = (dbgrid1.FieldCount - 1) then
        begin
          dbgrid1.selectedindex := 0;
        end
        else
           dbgrid1.SelectedIndex := dbgrid1.SelectedIndex + 1;
       end
       else
//       if fechas(sender) then
          Perform(WM_NextDLGCtl, 0, 0);
          key:=#0;
    end;

    if not (activeControl is TDBEdit) THEN
//    (ActiveControl is TDBGrid) then
    begin
{       if uppercase(key)='A' then if BAltas.enabled then BAltas.click;
       if uppercase(key)='B' then if BBajas.enabled then BBajas.click;
       if uppercase(key)='C' then if BConsultas.enabled then BConsultas.click;
       if uppercase(key)='M' then if BModificaciones.enabled then BModificaciones.click;
       if uppercase(key)='D' then if BListado.enabled then BListado.click;
       if not (DMGS.CDSQ_MDLINEAALBARAN.state in [dsedit,dsinsert]) then
       begin
           if uppercase(key)='L' then if BAltas2.enabled then
           begin
               BAltas2.click;
               key:=#0;
           end;
           if uppercase(key)='J' then if Bbajas2.enabled then
           begin
               Bbajas2.click;
               key:=#0;
           end;
           if uppercase(key)='F' then if Bmodificar2.enabled then
           begin
               Bmodificar2.click;
               key:=#0;
           end;
       end; }
    end;
{    IF (( NOT (DMGS.CDSQ_MDLINEAALBARAN.State IN [DSEDIT,DSINSERT]))) THEN
    begin
       if uppercase(key)='A' then if BAltas.enabled then BAltas.click;
       if uppercase(key)='B' then if BBajas.enabled then BBajas.click;
       if uppercase(key)='C' then if BConsultas.enabled then BConsultas.click;
       if uppercase(key)='M' then if BModificaciones.enabled then BModificaciones.click;
//       if uppercase(key)='L' then if BListado.enabled then BListado.click;
       if ( key <> #27 ) then
           key:=#0;
    end;
}
{    if (key = #27) and not ((DMGS.CDSQ_MDALBARAN.state in [dsedit,dsinsert]))
            then close;
    if (key = #27) and (DMGS.CDSQ_MDALBARAN.state in [dsedit,dsinsert])
       and (not( dmgs.cdsq_MDLINEAALBARAN.state in [dsedit,dsinsert]))
    then
       if DMGS.RALBARAN.BUSCANDO then
          buscar
       ELSE
          DMGS.CDSQ_MDALBARAN.Post;}
end;
procedure TMENU.FormShow(Sender: TObject);
begin
   dm.empresa.Open;
end;

procedure TMENU.Grupos1Click(Sender: TObject);
begin
    btgrupos.Click;
end;

procedure TMENU.imgfoto2DblClick(Sender: TObject);
var nomarchivo:string;
begin
    nomarchivo:='empimg'+dmalumnos.imagenes_alumnostipo.AsString;
    ShellExecute(Handle,nil,PChar('c:\formagest\tmp\'+nomarchivo),'','',SW_SHOWNORMAL);
end;

procedure TMENU.Libros1Click(Sender: TObject);
begin
    libros := Tlibros.Create(nil);
    try
      libros.showmodal();
    finally
      libros.Free;
    end;
end;

procedure TMENU.MenuItem1Click(Sender: TObject);
begin
   bteimagen.Caption:='Cargar imagen';
   bteimagen.Click;
end;

procedure TMENU.MenuItem2Click(Sender: TObject);
begin
    bteimagen.Caption:='Capturar imagen';
    panelfotoe.Visible:=true;
    imgfotoe.Visible:=true;
    btactivarcamarae.Click;
end;

procedure TMENU.Niveles1Click(Sender: TObject);
begin
    niveles := Tniveles.Create(nil);
    try
      niveles.showmodal();
    finally
      niveles.Free;
    end;
end;

procedure TMENU.Normal1Click(Sender: TObject);
var nota:real;
begin
dminf.qboletin.Close;
qaux.SQL.Clear;
qaux.SQL.Add('delete from boletin');
qaux.ExecSQL;
dminf.qboletin.Open;
dm.notas.close;
dm.notas.Open;
dm.qgrupoalumnos2.first;

while not dm.qgrupoalumnos2.Eof do
begin
  dm.notas.Filtered:=false;
  dm.notas.Filter:='ida='+dm.qgrupoalumnos2id.AsString+' and ide='+inttostr(centro)+' and idg='+dm.qgruposid.AsString;
  dm.notas.Filtered:=true;
  dminf.qboletin.Append;
  dminf.qboletingrupo.Value:=dm.qgruposnombre.asstring;
  dminf.qboletinprofesor.Value:=qtutoresnombre_completo.AsString;//dm.qgruposprofesor.AsString;dm.qgruposprofesor.AsString;
  dminf.qboletinalumno.Value:=dm.qgrupoalumnos2nombre_completo.AsString;
  dminf.qboletinfechaeval1.value:=dm.notasfechaeval1.asdatetime;
  dminf.qboletinlistening1.value:=dm.notaslistening1.asfloat;
  nota:=dminf.qboletinlistening1.asfloat;
  if (nota=0) then dminf.qboletinimglist1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist1.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist1.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist1.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist1.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist1.value:='c:\formagest\documentos\5oreja.bmp';
  dminf.qboletinspeaking1.value:=dm.notasspeaking1.asfloat;
  nota:=dminf.qboletinspeaking1.asfloat;
  if (nota=0) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading1.value:=dm.notasreading1.asfloat;
  nota:=dminf.qboletinreading1.asfloat;
  if (nota=0) then dminf.qboletinimgread1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread1.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread1.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread1.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread1.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread1.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting1.value:=dm.notaswriting1.asfloat;
  nota:=dminf.qboletinwriting1.asfloat;
  if (nota=0) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary1.value:=dm.notasvocabulary1.asfloat;
  nota:=dminf.qboletinvocabulary1.asfloat;
  if (nota=0) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo1.value:=dm.notasdesarrollo1.asfloat;
  nota:=dminf.qboletindesarrollo1.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletinfechaeval2.value:=dm.notasfechaeval2.asdatetime;
  dminf.qboletinlistenig2.value:=dm.notaslistenig2.asfloat;
  nota:=dminf.qboletinlistenig2.asfloat;
  if (nota=0) then dminf.qboletinimglist2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist2.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist2.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist2.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist2.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist2.value:='c:\formagest\documentos\5oreja.bmp';

  dminf.qboletinspeaking2.value:=dm.notasspeaking2.asfloat;
  nota:=dminf.qboletinspeaking2.asfloat;
  if (nota=0) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading2.value:=dm.notasreading2.asfloat;
  nota:=dminf.qboletinreading2.asfloat;
  if (nota=0) then dminf.qboletinimgread2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread2.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread2.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread2.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread2.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread2.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting2.value:=dm.notaswriting2.asfloat;
  nota:=dminf.qboletinwriting2.asfloat;
  if (nota=0) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary2.value:=dm.notasvocabulary2.asfloat;
  nota:=dminf.qboletinvocabulary2.asfloat;
  if (nota=0) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo2.value:=dm.notasdesarrollo2.asfloat;
  nota:=dminf.qboletindesarrollo2.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletinobservaciones2.value:=dm.notasobservaciones2.AsString;
  dminf.qboletinnota1eval.value:=dm.notasnota1eval.Asfloat;
  dminf.qboletinnota2eval.value:=dm.notasnota2eval.Asfloat;
  dminf.qboletinnotafinal.value:=dm.notasnotafinal.Asfloat;
  dminf.qboletin.Post;
  dm.qgrupoalumnos2.Next;
end;

   dm.notas.Filtered:=false;

    dminf.qboletin.Open;
    informedb.Datasource:=dminf.dsqboletin;
    informe.Report.Clear;
    informe.LoadFromFile('c:\formagest\informes\boletin_2.fr3');
//    informes.Report.FileName:=TMES.Text+' ' + qjornalestrabajador.asstring;
    informe.PrintOptions.Printer:=tprinter2;
    informe.ShowReport();
    informe.Clear;

end;

procedure TMENU.Normal2Click(Sender: TObject);
var nota:real;
begin
dminf.qboletin.Close;
qaux.SQL.Clear;
qaux.SQL.Add('delete from boletin');
qaux.ExecSQL;
dminf.qboletin.Open;
dm.notas.close;
dm.notas.Open;
dm.qgrupoalumnos2.first;

while not dm.qgrupoalumnos2.Eof do
begin
  dm.notas.Filtered:=false;
  dm.notas.Filter:='ida='+dm.qgrupoalumnos2id.AsString+' and ide='+inttostr(centro)+' and idg='+dm.qgruposid.AsString;
  dm.notas.Filtered:=true;
  dminf.qboletin.Append;
  dminf.qboletingrupo.Value:=dm.qgruposnombre.asstring;
  dminf.qboletinprofesor.Value:=qtutoresnombre_completo.AsString;//dm.qgruposprofesor.AsString;
  dminf.qboletinalumno.Value:=dm.qgrupoalumnos2nombre_completo.AsString;
  dminf.qboletinfechaeval1.value:=dm.notasfechaeval1.asdatetime;
  dminf.qboletinlistening1.value:=dm.notaslistening1.asfloat;
  nota:=dminf.qboletinlistening1.asfloat;
  if (nota=0) then dminf.qboletinimglist1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist1.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist1.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist1.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist1.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist1.value:='c:\formagest\documentos\5oreja.bmp';
  dminf.qboletinspeaking1.value:=dm.notasspeaking1.asfloat;
  nota:=dminf.qboletinspeaking1.asfloat;
  if (nota=0) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak1.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading1.value:=dm.notasreading1.asfloat;
  nota:=dminf.qboletinreading1.asfloat;
  if (nota=0) then dminf.qboletinimgread1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread1.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread1.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread1.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread1.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread1.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting1.value:=dm.notaswriting1.asfloat;
  nota:=dminf.qboletinwriting1.asfloat;
  if (nota=0) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit1.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary1.value:=dm.notasvocabulary1.asfloat;
  nota:=dminf.qboletinvocabulary1.asfloat;
  if (nota=0) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab1.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo1.value:=dm.notasdesarrollo1.asfloat;
  nota:=dminf.qboletindesarrollo1.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr1.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletinfechaeval2.value:=dm.notasfechaeval2.asdatetime;
  dminf.qboletinlistenig2.value:=dm.notaslistenig2.asfloat;
  nota:=dminf.qboletinlistenig2.asfloat;
  if (nota=0) then dminf.qboletinimglist2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimglist2.value:='c:\formagest\documentos\1oreja.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimglist2.value:='c:\formagest\documentos\2oreja.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimglist2.value:='c:\formagest\documentos\3oreja.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimglist2.value:='c:\formagest\documentos\4oreja.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimglist2.value:='c:\formagest\documentos\5oreja.bmp';

  dminf.qboletinspeaking2.value:=dm.notasspeaking2.asfloat;
  nota:=dminf.qboletinspeaking2.asfloat;
  if (nota=0) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\1labios.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\2labios.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\3labios.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\4labios.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgspeak2.value:='c:\formagest\documentos\5labios.bmp';

  dminf.qboletinreading2.value:=dm.notasreading2.asfloat;
  nota:=dminf.qboletinreading2.asfloat;
  if (nota=0) then dminf.qboletinimgread2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgread2.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgread2.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgread2.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgread2.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgread2.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinwriting2.value:=dm.notaswriting2.asfloat;
  nota:=dminf.qboletinwriting2.asfloat;
  if (nota=0) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\1lapiz.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\2lapiz.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\3lapiz.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\4lapiz.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgwrit2.value:='c:\formagest\documentos\5lapiz.bmp';

  dminf.qboletinvocabulary2.value:=dm.notasvocabulary2.asfloat;
  nota:=dminf.qboletinvocabulary2.asfloat;
  if (nota=0) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgvocab2.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletindesarrollo2.value:=dm.notasdesarrollo2.asfloat;
  nota:=dminf.qboletindesarrollo2.asfloat;
  if (nota=0) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\noevaluado.bmp';
  if (nota>0) and (nota<=1) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\1ok.bmp';
  if (nota>1) and (nota<=2) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\2ok.bmp';
  if (nota>2) and (nota<=3) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\3ok.bmp';
  if (nota>3) and (nota<=4) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\4ok.bmp';
  if (nota>4) and (nota<=5) then dminf.qboletinimgdesarr2.value:='c:\formagest\documentos\5ok.bmp';

  dminf.qboletinobservaciones.value:=dm.notasobservaciones.AsString;
  dminf.qboletinnota1eval.value:=dm.notasnota1eval.Asfloat;
  dminf.qboletinnota2eval.value:=dm.notasnota2eval.Asfloat;
  dminf.qboletinnotafinal.value:=dm.notasnotafinal.Asfloat;
  dminf.qboletin.Post;
  dm.qgrupoalumnos2.Next;
end;

   dm.notas.Filtered:=false;

    dminf.qboletin.Open;
    informedb.Datasource:=dminf.dsqboletin;
    informe.Report.Clear;
    informe.LoadFromFile('c:\formagest\informes\boletin_1.fr3');
//    informes.Report.FileName:=TMES.Text+' ' + qjornalestrabajador.asstring;
    informe.PrintOptions.Printer:=tprinter2;
    informe.ShowReport();
    informe.Clear;


end;

procedure TMENU.PageControl1Change(Sender: TObject);
begin
   if pagecontrol1.ActivePageIndex=1 then
   begin
     dmalumnos.qdocumentosal.Close;
     dmalumnos.qdocumentosal.Prepare;
     dmalumnos.qdocumentosal.ParamByName('PALUMNO').Asstring:=dmalumnos.alumnosid.Asstring;
     dmalumnos.qdocumentosal.ParamByName('PEMPRESA').AsInteger:=dmalumnos.alumnoside.AsInteger;
     dmalumnos.qdocumentosal.Open

   end;
end;

procedure TMENU.Partesdeasistencia1Click(Sender: TObject);
begin
    partes_asistencia := Tpartes_asistencia.Create(nil);
    try
      partes_asistencia.showmodal();
    finally
      partes_asistencia.Free;
    end;
end;

procedure TMENU.Planesdeestudios1Click(Sender: TObject);
begin
    planes := Tplanes.Create(nil);
    try
      planes.showmodal();
    finally
      planes.Free;
    end;
end;

procedure TMENU.Prestamos1Click(Sender: TObject);
begin
    prestamos := Tprestamos.Create(nil);
    try
      prestamos.showmodal();
    finally
      prestamos.Free;
    end;
end;

procedure TMENU.qfaltasAfterPost(DataSet: TDataSet);
begin
    dmalumnos.qfaltas.Refresh;
end;

procedure TMENU.qgrupoalumnosCalcFields(DataSet: TDataSet);
begin
    qgrupoalumnosedad.value:= trunc((date()-qgrupoalumnosfecha_nacimiento.AsDateTime)/365);
end;

procedure TMENU.RadioButton1Click(Sender: TObject);
begin
    dbgrid28.DataSource:=dm.dsqreciboscliente2;
//    dm.recibos.MasterSource:=dm.dsqreciboscliente2;
    dbgrid28.Columns[3].FieldName:='cliente';
    dbgrid28.Columns[3].Title.caption :='Cliente';
        dm.qreciboscliente2.close;
        dm.qreciboscliente2.sql.clear;
        dm.qreciboscliente2.SQL.Add('select co.*,a.nombre_completo as alumno,c.nombre_completo as cliente from cobros co,alumnos a,clientes c where co.ida=a.id and co.idc=c.id and co.ide='+inttostr(centro)+' order by pagado,cliente,fecharecibo desc');
        dm.qreciboscliente2.Open;
end;

procedure TMENU.RadioButton2Click(Sender: TObject);
begin
    dbgrid28.DataSource:=dm.dsqreciboscliente2;
//    dm.recibos.MasterSource:=dm.dsqreciboscliente2;
    dbgrid28.Columns[3].FieldName:='cliente';
    dbgrid28.Columns[3].Title.caption :='Cliente';
    dm.qreciboscliente2.close;
    dm.qreciboscliente2.sql.clear;
    dm.qreciboscliente2.SQL.Add('select co.*,a.nombre_completo as alumno,c.nombre_completo as cliente from cobros co,alumnos a,clientes c where co.ida=a.id and co.idc=c.id and co.ide='+inttostr(centro)+' and co.seleccionado=1 order by pagado,cliente,fecharecibo desc');
    dm.qreciboscliente2.Open;
end;

procedure TMENU.Recibos1Click(Sender: TObject);
begin
    btrecibos.Click;
end;

procedure TMENU.SdelclienteClick(Sender: TObject);
begin
    dbgrid28.DataSource:=dm.dsqreciboscliente;
    dm.recibos.MasterSource:=dm.dsqreciboscliente;
    dbgrid28.Columns[3].FieldName:='alumno';
    dbgrid28.Columns[3].Title.caption :='Alumno';
    dm.qreciboscliente.close;
    dm.qreciboscliente.sql.clear;
    dm.qreciboscliente.SQL.Add('select co.*,a.nombre_completo as alumno,c.nombre_completo as cliente from cobros co,alumnos a,clientes c where co.ida=a.id and co.idc=c.id and co.ide='+inttostr(centro)+' and co.idc='+dm.qclientesid.AsString+' order by pagado,alumno,fecharecibo desc');
    dm.qreciboscliente.Open;
end;

procedure TMENU.StodosClick(Sender: TObject);
begin
    dbgrid28.DataSource:=dm.dsqreciboscliente2;
    dm.recibos.MasterSource:=dm.dsqreciboscliente2;
    dm.qreciboscliente2.close;
    dm.qreciboscliente2.sql.clear;
    dm.qreciboscliente2.SQL.Add('select co.*,a.nombre_completo as alumno,c.nombre_completo as cliente from cobros co,alumnos a,clientes c where co.ida=a.id and co.idc=c.id and co.ide='+inttostr(centro)+' order by cliente,pagado,fecharecibo desc');
    dm.qreciboscliente2.Open;
end;

procedure TMENU.SSincobrarClick(Sender: TObject);
begin
    dbgrid28.DataSource:=dm.dsqreciboscliente2;
    dm.recibos.MasterSource:=dm.dsqreciboscliente2;
    dbgrid28.Columns[3].FieldName:='cliente';
    dbgrid28.Columns[3].Title.caption :='Cliente';

    dm.qreciboscliente2.close;
    dm.qreciboscliente2.sql.clear;
    dm.qreciboscliente2.SQL.Add('select co.*,a.nombre_completo as alumno,c.nombre_completo as cliente from cobros co,alumnos a,clientes c where co.ida=a.id and co.idc=c.id and co.ide='+inttostr(centro)+' and pagado=0 order by cliente,fechacobro desc,fecharecibo desc');
    dm.qreciboscliente2.Open;
end;

procedure TMENU.SdomiciliadosClick(Sender: TObject);
begin
    dbgrid28.DataSource:=dm.dsqreciboscliente2;
    dm.recibos.MasterSource:=dm.dsqreciboscliente2;
    dbgrid28.Columns[3].FieldName:='cliente';
    dbgrid28.Columns[3].Title.caption :='Cliente';
    dm.qreciboscliente2.close;
    dm.qreciboscliente2.sql.clear;
    dm.qreciboscliente2.SQL.Add('select co.*,a.nombre_completo as alumno,c.nombre_completo as cliente from cobros co,alumnos a,clientes c where co.ida=a.id and co.idc=c.id and co.ide='+inttostr(centro)+' and forma_pago in (select id from formas_pago where domiciliado=1) order by pagado,cliente,fecharecibo desc');
    dm.qreciboscliente2.Open;

end;

Procedure TMenu.AppMessage(var Msg: TMSg; Var Handled:Boolean);
 var
  actual : TWincontrol;
 begin
 if Msg.message = WM_KEYDOWN then
    begin

    // esto es para controlar que con la flecha abajo se desplegen las
    // listas

    if Msg.wParam = VK_DOWN then
      begin
      Actual := Screen.ActiveControl;
      if Actual is TDBLookupComboBox then
            if not TDBLookupComboBox(Screen.ActiveForm.ActiveControl).listVisible then
               TDBLookupComboBox(Screen.ActiveForm.ActiveControl).DropDown;

      // si utilizas las RX
   {   if Actual is TRxDBLookupCombo then
            if not TRxDBLookupCombo(Screen.ActiveForm.ActiveControl).listVisible then
               TRxDBLookupCombo(Screen.ActiveForm.ActiveControl).DropDown;

    }
      if Actual is TComboBox then
         SendMessage(TComboBox(Screen.ActiveForm.ActiveControl).Handle,CB_SHOWDROPDOWN,-1,0);

      if (Actual is TCustomEdit) then
          Msg.wParam := VK_TAB;
      // se pueden añadir mas controles....

      end;

    // y aqui es el control del intro.
    if Msg.wParam = VK_RETURN THEN
       begin
       Actual := Screen.ActiveControl;
       // para los edit.
       if (Actual is TCustomEdit) and
          not (Actual is TCustomMemo) then
          Msg.wParam := VK_TAB;

       // para los memo. Con ctrl + enter se salta de linea dentro del
       // memo, si solo es intro salta al siguiente control
       if (Actual is TCustomMemo) and
          (HiWord(GetKeyState(VK_CONTROL)) = 0)then
          Msg.wParam := VK_TAB;

       // para los lookup
       if Actual is TDBLookupComboBox then
          if not TDBLookupComboBox(Actual).listVisible then
             Msg.wParam := VK_TAB;

       // Si utilizas las RX
{       if Actual is TRxDBLookupCombo then
          if not TRxDBLookupCombo(Actual).listVisible then
             Msg.wParam := VK_TAB;
 }
       // Los combobox
       if Actual is TCustomComboBox then
          if not TCustomComboBox(Actual).DroppedDown then
             Msg.wParam := VK_TAB;

       // el radiobutton
       if Actual is TRadioButton then
          Msg.wParam := VK_TAB;

       // en el grid
       if Actual is TDBGrid then
          if (TDBGrid(Actual).ReadOnly) or
             (HiWord(GetKeyState(VK_CONTROL)) = 1)then
             Msg.wParam := VK_TAB;

       // o esto otro Con Ctrl + intro siguiente celda con
       // ctrl + shift + intro celda anterior
       // es complicado pero es por no liar con el intro solo
       // que siempre pasa de un control a otro.
       if Actual is TDBGrid then
          begin
          if (TDBGrid(Actual).ReadOnly) or
             (HiWord(GetKeyState(VK_CONTROL)) = 0) then
             Msg.wParam := VK_TAB
          else
             if not(HiWord(GetKeyState(VK_SHIFT)) = 0) then
                begin
                if TDBGrid(Actual).selectedindex > 0 then             { increment the field }
                   TDBGrid(Actual).selectedindex := TDBGrid(Actual).selectedindex -1
                else
                   TDBGrid(Actual).selectedindex := TDBGrid(Actual).fieldcount -1;
                end
             else
                begin
                if TDBGrid(Actual).selectedindex < (TDBGrid(Actual).fieldcount -1) then             { increment the field }
                   TDBGrid(Actual).selectedindex := TDBGrid(Actual).selectedindex +1
                else
                   TDBGrid(Actual).selectedindex := 0;
                end;
          end;


       // ListBox
       if Actual is TCustomListBox then
          Msg.wParam := VK_TAB;

       // TabControl
       if Actual is TCustomTabControl then
          Msg.wParam := VK_TAB;

       // Aqui se pondrían todos los controles que usamos en la
       // aplicación y necesitamos cambiar el tab por intro.
       // de esta forma te despreocupas de cuantos añades y es más
       // limpio el código

       end;
    end;
 end;
procedure TMENU.Sesiones1Click(Sender: TObject);
begin
    btsesiones.Click;
end;

procedure TMenu.SetResolution(Width, Height: integer);
var
  bi,bi2: BITMAPINFO;
begin
  SendMessage(hWndC, WM_GET_VIDEOFORMAT, sizeof(bi), Cardinal(@bi));
  bi.bmiHeader.biWidth:= Width;
  bi.bmiHeader.biHeight:= Height;

  if SendMessage(hWndC, WM_SET_VIDEOFORMAT, sizeof(bi), Cardinal(@bi)) <> 0 then
  begin
    SendMessage(hWndC, WM_DISCONNECT, 0, 0);
    SendMessage(hWndC, WM_CONNECT, 0, 0);

  end;
  SendMessage(hWndC2, WM_GET_VIDEOFORMAT, sizeof(bi2), Cardinal(@bi2));
  bi2.bmiHeader.biWidth:= Width;
  bi2.bmiHeader.biHeight:= Height;

  if SendMessage(hWndC2, WM_SET_VIDEOFORMAT, sizeof(bi2), Cardinal(@bi2)) <> 0 then
  begin
    SendMessage(hWndC2, WM_DISCONNECT, 0, 0);
    SendMessage(hWndC2, WM_CONNECT, 0, 0);

  end;

end;
procedure TMENU.ExportaraExcel(FileNameXLS, SheetName: String; DBGrid: TDBGrid; ProgressBarXls: TProgressBar);

  procedure ProgressBarInit;
  begin
    ProgressBarXls.Max := DBGrid.DataSource.DataSet.RecordCount;
    ProgressBarXls.Position := 0;
    ProgressBarXls.Visible := True;
  end;

const
  xlWBATworksheet = -4167;
var
  Excel, WorkBook, WorkSheet: OleVariant;
  I, J: Integer;
  PBookmark: TBookmark;
begin
  // Guardar la posición en la DB y desactivar que se mueva el registro
  PBookmark := DBGrid.DataSource.DataSet.GetBookmark;
  DBGrid.DataSource.DataSet.DisableControls;
  DBGrid.DataSource.DataSet.First;

  // Comprobar si existe el component TProgressBar
  if (ProgressBarXls <> nil) then
    ProgressBarInit;

  // Crear instancia de la aplicación Excel
  Excel := CreateOleObject('Excel.Application');

  // Evitar que nos pregunte si deseamos sobreescribir el archivo
  Excel.DisplayAlerts := False;

  // Agregar libro de trabajo
  WorkBook := Excel.Workbooks.Add(xlWBATWorksheet);

  // Tomar una referencia a la hoja creada
  WorkSheet := WorkBook.WorkSheets[1];

  // Se  describe el nombre de la hoja
  WorkSheet.Name := SheetName;

  // Llenamos las celdas
  //    Toma en cuenta que las columnas y filas empiezan en 1, y que en el
  // WorkSheet.Cells[I, J], I es la fila y J es la columna.

  //   Extrae los nombres de los campos del DBGrid y los coloca en el primer registro,
  // excluyendo los campos que están ocultos
  for J := 0 to DBGrid.FieldCount -1 do
    if DBGrid.Fields[J].Visible then
    begin
      // Poner la fuente de letra en Negrita
      WorkSheet.Cells[1, J +1].Font.Bold := True;
      // Centrar la celda
//      WorkSheet.Cells[1, J +1].HorizontalAlignment := xlCenter;
      // Asignamos Valor del titulo del DBrid
      WorkSheet.Cells[1, J +1] := DBGrid.Columns[J].Title.Caption;
    end;

  // Guardar los registros
  for I := 0 to DBGrid.DataSource.DataSet.RecordCount -1 do
  begin
    // Identificamos los campos y lo grabamos según su tipo
    for J := 0 to DBGrid.FieldCount -1 do
      case DBGrid.Fields[J].DataType of
        ftAutoInc, ftBytes, ftInteger, ftSmallint, ftWord: // Auto o Numérico
          WorkSheet.Cells[I +2, J +1] := DBGrid.Fields[J].AsInteger;
        ftBCD, ftFloat, ftCurrency: // Numérico con decimales
          WorkSheet.Cells[I +2, J +1] := DBGrid.Fields[J].AsFloat;
        ftDateTime, ftDate, ftTime: // Fecha y Hora
          WorkSheet.Cells[I +2, J +1] := DBGrid.Fields[J].AsDateTime;
        else // Todo lo demas caracteres
          WorkSheet.Cells[I +2, J +1] := DBGrid.Fields[J].AsString;
      end;

    // Saltamos de registro
    DBGrid.DataSource.DataSet.Next;

    // Comprobar si existe el component TProgressBar
    if (ProgressBarXls <> nil) then
      ProgressBarXls.Position := ProgressBarXls.Position +1;
  end;

  // Comprobar si existe el component TProgressBar
  if (ProgressBarXls <> nil) then
    ProgressBarXls.Visible := False;

  // Redimensionar todas las celdas para que esten según su tamaño
  WorkSheet.Cells.Columns.AutoFit;

  // Guardar el archivo
  WorkBook.SaveAs(FileNameXLS);

  // Cierra el archivo
  WorkBook.Close(FileNameXLS);

  // Salir de Excel
  Excel.Quit;

  // posicionar el registro donde estaba
  DBGrid.DataSource.DataSet.GotoBookmark(PBookmark);
  DBGrid.DataSource.DataSet.FreeBookmark(PBookmark);
  DBGrid.DataSource.DataSet.EnableControls;
end;

end.
