|
|
@@ -53,7 +53,7 @@ namespace UAS_MES_NEW.Query
|
|
|
pr_code.DBTitle = "物料查询";
|
|
|
pr_code.Condition = "pr_code not like '%LX%'";
|
|
|
pr_code.SetValueField = new string[] { "pr_code" };
|
|
|
-
|
|
|
+ DateCode.Value = DateCode.Value.AddMonths(2);
|
|
|
dh = SystemInf.dh;
|
|
|
}
|
|
|
|
|
|
@@ -118,190 +118,211 @@ namespace UAS_MES_NEW.Query
|
|
|
OperatResult.AppendText("正在解析Sheet" + workbook.Worksheets[i].Name + "\n");
|
|
|
if (JPG.Checked)
|
|
|
{
|
|
|
- try
|
|
|
+ //try
|
|
|
+ //{
|
|
|
+ // ---------- 输出目录 ----------
|
|
|
+ if (!Directory.Exists(Application.StartupPath + @"\" + ps_prodcode.Text))
|
|
|
{
|
|
|
- // ---------- 输出目录 ----------
|
|
|
- if (!Directory.Exists(Application.StartupPath + @"\" + ps_prodcode.Text))
|
|
|
- {
|
|
|
- Directory.CreateDirectory(Application.StartupPath + @"\" + ps_prodcode.Text);
|
|
|
- }
|
|
|
- string path = Application.StartupPath + @"\" + ps_prodcode.Text + @"\";
|
|
|
+ Directory.CreateDirectory(Application.StartupPath + @"\" + ps_prodcode.Text);
|
|
|
+ }
|
|
|
+ string path = Application.StartupPath + @"\" + ps_prodcode.Text + @"\";
|
|
|
|
|
|
- Worksheet she = workbook.Worksheets[i];
|
|
|
+ Worksheet she = workbook.Worksheets[i];
|
|
|
|
|
|
- // ---------- 基础参数 ----------
|
|
|
- int lastColIndex = she.Cells.MaxDataColumn + 3;
|
|
|
- string lastColLetter = CellsHelper.ColumnIndexToName(lastColIndex);
|
|
|
- const int headerRows = 3; // 表头行数(每页都保留)
|
|
|
- int dataRowsPerPage = int.Parse(RowCount.Value.ToString());
|
|
|
+ // ---------- 基础参数 ----------
|
|
|
+ int lastColIndex = she.Cells.MaxDataColumn + 3;
|
|
|
+ string lastColLetter = CellsHelper.ColumnIndexToName(lastColIndex);
|
|
|
+ const int headerRows = 3; // 表头行数(每页都保留)
|
|
|
+ int dataRowsPerPage = int.Parse(RowCount.Value.ToString());
|
|
|
|
|
|
- // ★ 关键修复①:计算"内容最大行"时必须包含图片和形状的底部锚点行
|
|
|
- // 图片/形状不影响 Cells.MaxDataRow,只看单元格会把底部图片切掉
|
|
|
- int contentMaxRow = she.Cells.MaxDataRow;
|
|
|
- for (int p = 0; p < she.Pictures.Count; p++)
|
|
|
- {
|
|
|
- if (she.Pictures[p].LowerRightRow > contentMaxRow)
|
|
|
- contentMaxRow = she.Pictures[p].LowerRightRow;
|
|
|
- }
|
|
|
- for (int s = 0; s < she.Shapes.Count; s++)
|
|
|
- {
|
|
|
- if (she.Shapes[s].LowerRightRow > contentMaxRow)
|
|
|
- contentMaxRow = she.Shapes[s].LowerRightRow;
|
|
|
- }
|
|
|
- int totalRows = contentMaxRow + 1;
|
|
|
- int totalDataRows = Math.Max(totalRows - headerRows, 0);
|
|
|
- int totalPages = (int)Math.Ceiling(totalDataRows / (double)dataRowsPerPage);
|
|
|
- if (totalPages == 0) totalPages = 1;
|
|
|
+ // ★ 关键修复①:计算"内容最大行"时必须包含图片和形状的底部锚点行
|
|
|
+ // 图片/形状不影响 Cells.MaxDataRow,只看单元格会把底部图片切掉
|
|
|
+ int contentMaxRow = she.Cells.MaxDataRow;
|
|
|
+ for (int p = 0; p < she.Pictures.Count; p++)
|
|
|
+ {
|
|
|
+ if (she.Pictures[p].LowerRightRow > contentMaxRow)
|
|
|
+ contentMaxRow = she.Pictures[p].LowerRightRow;
|
|
|
+ }
|
|
|
+ for (int s = 0; s < she.Shapes.Count; s++)
|
|
|
+ {
|
|
|
+ if (she.Shapes[s].LowerRightRow > contentMaxRow)
|
|
|
+ contentMaxRow = she.Shapes[s].LowerRightRow;
|
|
|
+ }
|
|
|
+ int totalRows = contentMaxRow + 1;
|
|
|
+ int totalDataRows = Math.Max(totalRows - headerRows, 0);
|
|
|
+ int totalPages = (int)Math.Ceiling(totalDataRows / (double)dataRowsPerPage);
|
|
|
+ if (totalPages == 0) totalPages = 1;
|
|
|
|
|
|
- // 水印在原表中的目标行/列
|
|
|
- int wmRowGlobal = int.Parse(Y.Value.ToString());
|
|
|
- int wmCol = int.Parse(X.Value.ToString());
|
|
|
+ // 水印在原表中的目标行/列
|
|
|
+ int wmRowGlobal = int.Parse(Y.Value.ToString());
|
|
|
+ int wmCol = int.Parse(X.Value.ToString());
|
|
|
|
|
|
- int imageIndex = 1;
|
|
|
+ int imageIndex = 1;
|
|
|
|
|
|
- for (int page = 0; page < totalPages; page++)
|
|
|
+ for (int page = 0; page < totalPages; page++)
|
|
|
+ {
|
|
|
+ // ---------- 1. 复制原表到临时工作表 ----------
|
|
|
+ int newSheetIndex = workbook.Worksheets.Add();
|
|
|
+ Worksheet newshe = workbook.Worksheets[newSheetIndex];
|
|
|
+ newshe.Copy(she);
|
|
|
+ newshe.Name = $"Temp_{page}";
|
|
|
+
|
|
|
+ // 本页在原表中的数据行区间(原表坐标,0-based)
|
|
|
+ int dataStartRow = headerRows + page * dataRowsPerPage;
|
|
|
+ int dataEndRow = Math.Min(headerRows + (page + 1) * dataRowsPerPage - 1, totalRows - 1);
|
|
|
+
|
|
|
+ // ---------- 2. 按页过滤原表图片(Pictures) ----------
|
|
|
+ for (int p = newshe.Pictures.Count - 1; p >= 0; p--)
|
|
|
{
|
|
|
- // ---------- 1. 复制原表到临时工作表 ----------
|
|
|
- int newSheetIndex = workbook.Worksheets.Add();
|
|
|
- Worksheet newshe = workbook.Worksheets[newSheetIndex];
|
|
|
- newshe.Copy(she);
|
|
|
- newshe.Name = $"Temp_{page}";
|
|
|
-
|
|
|
- // 本页在原表中的数据行区间(原表坐标,0-based)
|
|
|
- int dataStartRow = headerRows + page * dataRowsPerPage;
|
|
|
- int dataEndRow = Math.Min(headerRows + (page + 1) * dataRowsPerPage - 1, totalRows - 1);
|
|
|
-
|
|
|
- // ---------- 2. 按页过滤原表图片(Pictures) ----------
|
|
|
- for (int p = newshe.Pictures.Count - 1; p >= 0; p--)
|
|
|
+ Aspose.Cells.Drawing.Picture pic = newshe.Pictures[p];
|
|
|
+ int topRow = pic.UpperLeftRow;
|
|
|
+ bool isHeaderPic = topRow < headerRows;
|
|
|
+ bool belongsToPage = topRow >= dataStartRow && topRow <= dataEndRow;
|
|
|
+ if (!isHeaderPic && !belongsToPage)
|
|
|
{
|
|
|
- Aspose.Cells.Drawing.Picture pic = newshe.Pictures[p];
|
|
|
- int topRow = pic.UpperLeftRow;
|
|
|
- bool isHeaderPic = topRow < headerRows;
|
|
|
- bool belongsToPage = topRow >= dataStartRow && topRow <= dataEndRow;
|
|
|
- if (!isHeaderPic && !belongsToPage)
|
|
|
- {
|
|
|
- newshe.Pictures.RemoveAt(p);
|
|
|
- }
|
|
|
+ newshe.Pictures.RemoveAt(p);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // ---------- 3. 按页过滤原表形状(Shapes:文本框/箭头/连接线等) ----------
|
|
|
- for (int s = newshe.Shapes.Count - 1; s >= 0; s--)
|
|
|
- {
|
|
|
- Aspose.Cells.Drawing.Shape shape = newshe.Shapes[s];
|
|
|
- int topRow = shape.UpperLeftRow;
|
|
|
- bool isHeaderShape = topRow < headerRows;
|
|
|
- bool belongsToPage = topRow >= dataStartRow && topRow <= dataEndRow;
|
|
|
- if (!isHeaderShape && !belongsToPage)
|
|
|
- {
|
|
|
- newshe.Shapes.RemoveAt(s);
|
|
|
- }
|
|
|
- }
|
|
|
+ // ---------- 3. 按页过滤原表形状(Shapes:文本框/箭头/连接线等) ----------
|
|
|
|
|
|
- // ---------- 4. 清空非本页单元格内容 ----------
|
|
|
- for (int r = 0; r < totalRows; r++)
|
|
|
+ for (int s = newshe.Shapes.Count - 1; s >= 0; s--)
|
|
|
+ {
|
|
|
+ Aspose.Cells.Drawing.Shape shape;
|
|
|
+ try
|
|
|
{
|
|
|
- if (r < headerRows) continue;
|
|
|
- if (r >= dataStartRow && r <= dataEndRow) continue;
|
|
|
- newshe.Cells.ClearRange(r, 0, r, lastColIndex);
|
|
|
+ shape = newshe.Shapes[s];
|
|
|
}
|
|
|
-
|
|
|
- // ---------- 5. 删除非本页整行 ----------
|
|
|
- for (int r = totalRows - 1; r >= 0; r--)
|
|
|
+ catch
|
|
|
{
|
|
|
- if (r < headerRows) continue;
|
|
|
- if (r >= dataStartRow && r <= dataEndRow) continue;
|
|
|
- newshe.Cells.DeleteRow(r);
|
|
|
+ // 下标已经失效,直接跳过
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- // ---------- 6. 页面设置 ----------
|
|
|
- // ★ 关键修复②:PrintArea 必须覆盖临时表中图片/形状延伸到的最大行
|
|
|
- // 不能只用 Cells.MaxDataRow + 1,否则底部图片被截断
|
|
|
- int printMaxRow = newshe.Cells.MaxDataRow;
|
|
|
- for (int p = 0; p < newshe.Pictures.Count; p++)
|
|
|
- {
|
|
|
- if (newshe.Pictures[p].LowerRightRow > printMaxRow)
|
|
|
- printMaxRow = newshe.Pictures[p].LowerRightRow;
|
|
|
- }
|
|
|
- for (int s = 0; s < newshe.Shapes.Count; s++)
|
|
|
- {
|
|
|
- if (newshe.Shapes[s].LowerRightRow > printMaxRow)
|
|
|
- printMaxRow = newshe.Shapes[s].LowerRightRow;
|
|
|
- }
|
|
|
- int newTotalRows = printMaxRow + 1;
|
|
|
- if (i == 0)
|
|
|
- {
|
|
|
- newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{25}";
|
|
|
- }
|
|
|
- else {
|
|
|
- newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{newTotalRows}";
|
|
|
- }
|
|
|
- newshe.PageSetup.CenterHorizontally = true;
|
|
|
- newshe.PageSetup.CenterVertically = true;
|
|
|
- newshe.PageSetup.LeftMargin = 2;
|
|
|
- newshe.PageSetup.RightMargin = 2;
|
|
|
- newshe.PageSetup.TopMargin = 2;
|
|
|
- newshe.PageSetup.BottomMargin = 2;
|
|
|
- newshe.PageSetup.SetFooter(0, "");
|
|
|
- newshe.PageSetup.SetFooter(1, "");
|
|
|
- newshe.PageSetup.SetFooter(2, "");
|
|
|
-
|
|
|
- // ---------- 7. 插入水印(额外图片,坐标映射到压缩后本页) ----------
|
|
|
- if (File.Exists(PrintPath.Text))
|
|
|
- {
|
|
|
- int rowOffset = headerRows + int.Parse(Y.Value.ToString());
|
|
|
- newshe.Pictures.Add(rowOffset, int.Parse(X.Value.ToString()), PrintPath.Text);
|
|
|
- }
|
|
|
- // ---------- 8. 页脚 ----------
|
|
|
- string pageFooter = $"第 {imageIndex} 页 / 共 {totalPages} 页";
|
|
|
- newshe.PageSetup.SetFooter(1, pageFooter);
|
|
|
-
|
|
|
- // ---------- 9. 渲染为 PNG ----------
|
|
|
- ImageOrPrintOptions options = new ImageOrPrintOptions();
|
|
|
- options.ImageFormat = ImageFormat.Png;
|
|
|
- options.OnePagePerSheet = true;
|
|
|
- options.PrintingPage = PrintingPageType.Default;
|
|
|
-
|
|
|
- SheetRender sr = new SheetRender(newshe, options);
|
|
|
- if (sr.PageCount > 0)
|
|
|
+ int topRow = shape.UpperLeftRow;
|
|
|
+ bool isHeaderShape = topRow < headerRows;
|
|
|
+ bool belongsToPage = topRow >= dataStartRow && topRow <= dataEndRow;
|
|
|
+
|
|
|
+ if (!isHeaderShape && !belongsToPage)
|
|
|
{
|
|
|
- using (Bitmap bitmap = sr.ToImage(0))
|
|
|
+ try
|
|
|
+ {
|
|
|
+ newshe.Shapes.RemoveAt(s);
|
|
|
+ }
|
|
|
+ catch
|
|
|
{
|
|
|
- string imagename = $"{she.Name}_{imageIndex}.png";
|
|
|
- string imagePath = Path.Combine(path, imagename);
|
|
|
- bitmap.Save(imagePath, ImageFormat.Png);
|
|
|
- OperatResult.AppendText("解析图片【" + imagePath + "】\n");
|
|
|
-
|
|
|
- // ---------- 10. 上传 ----------
|
|
|
- Dictionary<string, object> dic = new Dictionary<string, object>();
|
|
|
- dic.Add("em_name", "管理员");
|
|
|
- dic.Add("em_code", "ADMIN");
|
|
|
- dic.Add("caller", "ProductSOP");
|
|
|
- OperatResult.AppendText("上传文件【" + imagePath + "】\n");
|
|
|
-
|
|
|
- string fp_id = UploadFilesToRemoteUrl(
|
|
|
- "https://mes.lihantech.cn/mes/MEScommon/uploadFiles.action?_noc=1",
|
|
|
- imagePath, dic);
|
|
|
-
|
|
|
- // ---------- 11. 入库 ----------
|
|
|
- string ps_id = dh.getFieldDataByCondition(
|
|
|
- "ProductSOP", "ps_id", "ps_prodcode='" + ps_prodcode.Text + "'").ToString();
|
|
|
-
|
|
|
- dh.ExecuteSql(
|
|
|
- "insert into ProductSOPdetail(psd_id,psd_psid,psd_attach) " +
|
|
|
- "select ProductSOPdetail_seq.nextval,ps_id,'" + imagename + ";" + fp_id +
|
|
|
- "' from ProductSOP where ps_prodcode='" + ps_prodcode.Text + "'", "insert");
|
|
|
+ // GroupShape组合形状无法直接RemoveAt,就隐藏
|
|
|
+ shape.IsHidden = true;
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // ---------- 12. 删除临时工作表 ----------
|
|
|
- workbook.Worksheets.RemoveAt(newSheetIndex);
|
|
|
- imageIndex++;
|
|
|
+ // ---------- 4. 清空非本页单元格内容 ----------
|
|
|
+ for (int r = 0; r < totalRows; r++)
|
|
|
+ {
|
|
|
+ if (r < headerRows) continue;
|
|
|
+ if (r >= dataStartRow && r <= dataEndRow) continue;
|
|
|
+ newshe.Cells.ClearRange(r, 0, r, lastColIndex);
|
|
|
}
|
|
|
+
|
|
|
+ // ---------- 5. 删除非本页整行 ----------
|
|
|
+ for (int r = totalRows - 1; r >= 0; r--)
|
|
|
+ {
|
|
|
+ if (r < headerRows) continue;
|
|
|
+ if (r >= dataStartRow && r <= dataEndRow) continue;
|
|
|
+ newshe.Cells.DeleteRow(r);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ---------- 6. 页面设置 ----------
|
|
|
+ // ★ 关键修复②:PrintArea 必须覆盖临时表中图片/形状延伸到的最大行
|
|
|
+ // 不能只用 Cells.MaxDataRow + 1,否则底部图片被截断
|
|
|
+ int printMaxRow = newshe.Cells.MaxDataRow;
|
|
|
+ for (int p = 0; p < newshe.Pictures.Count; p++)
|
|
|
+ {
|
|
|
+ if (newshe.Pictures[p].LowerRightRow > printMaxRow)
|
|
|
+ printMaxRow = newshe.Pictures[p].LowerRightRow;
|
|
|
+ }
|
|
|
+ for (int s = 0; s < newshe.Shapes.Count; s++)
|
|
|
+ {
|
|
|
+ if (newshe.Shapes[s].LowerRightRow > printMaxRow)
|
|
|
+ printMaxRow = newshe.Shapes[s].LowerRightRow;
|
|
|
+ }
|
|
|
+ int newTotalRows = printMaxRow + 1;
|
|
|
+ if (i == 0)
|
|
|
+ {
|
|
|
+ newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{25}";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ newshe.PageSetup.PrintArea = $"A1:{lastColLetter}{newTotalRows}";
|
|
|
+ }
|
|
|
+ newshe.PageSetup.CenterHorizontally = true;
|
|
|
+ newshe.PageSetup.CenterVertically = true;
|
|
|
+ newshe.PageSetup.LeftMargin = 2;
|
|
|
+ newshe.PageSetup.RightMargin = 2;
|
|
|
+ newshe.PageSetup.TopMargin = 2;
|
|
|
+ newshe.PageSetup.BottomMargin = 2;
|
|
|
+ newshe.PageSetup.SetFooter(0, "");
|
|
|
+ newshe.PageSetup.SetFooter(1, "");
|
|
|
+ newshe.PageSetup.SetFooter(2, "");
|
|
|
+
|
|
|
+ // ---------- 7. 插入水印(额外图片,坐标映射到压缩后本页) ----------
|
|
|
+ if (File.Exists(PrintPath.Text))
|
|
|
+ {
|
|
|
+ int rowOffset = headerRows + int.Parse(Y.Value.ToString());
|
|
|
+ newshe.Pictures.Add(rowOffset, int.Parse(X.Value.ToString()), PrintPath.Text);
|
|
|
+ }
|
|
|
+ // ---------- 8. 页脚 ----------
|
|
|
+ string pageFooter = $"第 {imageIndex} 页 / 共 {totalPages} 页";
|
|
|
+ newshe.PageSetup.SetFooter(1, pageFooter);
|
|
|
+
|
|
|
+ // ---------- 9. 渲染为 PNG ----------
|
|
|
+ ImageOrPrintOptions options = new ImageOrPrintOptions();
|
|
|
+ options.ImageFormat = ImageFormat.Png;
|
|
|
+ options.OnePagePerSheet = true;
|
|
|
+ options.PrintingPage = PrintingPageType.Default;
|
|
|
+
|
|
|
+ SheetRender sr = new SheetRender(newshe, options);
|
|
|
+ if (sr.PageCount > 0)
|
|
|
+ {
|
|
|
+ using (Bitmap bitmap = sr.ToImage(0))
|
|
|
+ {
|
|
|
+ string imagename = $"{she.Name}_{imageIndex}.png";
|
|
|
+ string imagePath = Path.Combine(path, imagename);
|
|
|
+ bitmap.Save(imagePath, ImageFormat.Png);
|
|
|
+ OperatResult.AppendText("解析图片【" + imagePath + "】\n");
|
|
|
+
|
|
|
+ // ---------- 10. 上传 ----------
|
|
|
+ Dictionary<string, object> dic = new Dictionary<string, object>();
|
|
|
+ dic.Add("em_name", "管理员");
|
|
|
+ dic.Add("em_code", "ADMIN");
|
|
|
+ dic.Add("caller", "ProductSOP");
|
|
|
+ OperatResult.AppendText("上传文件【" + imagePath + "】\n");
|
|
|
+
|
|
|
+ string fp_id = UploadFilesToRemoteUrl(
|
|
|
+ "https://mes.lihantech.cn/mes/MEScommon/uploadFiles.action?_noc=1",
|
|
|
+ imagePath, dic);
|
|
|
+
|
|
|
+ // ---------- 11. 入库 ----------
|
|
|
+ string ps_id = dh.getFieldDataByCondition(
|
|
|
+ "ProductSOP", "ps_id", "ps_prodcode='" + ps_prodcode.Text + "'").ToString();
|
|
|
+
|
|
|
+ dh.ExecuteSql(
|
|
|
+ "insert into ProductSOPdetail(psd_id,psd_psid,psd_attach) " +
|
|
|
+ "select ProductSOPdetail_seq.nextval,ps_id,'" + imagename + ";" + fp_id +
|
|
|
+ "' from ProductSOP where ps_prodcode='" + ps_prodcode.Text + "'", "insert");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ---------- 12. 删除临时工作表 ----------
|
|
|
+ workbook.Worksheets.RemoveAt(newSheetIndex);
|
|
|
+ imageIndex++;
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- OperatResult.AppendText(ex.Message + ex.StackTrace);
|
|
|
- }
|
|
|
+ //}
|
|
|
+ //catch (Exception ex)
|
|
|
+ //{
|
|
|
+ // OperatResult.AppendText(ex.Message + ex.StackTrace);
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
}
|