Example #1
0
        private void setTime() //获取文件中的时间然后设置到系统中
        {
            byte[]   array = new byte[100];
            string   path  = AppDomain.CurrentDomain.BaseDirectory + "\\zclTime.txt";
            FileInfo file  = new FileInfo(path);

            if (!file.Exists)
            {
                FileStream fs;
                fs = File.Create(path);
                fs.Close();
            }
            else
            {
                string   s = File.ReadAllText(path);
                DateTime t = Convert.ToDateTime(s);

                DateTime t1 = DateTime.Now;
                if (DateTime.Compare(t, t1) > 0)
                {
                    SystemTime st = new SystemTime();
                    st.FromDateTime(t);
                    //调用Win32 API设置系统时间
                    SetLocalTime(ref st);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 更改系統時間
        /// </summary>
        /// <param name="hostTime">The host time.</param>
        public void updateSystemTime(DateTime hostTime)
        {
            SystemTime st = new SystemTime();

            st.FromDateTime(hostTime);
            SystemTime.SetSystemTime(ref st);
            SystemTime.GetSystemTime(ref st);
            logger.Info("Set System Time:{0}", st.ToDateTime().ToString(SCAppConstants.TimestampFormat_16));
        }
Example #3
0
        private void setDate(int year, int month, int day)
        {
            DateTime t = DateTime.Now;

            t = Convert.ToDateTime(year + "-" + month + "-" + day + " " + t.Hour + ":" + t.Minute + ":" + t.Second);
            SystemTime st = new SystemTime();

            st.FromDateTime(t);
            Win32API.SetLocalTime(ref st);
            textBox2.AppendText("set the system time as:" + DateTime.Now.ToString() + Environment.NewLine);
        }
Example #4
0
        public static bool SetSystemTime(DateTime dt)
        {
            //转换System.DateTime到SystemTime
            SystemTime st = new SystemTime();

            st.FromDateTime(dt);

            //调用Win32 API设置系统时间
            SetLocalTime(ref st);

            return(true);
        }
Example #5
0
        /// <summary>
        /// Edit an existing user notification.
        /// </summary>
        /// <param name="handle">Handle to the notification to overwrite.</param>
        /// <param name="application">String that specifies the name of the application that owns this notification.</param>
        /// <param name="time">The time when the notification should occur.</param>
        /// <param name="notify">Notification object that describes the events that are to occur when the notification time is reached.</param>
        /// <returns>The handle to the notification indicates success.</returns>
        public static int SetUserNotification(int handle, string application, System.DateTime time, UserNotification notify)
        {
            //call api function
            int outhandle = CeSetUserNotification(handle, application, SystemTime.FromDateTime(time).ToByteArray(), notify.ToByteArray());

            //if invalid handle throw exception
            if (outhandle == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Error setting UserNotification");
            }
            return(outhandle);
        }
Example #6
0
        /// <summary>
        /// This function prompts the system to start running a specified application at a specified time.
        /// </summary>
        /// <param name="appName">Name of the application to be started.</param>
        /// <param name="time">DateTime at which to run application.</param>
        /// <remarks>To cancel an existing RunAppATime request pass the application name and DateTime.MinValue</remarks>
        public static void RunAppAtTime(string appName, System.DateTime time)
        {
            byte[] timebytes;

            if (time == System.DateTime.MinValue)
            {
                //cancel request pass null
                timebytes = null;
            }
            else
            {
                //get native system time struct
                SystemTime st = SystemTime.FromDateTime(time);
                //get bytes
                timebytes = st.ToByteArray();
            }

            if (!CeRunAppAtTime(appName, timebytes))
            {
                throw new WinAPIException("Cannot Set Notification Handler");
            }
        }
Example #7
0
 static void UpdateTime()
 {
     GetSystemTimeZone();
     DateTime dt = GetBeijingTime();
     string timeZone = INIFILE.GetValue("MAIN", "TimeZone");
     DateTime dtUTC = TimeZoneInfo.ConvertTimeToUtc(dt, TimeZoneInfo.FindSystemTimeZoneById(ListTimeMap[defaultTimeSpane]));
     dt = TimeZoneInfo.ConvertTimeFromUtc(dtUTC, TimeZoneInfo.FindSystemTimeZoneById(ListTimeMap.Values.ElementAt(GetIndex(timeZone))));
     SystemTime st = new SystemTime();
     st.FromDateTime(dt);
     SetLocalTime(ref st);
 }
Example #8
0
        private void UpdateTime(jimmy myjimmy, string msg)
        {
            DateTime dt = DateTime.Now;
            DateTime dt1 = DateTime.Now;
            try
            {
                switch (myjimmy)
                {
                    case jimmy.year:
                        dt1 = new DateTime((int)Int32.Parse(msg), dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
                        break;
                    case jimmy.month:
                        dt1 = new DateTime(dt.Year, (int)Int32.Parse(msg), dt.Day, dt.Hour, dt.Minute, dt.Second);
                        break;
                    case jimmy.day:
                        dt1 = new DateTime(dt.Year, dt.Month, (int)Int32.Parse(msg), dt.Hour, dt.Minute, dt.Second);
                        break;
                    case jimmy.hour:
                        dt1 = new DateTime(dt.Year, dt.Month, dt.Day, (int)Int32.Parse(msg), dt.Minute, dt.Second);
                        break;
                    case jimmy.minute:
                        dt1 = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, (int)Int32.Parse(msg), dt.Second);
                        break;
                    case jimmy.second:
                        dt1 = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, (int)Int32.Parse(msg));
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {

            }
            SystemTime st = new SystemTime();
            st.FromDateTime(dt1);
            SetLocalTime(ref st);
        }
Example #9
0
        static void PressOnTimerBtn()
        {
            try
            {

                if (IsConnected())
                {
                    DateTime dtUTC = GetInternetTime();//0时区时间
                    ///0时区标准时间
                    DateTime dt = TimeZoneInfo.ConvertTimeFromUtc(dtUTC, TimeZoneInfo.FindSystemTimeZoneById(ListTimeMap.Values.ElementAt(currentTimeZoneIndex)));
                    SystemTime st = new SystemTime();
                    st.FromDateTime(dt);
                    SetLocalTime(ref st);
                }
                else
                {
                    //Warning.WarningText = "网络连接不存在,不能同步网络时间。";
                    //MessageBox.Show("网络无法连接");
                    //Console.WriteLine();
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("网络无法连接");
            }
        }
Example #10
0
        void PressOnTimerBtn()
        {
            try
            {
                //Ping ping = new Ping();
                //PingReply replay = ping.Send("202.108.22.5");
                if (IsConnected())
                //if (replay.Status == IPStatus.Success)
                {
                    dtTimer.Stop();
                    internetTime.RemoteClick();
                    WriteLog("1111111111111111111111111111111111111111111111111");
                    //DateTime dt = GetBeijingTime();
                    DateTime dtUTC = GetInternetTime();//0时区时间
                    ///0时区标准时间
                    //DateTime dtUTC = TimeZoneInfo.ConvertTimeToUtc(dt, TimeZoneInfo.FindSystemTimeZoneById(ListTimeMap[defaultTimeSpane]));
                    DateTime dt = TimeZoneInfo.ConvertTimeFromUtc(dtUTC, TimeZoneInfo.FindSystemTimeZoneById(ListTimeMap.Values.ElementAt(currentTimeZoneIndex)));
                    WriteLog("2222222222222222222222222222222222222222222");

                    _year._time.Text = dt.Year.ToString() + "年";
                    _month._time.Text = dt.Month.ToString() + "月";
                    _day._time.Text = dt.Day.ToString() + "日";
                    _hour._time.Text = dt.Hour.ToString() + "时";
                    _minute._time.Text = dt.Minute.ToString() + "分";
                    _second._time.Text = dt.Second.ToString() + "秒";
                    SystemTime st = new SystemTime();
                    st.FromDateTime(dt);
                    WriteLog("333333333333333333333333333333333333");

                    SetLocalTime(ref st);
                    WriteLog("44444444444444444444444444444444444");

                    //SetMyLocalTime(dt);
                    Warning.WarningText = "系统时间更新成功。";
                    dtTimer.Start();
                    WriteLog("5555555555555555555555555");

                    //Thread.Sleep(500);
                }
                else
                {
                    Warning.WarningText = "网络连接不存在,不能同步网络时间。";
                }
            }
            catch (Exception ex)
            {
                Warning.WarningText = "网络连接不存在,不能同步网络时间。";
            }
        }