You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1352 lines
95 KiB

using FactorySystemCommon;
using FactorySystemModel.SqlSugarModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FactorySystemModel.EnumModel;
using System.Data;
namespace FactorySystemBll
{
public class MaterialBll
{
private readonly string[] NoSetField = "FID,FAddDate,FEditDate".Split(',');
/// <summary>
/// 物料主数据比对
/// </summary>
public int DockingRecipeData(List<TFS_Material> mainList, List<PropertyInfo> mainProp, int userId)
{
int result = 0;
if (mainList.Count == 0) return result;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<TFS_Factory> factorys = db.Queryable<TFS_Factory>().OrderBy(s => s.FDeleted).ToList();
//已存在
List<string> codes = mainList.GroupBy(g => g.FCode).Select(ss => ss.Key).ToList();
List<TFS_Material> mainsList = db.Queryable<TFS_Material>().Where(s => s.FDeleted != (int)Constant.DeleteCode. && codes.Contains(s.FCode)).ToList();
//增改
List<TFS_Material> updateList = new List<TFS_Material>();
List<TFS_Material> insertList = new List<TFS_Material>();
//根据物料号分组
foreach (var item in mainList.GroupBy(s => s.FCode))
{
TFS_Material temp = mainsList.Find(d => d.FCode == item.Key);
if (temp == null)
{
temp = item.First();
if (!string.IsNullOrEmpty(temp.FFactoryCode))
{
TFS_Factory factory = factorys.Find(s => s.FCode == temp.FFactoryCode);
if (factory == null) factory = factorys.Find(s => s.FName == temp.FFactoryCode);
if (factory == null) temp.FFactoryID = -1;
else temp.FFactoryID = factory.FID;
}
temp.FAddDate = temp.FEditDate = DateTime.Now;
temp.FEditUser = userId;
insertList.Add(temp);
}
else
{
temp.FEditDate = DateTime.Now;
temp.FEditUser = userId;
string value;
foreach (PropertyInfo mProp in mainProp)
{
if (!NoSetField.Contains(mProp.Name) && mProp.PropertyType.Name != "Boolean")
{
object mPV = mProp.GetValue(item.First());
if (mPV != null && !string.IsNullOrEmpty(value = mPV.ToString()) && value != "null" && value != "0")
{
if (mProp.PropertyType.Name == "Int32")
{
if (int.TryParse(value, out int val)) mProp.SetValue(temp, val);
}
else
{
mProp.SetValue(temp, value);
}
}
}
}
updateList.Add(temp);
}
}
try
{
db.BeginTran();
if (updateList.Count > 0)
{
foreach (var item in updateList)
{
result += db.Updateable(item).IgnoreColumns(true).ExecuteCommand();
}
}
if (insertList.Count > 0)
{
foreach (var item in insertList)
{
result += db.Insertable(item).IgnoreColumns(true).ExecuteCommand();
}
}
db.CommitTran();
}
catch (Exception)
{
db.RollbackTran();
}
return result;
}
public List<TFS_Material> GetMaterial(int tempId)
{
return AppSettingsHelper.GetSqlSugar()
.Queryable<TFS_Material, TFS_ViewMaterial>((a, b) => new JoinQueryInfos(JoinType.Left, a.FID == b.FMaterialID))
.Where((a, b) => b.FTeamID == tempId).Select<TFS_Material>((a, b) => a).ToList();
}
/// <summary>
/// 物料子数据比对
/// </summary>
public int DockingRecipeData(List<TFS_ViewMaterial> childList, List<PropertyInfo> childProp, int userId)
{
int result = 0;
if (childList.Count == 0) return result;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
//主数据
List<string> codes = childList.GroupBy(g => g.FCode).Select(ss => ss.Key).ToList();
List<TFS_Material> mainList = db.Queryable<TFS_Material>().Where(s => s.FDeleted != (int)Constant.DeleteCode. && codes.Contains(s.FCode)).ToList();
if (mainList == null || mainList.Count == 0) return result;
//已存在子数据
codes = mainList.Select(ss => ss.FID.ToString()).ToList();
List<TFS_ViewMaterial> childsList = db.Queryable<TFS_ViewMaterial>().Where(s => s.FDeleted != (int)Constant.DeleteCode.
&& codes.Contains(s.FMaterialID.ToString())).ToList();
List<TFS_Factory> factorys = db.Queryable<TFS_Factory>().OrderBy(s => s.FDeleted).ToList();
List<TFS_ViewMaterial> updateList = new List<TFS_ViewMaterial>();
List<TFS_ViewMaterial> insertList = new List<TFS_ViewMaterial>();
foreach (TFS_Material main in mainList)
{
List<TFS_ViewMaterial> childs = childList.Where(s => s.FCode.Equals(main.FCode)).ToList();
if (childs != null && childs.Count() > 0)
{
foreach (TFS_ViewMaterial child in childs)
{
TFS_ViewMaterial temp = childsList.Find(s => s.FMaterialID == main.FID && s.FFactoryCode.Equals(child.FFactoryCode));
if (temp == null)
{
temp = child;
temp.FAddDate = temp.FEditDate = DateTime.Now;
temp.FEditUser = userId;
insertList.Add(temp);
}
else
{
temp.FEditDate = DateTime.Now;
temp.FEditUser = userId;
foreach (PropertyInfo mProp in childProp)
{
if (!NoSetField.Contains(mProp.Name))
{
string value = mProp.GetValue(child).ToString();
if (!string.IsNullOrEmpty(value) && value != "null" && value != "0")
{
if (mProp.PropertyType.Name == "Int32")
{
if (int.TryParse(value, out int val)) mProp.SetValue(temp, val);
}
else
{
mProp.SetValue(temp, value);
}
}
}
}
updateList.Add(temp);
}
temp.FMaterialID = main.FID;
if (!string.IsNullOrEmpty(temp.FFactoryCode))
{
TFS_Factory factory = factorys.Find(s => s.FCode == temp.FFactoryCode);
if (factory == null) factory = factorys.Find(s => s.FName == temp.FFactoryCode);
if (factory == null) temp.FFactoryID = -1;
else temp.FFactoryID = factory.FID;
}
}
}
}
try
{
db.BeginTran();
if (updateList.Count > 0)
{
foreach (var item in updateList)
{
result += db.Updateable(item).IgnoreColumns(true).ExecuteCommand();
}
}
if (insertList.Count > 0)
{
foreach (var item in insertList)
{
result += db.Insertable(item).IgnoreColumns(true).ExecuteCommand();
}
}
db.CommitTran();
}
catch (Exception)
{
db.RollbackTran();
}
return result;
}
/// <summary>
/// 物料查询接口--弃用
/// </summary>
public object SearchMaterialData(Dictionary<string, object> inParam)
{
List<object> resultList = new List<object>();
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<TFS_Material> materialList = db.Queryable<TFS_Material>()
.WhereIF(inParam.ContainsKey("FVersionCode"), a => a.FVersionCode.Equals(inParam["FVersionCode"].ToString()))
.WhereIF(inParam.ContainsKey("FCode"), a => a.FCode.Equals(inParam["FCode"].ToString()))
.WhereIF(inParam.ContainsKey("FPlmCode"), a => a.FCode.Equals(inParam["FPlmCode"].ToString()))
.WhereIF(inParam.ContainsKey("FName"), a => a.FName.Equals(inParam["FName"].ToString()))
.WhereIF(inParam.ContainsKey("FTestCode"), a => a.FTestCode.Equals(inParam["FTestCode"].ToString()))
.ToList();
if (materialList != null && materialList.Count > 0)
{
List<TFS_ViewMaterial> viewList = new List<TFS_ViewMaterial>();
if (inParam.ContainsKey("FFactoryCode"))
{
List<int> mIds = materialList.Select(s => s.FID).ToList();
viewList = db.Queryable<TFS_ViewMaterial>().Where(s => mIds.Contains(s.FMaterialID) &&
s.FFactoryCode.Equals(inParam["FFactoryCode"].ToString())).ToList();
}
foreach (TFS_Material material in materialList)
{
TFS_ViewMaterial view = viewList.Find(s => s.FMaterialID == material.FID);
if (view != null)
{
resultList.Add(new
{
FName = view.FBaseMaterialDesc,
FType = material.FType,
FCode = view.FBaseMaterialCode,
FTestCode = view.FBaseTestCode,
FVersionCode = material.FVersionCode,
FPlmCode = material.FPlmCode
});
}
else
{
resultList.Add(new
{
material.FName,
material.FType,
material.FCode,
material.FTestCode,
material.FVersionCode,
material.FPlmCode
});
}
}
}
return resultList;
}
/// <summary>
/// 物料查询接口
/// </summary>
public dynamic SearchMaterialData2(Dictionary<string, object> inParam)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
string selectVal = "distinct isnull(b.FBaseMaterialDesc,a.FName)FName,isnull(b.FMRP1ProductType,a.FType)FType," +
"isnull(b.FBaseMaterialCode,a.FCode)FCode,isnull(a.FPlmCode,'')FPlmCode,isnull(b.FBaseTestCode,a.FTestCode)" +
"FTestCode,isnull(a.FVersionCode,'')FVersionCode";
string code1 = "", code2 = "", code3 = "";
dynamic result = new List<int>();
switch (inParam["FType"].ToString())
{
case "1":
if (inParam.TryGetValue("FCode", out object obj1)) code1 = obj1.ToString();
result = db.Queryable<TFS_Material, TFS_ViewMaterial>((a, b) => new JoinQueryInfos(JoinType.Left, a.FID == b.FMaterialID))
.Where((a, b) => b.FBaseMaterialCode.Equals(code1)).Select<dynamic>(selectVal).ToList();
break;
case "2":
if (inParam.TryGetValue("FPlmCode", out object obj2)) code1 = obj2.ToString();
if (inParam.TryGetValue("FVersionCode", out object obj3)) code2 = obj3.ToString();
result = db.Queryable<TFS_Material, TFS_ViewMaterial>((a, b) => new JoinQueryInfos(JoinType.Left, a.FID == b.FMaterialID))
.Where((a, b) => a.FPlmCode.Equals(code1) && a.FVersionCode.Equals(code2)).Select<dynamic>(selectVal).ToList();
break;
case "3":
if (inParam.TryGetValue("FPlmCode", out object obj4)) code1 = obj4.ToString();
if (inParam.TryGetValue("FFactoryCode", out object obj5)) code2 = obj5.ToString();
result = db.Queryable<TFS_Material, TFS_ViewMaterial>((a, b) => new JoinQueryInfos(JoinType.Left, a.FID == b.FMaterialID))
.Where((a, b) => a.FPlmCode.Equals(code1) && b.FFactoryCode.Equals(code2)).Select<dynamic>(selectVal).ToList();
break;
case "4":
if (inParam.TryGetValue("FPlmCode", out object obj6)) code1 = obj6.ToString();
if (inParam.TryGetValue("FVersionCode", out object obj7)) code2 = obj7.ToString();
if (inParam.TryGetValue("FFactoryCode", out object obj8)) code3 = obj8.ToString();
result = db.Queryable<TFS_Material, TFS_ViewMaterial>((a, b) => new JoinQueryInfos(JoinType.Left, a.FID == b.FMaterialID))
.Where((a, b) => a.FPlmCode.Equals(code1) && a.FVersionCode.Equals(code2) && b.FFactoryCode.Equals(code3)).Select<dynamic>(selectVal).ToList();
break;
}
return result;
}
/// <summary>
/// 物料信息补全导入
/// </summary>
public int InsertBatchInfoMaterialData(List<TFS_Material> mainList, List<TFS_MaterialInfo> infoList, List<PropertyInfo> mainProp,
List<PropertyInfo> childProp, List<TFS_FieldInfo> fieldList, int userId)
{
int result = 0;
if (mainList.Count == 0) return result;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<TFS_MaterialType> typeList = db.Queryable<TFS_MaterialType>().Where(s => s.FDeleted != 1).ToList();
List<Dictionary<string, object>> updateList = new List<Dictionary<string, object>>();
object dataVal = null; TFS_Material temp1 = null; TFS_MaterialInfo temp2 = null;
for (int i = 0; i < mainList.Count; i++)
{
temp1 = mainList[i];
temp2 = infoList[i];
TFS_Material mainMater = db.Queryable<TFS_Material>().Where(s => s.FCode == temp1.FCode).OrderBy(s => s.FID, OrderByType.Desc).First();
if (mainMater == null) continue;
List<TFS_MaterialType> tempType1 = typeList.Where(s => s.FName == temp1.FTypeName1.Trim() && s.FDepth == 1).ToList();
List<TFS_MaterialType> tempType2 = typeList.Where(s => s.FName == temp1.FTypeName2.Trim() && s.FDepth == 2).ToList();
if (tempType2.Count == 1 && tempType1.Count == 1)
{
mainMater.FTypeID1 = tempType1.FirstOrDefault().FID;
mainMater.FTypeID2 = tempType2.FirstOrDefault().FID;
}
else
{
foreach (TFS_MaterialType type1 in tempType1)
{
TFS_MaterialType type2 = tempType2.Find(s => s.FParentID == type1.FID);
if (type2 != null)
{
mainMater.FTypeID1 = type1.FID;
mainMater.FTypeID2 = type2.FID;
break;
}
}
}
TFS_MaterialInfo childMater = db.Queryable<TFS_MaterialInfo>().Where(s => s.FDataID == mainMater.FID && s.FType == 2)
.OrderBy(s => s.FID, OrderByType.Desc).First();
if (childMater == null && mainMater.FTypeID2 > 0)
{
childMater = db.Queryable<TFS_MaterialInfo>().Where(s => s.FDataID == mainMater.FTypeID2 && s.FType == 1)
.OrderBy(s => s.FID, OrderByType.Desc).First();
if (childMater != null)
{
childMater.FID = -1;
childMater.FType = 2;
childMater.FDataID = mainMater.FID;
childMater.FAddDate = null;
childMater.FAddUser = userId;
}
}
if (childMater == null)
{
childMater = new TFS_MaterialInfo()
{
FType = 2,
FDataID = mainMater.FID,
FAddUser = userId
};
}
Dictionary<string, object> update = new Dictionary<string, object>();
foreach (TFS_FieldInfo field in fieldList)
{
PropertyInfo mProp = mainProp.Find(s => s.Name == field.FColumnFIeld);
if (mProp != null && (dataVal = mProp.GetValue(temp1)) != null)
{
update.Add(field.FColumnFIeld, dataVal);
}
mProp = childProp.Find(s => s.Name == field.FColumnFIeld);
if (mProp != null && (dataVal = mProp.GetValue(temp2)) != null)
{
mProp.SetValue(childMater, dataVal);
}
}
if (update.Count > 0)
{
update.Add("FID", mainMater.FID);
update.Add("FTypeID1", mainMater.FTypeID1 < 1 ? -1 : mainMater.FTypeID1);
update.Add("FTypeID2", mainMater.FTypeID2 < 1 ? -1 : mainMater.FTypeID2);
update.Remove("FTypeName1");
update.Remove("FTypeName2");
update.Add("FEditUser", userId);
update.Add("FEditDate", DateTime.Now);
updateList.Add(update);
infoList[i] = childMater;
}
else
{
infoList[i] = null;
}
}
try
{
if (updateList.Count > 0)
{
db.BeginTran();
result += db.Updateable(updateList).AS("TFS_Material").WhereColumns("FID").IgnoreColumns(true).ExecuteCommand();
List<TFS_MaterialInfo> temps = infoList.Where(s => s != null && s.FID > 0).ToList();
if (temps.Count > 0) db.Updateable(temps).WhereColumns("FID").IgnoreColumns(true).ExecuteCommand();
temps = infoList.Where(s => s != null && s.FID <= 0).ToList();
if (temps.Count > 0) db.Insertable(temps).IgnoreColumns(true).ExecuteCommand();
db.CommitTran();
}
ExceptionHelper.AddSystemJournal(null, mainList, new { updateList, infoList }, userId, "InsertBatchInfoMaterialData");
}
catch (Exception ex)
{
db.RollbackTran();
ExceptionHelper.AddSystemJournal(null, mainList, new { updateList, infoList, ex.Message }, userId, "InsertBatchInfoMaterialData");
}
return result;
}
/// <summary>
/// 替代料导入处理
/// </summary>
public int InsertBatchTiMaterialData(List<TFS_Material> mainList, List<PropertyInfo> mainProp, List<TFS_FieldInfo> fieldList, int userId)
{
int result = 0;
if (mainList.Count == 0) return result;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<Dictionary<string, object>> updateList = new List<Dictionary<string, object>>();
object dataVal = null; TFS_Material temp = null;
foreach (var item in mainList.GroupBy(s => new { s.FCode, s.FName }))
{
temp = item.ToList().Find(s => !string.IsNullOrEmpty(s.FSuccedaneumCode));
if (temp == null || string.IsNullOrEmpty(item.Key.FCode)) continue;
TFS_Material mainMater = db.Queryable<TFS_Material>().Where(s => s.FCode == item.Key.FCode).OrderBy(s => s.FID, OrderByType.Desc).First();
if (mainMater == null) continue;
TFS_Material lossMater = db.Queryable<TFS_Material>().Where(s => s.FCode == temp.FSuccedaneumCode).OrderBy(s => s.FID, OrderByType.Desc).First();
if (lossMater == null) continue;
Dictionary<string, object> update = new Dictionary<string, object>();
foreach (TFS_FieldInfo field in fieldList)
{
PropertyInfo mProp = mainProp.Find(s => s.Name == field.FColumnFIeld);
if (mProp != null && (dataVal = mProp.GetValue(temp)) != null)
{
update.Add(field.FColumnFIeld, dataVal);
}
}
if (update.Count > 0)
{
update.Add("FID", mainMater.FID);
update.Add("FEditDate", DateTime.Now);
update.Add("FEditUser", userId);
update.Add("FSuccedaneumID", lossMater.FID);
update.Add("FSuccedaneumInfo", lossMater.FName);
update.Add("FSuccedaneumType", lossMater.FType);
updateList.Add(update);
}
}
try
{
if (updateList.Count > 0)
{
db.BeginTran();
result += db.Updateable(updateList).AS("TFS_Material").WhereColumns("FID").IgnoreColumns(true).ExecuteCommand();
db.CommitTran();
}
ExceptionHelper.AddSystemJournal(null, mainList, updateList, userId, "InsertBatchTiMaterialData");
}
catch (Exception ex)
{
db.RollbackTran();
ExceptionHelper.AddSystemJournal(null, mainList, new { updateList, ex.Message }, userId, "InsertBatchTiMaterialData");
}
return result;
}
/// <summary>
/// 副产物导入处理
/// </summary>
public int InsertBatchFuMaterialData(List<TFS_Material> mainList, List<PropertyInfo> mainProp, List<TFS_FieldInfo> fieldList, int userId)
{
int result = 0;
if (mainList.Count == 0) return result;
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<Dictionary<string, object>> updateList = new List<Dictionary<string, object>>();
object dataVal = null; TFS_Material temp = null;
foreach (var item in mainList.GroupBy(s => new { s.FCode, s.FName }))
{
temp = item.ToList().Find(s => !string.IsNullOrEmpty(s.FFuProductsCode) && !string.IsNullOrEmpty(s.FFuProductsInfo));
if (temp == null || string.IsNullOrEmpty(item.Key.FCode) || string.IsNullOrEmpty(item.Key.FName)) continue;
TFS_Material mainMater = db.Queryable<TFS_Material>().Where(s => s.FCode == item.Key.FCode && s.FName == item.Key.FName)
.OrderBy(s => s.FID, OrderByType.Desc).First();
if (mainMater == null) continue;
TFS_Material lossMater = db.Queryable<TFS_Material>().Where(s => s.FCode == temp.FFuProductsCode && s.FName == temp.FFuProductsInfo)
.OrderBy(s => s.FID, OrderByType.Desc).First();
if (lossMater == null) continue;
Dictionary<string, object> update = new Dictionary<string, object>();
foreach (TFS_FieldInfo field in fieldList)
{
PropertyInfo mProp = mainProp.Find(s => s.Name == field.FColumnFIeld);
if (mProp != null && (dataVal = mProp.GetValue(temp)) != null)
{
update.Add(field.FColumnFIeld, dataVal);
}
}
if (update.Count > 0)
{
update.Add("FID", mainMater.FID);
update.Add("FEditDate", DateTime.Now);
update.Add("FEditUser", userId);
update.Add("FFuProductsID", lossMater.FID);
update.Add("FFuProductsType", lossMater.FType);
updateList.Add(update);
}
}
try
{
if (updateList.Count > 0)
{
db.BeginTran();
foreach (var item in updateList)
{
result += db.Updateable(item).AS("TFS_Material").WhereColumns("FID").IgnoreColumns(true).ExecuteCommand();
}
db.CommitTran();
}
ExceptionHelper.AddSystemJournal(null, mainList, updateList, userId, "InsertBatchFuMaterialData");
}
catch (Exception ex)
{
db.RollbackTran();
ExceptionHelper.AddSystemJournal(null, mainList, new { updateList, ex.Message }, userId, "InsertBatchFuMaterialData");
}
return result;
}
/// <summary>
/// 对接SAP物料同步
/// </summary>
public int DockSapMaterial(List<TFS_Material> materialList, int userId)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
int okCount = 0;
db.BeginTran();
List<TFS_ViewMaterial> views = new List<TFS_ViewMaterial>();
try
{
foreach (TFS_Material item in materialList)
{
TFS_Material temp = db.Queryable<TFS_Material>().Where(s => s.FCode == item.FCode).First();
if (temp == null)
{
temp = item;
temp.FID = db.Insertable(item).IgnoreColumns(true).ExecuteReturnIdentity();
okCount += 1;
}
if (db.Queryable<TFS_ViewMaterial>().Where(s => s.FMaterialID == temp.FID && s.FFactoryID == item.FFactoryID).First() == null)
{
TFS_ViewMaterial view = new TFS_ViewMaterial()
{
FMaterialID = temp.FID,
FFactoryID = item.FFactoryID,
FFactoryCode = item.FFactoryCode,
FBaseMaterialCode = string.IsNullOrEmpty(item.FCode) ? temp.FCode : item.FCode,
FBaseMaterialDesc = string.IsNullOrEmpty(item.FName) ? temp.FName : item.FName,
FBaseTestCode = string.IsNullOrEmpty(item.FTestCode) ? temp.FTestCode : item.FTestCode,
FBaseBasicMeter = string.IsNullOrEmpty(item.FBaseUnit) ? temp.FBaseUnit : item.FBaseUnit,
FBaseMaterialGroup = string.IsNullOrEmpty(item.FMaterialGroup) ? temp.FMaterialGroup : item.FMaterialGroup,
FBaseFameCode = string.IsNullOrEmpty(item.FFameCode) ? temp.FFameCode : item.FFameCode,
FOrganizeMaterialType = string.IsNullOrEmpty(item.FMaterialType) ? temp.FMaterialType : item.FMaterialType
};
okCount += db.Insertable(view).IgnoreColumns(true).ExecuteCommand();
views.Add(view);
}
}
db.CommitTran();
ExceptionHelper.AddSystemJournal(null, materialList, new { views }, userId, "InsertBatchFuMaterialData");
}
catch (Exception ex)
{
db.RollbackTran();
ExceptionHelper.AddSystemJournal(null, materialList, new { views, ex.Message }, userId, "InsertBatchFuMaterialData");
}
return okCount;
}
/// <summary>
/// 导出视图
/// </summary>
/// <param name="intType"></param>
/// <param name="savePath"></param>
/// <param name="selectSql"></param>
/// <param name="whereSql"></param>
/// <param name="joinSql"></param>
/// <param name="teamId"></param>
/// <param name="halfId"></param>
public void CreateExeclFile(string fType, string savePath, string selectSql, string whereSql, string joinSql, string teamId, string halfId)
{
//selectSql = selectSql.Replace("@FMaterialID@", halfId);
DataTable dataList = new DataTable();
dataList = GetMaterialInfo(teamId);
//dataList.Columns.Remove("FMaterialID");
NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath.Replace(".xlsx", fType + ".xlsx"));
}
/// <summary>
/// 导出SAP视图
/// </summary>
/// <param name="intType"></param>
/// <param name="savePath"></param>
/// <param name="selectSql"></param>
/// <param name="whereSql"></param>
/// <param name="joinSql"></param>
/// <param name="teamId"></param>
/// <param name="halfId"></param>
public void CreateExeclFileSAP(string fType, string savePath, string selectSql, string whereSql, string joinSql, string teamId, string halfId)
{
DataTable dataList = new DataTable();
dataList = GetMaterialInfoSAP(teamId);
//dataList.Columns.Remove("FMaterialID");
NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath.Replace(".xlsx", fType + ".xlsx"));
}
public DataTable GetMaterialInfo(string FID)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
string strSql = string.Format(@"
SELECT
isnull( FTypeName1, '' ) AS '',
isnull( FTypeName2, '' ) AS '',
isnull( FK3Code, '' ) AS 'K3',
isnull( FK3Name, '' ) AS 'K3',
isnull( FK3ShortCode, '' ) AS 'K3',
isnull( FTestCode, '' ) AS '',
isnull( FCode, '' ) AS 'SAP',
isnull( FName, '' ) AS 'SAP',
isnull( FMaterialGroup, '' ) AS '',
isnull( FMaterialType, '' ) AS '',
isnull( FCustomerCode, '' ) AS '',
isnull( FStoreHouse, '' ) AS '',
isnull( FBomEntry, '' ) AS 'BOM',
isnull( FLineHouse, '' ) AS '线',
isnull( FProductDesc, '' ) AS '',
isnull( FWorkCenter, '' ) AS '',
isnull( FCraftExplain, '' ) AS '',
isnull( FIidentifier, '' ) AS '',
isnull( FGuaranteePeriod, '' ) AS '',
isnull( FStorageConditions, '' ) AS '',
isnull( FSafetyStock, '' ) AS '',
isnull( FTriggerRatio, '' ) AS '',
isnull( FMinAmount, '' ) AS '',
isnull( FMaxAmount, '' ) AS '',
isnull( FYield, '' ) AS '',
isnull( FFixedLoss, '' ) AS '',
isnull( FTheoryYield, '' ) AS '',
isnull( FQualityTest1, '' ) AS '1',
isnull( FQualityTest2, '' ) AS '2',
isnull( FName, '' ) AS '',
isnull( FDesc, '' ) AS '',
isnull( FType, '' ) AS '',
isnull( FCode, '' ) AS '',
isnull( FTestCode, '' ) AS '',
isnull( FVersionCode, '' ) AS '',
isnull( FFactoryCode, '' ) AS '',
isnull( FSupplyCode, '' ) AS '',
isnull( FGroupCode, '' ) AS '',
isnull( FBaseUnit, '' ) AS '',
isnull( FMaterialGroup, '' ) AS '',
isnull( FStoreHouse, '' ) AS '',
isnull( FWorkCenter, '' ) AS '',
isnull( FCraftDesc, '' ) AS '',
isnull( FCraftExplain, '' ) AS '',
isnull( FLineHouse, '' ) AS '线',
isnull( FFixedLoss, '' ) AS '',
isnull( FOrganizeIndustryField, '' ) AS '.',
isnull( FOrganizeMaterialType, '' ) AS '.',
isnull( FOrganizeFactory, '' ) AS '.',
isnull( FOrganizeInventoryLocation, '' ) AS '.',
isnull( FOrganizeSalesOrganize, '' ) AS '.',
isnull( FOrganizeDistributionChannel, '' ) AS '.',
isnull( FBaseMaterialCode, '' ) AS '.',
isnull( FBaseTestCode, '' ) AS '.',
isnull( FBaseBasicMeter, '' ) AS '.',
isnull( FBaseMaterialDesc, '' ) AS '.',
isnull( FBaseMaterialGroup, '' ) AS '.',
isnull( FBaseSpecification, '' ) AS './()',
isnull( FBaseMaterialText, '' ) AS '.',
isnull( FBaseIdentifier, '' ) AS '.:/',
isnull( FBaseVolumeUnit, '' ) AS '.',
isnull( FBaseGrossWeight, '' ) AS '.',
isnull( FBaseNetWeight, '' ) AS '.',
isnull( FBaseWeightUnit, '' ) AS '.',
isnull( FBaseBusinessVolume, '' ) AS '.',
isnull( FBaseFameCode, '' ) AS '.fame',
isnull( FPurchaseGroup, '' ) AS '.',
isnull( FPurchaseCompany, '' ) AS '.',
isnull( FPurchaseCompanyCount, '' ) AS '.',
isnull( FPurchaseBaseCompanyCount, '' ) AS '.',
isnull( FPurchaseValueCode, '' ) AS '.',
isnull( FPurchaseFactorySpecificStatus, '' ) AS '.',
isnull( FPurchaseAutoOrder, '' ) AS '.',
isnull( FPurchaseGoodsSource, '' ) AS '.',
isnull( FTypeCategoryType, '' ) AS '.',
isnull( FTypeType, '' ) AS '.',
isnull( FSaleDeliveryFactory, '' ) AS '.',
isnull( FSaleTaxType, '' ) AS '.',
isnull( FSaleMaterialStatisticsGroup, '' ) AS '.',
isnull( FSaleSalesCompany, '' ) AS '.',
isnull( FSaleBaseCompanyCount, '' ) AS '.',
isnull( FSaleSalesCompanyCount, '' ) AS '.',
isnull( FSaleAccountSettingGroup, '' ) AS '.',
isnull( FSaleGeneralProjectCategoryGroup, '' ) AS '.',
isnull( FSaleProjectCategoryGroup, '' ) AS '.',
isnull( FSaleAvailabilityCheck, '' ) AS '.',
isnull( FSaleOutfitGroup, '' ) AS '.',
isnull( FSaleOldMaterialCode, '' ) AS '.',
isnull( FStorageConditions, '' ) AS '.',
isnull( FStorageBatchManage, '' ) AS '.',
isnull( FStorageMaxStoragePeriod, '' ) AS '.',
isnull( FStorageTimeUnit, '' ) AS '.',
isnull( FStorageMinSurplusShelfLife, '' ) AS '.寿',
isnull( FStorageTotalShelfLife, '' ) AS '.寿',
isnull( FStorageSLEDCode, '' ) AS '.SLED',
isnull( FMRP1Type, '' ) AS 'MRP1.MRP',
isnull( FMRP1Controller, '' ) AS 'MRP1.MRP',
isnull( FMRP1BatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MinBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MaxBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1Group, '' ) AS 'MRP1.MRP',
isnull( FMRP1RoundValue, '' ) AS 'MRP1.',
isnull( FMRP1ProductType, '' ) AS 'MRP1.',
isnull( FMRP1CustomerCode, '' ) AS 'MRP1.',
isnull( FMRP1SizeMaterial, '' ) AS 'MRP1.',
isnull( FMRP1SmallMaterialStandard, '' ) AS 'MRP1.',
isnull( FMRP2PurchaseType, '' ) AS 'MRP2.',
isnull( FMRP2PlanMarginalCode, '' ) AS 'MRP2.',
isnull( FMRP2SpecialProcurement, '' ) AS 'MRP2.',
isnull( FMRP2Recoil, '' ) AS 'MRP2.',
isnull( FMRP2SelfProductTime, '' ) AS 'MRP2.',
isnull( FMRP2PlannDeliveryTime, '' ) AS 'MRP2.',
isnull( FMRP2ReceiveProcessTime, '' ) AS 'MRP2.',
isnull( FMRP2SafeStock, '' ) AS 'MRP2.',
isnull( FMRP2DeliveryInventoryPlace, '' ) AS 'MRP2.',
isnull( FMRP2ExternalStoragePlace, '' ) AS 'MRP2.',
isnull( FMRP3PolicyGroup, '' ) AS 'MRP3.',
isnull( FMRP3ConsumePattern, '' ) AS 'MRP3.',
isnull( FMRP3ForwardConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3ReverseConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3BlendMRP, '' ) AS 'MRP3.MRP',
isnull( FMRP3AvailabilityCheck, '' ) AS 'MRP3.',
isnull( FMRP4AloneOrFocus, '' ) AS 'MRP3.',
isnull( FPlanProductPlanParam, '' ) AS '.',
isnull( FPlanUnlimitedOverDelivery, '' ) AS '.',
isnull( FPlanUnderDeliveryTolerance, '' ) AS '.',
isnull( FPlanOverDeliveryTolerance, '' ) AS '.',
isnull( FPlanDeliverCompany, '' ) AS '.',
isnull( FPlanDeliverCompanyCount, '' ) AS '.',
isnull( FPlanBaseCompanyCount, '' ) AS '.',
isnull( FQualityType1, '' ) AS '.1',
isnull( FQualityType2, '' ) AS '.2',
isnull( FQualityType3, '' ) AS '.3',
isnull( FQualityType4, '' ) AS '.4',
isnull( FQualityType5, '' ) AS '.5',
isnull( FQualityType6, '' ) AS '.6',
isnull( FAccountPriceControl, '' ) AS '.',
isnull( FAccountPriceDetermine, '' ) AS '.',
isnull( FAccountPriceUnit, '' ) AS '.',
isnull( FAccountAccessType, '' ) AS '.',
isnull( FAccountSaleOrderInventory, '' ) AS '.VC: ',
isnull( FAccountStandardPrice, '' ) AS '.',
isnull( FAccountProfitCenter, '' ) AS '.',
isnull( FAccountCostAccountBatch, '' ) AS '.'
FROM(
SELECT
isnull( b.FName, '' ) AS 'FTypeName1',
isnull( c.FName, '' ) AS 'FTypeName2',
isnull( FSAPCode, '' ) AS 'FCode',
isnull( FSAPDescription, '' ) AS 'FName',
isnull( FBaseMaterialDesc, '' ) AS 'FDesc',
isnull( FBaseMaterialDesc, '' ) AS 'FVersionCode',
isnull( FBaseMaterialDesc, '' ) AS 'FFactoryCode',
isnull( FBaseMaterialDesc, '' ) AS 'FSupplyCode',
isnull( FBaseMaterialGroup, '' ) AS 'FGroupCode',
isnull( FBaseWeightUnit, '' ) AS 'FBaseUnit',
isnull( FCraftExplain, '' ) AS 'FCraftDesc',
d.FName AS 'FtypeName',
a.*
FROM
TFS_MaterialInfo AS a
LEFT JOIN TFS_MaterialType AS d ON a.FType=d.FID
LEFT JOIN TFS_MaterialType AS b ON a.FTypeID1= b.FID
LEFT JOIN TFS_MaterialType AS C ON a.FTypeID2= b.FID
WHERE
FDataId = {0})a;", FID);
DataTable data = db.Ado.GetDataTable(strSql);
return data;
}
public DataTable GetMaterialInfoSAP(string FID)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
string strSql = string.Format(@"
SELECT
isnull( FName, '' ) AS '',
isnull( FDesc, '' ) AS '',
isnull( REPLACE ( FType , FType , FtypeName ), '' ) AS '',
isnull( FCode, '' ) AS '',
isnull( FTestCode, '' ) AS '',
isnull( FVersionCode, '' ) AS '',
isnull( FFactoryCode, '' ) AS '',
isnull( FSupplyCode, '' ) AS '',
isnull( FGroupCode, '' ) AS '',
isnull( FBaseUnit, '' ) AS '',
isnull( FMaterialGroup, '' ) AS '',
isnull( FStoreHouse, '' ) AS '',
isnull( FWorkCenter, '' ) AS '',
isnull( FCraftDesc, '' ) AS '',
isnull( FCraftExplain, '' ) AS '',
isnull( FLineHouse, '' ) AS '线',
isnull( FFixedLoss, '' ) AS '',
isnull( FOrganizeIndustryField, '' ) AS '.',
isnull( FOrganizeMaterialType, '' ) AS '.',
isnull( FOrganizeFactory, '' ) AS '.',
isnull( FOrganizeInventoryLocation, '' ) AS '.',
isnull( FOrganizeSalesOrganize, '' ) AS '.',
isnull( FOrganizeDistributionChannel, '' ) AS '.',
isnull( FBaseMaterialCode, '' ) AS '.',
isnull( FBaseTestCode, '' ) AS '.',
isnull( FBaseBasicMeter, '' ) AS '.',
isnull( FBaseMaterialDesc, '' ) AS '.',
isnull( FBaseMaterialGroup, '' ) AS '.',
isnull( FBaseSpecification, '' ) AS './()',
isnull( FBaseMaterialText, '' ) AS '.',
isnull( FBaseIdentifier, '' ) AS '.:/',
isnull( FBaseVolumeUnit, '' ) AS '.',
isnull( FBaseGrossWeight, '' ) AS '.',
isnull( FBaseNetWeight, '' ) AS '.',
isnull( FBaseWeightUnit, '' ) AS '.',
isnull( FBaseBusinessVolume, '' ) AS '.',
isnull( FBaseFameCode, '' ) AS '.fame',
isnull( FPurchaseGroup, '' ) AS '.',
isnull( FPurchaseCompany, '' ) AS '.',
isnull( FPurchaseCompanyCount, '' ) AS '.',
isnull( FPurchaseBaseCompanyCount, '' ) AS '.',
isnull( FPurchaseValueCode, '' ) AS '.',
isnull( FPurchaseFactorySpecificStatus, '' ) AS '.',
isnull( FPurchaseAutoOrder, '' ) AS '.',
isnull( FPurchaseGoodsSource, '' ) AS '.',
isnull( FTypeCategoryType, '' ) AS '.',
isnull( FTypeType, '' ) AS '.',
isnull( FSaleDeliveryFactory, '' ) AS '.',
isnull( FSaleTaxType, '' ) AS '.',
isnull( FSaleMaterialStatisticsGroup, '' ) AS '.',
isnull( FSaleSalesCompany, '' ) AS '.',
isnull( FSaleBaseCompanyCount, '' ) AS '.',
isnull( FSaleSalesCompanyCount, '' ) AS '.',
isnull( FSaleAccountSettingGroup, '' ) AS '.',
isnull( FSaleGeneralProjectCategoryGroup, '' ) AS '.',
isnull( FSaleProjectCategoryGroup, '' ) AS '.',
isnull( FSaleAvailabilityCheck, '' ) AS '.',
isnull( FSaleOutfitGroup, '' ) AS '.',
isnull( FSaleOldMaterialCode, '' ) AS '.',
isnull( FStorageConditions, '' ) AS '.',
isnull( FStorageBatchManage, '' ) AS '.',
isnull( FStorageMaxStoragePeriod, '' ) AS '.',
isnull( FStorageTimeUnit, '' ) AS '.',
isnull( FStorageMinSurplusShelfLife, '' ) AS '.寿',
isnull( FStorageTotalShelfLife, '' ) AS '.寿',
isnull( FStorageSLEDCode, '' ) AS '.SLED',
isnull( FMRP1Type, '' ) AS 'MRP1.MRP',
isnull( FMRP1Controller, '' ) AS 'MRP1.MRP',
isnull( FMRP1BatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MinBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MaxBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1Group, '' ) AS 'MRP1.MRP',
isnull( FMRP1RoundValue, '' ) AS 'MRP1.',
isnull( FMRP1ProductType, '' ) AS 'MRP1.',
isnull( FMRP1CustomerCode, '' ) AS 'MRP1.',
isnull( FMRP1SizeMaterial, '' ) AS 'MRP1.',
isnull( FMRP1SmallMaterialStandard, '' ) AS 'MRP1.',
isnull( FMRP2PurchaseType, '' ) AS 'MRP2.',
isnull( FMRP2PlanMarginalCode, '' ) AS 'MRP2.',
isnull( FMRP2SpecialProcurement, '' ) AS 'MRP2.',
isnull( FMRP2Recoil, '' ) AS 'MRP2.',
isnull( FMRP2SelfProductTime, '' ) AS 'MRP2.',
isnull( FMRP2PlannDeliveryTime, '' ) AS 'MRP2.',
isnull( FMRP2ReceiveProcessTime, '' ) AS 'MRP2.',
isnull( FMRP2SafeStock, '' ) AS 'MRP2.',
isnull( FMRP2DeliveryInventoryPlace, '' ) AS 'MRP2.',
isnull( FMRP2ExternalStoragePlace, '' ) AS 'MRP2.',
isnull( FMRP3PolicyGroup, '' ) AS 'MRP3.',
isnull( FMRP3ConsumePattern, '' ) AS 'MRP3.',
isnull( FMRP3ForwardConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3ReverseConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3BlendMRP, '' ) AS 'MRP3.MRP',
isnull( FMRP3AvailabilityCheck, '' ) AS 'MRP3.',
isnull( FMRP4AloneOrFocus, '' ) AS 'MRP3.',
isnull( FPlanProductPlanParam, '' ) AS '.',
isnull( FPlanUnlimitedOverDelivery, '' ) AS '.',
isnull( FPlanUnderDeliveryTolerance, '' ) AS '.',
isnull( FPlanOverDeliveryTolerance, '' ) AS '.',
isnull( FPlanDeliverCompany, '' ) AS '.',
isnull( FPlanDeliverCompanyCount, '' ) AS '.',
isnull( FPlanBaseCompanyCount, '' ) AS '.',
isnull( FQualityType1, '' ) AS '.1',
isnull( FQualityType2, '' ) AS '.2',
isnull( FQualityType3, '' ) AS '.3',
isnull( FQualityType4, '' ) AS '.4',
isnull( FQualityType5, '' ) AS '.5',
isnull( FQualityType6, '' ) AS '.6',
isnull( FAccountPriceControl, '' ) AS '.',
isnull( FAccountPriceDetermine, '' ) AS '.',
isnull( FAccountPriceUnit, '' ) AS '.',
isnull( FAccountAccessType, '' ) AS '.',
isnull( FAccountSaleOrderInventory, '' ) AS '.VC: ',
isnull( FAccountStandardPrice, '' ) AS '.',
isnull( FAccountProfitCenter, '' ) AS '.',
isnull( FAccountCostAccountBatch, '' ) AS '.'
FROM(
SELECT
isnull( b.FName, '' ) AS 'FTypeName1',
isnull( c.FName, '' ) AS 'FTypeName2',
isnull( FSAPCode, '' ) AS 'FCode',
isnull( FSAPDescription, '' ) AS 'FName',
isnull( FBaseMaterialDesc, '' ) AS 'FDesc',
isnull( FBaseMaterialDesc, '' ) AS 'FVersionCode',
isnull( FBaseMaterialDesc, '' ) AS 'FFactoryCode',
isnull( FBaseMaterialDesc, '' ) AS 'FSupplyCode',
isnull( FBaseMaterialGroup, '' ) AS 'FGroupCode',
isnull( FBaseWeightUnit, '' ) AS 'FBaseUnit',
isnull( FCraftExplain, '' ) AS 'FCraftDesc',
d.FName AS 'FtypeName',
a.*
FROM
TFS_MaterialInfo AS a
LEFT JOIN TFS_MaterialType AS d ON a.FType=d.FID
LEFT JOIN TFS_MaterialType AS b ON a.FTypeID1= b.FID
LEFT JOIN TFS_MaterialType AS C ON a.FTypeID2= b.FID
WHERE
FDataId = {0})a;", FID);
DataTable data = db.Ado.GetDataTable(strSql);
return data;
}
public void CreateExeclFileALL(string FType,string savePath)
{
DataTable dataList = new DataTable();
string str = "";
if (FType == "1")
{
str = "视图";
dataList = GetMaterialInfoALL();
}
else {
str = "基础视图";
dataList = GetMaterialInfoSAPALL();
}
//dataList.Columns.Remove("FMaterialID");
NPOIHelper.ExportDTtoExcel(dataList, "Sheet1", savePath.Replace(".xlsx",str+".xlsx"));
}
public DataTable GetMaterialInfoALL()
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
string strSql = string.Format(@"
SELECT
isnull( FTypeName1, '' ) AS '',
isnull( FTypeName2, '' ) AS '',
isnull( FK3Code, '' ) AS 'K3',
isnull( FK3Name, '' ) AS 'K3',
isnull( FK3ShortCode, '' ) AS 'K3',
isnull( FTestCode, '' ) AS '',
isnull( FCode, '' ) AS 'SAP',
isnull( FName, '' ) AS 'SAP',
isnull( FMaterialGroup, '' ) AS '',
isnull( FMaterialType, '' ) AS '',
isnull( FCustomerCode, '' ) AS '',
isnull( FStoreHouse, '' ) AS '',
isnull( FBomEntry, '' ) AS 'BOM',
isnull( FLineHouse, '' ) AS '线',
isnull( FProductDesc, '' ) AS '',
isnull( FWorkCenter, '' ) AS '',
isnull( FCraftExplain, '' ) AS '',
isnull( FIidentifier, '' ) AS '',
isnull( FGuaranteePeriod, '' ) AS '',
isnull( FStorageConditions, '' ) AS '',
isnull( FSafetyStock, '' ) AS '',
isnull( FTriggerRatio, '' ) AS '',
isnull( FMinAmount, '' ) AS '',
isnull( FMaxAmount, '' ) AS '',
isnull( FYield, '' ) AS '',
isnull( FFixedLoss, '' ) AS '',
isnull( FTheoryYield, '' ) AS '',
isnull( FQualityTest1, '' ) AS '1',
isnull( FQualityTest2, '' ) AS '2',
isnull( FName, '' ) AS '',
isnull( FDesc, '' ) AS '',
isnull( FType, '' ) AS '',
isnull( FCode, '' ) AS '',
isnull( FTestCode, '' ) AS '',
isnull( FVersionCode, '' ) AS '',
isnull( FFactoryCode, '' ) AS '',
isnull( FSupplyCode, '' ) AS '',
isnull( FGroupCode, '' ) AS '',
isnull( FBaseUnit, '' ) AS '',
isnull( FMaterialGroup, '' ) AS '',
isnull( FStoreHouse, '' ) AS '',
isnull( FWorkCenter, '' ) AS '',
isnull( FCraftDesc, '' ) AS '',
isnull( FCraftExplain, '' ) AS '',
isnull( FLineHouse, '' ) AS '线',
isnull( FFixedLoss, '' ) AS '',
isnull( FOrganizeIndustryField, '' ) AS '.',
isnull( FOrganizeMaterialType, '' ) AS '.',
isnull( FOrganizeFactory, '' ) AS '.',
isnull( FOrganizeInventoryLocation, '' ) AS '.',
isnull( FOrganizeSalesOrganize, '' ) AS '.',
isnull( FOrganizeDistributionChannel, '' ) AS '.',
isnull( FBaseMaterialCode, '' ) AS '.',
isnull( FBaseTestCode, '' ) AS '.',
isnull( FBaseBasicMeter, '' ) AS '.',
isnull( FBaseMaterialDesc, '' ) AS '.',
isnull( FBaseMaterialGroup, '' ) AS '.',
isnull( FBaseSpecification, '' ) AS './()',
isnull( FBaseMaterialText, '' ) AS '.',
isnull( FBaseIdentifier, '' ) AS '.:/',
isnull( FBaseVolumeUnit, '' ) AS '.',
isnull( FBaseGrossWeight, '' ) AS '.',
isnull( FBaseNetWeight, '' ) AS '.',
isnull( FBaseWeightUnit, '' ) AS '.',
isnull( FBaseBusinessVolume, '' ) AS '.',
isnull( FBaseFameCode, '' ) AS '.fame',
isnull( FPurchaseGroup, '' ) AS '.',
isnull( FPurchaseCompany, '' ) AS '.',
isnull( FPurchaseCompanyCount, '' ) AS '.',
isnull( FPurchaseBaseCompanyCount, '' ) AS '.',
isnull( FPurchaseValueCode, '' ) AS '.',
isnull( FPurchaseFactorySpecificStatus, '' ) AS '.',
isnull( FPurchaseAutoOrder, '' ) AS '.',
isnull( FPurchaseGoodsSource, '' ) AS '.',
isnull( FTypeCategoryType, '' ) AS '.',
isnull( FTypeType, '' ) AS '.',
isnull( FSaleDeliveryFactory, '' ) AS '.',
isnull( FSaleTaxType, '' ) AS '.',
isnull( FSaleMaterialStatisticsGroup, '' ) AS '.',
isnull( FSaleSalesCompany, '' ) AS '.',
isnull( FSaleBaseCompanyCount, '' ) AS '.',
isnull( FSaleSalesCompanyCount, '' ) AS '.',
isnull( FSaleAccountSettingGroup, '' ) AS '.',
isnull( FSaleGeneralProjectCategoryGroup, '' ) AS '.',
isnull( FSaleProjectCategoryGroup, '' ) AS '.',
isnull( FSaleAvailabilityCheck, '' ) AS '.',
isnull( FSaleOutfitGroup, '' ) AS '.',
isnull( FSaleOldMaterialCode, '' ) AS '.',
isnull( FStorageConditions, '' ) AS '.',
isnull( FStorageBatchManage, '' ) AS '.',
isnull( FStorageMaxStoragePeriod, '' ) AS '.',
isnull( FStorageTimeUnit, '' ) AS '.',
isnull( FStorageMinSurplusShelfLife, '' ) AS '.寿',
isnull( FStorageTotalShelfLife, '' ) AS '.寿',
isnull( FStorageSLEDCode, '' ) AS '.SLED',
isnull( FMRP1Type, '' ) AS 'MRP1.MRP',
isnull( FMRP1Controller, '' ) AS 'MRP1.MRP',
isnull( FMRP1BatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MinBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MaxBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1Group, '' ) AS 'MRP1.MRP',
isnull( FMRP1RoundValue, '' ) AS 'MRP1.',
isnull( FMRP1ProductType, '' ) AS 'MRP1.',
isnull( FMRP1CustomerCode, '' ) AS 'MRP1.',
isnull( FMRP1SizeMaterial, '' ) AS 'MRP1.',
isnull( FMRP1SmallMaterialStandard, '' ) AS 'MRP1.',
isnull( FMRP2PurchaseType, '' ) AS 'MRP2.',
isnull( FMRP2PlanMarginalCode, '' ) AS 'MRP2.',
isnull( FMRP2SpecialProcurement, '' ) AS 'MRP2.',
isnull( FMRP2Recoil, '' ) AS 'MRP2.',
isnull( FMRP2SelfProductTime, '' ) AS 'MRP2.',
isnull( FMRP2PlannDeliveryTime, '' ) AS 'MRP2.',
isnull( FMRP2ReceiveProcessTime, '' ) AS 'MRP2.',
isnull( FMRP2SafeStock, '' ) AS 'MRP2.',
isnull( FMRP2DeliveryInventoryPlace, '' ) AS 'MRP2.',
isnull( FMRP2ExternalStoragePlace, '' ) AS 'MRP2.',
isnull( FMRP3PolicyGroup, '' ) AS 'MRP3.',
isnull( FMRP3ConsumePattern, '' ) AS 'MRP3.',
isnull( FMRP3ForwardConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3ReverseConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3BlendMRP, '' ) AS 'MRP3.MRP',
isnull( FMRP3AvailabilityCheck, '' ) AS 'MRP3.',
isnull( FMRP4AloneOrFocus, '' ) AS 'MRP3.',
isnull( FPlanProductPlanParam, '' ) AS '.',
isnull( FPlanUnlimitedOverDelivery, '' ) AS '.',
isnull( FPlanUnderDeliveryTolerance, '' ) AS '.',
isnull( FPlanOverDeliveryTolerance, '' ) AS '.',
isnull( FPlanDeliverCompany, '' ) AS '.',
isnull( FPlanDeliverCompanyCount, '' ) AS '.',
isnull( FPlanBaseCompanyCount, '' ) AS '.',
isnull( FQualityType1, '' ) AS '.1',
isnull( FQualityType2, '' ) AS '.2',
isnull( FQualityType3, '' ) AS '.3',
isnull( FQualityType4, '' ) AS '.4',
isnull( FQualityType5, '' ) AS '.5',
isnull( FQualityType6, '' ) AS '.6',
isnull( FAccountPriceControl, '' ) AS '.',
isnull( FAccountPriceDetermine, '' ) AS '.',
isnull( FAccountPriceUnit, '' ) AS '.',
isnull( FAccountAccessType, '' ) AS '.',
isnull( FAccountSaleOrderInventory, '' ) AS '.VC: ',
isnull( FAccountStandardPrice, '' ) AS '.',
isnull( FAccountProfitCenter, '' ) AS '.',
isnull( FAccountCostAccountBatch, '' ) AS '.'
FROM(
SELECT
isnull( b.FName, '' ) AS 'FTypeName1',
isnull( c.FName, '' ) AS 'FTypeName2',
isnull( FSAPCode, '' ) AS 'FCode',
isnull( FSAPDescription, '' ) AS 'FName',
isnull( FBaseMaterialDesc, '' ) AS 'FDesc',
isnull( FBaseMaterialDesc, '' ) AS 'FVersionCode',
isnull( FBaseMaterialDesc, '' ) AS 'FFactoryCode',
isnull( FBaseMaterialDesc, '' ) AS 'FSupplyCode',
isnull( FBaseMaterialGroup, '' ) AS 'FGroupCode',
isnull( FBaseWeightUnit, '' ) AS 'FBaseUnit',
isnull( FCraftExplain, '' ) AS 'FCraftDesc',
d.FName AS 'FtypeName',
a.*
FROM
TFS_MaterialInfo AS a
LEFT JOIN TFS_MaterialType AS d ON a.FType=d.FID
LEFT JOIN TFS_MaterialType AS b ON a.FTypeID1= b.FID
LEFT JOIN TFS_MaterialType AS C ON a.FTypeID2= b.FID
)a;");
DataTable data = db.Ado.GetDataTable(strSql);
return data;
}
public DataTable GetMaterialInfoSAPALL()
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
string strSql = string.Format(@"
SELECT
isnull( FName, '' ) AS '',
isnull( FDesc, '' ) AS '',
isnull( REPLACE ( FType , FType , FtypeName ), '' ) AS '',
isnull( FCode, '' ) AS '',
isnull( FTestCode, '' ) AS '',
isnull( FVersionCode, '' ) AS '',
isnull( FFactoryCode, '' ) AS '',
isnull( FSupplyCode, '' ) AS '',
isnull( FGroupCode, '' ) AS '',
isnull( FBaseUnit, '' ) AS '',
isnull( FMaterialGroup, '' ) AS '',
isnull( FStoreHouse, '' ) AS '',
isnull( FWorkCenter, '' ) AS '',
isnull( FCraftDesc, '' ) AS '',
isnull( FCraftExplain, '' ) AS '',
isnull( FLineHouse, '' ) AS '线',
isnull( FFixedLoss, '' ) AS '',
isnull( FOrganizeIndustryField, '' ) AS '.',
isnull( FOrganizeMaterialType, '' ) AS '.',
isnull( FOrganizeFactory, '' ) AS '.',
isnull( FOrganizeInventoryLocation, '' ) AS '.',
isnull( FOrganizeSalesOrganize, '' ) AS '.',
isnull( FOrganizeDistributionChannel, '' ) AS '.',
isnull( FBaseMaterialCode, '' ) AS '.',
isnull( FBaseTestCode, '' ) AS '.',
isnull( FBaseBasicMeter, '' ) AS '.',
isnull( FBaseMaterialDesc, '' ) AS '.',
isnull( FBaseMaterialGroup, '' ) AS '.',
isnull( FBaseSpecification, '' ) AS './()',
isnull( FBaseMaterialText, '' ) AS '.',
isnull( FBaseIdentifier, '' ) AS '.:/',
isnull( FBaseVolumeUnit, '' ) AS '.',
isnull( FBaseGrossWeight, '' ) AS '.',
isnull( FBaseNetWeight, '' ) AS '.',
isnull( FBaseWeightUnit, '' ) AS '.',
isnull( FBaseBusinessVolume, '' ) AS '.',
isnull( FBaseFameCode, '' ) AS '.fame',
isnull( FPurchaseGroup, '' ) AS '.',
isnull( FPurchaseCompany, '' ) AS '.',
isnull( FPurchaseCompanyCount, '' ) AS '.',
isnull( FPurchaseBaseCompanyCount, '' ) AS '.',
isnull( FPurchaseValueCode, '' ) AS '.',
isnull( FPurchaseFactorySpecificStatus, '' ) AS '.',
isnull( FPurchaseAutoOrder, '' ) AS '.',
isnull( FPurchaseGoodsSource, '' ) AS '.',
isnull( FTypeCategoryType, '' ) AS '.',
isnull( FTypeType, '' ) AS '.',
isnull( FSaleDeliveryFactory, '' ) AS '.',
isnull( FSaleTaxType, '' ) AS '.',
isnull( FSaleMaterialStatisticsGroup, '' ) AS '.',
isnull( FSaleSalesCompany, '' ) AS '.',
isnull( FSaleBaseCompanyCount, '' ) AS '.',
isnull( FSaleSalesCompanyCount, '' ) AS '.',
isnull( FSaleAccountSettingGroup, '' ) AS '.',
isnull( FSaleGeneralProjectCategoryGroup, '' ) AS '.',
isnull( FSaleProjectCategoryGroup, '' ) AS '.',
isnull( FSaleAvailabilityCheck, '' ) AS '.',
isnull( FSaleOutfitGroup, '' ) AS '.',
isnull( FSaleOldMaterialCode, '' ) AS '.',
isnull( FStorageConditions, '' ) AS '.',
isnull( FStorageBatchManage, '' ) AS '.',
isnull( FStorageMaxStoragePeriod, '' ) AS '.',
isnull( FStorageTimeUnit, '' ) AS '.',
isnull( FStorageMinSurplusShelfLife, '' ) AS '.寿',
isnull( FStorageTotalShelfLife, '' ) AS '.寿',
isnull( FStorageSLEDCode, '' ) AS '.SLED',
isnull( FMRP1Type, '' ) AS 'MRP1.MRP',
isnull( FMRP1Controller, '' ) AS 'MRP1.MRP',
isnull( FMRP1BatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MinBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1MaxBatchSize, '' ) AS 'MRP1.',
isnull( FMRP1Group, '' ) AS 'MRP1.MRP',
isnull( FMRP1RoundValue, '' ) AS 'MRP1.',
isnull( FMRP1ProductType, '' ) AS 'MRP1.',
isnull( FMRP1CustomerCode, '' ) AS 'MRP1.',
isnull( FMRP1SizeMaterial, '' ) AS 'MRP1.',
isnull( FMRP1SmallMaterialStandard, '' ) AS 'MRP1.',
isnull( FMRP2PurchaseType, '' ) AS 'MRP2.',
isnull( FMRP2PlanMarginalCode, '' ) AS 'MRP2.',
isnull( FMRP2SpecialProcurement, '' ) AS 'MRP2.',
isnull( FMRP2Recoil, '' ) AS 'MRP2.',
isnull( FMRP2SelfProductTime, '' ) AS 'MRP2.',
isnull( FMRP2PlannDeliveryTime, '' ) AS 'MRP2.',
isnull( FMRP2ReceiveProcessTime, '' ) AS 'MRP2.',
isnull( FMRP2SafeStock, '' ) AS 'MRP2.',
isnull( FMRP2DeliveryInventoryPlace, '' ) AS 'MRP2.',
isnull( FMRP2ExternalStoragePlace, '' ) AS 'MRP2.',
isnull( FMRP3PolicyGroup, '' ) AS 'MRP3.',
isnull( FMRP3ConsumePattern, '' ) AS 'MRP3.',
isnull( FMRP3ForwardConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3ReverseConsumePeriod, '' ) AS 'MRP3.',
isnull( FMRP3BlendMRP, '' ) AS 'MRP3.MRP',
isnull( FMRP3AvailabilityCheck, '' ) AS 'MRP3.',
isnull( FMRP4AloneOrFocus, '' ) AS 'MRP3.',
isnull( FPlanProductPlanParam, '' ) AS '.',
isnull( FPlanUnlimitedOverDelivery, '' ) AS '.',
isnull( FPlanUnderDeliveryTolerance, '' ) AS '.',
isnull( FPlanOverDeliveryTolerance, '' ) AS '.',
isnull( FPlanDeliverCompany, '' ) AS '.',
isnull( FPlanDeliverCompanyCount, '' ) AS '.',
isnull( FPlanBaseCompanyCount, '' ) AS '.',
isnull( FQualityType1, '' ) AS '.1',
isnull( FQualityType2, '' ) AS '.2',
isnull( FQualityType3, '' ) AS '.3',
isnull( FQualityType4, '' ) AS '.4',
isnull( FQualityType5, '' ) AS '.5',
isnull( FQualityType6, '' ) AS '.6',
isnull( FAccountPriceControl, '' ) AS '.',
isnull( FAccountPriceDetermine, '' ) AS '.',
isnull( FAccountPriceUnit, '' ) AS '.',
isnull( FAccountAccessType, '' ) AS '.',
isnull( FAccountSaleOrderInventory, '' ) AS '.VC: ',
isnull( FAccountStandardPrice, '' ) AS '.',
isnull( FAccountProfitCenter, '' ) AS '.',
isnull( FAccountCostAccountBatch, '' ) AS '.'
FROM(
SELECT
isnull( b.FName, '' ) AS 'FTypeName1',
isnull( c.FName, '' ) AS 'FTypeName2',
isnull( FSAPCode, '' ) AS 'FCode',
isnull( FSAPDescription, '' ) AS 'FName',
isnull( FBaseMaterialDesc, '' ) AS 'FDesc',
isnull( FBaseMaterialDesc, '' ) AS 'FVersionCode',
isnull( FBaseMaterialDesc, '' ) AS 'FFactoryCode',
isnull( FBaseMaterialDesc, '' ) AS 'FSupplyCode',
isnull( FBaseMaterialGroup, '' ) AS 'FGroupCode',
isnull( FBaseWeightUnit, '' ) AS 'FBaseUnit',
isnull( FCraftExplain, '' ) AS 'FCraftDesc',
d.FName AS 'FtypeName',
a.*
FROM
TFS_MaterialInfo AS a
LEFT JOIN TFS_MaterialType AS d ON a.FType=d.FID
LEFT JOIN TFS_MaterialType AS b ON a.FTypeID1= b.FID
LEFT JOIN TFS_MaterialType AS C ON a.FTypeID2= b.FID
)a;");
DataTable data = db.Ado.GetDataTable(strSql);
return data;
}
/// <summary>
/// DataTable转List
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dt"></param>
/// <returns></returns>
public static List<T> TableToListModel<T>(DataTable dt) where T : new()
{
// 定义集合
List<T> ts = new List<T>();
// 获得此模型的类型
Type type = typeof(T);
string tempName = "";
foreach (DataRow dr in dt.Rows)
{
T t = new T();
// 获得此模型的公共属性
PropertyInfo[] propertys = t.GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
{
tempName = pi.Name; // 检查DataTable是否包含此列
if (dt.Columns.Contains(tempName))
{
// 判断此属性是否有Setter
if (!pi.CanWrite) continue;
object value = dr[tempName];
if (value != DBNull.Value)
pi.SetValue(t, value, null);
}
}
ts.Add(t);
}
return ts;
}
public int ExecSql(string sql)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
return db.Ado.ExecuteCommand(sql);
}
public List<TFS_Material> GetMaterialByFName(string fname)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
List<TFS_Material> mainsList = db.Queryable<TFS_Material>().Where(s => s.FDeleted != (int)Constant.DeleteCode. && s.FName.Equals(fname)).ToList();
return mainsList;
}
public int InsertMaterial(TFS_Material material)
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
return db.Insertable(material).IgnoreColumns(true).ExecuteReturnIdentity();
}
3 years ago
public List<TFS_MaterialInfo> GetMaterialInfoList()
{
SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
return db.Queryable<TFS_MaterialInfo>().Where(s => s.FType == 1).ToList();
}
}
}