/
SystemManageEditForm.cs
134 lines (118 loc) · 4.19 KB
/
SystemManageEditForm.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using zhuhai.model;
using zhuhai.service;
using DevExpress.XtraEditors.Controls;
using zhuhai.util;
namespace zhuhai
{
public partial class SystemManageEditForm : DevExpress.XtraEditors.XtraForm
{
private int id = 0;
public int Id {
get {return id;}
set {id = value;}
}
private SystemManageService smService;
public SystemManageEditForm()
{
InitializeComponent();
init();
}
public SystemManageEditForm(SystemManage sys)
{
InitializeComponent();
init();
Id = sys.Id;
SystemManage sm = sys;
//编辑,根据id取出原来的数据,显示出来
textEdit_userName.Text = sm.UserName;
textEdit_password.Text = sm.Password ;
textEdit_name.Text = sm.Name;
textEdit_IDCard.Text = sm.IdCard;
comboBoxEdit_type.SelectedIndex = smService.getIndex(sm.Type);
//不可修改用户名
textEdit_userName.Properties.ReadOnly = true;
}
public void init()
{
smService = SystemManageService.getInstance();
comboBoxEdit_type.Properties.Items.AddRange(smService.getTypes().ToArray());
//设置ComboBoxEdit下拉不可编辑
comboBoxEdit_type.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
comboBoxEdit_type.SelectedIndex = 0;
}
private void simpleButton_add_Click(object sender, EventArgs e)
{
SystemManage sm = new SystemManage();
sm.UserName = textEdit_userName.Text;
sm.Password = textEdit_password.Text;
sm.Name = textEdit_name.Text;
sm.IdCard = textEdit_IDCard.Text;
if (String.IsNullOrEmpty(sm.UserName))
{
MessageBox.Show("用户名不能为空!", "提示");
return;
}
if (smService.findRowByIdAndName(id, sm.UserName))
{
MessageBox.Show("用户名已重复!", "提示");
return;
}
if (String.IsNullOrEmpty(sm.Password))
{
MessageBox.Show("密码不能为空!", "提示");
return;
}
if (String.IsNullOrEmpty(sm.Name))
{
MessageBox.Show("姓名不能为空!", "提示");
return;
}
if (String.IsNullOrEmpty(sm.IdCard))
{
MessageBox.Show("证件号不能为空!", "提示");
return;
}
if (comboBoxEdit_type.SelectedIndex == -1 || comboBoxEdit_type.SelectedIndex == 0)
{
MessageBox.Show("请选择类型!", "提示");
return;
}
sm.Type = (smService.getTypes())[comboBoxEdit_type.SelectedIndex].Key;
sm.Id = Id;
//保存
if (Id == 0 && smService.addRow(sm) == true)
{
MessageBox.Show("保存成功!", "提示");
LogService.getInstance().log("新增,用户名为" + sm.UserName, ModuleConstant.SystemManage_MODULE);
this.Close();
}
//编辑
else if (Id != 0 && smService.modifyRow(sm) == true)
{
MessageBox.Show("保存成功!", "提示");
LogService.getInstance().log("修改,用户名为" + sm.UserName, ModuleConstant.SystemManage_MODULE);
this.Close();
}
else
{
MessageBox.Show("保存失败!", "提示");
}
}
private void simpleButton_cancel_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确定要退出吗?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.Close();
}
}
}
}