Iraitz

Iraitz

  • NA
  • 1
  • 0

PDAs hour update failed

Apr 23 2009 5:46 AM
Hello everybody.

Firstly i would say sorry for my english low level.

I'm trying update a PDA's date synchronizing with a server. To do that, I have created a program with c#.Apparently my program it's ok, but after doing a hard reset, if I execute the program, without change anything, the hour, year, month, day and minutes updates well, but the hour no. Else, if I change the hour (any change) after doing a hard reset and before execute the program, the hour updates ok. I would like that the hour will update whithout need to do changes before the execute.

this is the code of my program:


/////Function thas start the updating/////
private void ActualizarFecha()
        {
            try
            {
               
                DateTime fechaServidor = this.Servidor.fFechaServidor();

                Utiles.ActualizarFecha(fechaServidor);

              
            }
            catch
            {
                TLog.AddError("Error al actualizar la fecha/hora de la maquina");
            }
        }

/////Servidor/////
public override DateTime fFechaServidor()
        {
            String strSQL;
            System.DateTime result = System.DateTime.UtcNow;

            strSQL = "SELECT getutcdate() AS fecha";
            _cmSQL.CommandText = strSQL;
            this._drSQL = _cmSQL.ExecuteReader();
            if (this._drSQL.Read())
            {
                result = Convert.ToDateTime(this._drSQL["fecha"]);
            }
            this._drSQL.Close();

            return result;
        }

/////Utiles/////
public static void ActualizarFecha(System.DateTime paramFecha)
        {
#if PDA
            SystemTime st = new SystemTime();

            GetSystemTime(ref st);
            st.wYear = Convert.ToUInt16(paramFecha.Year);
            st.wMonth = Convert.ToUInt16(paramFecha.Month);
            st.wDay = Convert.ToUInt16(paramFecha.Day);
            st.wHour = Convert.ToUInt16(paramFecha.Hour);
            st.wMinute = Convert.ToUInt16(paramFecha.Minute);
            st.wSecond = Convert.ToUInt16(paramFecha.Second);
            st.wMilliseconds = Convert.ToUInt16(paramFecha.Millisecond);
            SetSystemTime(ref st);
#endif
}

Before doing a hard reset, the date in the PDA is 01 September 2007, 0:00. But when I debug my program, System.DateTime.UtcNow sometimes(usually at mornings) returns 01/09/07 8:xx:xx and sometimes(usually at afternoons) 31/08/2007 23:xx:xx. And GetSystemTime(ref st) sometimes returns st.wYear=2007, st.wMonth=9, st.wDay=1 and st.wHour=8, and other times st.wYear=2007, st.wMonth=8, st.wDay=31 and st.wHour=23. And although I change the values of st, SetSystemTime(ref st) donĀ“t update well the PDA's hour.

Someone knows why happens this? And how can I solve the problem?

My PDA is a HP iPAQ 214 with windows mobile 6.

Thank you very much.