예제 #1
0
파일: home.cs 프로젝트: wannaphong/timenone
        public TimeSpan timeOfDayOld = new TimeSpan(0, 0, 0);                           // ประกาศตัวแปร timeOfDayOld เป็นข้อมูลชนิด TimeSpan โดยเก็บข้อมูล TimeSpan เวลา 00:00:00
        public void check_time(DateTime s)                                              // ประกาศ method ชื่อ check_time โดยรับข้อมูล DateTime
        {
            TimeSpan timeOfDay = DateTime.Now.TimeOfDay;                                // ประกาศตัวแปร timeOfDay แทน DateTime.Now.TimeOfDay

            if (timeOfDayOld.ToString(@"hh\:mm") != timeOfDay.ToString(@"hh\:mm"))      // ให้เปรียบเทียบ timeOfDayOld กับ timeOfDay ถ้าไม่เท่ากัน
            {
                timeOfDayOld = timeOfDay;                                               // ให้ timeOfDayOld เท่ากับ  timeOfDay
                var day  = s.DayOfWeek.ToString();                                      // ประกาศตัวแปร day แทน s.DayOfWeek
                var time = new db.Notifications();                                      // ประกาศตัวแปร time แทน db.Notifications
                using (var db2 = new LiteDatabase(file))                                // เรียกใช้ข้อมูลจากฐานข้อมูล
                {
                    var orders = db2.GetCollection <db.Notifications>("Notifications"); // ประกาศตัวแปร orders แทน db.GetCollection<Notifications>("Notifications")

                    // ทำการ query กับ Order, เรียกใช้แทนการอ้างอิง
                    var query = orders
                                .Find(x => x.H == timeOfDay.Hours.ToString() && x.M == timeOfDay.Minutes.ToString()); // ค้นหาข้อมูลถ้า H ตรงกับ timeOfDay.Hours และ M ตรงกับ timeOfDay.Minutes
                    if (query.ToArray().Length != 0)                                                                  // ถ้า query.ToArray() แล้วยาวไม่เท่ากับ 0
                    {
                        foreach (var order in query)                                                                  // ลูป query ทีละตัวเก็บไว้ใน order
                        {
                            if (order.IsActive == true)                                                               // ถ้า IsActive เป็น true
                            {
                                switch (day)                                                                          // เช็คเงื่อนไขวันโดยใช้ตัวแปร day ด้วย switch case
                                {
                                case "Sunday":                                                                        // กรณีเป็นวันอาทิตย์
                                    if (order.Sunday == true)
                                    {
                                        show_Notifications(timeOfDay, order.Title); // ถ้า order.Sunday เป็นจริง (คือเปิดใช้งาน) ให้ใช้ method  show_Notifications ส่งค่า timeOfDay, order.Title
                                    }
                                    break;                                          // ออก

                                case "Monday":                                      // กรณีเป็นวันจันทร์
                                    if (order.Monday == true)
                                    {
                                        show_Notifications(timeOfDay, order.Title); // ถ้า order.Monday เป็นจริง (คือเปิดใช้งาน) ให้ใช้ method  show_Notifications ส่งค่า timeOfDay, order.Title
                                    }
                                    break;                                          // ออก

                                case "Tuesday":                                     // กรณีเป็นวันอังคาร
                                    if (order.Tuesday == true)
                                    {
                                        show_Notifications(timeOfDay, order.Title); // ถ้า order.Tuesday เป็นจริง (คือเปิดใช้งาน) ให้ใช้ method  show_Notifications ส่งค่า timeOfDay, order.Title
                                    }
                                    break;                                          // ออก

                                case "Wednesday":                                   // กรณีเป็นวันพุธ
                                    if (order.Wednesday == true)
                                    {
                                        show_Notifications(timeOfDay, order.Title); // ถ้า order.Wednesday เป็นจริง (คือเปิดใช้งาน) ให้ใช้ method  show_Notifications ส่งค่า timeOfDay, order.Title
                                    }
                                    break;                                          // ออก

                                case "Thursday":                                    // กรณีเป็นวันพฤหัสบดี
                                    if (order.Thursday == true)
                                    {
                                        show_Notifications(timeOfDay, order.Title); // ถ้า order.Thursday เป็นจริง (คือเปิดใช้งาน) ให้ใช้ method  show_Notifications ส่งค่า timeOfDay, order.Title
                                    }
                                    break;                                          // ออก

                                case "Friday":                                      // กรณีเป็นวันศุกร์
                                    if (order.Friday == true)
                                    {
                                        show_Notifications(timeOfDay, order.Title); // ถ้า order.Friday เป็นจริง (คือเปิดใช้งาน) ให้ใช้ method  show_Notifications ส่งค่า timeOfDay, order.Title
                                    }
                                    break;                                          // ออก

                                case "Saturday":                                    // กรณีเป็นวันเสาร์
                                    if (order.Saturday == true)
                                    {
                                        show_Notifications(timeOfDay, order.Title); // ถ้า order.Saturday เป็นจริง (คือเปิดใช้งาน) ให้ใช้ method  show_Notifications ส่งค่า timeOfDay, order.Title
                                    }
                                    break;                                          // ออก
                                }
                            }
                        }
                    }
                }
            }
            else // กรณีไม่เข้าเงื่อนไขข้างบน
            {
                name_5.Clear(); // ล้างข้อมูลใน name_5*
            }
        }
예제 #2
0
        private void check_time(DateTime s)
        {
            TimeSpan timeOfDay = s.TimeOfDay;
            var      day       = s.DayOfWeek.ToString();
            var      time      = new db.Notifications();

            //MessageBox.Show(day+timeOfDay.Hours.ToString() + timeOfDay.Minutes.ToString() + timeOfDay.Seconds.ToString());
            using (var db2 = new LiteDatabase(file))
            {
                var orders = db2.GetCollection <db.Notifications>("Notifications");

                // When query Order, includes references
                var query = orders//.Include(S => timeOfDay.Seconds.ToString())
                            .Find(x => x.H == timeOfDay.Hours.ToString() && x.M == timeOfDay.Minutes.ToString());
                if (query.ToArray().Length != 0)
                {
                    foreach (var order in query)
                    {
                        if (order.IsActive == true)
                        {
                            switch (day)
                            {
                            case "Sunday":
                                if (order.Sunday == true)
                                {
                                    show_Notifications(timeOfDay, order.Title);
                                }
                                break;

                            case "Monday":
                                if (order.Monday == true)
                                {
                                    show_Notifications(timeOfDay, order.Title);
                                }
                                break;

                            case "Tuesday":
                                if (order.Tuesday == true)
                                {
                                    show_Notifications(timeOfDay, order.Title);
                                }
                                break;

                            case "Wednesday":
                                if (order.Wednesday == true)
                                {
                                    show_Notifications(timeOfDay, order.Title);
                                }
                                break;

                            case "Thursday":
                                if (order.Thursday == true)
                                {
                                    show_Notifications(timeOfDay, order.Title);
                                }
                                break;

                            case "Friday":
                                if (order.Friday == true)
                                {
                                    show_Notifications(timeOfDay, order.Title);
                                }
                                break;

                            case "Saturday":
                                if (order.Saturday == true)
                                {
                                    show_Notifications(timeOfDay, order.Title);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }