// find all child of parent private void soLuongCom_SelectionChanged(object sender, SelectionChangedEventArgs e) { //init_monandachon(); double kaloFollow; ComboBox combo = sender as ComboBox; // cho lan chay dau tien, khi tag chua duoc binding if (combo.Tag == null) return; // lay tag của nhóm int checkTag = (int)combo.Tag; // lấy số lượng chọn int soluong = Int32.Parse((combo.SelectedItem as ComboBoxItem).Content.ToString()); // thay doi phan tu o list ThucDon td = monanChonList.Find(r => r.IdMonAn == checkTag); if (td == null) td = new ThucDon(); td.SoLuong = soluong; var lstText = AllChildren(combo.Parent).OfType<TextBlock>(); // truong hop check box chua duoc check if (((combo.Parent as StackPanel).Parent as CheckBox).IsChecked == false) { foreach (var item in lstText) { if ((item as TextBlock).Name.Equals("kaloBlock")) { // lay luong kalo cua mon an tu list; double kaloBD = monAnList.Find(r => r.IdMonAn == checkTag).LuongKaloTrenDonVi; // nhan voi so luong kaloFollow = kaloBD * soluong; // roi day ra man hinh (item as TextBlock).Text = kaloFollow.ToString(); } } } // truong hop check box da duoc check else { foreach (var item in lstText) { if ((item as TextBlock).Name.Equals("kaloBlock")) { // phai tru di luong ban dau TongLuongKalo -= Double.Parse((item as TextBlock).Text); // lay luong kalo cua mon an tu list; double kaloBD = monAnList.Find(r => r.IdMonAn == checkTag).LuongKaloTrenDonVi; // nhan voi so luong kaloFollow = kaloBD * soluong; td.LuongKalo = kaloFollow; // cong lai luong thay doi TongLuongKalo += kaloFollow; // roi day ra man hinh (item as TextBlock).Text = kaloFollow.ToString(); } } } }
//chuyen trang sau dialog //public void chuyenPage(IUICommand command) //{ // //Frame.Navigate(typeof(KaloNgoaiPage)); //} private void CheckBox_Checked(object sender, RoutedEventArgs e) { ThucDon td = new ThucDon(); // them cac IdThongKeNgay o day td.IdThongKeNgay = thongkengay.IdThongKeNgay; var checkMonAn = sender as CheckBox; td.IdMonAn = (int)(checkMonAn.Content as StackPanel).Tag; td.SoLuong = Int32.Parse(((checkMonAn.Content as StackPanel).Children.OfType<ComboBox>().FirstOrDefault().SelectedItem as ComboBoxItem).Content.ToString()); var listBlock = AllChildren(checkMonAn.Content as StackPanel).OfType<TextBlock>(); foreach (var item in listBlock) { if ((item as TextBlock).Name.Equals("kaloBlock")) { td.LuongKalo = double.Parse((item as TextBlock).Text); TongLuongKalo += double.Parse((item as TextBlock).Text); } } // chua co idThongKeNgay monanChonList.Add(td); }