预约系统(九) 管理页面--部门管理
部门管理页面功能与会议室管理差不多。
部门管理页面代码:
1 <!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta name="viewport" content="width=device-width" /> 6 <title>部门管理</title> 7 8 <script src="~/Scripts/jquery-1.8.2.min.js"></script> 9 @*<script src="~/Scripts/jquery.min.js"></script>*@ 10 11 <script src="~/Scripts/jquery.easyui.min.js"></script> 12 13 <link href="~/Content/DarkBlue/easyui.css" rel="stylesheet" /> 14 <link href="~/Content/DarkBlue/icon.css" rel="stylesheet" /> 15 <script src="~/Scripts/easyui-lang-zh_CN.js"></script> 16 17 <style type="text/css"> 18 .tb_dia{ width:400px; margin:0px auto; font-size:15px;} 19 .tb_dia td{ height:30px; line-height:30px;} 20 .tb_lable{ width:80px; text-align:right;} 21 </style> 22 23 </head> 24 <body style="padding-top: 10px;"> 25 26 <div data-options="region:'center'" style="overflow: hidden;"> 27 28 <div id="containter" style="width: 1000px; height: auto; margin: 0px auto;"> 29 30 <!--panel--> 31 <div class="easyui-panel" title="部门管理" data-options="iconCls:'icon-filter'" style="width:100%;max-width:960px;padding:10px 15px;"> 32 33 <!--表格--> 34 <table id="dg" class="easyui-datagrid" style="height:450px;" data-options="method:'post',toolbar: '#tb_search',singleSelect: true"> 35 <thead> 36 <tr> 37 <th data-options="field:'Id',width:80,align:'center'">编号</th> 38 <th data-options="field:'Bm_no',width:100,align:'center'">部门代号</th> 39 <th data-options="field:'Bm_mc',width:100,align:'center'">部门名称</th> 40 <th data-options="field:'Adder',width:100,align:'center'">创建人</th> 41 </tr> 42 </thead> 43 </table> 44 45 <!--toolbar--> 46 <div id="tb_search" style="padding:2px 15px;"> 47 <div style="margin-bottom:1px;font-weight:bold;"> 48 <a href="#" id="add" class="easyui-linkbutton" data-options="iconCls:'icon-add'" style="width:100px; height:30px; background-color:#0993D3;">添加</a> 49 <a href="#" id="del" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" style="width:100px; height:30px; background-color:#0993D3;">删除</a> 50 <a href="#" id="reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" style="width:100px; height:30px; background-color:#0993D3;">刷新</a> 51 </div> 52 </div> 53 54 </div> 55 56 <!--add dialog--> 57 <div id="dia_add" style="padding-top:15px;display:none;"> 58 <div id="dia_add_Content" style="width:450px; margin:0px auto;"> 59 <table class="tb_dia"> 60 <tr><td class="tb_lable">部门代号:</td><td><input id="add_bmno" class="easyui-textbox" style="width:250px" data-options="required:true"></td></tr> 61 <tr><td class="tb_lable">部门名称:</td><td><input id="add_bmmc" class="easyui-textbox" style="width:250px" data-options="required:true"></td></tr> 62 63 </table> 64 </div> 65 </div> 66 67 </div> 68 69 </div> 70 71 72 </body> 73 </html>
表格绑定
js:
1 $(function () { 2 // 3 $('#dg').datagrid({ 4 url: '/Manage/Return_BmAll' 5 }); 6 })
controller:
1 /// <summary> 2 /// 部门展示 3 /// </summary> 4 /// <returns></returns> 5 public ActionResult Return_BmAll() 6 { 7 List<T_Bm> bmlist = new BmService().ReturnAll(); 8 return Json(bmlist, JsonRequestBehavior.AllowGet); 9 }
bll:
1 public List<T_Bm> ReturnAll() 2 { 3 return bmdal.ReturnAll(); 4 }
dal:
1 /// <summary> 2 /// 返回所有部门的信息 3 /// </summary> 4 /// <returns></returns> 5 public List<T_Bm> ReturnAll() 6 { 7 string sql = " select * from T_bm "; 8 9 DataTable dt = SqlHelper.SelectSqlReturnDataTable(sql, CommandType.Text); 10 List<T_Bm> bmlist = null; 11 if(dt.Rows.Count>0) 12 { 13 bmlist = new List<T_Bm>(); 14 T_Bm bm = null; 15 foreach(DataRow row in dt.Rows) 16 { 17 bm = new T_Bm(); 18 LoadEntity(row, bm); 19 bmlist.Add(bm); 20 } 21 } 22 return bmlist; 23 } 24 25 /// <summary> 26 /// 初始化 27 /// </summary> 28 /// <param name="row"></param> 29 /// <param name="bm"></param> 30 public void LoadEntity(DataRow row, T_Bm bm) 31 { 32 bm.Id = Convert.ToInt32(row["id"].ToString()); 33 bm.Bm_no = row["bm_no"] != DBNull.Value ? row["bm_no"].ToString() : string.Empty; 34 bm.Bm_mc = row["bm_mc"] != DBNull.Value ? row["bm_mc"].ToString() : string.Empty; 35 bm.Adder = row["adder"] != DBNull.Value ? row["adder"].ToString() : string.Empty; 36 bm.Add_time = Convert.ToDateTime(row["add_time"].ToString()); 37 }
添加功能
js:
1 //add 2 $("#add").click(function () { 3 $("#dia_add").dialog({ 4 title: "添加会议室", 5 width: 500, 6 height: 250, 7 buttons: [{ 8 text: '添加', 9 iconCls: 'icon-ok', 10 handler: function () { 11 $.messager.confirm('确认', '您确认要添加吗?', function (r) { 12 if (r) { 13 //添加 14 $.ajax({ 15 url: "/Manage/Bm_add", 16 type: "post", 17 data: { 18 "bm_no": $("#add_bmno").textbox("getText"), 19 "bm_mc": $("#add_bmmc").textbox("getText") 20 }, 21 success: function (data) { 22 // 23 if (data == "ok") { 24 // 25 $.messager.alert("提示", "添加成功!", "info", function () { 26 // 27 $("#add_bmno").textbox("setText", ""); 28 $("#add_bmmc").textbox("setText", ""); 29 $('#dia_add').dialog('close'); 30 $('#dg').datagrid('reload'); 31 }) 32 } 33 else { 34 // 35 $.messager.alert("提示", "添加异常,联系管理员!", "info"); 36 } 37 } 38 }) 39 } 40 }) 41 } 42 }, { 43 text: '取消', 44 iconCls: 'icon-no', 45 handler: function () { 46 //关闭之前要清空 47 $("#add_bmno").textbox("setText",""); 48 $("#add_bmmc").textbox("setText",""); 49 $('#dia_add').dialog('close'); 50 } 51 }], 52 modal: true 53 }) 54 })
controller:
1 /// <summary> 2 /// 部门添加 3 /// </summary> 4 /// <returns></returns> 5 public ActionResult Bm_add() 6 { 7 T_Bm bm = new T_Bm(); 8 bm.Bm_no = Request["bm_no"]; 9 bm.Bm_mc = Request["bm_mc"]; 10 bm.Adder = ((T_UserInfo)Session["UserInfo"]).User_FullName; 11 12 if(new BmService().InsertIntoTab(bm) > 0) 13 { 14 return Content("ok"); 15 } 16 else 17 { 18 return Content("no"); 19 } 20 }
bll:
1 public int InsertIntoTab(T_Bm bm) 2 { 3 return bmdal.InsertIntoTab(bm); 4 }
dal:
1 /// <summary> 2 /// 添加部门信息 3 /// </summary> 4 /// <param name="bm"></param> 5 /// <returns></returns> 6 public int InsertIntoTab(T_Bm bm) 7 { 8 string sql = " insert into T_bm (bm_no,bm_mc,adder) values (@bm_no,@bm_mc,@adder) "; 9 SqlParameter[] pars ={ 10 new SqlParameter("@bm_no",SqlDbType.NVarChar,50), 11 new SqlParameter("@bm_mc",SqlDbType.NVarChar,50), 12 new SqlParameter("@adder",SqlDbType.NVarChar,50) 13 }; 14 pars[0].Value = bm.Bm_no; 15 pars[1].Value = bm.Bm_mc; 16 pars[2].Value = bm.Adder; 17 18 return SqlHelper.ExcuteSQLReturnInt(sql, CommandType.Text, pars); 19 }
删除功能
js:
1 //del 2 $("#del").click(function () { 3 4 //删除 5 var row = $("#dg").datagrid('getSelected'); 6 if (row) { 7 8 $.messager.confirm('删除', '您确认想要删除记录吗?', function (r) { 9 if (r) { 10 $.ajax({ 11 url: "/Manage/Bm_del", 12 type: "post", 13 data: { 14 "id": row.Id 15 }, 16 success:function(data){ 17 if (data == "ok") { 18 $.messager.alert('提示', ' 删除成功!', 'info', function () { 19 var index = $("#dg").datagrid('getRowIndex', row); 20 $("#dg").datagrid('deleteRow', index); 21 }) 22 } else { 23 //失败 24 $.messager.alert('提示', ' 删除失败,请重新选择', 'warning'); 25 } 26 } 27 }) 28 } 29 }) 30 31 } else { 32 $.messager.alert('提示', ' 请选择要删除的行!', 'warning'); 33 } 34 })
controller:
1 /// <summary> 2 /// 部门删除 3 /// </summary> 4 /// <returns></returns> 5 public ActionResult Bm_del() 6 { 7 int id = Convert.ToInt32(Request["id"]); 8 if (new BmService().Del_infoByid(id) > 0) 9 { 10 return Content("ok"); 11 } 12 else 13 { 14 return Content("no"); 15 } 16 }
bll:
1 public int Del_infoByid(int id) 2 { 3 return bmdal.Del_infoByid(id); 4 }
dal:
1 /// <summary> 2 /// 删除一条记录 3 /// </summary> 4 /// <param name="id"></param> 5 /// <returns></returns> 6 public int Del_infoByid(int id) 7 { 8 string sql = " delete from T_bm where id =@id "; 9 SqlParameter[] pars ={ 10 new SqlParameter("@id",SqlDbType.Int) 11 }; 12 pars[0].Value = id; 13 return SqlHelper.ExcuteSQLReturnInt(sql, CommandType.Text, pars); 14 }
刷新功能
//reload $("#reload").click(function () { $('#dg').datagrid('reload'); })
You are never too old to set another goal or to dream a new dream!!!