1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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
    {
        /// <summary>
        /// /
        /// </summary>
        public EmloyeeInfoCtrl()
        {
            InitializeComponent();
 
 
        }
        HStation.BLL.EmployeeMain _service;
        HStation.Vmo.EmployeeMain _employee;
        int staffstatus;
        public void ShowBangDingData(HStation.Vmo.EmployeeMain employee)//展示本控件数据
        {
            //HStation.WinFrmUI.Organize.EmployeeViewModel _employee = new HStation.WinFrmUI.Organize.EmployeeViewModel(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 == Vmo.eJobType.exist)
            {
                ZhuangTaiimageComboBoxEdit.SelectedIndex = 1;
            }
            else
            {
                ZhuangTaiimageComboBoxEdit.SelectedIndex = 0;
            }
            EnglishNametextEdit.Text = employee.LastName;//姓名 英文
        }
 
        public HStation.Vmo.EmployeeMain ReadCtrlData(out string error)//传入本控件数据
        {
            error = "";
            HStation.Vmo.EmployeeMain employee = new Vmo.EmployeeMain();
            employee = _employee;
            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.LastModifyTime = DateTime.Now.ToString();
            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;
            if (ZhuangTaiimageComboBoxEdit.SelectedIndex == 1)
            {
                employee.StaffStatus = Vmo.eJobType.exist;
            }else
            {
                employee.StaffStatus = Vmo.eJobType.leave;
            }
            employee.LastName = EnglishNametextEdit.Text;
            return employee;
        }
 
 
 
        public HStation.Vmo.EmployeeMain SetBindingData(HStation.Vmo.EmployeeMain employee, out string error)
        {
            error = "";
            
            this._employee = employee;
            if (_employee.EmployeeID == 0)
            {
                //_employee.AddTime = DateTime.Now;
                //_employee.LastModifyTime = DateTime.Now.ToString();
                _employee = ReadCtrlData(out error);
                employee.AddTime = DateTime.Now;
                if (!string.IsNullOrEmpty(error))
                {
                    return null;
                }
                if (!checkEditCreateLogin.Checked)//判断是否新建用户
                {
                    return _employee;
                }
                else
                {
                    if (loginUserInfoCtrl.NewBindingData(_employee.User, out error) == null)//出现错误并返回null和错误
                    {
                        return null;
                    }
                }
                return _employee;
            }
            else
            {
                _employee = ReadCtrlData(out error);
                if (_employee.EmployeeID == 0)//出现错误并返回null和错误
                {
                    error = "出现错误!ID为0!";
                    return null;
                }
                if (!string.IsNullOrEmpty(error))
                {
                    return null;
                }
                if (!checkEditCreateLogin.Checked)//判断是否新建用户
                {
                    return _employee;
                }
                else
                {
                    if (loginUserInfoCtrl.NewBindingData(_employee.User, 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.User != null)
            {
                loginUserInfoCtrl.SetNoInput();
                checkEditCreateLogin.Visible = false;
            }
        }
 
 
        //只读
        public void SetOnlyRead(HStation.Vmo.EmployeeMain employee, out string error)
        {
            error = "";
            if (employee == null)
            {
                error = "入参为空!";
                return;
            }
            ShowBangDingData(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();
            }
        }
    }
}