在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
具体效果如下: 首页
添加值班信息页面:
编辑 值班信息页面
控制器源码1 private DoctorDutyDao doctorDutyDao = new DoctorDutyDao(); 2 private TimeDao timeDao = new TimeDao(); 3 4 //展示首页 5 public ActionResult Index() 6 { 7 SetupLayoutViewData(750, 700); 8 //查询时间表 9 Time queryTime = new Time(); 10 if (UserContext.CurrentUser != null) 11 { 12 queryTime.CompanyId = UserContext.CurrentUser.Id; 13 } 14 IList<Time> times = timeDao.QueryForList(queryTime); 15 //生成JS 16 string js = @"$(function () {"; 17 js += @"$('#grid').datagrid({"; 18 js += @"url: 'QueryForPage',"; 19 js += @"singleSelect: true,"; 20 js += @"fitColumns: true,"; 21 js += @"columns: [["; 22 js += @"{ field: 'Id', title: '选择', hidden: true, width: 100, align: 'center',formatter:radioFormatter },"; 23 js += @"{ field: 'DoctorName', title: '医生名称', width: 100, align: 'center',formatter:PageUI.RenderEditTrigger },"; 24 js += @"{ field: 'DoctorPosition', title: '职称', width: 100, align: 'center' },"; 25 js += @"{ field: 'Date', title: '起始日期', width: 100, align: 'center' },"; 26 js += @"{ field: 'EndDate', title: '结束日期', width: 100, align: 'center' }"; 27 28 //循环时间表 29 for (int i = 0; i < times.Count; i++) 30 { //doctorDutyCell+i 方法,是关键点,该方法内部 调用 index 母版页的 doctorDutyCell 方法 31 js += @",{ field: 'Time" + (i + 1) + "', title: '" + times[i].Value + "', width: 100, align: 'center',formatter:doctorDutyCell" + (i + 1) + " }"; 32 } 33 js += @" ]]"; 34 js += @" });"; 35 js += @"});;"; 36 37 //循环时间表创建方法 38 for (int i = 0; i < times.Count; i++) 39 { 40 js += @" function doctorDutyCell" + (i + 1) + "(value, row, index) {"; 41 js += @"return doctorDutyCell(value, row, index, '" + times[i].Value + "'," + i + ");"; 42 js += @"}"; 43 } 44 45 46 ViewBag.js = js; 47 return View(); 48 } 49 50 /// <summary> 51 /// 返回数据,填充,添加页 的列表。 52 /// </summary> 53 /// <returns></returns> 54 public ActionResult GetByCompany() 55 { 56 57 IList<DoctorDuty> model; 58 59 DoctorDuty query = new DoctorDuty(); 60 long CompanyId = UserContext.CurrentUser.Id; 61 model = doctorDutyDao.GetByCompany(CompanyId); 62 foreach (DoctorDuty doctorDuty in model) 63 { 64 doctorDuty.Date = DateTime.Now.ToString("yyyy-MM-dd"); 65 doctorDuty.EndDate = DateTime.Now.ToString("yyyy-MM-dd"); 66 67 } 68 return Json(model); 69 70 } 71 72 /// <summary> 73 /// 查询,时间 下拉框 74 /// </summary> 75 /// <param name="Name"></param> 76 /// <returns></returns> 77 public ActionResult QueryForTimeListDoctorDuty(string Name) 78 { 79 Time queryTime = new Time(); 80 queryTime.CompanyId = UserContext.CurrentUser.Id; 81 IList<Time> times = timeDao.QueryForListDoctorDuty(queryTime); 82 return Json(times); 83 } 84 85 86 /// <summary> 87 /// 添加医生值班信息 88 /// </summary> 89 /// <returns></returns> 90 public ActionResult AddIndex() 91 { 92 #region zhongjh 生成js 93 //查询时间表 94 Time queryTime = new Time(); 95 queryTime.CompanyId = UserContext.CurrentUser.Id; 96 IList<Time> times = timeDao.QueryForList(queryTime); 97 #region zhongjh 生成表格的js 98 //生成JS 99 string gridJs = @"var url = '@Url.Action(""GetByCompany"")';"; 100 gridJs += @" $('#grid').datagrid({"; 101 gridJs += "url:'GetByCompany',"; 102 gridJs += @"singleSelect: false,"; 103 gridJs += @"fitColumns: true,"; 104 gridJs += @"striped: true,"; 105 gridJs += @"fit: true,"; 106 gridJs += "columns:[["; 107 gridJs += "{field:'Id',title:'选择',checkbox:'true',width:100,align:'center'},"; 108 gridJs += "{field:'DoctorName',title:'医生名称',width:100,align:'center'},"; 109 gridJs += "{field:'DoctorPosition',title:'职称',width:50,align:'center'},"; 110 gridJs += "{field:'Date',title:'起始日期',width:100,formatter:setDate},"; 111 gridJs += "{ field: 'EndDate', title: '结束日期', width: 100, align: 'center',formatter:setEndDate }"; 112 113 //循环时间表 114 for (int i = 0; i < times.Count; i++) 115 { //formatter:function(value,row,index){ return '<input type=checkbox checked=checked id='+row._Id+'_" + (i + 1) + " >' 方法,添加的时候,复选框都勾选 116 gridJs += ",{ field: 'Time" + (i + 1) + "', title: '" + times[i].Value + "', width: 80,formatter:function(value,row,index){ return '<input type=checkbox checked=checked id='+row._Id+'_" + (i + 1) + " >';}}"; 117 } 118 gridJs += ",{field:'Remarks',title:'备注',width:100,formatter:setRemarks}"; 119 120 gridJs += "]]"; 121 gridJs += "}); "; 122 ViewBag.gridJs = gridJs; 123 124 125 126 127 string gridJs3 = ""; 128 //循环时间表 var time1 = document.getElementById(n._Id + "_1").checked != false ? "9:00-11:00" : "false"; 129 130 for (int i = 0; i < times.Count; i++) 131 { //获取,保存的数据,因为保存的数据主要是,是否勾选复选框 132 gridJs3 += "var time" + (i + 1) + " = document.getElementById(n._Id + \"_" + (i + 1) + "\").checked != false ? \"" + times[i].Value + "\" : \"false\";"; 133 134 } 135 136 gridJs3 += " value += n._Id + \",\" + $(\"#\" + n._Id + \"_date\").val() + \",\" + $(\"#\" + n._Id + \"_Enddate\").val() + \",\" + ( "; 137 138 for (int i = 0; i < times.Count; i++) 139 { 140 if (i == times.Count - 1) 141 { 142 gridJs3 += "time" + (i + 1) + ") + \",\" + encodeURI(encodeURI($(\"#\" + n._Id + \"_remarks\").val())) + \"*\";"; 143 } 144 else 145 { 146 gridJs3 += "time" + (i + 1) + "+\"_\"+"; 147 } 148 149 } 150 151 152 ViewBag.gridJs3 = gridJs3; 153 154 #endregion 155 156 #region zhongjh 保存的js 157 string saveJs = ""; 158 //循环时间表 159 for (int i = 0; i < times.Count; i++) 160 { 161 saveJs += @"var time" + (i + 1) + " = $(\"#\"+n.id+\"_" + (i + 1) + "\").attr(\"checked\") != undefined?\"" + times[i].Value + "\":\"false\";"; 162 } 163 string saveJsFu = ""; 164 for (int i = 0; i < times.Count; i++) 165 { 166 if (i == 0) 167 { 168 saveJsFu += "\"+(time" + (i + 1) + "+\""; 169 } 170 else if (i == times.Count - 1) 171 { 172 saveJsFu += "_\"+time" + (i + 1) + ")+\""; 173 } 174 else 175 { 176 saveJsFu += "_\"+time" + (i + 1) + "+\""; 177 } 178 } 179 saveJs += "value += n.Id+\",\"+$(\"#\"+n.id+\"_date\").val()+\"," + saveJsFu + ",\"+encodeURI(encodeURI($(\"#\"+n.id+\"_remarks\").val()))+\"*\";"; 180 ViewBag.saveJs = saveJs; 181 #endregion 182 #endregion 183 184 return View(); 185 } 186 /// <summary> 187 /// 编辑医生值班信息 188 /// </summary> 189 /// <param name="id"></param> 190 /// <returns></returns> 191 public ActionResult Edit(long id) 192 { 193 DoctorDuty model = doctorDutyDao.GetById(id); 194 string dutyTime = model.DutyTime; 195 196 return View(model); 197 } 198 199 public ActionResult QueryForPage(string time) 200 { 201 DoctorDuty query = new DoctorDuty(); 202 query.CompanyId = UserContext.CurrentUser.Id; 203 204 if (time != null && time.Trim().Length > 0) 205 { 206 query.Date = time; 207 } 208 GenericPage<DoctorDuty> page = this.GetGenericPage(); 209 210 doctorDutyDao.QueryForPage(query, page); 211 212 213 214 215 return new GenericPageResult<DoctorDuty>(page); 216 } 217 218 /// <summary> 219 /// 只用于更新 220 /// </summary> 221 /// <returns></returns> 222 public ActionResult Save() 223 { 224 DoctorDuty doctorDuty = new DoctorDuty(); 225 TryUpdateModel<DoctorDuty>(doctorDuty); 226 doctorDutyDao.Update(doctorDuty); 227 return View("Edit", doctorDuty); 228 } 229 230 /// <summary> 231 /// 只用于添加 232 /// </summary> 233 /// <returns></returns> 234 public ActionResult AddSave() 235 { 236 try 237 { 238 String value = Request.QueryString["value"].ToString(); 239 long CompanyId = UserContext.CurrentUser.Id; 240 String[] arr = value.Split(new Char[] { '*' }); //分割勾选的每行数据 241 foreach (String values in arr) 242 { 243 244 String doctorId = ""; //医生ID 245 String date = ""; //起始日期 246 String endDate = ""; //结束日期 247 String dutyTime = ""; //值班时间段 248 String remarks = ""; //备注 249 250 String[] s = values.Split(new Char[] { ',' }); 251 252 253 doctorId = s[0]; 254 date = s[1]; 255 endDate = s[2]; 256 String[] times = s[3].Split(new Char[] { '_' }); //拼接值班时间段 257 foreach (String time in times) 258 { 259 dutyTime += !time.Equals("false") ? time + "," : ""; 260 } 261 dutyTime = !dutyTime.Equals("") ? dutyTime.Substring(0, dutyTime.Length - 1) : ""; 262 263 remarks = s.Length == 5 ? Server.UrlDecode(s[4]) : "";//解码 JavaScript encodeuri 264 265 DoctorDuty doctorDuty = new DoctorDuty(); 266 doctorDuty.CompanyId = CompanyId; 267 doctorDuty.Date = date; 268 doctorDuty.EndDate = endDate; 269 doctorDuty.DutyTime = dutyTime; 270 doctorDuty.Remarks = remarks; 271 doctorDuty.DoctorId = long.Parse(doctorId); 272 273 //根据日期判断当天是否有值班记录 274 IList<DoctorDuty> list = doctorDutyDao.getDoctorDutyBy(doctorDuty); 275 if (list != null && list.Count != 0) 276 { //如果存在值班记录则删除该记录 277 DoctorDuty doctorList1 = list[0]; 278 doctorDutyDao.Delete(doctorList1.Id); 279 doctorDutyDao.Add(doctorDuty); 280 } 281 else 282 { 283 doctorDutyDao.Add(doctorDuty); 284 } 285 286 } 287 return Json("保存成功"); 288 } 289 catch (Exception exx) 290 { 291 string a = exx.ToJson(); 292 throw; 293 } 294 295 } 296 297 public String Delete(long id) 298 { 299 doctorDutyDao.Delete(id); 300 return "success"; 301 } 302 303 304 305 } 306 }
首页代码1 @{ 2 ViewBag.Title = "详细信息"; 3 Layout = "~/Views/Shared/_Layout.cshtml"; 4 } 5 @section head{ 6 7 } 8 9 @section toolbar{ 10 <a href="@Url.Content("~/Tooth/DoctorDuty/AddIndex")" onclick="" class="easyui-linkbutton" data-options="iconCls:'icon-save'" title="添加">添加</a> 11 } 12 13 @section query{ 14 <table width="100%" id="queryTable"> 15 <tr> 16 <td> 17 <div class="conditions"> 18 <table border="0" cellspacing="0" cellpadding="0"> 19 <tr> 20 <td class="table_left">查询日期:</td> 21 <td class="table_right"> 22 <input type="text" style="width: 130px;" class="information-input" onclick="WdatePicker()" id="time" name="time" maxlength="30" /> 23 </td> 24 </tr> 25 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论