Exemplo n.º 1
0
        private async void Add_Shift_btn_Click(object sender, RoutedEventArgs e)
        {
            string btnName = (sender as Button).Name.ToString();

            string[] element = btnName.Split('_');
            var      f       = new Add_Shift(element[1], element[2]);

            f.ShowDialog();

            //add thì update thằng đó thôi, update hết sẽ lâu
            ShiftMapping currentElement = listShiftMapping.Find((map) => map.button == (sender as Button));

            currentElement.shift.Status = 0;
            await LoadShift(currentElement);
        }
Exemplo n.º 2
0
        //async thì c# tự hiểu là tạo thread mới
        private async Task LoadShift(ShiftMapping map)
        {
            //tạo kiểu task
            await Task.Run(() =>
            {
                //có cập nhật UI thì phải xài hàm này để đảm bảo không conflict UI
                this.Dispatcher.Invoke(() =>
                {
                    //đoạn này của m
                    if (map.shift.Status == 0)
                    {
                        Object Id = new
                        {
                            Week    = DateTime.Today.DayOfYear / 7,
                            WeekDay = map.shift.WeekDay,
                            Shift   = map.shift.Shift
                        };
                        ShiftDAO dao = new ShiftDAO();

                        UserShiftEntity sample = dao.get(Id, typeof(UserShiftEntity)) as UserShiftEntity;

                        map.button.Visibility    = Visibility.Hidden;
                        BrushConverter bc        = new BrushConverter();
                        map.textBlock.Background = (Brush)bc.ConvertFrom("#DCDCDC");

                        map.textBlock.Text =
                            (new UserDAO().get(sample.CashierID) as UserEntity)
                            .FullName.Trim();

                        map.textBlock.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        map.button.Visibility    = Visibility.Visible;
                        map.textBlock.Visibility = Visibility.Hidden;
                    }
                });
            });
        }