/// <summary>
        /// Prints to pdf the transaction
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonPrintTransaction_OnClick(object sender, RoutedEventArgs e)
        {
            var            document = DataGridTransactions.ExportToPdf();
            SaveFileDialog sfd      = new SaveFileDialog
            {
                Filter = "PDF Files(*.pdf)|*.pdf"
            };

            if (sfd.ShowDialog() == true)
            {
                using (Stream stream = sfd.OpenFile())
                {
                    document.Save(stream);
                }

                //Message box confirmation to view the created Pdf file.

                if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created",
                                    MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    //Launching the Pdf file using the default Application.
                    Process.Start(sfd.FileName);
                }
            }
        }
Ejemplo n.º 2
0
        public void FillDataGrid(string date, string asset = null)
        {
            //filling datagrid investments
            string   selected_person    = "";
            DateTime date_selected_to   = new DateTime();
            DateTime date_selected_from = new DateTime();

            Dispatcher.Invoke(() =>
            {
                selected_person = HoldersItems.Where(r => r.IsChecked == true).Select(x => x.HolderName).First();
                if (date == null)
                {
                    date_selected_to   = Convert.ToDateTime(date_month_to.SelectedDate);
                    date_selected_from = Convert.ToDateTime(date_month_to.SelectedDate).AddMonths(-3);
                }
                else
                {
                    DateTime.TryParseExact(date, "MMM yy", new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.None, out date_selected_to);
                    date_selected_from = Convert.ToDateTime(date_month_from.SelectedDate);
                }
            });
            DataTable dt_investments  = BrokerageAsset.GetMonthInvestments(selected_person, date_selected_to);
            DataTable dt_transactions = BrokerageTransaction.GetHistoricalTransactions(asset, selected_person, date_selected_from, date_selected_to.AddMonths(1).AddDays(-1));

            if (dt_transactions.Rows.Count > 0)
            {
                dt_transactions = dt_transactions.AsEnumerable().OrderByDescending(r => r["date"]).CopyToDataTable();
            }
            Dispatcher.Invoke(() =>
            {
                if (dt_investments.Rows.Count > 0)
                {
                    date_grid.Text = "Date: " + dt_investments.Rows[0].Field <DateTime>("date").ToShortDateString();
                }
                else
                {
                    date_grid.Text = "";
                }
                DataGridInvestments.CommitEdit();
                DataGridInvestments.CommitEdit();
                DataGridInvestments.DataContext = dt_investments;

                DataGridTransactions.CommitEdit();
                DataGridTransactions.CommitEdit();
                DataGridTransactions.DataContext = dt_transactions;
            });
        }