锐腾搅拌上料功能
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.

349 lines
14 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 FormICSUserInfoAdd : DevExpress.XtraEditors.XtraForm
{
string UserCode = "";
string SEGCode = "";
ICSUserInfo user = new ICSUserInfo();
bool Add = true;
#region 构造函数
public FormICSUserInfoAdd()
{
InitializeComponent();
this.UserCode = "";
Add = true;
}
public FormICSUserInfoAdd(String userid)
{
InitializeComponent();
this.UserCode = userid;
Add = false;
}
#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 (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 FormICSUserInfoAdd_Load(object sender, EventArgs e)
{
init();
if (Add)
{
lblTitle.Text = "新增";
}
else
{
//只能修改手机号,邮件,车间
lblTitle.Text = "修改";
txtUserCode.Properties.ReadOnly = true;
chkFrontLine.Enabled = false;
txtSGroup.Properties.ReadOnly = true;
DataTable dt = ICSUserInfoBLL.Select(UserCode);
if (dt == null || dt.Rows.Count == 0)
{
throw new Exception("没有用户数据");
}
txtUserCode.Text = dt.Rows[0]["UserCode"].ToString();
txtUserName.Text = dt.Rows[0]["UserName"].ToString();
txtSEGCode.Text = dt.Rows[0]["SEGCode"].ToString();
txtSEGDesc.Text = dt.Rows[0]["SEGDesc"].ToString();
chkFrontLine.Checked = Convert.ToBoolean(dt.Rows[0]["FrontLine"]);
txtSGroup.Text = dt.Rows[0]["SGroup"].ToString();
txtPhone.Text = dt.Rows[0]["Phone"].ToString();
txtMail.Text = dt.Rows[0]["Mail"].ToString();
}
this.chkFrontLine.CheckedChanged += new System.EventHandler(this.chkFrontLine_CheckedChanged);
}
#endregion
#region 初始化查询条件
private void init()
{
#region 人员信息
string sql1 = @"
SELECT A.UserCode 工号,A.UserName 姓名 FROM dbo.Sys_User A with(nolock)
LEFT JOIN dbo.ICSUserInfo B with(nolock) ON A.UserCode=B.UserCode AND A.WorkPointCode=B.WorkPoint
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
#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.Properties.ValueMember = "车间代码";
txtSEGCode.Properties.DisplayMember = "车间代码";
txtSEGCode.Properties.DataSource = dt2;
txtSEGCode.Properties.NullText = "";//空时的值
txtSEGCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
txtSEGCode.Properties.ValidateOnEnterKey = true;//回车确认
txtSEGCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
txtSEGCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
//自适应宽度
txtSEGCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
#endregion
#region 班组
string sql3 = @"SELECT EnumKey ,EnumValue AS 班组代码,EnumText AS 班组说明 FROM dbo.Sys_EnumValues WHERE EnumKey='00022' AND StartFlag=1 AND WorkPointCode='{0}' ORDER BY EnumKey ";
sql3 = string.Format(sql3, AppConfig.WorkPointCode);
DataTable dt3 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql3).Tables[0];
txtSGroup.Properties.ValueMember = "班组代码";
txtSGroup.Properties.DisplayMember = "班组说明";
txtSGroup.Properties.DataSource = dt3;
txtSGroup.Properties.NullText = "";//空时的值
txtSGroup.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
txtSGroup.Properties.ValidateOnEnterKey = true;//回车确认
txtSGroup.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
txtSGroup.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
//自适应宽度
txtSGroup.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
#endregion
}
#endregion
/// <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)
{
DataRowView view = o as DataRowView;
txtUserName.Text = view.Row["姓名"].ToString();
UserCode = view.Row["工号"].ToString();
}
else
{
txtUserName.Text = "";
UserCode = "";
}
}
}
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();
}
}
}
}