void worker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; BatchPrintClass Params = e.Argument as BatchPrintClass; ModuleConfiguration Model = Params.modelInfo; String DataCode = Params.dataCode; ModelDataManager DataManager = new ModelDataManager(); DataSet dataSet = new DataSet(); if (dataID != null) { dataSet = DataManager.GetData(Model, dataID, DataCode); } else { dataSet = DataManager.GetData(Model, DataCode); } FpSpread fpSpread = new MyCell(); PrintDialog Dialog = new PrintDialog(); Dialog.AllowSomePages = true; Dialog.PrinterSettings.PrintRange = PrintRange.SomePages; Dialog.PrinterSettings.FromPage = 1; Dialog.PrinterSettings.ToPage = 1; if (DialogResult.OK == Dialog.ShowDialog()) { //初始化模板样式 fpSpread.Sheets.Clear(); foreach (SheetConfiguration Sheet in Model.Sheets) { SheetView SheetView = Serializer.LoadObjectXml(typeof(SheetView), Sheet.SheetStyle, "SheetView") as SheetView; SheetView.Tag = Sheet; SheetView.SheetName = Sheet.Description; fpSpread.Sheets.Add(SheetView); } fpSpread.LoadFormulas(true); //加载数据到模板样式 if (dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0) { foreach (DataRow Row in dataSet.Tables[0].Rows) { Application.DoEvents(); int Index = dataSet.Tables[0].Rows.IndexOf(Row); worker.ReportProgress((Index + 1) / dataSet.Tables[0].Rows.Count); String DataID = Row["ID"].ToString(); foreach (SheetView SheetView in fpSpread.Sheets) { SheetConfiguration SheetConfiguration = SheetView.Tag as SheetConfiguration; TableDefineInfo TableInfo = SheetConfiguration.DataTableSchema.Schema; if (TableInfo != null) { foreach (FieldDefineInfo FieldInfo in TableInfo.FieldInfos) { DataRow[] DataRows = dataSet.Tables[GetBracketName(TableInfo.Name)].Select("ID='" + DataID + "'"); SheetView.Cells[FieldInfo.RangeInfo].Value = DataRows[0][FieldInfo.FieldName]; } } } //批量打印 BatchPrintDocument Document = new BatchPrintDocument(fpSpread); Document.PrinterSettings = Dialog.PrinterSettings; Document.Print(); } e.Result = "已输出全部资料到打印机。"; } else { e.Result = string.Format("模板 {0} 中没有资料数据。", Model.Description); } fpSpread.Dispose(); fpSpread = null; } else { return; } }
public ModuleControlor(ModelDataManager dataManager) { DataManager = dataManager; }