/// <summary> /// 从数据表中提取生成条形码的源数据 /// </summary> /// <param name="productCode">产品代码</param> /// <param name="productAmount">本班次生产的产品数量,直接影响生成的条码数</param> /// <param name="dt">数据表</param> /// <param name="managementBarcode">提取到的用于生成管理条形码的数据</param> private void ExtractSourceDataFormDT(string productCode, int productAmount, DataTable dt, BatchBarcodeInf managementBarcode) { // 列名 string colName; // 数据值 object value; // 设置主总成代码(从DB中获取的主总成代码为空或空串) bool bSetUnitCode = false; // 从数据库中获取要生成管理条形码的数据项及信息 for (int row = 0; row < dt.Rows.Count; row++) { AssemblyManagementBarcode amb = new AssemblyManagementBarcode(dt.Columns.Count, productAmount); for (int col = 0; col < dt.Columns.Count; col++) { colName = dt.Columns[col].Caption; value = dt.Rows[row][col]; if (colName.CompareTo("PartCode") == 0) { if (!bSetUnitCode) { // 设置主总成代码 if (value == null || value.ToString().Length == 0) { dt.Rows[row][col] = productCode; } bSetUnitCode = true; } amb.PartCode = dt.Rows[row][col].ToString(); } else if (amb.PartName == null && colName.CompareTo("PartName") == 0) { amb.PartName = value.ToString(); } else if (amb.ProductCode == null && colName.CompareTo("ProductType") == 0) { amb.ProductCode = value.ToString(); } else if (colName.CompareTo("BuildRule") == 0) { amb.BuildRule = value.ToString(); } else if (colName.CompareTo("SerialNumber") == 0) { amb.SerialNumber = Convert.ToInt32(value); } amb.SourceData[col] = value; } // 如果是主总成则其零部件代码为空或空串 managementBarcode.Barcodes.Add(amb.PartName, amb); } }
/// <summary> /// 生成条形码 /// </summary> /// <param name="productCode">产品代码</param> /// <param name="productAmount">本班次生产的产品数量,直接影响生成的条码数</param> /// <param name="dateTimeValue">日期</param> /// <param name="barcodes">生成的条形码信息</param> private void BuildBarcode(string productCode, int productAmount, DateTime dateTimeValue, AssemblyManagementBarcode barcodes) { barcodes.BuildRule = barcodes.BuildRule.ToUpper(); for (int i = 0; i < productAmount; i++) { barcodes.SourceData[5] = barcodes.SerialNumber++; if (productCode == "RDC15FK-1500000" || productCode == "RDC18FC-1500000" || productCode == "RDC18FC-A") { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; barcodes.BuildRule = ctx.Fun_get_ProductCode_DongFengXiaoKang(dateTimeValue); barcodes.SourceData[9] = barcodes.BuildRule; ctx.SubmitChanges(); #region 夏石友 2016-11-18 修改 barcodes.Barcode[i] = string.Format("{0} {1}{2:D5}", productCode, barcodes.BuildRule, barcodes.SourceData[5]); //barcodes.Barcode[i] = string.Format("{0} {1}{2:D5}", // productCode.Substring(0, productCode.IndexOf("-")), barcodes.BuildRule, barcodes.SourceData[5]); #endregion } else { if (barcodes.BuildRule.Contains("[YYYYMM]")) { barcodes.BuildRule = barcodes.BuildRule.Replace("[YYYYMM]", "{0}"); barcodes.SourceData[0] = dateTimeValue.ToString("yyyyMM"); barcodes.SourceData[9] = barcodes.BuildRule; } else if (barcodes.BuildRule.Contains("[YYMM]")) { barcodes.BuildRule = barcodes.BuildRule.Replace("[YYMM]", "{0}"); barcodes.SourceData[0] = dateTimeValue.ToString("yyMM"); barcodes.SourceData[9] = barcodes.BuildRule; } else if (barcodes.BuildRule.Contains("[YYMMDD]")) { barcodes.BuildRule = barcodes.BuildRule.Replace("[YYMMDD]", "{0}"); barcodes.SourceData[0] = dateTimeValue.ToString("yyMMdd"); barcodes.SourceData[9] = barcodes.BuildRule; } barcodes.Barcode[i] = string.Format(barcodes.BuildRule, barcodes.SourceData); } } }
/// <summary> /// 打印 /// </summary> /// <param name="barcode">装配用管理条形码信息</param> /// <param name="err">错误信息, 如果没有则输出值为null</param> /// <returns>成功返回true, 失败返回false</returns> static private bool Print(AssemblyManagementBarcode barcode, out string err) { // 小条码纸适用 err = null; IntPtr hDC = IntPtr.Zero; bool bRet = true; double x = 50; double y = 0; double width = 42; string barcodeType = "ETN-128"; try { foreach (string barcodeContent in barcode.Barcode) { //x = 45; //bRet &= BarcodePrint.UTC_Begin(hDC, false); //if (barcodeContent.Length <= 7) //{ // y = 4; // width = 22; // OK, 扫描很快 // // width = 25; // OK, 扫描很快 // // width = 30; // OK, 扫描很快 // // width = 15; // NG, 效果不好 // // width = 18; // NG, 效果不好 // // width = 20; // NG, 效果不好 // bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 9, barcodeContent, barcodeType, 0, false); // bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false); // x = x + (width - BarcodePrint.UTC_GetTextWidth(barcodeContent)) / 2; // bRet &= BarcodePrint.UTC_Text(x, y + 10, barcodeContent, 0); //} //else if (barcodeContent.Length < 15) //{ // y = 4; // width = 38; // bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 9, barcodeContent, barcodeType, 0, false); // bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false); // x = x + (width - BarcodePrint.UTC_GetTextWidth(barcodeContent)) / 2; // bRet &= BarcodePrint.UTC_Text(x, y + 10, barcodeContent, 0); //} //else //{ // y = 1; // width = 40; // int len = barcodeContent.Length / 2; // string data1 = barcodeContent.Substring(0, len); // string data2 = barcodeContent.Substring(len, barcodeContent.Length - len); // bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 6, data1, barcodeType, 0, false); // bRet &= bRet = BarcodePrint.UTC_Barcode(x, y + 8, width, 6, data2, barcodeType, 0, false); // bRet &= BarcodePrint.UTC_SetFont("黑体", 8, true, false, false, false); // x = x + (width - BarcodePrint.UTC_GetTextWidth(barcodeContent)) / 2; // bRet &= BarcodePrint.UTC_Text(x, y + 15, barcodeContent, 0); //} if (barcode.PartCode.Contains("RDC")) { x = 35; y = 6; bRet &= BarcodePrint.UTC_Begin(hDC, false); bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, 50, 9, barcode.PartCode, barcodeType, 0, false); y += 11; bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, 40, 9, barcodeContent.Replace(barcode.PartCode, "").Trim(), barcodeType, 0, false); y += 11; bRet &= BarcodePrint.UTC_SetFont("黑体", 8, true, false, false, false); x = x + (width - BarcodePrint.UTC_GetTextWidth(barcodeContent)) / 2; bRet &= BarcodePrint.UTC_Text(x, y, barcodeContent, 0); } else { string barCode = barcodeContent; x = 35; y = 6; width = 38; bRet &= BarcodePrint.UTC_Begin(hDC, false); bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false); double x1 = x + (width - BarcodePrint.UTC_GetTextWidth(barcode.PartName)) / 2; bRet &= BarcodePrint.UTC_Text(x1, y, barcode.PartName, 0); y += 5; bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 9, barCode, barcodeType, 0, false); bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false); double x2 = x + (width - BarcodePrint.UTC_GetTextWidth(barCode)) / 2; bRet &= BarcodePrint.UTC_Text(x2, y + 10, barCode, 0); } bRet &= BarcodePrint.UTC_End(); //分页 if (!bRet) { return(bRet); } } } catch (Exception exce) { err = exce.Message; bRet = false; } return(bRet); }