| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 | using MECF.Framework.UI.Client.ClientBase;using System;using System.Runtime.InteropServices;using System.Windows;using System.Windows.Controls;namespace MECF.Framework.UI.Client.CenterViews.DataLogs.Event{    public class SelectDateViewModel : BaseModel    {        private SelectDateView view;        TextBox[] tbboxs;        private string _year;        public string Year        {            get            {                return _year;            }            set            {                _year = value;                NotifyOfPropertyChange("Year");            }        }        private string _month;        public string Month        {            get            {                return _month.PadLeft(2, '0');            }            set            {                _month = value;                NotifyOfPropertyChange("Month");            }        }        private string _day;        public string Day        {            get            {                return _day.PadLeft(2, '0');            }            set            {                _day = value;                NotifyOfPropertyChange("Day");            }        }        private string _hour;        public string Hour        {            get            {                return _hour.PadLeft(2, '0');            }            set            {                _hour = value;                NotifyOfPropertyChange("Hour");            }        }        private string _minute;        public string Minute        {            get            {                return _minute.PadLeft(2, '0');            }            set            {                _minute = value;                NotifyOfPropertyChange("Minute");            }        }        private string _second;        public string Second        {            get            {                return _second.PadLeft(2, '0');            }            set            {                _second = value;                NotifyOfPropertyChange("Second");            }        }        public DateTime SearchDate { get; set; }        public DateTime tempDate;        public SelectDateViewModel(DateTime date)        {            tempDate = date;        }        protected override void OnViewLoaded(object _view)        {            //base.OnViewLoaded(_view);            //this.view = (SelectDateView)_view;            //this.view.tbYear.Focus();            //this.view.tbYear.SelectAll();            //tbboxs = new TextBox[6] {this.view.tbYear,this.view.tbMonth,this.view.tbDay,this.view.tbHour,this.view.tbMinute,this.view.tbSecond};        }        protected override void OnActivate()        {            base.OnActivate();            Year = tempDate.Year.ToString();            Month = tempDate.Month.ToString();            Day = tempDate.Day.ToString();            Hour = tempDate.Hour.ToString();            Minute = tempDate.Minute.ToString();            Second = tempDate.Second.ToString();            string date = Year + "-" + Month + "-" + Day + " " + Hour + ":" + Minute + ":" + Second;            SearchDate = Convert.ToDateTime(date);            this.view = (GetView() as Window).Content as SelectDateView;            tbboxs = new TextBox[6] { this.view.tbYear, this.view.tbMonth, this.view.tbDay, this.view.tbHour, this.view.tbMinute, this.view.tbSecond };            this.view.tbYear.Focus();            this.view.tbYear.SelectAll();        }        public void SaveDate()        {            //if (Convert.ToInt32(Day) > GetCurrentMonthMaxDay() || Convert.ToInt32(Day) < 1)            //{            //    DialogBox.ShowDialog(DialogButton.OK, DialogType.WARNING, $"The maximum number of days in the current month is {GetCurrentMonthMaxDay()},please enter again!");            //    return;            //}            DateTime dateTime;            string date = Year + "-" + Month + "-" + Day + " " + Hour + ":" + Minute + ":" + Second;            if (DateTime.TryParse(date, out dateTime))            {                SearchDate = dateTime;                this.TryClose(true);            }        }        public void Close()        {            this.TryClose();        }        private int GetCurrentMonthMaxDay()        {            int days = 0;            switch (Convert.ToInt32(Month))            {                case 1:                    days = 31;                    break;                case 2:                    if (Convert.ToInt32(Year) % 4 == 0 && Convert.ToInt32(Year) % 100 != 0 || Convert.ToInt32(Year) % 400 == 0)                        days = 29;                    else                        days = 28;                    break;                case 3: days = 31; break;                case 4: days = 30; break;                case 5: days = 31; break;                case 6: days = 30; break;                case 7: days = 31; break;                case 8: days = 31; break;                case 9: days = 30; break;                case 10: days = 31; break;                case 11: days = 30; break;                case 12: days = 31; break;            }            return days;        }        [DllImport("user32.dll")]        public static extern int GetFous();        public void MoveFous(string Direction)        {            for (int i = 0; i < tbboxs.Length; i++)            {                if (tbboxs[i].IsFocused)                {                    if (Direction == "Left")                    {                        if (i == 0)                        {                            tbboxs[i].Focus();                            tbboxs[i].SelectAll();                            break;                        }                        else                        {                            tbboxs[i - 1].Focus();                            tbboxs[i - 1].SelectAll();                            break;                        }                    }                    else                    {                        if (i == 5)                        {                            tbboxs[i].Focus();                            tbboxs[i].SelectAll();                            break;                        }                        else                        {                            tbboxs[i + 1].Focus();                            tbboxs[i + 1].SelectAll();                            break;                        }                    }                }            }        }        public void ChangeValue(string Operation)        {            for (int i = 0; i < tbboxs.Length; i++)            {                if (tbboxs[i].IsFocused)                {                    if (Operation == "Add")                    {                        tbboxs[i].Text = (Convert.ToInt32(tbboxs[i].Text) + 1).ToString();                        if (i == 1)                        {                            if (Convert.ToInt32(tbboxs[i].Text) > 12)                                tbboxs[i].Text = "1";                        }                        if (i == 2)                        {                            if (Convert.ToInt32(tbboxs[i].Text) > GetCurrentMonthMaxDay())                                tbboxs[i].Text = "1";                        }                        if (i == 3)                        {                            if (Convert.ToInt32(tbboxs[i].Text) > 23)                                tbboxs[i].Text = "0";                        }                        if (i == 4 || i == 5)                        {                            if (Convert.ToInt32(tbboxs[i].Text) > 59)                                tbboxs[i].Text = "0";                        }                        break;                    }                    else                    {                        int temp = Convert.ToInt32(tbboxs[i].Text) - 1;                        tbboxs[i].Text = temp.ToString();                        if (i == 1)                        {                            if (Convert.ToInt32(tbboxs[i].Text) < 1)                                tbboxs[i].Text = "12";                        }                        if (i == 2)                        {                            if (Convert.ToInt32(tbboxs[i].Text) < 1)                                tbboxs[i].Text = GetCurrentMonthMaxDay().ToString();                        }                        if (i == 3)                        {                            if (Convert.ToInt32(tbboxs[i].Text) < 1)                                tbboxs[i].Text = "23";                        }                        if (i == 4 || i == 5)                        {                            if (Convert.ToInt32(tbboxs[i].Text) < 1)                                tbboxs[i].Text = "59";                        }                        break;                    }                }            }        }    }}
 |