using System;
using System.Collections.Generic;
using System.Linq;
//Ref:
using System.Data;
using QMAPP.BoraUpgrade.DAL;
using QMAPP.BoraUpgrade.Entity;
namespace QMAPP.BoraUpgrade.BLL
{
public class WorkOrderBLL
{
///
/// 获取全部宝来升级路由列表
///
///
public static T_MD_MATERIAL GetMaterialListByWorkOrderID(string workOrderID, string materialType)
{
T_MD_MATERIAL newMaterial = new T_MD_MATERIAL();
DataTable dataTable = QMAPP.BoraUpgrade.DAL.WorkOrderDAL.GetMaterialByWorkOrderID(workOrderID, materialType);
if (dataTable.Rows.Count != 0)
{
foreach (DataRow currRow in dataTable.Rows)
{
newMaterial.PID = currRow["PID"].ToString();
newMaterial.MATERIAL_CODE = currRow["MATERIAL_CODE"].ToString();
newMaterial.MATERIAL_TYPE_CODE = currRow["MATERIAL_TYPE_CODE"].ToString();
newMaterial.UNIT_CODE = currRow["UNIT_CODE"].ToString();
newMaterial.MATERIAL_NAME = currRow["MATERIAL_NAME"].ToString();
newMaterial.MATERIAL_COMP = currRow["MATERIAL_COMP"].ToString();
newMaterial.REMARK = currRow["REMARK"].ToString();
newMaterial.CREATEUSER = currRow["CREATEUSER"].ToString();
newMaterial.CREATEDATE = DateTime.Parse(currRow["CREATEDATE"].ToString());
newMaterial.UPDATEUSER = currRow["UPDATEUSER"].ToString();
newMaterial.UPDATEDATE = currRow["UPDATEDATE"].ToString();
newMaterial.OUTSOURCE = currRow["OUTSOURCE"].ToString();
newMaterial.STD_QTY = int.Parse(currRow["STD_QTY"].ToString());
newMaterial.FLGDEL = currRow["FLGDEL"].ToString();
newMaterial.COLOR = currRow["COLOR"].ToString();
newMaterial.HBTYPE = currRow["HBTYPE"].ToString();
newMaterial.PROJECTCODE = currRow["PROJECTCODE"].ToString();
if ( !string.IsNullOrWhiteSpace(currRow["WEIGHT"].ToString()) )
{
newMaterial.WEIGHT = int.Parse(currRow["WEIGHT"].ToString());
}
newMaterial.MATERIAL_SHORT = currRow["MATERIAL_SHORT"].ToString();
newMaterial.WORKBIN_TYPE = currRow["WORKBIN_TYPE"].ToString();
newMaterial.CAPACITY = int.Parse(currRow["CAPACITY"].ToString());
newMaterial.FACTORY_CODE = currRow["FACTORY_CODE"].ToString();
}
}
return newMaterial;
}
///
/// 查询fis工单
///
/// 0:未处理 1:已打印BZD 2:已器具排序
///
public static DataTable GetFisOrder(string lineCode,int state,int pQty = 1000)
{
return WorkOrderDAL.GetFisOrders(lineCode, state, pQty);
}
///
/// 修改fis订单的状态
///
///
///
///
public static bool UpdateFisOrderState(string pOrderNo, string pBzdCode, int state)
{
return WorkOrderDAL.UpdateFisOrderState(pOrderNo, pBzdCode, state);
}
///
/// 终检排序扫描记录的保存 T_AW_FinalSortRecord
///
///
public static bool SaveSacnOrderRecord(DataRow dataRow)
{
return WorkOrderDAL.SaveSacnOrderRecord(dataRow);
}
///
/// A3车型,根据BZD条码获取物料号
///
///
///
public static string GetA3MaterialCodeByBZD(string bzdCode)
{
return WorkOrderDAL.GetA3MaterialCodeByBZD(bzdCode);
}
///
/// MPID码获取物料号
///
///
///
public static string GetA3MaterialCodeByPID(string mpid)
{
return WorkOrderDAL.GetA3MaterialCodeByPID(mpid);
}
///
/// BZD条码是否没有被使用
///
///
///
public static bool IsNoUsedBzdCode(string pBzdCode)
{
return WorkOrderDAL.IsNoUsedBzdCode(pBzdCode);
}
///
/// 宝来仪表板,根据本体码查询总成数据
///
///
///
public static DataTable GetMainInfo(string productCode)
{
return WorkOrderDAL.GetMainInfo(productCode);
}
///
/// 根据扫描的本体码查找生产产品的总成零件号
/// 适合倒数第二工位 ,在product表找最新生产记录的物料号. 然后在pbomitem表找到pbomcode. 最后在pbom表找到总成零件号
///
///
///
public static string GetPMaterialCode(string productCode)
{
return WorkOrderDAL.GetPMaterialCode(productCode);
}
///
/// 校验该本体条码在该工序是否生产完成
///
///
///
///
public static bool VerifyLastCellOver(string productCode,string lastCellCode)
{
return WorkOrderDAL.VerifyLastCellOver(productCode, lastCellCode);
}
public static bool IsBarCodeRepet(string productCode )
{
return WorkOrderDAL.IsBarCodeRepet(productCode);
}
///
/// 查询计划编号
///
///
///
public static string GetPlanCode(string productCode)
{
return WorkOrderDAL.GetPlanCode(productCode);
}
///
/// 获取班次信息
///
///
public static List GetShiftList()
{
return WorkOrderDAL.GetShiftList();
}
public static string GetBoraBZDCode(string productCode, string materialCode)
{
return WorkOrderDAL.GetBoraBZDCode(productCode, materialCode);
}
public static string GetA3ProductCodeByBzd(string bzdCode)
{
return WorkOrderDAL.GetA3ProductCodeByBzd(bzdCode);
}
public static string GetA3ProductCreateByBzd(string bzdCode)
{
return WorkOrderDAL.GetA3ProductCreateByBzd(bzdCode);
}
public static string GetA3MpidCodeByBzd(string bzdCode)
{
return WorkOrderDAL.GetA3MpidCodeByBzd(bzdCode);
}
public static void SaveA3MainRecord( string[] basicData, string userID, string materialCode, string bzdCode, string productionCode,string lineCode)
{
WorkOrderDAL.SaveA3MainRecord(basicData, bzdCode, productionCode, userID, materialCode, lineCode);
}
public static DataTable GetStoreData(int count = 100)
{
return WorkOrderDAL.GetStoreData(count);
}
///
/// 计划挂起
///
public static void UpBills(List upRows)
{
List rows = upRows.Where(p => p.Field("SendState") != 0).ToList();
if(rows.Count >0)
{
List list = rows.Select(p => p.Field("FisOrderNo")).ToList();
throw new Exception("挂起失败,因为编号为[" + string.Join(";", list) + "]的订单正在生产或发运状态中,不满足要求");
}
foreach(DataRow upRow in upRows)
{
WorkOrderDAL.UpdateFisSetState(upRow);
}
}
///
/// 查询每天早8:30到第二天8:30的产量
///
///
public static string GetDayYield()
{
return WorkOrderDAL.GetDayYield();
}
public static string GetA3DayYield()
{
return WorkOrderDAL.GetA3DayYield();
}
public static string GetBoraHDayYield()
{
return WorkOrderDAL.GetBoraHDayYield();
}
public static string GetBoraLDayYield()
{
return WorkOrderDAL.GetBoraLDayYield();
}
public static void UpBillsDispose(List upRows)
{
List rows = upRows.Where(p => p.Field("SendState") != 9).ToList();
if (rows.Count > 0)
{
List list = rows.Select(p => p.Field("FisOrderNo")).ToList();
throw new Exception("取消挂起失败,因为编号为[" + string.Join(";", list) + "]的订单不属于挂起状态!");
}
//foreach (DataRow upRow in upRows)
//{
// WorkOrderDAL.UpdateFisSetStateDispose(upRow);
//}
WorkOrderDAL.UpdateFisSetStateDisposes(upRows);
}
public static void SaveStartIndex(int startIndex)
{
WorkOrderDAL.SaveStartIndex(startIndex);
}
public static int GetStartIndex()
{
return WorkOrderDAL.GetStartIndex();
}
}
}