You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
497 lines
18 KiB
497 lines
18 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using System.Data.Linq;
|
|
using System.Linq;
|
|
using ICSSoft.Base.Language.Tool;
|
|
using System.Reflection;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using ICSSoft.Base.ReferForm;
|
|
using ICSSoft.Base.Report;
|
|
using ICSSoft.Base.ReferForm.AppReferForm;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Frame.Data.BLL;
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
namespace ICSSoft.Frame.APP
|
|
{
|
|
public partial class FormICSUserInfoAdd1 : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
DataTable dtDetail = new DataTable();
|
|
bool modify = true;
|
|
|
|
#region 构造函数
|
|
public FormICSUserInfoAdd1()
|
|
{
|
|
modify = false;
|
|
InitializeComponent();
|
|
init();
|
|
QueryUserInfo("");
|
|
}
|
|
|
|
public FormICSUserInfoAdd1(string userCode)
|
|
{
|
|
modify = true;
|
|
InitializeComponent();
|
|
init();
|
|
QueryUserInfo(userCode);
|
|
}
|
|
|
|
private void QueryUserInfo(string userCode)
|
|
{
|
|
dtDetail = ICSUserInfoBLL.Select(userCode);
|
|
grdDetail.DataSource = dtDetail;
|
|
if (dtDetail.Rows.Count > 0)
|
|
{
|
|
txtPhone.Text = dtDetail.Rows[0]["Phone"].ToString();
|
|
txtMail.Text = dtDetail.Rows[0]["Mail"].ToString();
|
|
chkFrontLine.Checked = Convert.ToBoolean(dtDetail.Rows[0]["FrontLine"]);
|
|
}
|
|
if (modify)
|
|
{
|
|
txtUserCode.Text = userCode;
|
|
txtUserCode.Properties.ReadOnly = true;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 关闭 退出
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
#endregion
|
|
|
|
#region 移动窗体
|
|
private const int WM_NCHITTEST = 0x84;
|
|
private const int HTCLIENT = 0x1;
|
|
private const int HTCAPTION = 0x2;
|
|
//首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
|
|
//系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
|
|
//假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
|
|
//同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
|
|
|
|
//重写窗体,使窗体可以不通过自带标题栏实现移动
|
|
protected override void WndProc(ref Message m)
|
|
{
|
|
|
|
|
|
//当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
|
|
//当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
|
|
//这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
|
|
//注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
|
|
switch (m.Msg)
|
|
{
|
|
case WM_NCHITTEST:
|
|
base.WndProc(ref m);
|
|
if ((int)m.Result == HTCLIENT)
|
|
m.Result = (IntPtr)HTCAPTION;
|
|
return;
|
|
}
|
|
//拦截双击标题栏、移动窗体的系统消息
|
|
if (m.Msg != 0xA3)
|
|
{
|
|
base.WndProc(ref m);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 新增 修改
|
|
private void save_Click(object sender, EventArgs e)
|
|
{
|
|
if (dtDetail.Rows.Count == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("请添加一条数据");
|
|
return;
|
|
}
|
|
string seg = "";
|
|
string userCode = txtUserCode.Text;
|
|
if (string.IsNullOrEmpty(userCode))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("员工不能为空");
|
|
return;
|
|
}
|
|
List<ICSUserInfo> list = new List<ICSUserInfo>();
|
|
foreach (DataRow dr in dtDetail.Rows)
|
|
{
|
|
string id = dr["ID"].ToString();
|
|
string segcode = dr["SEGCODE"].ToString();
|
|
string group = dr["SGroup"].ToString();
|
|
bool add = Convert.ToBoolean(dr["ADD"]);
|
|
|
|
if (string.IsNullOrEmpty(segcode))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("车间不能为空");
|
|
return;
|
|
}
|
|
if (chkFrontLine.Checked)
|
|
{
|
|
//一线员工必须有组
|
|
if (string.IsNullOrEmpty(group))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("组不能为空,一线员工必须有组");
|
|
return;
|
|
}
|
|
}
|
|
if (seg == "")
|
|
{
|
|
seg = segcode;
|
|
}
|
|
else
|
|
{
|
|
if (seg == segcode)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("同一人同一车间不能有多个小组");
|
|
return;
|
|
}
|
|
}
|
|
|
|
ICSUserInfo usr = new ICSUserInfo();
|
|
usr.ID = id;
|
|
usr.UserCode = userCode;
|
|
usr.FrontLine = chkFrontLine.Checked;
|
|
usr.Mail = txtMail.Text;
|
|
usr.Phone = txtPhone.Text;
|
|
usr.SEGCode = segcode;
|
|
usr.SGroup = group;
|
|
usr.ModifyDate = DateTime.Now;
|
|
usr.ModifyUserCode = AppConfig.UserCode;
|
|
usr.WorkPoint = AppConfig.WorkPointCode;
|
|
if (add)
|
|
{
|
|
usr.CreateDate = usr.ModifyDate;
|
|
usr.CreateUserCode = usr.ModifyUserCode;
|
|
}
|
|
else
|
|
{
|
|
usr.CreateDate = Convert.ToDateTime(dr["CreateDate"]);
|
|
usr.CreateUserCode = dr["CreateUserCode"].ToString();
|
|
}
|
|
list.Add(usr);
|
|
}
|
|
ICSUserInfoBLL.DeleteThenInsert(list);
|
|
dtDetail.Rows.Clear();
|
|
ICSBaseSimpleCode.AppshowMessageBox("成功");
|
|
if (modify)
|
|
{
|
|
this.Close();
|
|
}
|
|
else
|
|
{
|
|
#region 人员信息
|
|
string sql1 = @"
|
|
SELECT
|
|
A.UserCode 工号,A.UserName 姓名
|
|
FROM dbo.Sys_User A with(nolock)
|
|
LEFT JOIN ICSUserInfo B with(nolock) ON B.UserCode=A.UserCode AND B.WorkPoint=A.WorkPointCode
|
|
WHERE
|
|
A.WorkPointCode='{0}' AND A.StartFlag='1' AND B.UserCode IS NULL
|
|
ORDER BY A.UserCode
|
|
";
|
|
sql1 = string.Format(sql1, AppConfig.WorkPointCode);
|
|
DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql1).Tables[0];
|
|
txtUserCode.Properties.ValueMember = "工号";
|
|
txtUserCode.Properties.DisplayMember = "工号";
|
|
txtUserCode.Properties.DataSource = dt1;
|
|
txtUserCode.Properties.NullText = "";//空时的值
|
|
txtUserCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
|
|
txtUserCode.Properties.ValidateOnEnterKey = true;//回车确认
|
|
txtUserCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
|
|
txtUserCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
|
|
//自适应宽度
|
|
txtUserCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
#endregion
|
|
}
|
|
//if (this.UserCode == "")
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox("员工不能为空!");
|
|
// return;
|
|
//}
|
|
//if (this.SEGCode == "")
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox("车间不能为空!");
|
|
// return;
|
|
//}
|
|
//if (chkFrontLine.Checked && txtSGroup.Text.Trim() == "")
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox("勾选一线人员后,班组不能为空!");
|
|
// return;
|
|
//}
|
|
//user.UserCode = this.UserCode;
|
|
//user.SEGCode = this.SEGCode;
|
|
//user.FrontLine = chkFrontLine.Checked;
|
|
//user.Mail = txtMail.Text.Trim();
|
|
//user.Phone = txtPhone.Text.Trim();
|
|
//user.SGroup = user.FrontLine ? txtSGroup.Text.Trim() : "";
|
|
//user.ModifyUserCode = AppConfig.UserCode;
|
|
//user.ModifyDate = DateTime.Now;
|
|
//user.WorkPoint = AppConfig.WorkPointCode;
|
|
//bool exist = ICSUserInfoBLL.ExistUserCode(user.UserCode);
|
|
//if (!exist)
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox(user.UserCode + "不存在");
|
|
// return;
|
|
//}
|
|
//bool isNew = ICSUserInfoBLL.AllowAdd(user.UserCode);
|
|
//try
|
|
//{
|
|
// if (Add)
|
|
// {
|
|
// if (!isNew)
|
|
// {
|
|
// ICSBaseSimpleCode.AppshowMessageBox(user.UserCode + "已存在");
|
|
// return;
|
|
// }
|
|
// user.CreateUserCode = user.ModifyUserCode;
|
|
// user.CreateDate = user.ModifyDate;
|
|
// }
|
|
// else
|
|
// {
|
|
// if (isNew)
|
|
// {
|
|
// ICSBaseSimpleCode.AppshowMessageBox(user.UserCode + "不存在");
|
|
// return;
|
|
// }
|
|
// }
|
|
|
|
// int[] iou= ICSUserInfoBLL.AddAndEdit(new List<ICSUserInfo> { user });
|
|
// this.Close();
|
|
// ICSBaseSimpleCode.AppshowMessageBox("成功 新增" + iou[0].ToString()+ "修改"+ iou[1].ToString());
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
//}
|
|
}
|
|
#endregion
|
|
|
|
#region 取消
|
|
private void can_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
#endregion
|
|
|
|
#region 初始化查询条件
|
|
private void init()
|
|
{
|
|
#region 人员信息
|
|
string sql1 = @"
|
|
SELECT
|
|
A.UserCode 工号,A.UserName 姓名
|
|
FROM dbo.Sys_User A with(nolock)
|
|
LEFT JOIN ICSUserInfo B with(nolock) ON B.UserCode=A.UserCode AND B.WorkPoint=A.WorkPointCode
|
|
WHERE
|
|
A.WorkPointCode='{0}' AND A.StartFlag='1' {1}
|
|
ORDER BY A.UserCode
|
|
";
|
|
if (modify)
|
|
{
|
|
sql1 = string.Format(sql1, AppConfig.WorkPointCode, " AND B.UserCode IS NOT NULL");
|
|
}
|
|
else
|
|
{
|
|
sql1 = string.Format(sql1, AppConfig.WorkPointCode, " AND B.UserCode IS NULL");
|
|
}
|
|
DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql1).Tables[0];
|
|
txtUserCode.Properties.ValueMember = "工号";
|
|
txtUserCode.Properties.DisplayMember = "工号";
|
|
txtUserCode.Properties.DataSource = dt1;
|
|
txtUserCode.Properties.NullText = "";//空时的值
|
|
txtUserCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
|
|
txtUserCode.Properties.ValidateOnEnterKey = true;//回车确认
|
|
txtUserCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
|
|
txtUserCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
|
|
//自适应宽度
|
|
txtUserCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
#endregion
|
|
|
|
#region 车间
|
|
string sql2 = @"SELECT SEGCODE 车间代码,SEGDESC 车间描述 FROM dbo.ICSSEG WHERE WorkPoint='{0}' ORDER BY SEGCODE ";
|
|
sql2 = string.Format(sql2, AppConfig.WorkPointCode);
|
|
DataTable dt2 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql2).Tables[0];
|
|
txtSEGCode.ValueMember = "车间代码";
|
|
txtSEGCode.DisplayMember = "车间代码";
|
|
txtSEGCode.DataSource = dt2;
|
|
txtSEGCode.NullText = "";//空时的值
|
|
txtSEGCode.ImmediatePopup = true;//输入值是否马上弹出窗体
|
|
txtSEGCode.ValidateOnEnterKey = true;//回车确认
|
|
txtSEGCode.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
|
|
txtSEGCode.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
|
|
//自适应宽度
|
|
txtSEGCode.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
#endregion
|
|
|
|
#region 班组
|
|
DataTable dt3 = ICSTeamGroupBLL.SelectAll();
|
|
txtSGroup.ValueMember = "班组代码";
|
|
txtSGroup.DisplayMember = "班组代码";
|
|
txtSGroup.DataSource = dt3;
|
|
txtSGroup.NullText = "";//空时的值
|
|
txtSGroup.ImmediatePopup = true;//输入值是否马上弹出窗体
|
|
txtSGroup.ValidateOnEnterKey = true;//回车确认
|
|
txtSGroup.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
|
|
txtSGroup.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
|
|
//自适应宽度
|
|
txtSGroup.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
|
#endregion
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
int hq = 0;
|
|
/// <summary>
|
|
/// 选择人员
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void txtUserCode_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
GridLookUpEdit lookUP = sender as GridLookUpEdit;
|
|
if (!string.IsNullOrWhiteSpace(lookUP.EditValue.ToString()))
|
|
{
|
|
var o = lookUP.Properties.GetRowByKeyValue(lookUP.EditValue);
|
|
if (o is DataRowView)
|
|
{
|
|
//hq++;
|
|
//label4.Text = hq.ToString();
|
|
DataRowView view = o as DataRowView;
|
|
txtUserName.Text = view.Row["姓名"].ToString();
|
|
QueryUserInfo(txtUserCode.Text);
|
|
}
|
|
else
|
|
{
|
|
txtUserName.Text = "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
txtUserName.Text = "";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选择车间
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void txtSEG_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//GridLookUpEdit lookUP = sender as GridLookUpEdit;
|
|
//if (!string.IsNullOrWhiteSpace(lookUP.EditValue.ToString()))
|
|
//{
|
|
// var o = lookUP.Properties.GetRowByKeyValue(lookUP.EditValue);
|
|
// if (o is DataRowView)
|
|
// {
|
|
// DataRowView view = o as DataRowView;
|
|
// txtSEGDesc.Text = view.Row["车间描述"].ToString();
|
|
// SEGCode = view.Row["车间代码"].ToString();
|
|
// }
|
|
// else
|
|
// {
|
|
// txtSEGDesc.Text = "";
|
|
// SEGCode = "";
|
|
// }
|
|
//}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否是一线员工
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void chkFrontLine_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
//if (chkFrontLine.Checked)
|
|
//{
|
|
// txtSGroup.Properties.ReadOnly = false;
|
|
// txtSGroup.Focus();
|
|
//}
|
|
//else
|
|
//{
|
|
// txtSGroup.Text = "";
|
|
// txtSGroup.Properties.ReadOnly = true;
|
|
// txtPhone.SelectAll();
|
|
// txtPhone.Focus();
|
|
//}
|
|
}
|
|
|
|
|
|
private void btnAddRow_Click(object sender, EventArgs e)
|
|
{
|
|
DataRow dr = dtDetail.NewRow();
|
|
dr["isSelect"] = true;
|
|
dr["ID"] = AppConfig.GetGuid();
|
|
dr["SEGCODE"] = "";
|
|
dr["SGroup"] = "";
|
|
dr["ADD"] = true;
|
|
dtDetail.Rows.Add(dr);
|
|
grdDetail.DataSource = dtDetail;
|
|
}
|
|
|
|
private void txtUserCode_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode != Keys.Enter)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QueryUserInfo(txtUserCode.Text);
|
|
}
|
|
|
|
private void btnRemoveRow_Click(object sender, EventArgs e)
|
|
{
|
|
List<string> list = new List<string>();
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect)))
|
|
{
|
|
list.Add(grvDetail.GetRowCellValue(i, colID).ToString());
|
|
}
|
|
}
|
|
if (list.Count == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("请至少选择一行");
|
|
return;
|
|
}
|
|
DataRow[] drs = dtDetail.Select("ID IN ('" + string.Join("','", list) + "')");
|
|
foreach (DataRow dr in drs)
|
|
{
|
|
dtDetail.Rows.Remove(dr);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|