|
|
@@ -54,14 +54,66 @@ namespace UAS_MES_NEW.Query
|
|
|
|
|
|
/// <summary>
|
|
|
/// 人员编号输入框,回车后按选中的模式执行上线/下线
|
|
|
+ /// 兼容两种输入格式:①只输入工号(名称从 SOPEMPLOYEEDETAIL 查) ②扫描/输入「工号/人员姓名」(直接解析,不再查表)
|
|
|
/// </summary>
|
|
|
private void em_code_KeyDown(object sender, KeyEventArgs e)
|
|
|
{
|
|
|
if (e.KeyCode != Keys.Enter)
|
|
|
return;
|
|
|
+ //阻止回车继续冒泡到 SnCollectionBox / EnterTextBox 的回车逻辑
|
|
|
+ //(SnCollectionBox 的 KeyDown 里有一句 this.SelectAll(),会受消息顺序影响;
|
|
|
+ // 另配 Em_code_KeyPress 拦掉字符级回车,双保险,不让内置逻辑有机会执行)
|
|
|
+ e.SuppressKeyPress = true;
|
|
|
+ e.Handled = true;
|
|
|
+ HandleEmCode();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 字符级拦截:SnCollectionBox/EnterTextBox 内部的回车处理挂在 KeyDown 上,不监听 KeyPress,
|
|
|
+ /// 而扫描枪以 Tab 结尾或手工回车都会先产生字符级 \r。
|
|
|
+ /// 这里直接把 \r 吞掉并调用统一处理,SnCollectionBox 的回车逻辑(含 SelectAll)就完全不会触发,
|
|
|
+ /// 从而不必改动该公共控件。
|
|
|
+ /// </summary>
|
|
|
+ private void Em_code_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.KeyChar == '\r' || e.KeyChar == '\n')
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ HandleEmCode();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 上线/下线的统一处理入口(由回车、字符级 \r 两处触发,故用 _emBusy 防止同一次回车重复执行)
|
|
|
+ /// </summary>
|
|
|
+ private bool _emBusy = false;
|
|
|
+
|
|
|
+ private void HandleEmCode()
|
|
|
+ {
|
|
|
+ if (_emBusy)
|
|
|
+ return;
|
|
|
+ _emBusy = true;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DoEmCode();
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ _emBusy = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoEmCode()
|
|
|
+ {
|
|
|
string linecode = li_code.Text.Trim();
|
|
|
- string emcode = em_code.Text.Trim();
|
|
|
- //限制:人员编号不能为空
|
|
|
+ string emcode = "";
|
|
|
+ string emname = "";
|
|
|
+ //解析输入内容:扫描枪输出「工号/人员姓名」两段格式,手工输入则只有工号
|
|
|
+ if (!SplitEmInfo(em_code.Text, out emcode, out emname))
|
|
|
+ {
|
|
|
+ OperateResult.AppendText("<<扫描内容格式有误,应为「工号/人员姓名」\n", Color.Red, em_code);
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (emcode == "")
|
|
|
{
|
|
|
OperateResult.AppendText("<<人员编号不能为空\n", Color.Red, em_code);
|
|
|
@@ -75,14 +127,18 @@ namespace UAS_MES_NEW.Query
|
|
|
OperateResult.AppendText("<<请先选择线别\n", Color.Red, li_code);
|
|
|
return;
|
|
|
}
|
|
|
- //上线:先校验人员编号存在于 SOPEMPLOYEEDETAIL,并取出人员名称(同一 sed_emcode 可能多条,取最大值聚合)
|
|
|
- string emname = dh.getFieldDataByCondition("SOPEMPLOYEEDETAIL", "max(sed_emname)", "sed_emcode='" + emcode + "'").ToString().Trim();
|
|
|
+ //上线:扫描格式已带姓名则直接用;只输入工号时才去 SOPEMPLOYEEDETAIL 取名称
|
|
|
if (emname == "")
|
|
|
{
|
|
|
- OperateResult.AppendText("<<" + emcode + "人员编号不存在\n", Color.Red, em_code);
|
|
|
- em_code.Clear();
|
|
|
- em_code.Focus();
|
|
|
- return;
|
|
|
+ //同一 sed_emcode 可能多条,取最大值聚合
|
|
|
+ emname = dh.getFieldDataByCondition("SOPEMPLOYEEDETAIL", "max(sed_emname)", "sed_emcode='" + emcode + "'").ToString().Trim();
|
|
|
+ if (emname == "")
|
|
|
+ {
|
|
|
+ OperateResult.AppendText("<<" + emcode + "人员编号不存在\n", Color.Red, em_code);
|
|
|
+ em_code.Clear();
|
|
|
+ em_code.Focus();
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
//一个人只能同时一条线上线:若已在别的线体上线,先把原线体自动下线,再在新线体上线
|
|
|
DataTable dtOn = (DataTable)dh.ExecuteSql("select lm_linecode from loadman where lm_emcode='" + emcode + "' and lm_downtime is null", "select");
|
|
|
@@ -117,7 +173,11 @@ namespace UAS_MES_NEW.Query
|
|
|
return;
|
|
|
}
|
|
|
dh.ExecuteSql("update loadman set lm_downtime=sysdate where lm_emcode='" + emcode + "' and lm_downtime is null", "update");
|
|
|
- OperateResult.AppendText("<<" + emcode + "已从" + dtOn.Rows[0]["lm_linecode"].ToString() + "下线\n", Color.Green, em_code);
|
|
|
+ //姓名优先取扫描解析出的,否则用 loadman 里记录的名称
|
|
|
+ string downName = emname == "" ? dh.getFieldDataByCondition("loadman", "max(lm_emname)",
|
|
|
+ "lm_emcode='" + emcode + "' and lm_downtime is null").ToString().Trim() : emname;
|
|
|
+ OperateResult.AppendText("<<" + emcode + (downName == "" ? "" : " " + downName) + " 已从"
|
|
|
+ + dtOn.Rows[0]["lm_linecode"].ToString() + "下线\n", Color.Green, em_code);
|
|
|
}
|
|
|
//数据变更后刷新
|
|
|
LoadGridData();
|
|
|
@@ -125,6 +185,34 @@ namespace UAS_MES_NEW.Query
|
|
|
em_code.Focus();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 解析人员输入内容,兼容两种格式:
|
|
|
+ /// ①「工号/人员姓名」(扫描枪常用格式,分隔符支持 / \ 全角/ 竖线 | ,也兼容空格和中文顿号) → 工号与姓名都带出
|
|
|
+ /// ②只有工号(手工输入) → 姓名返回空串,由调用方决定是否去 SOPEMPLOYEEDETAIL 查
|
|
|
+ /// 分隔符在首尾或出现多次时视为格式错误,返回 false
|
|
|
+ /// </summary>
|
|
|
+ private bool SplitEmInfo(string input, out string emcode, out string emname)
|
|
|
+ {
|
|
|
+ emcode = "";
|
|
|
+ emname = "";
|
|
|
+ if (input == null)
|
|
|
+ return true;
|
|
|
+ string text = input.Trim();
|
|
|
+ if (text == "")
|
|
|
+ return true;
|
|
|
+ string[] sep = new string[] { "/", "\\", "/", "|", "|", " ", " ", "、" };
|
|
|
+ string[] parts = text.Split(sep, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ if (parts.Length == 0)
|
|
|
+ return true;
|
|
|
+ emcode = parts[0].Trim();
|
|
|
+ if (parts.Length > 1)
|
|
|
+ emname = parts[1].Trim();
|
|
|
+ //带分隔符却没解析出两段,说明格式不对(如以分隔符开头或多余分隔符)
|
|
|
+ if (text.IndexOfAny(new char[] { '/', '\\', '/', '|', '|', ' ', ' ', '、' }) >= 0 && (emcode == "" || emname == ""))
|
|
|
+ return false;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 判断DGV中是否有勾选的行
|
|
|
/// </summary>
|
|
|
@@ -168,7 +256,7 @@ namespace UAS_MES_NEW.Query
|
|
|
continue;
|
|
|
lmId = row.Cells["lm_id"].Value.ToString();
|
|
|
emcode = row.Cells["lm_emcode"].Value == null ? "" : row.Cells["lm_emcode"].Value.ToString();
|
|
|
- emname = row.Cells["sed_emname"].Value == null ? "" : row.Cells["sed_emname"].Value.ToString();
|
|
|
+ emname = row.Cells["lm_emname"].Value == null ? "" : row.Cells["lm_emname"].Value.ToString();
|
|
|
linecode = row.Cells["lm_linecode"].Value == null ? "" : row.Cells["lm_linecode"].Value.ToString();
|
|
|
try
|
|
|
{
|
|
|
@@ -207,12 +295,16 @@ namespace UAS_MES_NEW.Query
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 刷新DGV:只取未下线的人员,已选线别时只显示当前线别;按 lm_emcode 关联 SOPEMPLOYEEDETAIL 取人员名称
|
|
|
- /// (SOPEMPLOYEEDETAIL 同一 sed_emcode 可能有多条,先按其聚合去重再关联;上线时间 to_char 到秒)
|
|
|
+ /// 刷新DGV:只取未下线的人员,已选线别时只显示当前线别
|
|
|
+ /// 人员名称直接取 loadman.lm_emname(上线时已写入),不再关联 SOPEMPLOYEEDETAIL;
|
|
|
+ /// 兼容历史数据:lm_emname 为空时才回退到 SOPEMPLOYEEDETAIL 取名称
|
|
|
+ /// (SOPEMPLOYEEDETAIL 同一 sed_emcode 可能有多条,先按其聚合去重;上线时间 to_char 到秒)
|
|
|
/// </summary>
|
|
|
private void LoadGridData()
|
|
|
{
|
|
|
- string sql = "select lm.lm_id,lm.lm_linecode,lm.lm_emcode,se.sed_emname,to_char(lm.lm_uptime,'yyyy-mm-dd hh24:mi:ss') lm_uptime,lm.lm_inman from loadman lm"
|
|
|
+ string sql = "select lm.lm_id,lm.lm_linecode,lm.lm_emcode,lm.lm_emname,"
|
|
|
+ + "nvl(lm.lm_emname,se.sed_emname) emname,"
|
|
|
+ + "to_char(lm.lm_uptime,'yyyy-mm-dd hh24:mi:ss') lm_uptime,lm.lm_inman from loadman lm"
|
|
|
+ " left join (select sed_emcode,max(sed_emname) sed_emname from SOPEMPLOYEEDETAIL group by sed_emcode) se on lm.lm_emcode=se.sed_emcode"
|
|
|
+ " where lm.lm_downtime is null";
|
|
|
if (li_code.Text != "")
|