public ActionResult UpdTaskData() { int id = int.Parse(Request.Params["taskid"]); string taskcode = Request.Params["taskcode"]; string taskname = Request.Params["taskname"]; int lineid = int.Parse(Request.Params["lineid"]); string linecode = Request.Params["linecode"]; string linename = Request.Params["linename"]; int startpole = int.Parse(Request.Params["startpole"]); int endpole = int.Parse(Request.Params["endpole"]); string startpolecode = Request.Params["startpolecode"]; string endpolecode = Request.Params["endpolecode"]; string desc = Request.Params["desc"]; string issuedcode = Request.Params["issuedcode"]; //下发人code string issuedname = Request.Params["issuedname"]; //下发人name DateTime issuedtime = Convert.ToDateTime(Request.Params["issuedtime"]); //下发时间 string inspectorcode = Request.Params["inspectorcode"]; string createdBy = Request.Params["createdBy"]; DateTime createdtime = Convert.ToDateTime(Request.Params["createdtime"]); bool b = true; var users = (from u in medc.ps_user where u.id == int.Parse(Session["userid"].ToString()) select u).FirstOrDefault(); var inspectormain = (from i in medc.ps_inspectiontask_main where i.id == id select i).FirstOrDefault(); //修改数据 inspectormain.inspectionTaskCode = taskcode; inspectormain.inspectionTaskName = taskname; inspectormain.lineId = lineid; inspectormain.lineCode = linecode; inspectormain.lineName = linename; inspectormain.startPole = startpole; inspectormain.startPoleCode = startpolecode; inspectormain.endPole = endpole; inspectormain.endPoleCode = endpolecode; inspectormain.taskStatus = 2; inspectormain.taskStatusName = "已分配"; inspectormain.common = desc; inspectormain.lastUpdateTime = DateTime.Now; try { //保存修改 medc.SubmitChanges(); } catch (Exception) { b = false; } if (b) //修改巡检员信息表的数据 { if (inspectorcode.IndexOf(',') > 0) { List <ps_inspector_detail> list2 = new List <ps_inspector_detail>(); string[] strlist = inspectorcode.Split(','); for (var i = 0; i < strlist.Length; i++) { var user = (from c in medc.ps_user where c.userCode == strlist[i] select c).FirstOrDefault(); ps_inspector_detail detail = new ps_inspector_detail() { taskId = id, inspectorCode = user.userCode, inspectorName = user.userName, creationTime = DateTime.Now, createdBy = users.userCode, lastUpdateTime = DateTime.Now }; list2.Add(detail); } //保存数据 medc.ps_inspector_detail.InsertAllOnSubmit(list2); try { medc.SubmitChanges(); } catch (Exception) { b = false; } } } return(Json(b)); }
public ActionResult AddInspector() { int taskid = int.Parse(Request.Params["taskid"]); string strs = Request.Params["inspectors"]; bool b = true; if (strs.IndexOf(',') > 0) { List <ps_inspector_detail> des = new List <ps_inspector_detail>(); var user = (from u in medc.ps_user where u.id == int.Parse(Session["userid"].ToString()) select u).FirstOrDefault(); string[] strlist = strs.Split(','); for (var i = 0; i < strlist.Length; i++) { var users = (from u in medc.ps_user where u.id == int.Parse(strlist[i]) select u).FirstOrDefault(); ps_inspector_detail dd = new ps_inspector_detail() { taskId = taskid, inspectorCode = users.userCode, inspectorName = users.userName, creationTime = DateTime.Now, createdBy = user.userCode, lastUpdateTime = DateTime.Now }; des.Add(dd); } medc.ps_inspector_detail.InsertAllOnSubmit(des); try { medc.SubmitChanges(); } catch (Exception) { b = false; } if (b) { var ins = (from a in medc.ps_inspectiontask_main where a.id == taskid select a).FirstOrDefault(); ins.taskStatus = 2; ins.taskStatusName = "已分配"; try { medc.SubmitChanges(); } catch (Exception) { b = false; } } } else { var user = (from u in medc.ps_user where u.id == int.Parse(Session["userid"].ToString()) select u).FirstOrDefault(); var users = (from u in medc.ps_user where u.id == int.Parse(strs) select u).FirstOrDefault(); ps_inspector_detail dd = new ps_inspector_detail() { taskId = taskid, inspectorCode = users.userCode, inspectorName = users.userName, creationTime = DateTime.Now, createdBy = user.userCode, lastUpdateTime = DateTime.Now }; medc.ps_inspector_detail.InsertOnSubmit(dd); try { medc.SubmitChanges(); } catch (Exception) { b = false; } if (b) { var ins = (from a in medc.ps_inspectiontask_main where a.id == taskid select a).FirstOrDefault(); ins.taskStatus = 2; ins.taskStatusName = "已分配"; try { medc.SubmitChanges(); } catch (Exception) { b = false; } } } return(Json(b)); }
public ActionResult AddTaskinfo() { string taskcode = Request.Params["taskcode"]; string taskname = Request.Params["taskname"]; int lineid = int.Parse(Request.Params["lineid"]); string linecode = Request.Params["linecode"]; string linename = Request.Params["linename"]; int startpole = int.Parse(Request.Params["startpole"]); int endpole = int.Parse(Request.Params["endpole"]); string startpolecode = Request.Params["startpolecode"]; string endpolecode = Request.Params["endpolecode"]; string desc = Request.Params["desc"]; DateTime issuedtime = Convert.ToDateTime(Request.Params["issuedtime"]); string inspecname = ""; string inspectorcode = ""; var user = (from u in medc.ps_user where u.id == int.Parse(Session["userid"].ToString()) && u.userStatus == 1 select u).FirstOrDefault(); bool b = true; if (Request.Params["inspecname"] != "" && Request.Params["inspectorcode"] != "") { inspectorcode = Request.Params["inspectorcode"]; inspecname = Request.Params["inspecname"]; ps_inspectiontask_main taskmain = new ps_inspectiontask_main(); taskmain.inspectionTaskCode = taskcode; taskmain.inspectionTaskName = taskname; taskmain.lineId = lineid; taskmain.lineCode = linecode; taskmain.lineName = linename; taskmain.startPole = startpole; taskmain.startPoleCode = startpolecode; taskmain.endPole = endpole; taskmain.endPoleCode = endpolecode; taskmain.issuedByCode = user.userCode; taskmain.issuedByName = user.userName; taskmain.issuedTime = issuedtime; taskmain.taskStatus = 2; taskmain.taskStatusName = "已分配"; taskmain.finishTime = null; taskmain.common = desc; taskmain.createdBy = user.userCode; taskmain.creationTime = DateTime.Now; taskmain.lastUpdateTime = DateTime.Now; taskmain.isCancel = 0; medc.ps_inspectiontask_main.InsertOnSubmit(taskmain); //保存添加 try { medc.SubmitChanges(); } catch (Exception) { b = false; } if (b) { var tm = (from m in medc.ps_inspectiontask_main orderby m.id descending select m).FirstOrDefault(); List <ps_inspector_detail> ilist = new List <ps_inspector_detail>(); if (inspectorcode.IndexOf(',') > 0) { string[] strslist = inspectorcode.Split(','); for (var i = 0; i < strslist.Length; i++) { var u = (from p in medc.ps_user where p.userCode == strslist[i] select p).FirstOrDefault(); ps_inspector_detail det = new ps_inspector_detail() { taskId = tm.id, inspectorCode = strslist[i], inspectorName = u.userName, creationTime = DateTime.Now, createdBy = user.userCode, lastUpdateTime = DateTime.Now }; ilist.Add(det); } } else { ps_inspector_detail det = new ps_inspector_detail() { taskId = tm.id, inspectorCode = inspectorcode, inspectorName = inspecname, creationTime = DateTime.Now, createdBy = user.userCode, lastUpdateTime = DateTime.Now }; ilist.Add(det); } medc.ps_inspector_detail.InsertAllOnSubmit(ilist); try { medc.SubmitChanges(); } catch (Exception) { b = false; } } } else { //实例化对象将数据添加到该实例中 ps_inspectiontask_main taskmain = new ps_inspectiontask_main() { inspectionTaskCode = taskcode, inspectionTaskName = taskname, lineId = lineid, lineCode = linecode, lineName = linename, startPole = startpole, startPoleCode = startpolecode, endPole = endpole, endPoleCode = endpolecode, issuedByCode = user.userCode, issuedByName = user.userName, issuedTime = issuedtime, taskStatus = 1, taskStatusName = "未分配", finishTime = null, common = desc, creationTime = DateTime.Now, createdBy = user.userCode, lastUpdateTime = DateTime.Now, isCancel = 0 }; medc.ps_inspectiontask_main.InsertOnSubmit(taskmain); try { medc.SubmitChanges(); } catch (Exception) { b = false; } } if (b) { //首先查询出刚刚添加的任务的id var taskmains = (from i in medc.ps_inspectiontask_main orderby i.id descending select i).FirstOrDefault(); //根据线路编号查询出所有的杆塔信息 var poles = (from p in medc.ps_pole_info where p.lineId == lineid select p).ToList(); List <ps_inspectiontask_detail> taskdetails = new List <ps_inspectiontask_detail>(); for (var i = 0; i < poles.Count(); i++) { ps_inspectiontask_detail dets = new ps_inspectiontask_detail() { taskid = taskmains.id, poleid = poles[i].id, poleCode = poles[i].poleCode, lineCode = poles[i].lineCode, lineName = poles[i].lineName, isBug = 0, intactRate = 100, bugLevel = null, bugLevelName = null, bugType = null, bugTypeName = null, bugDesc = null, discovererCode = user.userCode, discovererName = user.userName, discoverTime = DateTime.Now, isSolve = 0, inspectTime = null, createdBy = user.userCode, creationTime = DateTime.Now, lastUpdateTime = DateTime.Now, taskStatus = 1, isBugLevel = 0 }; taskdetails.Add(dets); } //插入数据 medc.ps_inspectiontask_detail.InsertAllOnSubmit(taskdetails); try { medc.SubmitChanges(); } catch (Exception) { b = false; } } return(Json(b)); }