async void FillData(Family f) { var hs = House.GetHouseAllByFamilyID(f.FamilyID); if (hs != null && hs.Count() > 0) { f.FamilyHouse = hs.Last(); } else { f.FamilyHouse = new House(); } if (f.FamilyID.HasValue) { cFamily.dgChild.ItemsSource = (from x in FamilyPerson.GetFamilyPersonByFamilyID(f.FamilyID.Value) orderby x.DOB select x).ToList(); } else { cFamily.dgChild.ItemsSource = new List <FamilyPerson>(); } cFamilyNeed.FamilyID = f.FamilyID; cExternalFamilySupport.FamilyID = f.FamilyID; //cFamilyProperty.FamilyID = FamilyID; cSpecialCard.FamilyID = f.FamilyID; cListerGroup.FamilyID = f.FamilyID; cAdminEvaluation.FamilyID = f.FamilyID; cOrders.FamilyID = f.FamilyID; cFamily.txtFamilyCode.IsReadOnly = true; var lst = cOrders?.lvOrders?.ItemsSource as List <Order>; if (lst != null && lst.Count > 0 && lst.Where(x => x.NextOrderDate.HasValue).Count() > 0) { var MaxNextOrderDate = lst.Where(x => x.NextOrderDate.HasValue).Select(x => x.NextOrderDate.Value).Max(); if (MaxNextOrderDate > BaseDataBase.DateNow) { MyMessageBox.Show("متبقي " + (MaxNextOrderDate - BaseDataBase.DateNow).Days + " ايام للاستلام القادم\nتاريخ الاستلام القادم " + MaxNextOrderDate.ToShortDateString()); } } }
private void btnPrintAll_Click(object sender, RoutedEventArgs e) { if (cmboPrintType.SelectedIndex == 0) { SaveFileDialog dlg = new SaveFileDialog(); dlg.DefaultExt = ".xps"; dlg.Filter = "XPS Print Documents (.xps)|*.xps"; if (dlg.ShowDialog() == true) { tfs = new List <TempFamily>(); FileName = dlg.FileName; if (FileName.Substring(FileName.LastIndexOf('.'), FileName.Length - FileName.LastIndexOf('.')) != ".xps") { FileName += ".xps"; } foreach (DataRowView item in dgmain.ItemsSource as DataView) { tfs.Add(TempFamily.GetTempFamilyByID((int)item[0])); } try { FixedDocument fd = new FixedDocument(); fd.DocumentPaginator.PageSize = new Size(1056, 768); int index = 0; foreach (var f in tfs) { index++; var pc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "TempFamilyReportTemplate.xaml")) as PageContent; if (pc != null) { pc.Child.Margin = new Thickness(25); var img = pc.FindName("img") as Image; if (img != null) { img.Stretch = Stretch.Fill; BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute); bi.EndInit(); img.Source = bi; } var txtUser = pc.FindName("txtUser") as TextBlock; if (txtUser != null) { txtUser.Text = BaseDataBase.CurrentUser.Name; } var txt = pc.FindName("txtMainDescription") as TextBlock; if (txt != null) { txt.Text = Properties.Settings.Default.ReportHeaderDescription; } var gridChild = pc.Child.FindName("grdChilds") as Grid; if (gridChild != null) { int i = 1; foreach (var tc in f.TempChilds) { TextBlock tb1 = new TextBlock(); tb1.Text = tc.Name; tb1.SetValue(Grid.ColumnProperty, 1); tb1.SetValue(Grid.RowProperty, i); TextBlock tb2 = new TextBlock(); tb2.Text = tc.Gender; tb2.SetValue(Grid.ColumnProperty, 2); tb2.SetValue(Grid.RowProperty, i); TextBlock tb3 = new TextBlock(); tb3.Text = tc.DOB.Value.ToString("dd/MM/yyyy"); tb3.SetValue(Grid.ColumnProperty, 4); tb3.SetValue(Grid.RowProperty, i); gridChild.Children.Add(tb1); gridChild.Children.Add(tb2); gridChild.Children.Add(tb3); i++; } } pc.Child.DataContext = null; pc.Child.DataContext = f; fd.Pages.Add(pc); } } CreateXPSDocument(fd.DocumentPaginator, FileName); foreach (var item in tfs) { item.Printer = BaseDataBase.CurrentUser.Name; item.IsPrinted = true; TempFamily.UpadteData(item); } MyMessageBox.Show("تمت الطباعة بنجاح"); } catch (Exception ex) { MyMessageBox.Show(ex.Message); } } } else { SaveFileDialog dlg = new SaveFileDialog(); dlg.DefaultExt = ".xps"; dlg.Filter = "XPS Print Documents (.xps)|*.xps"; if (dlg.ShowDialog() == true) { fs = new List <Family>(); FileName = dlg.FileName; if (FileName.Substring(FileName.LastIndexOf('.'), FileName.Length - FileName.LastIndexOf('.')) != ".xps") { FileName += ".xps"; } foreach (DataRowView item in dgmain.ItemsSource as DataView) { fs.Add(Family.GetFamilyByID((int)item[0])); } try { FixedDocument fd = new FixedDocument(); fd.DocumentPaginator.PageSize = new Size(1056, 768); int index = 0; foreach (var f in fs) { index++; var pc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "FamilyReportTemplate.xaml")) as PageContent; if (pc != null) { pc.Child.Margin = new Thickness(25); var img = pc.FindName("img") as Image; if (img != null) { img.Stretch = Stretch.Fill; BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute); bi.EndInit(); img.Source = bi; } var txt = pc.FindName("txtMainDescription") as TextBlock; if (txt != null) { txt.Text = Properties.Settings.Default.ReportHeaderDescription; } var gridHouse = pc.Child.FindName("grdHouse") as Grid; if (gridHouse != null) { var hs = House.GetHouseAllByFamilyID(f.FamilyID); if (hs != null && hs.Count > 0) { gridHouse.DataContext = hs.Last(); } } var gridChild = pc.Child.FindName("grdChilds") as Grid; if (gridChild != null) { int i = 1; foreach (var tc in FamilyPerson.GetFamilyPersonByFamilyID(f.FamilyID.Value)) { TextBlock tb1 = new TextBlock(); tb1.Text = tc.FirstName; tb1.SetValue(Grid.ColumnProperty, 1); tb1.SetValue(Grid.RowProperty, i); TextBlock tb2 = new TextBlock(); tb2.Text = tc.Gender; tb2.SetValue(Grid.ColumnProperty, 2); tb2.SetValue(Grid.RowProperty, i); TextBlock tb3 = new TextBlock(); tb3.Text = tc.RelationShip; tb3.SetValue(Grid.ColumnProperty, 3); tb3.SetValue(Grid.RowProperty, i); TextBlock tb4 = new TextBlock(); tb4.Text = tc.DOB.Value.ToString("dd/MM/yyyy"); tb4.SetValue(Grid.ColumnProperty, 4); tb4.SetValue(Grid.RowProperty, i); TextBlock tb5 = new TextBlock(); tb5.Text = tc.StudyStatus; tb5.SetValue(Grid.ColumnProperty, 5); tb5.SetValue(Grid.RowProperty, i); TextBlock tb6 = new TextBlock(); tb6.Text = tc.HealthStatus; tb6.SetValue(Grid.ColumnProperty, 6); tb6.SetValue(Grid.RowProperty, i); TextBlock tb7 = new TextBlock(); tb7.Text = tc.MaritalStatus; tb7.SetValue(Grid.ColumnProperty, 7); tb7.SetValue(Grid.RowProperty, i); TextBlock tb8 = new TextBlock(); tb8.Text = tc.Job; tb8.SetValue(Grid.ColumnProperty, 8); tb8.SetValue(Grid.RowProperty, i); gridChild.Children.Add(tb1); gridChild.Children.Add(tb2); gridChild.Children.Add(tb3); gridChild.Children.Add(tb4); gridChild.Children.Add(tb5); gridChild.Children.Add(tb6); gridChild.Children.Add(tb7); gridChild.Children.Add(tb8); i++; } } pc.Child.DataContext = null; pc.Child.DataContext = f; fd.Pages.Add(pc); } } CreateXPSDocument(fd.DocumentPaginator, FileName); MyMessageBox.Show("تمت الطباعة بنجاح"); } catch (Exception ex) { MyMessageBox.Show(ex.Message); } } } }
async void FillData(Orphan o) { Family f = o.OrphanFamily; var hs = House.GetHouseAllByFamilyID(f.FamilyID); if (hs != null && hs.Count() > 0) { f.FamilyHouse = hs.Last(); } else { f.FamilyHouse = new House(); } if (f.FamilyID.HasValue) { cOrphanFamily.dgChild.ItemsSource = (from x in FamilyPerson.GetFamilyPersonByFamilyID(f.FamilyID.Value) orderby x.DOB select x).ToList(); } else { cOrphanFamily.dgChild.ItemsSource = new List <FamilyPerson>(); } cFamilyNeed.FamilyID = f.FamilyID; cExternalFamilySupport.FamilyID = f.FamilyID; cSpecialCard.FamilyID = f.FamilyID; cListerGroup.FamilyID = f.FamilyID; cTrainings.FamilyID = f.FamilyID; if (o.OrphanID.HasValue) { cSponsor.OrphanID = o.OrphanID; } cOrders.FamilyID = f.FamilyID; cOrphanFamily.txtFamilyCode.IsReadOnly = true; if (o.OrphanID.HasValue) { o.Account = Account.GetAccountByOwnerID(Account.AccountType.Student, o.OrphanID.Value); cAccount.Account = o.Account; } Guardian.GetAllGuardianByFamily(f); if (f.OrphanNursemaid == null) { f.OrphanNursemaid = new Guardian() { Gender = "أنثى" } } ; if (f.OrphanGuardian == null) { f.OrphanGuardian = new Guardian() { Gender = "ذكر" } } ; f.FamilyOrphans = await Orphan.GetAllOrphanByFamily(f, o, true); cOrphanFamily.Orphans = await Orphan.GetAllOrphanByFamily(f, o); }