using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Ref:
using System.Data;
using QMAPP.BoraUpgrade.DAL;
using QMAPP.BoraUpgrade.Entity;
using System.Text.RegularExpressions;
namespace QMAPP.BoraUpgrade.BLL
{
public class PrintCodeRouteHelper
{
#region 获取全部打码规则
///
/// 获取全部打码规则
///
///
public static List GetAllPrintCodeRouteList()
{
List returnVal = null;
DataTable dataSrouce = PrintCodeRouteDataAccess.GetPrintCodeRouteAllList();
if (dataSrouce.Rows.Count > 0)
{
returnVal = new List();
foreach (DataRow currDataRow in dataSrouce.Rows)
{
T_CC_PrintCodeRoute newPrintCodeRoute = new T_CC_PrintCodeRoute();
newPrintCodeRoute.PrintCodeRouteID = int.Parse(currDataRow[0].ToString());
newPrintCodeRoute.BarCodeRule = currDataRow[1].ToString();
newPrintCodeRoute.MachineName = currDataRow[2].ToString();
newPrintCodeRoute.MachineCode = currDataRow[3].ToString();
newPrintCodeRoute.Material_Code = currDataRow[4].ToString();
newPrintCodeRoute.WorkCell_Code = currDataRow[5].ToString();
newPrintCodeRoute.WorkLoc_Code = currDataRow[6].ToString();
newPrintCodeRoute.WorkCenter = currDataRow[7].ToString();
newPrintCodeRoute.Matrail_Type = currDataRow[8].ToString();
newPrintCodeRoute.IsProduct = bool.Parse(currDataRow[9].ToString());
newPrintCodeRoute.IsAppend = bool.Parse(currDataRow[10].ToString());
newPrintCodeRoute.Color = int.Parse(currDataRow["Color"].ToString());
newPrintCodeRoute.MachineID = currDataRow["MachineID"].ToString();
returnVal.Add(newPrintCodeRoute);
}
}
return returnVal;
}
#endregion
#region
///
/// 处理打码路由
///
/// 产品码
/// 工位码
public static T_CC_PrintCodeRoute ProcessPrintCodeRoute(List ePrintCodeRouteList, string ProductCode, string WorkCell_Code)
{
T_CC_PrintCodeRoute returnVal = null;
//提取产品信息
T_AW_PRODUCT eProduct = ProductHelper.GetProductByProductCode(ProductCode);
if (eProduct == null)
{
#region 处理新增
foreach ( T_CC_PrintCodeRoute ePrintCodeRoute in ePrintCodeRouteList )
{
//匹配工位
T_CC_PrintCodeRoute eMatchingPrintCodeRoute =
ePrintCodeRouteList.Find(s => s.WorkCell_Code == WorkCell_Code);
//判断是否存在匹配
if ( eMatchingPrintCodeRoute == null )
{
break;
}
//changed by wrx 20200312 Regex.IsMatch("A3ZQZC202003120003", "1")=true Regex.IsMatch("A3ZQZC202003", "1")=false 不知道为什么
string realProductCode = string.Empty;
string createTime = string.Empty;
string color = string.Empty;
string machineID = string.Empty;
if ( ProductCode.Length == 29 )
{
realProductCode = ProductCode.Substring(0, 23);
createTime = string.Format("20{0}-{1}-{2} {3}:{4}:{5}", ProductCode.Substring(11, 2), ProductCode.Substring(13, 2), ProductCode.Substring(15, 2),
ProductCode.Substring(17, 2), ProductCode.Substring(19, 2), ProductCode.Substring(21, 2)
);
color = ProductCode.Substring(23, 1);
machineID = ProductCode.Substring(24, 1);
}
else
{
return null;
}
if (System.Text.RegularExpressions.Regex.IsMatch(realProductCode, ePrintCodeRoute.BarCodeRule) == true
&& ePrintCodeRoute.WorkCell_Code.ToUpper().Trim() == WorkCell_Code.ToUpper().Trim()
&& ePrintCodeRoute.BarCodeRule != "1" && ePrintCodeRoute.BarCodeRule != "2" && ePrintCodeRoute.BarCodeRule != "3"
&& color == ePrintCodeRoute.Color.ToString() && machineID == ePrintCodeRoute.MachineID
)
{
if (eMatchingPrintCodeRoute.IsProduct == true)
{
//判断是否追加
if (eMatchingPrintCodeRoute.IsAppend == true)
{
#region 组成新增产品实例
T_AW_PRODUCT newProduct = new T_AW_PRODUCT();
newProduct.PID = Guid.NewGuid().ToString();
newProduct.PRODUCTTYPE = string.Empty;
newProduct.PRODUCTCODE = ProductCode;
newProduct.PRODUCTSOURCE = "0";
newProduct.MACHINENAME = ePrintCodeRoute.MachineName;
newProduct.MACHINECODDE = ePrintCodeRoute.MachineCode;
newProduct.MATERIAL_CODE = ePrintCodeRoute.Material_Code;
newProduct.STATUS = "0";
newProduct.OUTFLAG = "0";
newProduct.CAPACITY = 1;
newProduct.USINGCOUNT = 0;
newProduct.WORKCELL_CODE = ePrintCodeRoute.WorkCell_Code;
newProduct.WORKLOC_CODE = ePrintCodeRoute.WorkLoc_Code;
newProduct.WORKCENTER_CODE = ePrintCodeRoute.WorkCenter;
newProduct.MATERIAL_TYPE = ePrintCodeRoute.Matrail_Type;
newProduct.USINGSTATE = "0";
newProduct.CREATEDATE = DateTime.Parse(createTime);
#endregion
//新增
ProductHelper.Insert(newProduct);
}
}
//非产品
if (eMatchingPrintCodeRoute.IsProduct == false)
{
returnVal = eMatchingPrintCodeRoute;
}
break;
}
}
#endregion
}
else
{
if (ePrintCodeRouteList == null || ePrintCodeRouteList.Count == 0) return null;
//匹配工位
List eMatchingPrintCodeRouteList =
ePrintCodeRouteList.FindAll(s => s.WorkCell_Code == WorkCell_Code);
#region 处理更新
foreach (T_CC_PrintCodeRoute ePrintCodeRoute in eMatchingPrintCodeRouteList)
{
if ( System.Text.RegularExpressions.Regex.IsMatch(ProductCode, ePrintCodeRoute.BarCodeRule) == false )
{
break;
}
//changed by wrx 20200312 Regex.IsMatch("A3ZQZC202003120003", "1")=true Regex.IsMatch("A3ZQZC202003", "1")=false 不知道为什么
if (ePrintCodeRoute.WorkCell_Code.ToUpper().Trim() == WorkCell_Code.ToUpper().Trim() && ePrintCodeRoute.IsAppend == false && eProduct.USINGSTATE == "0"
&& ePrintCodeRoute.BarCodeRule != "1" && ePrintCodeRoute.BarCodeRule != "2" && ePrintCodeRoute.BarCodeRule != "3")
{
T_AW_PRODUCT modifyProduct = new T_AW_PRODUCT();
modifyProduct.PID = eProduct.PID;
//modifyProduct.MATERIAL_CODE = ePrintCodeRoute.Material_Code;
modifyProduct.WORKCELL_CODE = ePrintCodeRoute.WorkCell_Code;
modifyProduct.WORKLOC_CODE = ePrintCodeRoute.WorkLoc_Code;
modifyProduct.WORKCENTER_CODE = ePrintCodeRoute.WorkCenter;
modifyProduct.MATERIAL_TYPE = ePrintCodeRoute.Matrail_Type;
ProductHelper.Modify(modifyProduct);
}
}
#endregion
}
return returnVal;
}
public static void SaveLLightBarCode(List pPrintCodeRouteList,string pProductCode,string pWorkCellCode)
{
foreach(T_CC_PrintCodeRoute route in pPrintCodeRouteList)
{
if(System.Text.RegularExpressions.Regex.IsMatch(pProductCode, route.BarCodeRule) == true && route.WorkCell_Code == pWorkCellCode)
{
DataTable exsitTable = PrintCodeRouteDataAccess.GetExsitProductCodeQty(pProductCode, pWorkCellCode);
if(exsitTable.Rows.Count == 0)
{
T_AW_PRODUCT newProduct = new T_AW_PRODUCT();
newProduct.PID = Guid.NewGuid().ToString();
newProduct.PRODUCTTYPE = string.Empty;
newProduct.PRODUCTCODE = pProductCode;
newProduct.PRODUCTSOURCE = "0";
newProduct.MACHINENAME = route.MachineName;
newProduct.MACHINECODDE = route.MachineCode;
newProduct.MATERIAL_CODE = route.Material_Code;
newProduct.STATUS = "0";
newProduct.OUTFLAG = "0";
newProduct.CAPACITY = 1;
newProduct.USINGCOUNT = 0;
newProduct.WORKCELL_CODE = route.WorkCell_Code;
newProduct.WORKLOC_CODE = route.WorkLoc_Code;
newProduct.WORKCENTER_CODE = route.WorkCenter;
newProduct.MATERIAL_TYPE = route.Matrail_Type;
newProduct.USINGSTATE = "0";
newProduct.CREATEDATE = DateTime.Now;
#endregion
//新增
ProductHelper.Insert(newProduct);
}
//else
//{
// T_AW_PRODUCT modifyProduct = new T_AW_PRODUCT();
// modifyProduct.PID = exsitTable.Rows[0]["PID"].ToString();
// //modifyProduct.MATERIAL_CODE = ePrintCodeRoute.Material_Code;
// modifyProduct.WORKCELL_CODE = route.WorkCell_Code;
// modifyProduct.WORKLOC_CODE = route.WorkLoc_Code;
// modifyProduct.WORKCENTER_CODE = route.WorkCenter;
// modifyProduct.MATERIAL_TYPE = route.Matrail_Type;
// ProductHelper.Modify(modifyProduct);
//}
return;
}
}
}
#region 处理打码路由
///
/// 处理打码路由
///
/// 产品码
/// 工位码
public static T_CC_PrintCodeRoute ProcessPrintCodeRoute(List ePrintCodeRouteList, string ProductCode)
{
T_CC_PrintCodeRoute returnVal = null;
//提取产品信息
T_AW_PRODUCT eProduct = ProductHelper.GetProductByProductCode(ProductCode);
if (eProduct == null)
{
#region 处理新增
foreach (T_CC_PrintCodeRoute ePrintCodeRoute in ePrintCodeRouteList)
{
//changed by wrx 20200312 Regex.IsMatch("A3ZQZC202003120003", "1")=true Regex.IsMatch("A3ZQZC202003", "1")=false 不知道为什么
string realProductCode = string.Empty;
string createTime = string.Empty;
string color = string.Empty;
string machineID = string.Empty;
if (ProductCode.Length == 29)
{
realProductCode = ProductCode.Substring(0, 23);
createTime = string.Format("20{0}-{1}-{2} {3}:{4}:{5}", ProductCode.Substring(11, 2), ProductCode.Substring(13, 2), ProductCode.Substring(15, 2),
ProductCode.Substring(17, 2), ProductCode.Substring(19, 2), ProductCode.Substring(21, 2)
);
color = ProductCode.Substring(23, 1);
machineID = ProductCode.Substring(24, 1);
}
else
{
return null;
}
if (System.Text.RegularExpressions.Regex.IsMatch(realProductCode, ePrintCodeRoute.BarCodeRule) == true
&& ePrintCodeRoute.BarCodeRule != "1" && ePrintCodeRoute.BarCodeRule != "2" && ePrintCodeRoute.BarCodeRule != "3"
&& color == ePrintCodeRoute.Color.ToString() && machineID == ePrintCodeRoute.MachineID
)
{
#region 组成新增产品实例
T_AW_PRODUCT newProduct = new T_AW_PRODUCT();
newProduct.PID = Guid.NewGuid().ToString();
newProduct.PRODUCTTYPE = string.Empty;
newProduct.PRODUCTCODE = ProductCode;
newProduct.PRODUCTSOURCE = "0";
newProduct.MACHINENAME = ePrintCodeRoute.MachineName;
newProduct.MACHINECODDE = ePrintCodeRoute.MachineCode;
newProduct.MATERIAL_CODE = ePrintCodeRoute.Material_Code;
newProduct.STATUS = "0";
newProduct.OUTFLAG = "0";
newProduct.CAPACITY = 1;
newProduct.USINGCOUNT = 0;
newProduct.WORKCELL_CODE = ePrintCodeRoute.WorkCell_Code;
newProduct.WORKLOC_CODE = ePrintCodeRoute.WorkLoc_Code;
newProduct.WORKCENTER_CODE = ePrintCodeRoute.WorkCenter;
newProduct.MATERIAL_TYPE = ePrintCodeRoute.Matrail_Type;
newProduct.USINGSTATE = "0";
newProduct.CREATEDATE = DateTime.Parse(createTime);
#endregion
//新增
ProductHelper.Insert(newProduct);
break;
}
}
#endregion
}
return returnVal;
}
#endregion
}
}