using DevExpress.DocumentView.Native; using DevExpress.Mvvm.POCO; using Furion.LinqBuilder; using System.Text.RegularExpressions; using Yw.Entity; namespace HStation.WinFrmUI.Organize { public partial class EmloyeeInfoCtrl : UserControl { /// /// / /// public EmloyeeInfoCtrl() { InitializeComponent(); } HStation.BLL.EmployeeMain _service; HStation.Vmo.EmployeeMain _employee; int staffstatus; public void ShowBangDingData(HStation.Vmo.EmployeeMain employee)//展示本控件数据 { NametextEdit.Text = employee.FirstName;//姓名 textEditBianHao.Text = employee.ErpCode;//编号 ZhiWutextEdit.Text = employee.PositonName;//职务 DianHuatextEdit.Text = employee.Telephone;//电话 textEditQianMing.Text = employee.DrawSignal;//签名 YouXiangtextEdit.Text = employee.Email;//邮箱 ChongZhiimageComboBoxEdit.SelectedIndex = employee.RequirePasswordReset;//重置密码 if (employee.StaffStatus.ToString() == "在职") { staffstatus = 1; } else { staffstatus = 0; } ZhuangTaiimageComboBoxEdit.SelectedIndex = staffstatus;//在职状态 EnglishNametextEdit.Text = employee.LastName;//姓名 英文 } public HStation.Vmo.EmployeeMain ReadCtrlData(out string error)//传入本控件数据 { error = ""; HStation.Vmo.EmployeeMain employee = new Vmo.EmployeeMain(); dxValidationProviderBianHao.Validate(); if (String.IsNullOrEmpty(NametextEdit.Text) || String.IsNullOrEmpty(textEditBianHao.Text) ) { error = "姓名或编号未填写!"; return null; } if (!String.IsNullOrEmpty(DianHuatextEdit.Text)) { if (DianHuatextEdit.Text.Length != 11) { error = "请输入正确电话号码!"; return null; } foreach (char _Telephone in DianHuatextEdit.Text) { if (_Telephone < '0' && _Telephone > '9') { error = "请输入正确电话号码!"; return null; } } } if (!Regex.IsMatch(YouXiangtextEdit.Text, @"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$") && !String.IsNullOrEmpty(YouXiangtextEdit.Text)) { error = "请输入正确的邮箱!"; return null; } employee.FirstName = NametextEdit.Text; employee.ErpCode = textEditBianHao.Text; employee.PositonName = ZhiWutextEdit.Text; employee.Telephone = DianHuatextEdit.Text; employee.DrawSignal = textEditQianMing.Text; employee.Email = YouXiangtextEdit.Text; employee.RequirePasswordReset = ChongZhiimageComboBoxEdit.SelectedIndex; employee.StaffStatus = Vmo.eJobType.exist; employee.LastName = EnglishNametextEdit.Text; return employee; } public HStation.Vmo.EmployeeMain SetBindingData(HStation.Vmo.EmployeeMain employee, out string error) { error = ""; this._employee = employee; if (_employee.ErpCode == null)//添加 { //_employee.AddTime = DateTime.Now; //_employee.LastModifyTime = DateTime.Now.ToString(); _employee = ReadCtrlData(out error); if (_employee == null)//出现错误并返回null和错误 { return null; } if (!string.IsNullOrEmpty(error)) { return null; } if (!checkEditCreateLogin.Checked) //没有选中创建用户 { //loginUserInfoCtrl.SetNoInput();//loginUserInfoCtrl控件不可编辑 return _employee; } //loginUserInfoCtrl.SetOffInput();//loginUserInfoCtrl控件可编辑 if (loginUserInfoCtrl.NewBindingData(_employee.LoginAccount, out error) == null)//出现错误并返回null和错误 { return null; } return _employee; } else//修改 { //_employee.LastModifyTime = DateTime.Now.ToString(); _employee = ReadCtrlData(out error); if (!string.IsNullOrEmpty(error)) { return null; } if (!checkEditCreateLogin.Checked)//判断是否新建用户 { return _employee; } else { if (loginUserInfoCtrl.NewBindingData(_employee.LoginAccount, out error) != null)//出现错误并返回null和错误 { return null; } } return _employee; } } public void GetBindingData(HStation.Vmo.EmployeeMain employee, out string error)//修改时展示原信息 { error = ""; if (employee == null) { error = "入参为空!"; return; } ShowBangDingData(employee); if (employee.LoginAccount != null) { loginUserInfoCtrl.SetNoInput(); checkEditCreateLogin.Visible = false; } //if (!checkEditCreateLogin.Checked)//判断该控件是否可编辑 //{ // loginUserInfoCtrl.SetNoInput(); //} //else //{ // loginUserInfoCtrl.SetOffInput(); //} } //只读 public void SetOnlyRead(HStation.Vmo.EmployeeMain employee, out string error) { error = ""; if (employee == null) { error = "入参为空!"; return; } ShowBangDingData(employee); } //public HStation.Vmo.EmployeeMain GetBindingData(out string error) //{ // if (this._employee == null) // { // error = "入参为空"; // return null; // } // _employee.FirstName = NametextEdit.Text; // _employee.ErpCode = textEditBianHao.Text; // _employee.PositonName = ZhiWutextEdit.Text; // _employee.Telephone = DianHuatextEdit.Text; // _employee.DrawSignal = textEditQianMing.Text; // _employee.Email = YouXiangtextEdit.Text; // _employee.RequirePasswordReset = ChongZhiimageComboBoxEdit.SelectedIndex; // _employee.StaffStatus = ZhuangTaiimageComboBoxEdit.SelectedIndex; // _employee.LastName = EnglishNametextEdit.Text; // if (!dxValidationProviderBianHao.Validate()) // { // error = "wei......"; // return null; // } // error = "ing...."; // return _employee; //} private void TouXiangpictureEdit_Click(object sender, EventArgs e) { if (QianMingopenFileDialog.ShowDialog() != DialogResult.OK) { return; } string QianMingfilePath = QianMingopenFileDialog.FileName; if (QianMingfilePath == null) { return; } TouXiangpictureEdit.Image = Image.FromFile(QianMingfilePath); } private void checkEditCreateLogin_CheckedChanged(object sender, EventArgs e)//按钮状态发生改变时 { if (checkEditCreateLogin.Checked) { loginUserInfoCtrl.SetOffInput(); } else { loginUserInfoCtrl.SetNoInput(); } } } }