-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnew_房间管理.cs
185 lines (179 loc) · 5.11 KB
/
new_房间管理.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
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
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Warehouse.工具窗体;
namespace Warehouse
{
public partial class new_房间管理 : UITitlePage
{
SystemLog log = new SystemLog();
int Dindex = -1;
public new_房间管理()
{
InitializeComponent();
//给search控件赋值
search1.uiComboBox1.Items.Add("房间ID");
search1.uiComboBox1.Items.Add("房子名字");
//search1.uiComboBox1.Items.Add("负责人名称");
search1.uiComboBox1.SelectedIndex = 0;
grid.ClearAll();
//窗体初始化绑定数据
grid.AddColumn("房间ID", "storage_id");
grid.AddColumn("房间名称", "storage_name");
grid.AddColumn("房间创建时间", "storage_create_time");
grid.AddColumn("房间面积大小(m²)", "storage_area");
grid.AddColumn("房间剩余库柜数", "storage_remain_chest");
grid.AddColumn("房间剩余库位", "storage_remain_seat");
grid.AddColumn("房间备注信息", "storage_comment");
grid.AddColumn("缩写", "storage_sx");
#region 添加修改,删除两个按钮
DataGridViewButtonColumn but = new DataGridViewButtonColumn();
but.HeaderText = "操作"; //设置列表头的名字
but.SetFixedMode(50);//设置按钮大小
but.Name = "UpDate";//设置按钮的名字
but.DefaultCellStyle.NullValue = "修改";
grid.Columns.Add(but);
DataGridViewButtonColumn but1 = new DataGridViewButtonColumn();
but1.HeaderText = "";
but1.SetFixedMode(50);
but1.Name = "Delete";
but1.DefaultCellStyle.NullValue = "删除";
grid.Columns.Add(but1);
#endregion
for (int i = 0; i < grid.ColumnCount; i++) { grid.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; }
AddRow();
//确定按钮和搜索按钮赋值
search1.uiButton1.Click += new EventHandler(this.search1_AddEvent);
search1.SearchButton.Click += new EventHandler(this.search1_SearchEvent);
}
//赋值
private void AddRow()
{
BLL.storage bsta = new BLL.storage();
this.grid.DataSource = bsta.GetModelList("");
this.uiPagination1.DataSource = bsta.GetModelList("");
uiPagination1.ActivePage = 1;
}
//搜索
private void search1_SearchEvent(object sender, EventArgs e)
{
if (search1.SearchBox.Text.Trim() != "")
{
int f = search1.uiComboBox1.SelectedIndex;
string leixing = null;
string leixing_log = null;
if (f == 0)
{
leixing = "storage_id";
leixing_log = "房间ID";
}
if (f == 1)
{
leixing = "storage_name";
leixing_log = "房间名称";
}
string m = search1.SearchBox.Text.Trim();
string str = leixing.Trim() +
"=" + "\"" + search1.SearchBox.Text.Trim() + "\"";
BLL.storage dep = new BLL.storage();
uiPagination1.DataSource = dep.GetModelList(str);
grid.DataSource = dep.GetModelList(str);
log.WriteLog(4, Session.staffId, DateTime.Now.ToString("yyyy-MM-dd"), "房间管理", "查询" + leixing_log, "");
}
}
private void search1_AddEvent(object sender, EventArgs e)
{
FormEditRoom room = new FormEditRoom();
room.ShowDialog();
if (room.IsOK)
{
BLL.storage sr_ = new BLL.storage();
bool m = sr_.Add(room.StorageModel);
if (m == true)
{
UIMessageBox.ShowSuccess("新增成功");
}
else
{
UIMessageBox.ShowWarning("新增失败");
}
}
}
//翻页
private void uiPagination1_PageChanged(object sender, object pagingSource, int pageIndex, int count)
{
grid.DataSource = pagingSource;
}
//Grid的点击事件
private void grid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//更新
if (grid.Columns[e.ColumnIndex].Name == "UpDate" && e.RowIndex >= 0)
{
//获得选择的行
int rowIndex = e.RowIndex;
string id = grid.CurrentRow.Cells[2].Value.ToString();
//string id = grid.Rows[rowIndex].Cells[0].Value.ToString().Trim();
Model.storage sta = new Model.storage();
sta.storage_id = id;
//弹出对话框
FormEditRoom room = new FormEditRoom();
bool m = room.FuZhi(id);
if (m != true)
{
UIMessageBox.ShowWarning("错误", true);
}
else
{
room.ShowDialog();
}
if (room.IsOK)
{
BLL.storage bllstorage = new BLL.storage();
bool k = bllstorage.Update(room.StorageModel);
//更改成功
if (k)
{
ShowSuccessDialog("更改成功");
}
//更改失败
else
{
UIMessageBox.ShowError("编辑失败");
}
}
else
{
UIMessageBox.ShowError("编辑失败");
}
}
//删除
if (grid.Columns[e.ColumnIndex].Name == "Delete" && e.RowIndex >= 0)
{
if (ShowAskDialog("此操作不可恢复。是否确认删除?"))
{
int rowIndex = e.RowIndex;
string id = grid.CurrentRow.Cells[2].Value.ToString();
BLL.storage bllstorage = new BLL.storage();
bool die = bllstorage.Delete(id);
if (die)
{
ShowSuccessDialog("删除成功");
AddRow();
}
else
{
ShowErrorDialog("删除失败");
}
}
}
}
}
}