using Microsoft.Win32; using HotelPms.Share.Util; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using HotelPms.Share.Windows.Util; namespace HotelPms.Share.Windows.Report { public enum ReportType : int { Print = 0, Pdf, Xlsx, Csv, Html, Json, Xml, Xls, Preveiw, } #pragma warning disable CA1416 public abstract class ReportBase { protected float m_PrintWidth = 700F; // 印字使用幅(A4) protected float m_PrintHeight = 1032F; // 印字使用高(A4) protected float m_LeftMargins = 50F; //左余白 protected float m_TopMargins = 60F; //上余白 protected int m_PageCount = 0; protected int m_PageIndex = 1; protected int m_DataRowIndex = 0; protected float m_DetailRowHeight = 0F; protected float m_TitleHeight = 0F; protected int m_DetailRowCount = 0; protected float m_HeaderHeight = 0F; protected float m_CaptionHeight = 0F; //項目名の固定行 protected float m_FooterHeight = 0F; protected DataTable m_Data = null; public DataTable Data { get { return m_Data; } set { m_Data = value; } } protected GridStyle m_Style = null; public GridStyle Style { get { return m_Style; } set { m_Style = value; } } /// /// 1/100 インチ ⇒ Point /// /// /// public float GetPointWithDisplay(float value) { return value * 0.72F; } public float GetTextHeight(Graphics g, Font font) { return g.MeasureString("A", font).Height; } public float GetTextWidth(Graphics g, Font font, string text) { return g.MeasureString(text, font).Width; } public static void CreateColumnStyle(DataGridView grid, GridStyle style) { style.ColumnStyle.Clear(); int total = 0; int lastIdx = 0; foreach (DataGridViewColumn col in grid.Columns) { if (!col.Visible || (col.CellType.Name != "DataGridViewTextBoxCell")) { continue; } total += col.Width; lastIdx = col.Index; } float rate = 0F; foreach (DataGridViewColumn col in grid.Columns) { if (!col.Visible || (col.CellType.Name != "DataGridViewTextBoxCell")) { continue; } ColumnStyle colStyle = new ColumnStyle(); colStyle.DefaultCellStyle = new CellStyle(); colStyle.WidthRate = lastIdx == col.Index ? (1.0F - rate) : (float)CConvert.Divide(col.Width * 1.0F, total, 2); colStyle.Width = col.Width * 1.0F; rate += colStyle.WidthRate; colStyle.DataField = col.DataPropertyName.Length > 0 ? col.DataPropertyName : col.Name; colStyle.Text = col.HeaderText; colStyle.Alignment = GeneralSub.ToStringAlignment(grid.ColumnHeadersDefaultCellStyle.Alignment); colStyle.LineAlignment = GeneralSub.ToLineStringAlignment(grid.ColumnHeadersDefaultCellStyle.Alignment); colStyle.DefaultCellStyle.Alignment = GeneralSub.ToStringAlignment(col.DefaultCellStyle.Alignment); colStyle.DefaultCellStyle.LineAlignment = GeneralSub.ToLineStringAlignment(col.DefaultCellStyle.Alignment); colStyle.DefaultCellStyle.Font = col.DefaultCellStyle.Font; colStyle.Font = grid.ColumnHeadersDefaultCellStyle.Font; style.ColumnStyle.Add(colStyle); } } public static SortedDictionary ReadFontInformation() { var dictionary = new SortedDictionary(); RegistryKey mykey = Registry.LocalMachine; string key = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"; using (RegistryKey regkey = mykey.OpenSubKey(key, false)) { if (regkey != null) { //获取字体名 string[] mynames = regkey.GetValueNames(); foreach (string name in mynames) { //获取字体的文件名 string myvalue = regkey.GetValue(name).ToString(); if (myvalue.Substring(myvalue.Length - 4).ToUpper() == ".TTF" && myvalue.Substring(1, 2).ToUpper() != @":\") { string val = name.Substring(0, name.Length - 11); dictionary[val] = myvalue; } } regkey.Close(); } } return dictionary; } } }