Beispiel #1
0
        public void TimeManipulation(string senderName, UInt16 parsedSec)
        {
            char operation = senderName[senderName.Length - 1];

            var st = new NativeMethods.SYSTEMTIME();

            NativeMethods.GetSystemTime(ref st);

            if (senderName.StartsWith("s"))
            {
                st.wSecond = operation == 'A' ? (ushort)(st.wSecond + parsedSec % 60) :
                             (ushort)(st.wSecond - parsedSec % 60);
            }
            else
            {
                st.wMilliseconds = operation == 'A' ? (ushort)(st.wMilliseconds + parsedSec % 60000) :
                                   (ushort)(st.wMilliseconds - parsedSec % 60000);
            }
            NativeMethods.SetSystemTime(ref st);
        }
Beispiel #2
0
        private void TimeManipulation(string type, string operation)
        {
            if (type == "seconds")
            {
                var isDigit = Regex.IsMatch(SecondsBox.Text, @"^\d+$");

                if (isDigit == true)
                {
                    if (operation == "add")
                    {
                        var st = new NativeMethods.SYSTEMTIME();
                        NativeMethods.GetSystemTime(ref st);

                        var seconds = UInt16.Parse(SecondsBox.Text);
                        st.wSecond = (ushort)(st.wSecond + seconds % 60);

                        NativeMethods.SetSystemTime(ref st);
                    }

                    else if (operation == "subract")
                    {
                        var st = new NativeMethods.SYSTEMTIME();
                        NativeMethods.GetSystemTime(ref st);

                        var seconds = UInt16.Parse(SecondsBox.Text);
                        st.wSecond = (ushort)(st.wSecond - seconds % 60);

                        NativeMethods.SetSystemTime(ref st);
                    }
                }
            }

            else if (type == "milliseconds")
            {
                var isDigit = Regex.IsMatch(MSecondsBox.Text, @"^\d+$");

                if (isDigit == true)
                {
                    if (operation == "add")
                    {
                        var st = new NativeMethods.SYSTEMTIME();
                        NativeMethods.GetSystemTime(ref st);

                        var mseconds = UInt16.Parse(MSecondsBox.Text);
                        st.wMilliseconds = (ushort)(st.wMilliseconds + mseconds % 60000);

                        NativeMethods.SetSystemTime(ref st);
                    }

                    else if (operation == "subract")
                    {
                        var st = new NativeMethods.SYSTEMTIME();
                        NativeMethods.GetSystemTime(ref st);

                        var mseconds = UInt16.Parse(MSecondsBox.Text);
                        st.wMilliseconds = (ushort)(st.wMilliseconds - mseconds % 60000);

                        NativeMethods.SetSystemTime(ref st);
                    }
                }
            }
        }