Пример #1
0
        private void Print()
        {
            AnalyzeView analyzeView = new AnalyzeView();

            analyzeView.Show();

            return;

            CalendarView calendar = new CalendarView();

            calendar.ViewModel.OKClicked += (s, e) =>
            {
                var data = e.EventData;

                var startDate = data.Item1;
                var endDate   = data.Item2;

                if (startDate > endDate)
                {
                    var temp = startDate;
                    startDate = endDate;
                    endDate   = temp;
                }

                var result = _database.GetPeriodListAccount(DateHelper.ToStringDate(startDate), DateHelper.ToStringDate(endDate));
                try
                {
                    var modelList = JsonConvert.DeserializeObject <List <DailyModel> >(result);
                    modelList.Sort((DailyModel x, DailyModel y) => x.Date.CompareTo(y.Date));

                    if (modelList != null && modelList.Count > 0)
                    {
                        Microsoft.Office.Interop.Word.Application word     = new Microsoft.Office.Interop.Word.Application();
                        Microsoft.Office.Interop.Word.Document    document = new Microsoft.Office.Interop.Word.Document();

                        Object oMissing = System.Reflection.Missing.Value;
                        Object oFalse   = false;

                        Microsoft.Office.Interop.Word.Paragraph paragraph = document.Content.Paragraphs.Add(ref oMissing);
                        paragraph.Range.Font.Size = 15;

                        object start     = 0;
                        object end       = 0;
                        object oEndOfDoc = "\\endofdoc";
                        Microsoft.Office.Interop.Word.Range tableLocation = document.Bookmarks.get_Item(ref oEndOfDoc).Range;
                        var table = document.Content.Tables.Add(tableLocation, modelList.Count, 4);
                        table.Range.Font.Size          = 15;
                        table.Borders.InsideLineStyle  = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                        table.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
                        table.AllowAutoFit             = true;

                        int row = 1;
                        foreach (var model in modelList)
                        {
                            table.Cell(row, 1).Range.Text = model.Date;
                            table.Cell(row, 2).Range.Text = model.Type.ToString();
                            table.Cell(row, 3).Range.Text = model.Name;

                            if (model.Type == ItemType.Outgo || model.Type == ItemType.Kakao ||
                                model.Type == ItemType.Samsung || model.Type == ItemType.Hana ||
                                model.Type == ItemType.Hyundai || model.Type == ItemType.Cash)
                            {
                                table.Cell(row, 4).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorRed;
                            }
                            else
                            {
                                table.Cell(row, 4).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlue;
                            }

                            table.Cell(row, 4).Range.Text = "\\ " + string.Format("{0:###,###,###,###,###,###,###}", model.Amount);

                            row++;
                        }

                        table.Columns[1].AutoFit();
                        Single width1 = table.Columns[1].Width;
                        table.AutoFitBehavior(Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitContent); // fill page width
                        table.Columns[1].SetWidth(width1, Microsoft.Office.Interop.Word.WdRulerStyle.wdAdjustFirstColumn);

                        table.Columns[2].AutoFit();
                        Single width2 = table.Columns[2].Width;
                        table.AutoFitBehavior(Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitContent); // fill page width
                        table.Columns[2].SetWidth(width2, Microsoft.Office.Interop.Word.WdRulerStyle.wdAdjustFirstColumn);

                        table.Columns[3].AutoFit();
                        Single width3 = table.Columns[3].Width;
                        table.AutoFitBehavior(Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitContent); // fill page width
                        table.Columns[3].SetWidth(width3, Microsoft.Office.Interop.Word.WdRulerStyle.wdAdjustFirstColumn);

                        table.Columns[4].AutoFit();
                        Single width4 = table.Columns[4].Width;
                        table.AutoFitBehavior(Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitContent); // fill page width
                        table.Columns[4].SetWidth(width4, Microsoft.Office.Interop.Word.WdRulerStyle.wdAdjustFirstColumn);

                        table.Rows.Alignment = Microsoft.Office.Interop.Word.WdRowAlignment.wdAlignRowCenter;

                        document.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;

                        Object fileName = Directory.GetCurrentDirectory() + "\\" + "Report_" + DateHelper.ToStringDate(startDate) + "_" + DateHelper.ToStringDate(endDate) + ".doc";

                        try
                        {
                            document.SaveAs(ref fileName);

                            System.Diagnostics.Process.Start(fileName.ToString());

                            if (word.ActivePrinter != null || word.ActivePrinter != "")
                            {
                                document.PrintOut(ref oFalse, ref oMissing, ref oMissing, ref oMissing,
                                                  ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oFalse,
                                                  ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                            }

                            document.Close();
                            word.Quit();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("오류가 발생했습니다. 다시 시도 해 주세요.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            };
            calendar.ViewModel.Closing += (s, e) =>
            {
                calendar.Close();
            };
            calendar.ViewModel.SelectedStartDate = DateHelper.GetMondayOfWeek(_selectedDate);
            calendar.ViewModel.SelectedEndDate   = DateHelper.GetSundayOfWeek(_selectedDate);
            calendar.ShowDialog();
        }