public void CreateCitaEvent(Int32 curCita)
        {
            DatosCehavi datos1 = new DatosCehavi();

            datos1.Connect();

            //DataTable TempData = datos1.GetEvents();
            DataTable TempData     = datos1.LoadData("select * from Citas where Id=" + curCita.ToString());
            DataTable TablaColores = datos1.LoadData("select * from Colores order by Id");

            string NombrePaciente = "";
            Int16  StatusPaciente = 0;
            Int32  CurColor       = 0;
            int    CurPaciente    = 0;
            string ColorPaciente  = "#000000";



            foreach (DataRow c in TempData.Rows)
            {
                Int32    IdEvento    = (Int32)c["Id"];
                Int32    IdPaciente  = (Int32)c["IdPaciente"];
                Int16    Duracion    = (Int16)c["Duracion"];
                Int16    IdTerapueta = (Int16)c["IdTerapeuta"];
                DateTime AFecha      = (DateTime)c["Fecha"];


                if (CurPaciente == 0 || IdPaciente != CurPaciente)
                {
                    CurPaciente = IdPaciente;
                    DataTable DatosPaciente = datos1.LoadData("select * from pacientes where IdPaciente=" + IdPaciente.ToString());
                    NombrePaciente = DatosPaciente.Rows[0]["Nombre"].ToString();
                    StatusPaciente = (Int16)DatosPaciente.Rows[0]["estatus"];
                    CurColor       = IdPaciente % 55;
                    ColorPaciente  = "#" + TablaColores.Rows[CurColor]["Color"].ToString();
                }



                DateTime EventoFechaStart = AFecha;
                DateTime EventoFechaEnd   = EventoFechaStart.AddMinutes(Duracion);



                ArrayList valores = new ArrayList();

                valores.Add(new Registro("IdEvento", IdEvento));
                valores.Add(new Registro("Title", NombrePaciente));
                valores.Add(new Registro("start_event", EventoFechaStart.ToString("yyyy-MM-dd HH:mm:ss")));
                valores.Add(new Registro("end_event", EventoFechaEnd.ToString("yyyy-MM-dd HH:mm:ss")));
                valores.Add(new Registro("Color", ColorPaciente));
                valores.Add(new Registro("status1", 0));
                valores.Add(new Registro("status2", 0));
                valores.Add(new Registro("IdTipo", 2));

                datos1.InsertData(valores, "Eventos");
            }
        }
        /*
         *
         *
         *
         *
         *
         *
         *
         *
         * public DataTable GetCurretEvents(DateTime StartDate, DateTime EndDate)
         * {
         *   DataTable DatosEventos = new DataTable("Eventos");
         *
         *   DatosCehavi datos1 = new DatosCehavi();
         *   datos1.Connect();
         *
         *   DataTable TempData = datos1.GetEvents();
         *
         *   string NombrePaciente = "";
         *   Int16 StatusPaciente = 0;
         *   int CurPaciente = 0;
         *
         *   DatosEventos.Columns.Add("IdEvento", Type.GetType("System.Int32"));
         *   DatosEventos.Columns.Add("Fecha", Type.GetType("System.DateTime"));
         *   DatosEventos.Columns.Add("Duracion", Type.GetType("System.Int16"));
         *   DatosEventos.Columns.Add("Title", Type.GetType("System.String"));
         *
         *
         *   foreach (DataRow c in TempData.Rows)
         *   {
         *       Int32 IdEvento = (Int32)c["Id"];
         *       Int32 IdPaciente = (Int32)c["IdPaciente"];
         *       Int16 Duracion = (Int16)c["Duracion"];
         *       Int16 IdTerapueta = (Int16)c["IdTerapeuta"];
         *       Int16 Periodo = (Int16)c["Periodo"];
         *       DateTime AFecha = (DateTime)c["Fecha"];
         *       DateTime BFecha = (DateTime)c["Fecha2"];
         *       Byte Dia = (Byte)c["Dia"];
         *
         *
         *       if (CurPaciente == 0 || IdPaciente != CurPaciente)
         *       {
         *           CurPaciente = IdPaciente;
         *           DataTable DatosPaciente = datos1.LoadData("select * from pacientes where IdPaciente=" + IdPaciente.ToString());
         *           NombrePaciente = DatosPaciente.Rows[0]["Nombre"].ToString();
         *           StatusPaciente = (Int16)DatosPaciente.Rows[0]["estatus"];
         *       }
         *
         *
         *       if (DateTime.Compare(BFecha, StartDate) <= 0) continue;
         *       if (DateTime.Compare(AFecha, EndDate) >= 0) continue;
         *
         *       //if (DateTime.Compare(AFecha, StartDate) > 0) AFecha = StartDate;
         *       if (DateTime.Compare(BFecha, EndDate) > 0) BFecha = EndDate;
         *
         *
         *
         *       while (DateTime.Compare(AFecha,BFecha)<0)
         *       {
         *           int curDia = (int)AFecha.DayOfWeek;
         *           int diasadd = 0;
         *           if (curDia > Dia) diasadd = (6 - curDia) + Dia;
         *           if (curDia < Dia) diasadd = Dia - curDia;
         *           DateTime EventoFecha = AFecha.AddDays(diasadd);
         *
         *           DatosEventos.Rows.Add(IdEvento, AFecha.ToString("yyyy-MM-dd HH:mm:ss"),Duracion,NombrePaciente);
         *
         *           if (Periodo == 2) AFecha = AFecha.AddDays(1);
         *           if (Periodo == 3) AFecha = AFecha.AddDays(7);
         *           if (Periodo == 4) AFecha = AFecha.AddMonths(1);
         *
         *
         *
         *       }
         *
         *
         *
         *
         *
         *
         *   }
         *
         *   return DatosEventos;
         *
         * }
         *
         */


        public void CreateCurrentEvents(Int32 curTerapia)
        {
            DatosCehavi datos1 = new DatosCehavi();

            datos1.Connect();

            //DataTable TempData = datos1.GetEvents();
            DataTable TempData     = datos1.LoadData("select * from Terapias where Id=" + curTerapia.ToString());
            DataTable TablaColores = datos1.LoadData("select * from Colores order by Id");

            string NombrePaciente = "";
            Int16  StatusPaciente = 0;
            Int32  CurColor       = 0;
            int    CurPaciente    = 0;
            string ColorPaciente  = "#000000";



            foreach (DataRow c in TempData.Rows)
            {
                Int32    IdEvento    = (Int32)c["Id"];
                Int32    IdPaciente  = (Int32)c["IdPaciente"];
                Int16    Duracion    = (Int16)c["Duracion"];
                Int16    IdTerapueta = (Int16)c["IdTerapeuta"];
                Int16    Periodo     = (Int16)c["Periodo"];
                DateTime AFecha      = (DateTime)c["Fecha"];
                DateTime BFecha      = (DateTime)c["Fecha2"];
                DateTime Hora        = (DateTime)c["Hora"];
                Byte     Dia         = (Byte)c["Dia"];


                if (CurPaciente == 0 || IdPaciente != CurPaciente)
                {
                    CurPaciente = IdPaciente;
                    DataTable DatosPaciente = datos1.LoadData("select * from pacientes where IdPaciente=" + IdPaciente.ToString());
                    NombrePaciente = DatosPaciente.Rows[0]["Nombre"].ToString();
                    StatusPaciente = (Int16)DatosPaciente.Rows[0]["estatus"];
                    CurColor       = IdPaciente % 55;
                    ColorPaciente  = "#" + TablaColores.Rows[CurColor]["Color"].ToString();
                }


                int curDia  = (int)AFecha.DayOfWeek;
                int diasadd = 0;
                if (curDia > Dia)
                {
                    diasadd = (7 - curDia) + Dia;
                }
                if (curDia < Dia)
                {
                    diasadd = Dia - curDia;
                }

                DateTime EventoFecha      = AFecha.AddDays(diasadd);
                DateTime EventoFechaStart = new DateTime(AFecha.Year, AFecha.Month, EventoFecha.Day, Hora.Hour, Hora.Minute, 0);
                DateTime EventoFechaEnd   = EventoFechaStart.AddMinutes(Duracion);



                while (DateTime.Compare(EventoFechaStart, BFecha) < 0)
                {
                    ArrayList valores = new ArrayList();

                    valores.Add(new Registro("IdEvento", IdEvento));
                    valores.Add(new Registro("Title", NombrePaciente));
                    valores.Add(new Registro("start_event", EventoFechaStart.ToString("yyyy-MM-dd HH:mm:ss")));
                    valores.Add(new Registro("end_event", EventoFechaEnd.ToString("yyyy-MM-dd HH:mm:ss")));
                    valores.Add(new Registro("Color", ColorPaciente));
                    valores.Add(new Registro("status1", 0));
                    valores.Add(new Registro("status2", 0));
                    valores.Add(new Registro("IdTipo", 1));
                    datos1.InsertData(valores, "Eventos");


                    if (Periodo == 2)
                    {
                        EventoFechaStart = EventoFechaStart.AddDays(1);
                        EventoFechaEnd   = EventoFechaEnd.AddDays(1);
                    }

                    if (Periodo == 3)
                    {
                        EventoFechaStart = EventoFechaStart.AddDays(7);
                        EventoFechaEnd   = EventoFechaEnd.AddDays(7);
                    }

                    if (Periodo == 4)
                    {
                        EventoFechaStart = EventoFechaStart.AddMonths(1);
                        EventoFechaEnd   = EventoFechaEnd.AddMonths(1);
                    }
                }
            }
        }
        private void save_Click(object sender, RoutedEventArgs e)
        {
            DatosCehavi datos1 = new DatosCehavi();

            datos1.Connect();

            ArrayList valores = new ArrayList();

            if (this.TerapiaFecha == null)
            {
                MessageBox.Show("Selecciona una fecha", "Advertencia");
                return;
            }

            if (this.TerapiaFecha.Length == 0)
            {
                MessageBox.Show("Selecciona una fecha", "Advertencia");
                return;
            }

            DateTime curFecha = System.Convert.ToDateTime(this.TerapiaFecha);

            //  Int32 Dia = System.Convert.ToInt32(this.comboBoxDias.SelectedValue);
            //  Int32 Hora = System.Convert.ToInt32(this.comboBoxHoras.SelectedValue);
            Int32    Duracion   = System.Convert.ToInt32(this.textBox.Text);
            Int32    Terapeuta  = System.Convert.ToInt32(this.comboBoxTerapeutas.SelectedValue);
            Int32    Periodo    = System.Convert.ToInt32(this.Repeticion.SelectedValue);
            DateTime StartFecha = (DateTime)this.datePicker0.SelectedDate;
            DateTime EndFecha   = (DateTime)this.datePicker1.SelectedDate;

            //  Int32 Minuto = System.Convert.ToInt32(this.comboBoxMinutos.SelectedValue);

            int CurDia = (int)curFecha.DayOfWeek;


            valores.Add(new Registro("Duracion", Duracion));
            valores.Add(new Registro("IdPaciente", this.curPaciente));
            valores.Add(new Registro("IdTerapeuta", Terapeuta));
            valores.Add(new Registro("Periodo", Periodo));
            valores.Add(new Registro("Fecha", StartFecha.ToString("yyyy-MM-dd HH:mm:ss")));
            valores.Add(new Registro("Fecha2", EndFecha.ToString("yyyy-MM-dd HH:mm:ss")));
            valores.Add(new Registro("Dia", CurDia));
            valores.Add(new Registro("Hora", curFecha.ToString("2000-01-01 HH:mm:ss")));



            if (this.curTerapia != 0)
            {
                datos1.UpdateData(valores, this.curTerapia, "Id", "terapias");
                datos1.executeQuery("delete from eventos where IdTipo=1 and IdEvento=" + this.curTerapia.ToString());
                datos1.CreateCurrentEvents(this.curTerapia);
            }

            else
            {
                this.curTerapia = datos1.InsertData(valores, "terapias");
            }

            //MessageBox.Show(curFecha.ToShortDateString(),"Fecha");
            //MessageBox.Show(curFecha.ToShortTimeString(), "Hora");



            this.Close();
        }
        private void guardaPaciente(object sender, RoutedEventArgs e)
        {
            ArrayList valores = new ArrayList();
            int       Sexo    = 1;

            if (this.radioButton2.IsChecked.Value)
            {
                Sexo = 2;
            }

            DatosCehavi datos1 = new DatosCehavi();

            datos1.Connect();

            string NombrePaciente = this.NombrePaciente.Text;

            if (NombrePaciente.Length < 5)
            {
                MessageBox.Show("El nombre es invalido!", "Advertencia:");
                return;
            }


            if (this.FechaNac_DatePicker.SelectedDate == null)
            {
                MessageBox.Show("La Fecha de naciemiento es invalida!", "Advertencia:");
                return;
            }



            valores.Add(new Registro("Nombre", NombrePaciente));
            valores.Add(new Registro("FechaNac", this.FechaNac_DatePicker.SelectedDate));
            valores.Add(new Registro("Sexo", Sexo));
            valores.Add(new Registro("IdGradoEscuela", this.comboBox1.SelectedValue));
            valores.Add(new Registro("IdEscuela", this.comboBox2.SelectedValue));
            valores.Add(new Registro("terapias", 1));

            valores.Add(new Registro("estatus", this.comboBox3.SelectedValue));
            valores.Add(new Registro("calle", this.Calle.Text));
            valores.Add(new Registro("cp", this.CodigoPostal.Text));
            valores.Add(new Registro("idestado", this.comboBox4.SelectedValue));

            valores.Add(new Registro("exterior", this.exterior.Text));
            valores.Add(new Registro("interior", this.interior.Text));

            valores.Add(new Registro("telefonocasa", this.telefonocasa.Text));
            valores.Add(new Registro("telefonocel", this.telefonomovil.Text));

            valores.Add(new Registro("telefonorecados", this.telefonorecados.Text));
            valores.Add(new Registro("email", this.email.Text));


            Int32 CurCiudad = datos1.BuscaNombreTabla(this.Ciudad.Text, "Ciudad", "Id", "Nombre");

            if (CurCiudad == 0)
            {
                CurCiudad = datos1.InsertaNombreCampo(this.Ciudad.Text, "Ciudad", "Nombre");
            }

            Int32 CurMunicipio = datos1.BuscaNombreTabla(this.Municipio.Text, "Municipio", "Id", "Nombre");

            if (CurMunicipio == 0)
            {
                CurMunicipio = datos1.InsertaNombreCampo(this.Ciudad.Text, "Municipio", "Nombre");
            }

            Int32 CurColonia = datos1.BuscaNombreTabla(this.Colonia.Text, "Colonia", "Id", "Nombre");

            if (CurColonia == 0)
            {
                CurColonia = datos1.InsertaNombreCampo(this.Colonia.Text, "Colonia", "Nombre");
            }


            valores.Add(new Registro("idciudad", CurCiudad));
            valores.Add(new Registro("idmunicipio", CurMunicipio));
            valores.Add(new Registro("idcolonia", CurColonia));



            if (this.curPaciente != 0)
            {
                datos1.UpdateData(valores, this.curPaciente, "IdPaciente", "pacientes");
            }
            else
            {
                this.curPaciente = datos1.InsertData(valores, "pacientes");
            }



            if (this.newLoadedImage)
            {
                try
                {
                    JpegBitmapEncoder encoder       = new JpegBitmapEncoder();
                    String            photolocation = "C:\\Datos\\images\\" + this.curPaciente.ToString() + ".jpg"; //file name

                    //encoder.Frames.Add(BitmapFrame.Create(this.personPhoto));
                    encoder.Frames.Add(BitmapFrame.Create((BitmapImage)this.image.Source));
                    using (var filestream = new FileStream(photolocation, FileMode.Create))
                        encoder.Save(filestream);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to save now.");
                }
            }


            this.Close();
        }
Exemple #5
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            DatosCehavi datos1 = new DatosCehavi();

            datos1.Connect();

            ArrayList valores = new ArrayList();

            if (this.CitaFecha == null)
            {
                MessageBox.Show("Selecciona una fecha", "Advertencia");
                return;
            }


            if (this.CitaFecha.Length == 0)
            {
                MessageBox.Show("Selecciona una fecha", "Advertencia");
                return;
            }

            DateTime curFecha = System.Convert.ToDateTime(this.CitaFecha);

            Int32 Duracion  = System.Convert.ToInt32(this.textBox.Text);
            Int32 Terapeuta = System.Convert.ToInt32(this.comboBoxTerapeutas.SelectedValue);



            //  Int32 Minuto = System.Convert.ToInt32(this.comboBoxMinutos.SelectedValue);



            valores.Add(new Registro("Duracion", Duracion));
            valores.Add(new Registro("IdPaciente", this.curPaciente));
            valores.Add(new Registro("IdTerapeuta", Terapeuta));
            valores.Add(new Registro("comentarios", this.comentarios.Text));
            valores.Add(new Registro("Fecha", curFecha.ToString("yyyy-MM-dd HH:mm:ss")));



            if (this.curCita != 0)
            {
                datos1.UpdateData(valores, this.curCita, "Id", "Citas");
            }
            else
            {
                this.curCita = datos1.InsertData(valores, "Citas");
            }


            if (this.curCita != 0)
            {
                datos1.executeQuery("delete from eventos where IdTipo=2 and IdEvento=" + this.curCita.ToString());
                datos1.CreateCitaEvent(this.CurCita);
            }

            else
            {
                this.curCita = datos1.InsertData(valores, "Citas");
            }



            this.Close();
        }