章政 5 жил өмнө
parent
commit
61de03c5b3

+ 123 - 27
UAS-出货标签管理(贸易版)/PublicMethod/ExcelHandler.cs

@@ -458,7 +458,11 @@ namespace UAS_LabelMachine
                     }
                     if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
                     {
-                        ShowSplitBatch = false;
+                        if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
+                        {
+                            DataTable.Columns.RemoveAt(i);
+                            break;
+                        }
                     }
                     if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
                     {
@@ -598,7 +602,11 @@ namespace UAS_LabelMachine
                                     {
                                         if (PercentSum.ContainsKey(j))
                                         {
-                                            row1.Cells[j].SetCellValue(PercentSum[j]);
+                                            if (PercentSum[j] != 0)
+                                            {
+                                                row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
+                                                PercentSum[j] = 0;
+                                            }
                                         }
                                     }
                                 }
@@ -663,7 +671,8 @@ namespace UAS_LabelMachine
                                 {
                                     if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
                                     {
-                                        PercentSum.Add(j - 4, 0);
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -671,7 +680,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
                                     {
-                                        PercentSum.Add(j - 4, 0);
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -679,7 +689,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
                                     {
-                                        PercentSum.Add(j - 4, 0);
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -687,7 +698,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
                                     {
-                                        PercentSum.Add(j - 4, 0);
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -695,7 +707,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
                                     {
-                                        PercentSum.Add(j - 4, 0);
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -818,7 +831,11 @@ namespace UAS_LabelMachine
                                     {
                                         if (PercentSum.ContainsKey(j))
                                         {
-                                            row1.Cells[j].SetCellValue(PercentSum[j]/PercentSum.Count);
+                                            if (PercentSum[j] != 0)
+                                            {
+                                                row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
+                                                PercentSum[j] = 0;
+                                            }
                                         }
                                     }
                                 }
@@ -890,6 +907,20 @@ namespace UAS_LabelMachine
                                 {
                                     row1.Cells[j].CellStyle = styleborder;
                                 }
+                                if (CountQty)
+                                {
+                                    for (int k = 0; k < PercentSum.Count; k++)
+                                    {
+                                        if (PercentSum.ContainsKey(j))
+                                        {
+                                            if (PercentSum[j] != 0)
+                                            {
+                                                row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
+                                                PercentSum[j] = 0;
+                                            }
+                                        }
+                                    }
+                                }
                             }
                             sumCount = 0;
                             row1 = sheet.CreateRow(PaintIndex);
@@ -958,6 +989,8 @@ namespace UAS_LabelMachine
                                     }
                                     if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -965,6 +998,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -972,6 +1007,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -979,6 +1016,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -986,6 +1025,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -1011,9 +1052,6 @@ namespace UAS_LabelMachine
                                         }
                                     }
                                 }
-                                //不展示扩散批
-                                if (!ShowSplitBatch)
-                                    sheet.SetColumnWidth(SplitBatchIndex, 0);
 
                                 ShowColumnCount = showcount;
                                 row1 = sheet.CreateRow(PaintIndex);
@@ -1039,6 +1077,13 @@ namespace UAS_LabelMachine
                                 if (double.TryParse(Data, out Num))
                                 {
                                     row1.Cells[j - 4].SetCellValue(Num);
+                                    for (int k = 0; k < PercentSum.Count; k++)
+                                    {
+                                        if (PercentSum.ContainsKey(j - 4))
+                                        {
+                                            PercentSum[j - 4] += Num;
+                                        }
+                                    }
                                 }
                                 else
                                 {
@@ -1085,20 +1130,36 @@ namespace UAS_LabelMachine
                                 {
                                     if (ShowCountIndex == SplitBatchIndex)
                                     {
-                                        row1.Cells[j+1].SetCellValue(sumCount);
-                                        row1.Cells[j+1].CellStyle = styleborder;
+                                        row1.Cells[j + 1].SetCellValue(sumCount);
+                                        row1.Cells[j + 1].CellStyle = styleborder;
                                     }
-                                    else {
+                                    else
+                                    {
                                         row1.Cells[j].SetCellValue(sumCount);
                                         row1.Cells[j].CellStyle = styleborder;
                                     }
-                             
+
                                 }
                                 else
                                 {
                                     row1.Cells[j].CellStyle = styleborder;
                                 }
+                                if (CountQty)
+                                {
+                                    for (int k = 0; k < PercentSum.Count; k++)
+                                    {
+                                        if (PercentSum.ContainsKey(j))
+                                        {
+                                            if (PercentSum[j] != 0)
+                                            {
+                                                row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
+                                                PercentSum[j] = 0;
+                                            }
+                                        }
+                                    }
+                                }
                             }
+
                             //创建备注内容
                             row1 = sheet.CreateRow(PaintIndex);
                             for (int j = 0; j < columnNum - 3; j++)
@@ -1138,14 +1199,6 @@ namespace UAS_LabelMachine
                         pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
                         pib_outboxcode1.Add(BoxCode.ToString());
                     }
-                    //for (int i = 0; i < sheet.LastRowNum; i++)
-                    //{
-                    //    if (i != 0)
-                    //    {
-                    //        sheet.AutoSizeColumn(i);
-                    //        sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
-                    //    }
-                    //}
                     break;
                 case "BoxCode":
                     string LastBoxCode = "";
@@ -1181,6 +1234,20 @@ namespace UAS_LabelMachine
                                 {
                                     row1.Cells[j].CellStyle = styleborder;
                                 }
+                                if (CountQty)
+                                {
+                                    for (int k = 0; k < PercentSum.Count; k++)
+                                    {
+                                        if (PercentSum.ContainsKey(j))
+                                        {
+                                            if (PercentSum[j] != 0)
+                                            {
+                                                row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
+                                                PercentSum[j] = 0;
+                                            }
+                                        }
+                                    }
+                                }
                             }
                             sumCount = 0;
                             row1 = sheet.CreateRow(PaintIndex);
@@ -1238,12 +1305,12 @@ namespace UAS_LabelMachine
                                 row1 = sheet.CreateRow(PaintIndex);
                                 PaintIndex = PaintIndex + 1;
                                 int showcount = 0;
-                          
                                 for (int j = 4; j < columnNum; j++)
                                 {
-                                  
-                                        if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
+                                    if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -1251,6 +1318,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -1258,6 +1327,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -1265,6 +1336,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -1272,6 +1345,8 @@ namespace UAS_LabelMachine
                                     }
                                     else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
                                     {
+                                        if (!PercentSum.ContainsKey(j - 4))
+                                            PercentSum.Add(j - 4, 0);
                                         showcount = showcount + 1;
                                         row1.CreateCell(j - 4);
                                         row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
@@ -1297,7 +1372,7 @@ namespace UAS_LabelMachine
                                         }
                                     }
                                 }
-                              
+
 
                                 ShowColumnCount = showcount;
                                 row1 = sheet.CreateRow(PaintIndex);
@@ -1323,6 +1398,13 @@ namespace UAS_LabelMachine
                                 if (double.TryParse(Data, out Num))
                                 {
                                     row1.Cells[j - 4].SetCellValue(Num);
+                                    for (int k = 0; k < PercentSum.Count; k++)
+                                    {
+                                        if (PercentSum.ContainsKey(j - 4))
+                                        {
+                                            PercentSum[j - 4] += Num;
+                                        }
+                                    }
                                 }
                                 else
                                 {
@@ -1373,6 +1455,20 @@ namespace UAS_LabelMachine
                                 {
                                     row1.Cells[j].CellStyle = styleborder;
                                 }
+                                if (CountQty)
+                                {
+                                    for (int k = 0; k < PercentSum.Count; k++)
+                                    {
+                                        if (PercentSum.ContainsKey(j))
+                                        {
+                                            if (PercentSum[j] != 0)
+                                            {
+                                                row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
+                                                PercentSum[j] = 0;
+                                            }
+                                        }
+                                    }
+                                }
                             }
                             row1 = sheet.CreateRow(PaintIndex);