diff --git a/JY.Inspection/Common/UserHelper.cs b/JY.Inspection/Common/UserHelper.cs
index 9576ff6..5c30389 100644
--- a/JY.Inspection/Common/UserHelper.cs
+++ b/JY.Inspection/Common/UserHelper.cs
@@ -1,4 +1,9 @@
-using System;
+using JY.Inspection.Enums;
+using JY.Inspection.Mes;
+using JY.MES.Entity;
+using JY.MES.MES;
+using Newtonsoft.Json;
+using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
@@ -36,14 +41,11 @@ namespace JY.Inspection.Common
///
[Display(Name = "密码")]
public string PassWord { get; set; }
- ///
- /// 权限
- ///
- ///
+
+
[Display(Name = "权限")]
public Autuority Level { get; set; }
}
-
///
/// 权限枚举
///
@@ -54,7 +56,6 @@ namespace JY.Inspection.Common
操作员,//操作员
Empty,
}
-
public class UserHelper
{
private string filePath = string.Empty;
@@ -292,5 +293,52 @@ namespace JY.Inspection.Common
}
return user;
}
+
+ ///
+ /// 使用MES员工信息接口校验登录信息
+ ///
+ ///
+ public User CheckMesUserLogin(string userName, string passWord, ref string strErr)
+ {
+ User user = null;
+
+ ReqLoginMes req = new ReqLoginMes()
+ {
+ SiteCode = Global.systemConfig.siteCode,
+ LineCode = Global.systemConfig.lineCode,
+ EquipNum = Global.systemConfig.equipCode,
+ UserName = userName,
+ PassWord = passWord,
+ UserCardID = string.Empty
+ };
+
+ string strJson = JsonConvert.SerializeObject(req);
+
+ MesCallResult result = new MESDataCombin().LoginMes(req);
+
+ if (result.IsSuccess && result.OriResponse?.Rows.Length == 1)
+ {
+ // TODO 权限转化
+ string levelStr = result.OriResponse.Rows[0].PermissionLevel;
+
+ bool resultLevel = Int32.TryParse(levelStr, out int level);
+ if (!resultLevel)
+ {
+ strErr = $"权限转化失败,权限值为:{levelStr}";
+ return user;
+ }
+
+ user = new User() {
+ UserName = result.OriResponse.Rows[0].Username,
+ Level = level.ToEnum().MapperEnum()
+ };
+ }
+ else
+ {
+ strErr = string.IsNullOrEmpty(result.OriResponse?.Message) ? result.ErrorMessage : result.OriResponse?.Message;
+ }
+
+ return user;
+ }
}
}
diff --git a/JY.Inspection/Enums/EnumAutority.cs b/JY.Inspection/Enums/EnumAutority.cs
new file mode 100644
index 0000000..007c839
--- /dev/null
+++ b/JY.Inspection/Enums/EnumAutority.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JY.Inspection.Enums
+{
+ ///
+ /// 用户权限
+ ///
+ public enum EnumAutority
+ {
+ ///
+ /// 管理员
+ ///
+ [Description("管理员")]
+ Administrator = 1,
+
+ ///
+ /// 工程师
+ ///
+ [Description("工程师")]
+ Engineer = 2,
+
+ ///
+ /// 操作员
+ ///
+ [Description("操作员")]
+ Operator = 3,
+
+ None = 4
+ }
+}
diff --git a/JY.Inspection/Enums/EnumExtension.cs b/JY.Inspection/Enums/EnumExtension.cs
new file mode 100644
index 0000000..68c5a2f
--- /dev/null
+++ b/JY.Inspection/Enums/EnumExtension.cs
@@ -0,0 +1,56 @@
+using JY.Inspection.Common;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JY.Inspection.Enums
+{
+ public static class EnumExtension
+ {
+ // 输入枚举,获取其Description属性对应的名称
+ public static string GetDescription(this Enum value)
+ {
+ FieldInfo field = value.GetType().GetField(value.ToString());
+ if (field != null)
+ {
+ DescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
+ if (attribute != null)
+ {
+ return attribute.Description;
+ }
+ }
+ return value.ToString();
+ }
+
+ // 输入数字,转化成对应的枚举
+ public static T ToEnum(this int value)
+ {
+ return (T)Enum.ToObject(typeof(T), value);
+ }
+
+ public static Autuority MapperEnum(this EnumAutority srcEnum)
+ {
+ switch (srcEnum)
+ {
+ case EnumAutority.Administrator:
+ return Autuority.管理员;
+
+ case EnumAutority.Engineer:
+ return Autuority.工程师;
+
+ case EnumAutority.Operator:
+ return Autuority.操作员;
+
+ case EnumAutority.None:
+ return Autuority.Empty;
+
+ default:
+ return Autuority.Empty;
+ }
+ }
+ }
+}
diff --git a/JY.Inspection/Frm/LoginForm.cs b/JY.Inspection/Frm/LoginForm.cs
index c7d7c7d..b6feaca 100644
--- a/JY.Inspection/Frm/LoginForm.cs
+++ b/JY.Inspection/Frm/LoginForm.cs
@@ -43,7 +43,6 @@ namespace JY.Inspection.Frm
TimeSpan ts = _tempDt.Subtract(_dt);
if (ts.Milliseconds > 100)
{
-
txtPassword2.Text = "";//清空
}
else
@@ -75,7 +74,6 @@ namespace JY.Inspection.Frm
}
private void btLogin_Click(object sender, EventArgs e)
{
-
if (string.IsNullOrEmpty(txtUserID.Text) | string.IsNullOrEmpty(txtPassWord.Text))
{
txtUserID.Focus();
@@ -84,12 +82,31 @@ namespace JY.Inspection.Frm
}
UserHelper helper = new UserHelper("");
string strErr = "";
- var res = helper.CheckUserLogin("user.pt", txtUserID.Text.Trim(), txtPassWord.Text.Trim(), ref strErr);
+
+ User res = null;
+
+ if (check_isMesLogin.Checked)
+ {
+ res = helper.CheckMesUserLogin(txtUserID.Text.Trim(), txtPassWord.Text.Trim(), ref strErr);
+ }
+ else
+ {
+ res = helper.CheckUserLogin("user.pt", txtUserID.Text.Trim(), txtPassWord.Text.Trim(), ref strErr);
+ }
+
if (res == null)
{
txtPassWord.Focus();
loginFailedCount++;
- MessageBox.Show($"用户名或密码不正确,登录失败({loginFailedCount})次!", "系统提示");
+ if (check_isMesLogin.Checked)
+ {
+ MessageBox.Show($"使用MES账户登录失败,错误信息: {strErr}!", "系统提示");
+ }
+ else
+ {
+ MessageBox.Show($"用户名或密码不正确,登录失败({loginFailedCount})次!", "系统提示");
+ }
+
return;
}
diff --git a/JY.Inspection/Frm/LoginForm.designer.cs b/JY.Inspection/Frm/LoginForm.designer.cs
index 24fe8fd..dfcc4a0 100644
--- a/JY.Inspection/Frm/LoginForm.designer.cs
+++ b/JY.Inspection/Frm/LoginForm.designer.cs
@@ -42,6 +42,7 @@ namespace JY.Inspection.Frm
this.pLogin_card = new System.Windows.Forms.Panel();
this.lblICCard = new MetroFramework.Controls.MetroLabel();
this.txtPassword2 = new MetroFramework.Controls.MetroTextBox();
+ this.check_isMesLogin = new MetroFramework.Controls.MetroCheckBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.pLogin_pwd.SuspendLayout();
this.pLogin_card.SuspendLayout();
@@ -51,7 +52,7 @@ namespace JY.Inspection.Frm
//
this.chkIsSK.AutoSize = true;
this.chkIsSK.Location = new System.Drawing.Point(237, 390);
- this.chkIsSK.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.chkIsSK.Margin = new System.Windows.Forms.Padding(4);
this.chkIsSK.Name = "chkIsSK";
this.chkIsSK.Size = new System.Drawing.Size(168, 17);
this.chkIsSK.TabIndex = 20;
@@ -61,7 +62,7 @@ namespace JY.Inspection.Frm
// btExit
//
this.btExit.Location = new System.Drawing.Point(279, 428);
- this.btExit.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.btExit.Margin = new System.Windows.Forms.Padding(4);
this.btExit.Name = "btExit";
this.btExit.Size = new System.Drawing.Size(127, 46);
this.btExit.TabIndex = 22;
@@ -72,7 +73,7 @@ namespace JY.Inspection.Frm
// btLogin
//
this.btLogin.Location = new System.Drawing.Point(81, 428);
- this.btLogin.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.btLogin.Margin = new System.Windows.Forms.Padding(4);
this.btLogin.Name = "btLogin";
this.btLogin.Size = new System.Drawing.Size(127, 46);
this.btLogin.TabIndex = 21;
@@ -83,7 +84,7 @@ namespace JY.Inspection.Frm
//
this.pictureBox1.Image = global::JY.Inspection.Properties.Resources.登录;
this.pictureBox1.Location = new System.Drawing.Point(153, 55);
- this.pictureBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.pictureBox1.Margin = new System.Windows.Forms.Padding(4);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(168, 165);
this.pictureBox1.TabIndex = 18;
@@ -95,10 +96,10 @@ namespace JY.Inspection.Frm
//
//
this.txtUserID.CustomButton.Image = null;
- this.txtUserID.CustomButton.Location = new System.Drawing.Point(236, 1);
- this.txtUserID.CustomButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.txtUserID.CustomButton.Location = new System.Drawing.Point(177, 1);
+ this.txtUserID.CustomButton.Margin = new System.Windows.Forms.Padding(4);
this.txtUserID.CustomButton.Name = "";
- this.txtUserID.CustomButton.Size = new System.Drawing.Size(36, 34);
+ this.txtUserID.CustomButton.Size = new System.Drawing.Size(27, 27);
this.txtUserID.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.txtUserID.CustomButton.TabIndex = 1;
this.txtUserID.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
@@ -107,7 +108,7 @@ namespace JY.Inspection.Frm
this.txtUserID.Lines = new string[] {
"Admin"};
this.txtUserID.Location = new System.Drawing.Point(108, 16);
- this.txtUserID.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.txtUserID.Margin = new System.Windows.Forms.Padding(4);
this.txtUserID.MaxLength = 32767;
this.txtUserID.Name = "txtUserID";
this.txtUserID.PasswordChar = '\0';
@@ -131,10 +132,10 @@ namespace JY.Inspection.Frm
//
//
this.txtPassWord.CustomButton.Image = null;
- this.txtPassWord.CustomButton.Location = new System.Drawing.Point(236, 1);
- this.txtPassWord.CustomButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.txtPassWord.CustomButton.Location = new System.Drawing.Point(177, 1);
+ this.txtPassWord.CustomButton.Margin = new System.Windows.Forms.Padding(4);
this.txtPassWord.CustomButton.Name = "";
- this.txtPassWord.CustomButton.Size = new System.Drawing.Size(36, 34);
+ this.txtPassWord.CustomButton.Size = new System.Drawing.Size(27, 27);
this.txtPassWord.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.txtPassWord.CustomButton.TabIndex = 1;
this.txtPassWord.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
@@ -143,7 +144,7 @@ namespace JY.Inspection.Frm
this.txtPassWord.Lines = new string[] {
"Admin"};
this.txtPassWord.Location = new System.Drawing.Point(108, 60);
- this.txtPassWord.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.txtPassWord.Margin = new System.Windows.Forms.Padding(4);
this.txtPassWord.MaxLength = 32767;
this.txtPassWord.Name = "txtPassWord";
this.txtPassWord.PasswordChar = '*';
@@ -246,11 +247,25 @@ namespace JY.Inspection.Frm
this.txtPassword2.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109)))));
this.txtPassword2.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel);
//
+ // check_isMesLogin
+ //
+ this.check_isMesLogin.AutoSize = true;
+ this.check_isMesLogin.Checked = true;
+ this.check_isMesLogin.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.check_isMesLogin.Location = new System.Drawing.Point(81, 390);
+ this.check_isMesLogin.Margin = new System.Windows.Forms.Padding(4);
+ this.check_isMesLogin.Name = "check_isMesLogin";
+ this.check_isMesLogin.Size = new System.Drawing.Size(114, 17);
+ this.check_isMesLogin.TabIndex = 28;
+ this.check_isMesLogin.Text = "MES员工登录";
+ this.check_isMesLogin.UseSelectable = true;
+ //
// LoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(472, 529);
+ this.Controls.Add(this.check_isMesLogin);
this.Controls.Add(this.pLogin_pwd);
this.Controls.Add(this.pLogin_card);
this.Controls.Add(this.chkIsSK);
@@ -258,7 +273,7 @@ namespace JY.Inspection.Frm
this.Controls.Add(this.btLogin);
this.Controls.Add(this.pictureBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+ this.Margin = new System.Windows.Forms.Padding(4);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginForm";
@@ -290,5 +305,6 @@ namespace JY.Inspection.Frm
private System.Windows.Forms.Panel pLogin_card;
private MetroFramework.Controls.MetroLabel lblICCard;
private MetroFramework.Controls.MetroTextBox txtPassword2;
+ private MetroFramework.Controls.MetroCheckBox check_isMesLogin;
}
}
\ No newline at end of file
diff --git a/JY.Inspection/Frm/SetForm.cs b/JY.Inspection/Frm/SetForm.cs
index a4a0c71..fc5c8a8 100644
--- a/JY.Inspection/Frm/SetForm.cs
+++ b/JY.Inspection/Frm/SetForm.cs
@@ -137,8 +137,6 @@ namespace JY.Inspection.Frm
///
private void btAdd_Click(object sender, EventArgs e)
{
-
-
User user = GetUser(ListUser);
var res = helper.AddUser("user.pt", ListUser, user);
if (res)
diff --git a/JY.Inspection/HomeForm.cs b/JY.Inspection/HomeForm.cs
index 8e3e15e..f889283 100644
--- a/JY.Inspection/HomeForm.cs
+++ b/JY.Inspection/HomeForm.cs
@@ -8,6 +8,7 @@ using JY.DAL.Repository;
using JY.DAL.Service;
using JY.Inspection.Common;
using JY.Inspection.Entity;
+using JY.Inspection.Enums;
using JY.Inspection.Frm;
using JY.Inspection.Mes;
using JY.MES;
@@ -1235,11 +1236,11 @@ namespace JY.Inspection
///
private void tsmiUserConfig_Click(object sender, EventArgs e)
{
- if (!CheckAdmin())
- {
- MessageBox.Show("权限不足", "系统提示");
- return;
- }
+ //if (!CheckAdmin())
+ //{
+ // MessageBox.Show("权限不足", "系统提示");
+ // return;
+ //}
SetForm setForm = new SetForm();
setForm.ShowDialog();
}
diff --git a/JY.Inspection/JY.Inspection.csproj b/JY.Inspection/JY.Inspection.csproj
index ae49b5a..3cab2be 100644
--- a/JY.Inspection/JY.Inspection.csproj
+++ b/JY.Inspection/JY.Inspection.csproj
@@ -190,6 +190,8 @@
+
+
Form
diff --git a/JY.Inspection/Mes/MESDataCombin.cs b/JY.Inspection/Mes/MESDataCombin.cs
index 99da3cb..9ca58f5 100644
--- a/JY.Inspection/Mes/MESDataCombin.cs
+++ b/JY.Inspection/Mes/MESDataCombin.cs
@@ -45,6 +45,8 @@ namespace JY.Inspection.Mes
///
///
RespExitStation PostProductExitStationData(ReqExitStation req);
+
+ MesCallResult LoginMes(ReqLoginMes req);
}
public class MESDataCombin : IMes
@@ -310,5 +312,49 @@ namespace JY.Inspection.Mes
return resp;
}
+
+ public MesCallResult LoginMes(ReqLoginMes req)
+ {
+ if (req == null)
+ {
+ throw new ArgumentNullException("MES员工登录请求信息为空");
+ }
+
+ // TODO MES登录请求地址
+ DateTime currentTime = DateTime.Now;
+ string reqUrl = string.Empty;
+ MesCallResult resp = new MesCallResult();
+
+ try
+ {
+ string reqJsonStr = JsonConvert.SerializeObject(req);
+ var sw = new Stopwatch();
+ sw.Start();
+ string mesRes = MESApiHelper.HttpPostJsonAPI(
+ reqUrl,
+ reqJsonStr,
+ Global.systemConfig.MesRequestTime
+ );
+ resp = MESApiHelper.HttpPostJsonAPI(reqUrl, reqJsonStr, Global.systemConfig.MesRequestTime);
+ sw.Stop();
+
+ if (resp?.OriResponse != null && resp?.OriResponse.Success != true)
+ {
+ resp.IsSuccess = false;
+ resp.ErrorType = MesErrorType.BusinessError;
+ resp.ErrorMessage = resp?.OriResponse?.Message ?? "MES业务处理失败, 错误消息为空";
+ }
+
+ new MesLog().LogLoginMes(currentTime, reqJsonStr, resp.OriRespJsonStr, sw.ElapsedMilliseconds);
+ }
+ catch (Exception ex)
+ {
+ resp.IsSuccess = false;
+ resp.ErrorType = MesErrorType.ClientError;
+ resp.ErrorMessage = "获取MES员工登录信息异常:" + ex.Message;
+ }
+
+ return resp;
+ }
}
}
diff --git a/JY.Inspection/Mes/MesLog.cs b/JY.Inspection/Mes/MesLog.cs
index 2b0ed9c..18cfb79 100644
--- a/JY.Inspection/Mes/MesLog.cs
+++ b/JY.Inspection/Mes/MesLog.cs
@@ -15,6 +15,8 @@ namespace JY.Inspection.Mes
void LogArrivalStation(DateTime curTime, string reqJsonStr, string respMes, long costTime);
void LogExitStation(DateTime curTime, string reqJsonStr, string respMes, long costTime);
+
+ void LogLoginMes(DateTime curTime, string reqJsonStr, string respMes, long costTime);
}
public class MesLog : IMesLog
@@ -62,5 +64,12 @@ namespace JY.Inspection.Mes
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
+
+ public void LogLoginMes(DateTime curTime, string reqJsonStr, string respMes, long costTime)
+ {
+ string actionName = "Mes员工登录";
+
+ LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
+ }
}
}
diff --git a/JY.MES/JY.MES.csproj b/JY.MES/JY.MES.csproj
index e31590b..a31c8d8 100644
--- a/JY.MES/JY.MES.csproj
+++ b/JY.MES/JY.MES.csproj
@@ -73,9 +73,11 @@
+
+
diff --git a/JY.MES/MES/ReqLoginMes.cs b/JY.MES/MES/ReqLoginMes.cs
new file mode 100644
index 0000000..ec51cd0
--- /dev/null
+++ b/JY.MES/MES/ReqLoginMes.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JY.MES.MES
+{
+ ///
+ /// 登录MES
+ ///
+ public class ReqLoginMes
+ {
+ ///
+ /// 工厂代码
+ ///
+ public string SiteCode { get; set; }
+
+ ///
+ /// 产线编号
+ ///
+ public string LineCode { get; set; }
+
+ ///
+ /// 设备编号
+ ///
+ public string EquipNum { get; set; }
+
+ ///
+ /// 员工账号 账号登录时,账号,密码必填
+ ///
+ public string UserName { get; set; }
+
+ ///
+ /// 员工密码
+ ///
+ public string PassWord { get; set; }
+
+ ///
+ /// 员工卡号 刷卡时,卡号必填
+ ///
+ public string UserCardID { get; set; }
+ }
+}
diff --git a/JY.MES/MES/RespLoginMes.cs b/JY.MES/MES/RespLoginMes.cs
new file mode 100644
index 0000000..6585b60
--- /dev/null
+++ b/JY.MES/MES/RespLoginMes.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JY.MES.MES
+{
+ ///
+ /// MES登录响应
+ ///
+ public class RespLoginMes
+ {
+ ///
+ /// 错误代码,成功不返回
+ ///
+ public string ErrorCode { get; set; }
+
+ ///
+ /// 成功标识 (false失败 true 成功)
+ ///
+ public bool Success { get; set; }
+
+ ///
+ /// 数据处理消息,成功不返回
+ ///
+ public string Message { get; set; }
+
+ ///
+ /// 报错消息类型
+ ///
+ public string Category { get; set; }
+
+ ///
+ /// 员工账号&权限等级
+ ///
+ public MesUserInfo[] Rows { get; set; }
+
+ ///
+ /// 条数,统一返回1
+ ///
+ public int Total { get; set; }
+ }
+
+ public class MesUserInfo
+ {
+ ///
+ /// 员工账号
+ ///
+ public string Username { get; set; }
+
+ ///
+ /// 权限等级
+ ///
+ public string PermissionLevel { get; set; }
+ }
+}