chore: 初始化合力驱动桥MES采集程序
This commit is contained in:
25
MisDataFunDll/MisDataFunDll.sln
Normal file
25
MisDataFunDll/MisDataFunDll.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.32901.82
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MisDataFunDll", "MisDataFunDll\MisDataFunDll.csproj", "{A0DE975B-3AFC-4F39-920E-29A874480A36}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A0DE975B-3AFC-4F39-920E-29A874480A36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A0DE975B-3AFC-4F39-920E-29A874480A36}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A0DE975B-3AFC-4F39-920E-29A874480A36}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A0DE975B-3AFC-4F39-920E-29A874480A36}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7A06AC19-C5B2-4DD8-821B-5996EC8AF877}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
91
MisDataFunDll/MisDataFunDll/13.4MisDataFunction.csproj
Normal file
91
MisDataFunDll/MisDataFunDll/13.4MisDataFunction.csproj
Normal file
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{A0DE975B-3AFC-4F39-920E-29A874480A36}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>MisDataFunDll</RootNamespace>
|
||||
<AssemblyName>MisDataFunDll</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MQTTnet">
|
||||
<HintPath>..\..\Common\dll\MQTTnet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MQTTnet.Extensions.ManagedClient">
|
||||
<HintPath>..\..\Common\dll\MQTTnet.Extensions.ManagedClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MisDataFun.MES.cs" />
|
||||
<Compile Include="MisDataFun.MES.New.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Reflection.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Common\00-1Json8.3\Json8.3\00-0Json8.3.1.csproj">
|
||||
<Project>{1a10fdb2-1a6a-44a8-ab4d-33387563247e}</Project>
|
||||
<Name>00-0Json8.3.1</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Common\00MesWorkMqtt\MesWorkMqtt\00MesWorkMqtt.csproj">
|
||||
<Project>{f55da1a0-a982-4479-8c47-0d9a5aaf3e18}</Project>
|
||||
<Name>00MesWorkMqtt</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Common\01DoWhatPlc\01_01DoWhatPlc.csproj">
|
||||
<Project>{0d1af432-439a-4920-8692-43ae139f5530}</Project>
|
||||
<Name>01_01DoWhatPlc</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Common\04DataBaseAccess\DataBaseAccess\04-DataBaseAccess.csproj">
|
||||
<Project>{f434e066-4c59-47c8-aa82-6f48cc84501a}</Project>
|
||||
<Name>04-DataBaseAccess</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Common\07WebBusinessFacade\BusinessFacade\07BusinessFacade.csproj">
|
||||
<Project>{f0a0c525-03fd-428a-9b17-7f54aa0e4475}</Project>
|
||||
<Name>07BusinessFacade</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Common\08WebFun_base\WebFun_base\08-WebFun_base.csproj">
|
||||
<Project>{d98be764-adeb-488d-9714-61e308aa8201}</Project>
|
||||
<Name>08-WebFun_base</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Common\09MesDataFunction\MesDataFunction\09-MesDataFunction.csproj">
|
||||
<Project>{90e76fb4-646d-45e2-95db-0b8ab4e465d6}</Project>
|
||||
<Name>09-MesDataFunction</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\MIS_FuntionSaveData\MIS_FuntionSaveData\13.3MIS_FuntionSaveData.csproj">
|
||||
<Project>{55b510c1-59e9-4bfd-ae84-d76d46f6e365}</Project>
|
||||
<Name>13.3MIS_FuntionSaveData</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
161
MisDataFunDll/MisDataFunDll/MisDataFun.MES.New.cs
Normal file
161
MisDataFunDll/MisDataFunDll/MisDataFun.MES.New.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace MisDataFunDll
|
||||
{
|
||||
public partial class MisDataFun
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存质量数据和过站信息
|
||||
/// 处理function
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
public static void TransferInfToMES_WebSubmit(object text)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
string recData = text.ToString();
|
||||
List<string> dataArray = DoWhatPlc.MessageText.GetCmdStringList(recData);
|
||||
|
||||
//string[] dataArray = recData.Split('|');
|
||||
if (dataArray.Count != 4)
|
||||
return;
|
||||
//消息来源
|
||||
string m_Source = dataArray[0].ToString();
|
||||
//消息类型 Barcode
|
||||
string m_Command = dataArray[1].ToString();
|
||||
//工位号
|
||||
string m_OpName = dataArray[2].ToString();
|
||||
//消息参数
|
||||
string m_Value = dataArray[3].ToString();
|
||||
|
||||
//if (!m_WorkStart_OpName.ContainsKey(m_OpName)) return; //当前系统是否存在该工位
|
||||
|
||||
switch (m_Source)
|
||||
{
|
||||
case "BarCode":
|
||||
//处理条码逻辑
|
||||
if (m_Command == "Bar")
|
||||
{
|
||||
MesServerFunction(recData);
|
||||
}
|
||||
break;
|
||||
case "WEB":
|
||||
if (m_Command == "Barcode")
|
||||
{
|
||||
MesServerFunction(recData);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
string Content = m_Command + "|" + m_Value;
|
||||
MesServerFunction(recData);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
////ApplicationLog.WriteLog(err, "TransferInf");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void TransferInfToMES(object text)
|
||||
{
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
string recData = text.ToString();
|
||||
List<string> dataArray = DoWhatPlc.MessageText.GetCmdStringList(recData);
|
||||
//string[] dataArray = recData.Split('|');
|
||||
//if (dataArray.Count != 4)
|
||||
//return;
|
||||
//消息来源
|
||||
string m_Source = dataArray[0].ToString();
|
||||
//消息类型 Barcode
|
||||
string m_Command = dataArray[1].ToString();
|
||||
//工位号
|
||||
string m_OpName = dataArray[2].ToString();
|
||||
//消息参数
|
||||
string m_Value = dataArray[3].ToString();
|
||||
|
||||
|
||||
string mesServerdllName;
|
||||
//获得工位对应的 dll
|
||||
if (!GetMesServerDllNameByOpName(out mesServerdllName, m_OpName)) return;
|
||||
if (mesServerdllName == null) return;
|
||||
if (mesServerdllName.Length < 1) return;
|
||||
|
||||
string ResultOK = "";
|
||||
object[] Paramsters = new object[1];
|
||||
Paramsters[0] = text;
|
||||
|
||||
System.Reflection.Assembly assembly = null;
|
||||
|
||||
bool IsOK = Hashtable_assembly.ContainsKey(mesServerdllName);
|
||||
if (IsOK)
|
||||
{
|
||||
assembly = (System.Reflection.Assembly)Hashtable_assembly[mesServerdllName];
|
||||
}
|
||||
else
|
||||
{
|
||||
assembly = System.Reflection.Assembly.Load(mesServerdllName);
|
||||
if (assembly == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Hashtable_assembly.Add(mesServerdllName, assembly);
|
||||
}
|
||||
ResultOK = Reflection.ReflectionMethod(assembly, "MesServerFunctions", "FunctionMES", "FunWork", Paramsters);
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
////ApplicationLog.WriteLog(err, "TransferInf");
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 获得工位对应的 dll
|
||||
/// </summary>
|
||||
/// <param name="mesServerdllName"></param>
|
||||
/// <param name="opName"></param>
|
||||
/// <returns></returns>
|
||||
private static bool GetMesServerDllNameByOpName(out string mesServerdllName, string opName)
|
||||
{
|
||||
try
|
||||
{
|
||||
//HashtableList hsList = DtWebApi.OpcDemo.GetHashtableList();
|
||||
//if(opName == "J07ET055")
|
||||
//{
|
||||
// mesServerdllName = "Function1061";
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
mesServerdllName = hashtable_MesDll[opName].ToString();
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
mesServerdllName = "";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
458
MisDataFunDll/MisDataFunDll/MisDataFun.MES.cs
Normal file
458
MisDataFunDll/MisDataFunDll/MisDataFun.MES.cs
Normal file
@@ -0,0 +1,458 @@
|
||||
using DataLinkMesWork;
|
||||
using DoWhatPlc;
|
||||
using MesServerWork;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MisDataFunDll
|
||||
{
|
||||
public partial class MisDataFun
|
||||
{
|
||||
static object locker = new object();
|
||||
/// <summary>
|
||||
///引用程序集Hashtable
|
||||
/// </summary>
|
||||
public static Hashtable Hashtable_assembly = new Hashtable();
|
||||
public static Hashtable hashtable_MesServerCode = new Hashtable();
|
||||
public static Hashtable hashtable_MesDll = new Hashtable();
|
||||
public static Hashtable hashtable_TagTypeTagName = new Hashtable();
|
||||
public static Hashtable hashtable_TagName = new Hashtable();
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 保存质量数据和过站信息
|
||||
///// 处理function
|
||||
///// </summary>
|
||||
///// <param name="text"></param>
|
||||
//public static void TransferInfToMES_Bak(object text)
|
||||
//{
|
||||
|
||||
|
||||
|
||||
// try
|
||||
// {
|
||||
// //try
|
||||
// //{
|
||||
// // //保存质量数据和过站信息
|
||||
// // MisDataSaveDateMesRead.Funtion.MIS_Funtion(text);
|
||||
// //}
|
||||
// //catch
|
||||
// //{
|
||||
|
||||
// //}
|
||||
// string recData = text.ToString();
|
||||
// List<string> dataArray = DoWhatPlc.MessageText.GetCmdStringList(recData);
|
||||
// //string[] dataArray = recData.Split('|');
|
||||
// //if (dataArray.Count != 4)
|
||||
// //return;
|
||||
// //消息来源
|
||||
// string m_Source = dataArray[0].ToString();
|
||||
// //消息类型 Barcode
|
||||
// string m_Command = dataArray[1].ToString();
|
||||
// //工位号
|
||||
// string m_OpName = dataArray[2].ToString();
|
||||
// //消息参数
|
||||
// string m_Value = dataArray[3].ToString();
|
||||
|
||||
// //if (!m_WorkStart_OpName.ContainsKey(m_OpName)) return; //当前系统是否存在该工位
|
||||
|
||||
// switch (m_Source)
|
||||
// {
|
||||
// case "BarCode":
|
||||
// //处理条码逻辑
|
||||
// if (m_Command == "Bar")
|
||||
// {
|
||||
// MesServerFunction(m_OpName, m_Value, "fun_Barcode");
|
||||
// }
|
||||
// break;
|
||||
// //case "WEB":
|
||||
// // if (m_Command == "Barcode")
|
||||
// // {
|
||||
// // MesServerFunction(m_OpName, m_Value, "fun_Barcode");
|
||||
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // string Content = m_Command + "|" + m_Value;
|
||||
// // MesServerFunction(m_OpName, Content, "fun_WebSubmit");
|
||||
|
||||
// // }
|
||||
// // break;
|
||||
// case "PLC":
|
||||
|
||||
// MesServerFunction(m_Value);
|
||||
// break;
|
||||
// }
|
||||
|
||||
// }
|
||||
// catch (Exception err)
|
||||
// {
|
||||
// ////ApplicationLog.WriteLog(err, "TransferInf");
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 保存质量数据和过站信息
|
||||
/// 处理function
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
//public static void TransferInfToMES_WebSubmit(object text)
|
||||
//{
|
||||
|
||||
|
||||
|
||||
// try
|
||||
// {
|
||||
// string recData = text.ToString();
|
||||
// List<string> dataArray = DoWhatPlc.MessageText.GetCmdStringList(recData);
|
||||
|
||||
// //string[] dataArray = recData.Split('|');
|
||||
// if (dataArray.Count != 4)
|
||||
// return;
|
||||
// //消息来源
|
||||
// string m_Source = dataArray[0].ToString();
|
||||
// //消息类型 Barcode
|
||||
// string m_Command = dataArray[1].ToString();
|
||||
// //工位号
|
||||
// string m_OpName = dataArray[2].ToString();
|
||||
// //消息参数
|
||||
// string m_Value = dataArray[3].ToString();
|
||||
|
||||
// //if (!m_WorkStart_OpName.ContainsKey(m_OpName)) return; //当前系统是否存在该工位
|
||||
|
||||
// switch (m_Source)
|
||||
// {
|
||||
// //case "BarCode":
|
||||
// // //处理条码逻辑
|
||||
// // if (m_Command == "Bar")
|
||||
// // {
|
||||
// // MesServerFunction(m_OpName, m_Value, "fun_Barcode");
|
||||
// // }
|
||||
// // break;
|
||||
// case "WEB":
|
||||
// if (m_Command == "Barcode")
|
||||
// {
|
||||
// MesServerFunction(m_OpName, m_Value, "fun_Barcode");
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// string Content = m_Command + "|" + m_Value;
|
||||
// MesServerFunction(m_OpName, Content, "fun_WebSubmit");
|
||||
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
|
||||
// }
|
||||
// catch (Exception err)
|
||||
// {
|
||||
// ////ApplicationLog.WriteLog(err, "TransferInf");
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// MesServerFunction
|
||||
///// </summary>
|
||||
///// <param name="OpName"></param>
|
||||
///// <param name="tagValue"></param>
|
||||
///// <param name="fun"></param>
|
||||
//private static void MesServerFunction(string OpName, object tagValue, string fun)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
|
||||
// CustomeEvetnArgs e = new CustomeEvetnArgs();
|
||||
|
||||
// string ResultOK = "";
|
||||
// string mesServerCode;
|
||||
// //mesServerCode = GetMesServerCodeByOpName(OpName);
|
||||
// string mesServerdllName;
|
||||
// //mesServerdllName = GetMesServeDllByOpName(OpName);
|
||||
// // TagType
|
||||
// if (!GetMesServerCodeByOpName(out mesServerdllName, out mesServerCode, OpName)) return;
|
||||
// if (mesServerdllName == null) return;
|
||||
// if (mesServerdllName.Length < 1) return;
|
||||
// e.OpName = OpName;
|
||||
// e.TagValue = tagValue;
|
||||
// switch (fun)
|
||||
// {
|
||||
// case "fun_Barcode":
|
||||
// e.TagTypeCodeID = "Barcode";
|
||||
// break;
|
||||
// case "fun_WebSubmit":
|
||||
// e.TagTypeCodeID = "WebSubmit";
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
// object[] Paramsters = new object[1];
|
||||
// Paramsters[0] = e;
|
||||
|
||||
// System.Reflection.Assembly assembly;
|
||||
|
||||
// //自动工位不调用function
|
||||
// //if (mesServerCode == "00")
|
||||
// //{
|
||||
// // return;
|
||||
// //}
|
||||
// bool IsOK = false;
|
||||
|
||||
// {
|
||||
// IsOK = Hashtable_assembly.ContainsKey(mesServerdllName);
|
||||
// }
|
||||
// if (IsOK)
|
||||
// {
|
||||
// assembly = (System.Reflection.Assembly)Hashtable_assembly[mesServerdllName];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// assembly = System.Reflection.Assembly.Load(mesServerdllName);
|
||||
// if (assembly == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// Hashtable_assembly.Add(mesServerdllName, assembly);
|
||||
// }
|
||||
// if(mesServerCode =="00")
|
||||
// {
|
||||
// fun = "FunWork";
|
||||
// ResultOK = Reflection.ReflectionMethod(assembly, "MesServerFunctions", " FunctionMES", "FunWork", Paramsters);
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ResultOK = Reflection.ReflectionMethod(assembly, "MesServerFunctions", "Functions_BASE_" + mesServerCode, fun, Paramsters);
|
||||
|
||||
// }
|
||||
// if (ResultOK != "ok")
|
||||
// {
|
||||
// // ApplicationLog.WriteLog("ReflectionMethod is Error:" + OpName + fun + ResultOK);
|
||||
// }
|
||||
// }
|
||||
// catch (Exception err)
|
||||
// {
|
||||
// //ApplicationLog.WriteLog(err, "MesServerFunction");
|
||||
// }
|
||||
//}
|
||||
//static bool GetMesServerCodeByOpName(out string mesServerdllName, out string mesServerCode,string opName)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// //HashtableList hsList = DtWebApi.OpcDemo.GetHashtableList();
|
||||
|
||||
// mesServerCode = Convert.ToInt32(hashtable_MesServerCode[opName]).ToString("00");
|
||||
// mesServerdllName = hashtable_MesDll[opName].ToString();
|
||||
// return true;
|
||||
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// mesServerdllName = null;
|
||||
// mesServerCode = null;
|
||||
// opName = null;
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
private static bool GetMesServerCodeByOpName(out string mesServerdllName, out string mesServerCode, out string fun, string opName, string tagType = "1")
|
||||
{
|
||||
try
|
||||
{
|
||||
//HashtableList hsList = DtWebApi.OpcDemo.GetHashtableList();
|
||||
try
|
||||
{
|
||||
mesServerCode = Convert.ToInt32(hashtable_MesServerCode[opName]).ToString("00");
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
mesServerCode = "00";
|
||||
}
|
||||
mesServerdllName = hashtable_MesDll[opName].ToString();
|
||||
fun = "fun_" + hashtable_TagTypeTagName[tagType].ToString();
|
||||
return true;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
mesServerdllName = null;
|
||||
mesServerCode = null;
|
||||
fun = null;
|
||||
opName = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="hashtable_TagName">变量名称对应的变量类型代码</param>
|
||||
/// <param name="hashtable_TagTypeTagName">变量类型代码对应的变量名称</param>
|
||||
public static void GetBaseData_tagTable_TagName(out Hashtable hashtable_TagName, out Hashtable hashtable_TagTypeTagName)
|
||||
{
|
||||
hashtable_TagName = new Hashtable();
|
||||
hashtable_TagTypeTagName = new Hashtable();
|
||||
|
||||
string tagName;
|
||||
string tagTypeCode;
|
||||
DataTable dt;//GetMesServerCodeFromMIS
|
||||
dt = BaseData_tagTable_TagName();
|
||||
if (dt != null)
|
||||
{
|
||||
for (int i = 0; i < dt.Rows.Count; i++)
|
||||
{
|
||||
tagName = dt.Rows[i]["TagName"].ToString();
|
||||
tagTypeCode = dt.Rows[i]["变量类型代码"].ToString();
|
||||
if (!hashtable_TagName.Contains(tagName))
|
||||
{
|
||||
hashtable_TagName.Add(tagName, tagTypeCode);
|
||||
}
|
||||
if (!hashtable_TagTypeTagName.Contains(tagTypeCode))
|
||||
{
|
||||
hashtable_TagTypeTagName.Add(tagTypeCode, tagName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static DataTable BaseData_tagTable_TagName()
|
||||
{
|
||||
DataTable dt = null;
|
||||
string sql;
|
||||
sql = "SELECT distinct[TagName],[变量类型代码] FROM[MES_基本变量_原始数据] ";
|
||||
DataAccess.ExecuteDataTable(sql, out dt);
|
||||
return dt;
|
||||
}
|
||||
public static void GetMesServerCodeAndMesDll(out Hashtable hashtable_MesServerCode, out Hashtable hashtable_MesDll)
|
||||
{
|
||||
hashtable_MesServerCode = new Hashtable();
|
||||
hashtable_MesDll = new Hashtable();
|
||||
|
||||
string OpName;
|
||||
string MesServerCode;
|
||||
string MesDll;
|
||||
DataTable dt;//GetMesServerCodeFromMIS
|
||||
dt = GetMesServerCodeFromMIS();
|
||||
if (dt != null)
|
||||
{
|
||||
for (int i = 0; i < dt.Rows.Count; i++)
|
||||
{
|
||||
OpName = dt.Rows[i]["工位号"].ToString();
|
||||
MesServerCode = dt.Rows[i]["MesServerCode"].ToString();
|
||||
MesDll = dt.Rows[i]["MesDll"].ToString();
|
||||
if (!hashtable_MesDll.Contains(OpName))
|
||||
{
|
||||
hashtable_MesDll.Add(OpName, MesDll);
|
||||
}
|
||||
if (!hashtable_MesServerCode.Contains(OpName))
|
||||
{
|
||||
hashtable_MesServerCode.Add(OpName, MesServerCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static DataTable GetMesServerCodeFromMIS()
|
||||
{
|
||||
DataTable dt;
|
||||
string sql;
|
||||
sql = "exec MES_计划BOM_工位与名称_查询应用程序";
|
||||
DataAccess.ExecuteDataTable(sql, out dt);
|
||||
return dt;
|
||||
}
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// MesServerFunction
|
||||
/// </summary>
|
||||
/// <param name="OpName"></param>
|
||||
/// <param name="tagValue"></param>
|
||||
/// <param name="fun"></param>
|
||||
private static void MesServerFunction(string msgValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool IsOK = false;
|
||||
//lock (locker)
|
||||
{
|
||||
DoWhatPlc.CustomeEvetnArgs e = Newtonsoft.Json.JsonConvert.DeserializeObject<DoWhatPlc.CustomeEvetnArgs>(msgValue);
|
||||
string tagValue;
|
||||
string mesServerCode;
|
||||
string mesServerdllName;
|
||||
string fun;
|
||||
if (!GetMesServerCodeByOpName(out mesServerdllName, out mesServerCode, out fun, e.OpName.ToString(), e.TagTypeCodeID.ToString())) return;
|
||||
if (mesServerdllName == null) return;
|
||||
if (mesServerdllName.Length < 1) return;
|
||||
//if (!GetMesServerCodeByOpName(out mesServerdllName, out mesServerCode, out fun, e.OpName.ToString(), e.TagType.ToString())) return;
|
||||
switch (e.TagValue.ToString().ToLower())
|
||||
{
|
||||
case "false":
|
||||
tagValue = "0";
|
||||
break;
|
||||
case "true":
|
||||
tagValue = "1";
|
||||
break;
|
||||
default:
|
||||
tagValue = e.TagValue.ToString();
|
||||
break;
|
||||
}
|
||||
|
||||
string ResultOK = "";
|
||||
object[] Paramsters = new object[1];
|
||||
Paramsters[0] = e;
|
||||
|
||||
System.Reflection.Assembly assembly = null;
|
||||
|
||||
//自动工位不调用function
|
||||
//if (mesServerCode == "00")
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
IsOK = Hashtable_assembly.ContainsKey(mesServerdllName);
|
||||
if (IsOK)
|
||||
{
|
||||
assembly = (System.Reflection.Assembly)Hashtable_assembly[mesServerdllName];
|
||||
}
|
||||
else
|
||||
{
|
||||
assembly = System.Reflection.Assembly.Load(mesServerdllName);
|
||||
if (assembly == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Hashtable_assembly.Add(mesServerdllName, assembly);
|
||||
}
|
||||
if (mesServerCode == "00")
|
||||
{
|
||||
fun = "FunWork";
|
||||
ResultOK = Reflection.ReflectionMethod(assembly, "MesServerFunctions", "FunctionMES", fun, Paramsters);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ResultOK = Reflection.ReflectionMethod(assembly, "MesServerFunctions", "Functions_BASE_" + mesServerCode, fun, Paramsters);
|
||||
|
||||
}
|
||||
if (ResultOK != "ok")
|
||||
{
|
||||
// //ApplicationLog.WriteLog("ReflectionMethod is Error:" + OpName + fun + ResultOK);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
////ApplicationLog.WriteLog(err, "MesServerFunction");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
301
MisDataFunDll/MisDataFunDll/MisDataFun.MIS_Funtion.cs
Normal file
301
MisDataFunDll/MisDataFunDll/MisDataFun.MIS_Funtion.cs
Normal file
@@ -0,0 +1,301 @@
|
||||
using DoWhatPlc;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MisDataFunDll
|
||||
{
|
||||
public partial class MisDataFun
|
||||
{
|
||||
//public void MIS_Funtion(object e)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// string recData = e.ToString();
|
||||
// string[] dataArray = recData.Split('|');
|
||||
// if (dataArray.Length != 4)
|
||||
// return;
|
||||
// //消息来源
|
||||
// string m_Source = dataArray[0].ToString();
|
||||
// //消息类型
|
||||
// string m_Command = dataArray[1].ToString();
|
||||
// //工位号
|
||||
// string m_OpName = dataArray[2].ToString();
|
||||
// //消息参数
|
||||
// string m_Value = dataArray[3].ToString();
|
||||
|
||||
// DoWhatPlc.ReturnValueString rv = Newtonsoft.Json.JsonConvert.DeserializeObject<DoWhatPlc.ReturnValueString>(m_Value);
|
||||
|
||||
|
||||
// int tagType;
|
||||
// string opName;
|
||||
// string tagValue;
|
||||
// int tagid;
|
||||
// DoWhatPlc.ReturnValueString msgEvent = rv;
|
||||
// if (msgEvent.TagValue == null) return;
|
||||
// tagType = Convert.ToInt32(msgEvent.TagTypeID);
|
||||
// opName = msgEvent.OpName.ToString();
|
||||
// tagid = Convert.ToInt32(msgEvent.TagID);
|
||||
// switch (Convert.ToInt32(msgEvent.TagTypeCodeID))
|
||||
// {
|
||||
// case 11:
|
||||
// switch (msgEvent.TagValue.ToLower())
|
||||
// {
|
||||
// case "1":
|
||||
// case "true":
|
||||
// tagValue = "1";
|
||||
// break;
|
||||
// default:
|
||||
// tagValue = "0";
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// tagValue = msgEvent.TagValue.ToString();
|
||||
// break;
|
||||
// }
|
||||
// ///根据信号处理逻辑
|
||||
// switch (tagType)
|
||||
// {
|
||||
// case 19:
|
||||
// //允许保存
|
||||
// //MesRead(opName, tagValue, tagid);
|
||||
// break;
|
||||
// case 14:
|
||||
// //心跳
|
||||
// //Heartbeat(opName, tagValue);
|
||||
// break;
|
||||
// case 44://PLC传递机型过后 才允许保存过站信息,否则不允许保存
|
||||
// //if (tagValue == "1")
|
||||
// //{
|
||||
// // IsEngTypeGetOver_Write(opName, true);
|
||||
|
||||
// // EngineData Enginedata = new EngineData(MesDataFunction.OpcOperation.ReadPLC(10, opName).ToString(), Convert.ToInt32(MesDataFunction.OpcOperation.ReadPLC(80, opName)));
|
||||
// // //保存产品编号、托盘号 保存过站信息用
|
||||
// // EngineData_Hash_Write(opName, Enginedata);
|
||||
// //}
|
||||
// break;
|
||||
// case 2://工件到位
|
||||
// //WorkStart(opName, tagValue);
|
||||
// break;
|
||||
// case 51:
|
||||
// //if (hashtableOpName_IsHaveComputer[opName].ToString() == "1")
|
||||
// //{
|
||||
// // SaveProductLeaveData(opName, 1);
|
||||
// //}
|
||||
|
||||
// break;
|
||||
// case 8:
|
||||
// //if (hashtableOpName_IsHaveComputer[opName].ToString() == "1")
|
||||
// //{
|
||||
// // SaveProductLeaveData(opName, 2);
|
||||
// //}
|
||||
// break;
|
||||
// }
|
||||
|
||||
// }
|
||||
// catch (Exception err)
|
||||
// {
|
||||
// ////ApplicationLog.WriteLog(err, err.Message);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 获取质量数据Hashtable
|
||||
///// </summary>
|
||||
///// <param name="opName"></param>
|
||||
///// <returns></returns>
|
||||
//static public Hashtable ReadPLC_Sync_DataList_MesRead(string opName)
|
||||
//{
|
||||
// return (Hashtable)MesDataFunction.OpcOperation.ReadPLC_Sync_DataList_MesRead(opName);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 允许保存(针对半自动和手动压装工位)
|
||||
/// </summary>
|
||||
/// <param name="OpName"></param>
|
||||
/// <param name="tagValue"></param>
|
||||
//private void MesRead(string opName, string tagValue, int tagid)
|
||||
//{
|
||||
// if (tagValue == "0")
|
||||
// {
|
||||
// MIS_BASE.Write_TagTypeID(20, opName, false);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SaveQualityData(opName, Convert.ToInt32(tagValue), tagid);
|
||||
// }
|
||||
//}
|
||||
|
||||
//private void SaveQualityData(string opName, int tagValue, int tagID)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// int id_tagCF;
|
||||
// int qualityMask = 0;
|
||||
// int engineTypeID = 0;
|
||||
// string engineID = "";
|
||||
// string engineType = "";
|
||||
// string engineTraceCode = "";
|
||||
// string engineCap = "";
|
||||
// string partPallet = "";
|
||||
// DataTable dt_WWW;
|
||||
// dt_WWW = BaseDataSystemMES.BuildDataTables_WWW();
|
||||
// Hashtable valueList;
|
||||
// Hashtable hashtable_EngineTypeID;
|
||||
// Hashtable hashtable_tagTable_OpName_SaveData;
|
||||
// DataTable BasicDataTagValue;
|
||||
// DataTable BasicDataTagValueUpDown;
|
||||
// ReadPLC_Sync_DataList_MesRead(opName, out valueList ,out BasicDataTagValue,out BasicDataTagValueUpDown,out hashtable_EngineTypeID,out hashtable_tagTable_OpName_SaveData);
|
||||
// valueList = GetQualityData_GoodBad_Values(valueList);
|
||||
// int mes_MustTest = 0;
|
||||
// int onLineState = 0;
|
||||
// int partMoveDirection = 0;
|
||||
// int pressIsOK = 0;
|
||||
// int pressIsNoOK = 0;
|
||||
// BaseDataSystemMES.GetQualityDataTable_B5A(valueList, opName, BasicDataTagValue,
|
||||
// BasicDataTagValueUpDown,
|
||||
// out dt_WWW,//数据列表
|
||||
// out qualityMask,//工位合格标志
|
||||
// out engineTypeID,//发动机类型代码
|
||||
// out engineID,//发动机编号
|
||||
// out engineType, //发动机型号
|
||||
// out partPallet,//托盘编号
|
||||
// out engineTraceCode, //发动机条码
|
||||
// out engineCap,//缸盖号,
|
||||
// hashtable_EngineTypeID,//发动机类型转换表
|
||||
// out mes_MustTest, out onLineState, out partMoveDirection, out pressIsOK, out pressIsNoOK);
|
||||
|
||||
// // 1:通过监控系统保存采集的质量数据;0:不通过监控系统保存采集的质量数据
|
||||
// if (Convert.ToInt32(hashtable_tagTable_OpName_SaveData[opName]) != 0)
|
||||
// {
|
||||
// DateTime lastupdatetime = DateTime.Now;
|
||||
|
||||
// BaseDataSystemMES.BaseData_tagTable_QualityData_B5A_IndexInsert(engineID, tagID, engineType, engineTypeID, opName, qualityMask, partPallet, out id_tagCF);
|
||||
// BaseDataSystemMES.BaseData_tagTable_QualityData_B5A_Insert(id_tagCF, engineTypeID, engineID, opName, dt_WWW);
|
||||
|
||||
// }
|
||||
// MIS_BASE.Write_TagTypeID(20, opName, true);
|
||||
|
||||
// }
|
||||
// catch (Exception err)
|
||||
// {
|
||||
// MIS_BASE.Write_TagTypeID(20, opName, true);
|
||||
// ////ApplicationLog.WriteLog(err, err.Message);
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 确定合格标志
|
||||
/// </summary>
|
||||
/// <param name="valuList"></param>
|
||||
/// <returns></returns>
|
||||
//public Hashtable GetQualityData_GoodBad_Values(Hashtable valuList)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// Hashtable valuList_Temp;
|
||||
// valuList_Temp = (Hashtable)valuList.Clone();
|
||||
// int[] value_GoodBad_New = new int[128];
|
||||
// int tagID;
|
||||
// QualityDataType value;
|
||||
// //1:获得合格标志
|
||||
// foreach (DictionaryEntry de in valuList) //ht为一个Hashtable实例
|
||||
// {
|
||||
// tagID = Convert.ToInt32(de.Key);
|
||||
// value = (QualityDataType)de.Value;
|
||||
|
||||
// //拧紧数据合格标志
|
||||
// if (value.tagProperty == 1)
|
||||
// {
|
||||
// if (value.tagTypeID == 8203)
|
||||
// {
|
||||
// value_GoodBad_New = (int[])value.tagValue;
|
||||
// break;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// value_GoodBad_New[value.tagOrderBy - 1] = Convert.ToInt32(value.tagValue);
|
||||
// }
|
||||
// }
|
||||
// //拧紧数据合格标志
|
||||
// if (value.tagProperty == 8)
|
||||
// {
|
||||
// if (value.tagTypeID == 8203)
|
||||
// {
|
||||
// value_GoodBad_New = (int[])value.tagValue;
|
||||
// break;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// value_GoodBad_New[value.tagOrderBy - 1] = Convert.ToInt32(value.tagValue);
|
||||
// }
|
||||
// }
|
||||
// //压装数据合格标志
|
||||
// if (value.tagProperty == 7)
|
||||
// {
|
||||
// value_GoodBad_New[value.tagOrderBy - 1] = Convert.ToInt32(value.tagValue);
|
||||
// }
|
||||
// }
|
||||
// //将合格标志赋予每个变量
|
||||
// foreach (DictionaryEntry de in valuList) //ht为一个Hashtable实例
|
||||
// {
|
||||
// tagID = Convert.ToInt32(de.Key);
|
||||
// value = (QualityDataType)de.Value;
|
||||
// //201706061720新加
|
||||
// if (value.tagTypeID == 11)
|
||||
// {
|
||||
// if (value.tagValue.ToString() == "False")
|
||||
// {
|
||||
// value.tagValue = "0";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// value.tagValue = "1";
|
||||
// }
|
||||
// valuList_Temp[tagID] = value;
|
||||
// //value.tagValue = Convert.ToInt32(value.tagValue);
|
||||
// }
|
||||
|
||||
|
||||
// //测量变量
|
||||
// if (value.tagProperty == 2 || value.tagProperty == 6)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (value_GoodBad_New != null)
|
||||
// {
|
||||
// value.isGoodBad = Convert.ToInt32(value_GoodBad_New[value.tagOrderBy - 1]);
|
||||
// valuList_Temp[tagID] = value;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// value.isGoodBad = 0;
|
||||
// valuList_Temp[tagID] = value;
|
||||
// }
|
||||
// }
|
||||
// catch (Exception err)
|
||||
// {
|
||||
// ////ApplicationLog.WriteLog(err, err.Message);
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// }
|
||||
// return valuList_Temp;
|
||||
// }
|
||||
// catch//转换出了故障时
|
||||
// {
|
||||
// return valuList;
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
36
MisDataFunDll/MisDataFunDll/Properties/AssemblyInfo.cs
Normal file
36
MisDataFunDll/MisDataFunDll/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("MisDataFunDll")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("MisDataFunDll")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("a0de975b-3afc-4f39-920e-29a874480a36")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
94
MisDataFunDll/MisDataFunDll/Reflection.cs
Normal file
94
MisDataFunDll/MisDataFunDll/Reflection.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace MisDataFunDll
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class Reflection
|
||||
{
|
||||
/// <summary>
|
||||
/// 通过反射调用动态连接库方法
|
||||
/// </summary>
|
||||
/// <param name="assembly">程序集(DLL)</param>
|
||||
/// <param name="Namespace">命名空间名称,如果无命名空间写“”</param>
|
||||
/// <param name="Classname">类名</param>
|
||||
/// <param name="Method">方法名</param>
|
||||
/// <param name="Paramsters">函数参数数组</param>
|
||||
static public string ReflectionMethod(Assembly assembly, string Namespace, string Classname, string Method, object[] Paramsters)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Type t;
|
||||
//类
|
||||
if (Namespace == "")
|
||||
{
|
||||
t = assembly.GetType(Classname);
|
||||
}
|
||||
else
|
||||
{
|
||||
t = assembly.GetType(Namespace + "." + Classname);
|
||||
}
|
||||
if (t == null)
|
||||
{
|
||||
return "类不存在";
|
||||
}
|
||||
////方法
|
||||
MethodInfo mi = t.GetMethod(Method); //获取方法
|
||||
if (mi == null)
|
||||
{
|
||||
return "方法不存在";
|
||||
}
|
||||
ParameterInfo[] paramsInfo = mi.GetParameters();
|
||||
for (int i = 0; i < paramsInfo.Length; i++)
|
||||
{
|
||||
Type tType = paramsInfo[i].ParameterType;
|
||||
//改变参数类型
|
||||
Paramsters[i]= SD_ChanageType(Paramsters[i],tType);
|
||||
}
|
||||
/// 建一个实例化的类
|
||||
object instanceObject = Activator.CreateInstance(t);
|
||||
mi.Invoke(instanceObject, Paramsters);
|
||||
return "ok";
|
||||
}
|
||||
catch(Exception err)
|
||||
{
|
||||
return err.ToString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="convertsionType"></param>
|
||||
/// <returns></returns>
|
||||
public static object SD_ChanageType(object value, Type convertsionType)
|
||||
{
|
||||
//判断convertsionType类型是否为泛型,因为nullable是泛型类,
|
||||
if (convertsionType.IsGenericType &&
|
||||
//判断convertsionType是否为nullable泛型类
|
||||
convertsionType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
|
||||
{
|
||||
if (value == null || value.ToString().Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//如果convertsionType为nullable类,声明一个NullableConverter类,该类提供从Nullable类到基础基元类型的转换
|
||||
NullableConverter nullableConverter = new NullableConverter(convertsionType);
|
||||
//将convertsionType转换为nullable对的基础基元类型
|
||||
convertsionType = nullableConverter.UnderlyingType;
|
||||
}
|
||||
return Convert.ChangeType(value, convertsionType);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user