123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- using Ant.Data;
- using Ant.ORM;
- using Ant.SuperSocket.Common;
- using Ant.Service.Common;
- using Ant.Service.Common.Enums;
- using Central.Control.Domain;
- using MES.Production.Entity;
- using MES.Production.Entity.Entity;
- using MES.Production.Entity.Enum;
- using Ant.Service.Mongodb;
- using MES.Production.Service.IService;
- using MES.Production.Service.ServiceImp;
- using Ant.Service.Utility;
- using ChangFa.Machinery.WebPage.Areas.SysManage.Models;
- using ChangFa.Machinery.WebPage.Controllers;
- using MongoDB.Driver.Builders;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- using JsonHelper = Ant.Service.Common.JsonHelper;
- namespace ChangFa.Machinery.WebPage.Areas.SysManage.Controllers
- {
- public class CoachController : BaseController
- {
- [UserAuthorizeAttribute(ModuleAlias = "coachList", OperaAction = "View")]
- public ActionResult CoachList()
- {
- try
- {
- PageInfo pageInfo = new PageInfo(base.page, base.pagesize, 0, JsonConverter.JsonClass(new List<EntYW_Bicycle>()));
- #region 处理查询参数
- var nameOrProject = Request.QueryString["nameOrProject"];
- #endregion
- #region 加载列表
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取教练员列表" };
- var coachList = orm.Queryable<YM_Coach>();
- int pageno = (base.page - 1) * base.pagesize;
- if (!nameOrProject.IsEmpty())
- {
- coachList = coachList.Where(p => (!string.IsNullOrEmpty(p.Name) && p.Name.Contains(nameOrProject)) || (!string.IsNullOrEmpty(p.Name) && p.Project.Contains(nameOrProject)));
- }
- if (CurrentUser.USERTYPE == UserRoleType.School.GetHashCode())
- {
- if (CurrentUser.DptInfo.IfNotNull())
- {
- if (!CurrentUser.DptInfo.ID.IsNullOrEmpty())
- {
- var schoolID = CurrentUser.DptInfo.ID;
- coachList = coachList.Where(p => p.SchoolID == schoolID);
- }
- }
- }
- var reslut = coachList.OrderByDesc(p => p.UpdateTime).Skip(pageno).Top(pagesize).ToList(res);
- if (reslut.IsSuccess)
- {
- reslut.RecordNum = coachList.Count();
- pageInfo = new PageInfo(base.page, base.pagesize, reslut.RecordNum, JsonConverter.JsonClass(reslut.ResultModel));
- }
- }
- ViewBag.Search = base.keywords;
- ViewData["nameOrProject"] = nameOrProject;
- return View(pageInfo);
- #endregion
- }
- catch (Exception e)
- {
- WriteLog(enumOperator.Select, "获取教练员列表:", e);
- throw e.InnerException;
- }
- }
- public ActionResult Delete(string idList)
- {
- JsonHelper json = new JsonHelper() { Status = "n", Msg = "删除教练成功" };
- try
- {
- //是否为空
- if (string.IsNullOrEmpty(idList)) { json.Msg = "未找到要删除的教练"; return Json(json); }
- string[] id = idList.Trim(',').Split(',');
- for (int i = 0; i < id.Length; i++)
- {
- var userId = (id[i]);
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "删除教练" },
- Oid = userId.ToString()
- };
- var reslut = orm.DeleteById<YM_Coach>(request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- WriteLog(enumOperator.Remove, json.Msg, enumLog4net.WARN);
- }
- }
- }
- }
- catch (Exception e)
- {
- json.Msg = "删除教练发生内部错误!";
- WriteLog(enumOperator.Remove, "删除教练:", e);
- }
- return Json(json);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="entity"></param>
- /// <returns></returns>
- [UserAuthorize(ModuleAlias = "coachList", OperaAction = "Add,Edit")]
- [ValidateInput(false)]
- [HttpPost]
- public ActionResult Save(YM_Coach entity)
- {
- JsonHelper json = new JsonHelper() { Msg = "保存教练成功", Status = "n", ReUrl = "/Sys/Coach/CoachList" };
- try
- {
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel();
- request.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "保存教练" };
- entity.Project = Request["Projects"].ToString();
- if (CurrentUser.USERTYPE == UserRoleType.School.GetHashCode())//用户是学校角色
- {
- if (CurrentUser.DptInfo.IfNotNull())
- {
- if (!CurrentUser.DptInfo.ID.IsNullOrEmpty())
- {
- var schoolID = CurrentUser.DptInfo.ID;
- entity.SchoolID = schoolID;
- entity.SchoolName = CurrentUser.DptInfo.Name;
- }
- }
- }
- if (!entity.IDCard.IsEmpty())
- {
- if (!CodeHelper.CheckIDCard(entity.IDCard))
- {
- json.Status = "n";
- json.Msg = "身份证无效,请重新核对!";
- return Json(json);
- }
- }
- if (!entity.MobilePhone.IsEmpty())
- {
- if (!CodeHelper.IsPhoneNo(entity.MobilePhone))
- {
- json.Status = "n";
- json.Msg = "手机号无效,请重新核对!";
- return Json(json);
- }
- }
- entity.Updator = entity.Creator;
- entity.UpdateTime = entity.CreateTime;
- if (entity.ID > 0)
- {
- request.Oid = entity.ID.ToString();
- var reslut = orm.UpdateById(entity, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存教练失败";
- }
- }
- else
- {
- entity.Creator = this.CurrentUser.Name;
- entity.CreateTime = DateTime.Now;
- var reslut = orm.Save(entity, request);
- if (reslut.IsSuccess)
- {
- json.Status = "y";
- }
- else
- {
- json.Msg = "保存教练失败";
- }
- }
- }
- }
- catch (Exception ex)
- {
- json.Msg = "保存教练发生内部错误!";
- WriteLog(enumOperator.None, "保存教练:", ex);
- }
- return Json(json);
- }
- [UserAuthorize(ModuleAlias = "coachList", OperaAction = "Detail")]
- public ActionResult Detail(int? id)
- {
- YM_CoachExted mod = new YM_CoachExted();
- if (id != null)
- {
- using (AntORM orm = new AntORM())
- {
- try
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel request = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询教练的单个实体方法" },
- Oid = id.ToString()
- };
- var reslut = orm.GetEntity<YM_Coach>(request);
- if (reslut.IsSuccess)
- {
- mod = JsonHelper.FromJson<YM_CoachExted>(JsonHelper.ToJson(reslut.ResultModel));
- mod.Projects = (mod.Project ?? string.Empty).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
- }
- }
- catch (Exception e)
- {
- }
- }
- }
- List<SelectListItem> items = new List<SelectListItem>();
- items.Add(new SelectListItem { Text = "请选择", Value = "" });
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel
- {
- newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "查询学校" },
- };
- var result = orm.Queryable<YM_School>().ToList(res);
- foreach (var item in result.ResultModel)
- {
- items.Add(new SelectListItem { Text = item.Name, Value = item.ID.ToString() });
- }
- }
- ViewBag.Schools = items;
- items = new List<SelectListItem>();
- items.Add(new SelectListItem { Text = "请选择", Value = "" });
- var sysCodes = CommonEnumHelper.LoadDic(CommonCodeType.性别);
- foreach (var item in sysCodes)
- {
- items.Add(new SelectListItem { Text = item.NAMETEXT, Value = item.NAMETEXT });
- }
- ViewBag.Sexs = items;
- items = new List<SelectListItem>();
- sysCodes = CommonEnumHelper.LoadDic(CommonCodeType.运动分类);
- foreach (var item in sysCodes)
- {
- if (!string.IsNullOrWhiteSpace(mod.Project) && mod.Project.IndexOf(item.NAMETEXT) >= 0)
- {
- items.Add(new SelectListItem { Text = item.NAMETEXT, Selected = true, Value = item.NAMETEXT });
- }
- else
- {
- items.Add(new SelectListItem { Text = item.NAMETEXT, Value = item.NAMETEXT });
- }
- }
- MultiSelectList multiList = new MultiSelectList(items, "Value", "Text");
- ViewBag.MultiProjects = multiList;
- return View(mod);
- }
- public FileResult ExportExecl()
- {
- try
- {
- NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
- //添加一个sheet
- NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("武进区学校体育教练员统计表");
- //给sheet1添加第一行的头部标题
- NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
- row1.CreateCell(0).SetCellValue("教练姓名");
- row1.CreateCell(1).SetCellValue("性别");
- row1.CreateCell(2).SetCellValue("学校");
- row1.CreateCell(3).SetCellValue("职称");
- row1.CreateCell(4).SetCellValue("指导项目");
- #region 处理查询参数
- var nameOrProject = Request.QueryString["nameOrProject"];
- #endregion
- #region 加载列表
- using (AntORM orm = new AntORM())
- {
- orm.db = DataAccessFactory.CreateDataConnection("CyclingItem");
- RequestModel res = new RequestModel();
- res.newSt = new SqlNote() { Author = "季健国", NewSt = new System.Diagnostics.StackTrace(true), SqlDesc = "获取教练员列表" };
- var coachList = orm.Queryable<YM_Coach>()
- .InnerJoin<YM_School>((coach, school) => coach.SchoolID == school.ID);
- int pageno = (base.page - 1) * base.pagesize;
- var views = coachList.Select((coach, school) => new
- {
- Coach = coach,
- School = school
- });
- if (!nameOrProject.IsEmpty())
- {
- views = views.Where(p => (!string.IsNullOrEmpty(p.Coach.Name) && p.Coach.Name.Contains(nameOrProject)) || (!string.IsNullOrEmpty(p.Coach.Name) && p.Coach.Project.Contains(nameOrProject)));
- }
- var reslut = views.OrderByDesc(p => p.Coach.UpdateTime).Skip(pageno).Top(pagesize).ToList(res);
- if (reslut.IsSuccess)
- {
- int rowIndex = 1;
- foreach (var item in reslut.ResultModel)
- {
- NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(rowIndex);
- rowtemp.CreateCell(0).SetCellValue(item.Coach.Name);
- rowtemp.CreateCell(1).SetCellValue(item.Coach.Sex);
- rowtemp.CreateCell(2).SetCellValue(item.School.Name);
- rowtemp.CreateCell(3).SetCellValue(item.Coach.Title);
- rowtemp.CreateCell(4).SetCellValue(item.Coach.Project);
- rowIndex++;
- }
- }
- }
- #endregion
- // 写入到客户端
- System.IO.MemoryStream ms = new System.IO.MemoryStream();
- book.Write(ms);
- ms.Seek(0, SeekOrigin.Begin);
- return File(ms, "application/vnd.ms-excel", "武进区学校体育教练员统计表.xls");
- }
- catch (Exception e)
- {
- throw e.InnerException;
- }
- }
- }
- }
|