下面示範 如何將 Microsoft Report不預覽 不顯示選印表機的對話框直接列印 到印表機 //報表資料來源ReportDataSource MyRDS = new ReportDataSource("DataSet1", (DataTable)MyDS.DataTable1);LocalReport MyReport = new LocalReport(); //本機報表MyReport.ReportEmbeddedResource = "WindowsFormsApplication1.Report2.rdlc"; //內崁資料名稱MyReport.DataSources.Add(MyRDS); //設定報表資料來源Warning[] warnings; //繪製報表時的警告清單int intIndex = 0; //頁數索引List<Stream> MyStreamList = new List<Stream>(); //各頁的串流//將報表繪製到串流MyReport.Render("Image", @"<DeviceInfo> <OutputFormat>EMF</OutputFormat> <PageWidth>10cm</PageWidth> <PageHeight>4cm</PageHeight> <MarginTop>0cm</MarginTop> <MarginLeft>0cm</MarginLeft> <MarginRight>0cm</MarginRight> <MarginBottom>0cm</MarginBottom> </DeviceInfo>", (Name, FileName, encode, mimeType, WillSeek) => { Stream stream = new MemoryStream(); //建立新串流 MyStreamList.Add(stream); return stream; }, out warnings);PrintDocument MyPD = new PrintDocument(); //列印文件//指定印表機名稱MyPD.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";//指定紙張大小 單位 百分之一英吋MyPD.DefaultPageSettings.PaperSize = new PaperSize("MySize", 393, 157);MyPD.PrintPage += (s, ev) => { //每列印一頁時的事件 Rectangle MyRectangle = new Rectangle( //計算調整大小 ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX, ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY, ev.PageBounds.Width, ev.PageBounds.Height); //將該頁串流位置設到起頭 MyStreamList[intIndex].Position = 0; //從串流繪製到印表機 ev.Graphics.DrawImage(new Metafile(MyStreamList[intIndex]), MyRectangle); //計算是否還有一下頁 ev.HasMorePages = ++intIndex < MyStreamList.Count;};MyPD.Print(); //列印
匿名型別 在 Linq 查詢中十分的好用但若將其 繫結 到 DataGridView 時要再取出就有點麻煩
方式如下:
使用Sql Server Management Studio 還原資料庫時,常會遇到 "無法獲得獨佔存取權,因為資料庫正在使用中" 的錯誤訊息 我的一勞永逸解決方法用指令還原指令如下ALTER DATABASE 你的DB名稱 SET OFFLINE WITH ROLLBACK IMMEDIATE RESTORE DATABASE 你的DB名稱 FROM DISK='C:\你的路徑\你的備份檔點BAK' WITH RESTRICTED_USER,REPLACE
使用Entity Framework在WinForm 中 Bind 到 DataGridView 似乎沒有排序功能就算加了BindingSource好像也沒用
所以我對 DataGridView 寫了一個擴充方法 SortEntity 如下
所以我們只要在DataGridView 的ColumnHeaderMouseClickEvent下SortEntity的方法 如下就可以排序囉~
使用Entity Framework在WinForm 中 Bind 到 DataGridView若對Entity 更新資料 DataGridView 會立即跟者改變若是新增時 則DataGridView一動也不動就算對DataGridView 下 Refresh 也沒用
這時要 dataGridView1.DataSource = MyEntity.Customers.Execute(MergeOption.AppendOnly);
它會重新對DB作Query 並 見其 MergeOption 它只會查 AppendOnly的部分