private static string Print(IPrintable printaleObject, string formatter)
 {
     foreach (var prop in printaleObject.GetType().GetProperties())
     {
         object val = prop.GetValue(printaleObject, null);
         if (val is IPrintable)
         {
             return(String.Format(formatter, printaleObject.Name) + Print((IPrintable)val, formatter));
         }
     }
     return(String.Format(formatter, printaleObject.Name));
 }
Beispiel #2
0
 /// <summary>
 /// will print the array
 /// </summary>
 /// <param name="arr">shoudl contain array of IPrintable items</param>
 static void PrintArr(object[] arr)
 {
     foreach (IPrintable item in arr)
     {
         Console.WriteLine();
         Console.WriteLine(item.GetType());
         item.Print();
     }
     Console.WriteLine("\n\n________again___________\n\n");
     for (int i = 0; i < arr.Length; i++)
     {
         IPrintable ip = arr[i] as IPrintable;
         if (ip != null)
         {
             Console.WriteLine();
             Console.WriteLine(ip.GetType());
             ip.Print();
         }
     }
 }
Beispiel #3
0
        public static string PrintableString(this IPrintable obj)
        {
            return(obj
                   .GetType()
                   .GetProperties()
                   .Where(propInfo => !propInfo.GetCustomAttributes(typeof(NoPrintAttribute), false).Any())
                   .Aggregate(string.Empty, (result, propInfo) => result += propInfo.GetValue(obj) + "\t"));

            /*
             * var typeObj = obj.GetType();
             * var propInfos = typeObj.GetProperties();
             * var result = string.Empty;
             * foreach (var propInfo in propInfos)
             * {
             *  var attrs = propInfo.GetCustomAttributes(typeof(NoPrintAttribute), false);
             *  if (attrs.Length == 0)
             *  {
             *      var value = propInfo.GetValue(obj);
             *      result += value.ToString() + "\t";
             *  }
             * }
             * return result;
             * */
        }
Beispiel #4
0
/// <summary>
/// Setup & show the dialog
/// </summary>
/// <param name="queryManager"></param>
/// <param name="control"></param>
/// <returns></returns>

        public new static DialogResult Show(
            QueryManager queryManager,
            IPrintable control)
        {
// When the GridView is active we can mostly the standard DevExpress printing stuff.
// We just remove the Checkmark boxes and make sure all data is read in before starting the print.
// However, when LayoutView is active (Cids & structures only) we must work around a couple of issues.
// 1. Use CardView instead of LayoutView because LayoutView cards get split between pages.
// 2. Scaling does not put the proper number of cards per row. Fix by scaling the cards rather
//    than the print Document.
//
// Print scaling is persisted in Query.PrintScale

            if (Instance == null)
            {
                Instance = new PrintPreviewDialog();
            }
            Instance.Qm = queryManager;
            Query query = queryManager.Query;

            Instance.Control = control;

            if (control is MoleculeGridControl)
            {
                int    printScalePct = query.PrintScale;              // scale the document
                double scale         = printScalePct / 100.0;
                queryManager.ResultsFormat.PageScale = printScalePct; // do view scaling based on printScale

                MoleculeGridControl grid = control as MoleculeGridControl;
                ResultsFormat       rf   = queryManager.ResultsFormat;
                queryManager.DataTableManager.ResetFormattedBitmaps(); // for structures to be redrawn in correct size

                if (rf.UseBandedGridView)                              // hide check mark band for printing
                {
                    BandedGridView bgv = grid.MainView as BandedGridView;
                    if (Lex.Eq(bgv.Bands[0].Name, "CheckMark"))                     // hide checkmark band
                    {
                        bgv.Bands[0].Visible = false;
                    }

                    if (printScalePct > 0)
                    {
                        grid.ScaleBandedGridView(scale);                                        // scale the BandedGridView
                    }
                }

                else                 // switch to special card view for printing
                {
                    CardView cv = grid.GetCardView();
                    grid.MainView = cv;
                    string keyLabel = queryManager.Query.Tables[0].MetaTable.KeyMetaColumn.Label;
                    cv.CardCaptionFormat = keyLabel + ": {2}";                     // set proper caption

                    if (printScalePct > 0)
                    {
                        grid.ScaleCardView(scale);                                        // scale the CardView
                    }
                }

                DialogResult dr = ShowDialog(grid);

                // Reset the grid view

                queryManager.DataTableManager.ResetFormattedBitmaps();  // clear struct bitmaps so they get redrawn in correct size
                queryManager.ResultsFormat.PageScale = query.ViewScale; // switch back to doing view scaling based on viewScale

                if (rf.UseBandedGridView)                               // unhide check mark band
                {
                    BandedGridView bgv = grid.MainView as BandedGridView;
                    bgv.Bands[0].Visible = true;
                    grid.ScaleBandedGridView(query.ViewScale / 100.0);                     // scale back for viewing
                }

                else                 // switch back to layout view
                {
                    grid.MainView = grid.GetLayoutView();
                }

                grid.Refresh();

                return(dr);
            }

            else if (control is PivotGridControlMx)
            {
                PivotGridControlMx grid = control as PivotGridControlMx;
                DialogResult       dr   = ShowDialog(grid);
                return(dr);
            }

            //else if (control is ChartControlMx)
            //{
            //	ChartControlMx chart = control as ChartControlMx;
            //	DialogResult dr = ShowDialog(chart);
            //	return dr;
            //}

            else
            {
                throw new Exception("Invalid control type: " + control.GetType());
            }
        }