xuwei 3 lat temu
rodzic
commit
53354816b1

+ 1 - 0
.gitignore

@@ -108,3 +108,4 @@ _UpgradeReport_Files/
 Backup*/
 UpgradeLog*.XML
 
+/.vs

+ 31 - 0
DK.XuWei.WebMes.sln

@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.33423.256
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DK.XuWei.WebMes", "DK.XuWei.WebMes\DK.XuWei.WebMes.csproj", "{D942649F-F369-4105-8745-0726232919E5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Debug|x86 = Debug|x86
+		Release|Any CPU = Release|Any CPU
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{D942649F-F369-4105-8745-0726232919E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D942649F-F369-4105-8745-0726232919E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D942649F-F369-4105-8745-0726232919E5}.Debug|x86.ActiveCfg = Debug|x86
+		{D942649F-F369-4105-8745-0726232919E5}.Debug|x86.Build.0 = Debug|x86
+		{D942649F-F369-4105-8745-0726232919E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D942649F-F369-4105-8745-0726232919E5}.Release|Any CPU.Build.0 = Release|Any CPU
+		{D942649F-F369-4105-8745-0726232919E5}.Release|x86.ActiveCfg = Release|x86
+		{D942649F-F369-4105-8745-0726232919E5}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {A6AB3B1D-2886-4DA7-B748-AA0C80F374A6}
+	EndGlobalSection
+EndGlobal

+ 110 - 0
DK.XuWei.WebMes/DK.XuWei.WebMes.csproj

@@ -0,0 +1,110 @@
+<?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>{D942649F-F369-4105-8745-0726232919E5}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>DK.XuWei.WebMes</RootNamespace>
+    <AssemblyName>DK.XuWei.WebMes</AssemblyName>
+    <TargetFrameworkVersion>v4.0</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>
+    <Prefer32Bit>false</Prefer32Bit>
+  </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>
+    <Prefer32Bit>false</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x86\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <Prefer32Bit>false</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
+    <OutputPath>bin\x86\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <Prefer32Bit>false</Prefer32Bit>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Curtain.Core.net4">
+      <HintPath>..\dll\Curtain.Core.net4.dll</HintPath>
+    </Reference>
+    <Reference Include="Curtain.DataAccess.net4">
+      <HintPath>..\dll\Curtain.DataAccess.net4.dll</HintPath>
+    </Reference>
+    <Reference Include="Curtain.Net.Sockets.net4">
+      <HintPath>..\dll\Curtain.Net.Sockets.net4.dll</HintPath>
+    </Reference>
+    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\dll\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+    <Reference Include="Oracle.ManagedDataAccess">
+      <HintPath>..\dll\Oracle.ManagedDataAccess.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.configuration" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Web" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+    <Reference Include="zxing">
+      <HintPath>..\dll\zxing\zxing.dll</HintPath>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Easyui.cs" />
+    <Compile Include="Import.cs" />
+    <Compile Include="SiemensS7.cs" />
+    <Compile Include="SoapClient.cs" />
+    <Compile Include="XmlClient.cs" />
+    <Compile Include="JsonClient.cs" />
+    <Compile Include="JsonExt.cs" />
+    <Compile Include="JsonResult.cs" />
+    <Compile Include="mes\Login\LoginByPara.cs" />
+    <Compile Include="mes\Login\LoginBySessionKey.cs" />
+    <Compile Include="mes\Login\LoginCheck.cs" />
+    <Compile Include="mes\Login\LoginResult.cs" />
+    <Compile Include="mes\Login\LoginSetting.cs" />
+    <Compile Include="mes\Login\SessionClear.cs" />
+    <Compile Include="mes\Login\SessionGet.cs" />
+    <Compile Include="mes\Right\RightPurview.cs" />
+    <Compile Include="mes\Right\RightCheck.cs" />
+    <Compile Include="mes\Setting\GetSetting.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 67 - 0
DK.XuWei.WebMes/Easyui.cs

@@ -0,0 +1,67 @@
+using System;
+using System.Web;
+using System.Web.SessionState;
+using System.Data;
+using System.Text;
+using System.Collections;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using Curtain.DataAccess;
+
+namespace DK.XuWei.WebMes
+{
+    public static class Easyui
+    {
+        public static string TableToEasyUITree(DataTable dt, string pCode, int pLen = 2)
+        {
+            string jsonStr = "";
+            string filter = " code like '" + pCode + "%' and len(code) - len('" + pCode + "') = " + pLen.ToString();
+            DataRow[] drs = dt.Select(filter);
+
+            if (drs.Length < 1) return "";
+            jsonStr += ",\"children\":[";
+            foreach (DataRow dr in drs)
+            {
+                string pcv = dr["code"].ToString();
+                jsonStr += "{";
+                jsonStr += "\"id\":\"" + dr["id"].ToString() + "\",";
+                jsonStr += "\"text\":\"" + dr["text"].ToString() + "\"";
+                if(dt.Columns.Contains("state")) jsonStr += ",\"state\":\"" + dr["state"].ToString() + "\"";
+                if(dt.Columns.Contains("url")) jsonStr += ",\"attributes\":{\"url\":\"" + dr["url"].ToString() + "\"}";
+                jsonStr += TableToEasyUITree(dt, pcv, pLen).TrimEnd(',');
+                jsonStr += "},";
+            }
+            if (jsonStr.EndsWith(","))
+            {
+                jsonStr = jsonStr.Remove(jsonStr.Length - 1, 1);
+            }
+            jsonStr += "]";
+            return jsonStr;
+        }
+
+        public static JsonResult ExecuteJsonResult(IDataAccess conn,string sqlStr, List<CDAParameter> sqlPara)
+        {
+            if (HttpContext.Current.Request["page"] is object)
+            {
+                //获取分页数据
+                int page = HttpContext.Current.Request["page"] is object ? Convert.ToInt32(HttpContext.Current.Request["page"]) : 1;
+                int rows = HttpContext.Current.Request["rows"] is object ? Convert.ToInt32(HttpContext.Current.Request["rows"]) : 10;
+                string sort = HttpContext.Current.Request["sort"] is object ? HttpContext.Current.Request["sort"] : "";
+                string order = HttpContext.Current.Request["order"] is object ? HttpContext.Current.Request["order"] : "";
+
+                int total = 0;
+                DataTable dt = conn.SelectPages(page, rows, out total, sqlStr, sqlPara.ToArray());
+                return new JsonResult(dt) { total = total };
+            }
+            else
+            {
+                //直接获取不分页数据
+                DataTable dt = conn.ExecuteDatatable(sqlStr, sqlPara.ToArray());
+                return new JsonResult(dt) { total = dt.Rows.Count };
+            }
+        }
+
+
+    }
+}

+ 110 - 0
DK.XuWei.WebMes/Import.cs

@@ -0,0 +1,110 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+using System.Data;
+using System.Data.OleDb;
+using Curtain.DataAccess;
+
+namespace DK.XuWei.WebMes
+{
+    public sealed class Import
+    {
+        public static DataTable ExcelToDataTable(string excelFile, string sqlWhere = "")
+        {
+            //try
+            //{
+            string excelConnStr = "";
+            if (Path.GetExtension(excelFile).ToLower() == ".xlsx")
+            {
+                excelConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFile + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1';";
+            }
+            if (Path.GetExtension(excelFile).ToLower() == ".xls")
+            {
+                excelConnStr = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + excelFile + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1';";
+            }
+
+            using (OleDbConnection conn = new OleDbConnection(excelConnStr))
+            {
+                conn.Open();
+                DataTable sheetsName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });
+                string firstSheetName = sheetsName.Rows[0][2].ToString();
+                string sql = string.Format("SELECT * FROM [{0}]", firstSheetName);
+                if (sqlWhere != "") sql = sql + " WHERE " + sqlWhere;
+                OleDbDataAdapter oda = new OleDbDataAdapter(sql, excelConnStr);
+                DataTable dt = new DataTable();
+                oda.Fill(dt);
+                return dt;
+            }
+            //}
+            //catch(Exception ex)
+            //{
+            //    return null;
+            //}
+        }
+
+        public static string DataTableToDataBase(DataTable dataTable, string tableName, string sqlWhere = "", DataAccess conn = null)
+        {
+            string result = "";
+
+            //不同数据库的查询列名语句
+            string sqlServerSql = "SELECT NAME FROM SYS.SYSCOLUMNS WHERE (ID = OBJECT_ID('" + tableName + "'))";
+            string oracleSql = "SELECT COL.COLUMN_NAME NAME FROM ALL_TAB_COLUMNS COL WHERE COL.TABLE_NAME = '" + tableName + "' ORDER BY COL.COLUMN_ID";
+
+            //读取列名确认与数据库一致的列名进行导入
+            string sqlStr = oracleSql;
+            ArrayList columnsList = new ArrayList();
+            DataTable databaseTable = conn.ExecuteDatatable(sqlStr);
+            for (int i = 0; i < databaseTable.Rows.Count; i++)
+            {
+                if (dataTable.Columns.Contains(databaseTable.Rows[i]["Name"].ToString()))
+                {
+                    columnsList.Add(databaseTable.Rows[i]["Name"].ToString());
+                }
+            }
+
+            //写入数据库
+            conn.BeginTransaction();
+            int lineNo = 0;
+            try
+            {
+                List<CDAParameter> sqlPara = new List<CDAParameter>();
+                string fname = "";
+                string fvalue = "";
+                for (int s = 0; s < columnsList.Count; s++)
+                {
+                    if (s > 0)
+                    {
+                        fname = fname + ",";
+                        fvalue = fvalue + ",";
+                    }
+                    fname += columnsList[s].ToString();
+                    fvalue += "@" + columnsList[s].ToString() + "@";
+                    sqlPara.Add(new CDAParameter(columnsList[s].ToString(), DBNull.Value));
+                }
+                string insertStr = "insert into " + tableName + "(" + fname + ") values (" + fvalue + ")";
+
+                for (int i = 0; i < dataTable.Rows.Count; i++)
+                {
+                    lineNo = i + 2;
+                    for (int j = 0; j < columnsList.Count; j++)
+                    {
+                        sqlPara[j].Value = dataTable.Rows[i][columnsList[j].ToString()].ToString();
+                    }
+                    conn.ExecuteNonQuery(insertStr, sqlPara.ToArray());
+                }
+                conn.Commit();
+            }
+            catch
+            {
+                conn.Rollback();
+                result = "行号:" + lineNo.ToString() + " 数据错误,请检查Excel数据文件!";
+            }
+            return result;
+        }
+
+
+    }
+}

+ 176 - 0
DK.XuWei.WebMes/JsonClient.cs

@@ -0,0 +1,176 @@
+using System;
+using System.Collections.Generic;
+using System.Dynamic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using System.Collections;
+
+/// <summary>
+/// 接口调用通用方法 xuwei 2019-11-26
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static class JsonClient
+    {
+        #region Get请求
+        public static string Get(string url,Hashtable para=null)
+        {
+            //拼合URL参数
+            string webUrl = url;
+            if (para != null) webUrl += "?" + ParaToString(para);
+            //创建Web访问对象
+            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(webUrl);
+            //通过Web访问对象获取响应内容
+            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
+            //通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
+            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
+            //string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
+            string returnXml = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
+            reader.Close();
+            myResponse.Close();
+            return returnXml;
+        }
+        #endregion
+
+        #region Post请求
+        public static string Post(string url, string data)
+        {
+            return PostData(url, data, "POST");
+        }
+        #endregion
+
+        #region Put请求
+        public static string Put(string url, string data)
+        {
+            return PostData(url, data, "PUT");
+        }
+        #endregion
+
+        #region Delete请求
+        public static string Delete(string url, string data)
+        {
+            return PostData(url, data, "DELETE");
+        }
+        #endregion
+
+        #region PostData 请求
+        public static string PostData(string url, string data, string method)
+        {
+            //将单引号转义成双引号
+            data = data.Replace("'", "\"");
+            //创建Web访问对象
+            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
+            //把用户传过来的数据转成“UTF-8”的字节流
+            byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(data);
+
+            myRequest.Method = method;
+            myRequest.ContentLength = buf.Length;
+            myRequest.ContentType = "application/json;charset=UTF-8";
+            //myRequest.MaximumAutomaticRedirections = 1;
+            myRequest.AllowAutoRedirect = true;
+            //发送请求
+            Stream stream = myRequest.GetRequestStream();
+            stream.Write(buf, 0, buf.Length);
+            stream.Close();
+
+            //获取接口返回值
+            //通过Web访问对象获取响应内容
+            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
+            //通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
+            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
+            //string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
+            string returnXml = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
+            reader.Close();
+            myResponse.Close();
+            return returnXml;
+        }
+
+        /// <summary>
+        /// 带身份验证的post请求
+        /// </summary>
+        /// <param name="url"></param>
+        /// <param name="data"></param>
+        /// <param name="method"></param>
+        /// <param name="anthInfo"></param>
+        /// <returns></returns>
+        public static string PostData2(string url, string data, string method, string anthInfo)
+        {
+            try
+            {
+                //将单引号转义成双引号
+                data = data.Replace("'", "\"");
+                //创建Web访问对象
+                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
+                //把用户传过来的数据转成“UTF-8”的字节流
+                byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(data);
+
+                myRequest.Method = method;
+                myRequest.ContentLength = buf.Length;
+                myRequest.ContentType = "application/json;charset=UTF-8";
+                //myRequest.MaximumAutomaticRedirections = 1;
+                myRequest.AllowAutoRedirect = true;
+
+                string base64Header = Convert.ToBase64String(Encoding.UTF8.GetBytes(anthInfo));
+                myRequest.Headers.Add("Authorization", "Basic " + base64Header);
+
+                //发送请求
+                Stream stream = myRequest.GetRequestStream();
+                stream.Write(buf, 0, buf.Length);
+                stream.Close();
+
+                //获取接口返回值
+                //通过Web访问对象获取响应内容
+                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
+                //通过响应内容流创建StreamReader对象,因为StreamReader更高级更快
+                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
+                //string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
+                string returnXml = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
+                reader.Close();
+                myResponse.Close();
+                return returnXml;
+            }
+            catch (Exception ex)
+            {
+                return ex.Message;
+            }
+        }
+        #endregion
+
+        #region 参数转字符串
+        public static String ParaToString(Hashtable para)
+        {
+            StringBuilder sb = new StringBuilder();
+            foreach (string k in para.Keys)
+            {
+                if (sb.Length > 0)
+                {
+                    sb.Append("&");
+                }
+                sb.Append(HttpUtility.UrlEncode(k) + "=" + HttpUtility.UrlEncode(para[k].ToString()));
+            }
+            return sb.ToString();
+        }
+        #endregion
+
+    }
+
+    public static class JsonPost
+    {
+        #region 获取提交过来的JSON参数
+        public static string Parameter()
+        {
+            HttpContext.Current.Response.ContentType = "application/json";
+            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
+            Stream inputStream = HttpContext.Current.Request.InputStream;
+            Encoding encoding = HttpContext.Current.Request.ContentEncoding;
+            StreamReader streamReader = new StreamReader(inputStream, encoding);
+            return streamReader.ReadToEnd();
+        }
+        #endregion
+    }
+}
+

+ 25 - 0
DK.XuWei.WebMes/JsonExt.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Data;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace DK.XuWei.WebMes
+{
+    public static class JsonExt
+    {
+        public static string ToJson(this DataTable dt)
+        {
+            return JsonConvert.SerializeObject(dt);
+        }
+
+        public static string ToJson(this JsonResult jr)
+        {
+            JsonSerializerSettings js = new JsonSerializerSettings();
+            js.DateFormatString = "yyyy-MM-dd HH:mm:ss";
+            return JsonConvert.SerializeObject(jr, js);
+        }
+    }
+}

+ 99 - 0
DK.XuWei.WebMes/JsonResult.cs

@@ -0,0 +1,99 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Data;
+
+namespace DK.XuWei.WebMes
+{
+    public enum JsonStatus : int
+    {
+        success = 0, //操作成功
+        error = -1,//操作失败
+        sessionKeyError = -2, //sessionKey错误
+        rightError = -3, //权限错误
+        loginError = -4, //登录异常
+        otherError = -999 //未知错误
+    }
+
+    public class JsonResult
+    {
+        public bool success = true;
+        public string message = "操作成功!";
+        public JsonStatus status = JsonStatus.success;
+        public int total = 0;
+        public object rows = "";
+        //public DataTable DataTable { get { if (rows.GetType() == typeof(DataTable)) return (DataTable)rows; else return null; } set { rows = value; } }
+
+        public JsonResult()
+        {
+
+        }
+
+        public JsonResult(DataTable dt)
+        {
+            if (dt == null)
+            {
+                total = 0;
+                rows = new DataTable();
+            }
+            else
+            {
+                total = dt.Rows.Count;
+                rows = dt;
+            }
+        }
+
+        public JsonResult(object o)
+        {
+            rows = o;
+        }
+
+        public JsonResult(JsonStatus code)
+        {
+            status = code;
+            if (code == JsonStatus.success)
+            {
+                success = true;
+                message = "操作成功!";
+                total = 0;
+                rows = "";
+            }
+            if (code == JsonStatus.error)
+            {
+                success = false;
+                message = "操作失败!";
+                total = 0;
+                rows = "";
+            }
+            if (code == JsonStatus.sessionKeyError)
+            {
+                success = false;
+                message = "sessionKey错误!";
+                rows = "";
+            }
+            if (code == JsonStatus.rightError)
+            {
+                success = false;
+                message = "权限错误!";
+                total = 0;
+                rows = "";
+            }
+            if (code == JsonStatus.otherError)
+            {
+                success = false;
+                message = "内部错误!";
+                total = 0;
+                rows = "";
+            }
+            if (code == JsonStatus.loginError)
+            {
+                success = false;
+                message = "登录异常!";
+                total = 0;
+                rows = "";
+            }
+
+        }
+    }
+}

+ 36 - 0
DK.XuWei.WebMes/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("DK.XuWei.WebMes")]
+[assembly: AssemblyDescription("依赖于Curtain的Mes通用类库")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("沈阳东科云信软件有限公司")]
+[assembly: AssemblyProduct("DK.XuWei.WebMes")]
+[assembly: AssemblyCopyright("Copyright ©  2019")]
+[assembly: AssemblyTrademark("东科软件")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("d942649f-f369-4105-8745-0726232919e5")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 61 - 0
DK.XuWei.WebMes/SiemensS7.cs

@@ -0,0 +1,61 @@
+using Curtain.Net.Sockets.PLC;
+using Curtain.Net.Sockets.PLC.Model.Siemens;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace DK.XuWei.WebMes
+{
+    public static class SiemensS7
+    {
+        //读取PLC数据默认1200D块
+        public static PLCResult<T> PlcRead<T>(string ip,string db)
+        {
+            SocketClient<SiemensS7_1200Model> plc = null;
+            plc = new SocketClient<SiemensS7_1200Model>();
+            plc.Connect(ip, 102);
+            PLCResult<T> resultRead = plc.Read<T>("D", db);
+            plc.Close();
+            plc.Dispose();
+            return resultRead;
+        }
+
+        //写入PLC数据默认1200D块
+        public static PLCResult PlcWrite<T>(string ip, string db, object value)
+        {
+            SocketClient<SiemensS7_1200Model> plc = null;
+            plc = new SocketClient<SiemensS7_1200Model>();
+            plc.Connect(ip, 102);
+            PLCResult resultWrite = plc.Write<T>("D", db, (T)(value));
+            plc.Close();
+            plc.Dispose();
+            return resultWrite;
+        }
+
+        //读取PLC数据200
+        public static PLCResult<T> PlcRead200<T>(string ip, string code,string number)
+        {
+            SocketClient<SiemensS7_200SmartModel> plc = null;
+            plc = new SocketClient<SiemensS7_200SmartModel>();
+            plc.Connect(ip, 102);
+            PLCResult<T> resultRead = plc.Read<T>(code, number);
+            plc.Close();
+            plc.Dispose();
+            return resultRead;
+        }
+
+        //写入PLC数据200
+        public static PLCResult PlcWrite200<T>(string ip,string code, string number, object value)
+        {
+            SocketClient<SiemensS7_200SmartModel> plc = null;
+            plc = new SocketClient<SiemensS7_200SmartModel>();
+            plc.Connect(ip, 102);
+            PLCResult resultWrite = plc.Write<T>(code, number, (T)(value));
+            plc.Close();
+            plc.Dispose();
+            return resultWrite;
+        }
+    }
+}

+ 54 - 0
DK.XuWei.WebMes/SoapClient.cs

@@ -0,0 +1,54 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Dynamic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using System.Xml;
+using System.Xml.Serialization;
+
+/// <summary>
+/// WebService接口调用通用方法 xuwei 2020-07-02
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static class SoapClient
+    {
+        //<webServices>
+        //  <protocols>
+        //    <add name="HttpGet"/>
+        //    <add name="HttpPost"/>
+        //    <add name="HttpSoap"/>
+        //  </protocols>
+        //</webServices>
+
+        public static XmlDocument Post(string url,string postData, NetworkCredential credential)
+        {
+            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
+            request.ContentType = "text/xml;charset=utf-8";
+            request.Accept = "text/xml";
+            request.Method = "POST";
+            request.Credentials = credential;
+            request.Timeout = 1000 * 30;
+            byte[] data = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(postData);
+            request.ContentLength = data.Length;
+            Stream writer = request.GetRequestStream();
+            writer.Write(data, 0, data.Length);
+            writer.Close();
+            StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.UTF8);
+            String retXml = sr.ReadToEnd();
+            sr.Close();
+            XmlDocument xml = new XmlDocument();
+            xml.LoadXml(retXml);
+            return xml;
+        }
+
+
+    }
+
+}
+

+ 232 - 0
DK.XuWei.WebMes/XmlClient.cs

@@ -0,0 +1,232 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Dynamic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using System.Xml;
+using System.Xml.Serialization;
+
+/// <summary>
+/// WebService接口调用通用方法 xuwei 2020-07-02
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static class XmlClient
+    {
+        //<webServices>
+        //  <protocols>
+        //    <add name="HttpGet"/>
+        //    <add name="HttpPost"/>
+        //    <add name="HttpSoap"/>
+        //  </protocols>
+        //</webServices>
+
+        private static Hashtable _xmlNamespaces = new Hashtable();//缓存xmlNamespace,避免重复调用GetNamespace
+
+
+        /// <summary>
+        /// HttpPost方式调用WebService
+        /// </summary>
+        /// <param name="URL">地址</param>
+        /// <param name="MethodName">方法名</param>
+        /// <param name="Pars">参数集合</param>
+        /// <returns></returns>
+        public static XmlDocument Post(String URL, String MethodName, Hashtable Pars, NetworkCredential credentials = null)
+        {
+            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName);
+            request.Method = "POST";
+            request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
+            if (credentials != null)
+                request.Credentials = credentials;
+            else
+                request.Credentials = CredentialCache.DefaultCredentials;
+            request.Timeout = 1000 * 30;
+            //SetWebRequest(request);
+            byte[] data = EncodePars(Pars);
+            WriteRequestData(request, data);
+            return ReadXmlResponse(request.GetResponse());
+        }
+
+        public static XmlDocument Post(String URL, String Str, NetworkCredential credentials = null)
+        {
+            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
+            request.Method = "POST";
+            request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
+            if (credentials != null) 
+                request.Credentials = credentials;
+            else 
+                request.Credentials = CredentialCache.DefaultCredentials;
+            request.Timeout = 1000 * 30;
+            //SetWebRequest(request);
+            byte[] data = EncodePars(Str);
+            WriteRequestData(request, data);
+            return ReadXmlResponse(request.GetResponse());
+        }
+
+        /// <summary>
+        /// HttpGet方式调用WebService
+        /// </summary>
+        /// <param name="URL">地址</param>
+        /// <param name="MethodName">方法名</param>
+        /// <param name="Pars">参数集合</param>
+        /// <returns></returns>
+        public static XmlDocument Get(String URL, String MethodName, Hashtable Pars)
+        {
+            string temp = URL + "/" + MethodName + "?" + ParsToString(Pars);
+            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName + "?" + ParsToString(Pars));
+            request.Method = "GET";
+            request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
+            SetWebRequest(request);
+            return ReadXmlResponse(request.GetResponse());
+        }
+
+        /// <summary>
+        /// Soap方式调用WebService
+        /// </summary>
+        /// <param name="URL">地址</param>
+        /// <param name="MethodName">方法名</param>
+        /// <param name="Pars">参数集合</param>
+        /// <returns></returns>
+        public static XmlDocument Soap(String URL, String MethodName, Hashtable Pars)
+        {
+            if (_xmlNamespaces.ContainsKey(URL))
+            {
+                return QuerySoapWebService(URL, MethodName, Pars, _xmlNamespaces[URL].ToString());
+            }
+            else
+            {
+                return QuerySoapWebService(URL, MethodName, Pars, GetNamespace(URL));
+            }
+        }
+
+        private static XmlDocument QuerySoapWebService(String URL, String MethodName, Hashtable Pars, string XmlNs)
+        {
+            _xmlNamespaces[URL] = XmlNs;//加入缓存,提高效率
+            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
+            request.Method = "POST";
+            request.ContentType = "text/xml; charset=utf-8";
+            request.Headers.Add("SOAPAction", "\"" + XmlNs + (XmlNs.EndsWith("/") ? "" : "/") + MethodName + "\"");
+            SetWebRequest(request);
+            byte[] data = EncodeParsToSoap(Pars, XmlNs, MethodName);
+            WriteRequestData(request, data);
+            XmlDocument doc = new XmlDocument(), doc2 = new XmlDocument();
+            doc = ReadXmlResponse(request.GetResponse());
+
+            XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
+            mgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
+            String RetXml = doc.SelectSingleNode("//soap:Body/*/*", mgr).InnerXml;
+            doc2.LoadXml("<root>" + RetXml + "</root>");
+            AddDelaration(doc2);
+            return doc2;
+        }
+        private static string GetNamespace(String URL)
+        {
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL + "?WSDL");
+            SetWebRequest(request);
+            WebResponse response = request.GetResponse();
+            StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
+            XmlDocument doc = new XmlDocument();
+            doc.LoadXml(sr.ReadToEnd());
+            sr.Close();
+            return doc.SelectSingleNode("//@targetNamespace").Value;
+        }
+        private static byte[] EncodeParsToSoap(Hashtable Pars, String XmlNs, String MethodName)
+        {
+            XmlDocument doc = new XmlDocument();
+            doc.LoadXml("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"></soap:Envelope>");
+            AddDelaration(doc);
+            XmlElement soapBody = doc.CreateElement("soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
+            XmlElement soapMethod = doc.CreateElement(MethodName);
+            soapMethod.SetAttribute("xmlns", XmlNs);
+            foreach (string k in Pars.Keys)
+            {
+                XmlElement soapPar = doc.CreateElement(k);
+                soapPar.InnerXml = ObjectToSoapXml(Pars[k]);
+                soapMethod.AppendChild(soapPar);
+            }
+            soapBody.AppendChild(soapMethod);
+            doc.DocumentElement.AppendChild(soapBody);
+            return Encoding.UTF8.GetBytes(doc.OuterXml);
+        }
+        private static string ObjectToSoapXml(object o)
+        {
+            XmlSerializer mySerializer = new XmlSerializer(o.GetType());
+            MemoryStream ms = new MemoryStream();
+            mySerializer.Serialize(ms, o);
+            XmlDocument doc = new XmlDocument();
+            doc.LoadXml(Encoding.UTF8.GetString(ms.ToArray()));
+            if (doc.DocumentElement != null)
+            {
+                return doc.DocumentElement.InnerXml;
+            }
+            else
+            {
+                return o.ToString();
+            }
+        }
+        private static void SetWebRequest(HttpWebRequest request)
+        {
+            request.Credentials = CredentialCache.DefaultCredentials;
+            request.Timeout = 10000;
+        }
+
+        private static void WriteRequestData(HttpWebRequest request, byte[] data)
+        {
+            request.ContentLength = data.Length;
+            Stream writer = request.GetRequestStream();
+            writer.Write(data, 0, data.Length);
+            writer.Close();
+        }
+
+        private static byte[] EncodePars(Hashtable Pars)
+        {
+            //return Encoding.UTF8.GetBytes(ParsToString(Pars));
+            return System.Text.Encoding.GetEncoding("UTF-8").GetBytes(ParsToString(Pars));
+        }
+
+        private static byte[] EncodePars(string Str)
+        {
+            //return Encoding.UTF8.GetBytes(ParsToString(Pars));
+            return System.Text.Encoding.GetEncoding("UTF-8").GetBytes(Str);
+        }
+
+        private static String ParsToString(Hashtable Pars)
+        {
+            StringBuilder sb = new StringBuilder();
+            foreach (string k in Pars.Keys)
+            {
+                if (sb.Length > 0)
+                {
+                    sb.Append("&");
+                }
+                sb.Append(HttpUtility.UrlEncode(k) + "=" + HttpUtility.UrlEncode(Pars[k].ToString()));
+            }
+            return sb.ToString();
+        }
+
+        private static XmlDocument ReadXmlResponse(WebResponse response)
+        {
+            StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
+            String retXml = sr.ReadToEnd();
+            sr.Close();
+            XmlDocument doc = new XmlDocument();
+            doc.LoadXml(retXml);
+            return doc;
+        }
+
+        private static void AddDelaration(XmlDocument doc)
+        {
+            XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
+            doc.InsertBefore(decl, doc.DocumentElement);
+        }
+
+
+    }
+
+}
+

+ 233 - 0
DK.XuWei.WebMes/mes/Login/LoginByPara.cs

@@ -0,0 +1,233 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+
+/// <summary>
+/// Login 的摘要说明
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static JsonResult LoginByPara(string accountCode, string userCode, string userPassword,bool productCheck = false)
+        {
+            JsonResult result = new JsonResult();
+
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                string userId = "";
+                DateTime today = DateTime.Now;
+                string guid = Guid.NewGuid().ToString();
+
+                //开启事务
+                conn.BeginTransaction();
+
+                #region 读取用户信息
+                DataTable userTable = conn.ExecuteDatatable(@"
+                    SELECT
+                        u.ACCOUNTID,
+                        u.ACCOUNTCODE,
+	                    u.USERID,
+	                    u.USERCODE,
+	                    u.USERNAME,
+	                    u.PASSWORD,
+	                    u.ORGANIZATIONID,
+	                    u.ISWORKER,
+	                    u.LIMITSTARTTIME,
+	                    u.LIMITENDTIME
+                    FROM
+	                    TP_MST_USER u
+                    WHERE
+	                    u.VALUEFLAG = '1' 
+	                    AND u.ACCOUNTCODE = @ACCOUNTCODE@
+	                    AND u.USERCODE = @USERCODE@
+                    ",
+                    new CDAParameter("ACCOUNTCODE", accountCode),
+                    new CDAParameter("USERCODE", userCode)
+                    );
+                #endregion
+
+                //验证用户密码
+                if (userTable.Rows.Count == 1)
+                {
+                    userId = userTable.Rows[0]["USERID"].ToString();
+                    if (userTable.Rows[0]["PASSWORD"].ToString() == userPassword)
+                    {
+                        result.success = true;
+                        result.message = "用户登录成功!";
+                    }
+                    else
+                    {
+                        //更新密码错误次数
+                        conn.ExecuteNonQuery(@"
+                            UPDATE 
+                                TP_MST_USERLOGIN
+                            SET
+                                MISSTIMES = MISSTIMES + 1
+                            WHERE 
+                                USERID = @USERID@
+                            ",
+                            new CDAParameter("USERID", userId)
+                            );
+
+                        //读取错误次数
+                        string missTimes = conn.ExecuteScalar(@"
+                            SELECT 
+                                MISSTIMES
+                            FROM
+                                TP_MST_USERLOGIN
+                            WHERE
+                                USERID = @USERID@
+                            ",
+                            new CDAParameter("USERID", userId)
+                            ).ToString();
+
+                        result.success = false;
+                        result.message = "用户名或密码错误!";
+                        result.message += "登录失败次数:" + missTimes + ",";
+                        result.message += "连续登录失败 " + LoginSetting.MissTimes.ToString() + " 次,";
+                        result.message += "您的账号将被锁定 " + LoginSetting.LockHour.ToString() + " 小时!";
+
+                        //错误次数上限锁定操作
+                        //更新锁定标识
+                        int isLock = conn.ExecuteNonQuery(@"
+                            UPDATE 
+                                TP_MST_USERLOGIN
+                            SET
+                                ISLOCKED = '1',
+                                LOCKTIME = @LOCKTIME@
+                            WHERE 
+                                USERID = @USERID@
+                                AND MISSTIMES >= @MISSTIMES@
+                            ",
+                            new CDAParameter("LOCKTIME", today),
+                            new CDAParameter("USERID", userId),
+                            new CDAParameter("MISSTIMES", LoginSetting.MissTimes)
+                            );
+
+                        //写入锁定时间
+                        if(isLock>0)
+                        {
+                            conn.ExecuteNonQuery(@"
+                                UPDATE 
+                                    TP_MST_USER
+                                SET
+                                    LIMITSTARTTIME = @LIMITSTARTTIME@,
+                                    LIMITENDTIME = @LIMITENDTIME@
+                                WHERE 
+                                    USERID = @USERID@
+                                ",
+                                new CDAParameter("LIMITSTARTTIME", today),
+                                new CDAParameter("LIMITENDTIME", today.AddHours(LoginSetting.LockHour)),
+                                new CDAParameter("USERID", userId)
+                                );
+
+                            result.success = false;
+                            result.message = "用户账户已被锁定!";
+                            result.message += " 锁定时间:" + today.ToString() + " 至 " + today.AddHours(LoginSetting.LockHour);
+                        }
+                    }
+                }
+                else
+                {
+                    result.success = false;
+                    result.message = "用户名错误!";
+                }
+
+                //验证是否被锁定
+                if (result.success == true)
+                {
+                    DataTable lockTable = conn.ExecuteDatatable(@"
+                        SELECT
+	                        u.LIMITSTARTTIME,
+                            u.LIMITENDTIME
+                        FROM
+	                        TP_MST_USER u
+	                        LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID 
+                        WHERE
+	                        l.USERID = @USERID@ 
+	                        AND l.ISLOCKED = '1'
+	                        AND @LIMITSTARTTIME@ > u.LIMITSTARTTIME 
+	                        AND @LIMITENDTIME@ < u.LIMITENDTIME
+                        ",
+                        new CDAParameter("USERID", userId),
+                        new CDAParameter("LIMITSTARTTIME", today),
+                        new CDAParameter("LIMITENDTIME", today)
+                        );
+
+                    if (lockTable.Rows.Count == 0)
+                    {
+                        result.success = true;
+                        result.message = "用户登录成功!";
+                    }
+                    else
+                    {
+                        result.success = false;
+                        result.message = "用户账户已被锁定!";
+                        result.message += " 锁定时间:" + lockTable.Rows[0]["LIMITSTARTTIME"].ToString() + " 至 " + lockTable.Rows[0]["LIMITENDTIME"].ToString();
+                    }
+
+                }
+
+                //更新登录信息并记录Session
+                if (result.success == true)
+                {
+                    //重置密码错误次数 更新最后登录时间 更新SessionKey 更新登录状态
+                    conn.ExecuteNonQuery(@"
+                        UPDATE 
+                            TP_MST_USERLOGIN
+                        SET
+                            ISLOCKED = '0',
+                            MISSTIMES = 0,
+                            LASTLOGINTIME = @LASTLOGINTIME@,
+                            WEBISLOGIN = '1',
+                            WEBSESSIONKEY = @WEBSESSIONKEY@
+                        WHERE 
+                            USERID = @USERID@
+                        ",
+                        new CDAParameter("LASTLOGINTIME", today),
+                        new CDAParameter("WEBSESSIONKEY", guid),
+                        new CDAParameter("USERID", userId)
+                        );
+
+                    //记录Session
+                    HttpContext.Current.Session["accountId"] = userTable.Rows[0]["ACCOUNTID"].ToString();
+                    HttpContext.Current.Session["accountCode"] = userTable.Rows[0]["ACCOUNTCODE"].ToString();
+                    HttpContext.Current.Session["userId"] = userTable.Rows[0]["USERID"].ToString();
+                    HttpContext.Current.Session["userCode"] = userTable.Rows[0]["USERCODE"].ToString();
+                    HttpContext.Current.Session["userPassword"] = userTable.Rows[0]["PASSWORD"].ToString();
+                    HttpContext.Current.Session["webSessionKey"] = guid;
+
+                    //如果是成检 必须更新 sessionKey 会顶掉PC或PDA登录的相同用户
+                    if (productCheck)
+                    {
+                        conn.ExecuteNonQuery(@"
+                        UPDATE 
+                            TP_MST_USERLOGIN
+                        SET
+                            SESSIONKEY = @SESSIONKEY@
+                        WHERE 
+                            USERID = @USERID@
+                        ",
+                            new CDAParameter("SESSIONKEY", guid),
+                            new CDAParameter("USERID", userId)
+                            );
+                        HttpContext.Current.Session["sessionKey"] = guid;
+                    }
+
+                }
+
+                //提交数据
+                conn.Commit();
+
+                return result;
+            }
+
+        }
+
+    }
+}

+ 79 - 0
DK.XuWei.WebMes/mes/Login/LoginBySessionKey.cs

@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.SessionState;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+
+/// <summary>
+/// Login 的摘要说明
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static JsonResult LoginBySessionKey(string sessionKey)
+        {
+            JsonResult result = new JsonResult();
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                DateTime today = DateTime.Now;
+                //未被锁定 或 超过锁定时间 才允许登录
+                DataTable dt = conn.ExecuteDatatable(@"
+                    SELECT
+	                    u.USERID,
+	                    u.USERNAME,
+                        u.ACCOUNTID,
+                        u.ACCOUNTCODE,
+	                    u.USERCODE,
+	                    u.PASSWORD,
+	                    l.WEBSESSIONKEY
+                    FROM
+	                    TP_MST_USER u
+	                    LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID 
+                    WHERE
+	                    u.VALUEFLAG = '1' 
+	                    AND (l.ISLOCKED = '0' OR (l.ISLOCKED = '1' AND @LIMITENDTIME@ > u.LIMITENDTIME))
+                        AND l.SESSIONKEY = @SESSIONKEY@
+                    ",
+                    new CDAParameter("LIMITENDTIME", today),
+                    new CDAParameter("SESSIONKEY", sessionKey)
+                    );
+
+                if(dt.Rows.Count>0)
+                {
+                    //更新WEBISLOGIN
+                    conn.ExecuteNonQuery(@"
+                        UPDATE TP_MST_USERLOGIN 
+                        SET WEBISLOGIN = '1' 
+                        WHERE SESSIONKEY = @SESSIONKEY@",
+                        new CDAParameter("SESSIONKEY", sessionKey)
+                        );
+
+                    //登录成功
+                    result.success = true;
+                    result.message = "用户登录成功!";
+
+                    //记录Session
+                    HttpContext.Current.Session["accountId"] = dt.Rows[0]["ACCOUNTID"];
+                    HttpContext.Current.Session["accountCode"] = dt.Rows[0]["ACCOUNTCODE"];
+                    HttpContext.Current.Session["userId"] = dt.Rows[0]["USERID"];
+                    HttpContext.Current.Session["userCode"] = dt.Rows[0]["USERCODE"];
+                    HttpContext.Current.Session["userPassword"] = dt.Rows[0]["PASSWORD"];
+                    HttpContext.Current.Session["webSessionKey"] = dt.Rows[0]["WEBSESSIONKEY"];
+                    HttpContext.Current.Session["sessionKey"] = sessionKey;
+                }
+                else
+                {
+                    //登录失败
+                    result.success = false;
+                    result.message = "用户登录失败!";
+                }
+            }
+            return result;
+        }
+
+    }
+}

+ 75 - 0
DK.XuWei.WebMes/mes/Login/LoginCheck.cs

@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+using System.Web.SessionState;
+
+/// <summary>
+/// Login 的摘要说明
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static bool LoginCheck()
+        {
+            bool loginCheck = false;
+
+            //验证登录状态 如果是未登录状态 允许从sessionKey登录
+            if (   
+                   HttpContext.Current.Session["accountId"] is object
+                && HttpContext.Current.Session["accountCode"] is object
+                && HttpContext.Current.Session["userId"] is object
+                && HttpContext.Current.Session["userCode"] is object
+                && HttpContext.Current.Session["userPassword"] is object
+                && HttpContext.Current.Session["webSessionKey"] is object
+                )
+            {
+                loginCheck = true;
+            }
+            else
+            {
+                if (HttpContext.Current.Request["sessionKey"] is object)
+                {
+                    JsonResult result = mes.LoginBySessionKey(HttpContext.Current.Request["sessionKey"].ToString());
+                    loginCheck = result.success;
+                }
+            }
+
+            //验证单点登录 sessionKey
+            if (loginCheck)
+            {
+                using (IDataAccess conn = DataAccess.Create())
+                {
+                    DateTime today = DateTime.Now;
+                    string isLogin = conn.ExecuteScalar(@"
+                        SELECT
+	                        COUNT(u.USERID) 
+                        FROM
+	                        TP_MST_USER u
+	                        LEFT JOIN TP_MST_USERLOGIN l ON u.USERID = l.USERID 
+                        WHERE
+	                        u.VALUEFLAG = '1' --有效标识
+                            AND u.ACCOUNTCODE = @ACCOUNTCODE@ --账套
+	                        AND u.USERCODE = @USERCODE@ --用户工号
+	                        AND (l.ISLOCKED = '0' OR (l.ISLOCKED = '1' AND @LIMITENDTIME@ > u.LIMITENDTIME)) --未锁定或大于锁定时间
+	                        AND l.WEBISLOGIN = '1' --已登录
+	                        AND (l.WEBSESSIONKEY = @WEBSESSIONKEY@ OR l.WEBSESSIONKEY IS NULL)
+                        ",
+                        new CDAParameter("ACCOUNTCODE", HttpContext.Current.Session["accountCode"].ToString()),
+                        new CDAParameter("USERCODE", HttpContext.Current.Session["userCode"].ToString()),
+                        new CDAParameter("LIMITENDTIME", today),
+                        new CDAParameter("WEBSESSIONKEY", HttpContext.Current.Session["webSessionKey"].ToString())
+                        ).ToString();
+                    loginCheck = isLogin != "0" ? true : false;
+                }
+            }
+
+            return loginCheck;
+        }
+    }
+
+}

+ 20 - 0
DK.XuWei.WebMes/mes/Login/LoginResult.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+/// <summary>
+/// Login 的摘要说明
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public class LoginResult
+        {
+            public int Status = -1;
+            public string Message = "";
+        }
+    }
+
+}

+ 45 - 0
DK.XuWei.WebMes/mes/Login/LoginSetting.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+
+/// <summary>
+/// Login 的摘要说明
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static class LoginSetting
+        {
+            /// <summary>
+            /// 密码尝试次数,默认3次
+            /// </summary>
+            public static int MissTimes
+            {
+                get
+                {
+                    string times = mes.GetSetting("S_LGN_0001");
+                    return times == "" ? 3 : Convert.ToInt32(times);
+                }
+            }
+
+            /// <summary>
+            /// 用户锁定时长(小时),默认2小时
+            /// </summary>
+            public static int LockHour
+            {
+                get
+                {
+                    string times = mes.GetSetting("S_LGN_0002");
+                    return times == "" ? 2 : Convert.ToInt32(times);
+                }
+            }
+
+        }
+    }
+
+}

+ 27 - 0
DK.XuWei.WebMes/mes/Login/SessionClear.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using Newtonsoft.Json.Linq;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+
+/// <summary>
+/// Login 的摘要说明
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static void SessionClear()
+        {
+            while(HttpContext.Current.Session.Count>0)
+            {
+                HttpContext.Current.Session[HttpContext.Current.Session.Keys[0]] = null;
+                HttpContext.Current.Session.Remove(HttpContext.Current.Session.Keys[0]);
+            }
+        }
+    }
+
+}

+ 44 - 0
DK.XuWei.WebMes/mes/Login/SessionGet.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using Newtonsoft.Json.Linq;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+
+/// <summary>
+/// Login 的摘要说明
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static DataTable SessionGet()
+        {
+            //JObject para = new JObject();
+            //for (int i = 0; i < HttpContext.Current.Session.Count; i++)
+            //{
+            //    if (HttpContext.Current.Session[i] is object)
+            //        para.Add(new JProperty(HttpContext.Current.Session.Keys[i], HttpContext.Current.Session[i]));
+            //}
+            //return para;
+
+            DataTable dt = new DataTable();
+            for (int i = 0; i < HttpContext.Current.Session.Count; i++)
+            {
+                if (HttpContext.Current.Session[i] is object)
+                    dt.Columns.Add(HttpContext.Current.Session.Keys[i].ToString(), Type.GetType("System.String"));
+            }
+            DataRow row = dt.NewRow();
+            for (int i = 0; i < HttpContext.Current.Session.Count; i++)
+            {
+                if (HttpContext.Current.Session[i] is object)
+                    row[HttpContext.Current.Session.Keys[i].ToString()] = HttpContext.Current.Session[i].ToString();
+            }
+            if(HttpContext.Current.Session.Count >0) dt.Rows.Add(row);
+            return dt;
+        }
+    }
+
+}

+ 43 - 0
DK.XuWei.WebMes/mes/Right/RightCheck.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using Newtonsoft.Json.Linq;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+
+/// <summary>
+/// 校验功能权限
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static bool RightCheck(string functionFullName)
+        {
+            bool check = false;
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                DataTable dt = conn.ExecuteDatatable(@"
+                    SELECT
+	                    f.FUNCTIONCODE,
+	                    f.FUNCTIONNAME,
+                        f.FULLNAME
+                    FROM
+	                    TP_SYS_FUNCTION f
+	                    LEFT JOIN TP_MST_USERRIGHT r ON f.FUNCTIONCODE = r.FUNCTIONCODE 
+                    WHERE
+	                    f.FULLNAME LIKE '%' || @FULLNAME@ || '%'
+	                    AND r.USERID = @USERID@
+                    ",
+                    new CDAParameter("FULLNAME", functionFullName),
+                    new CDAParameter("USERID", HttpContext.Current.Session["userId"])
+                );
+                check = dt.Rows.Count > 0;
+            }
+            return check;
+        }
+    }
+
+}

+ 39 - 0
DK.XuWei.WebMes/mes/Right/RightPurview.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using Newtonsoft.Json.Linq;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+
+/// <summary>
+/// 校验范围权限
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static string RightPurview(int purviewType)
+        {
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                //读取范围权限列表
+                string jsonStr = conn.ExecuteScalar(@"
+                    SELECT 
+                        NVL( WMSYS.WM_CONCAT ( PURVIEWID ), '' )  
+                    FROM 
+                        TP_MST_USERPURVIEW 
+                    WHERE 
+                        USERID = @USERID@
+                ",
+                new CDAParameter("USERID", HttpContext.Current.Session["userId"])
+                ).ToString();
+
+                return jsonStr;
+            }
+
+        }
+    }
+
+}

+ 36 - 0
DK.XuWei.WebMes/mes/Setting/GetSetting.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Data;
+using Curtain.DataAccess;
+using DK.XuWei.WebMes;
+
+/// <summary>
+/// Login 的摘要说明
+/// </summary>
+namespace DK.XuWei.WebMes
+{
+    public static partial class mes
+    {
+        public static string GetSetting(string settingCode)
+        {
+            string value = "";
+            using (IDataAccess conn = DataAccess.Create())
+            {
+                value = conn.ExecuteScalar(@"
+                        SELECT
+	                        SETTINGVALUE 
+                        FROM
+	                        TP_MST_SYSTEMSETTING 
+                        WHERE
+	                        SETTINGCODE = @SETTINGCODE@
+                    ",
+                new CDAParameter("SETTINGCODE", settingCode)
+                ).ToString();
+            }
+            return value;
+        }
+    }
+
+}

+ 0 - 3
README.md

@@ -1,3 +0,0 @@
-# DK.xuwei.webmes
-
-WEBMES共通方法