天津投入产出系统后端
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.
 
 
 
 
 
 

409 lines
17 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.FIS;
using System.Data;
namespace QMAPP.FJC.DAL.FIS
{
public class FISPhraseDAL : BaseDAL
{
public string GetMESModulCode(string codeprefix, string positioncode)
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT MAX(MESModul" + positioncode + ") ");
sql.AppendLine(" FROM T_FIS_ASSEMBLY ");
sql.AppendLine(" WHERE AsmSetCode=@codeprefix ");
sql.AppendLine(" AND Active='1' ");
sql.AppendLine(" AND IsDeleted='0' ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
List<DataParameter> parameters = new List<DataParameter>();
parameters.Add(new DataParameter { ParameterName = "codeprefix", Value = codeprefix });
var MESModul= session.ExecuteSqlScalar(sql.ToString(),parameters.ToArray());
if (MESModul != null)
{
return MESModul.ToString();
}
return "";
}
}
public FISPhraseBook GetFisPhraseBook(string assymaterialcode, string positioncode)
{
string OptionColumn = "OptionDesc1";
string ModulColumn = "MESModulFL";
switch (positioncode)
{
case "LF":
case "FL":
{
OptionColumn = "OptionDesc1";
ModulColumn = "MESModulFL";
break;
}
case "RF":
case "FR":
{
OptionColumn = "OptionDesc2";
ModulColumn = "MESModulFR";
break;
}
case "LR":
case "RL":
{
OptionColumn = "OptionDesc3";
ModulColumn = "MESModulRL";
break;
}
case "RR":
{
OptionColumn = "OptionDesc4";
ModulColumn = "MESModulRR";
break;
}
}
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT A.Name");
sql.AppendLine(" ,B.Text");
sql.AppendLine(" ,B.Class");
sql.AppendLine(" ,A.CarModel");
sql.AppendLine(" FROM T_FIS_ASSEMBLY AS A");
sql.AppendLine(" LEFT JOIN T_FIS_PHRASEBOOK AS B");
sql.AppendLine(" ON A." + OptionColumn + "=B.Code");
sql.AppendLine(" WHERE "+ModulColumn+" =@assymaterialcode");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
List<DataParameter> parameters = new List<DataParameter>();
parameters.Add(new DataParameter { ParameterName = "assymaterialcode", Value = assymaterialcode });
return session.Get<FISPhraseBook>(sql.ToString(), parameters.ToArray());
}
}
public FISPhraseBook GetPHRASEBOOK(string Code,string Class)
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT Text ");
sql.AppendLine("FROM T_FIS_PHRASEBOOK ");
sql.AppendLine($"WHERE Code = '{Code}' ");
if (!string.IsNullOrEmpty(Class))
{
sql.AppendLine($"and Class = '{Class}' ");
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
List<DataParameter> parameters = new List<DataParameter>();
return session.Get<FISPhraseBook>(sql.ToString(), parameters.ToArray());
}
}
public List<FISAssembly> GetAssemblyList(FISAssembly condation)
{
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT FA.Id ");
sql.AppendLine(" ,FA.Name ");
sql.AppendLine(" ,FA.[Description] ");
sql.AppendLine(" ,FA.AsmSetCode ");
sql.AppendLine(" ,FA.ProjectCode ");
sql.AppendLine(" ,FA.CarModel ");
sql.AppendLine(" ,FA.Active ");
sql.AppendLine(" ,FA.IsDeleted ");
sql.AppendLine(" ,FA.MESModulFL ");
sql.AppendLine(" ,FLM.MATERIAL_NAME AS [MESModulFL_NAME] ");
sql.AppendLine(" ,FA.MESModulFR ");
sql.AppendLine(" ,FRM.MATERIAL_NAME AS [MESModulFR_NAME] ");
sql.AppendLine(" ,FA.MESModulRL ");
sql.AppendLine(" ,RLM.MATERIAL_NAME AS [MESModulRL_NAME] ");
sql.AppendLine(" ,FA.MESModulRR ");
sql.AppendLine(" ,RRM.MATERIAL_NAME AS [MESModulRR_NAME] ");
sql.AppendLine(" FROM T_FIS_ASSEMBLY AS FA ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS FLM ");
sql.AppendLine(" ON FLM.MATERIAL_CODE=FA.MESModulFL ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS FRM ");
sql.AppendLine(" ON FRM.MATERIAL_CODE=FA.MESModulFR ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS RLM ");
sql.AppendLine(" ON RLM.MATERIAL_CODE=FA.MESModulRL ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS RRM ");
sql.AppendLine(" ON RRM.MATERIAL_CODE=FA.MESModulRR ");
sql.AppendLine(" WHERE 1=1 ");
if (!string.IsNullOrWhiteSpace(condation.AsmSetCode))
{
sql.AppendLine(string.Format("AND FA.AsmSetCode LIKE '{0}%'", condation.AsmSetCode));
}
if (!string.IsNullOrWhiteSpace(condation.ProjectCode))
{
sql.AppendLine(string.Format("AND FA.ProjectCode LIKE '{0}%'", condation.ProjectCode));
}
if (!string.IsNullOrWhiteSpace(condation.CarModel))
{
sql.AppendLine(string.Format("AND FA.CarModel LIKE '{0}%'", condation.CarModel));
}
//sql.AppendLine(" AND Active='1' ");
//sql.AppendLine(" AND IsDeleted='0' ");
sql.AppendLine(" ORDER BY Id ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<FISAssembly>(sql.ToString(), parameters.ToArray()).ToList();
}
}
public FISAssembly GetAssembly(FISAssembly condation)
{
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT TOP 1 FA.Id ");
sql.AppendLine(" ,FA.Name ");
sql.AppendLine(" ,FA.[Description] ");
sql.AppendLine(" ,FA.AsmSetCode ");
sql.AppendLine(" ,FA.ProjectCode ");
sql.AppendLine(" ,FA.CarModel ");
sql.AppendLine(" ,FA.Active ");
sql.AppendLine(" ,FA.IsDeleted ");
sql.AppendLine(" ,FA.MESModulFL ");
sql.AppendLine(" ,FLM.MATERIAL_NAME AS [MESModulFL_NAME] ");
sql.AppendLine(" ,FA.MESModulFR ");
sql.AppendLine(" ,FRM.MATERIAL_NAME AS [MESModulFR_NAME] ");
sql.AppendLine(" ,FA.MESModulRL ");
sql.AppendLine(" ,RLM.MATERIAL_NAME AS [MESModulRL_NAME] ");
sql.AppendLine(" ,FA.MESModulRR ");
sql.AppendLine(" ,RRM.MATERIAL_NAME AS [MESModulRR_NAME] ");
sql.AppendLine(" FROM T_FIS_ASSEMBLY AS FA ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS FLM ");
sql.AppendLine(" ON FLM.MATERIAL_CODE=FA.MESModulFL ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS FRM ");
sql.AppendLine(" ON FRM.MATERIAL_CODE=FA.MESModulFR ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS RLM ");
sql.AppendLine(" ON RLM.MATERIAL_CODE=FA.MESModulRL ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS RRM ");
sql.AppendLine(" ON RRM.MATERIAL_CODE=FA.MESModulRR ");
sql.AppendLine(" WHERE 1=1 ");
if (!string.IsNullOrWhiteSpace(condation.Id))
{
sql.AppendLine("AND FA.Id =@fId");
parameters.Add(new DataParameter("fId",condation.Id));
}
if (!string.IsNullOrWhiteSpace(condation.AsmSetCode))
{
sql.AppendLine(string.Format("AND FA.AsmSetCode LIKE '{0}%'", condation.AsmSetCode));
}
if (!string.IsNullOrWhiteSpace(condation.ProjectCode))
{
sql.AppendLine(string.Format("AND FA.ProjectCode LIKE '{0}%'", condation.ProjectCode));
}
if (!string.IsNullOrWhiteSpace(condation.CarModel))
{
sql.AppendLine(string.Format("AND FA.CarModel LIKE '{0}%'", condation.CarModel));
}
//sql.AppendLine(" AND Active='1' ");
//sql.AppendLine(" AND IsDeleted='0' ");
sql.AppendLine(" ORDER BY Id ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<FISAssembly>(sql.ToString(), parameters.ToArray());
}
}
public int UpdateAssembly(FISAssembly Entity)
{
List<DataParameter> parameters = new List<DataParameter>();
StringBuilder sql = new StringBuilder();
sql.AppendLine("UPDATE T_FIS_ASSEMBLY ");
sql.AppendLine(" SET MESModulFL=@MESModulFL ");
sql.AppendLine(" ,MESModulFR=@MESModulFR ");
sql.AppendLine(" ,MESModulRL=@MESModulRL ");
sql.AppendLine(" ,MESModulRR=@MESModulRR ");
sql.AppendLine(" WHERE Id=@fId ");
parameters.Add(new DataParameter("fId", Entity.Id));
parameters.Add(new DataParameter("MESModulFL", Entity.MESModulFL));
parameters.Add(new DataParameter("MESModulFR", Entity.MESModulFR));
parameters.Add(new DataParameter("MESModulRL", Entity.MESModulRL));
parameters.Add(new DataParameter("MESModulRR", Entity.MESModulRR));
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.ExecuteSql(sql.ToString(), parameters.ToArray());
}
}
public int AssemblySync()
{
StringBuilder sqlmes = new StringBuilder();
sqlmes.AppendLine("SELECT * FROM [T_FIS_ASSEMBLY] ");
StringBuilder sqlfis = new StringBuilder();
sqlfis.AppendLine("SELECT [Id] ");
sqlfis.AppendLine(" ,[Name] ");
sqlfis.AppendLine(" ,[Description] ");
sqlfis.AppendLine(" ,[CarModel] ");
sqlfis.AppendLine(" ,[ProjectCode] ");
sqlfis.AppendLine(" ,[BaseSet] ");
sqlfis.AppendLine(" ,[Color] ");
sqlfis.AppendLine(" ,[Cover] ");
sqlfis.AppendLine(" ,[SetOption] ");
sqlfis.AppendLine(" ,[OptionDesc1] ");
sqlfis.AppendLine(" ,[OptionDesc2] ");
sqlfis.AppendLine(" ,[OptionDesc3] ");
sqlfis.AppendLine(" ,[OptionDesc4] ");
sqlfis.AppendLine(" ,[OptionDesc5] ");
sqlfis.AppendLine(" ,[AsmSetCode] ");
sqlfis.AppendLine(" ,[Active] ");
sqlfis.AppendLine(" ,[LegendColor] ");
sqlfis.AppendLine(" ,[LegendText] ");
sqlfis.AppendLine(" ,[ContractNo] ");
sqlfis.AppendLine(" ,[IsDeleted] ");
sqlfis.AppendLine(" FROM [Assembly] ");
List<DataParameter> parameters = new List<DataParameter>();
try
{
DataTable tbSourceAssembly = null;
using (IDataSession sessionfis = AppDataFactory.CreateSession("CDDPFISDB"))
{
tbSourceAssembly = sessionfis.GetTableWithSchema(sqlfis.ToString(), "Assembly", parameters.ToArray());
}
if (tbSourceAssembly != null && tbSourceAssembly.Rows.Count > 0)
{
using (IDataSession sessionmes = AppDataFactory.CreateMainSession())
{
var tbAssembly = sessionmes.GetTableWithSchema(sqlmes.ToString(), "T_FIS_ASSEMBLY", parameters.ToArray());
if (tbAssembly != null)
{
DataTableSync("Id",tbSourceAssembly, tbAssembly);
sessionmes.UpdateTable(tbAssembly);
}
}
}
return 0;
}
catch(Exception ex)
{
throw ex;
}
}
public int AssemblyModuleSync()
{
StringBuilder sqlmes = new StringBuilder();
sqlmes.AppendLine("SELECT * FROM [T_FIS_ASSEMBLYMODULE] ");
StringBuilder sqlfis = new StringBuilder();
sqlfis.AppendLine("SELECT * FROM [AssemblyModule] ");
List<DataParameter> parameters = new List<DataParameter>();
try
{
DataTable tbSource = null;
using (IDataSession sessionfis = AppDataFactory.CreateSession("CDDPFISDB"))
{
tbSource = sessionfis.GetTableWithSchema(sqlfis.ToString(), "AssemblyModule", parameters.ToArray());
}
if (tbSource != null && tbSource.Rows.Count > 0)
{
using (IDataSession sessionmes = AppDataFactory.CreateMainSession())
{
var tbTarget = sessionmes.GetTableWithSchema(sqlmes.ToString(), "T_FIS_ASSEMBLYMODULE", parameters.ToArray());
if (tbTarget != null)
{
DataTableSync("Id", tbSource, tbTarget);
sessionmes.UpdateTable(tbTarget);
}
}
}
return 0;
}
catch (Exception ex)
{
throw ex;
}
}
public int PhraseBookSync()
{
StringBuilder sqlmes = new StringBuilder();
sqlmes.AppendLine("SELECT * FROM [T_FIS_PHRASEBOOK] ");
StringBuilder sqlfis = new StringBuilder();
sqlfis.AppendLine("SELECT * FROM [PhraseBook] ");
List<DataParameter> parameters = new List<DataParameter>();
try
{
DataTable tbSource = null;
using (IDataSession sessionfis = AppDataFactory.CreateSession("CDDPFISDB"))
{
tbSource = sessionfis.GetTableWithSchema(sqlfis.ToString(), "PhraseBook", parameters.ToArray());
}
if (tbSource != null && tbSource.Rows.Count > 0)
{
using (IDataSession sessionmes = AppDataFactory.CreateMainSession())
{
var tbTarget = sessionmes.GetTableWithSchema(sqlmes.ToString(), "T_FIS_PHRASEBOOK", parameters.ToArray());
if (tbTarget != null)
{
DataTableSync("Id", tbSource, tbTarget);
sessionmes.UpdateTable(tbTarget);
}
}
}
return 0;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 从源数据表同步数据到目标表
/// 目标表需要原表具有相同的主键,并且包含源数据表的全部字段
/// </summary>
/// <param name="keyname">主键名</param>
/// <param name="tbSource">源数据表</param>
/// <param name="tbTarget">目标表</param>
private static void DataTableSync(string keyname,DataTable tbSource, DataTable tbTarget)
{
foreach (DataRow row in tbTarget.Rows)
{
DataRow sourcerow = tbSource.Rows.Find(row[keyname]);
if (sourcerow != null)
{
foreach (DataColumn column in tbSource.Columns)
{
if (!row[column.ColumnName].Equals(sourcerow[column.ColumnName]))
{
row[column.ColumnName] = sourcerow[column.ColumnName];
}
}
}
else
{
row.Delete();
}
}
var newrow = from DataRow row in tbSource.Rows
where !tbTarget.Rows.Contains(row[keyname])
select row;
foreach (var n in newrow)
{
var row = tbTarget.NewRow();
foreach (DataColumn c in tbSource.Columns)
{
row[c.ColumnName] = n[c.ColumnName];
}
tbTarget.Rows.Add(row);
}
}
}
}