|
|
@@ -0,0 +1,788 @@
|
|
|
+using System;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Data;
|
|
|
+using NPOI.SS.Util;
|
|
|
+using System.Drawing;
|
|
|
+using System.Windows;
|
|
|
+using System.Reflection;
|
|
|
+using NPOI.SS.UserModel;
|
|
|
+using NPOI.XSSF.UserModel;
|
|
|
+using NPOI.HSSF.UserModel;
|
|
|
+using System.Globalization;
|
|
|
+using System.ComponentModel;
|
|
|
+using SHJX.Service.Model.Dao;
|
|
|
+using System.Drawing.Imaging;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Windows.Media.Imaging;
|
|
|
+using Microsoft.Office.Interop.Word;
|
|
|
+using SHJX.Service.Common.Calculate;
|
|
|
+using DataTable = System.Data.DataTable;
|
|
|
+using Application = Microsoft.Office.Interop.Word.Application;
|
|
|
+using HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment;
|
|
|
+
|
|
|
+using OfficeOpenXml;
|
|
|
+using OfficeOpenXml.Style;
|
|
|
+using LicenseContext = OfficeOpenXml.LicenseContext;
|
|
|
+
|
|
|
+namespace SHJX.Service.Common.Extend
|
|
|
+{
|
|
|
+ public static class Converter
|
|
|
+ {
|
|
|
+ #region ExcelConvert
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// DataTable -> Excel
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dt">DataTable数据</param>
|
|
|
+ /// <param name="filePath">文件路径</param>
|
|
|
+ /// <param name="headLineName">头部行 默认无</param>
|
|
|
+ public static void ConvertToExcel(this DataTable dt, string filePath, string headLineName = null)
|
|
|
+ {
|
|
|
+ var fileExt = Path.GetExtension(filePath).ToLower();
|
|
|
+ IWorkbook workbook = fileExt switch
|
|
|
+ {
|
|
|
+ ".xlsx" => new XSSFWorkbook(),
|
|
|
+ ".xls" => new HSSFWorkbook(),
|
|
|
+ _ => null
|
|
|
+ };
|
|
|
+ if (workbook is null) return;
|
|
|
+ var sheet = string.IsNullOrEmpty(dt.TableName) ? workbook.CreateSheet("Sheet1") : workbook.CreateSheet(dt.TableName);
|
|
|
+ var rowNumber = 0;
|
|
|
+ if (headLineName is not null)
|
|
|
+ {
|
|
|
+ var rowHead = sheet?.CreateRow(rowNumber);
|
|
|
+ rowNumber++;
|
|
|
+ sheet?.AddMergedRegion(new CellRangeAddress(0, 0, 0, dt.Columns.Count - 1));
|
|
|
+ var cellHead = rowHead?.CreateCell(0);
|
|
|
+ //设置单元格内容
|
|
|
+ cellHead?.SetCellValue(headLineName);
|
|
|
+ var style = workbook.CreateCellStyle();
|
|
|
+ //设置单元格的样式:水平对齐居中
|
|
|
+ style.Alignment = HorizontalAlignment.Center;
|
|
|
+ //新建一个字体样式对象
|
|
|
+ var font = workbook.CreateFont();
|
|
|
+ font.FontHeightInPoints = 20;
|
|
|
+ //设置字体加粗样式
|
|
|
+ //使用SetFont方法将字体样式添加到单元格样式中
|
|
|
+ style.SetFont(font);
|
|
|
+ //将新的样式赋给单元格
|
|
|
+ if (cellHead is not null) cellHead.CellStyle = style;
|
|
|
+ }
|
|
|
+
|
|
|
+ //表头
|
|
|
+ if (sheet is not null)
|
|
|
+ {
|
|
|
+ var row = sheet.CreateRow(rowNumber);
|
|
|
+ for (var i = 0; i < dt.Columns.Count; i++)
|
|
|
+ {
|
|
|
+ var cell = row.CreateCell(i);
|
|
|
+ cell.SetCellValue(dt.Columns[i].ColumnName);
|
|
|
+ if (!rowNumber.Equals(0)) continue;
|
|
|
+ var style = workbook.CreateCellStyle();
|
|
|
+ //设置单元格的样式:水平对齐居中
|
|
|
+ style.Alignment = HorizontalAlignment.Center;
|
|
|
+ //新建一个字体样式对象
|
|
|
+ var font = workbook.CreateFont();
|
|
|
+ font.FontHeightInPoints = 12;
|
|
|
+ font.Boldweight = (short)FontBoldWeight.Bold;
|
|
|
+ style.SetFont(font);
|
|
|
+ cell.CellStyle = style;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据绑定
|
|
|
+ for (var i = 0; i < dt.Rows.Count; i++)
|
|
|
+ {
|
|
|
+ if (sheet is null) continue;
|
|
|
+ var row1 = sheet.CreateRow(i + rowNumber + 1);
|
|
|
+ for (var j = 0; j < dt.Columns.Count; j++)
|
|
|
+ {
|
|
|
+ var cell = row1.CreateCell(j);
|
|
|
+ if (dt.Rows[i][j].GetType().IsValueType)
|
|
|
+ {
|
|
|
+ cell.SetCellValue(Convert.ToDouble(dt.Rows[i][j]));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cell.SetCellValue(dt.Rows[i][j].ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //转为字节数组
|
|
|
+ var stream = new MemoryStream();
|
|
|
+ workbook.Write(stream);
|
|
|
+ var buf = stream.ToArray();
|
|
|
+ //保存为Excel文件
|
|
|
+ using var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
|
|
|
+ fs.Write(buf, 0, buf.Length);
|
|
|
+ fs.Flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Excel->DataTable
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="filePath">Excel文件路径</param>
|
|
|
+ public static DataTable ReadExcel(this string filePath)
|
|
|
+ {
|
|
|
+ IWorkbook iwkX;
|
|
|
+ using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
|
+ {
|
|
|
+ iwkX = WorkbookFactory.Create(fs);
|
|
|
+ fs.Close();
|
|
|
+ }
|
|
|
+ //sheet
|
|
|
+ var dt = new DataTable();
|
|
|
+ for (var h = 0; h < iwkX.NumberOfSheets; h++)
|
|
|
+ {
|
|
|
+ var sheet = iwkX.GetSheetAt(h);
|
|
|
+ var rows = sheet.GetRowEnumerator();
|
|
|
+ var isMove = rows.MoveNext();
|
|
|
+ //循环sheet
|
|
|
+ if (!isMove) continue;
|
|
|
+ var cols = (IRow)rows.Current;
|
|
|
+ dt.TableName = sheet.SheetName;
|
|
|
+ for (var i = 0; i < cols?.LastCellNum; i++)
|
|
|
+ {
|
|
|
+ dt.Columns.Add(cols.GetCell(i).ToString());
|
|
|
+ }
|
|
|
+ while (rows.MoveNext())
|
|
|
+ {
|
|
|
+ var row = (IRow)rows.Current;
|
|
|
+ var dr = dt.NewRow();
|
|
|
+ for (var i = 0; i < row?.LastCellNum; i++)
|
|
|
+ {
|
|
|
+ var cell = row.GetCell(i);
|
|
|
+ dr[i] = cell is null ? string.Empty : cell.ToString();
|
|
|
+ }
|
|
|
+ dt.Rows.Add(dr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return dt;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region DataTable -> List<T>
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 将DataTable转换为List
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dt"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static List<T> ConvertToList<T>(this DataTable dt) where T : class, new()
|
|
|
+ {
|
|
|
+ List<T> lists = new List<T>(); // 定义集合
|
|
|
+ foreach (DataRow dr in dt.Rows) //遍历DataTable中所有的数据行
|
|
|
+ {
|
|
|
+ T t = new();
|
|
|
+ PropertyInfo[] propertys = typeof(T).GetProperties(); // 获得此模型的公共属性
|
|
|
+ foreach (PropertyInfo item in propertys) //遍历该对象的所有属性
|
|
|
+ {
|
|
|
+ object[] attr = item.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|
|
+ string description = attr.Length.Equals(0) ? item.Name : ((DescriptionAttribute)attr[0]).Description;
|
|
|
+ //检查DataTable是否包含此列(列名等于对象的属性的Description属性)
|
|
|
+ if (!dt.Columns.Contains(description)) continue;
|
|
|
+ if (!item.CanWrite) continue; //该属性不可写,直接跳出
|
|
|
+ object value = dr[description];//取值
|
|
|
+ if (value.Equals(DBNull.Value)) continue;//如果非空,则赋给对象的属性
|
|
|
+ value = item.PropertyType.FullName switch
|
|
|
+ {
|
|
|
+ "System.String" => value.ToString(),
|
|
|
+ "System.Double" => Convert.ToDouble(value),
|
|
|
+ "System.Boolean" => value.Equals("1"),
|
|
|
+ "System.Int32" => Convert.ToInt32(value),
|
|
|
+ _ => throw new ArgumentNullException(item.PropertyType.FullName),
|
|
|
+ };
|
|
|
+ item.SetValue(t, value, null);
|
|
|
+ }
|
|
|
+ lists.Add(t); //对象添加到泛型集合中
|
|
|
+ }
|
|
|
+ return lists;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region List<EquipmentTask> -> Word
|
|
|
+ public static bool ConvertToExcel(this List<EquipmentTask> tasks, object path)
|
|
|
+ {
|
|
|
+ DataTable dt = new("Result");
|
|
|
+ dt.Columns.Add("类型", Type.GetType("System.String")!);
|
|
|
+ dt.Columns.Add("样品编号", Type.GetType("System.String")!);
|
|
|
+ dt.Columns.Add("取样体积", Type.GetType("System.String")!);
|
|
|
+ dt.Columns.Add("取样倍数", Type.GetType("System.String")!);
|
|
|
+ dt.Columns.Add("浓度", Type.GetType("System.String")!);
|
|
|
+ dt.Columns.Add("滴定体积", Type.GetType("System.String")!);
|
|
|
+ dt.Columns.Add("结果", Type.GetType("System.String")!);
|
|
|
+ dt.Columns.Add("分析时间", Type.GetType("System.String")!);
|
|
|
+ List<EquipmentTask> calibrationTasks = tasks.Where(item => item.TaskType.Equals("标定")).ToList();
|
|
|
+ //if (calibrationTasks is null or { Count: 0 })
|
|
|
+ //{
|
|
|
+ // calibrationTasks = DataCentre._dataManager.GetLastOtherTaskByWaveKey(item, level);
|
|
|
+ // tempCount = 0; GetLastOtherTaskByWaveKey("空白", task.SampleConcentration);// SearchOtherTask(TaskTypeName.CALIBRATION_ZH);
|
|
|
+ //}
|
|
|
+ if (calibrationTasks is not null)
|
|
|
+ {
|
|
|
+ InsertDataTable(calibrationTasks);
|
|
|
+ }
|
|
|
+ List<EquipmentTask> blankTasks = tasks.Where(item => item.TaskType.Equals("空白")).ToList();
|
|
|
+ //if (blankTasks is null or { Count: 0 })
|
|
|
+ //{
|
|
|
+ // blankTasks = GeBlankTaskResult(TaskTypeName.BLANK_ZH);
|
|
|
+ //}
|
|
|
+ if (blankTasks is not null)
|
|
|
+ {
|
|
|
+ InsertDataTable(blankTasks);
|
|
|
+ }
|
|
|
+ List<EquipmentTask> sampleTasks = tasks.Where(item => item.TaskType.Equals("水样")).ToList();
|
|
|
+ if (sampleTasks is not null)
|
|
|
+ {
|
|
|
+ InsertDataTable(sampleTasks);
|
|
|
+ }
|
|
|
+ dt.ExportResult(path.ToString(), tasks[0].WaveKey);
|
|
|
+
|
|
|
+ void InsertDataTable(List<EquipmentTask> insertTasks)
|
|
|
+ {
|
|
|
+ insertTasks.ForEach(task =>
|
|
|
+ {
|
|
|
+ dt.Rows.Add(task.TaskType, task.TaskDetailName, task.GetSampleVolume.ToString("F2"),
|
|
|
+ task.GetSampleMultiple.ToString("F2"), task.SampleConcentration.Equals("Low")?"低":"高",task.Amount.ToString("F2"),
|
|
|
+ task.Result.ToString("F2"), task.CreateTime.ToString("yyyy-MM-dd"));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ public static void ExportResult(this DataTable dt, string filePath,string wavekay)
|
|
|
+ {
|
|
|
+ string savePath = $"{filePath}\\SampleResult_{wavekay}.xlsx";
|
|
|
+ ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
|
|
+ using ExcelPackage package = new();
|
|
|
+ ExcelWorksheet sheet = package.Workbook.Worksheets.Add("SampleResult");
|
|
|
+ for (int i = 0; i < dt.Columns.Count; i++)
|
|
|
+ {
|
|
|
+ sheet.Column(i + 1).Width = 15;
|
|
|
+ }
|
|
|
+ sheet.Row(1).Style.Font.Bold = true;
|
|
|
+ sheet.Row(1).Style.Font.Size = 12;
|
|
|
+ sheet.Row(1).Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
|
+ sheet.Row(1).Style.VerticalAlignment = ExcelVerticalAlignment.Center;
|
|
|
+ //表头设置
|
|
|
+ for (int i = 0; i < dt.Columns.Count; i++)
|
|
|
+ {
|
|
|
+ sheet.SetValue(1, i + 1, dt.Columns[i].ColumnName);
|
|
|
+ }
|
|
|
+ //数据绑定
|
|
|
+ for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
+ {
|
|
|
+ sheet.Row(i + 2).Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
|
+ sheet.Row(i + 2).Style.VerticalAlignment = ExcelVerticalAlignment.Center;
|
|
|
+ for (int j = 0; j < dt.Columns.Count; j++)
|
|
|
+ {
|
|
|
+ sheet.SetValue(i + 2, j + 1, dt.Rows[i][j].GetType().IsValueType ? Convert.ToDouble(dt.Rows[i][j]) : dt.Rows[i][j].ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ byte[] bytes = package.GetAsByteArray();
|
|
|
+ File.WriteAllBytes(savePath, bytes);
|
|
|
+ }
|
|
|
+ public static bool ConvertToWord(this List<EquipmentTask> tasks, object path, double maxVloume)
|
|
|
+ {
|
|
|
+ var tableColumn = 11;
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ Document wordDoc; //Word文档变量
|
|
|
+ Application wordApp; //Word应用程序变量
|
|
|
+ wordApp = new ApplicationClass
|
|
|
+ {
|
|
|
+ Visible = false //使文档可见
|
|
|
+ };
|
|
|
+ //由于使用的是COM库,因此有许多变量需要用Missing.Value代替
|
|
|
+ object nothing = Missing.Value;
|
|
|
+ wordDoc = wordApp.Documents.Add(ref nothing, ref nothing, ref nothing, ref nothing);
|
|
|
+
|
|
|
+ #region 页面样式设置
|
|
|
+ wordDoc.PageSetup.PaperSize = WdPaperSize.wdPaperA4; //设置纸张样式为A4纸
|
|
|
+ wordDoc.PageSetup.Orientation = WdOrientation.wdOrientPortrait; //排列方式为垂直方向
|
|
|
+ wordDoc.PageSetup.TopMargin = 57.0f;
|
|
|
+ wordDoc.PageSetup.BottomMargin = 57.0f;
|
|
|
+ wordDoc.PageSetup.LeftMargin = 57.0f;
|
|
|
+ wordDoc.PageSetup.RightMargin = 57.0f;
|
|
|
+ wordDoc.PageSetup.HeaderDistance = 30.0f; //页眉位置
|
|
|
+ PageNumbers pns = wordApp.Selection.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers; //获取当前页的号码
|
|
|
+ pns.NumberStyle = WdPageNumberStyle.wdPageNumberStyleNumberInDash; //设置页码的风格,是Dash形还是圆形的
|
|
|
+ pns.HeadingLevelForChapter = 0;
|
|
|
+ pns.IncludeChapterNumber = false;
|
|
|
+ pns.RestartNumberingAtSection = false;
|
|
|
+ pns.StartingNumber = 0; //开始页页码?
|
|
|
+ object pagenmbetal = WdPageNumberAlignment.wdAlignPageNumberCenter; //将号码设置在中间
|
|
|
+ object first = true;
|
|
|
+ wordApp.Selection.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers
|
|
|
+ .Add(ref pagenmbetal, ref first);
|
|
|
+ object unite = WdUnits.wdStory;
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 添加表格、填充数据、设置表格行列宽高、合并单元格、添加表头斜线、给单元格添加图片
|
|
|
+
|
|
|
+ //wordDoc.Content.InsertAfter("\n"); //插入换行
|
|
|
+
|
|
|
+ wordApp.Selection.EndKey(ref unite, ref nothing); //将光标移动到文档末尾
|
|
|
+ wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
|
|
|
+ var kbLowTasks = tasks.Where(item => item.TaskType.Equals("空白") && item.SampleConcentration.Equals("Low")).ToList();
|
|
|
+ var kbHighTasks = tasks.Where(item => item.TaskType.Equals("空白") && item.SampleConcentration.Equals("High")).ToList();
|
|
|
+
|
|
|
+ var syTasks = tasks.Where(item => item.TaskType.Equals("水样")).ToList();
|
|
|
+ // var syLowTasks = tasks.Where(item => item.TaskType.Equals("水样") && item.SampleConcentration.Equals("Low")).ToList();
|
|
|
+ // var syHighTasks = tasks.Where(item => item.TaskType.Equals("水样") && item.SampleConcentration.Equals("High")).ToList();
|
|
|
+
|
|
|
+ var bdLowTasks = tasks.Where(item => item.TaskType.Equals("标定") && item.SampleConcentration.Equals("Low")).ToList();
|
|
|
+ var bdHighTasks = tasks.Where(item => item.TaskType.Equals("标定") && item.SampleConcentration.Equals("High")).ToList();
|
|
|
+
|
|
|
+ SampleCalculate.tempCount = 0;
|
|
|
+ kbLowTasks.GeBlankTaskResult(maxVloume, out var noneValueL);
|
|
|
+ SampleCalculate.tempCount = 0;
|
|
|
+ kbHighTasks.GeBlankTaskResult(maxVloume, out var noneValueH);
|
|
|
+ bdLowTasks.GetBDTaskResult(maxVloume, "Low", out var bdValueL);
|
|
|
+ bdHighTasks.GetBDTaskResult(maxVloume, "High", out var bdValueH);
|
|
|
+
|
|
|
+ int tableRow = 5 + 5 + 3 + 3 + 2; //设置表格的行数
|
|
|
+
|
|
|
+ tableRow += kbLowTasks.Count; //低浓度空白样
|
|
|
+ tableRow += kbHighTasks.Count;
|
|
|
+ tableRow += syTasks.Count;
|
|
|
+ //tableRow += syLowTasks.Count; //
|
|
|
+ //tableRow += syHighTasks.Count; //水样
|
|
|
+ tableRow += bdLowTasks.Count; //低浓度标定样
|
|
|
+ tableRow += bdHighTasks.Count;
|
|
|
+
|
|
|
+ //定义一个Word中的表格对象
|
|
|
+ var table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref nothing,
|
|
|
+ ref nothing);
|
|
|
+ //默认创建的表格没有边框,这里修改其属性,使得创建的表格带有边框(这个值可以设置得很大,例如5、13等等)
|
|
|
+ table.Borders.Enable = 1;
|
|
|
+
|
|
|
+ #region 头部
|
|
|
+
|
|
|
+ table.Cell(1, 1).Range.Text = "化学需氧量原始记录表";
|
|
|
+ table.Cell(1, 1).Range.Font.Size = 12F;
|
|
|
+ table.Cell(1, 1).Range.Bold = 1;
|
|
|
+ table.Rows[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; //表格文本居中
|
|
|
+ table.Rows[1].Range.Cells.VerticalAlignment =
|
|
|
+ WdCellVerticalAlignment.wdCellAlignVerticalCenter; //文本垂直居中
|
|
|
+
|
|
|
+ table.Cell(2, 1).Range.Text = "方法依据";
|
|
|
+ table.Cell(2, 2).Range.Text = "《水质化学需氧量的测定重铬酸钾法》HJ828-2017";
|
|
|
+ table.Cell(2, 8).Range.Text = "检出限";
|
|
|
+ table.Cell(2, 10).Range.Text = "4mg/l";
|
|
|
+ table.Cell(3, 1).Range.Text = "重铬酸钾配置日期";
|
|
|
+ table.Cell(3, 5).Range.Text = "重铬酸钾浓度";
|
|
|
+ table.Cell(3, 8).Range.Text = "分析日期";
|
|
|
+ table.Cell(4, 1).Range.Text = "样品编号或名称";
|
|
|
+ table.Cell(4, 2).Range.Text = "氯离子浓度(mg/l)";
|
|
|
+ table.Cell(4, 3).Range.Text = "硫酸汞加入量(ml)";
|
|
|
+ table.Cell(4, 4).Range.Text = "取样体积(ml)";
|
|
|
+ table.Cell(4, 5).Range.Text = "稀释倍数";
|
|
|
+ table.Cell(4, 6).Range.Text = "稀释定容体积(ml)";
|
|
|
+ table.Cell(4, 7).Range.Text = "硫酸亚铁铵标准溶液消耗量(ml)";
|
|
|
+ table.Cell(4, 10).Range.Text = "浓度高低";
|
|
|
+ table.Cell(4, 11).Range.Text = "计算结果(mg/l)或者ml";
|
|
|
+ table.Cell(5, 7).Range.Text = "V 始";
|
|
|
+ table.Cell(5, 8).Range.Text = "V 终";
|
|
|
+ table.Cell(5, 9).Range.Text = "V终-V始";
|
|
|
+
|
|
|
+ table.Cell(1, 1).Merge(table.Cell(1, 11));
|
|
|
+ table.Rows[1].Height = 35; //设置新增加的这行表格的高度
|
|
|
+ table.Cell(2, 10).Merge(table.Cell(2, 11));
|
|
|
+ table.Cell(2, 8).Merge(table.Cell(2, 9));
|
|
|
+ table.Cell(2, 2).Merge(table.Cell(2, 7));
|
|
|
+
|
|
|
+ table.Cell(3, 10).Merge(table.Cell(3, 11));
|
|
|
+ table.Cell(3, 8).Merge(table.Cell(3, 9));
|
|
|
+ table.Cell(3, 5).Merge(table.Cell(3, 6));
|
|
|
+ table.Cell(3, 3).Merge(table.Cell(3, 4));
|
|
|
+ table.Cell(3, 1).Merge(table.Cell(3, 2));
|
|
|
+
|
|
|
+ for (int i = 1; i < 7; i++)
|
|
|
+ table.Cell(4, i).Merge(table.Cell(5, i));
|
|
|
+ table.Cell(4, 11).Merge(table.Cell(5, 11));
|
|
|
+ table.Cell(4, 10).Merge(table.Cell(5, 10));
|
|
|
+ table.Cell(4, 7).Merge(table.Cell(4, 9));
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ var startRow = 6;
|
|
|
+ var endRows = 5;
|
|
|
+ var startRow2 = 0;
|
|
|
+
|
|
|
+
|
|
|
+ #region 空白样
|
|
|
+
|
|
|
+ #region 低浓度
|
|
|
+ if (kbLowTasks.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in kbLowTasks)
|
|
|
+ {
|
|
|
+ endRows++;
|
|
|
+ table.Cell(endRows, 1).Range.Text = item.TaskDetailName;
|
|
|
+ table.Cell(endRows, 3).Range.Text = item.HgSO4Volume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 4).Range.Text = item.GetSampleVolume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 5).Range.Text = item.GetSampleMultiple.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 6).Range.Text = "10";
|
|
|
+ table.Cell(endRows, 7).Range.Text = "0";
|
|
|
+ table.Cell(endRows, 8).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 9).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 10).Range.Text = "低";
|
|
|
+ }
|
|
|
+ SampleCalculate.tempCount = 0;
|
|
|
+ //kbLowTasks.GeBlankTaskResult(maxVloume, out var noneValue);
|
|
|
+ table.Cell(startRow, 11).Range.Text = noneValueL.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(startRow, 11).Merge(table.Cell(endRows, 11)); //合并
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 高浓度
|
|
|
+ startRow = endRows + 1;
|
|
|
+ if (kbHighTasks.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in kbHighTasks)
|
|
|
+ { endRows++;
|
|
|
+ table.Cell(endRows, 1).Range.Text = item.TaskDetailName;
|
|
|
+ table.Cell(endRows, 3).Range.Text = item.HgSO4Volume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 4).Range.Text = item.GetSampleVolume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 5).Range.Text = item.GetSampleMultiple.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 6).Range.Text = "10";
|
|
|
+ table.Cell(endRows, 7).Range.Text = "0";
|
|
|
+ table.Cell(endRows, 8).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 9).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 10).Range.Text = "高";
|
|
|
+ }
|
|
|
+ SampleCalculate.tempCount = 0;
|
|
|
+ //kbHighTasks.GeBlankTaskResult(maxVloume, out var noneValue);
|
|
|
+ table.Cell(startRow, 11).Range.Text = noneValueH.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(startRow, 11).Merge(table.Cell(endRows, 11)); //合并
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 水样
|
|
|
+
|
|
|
+ if (syTasks.Any())
|
|
|
+ {
|
|
|
+ syTasks.ForEach(item =>
|
|
|
+ {
|
|
|
+ endRows++;
|
|
|
+ table.Cell(endRows, 1).Range.Text = item.TaskDetailName;
|
|
|
+ table.Cell(endRows, 3).Range.Text = item.HgSO4Volume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 4).Range.Text = item.GetSampleVolume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 5).Range.Text = item.GetSampleMultiple.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 6).Range.Text = "10";
|
|
|
+ table.Cell(endRows, 7).Range.Text = "0";
|
|
|
+ table.Cell(endRows, 8).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 9).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 10).Range.Text = item.SampleConcentration == "Low" ? "低" : "高";
|
|
|
+ table.Cell(endRows, 11).Range.Text = item.Result.ToString(CultureInfo.CurrentCulture);
|
|
|
+ //table.Cell(endRows, 10).Merge(table.Cell(endRows, 11)); //合并
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ //9-13
|
|
|
+ #region 标定样
|
|
|
+ startRow2 = endRows+1;
|
|
|
+ #region 低浓度
|
|
|
+ if (bdLowTasks.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in bdLowTasks)
|
|
|
+ {
|
|
|
+ endRows++;
|
|
|
+ table.Cell(endRows, 1).Range.Text = item.TaskDetailName;
|
|
|
+ table.Cell(endRows, 3).Range.Text = item.HgSO4Volume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 4).Range.Text = item.GetSampleVolume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 5).Range.Text = item.GetSampleMultiple.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 6).Range.Text = "10";
|
|
|
+ table.Cell(endRows, 7).Range.Text = "0";
|
|
|
+ table.Cell(endRows, 8).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 9).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 10).Range.Text = "低";
|
|
|
+ }
|
|
|
+ //bdLowTasks.GetBDTaskResult(maxVloume, "Low",out var bdValue);
|
|
|
+ table.Cell(startRow2, 11).Range.Text = bdValueL.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(startRow2, 11).Merge(table.Cell(endRows, 11)); //合并
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 高浓度
|
|
|
+ startRow2 = endRows + 1;
|
|
|
+ if (bdHighTasks.Any())
|
|
|
+ {
|
|
|
+ foreach (var item in bdHighTasks)
|
|
|
+ {
|
|
|
+ endRows++;
|
|
|
+ table.Cell(endRows, 1).Range.Text = item.TaskDetailName;
|
|
|
+ table.Cell(endRows, 3).Range.Text = item.HgSO4Volume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 4).Range.Text = item.GetSampleVolume.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 5).Range.Text = item.GetSampleMultiple.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 6).Range.Text = "10";
|
|
|
+ table.Cell(endRows, 7).Range.Text = "0";
|
|
|
+ table.Cell(endRows, 8).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 9).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(endRows, 10).Range.Text = "高";
|
|
|
+ }
|
|
|
+ //bdHighTasks.GetBDTaskResult(maxVloume, "High",out var bdValue2);
|
|
|
+ table.Cell(startRow2, 11).Range.Text = bdValueH.ToString(CultureInfo.CurrentCulture);
|
|
|
+ table.Cell(startRow2, 11).Merge(table.Cell(endRows, 11)); //合并
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ #region 标定样
|
|
|
+
|
|
|
+ //if (bdLowTasks.Any())
|
|
|
+ //{
|
|
|
+ // table.Cell(endRows + 1, 1).Range.Text = "硫酸亚铁铵标准溶液的标定";
|
|
|
+ // table.Cell(endRows + 1, 3).Range.Text = "硫酸亚铁铵消耗体积(ml)";
|
|
|
+ // table.Cell(endRows + 1, 6).Range.Text = "硫酸亚铁铵浓度(mol/l)";
|
|
|
+ // table.Cell(endRows + 1, 7).Range.Text = "化学需氧量计算公式";
|
|
|
+
|
|
|
+ // table.Cell(endRows + 2, 3).Range.Text = "V始";
|
|
|
+ // table.Cell(endRows + 2, 4).Range.Text = "V终";
|
|
|
+ // table.Cell(endRows + 2, 5).Range.Text = "V终-V始";
|
|
|
+
|
|
|
+ // int bdRows = 2;
|
|
|
+ // foreach (var item in bdLowTasks)
|
|
|
+ // {
|
|
|
+ // bdRows++;
|
|
|
+ // table.Cell(endRows + bdRows, 3).Range.Text = "0";
|
|
|
+ // table.Cell(endRows + bdRows, 4).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture); //V终
|
|
|
+ // table.Cell(endRows + bdRows, 5).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture); //V终-V始
|
|
|
+ // }
|
|
|
+
|
|
|
+ // table.Cell(endRows + 1, 8).Merge(table.Cell(endRows + 5, 11));
|
|
|
+ // table.Cell(endRows + 1, 7).Merge(table.Cell(endRows + 5, 7));
|
|
|
+ // table.Cell(endRows + 1, 6).Merge(table.Cell(endRows + 2, 6)); //硫酸亚铁铵浓度(mol/l)
|
|
|
+ // table.Cell(endRows + 3, 6).Merge(table.Cell(endRows + 5, 6));
|
|
|
+ // table.Cell(endRows + 1, 3).Merge(table.Cell(endRows + 1, 5)); //硫酸亚铁铵消耗体积(ml)
|
|
|
+ // table.Cell(endRows + 1, 1).Merge(table.Cell(endRows + 5, 2));
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if (bdHighTasks.Any())
|
|
|
+ //{
|
|
|
+ // table.Cell(endRows + 1, 1).Range.Text = "硫酸亚铁铵标准溶液的标定";
|
|
|
+ // table.Cell(endRows + 1, 3).Range.Text = "硫酸亚铁铵消耗体积(ml)";
|
|
|
+ // table.Cell(endRows + 1, 6).Range.Text = "硫酸亚铁铵浓度(mol/l)";
|
|
|
+ // table.Cell(endRows + 1, 7).Range.Text = "化学需氧量计算公式";
|
|
|
+
|
|
|
+ // table.Cell(endRows + 2, 3).Range.Text = "V始";
|
|
|
+ // table.Cell(endRows + 2, 4).Range.Text = "V终";
|
|
|
+ // table.Cell(endRows + 2, 5).Range.Text = "V终-V始";
|
|
|
+ // int bdRows = 2;
|
|
|
+ // foreach (var item in bdHighTasks)
|
|
|
+ // {
|
|
|
+ // bdRows++;
|
|
|
+ // table.Cell(endRows + bdRows, 3).Range.Text = "0";
|
|
|
+ // table.Cell(endRows + bdRows, 4).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture); //V终
|
|
|
+ // table.Cell(endRows + bdRows, 5).Range.Text = item.Amount.ToString(CultureInfo.CurrentCulture); //V终-V始
|
|
|
+ // }
|
|
|
+ // table.Cell(endRows + 1, 8).Merge(table.Cell(endRows + 5, 11));
|
|
|
+ // table.Cell(endRows + 1, 7).Merge(table.Cell(endRows + 5, 7));
|
|
|
+ // table.Cell(endRows + 1, 6).Merge(table.Cell(endRows + 2, 6)); //硫酸亚铁铵浓度(mol/l)
|
|
|
+ // table.Cell(endRows + 3, 6).Merge(table.Cell(endRows + 5, 6));
|
|
|
+ // table.Cell(endRows + 1, 3).Merge(table.Cell(endRows + 1, 5)); //硫酸亚铁铵消耗体积(ml)
|
|
|
+ // table.Cell(endRows + 1, 1).Merge(table.Cell(endRows + 5, 2));
|
|
|
+ //}
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ endRows += 5;
|
|
|
+ //14-16
|
|
|
+
|
|
|
+ #region 准确度
|
|
|
+
|
|
|
+ table.Cell(endRows + 1, 1).Range.Text = "准确度";
|
|
|
+ table.Cell(endRows + 1, 2).Range.Text = "质控样品编号";
|
|
|
+ table.Cell(endRows + 1, 4).Range.Text = "保证值(mg/l)";
|
|
|
+ table.Cell(endRows + 1, 6).Range.Text = "测试含量(mg/l)";
|
|
|
+ table.Cell(endRows + 1, 8).Range.Text = "质控样类型";
|
|
|
+ table.Cell(endRows + 1, 10).Range.Text = "是否合格";
|
|
|
+
|
|
|
+ table.Cell(endRows + 2, 8).Range.Text = "\u00A3密码";
|
|
|
+ table.Cell(endRows + 2, 9).Range.Text = "\u00A3明码";
|
|
|
+ table.Cell(endRows + 2, 10).Range.Text = "\u00A3合格";
|
|
|
+ table.Cell(endRows + 2, 11).Range.Text = "\u00A3不合格";
|
|
|
+ table.Cell(endRows + 3, 8).Range.Text = "\u00A3密码";
|
|
|
+ table.Cell(endRows + 3, 9).Range.Text = "\u00A3明码" ;
|
|
|
+ table.Cell(endRows + 3, 10).Range.Text = "\u00A3合格";
|
|
|
+ table.Cell(endRows + 3, 11).Range.Text = "\u00A3不合格";
|
|
|
+
|
|
|
+ for (int i = endRows + 2; i < endRows + 4; i++)
|
|
|
+ for (int j = 8; j < 12; j++)
|
|
|
+ table.Cell(i, j).Range.Font.Name = "Wingdings 2";
|
|
|
+
|
|
|
+ table.Cell(endRows + 2, 6).Merge(table.Cell(endRows + 2, 7));
|
|
|
+ table.Cell(endRows + 2, 4).Merge(table.Cell(endRows + 2, 5));
|
|
|
+ table.Cell(endRows + 2, 2).Merge(table.Cell(endRows + 2, 3));
|
|
|
+
|
|
|
+ table.Cell(endRows + 3, 6).Merge(table.Cell(endRows + 3, 7));
|
|
|
+ table.Cell(endRows + 3, 4).Merge(table.Cell(endRows + 3, 5));
|
|
|
+ table.Cell(endRows + 3, 2).Merge(table.Cell(endRows + 3, 3));
|
|
|
+ table.Cell(endRows + 1, 1).Merge(table.Cell(endRows + 3, 1));
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ endRows += 3;
|
|
|
+ //17-19
|
|
|
+
|
|
|
+ #region 精密度
|
|
|
+
|
|
|
+ table.Cell(endRows + 1, 1).Range.Text = "精密度";
|
|
|
+ table.Cell(endRows + 1, 2).Range.Text = "平行样品编号";
|
|
|
+ table.Cell(endRows + 1, 7).Range.Text = "平行样编号";
|
|
|
+
|
|
|
+ table.Cell(endRows + 2, 2).Range.Text = "测试含量(mg/l)";
|
|
|
+ table.Cell(endRows + 2, 7).Range.Text = "平行样编号";
|
|
|
+
|
|
|
+ table.Cell(endRows + 3, 2).Range.Text = "相对偏差(%)";
|
|
|
+ table.Cell(endRows + 3, 7).Range.Text = "平行样编号";
|
|
|
+
|
|
|
+ table.Cell(endRows + 1, 9).Merge(table.Cell(endRows + 1, 11));
|
|
|
+ table.Cell(endRows + 1, 7).Merge(table.Cell(endRows + 1, 8));
|
|
|
+ table.Cell(endRows + 1, 4).Merge(table.Cell(endRows + 1, 6));
|
|
|
+ table.Cell(endRows + 1, 2).Merge(table.Cell(endRows + 1, 3));
|
|
|
+
|
|
|
+ table.Cell(endRows + 2, 9).Merge(table.Cell(endRows + 2, 10));
|
|
|
+ table.Cell(endRows + 2, 7).Merge(table.Cell(endRows + 2, 8));
|
|
|
+ table.Cell(endRows + 2, 4).Merge(table.Cell(endRows + 2, 5));
|
|
|
+ table.Cell(endRows + 2, 2).Merge(table.Cell(endRows + 2, 3));
|
|
|
+
|
|
|
+ table.Cell(endRows + 3, 9).Merge(table.Cell(endRows + 3, 11));
|
|
|
+ table.Cell(endRows + 3, 7).Merge(table.Cell(endRows + 3, 8));
|
|
|
+ table.Cell(endRows + 3, 4).Merge(table.Cell(endRows + 3, 6));
|
|
|
+ table.Cell(endRows + 3, 2).Merge(table.Cell(endRows + 3, 3));
|
|
|
+
|
|
|
+ table.Cell(endRows + 1, 1).Merge(table.Cell(endRows + 3, 1));
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ endRows += 3;
|
|
|
+ //20-21
|
|
|
+
|
|
|
+ #region 结尾
|
|
|
+
|
|
|
+ table.Cell(endRows + 1, 1).Range.Text = "分析人:";
|
|
|
+ table.Cell(endRows + 1, 4).Range.Text = "校准人:";
|
|
|
+ table.Cell(endRows + 1, 8).Range.Text = "审核人:";
|
|
|
+ table.Cell(endRows + 1, 8).Merge(table.Cell(endRows + 1, 11));
|
|
|
+ table.Cell(endRows + 1, 4).Merge(table.Cell(endRows + 1, 7));
|
|
|
+ table.Cell(endRows + 1, 1).Merge(table.Cell(endRows + 1, 3));
|
|
|
+
|
|
|
+
|
|
|
+ table.Cell(endRows + 2, 1).Range.Text = "日期: 年 月 日";
|
|
|
+ table.Cell(endRows + 2, 4).Range.Text = "日期: 年 月 日";
|
|
|
+ table.Cell(endRows + 2, 8).Range.Text = "日期: 年 月 日";
|
|
|
+ table.Cell(endRows + 2, 8).Merge(table.Cell(endRows + 2, 11));
|
|
|
+ table.Cell(endRows + 2, 4).Merge(table.Cell(endRows + 2, 7));
|
|
|
+ table.Cell(endRows + 2, 1).Merge(table.Cell(endRows + 2, 3));
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ wordApp.Selection.EndKey(ref unite, ref nothing); //将光标移动到文档末尾
|
|
|
+ wordDoc.Content.InsertAfter("\n");
|
|
|
+ //WdSaveFormat为Word 2003文档的保存格式
|
|
|
+ object format = WdSaveFormat.wdFormatDocument;
|
|
|
+ //将wordDoc文档对象的内容保存为DOCX文档
|
|
|
+ string cat = tasks[0].WaveKey;
|
|
|
+ string cat2 = path.ToString();
|
|
|
+ cat2 = cat2 + "\\SampleResult_" + cat + ".doc";
|
|
|
+ path = (object)cat2;
|
|
|
+ wordDoc.SaveAs(ref path, ref format, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
|
|
|
+ ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
|
|
|
+ ref nothing,
|
|
|
+ ref nothing);
|
|
|
+ wordDoc.Close(ref nothing, ref nothing, ref nothing); //关闭wordApp组件对象
|
|
|
+ wordApp.Quit(ref nothing, ref nothing, ref nothing); //退出wordApp组件对象
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 截图转换成Bitmap
|
|
|
+ /// <summary>
|
|
|
+ /// 截图转换成bitmap
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="element"></param>
|
|
|
+ /// <param name="width">默认控件宽度</param>
|
|
|
+ /// <param name="height">默认控件高度</param>
|
|
|
+ /// <param name="x">默认0</param>
|
|
|
+ /// <param name="y">默认0</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static Bitmap ScreenConvertToBitmap(this System.Windows.Media.Visual visual)
|
|
|
+ {
|
|
|
+ int width = 0, height = 0, x = 0, y = 0;
|
|
|
+ Rect rc = SystemParameters.WorkArea; //获取工作区大小
|
|
|
+ if (width == 0) width = (int)rc.Width;
|
|
|
+ if (height == 0) height = (int)rc.Height;
|
|
|
+ var rtb = new RenderTargetBitmap(width, height, x, y, System.Windows.Media.PixelFormats.Default);
|
|
|
+ rtb.Render(visual);
|
|
|
+ Bitmap bit = BitmapSourceToBitmap(rtb);
|
|
|
+ return bit;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// BitmapSource转Bitmap
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static Bitmap BitmapSourceToBitmap(BitmapSource source)
|
|
|
+ {
|
|
|
+ return BitmapSourceToBitmap(source, source.PixelWidth, source.PixelHeight);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Convert BitmapSource to Bitmap
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="source"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static Bitmap BitmapSourceToBitmap(BitmapSource source, int width, int height)
|
|
|
+ {
|
|
|
+ Bitmap bmp = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ PixelFormat format = PixelFormat.Format24bppRgb;
|
|
|
+ /*set the translate type according to the in param(source)*/
|
|
|
+ switch (source.Format.ToString())
|
|
|
+ {
|
|
|
+ case "Rgb24":
|
|
|
+ case "Bgr24": format = PixelFormat.Format24bppRgb; break;
|
|
|
+ case "Bgra32": format = PixelFormat.Format32bppPArgb; break;
|
|
|
+ case "Bgr32": format = PixelFormat.Format32bppRgb; break;
|
|
|
+ case "Pbgra32": format = PixelFormat.Format32bppArgb; break;
|
|
|
+ }
|
|
|
+ bmp = new Bitmap(width, height, format);
|
|
|
+ BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size),
|
|
|
+ ImageLockMode.WriteOnly,
|
|
|
+ format);
|
|
|
+ source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
|
|
|
+ bmp.UnlockBits(data);
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ if (bmp != null)
|
|
|
+ {
|
|
|
+ bmp.Dispose();
|
|
|
+ bmp = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return bmp;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|