public PqPlszjlModel GetModelByQybh(string qybh) { using (IDbConnection conn = new DapperConnection().DbConnection) { string sql = "SELECT TOP 1 * FROM dbo.pq_plszjl WHERE qybh=@qybh ORDER BY id DESC"; PqPlszjlModel model = conn.Query <PqPlszjlModel>(sql, new { qybh = qybh }).FirstOrDefault(); return(model); } }
public void Add(PqPlszjlModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into pq_plszjl("); strSql.Append("yybh,qybh,kssj,jssj,cjsj,mx)"); strSql.Append(" values ("); strSql.Append("@yybh,@qybh,@kssj,@jssj,@cjsj,@mx)"); strSql.Append(";select @@IDENTITY"); using (IDbConnection conn = new DapperConnection().DbConnection) { conn.ExecuteScalar(strSql.ToString(), model); } }
public ActionResult BatchSave() { string yybh = GLYadmin.YYID; string qybh = Request["qybh"]; //企业id int tqts = Convert.ToInt32(Request["tqts"]); //提前天数 string jzsj = Request["txtTimeBefor"]; //截止时间 //日期范围 DateTime ksrq = Convert.ToDateTime(Request["txtStartDate"]); DateTime jsrq = Convert.ToDateTime(Request["txtEndDate"]); //时间段 var kssjList = Request.Params.GetValues("kssj"); var jssjList = Request.Params.GetValues("jssj"); var tjrsList = Request.Params.GetValues("tjrs"); //休息日 var xxr = (Request["xxr"] ?? "").Replace(",", "|"); List <PlszMxModel> mxList = new List <PlszMxModel>(); List <PqTjrqModel> tjrqList = new List <PqTjrqModel>(); List <PqTjsjModel> tjsjList = new List <PqTjsjModel>(); for (int i = 0; i < kssjList.Count(); i++) { if (string.IsNullOrEmpty(kssjList[i]) || string.IsNullOrEmpty(jssjList[i])) { return(Json(new { code = 500, msg = "时间段不能为空" })); } else if (string.IsNullOrEmpty(tjrsList[i])) { return(Json(new { code = 500, msg = "预留人数不能为空" })); } for (int j = i + 1; j < kssjList.Count(); j++) { if (Convert.ToDateTime(kssjList[j]) > Convert.ToDateTime(kssjList[i]) && Convert.ToDateTime(kssjList[j]) < Convert.ToDateTime(jssjList[i])) { return(Json(new { code = 500, msg = "第" + (i + 1) + "和第" + (j + 1) + "行时间有重叠" })); } else if (Convert.ToDateTime(jssjList[j]) > Convert.ToDateTime(kssjList[i]) && Convert.ToDateTime(jssjList[j]) < Convert.ToDateTime(jssjList[i])) { return(Json(new { code = 500, msg = "第" + (i + 1) + "和第" + (j + 1) + "行时间有重叠" })); } else if (Convert.ToDateTime(kssjList[j]) < Convert.ToDateTime(kssjList[i]) && Convert.ToDateTime(jssjList[j]) > Convert.ToDateTime(jssjList[i])) { return(Json(new { code = 500, msg = "第" + (i + 1) + "和第" + (j + 1) + "行时间有重叠" })); } } mxList.Add(new PlszMxModel { kssj = kssjList[i], jssj = jssjList[i], tjrs = Convert.ToInt32(tjrsList[i]) }); } //获取企业排期基本设置 var qyPqModel = qypqszService.GetModelByQybh(qybh, GLYadmin.YYID); if (qyPqModel == null) { qyPqModel = new PqQyszModel() { qybh = qybh, yybh = yybh, jzsj = jzsj, tqts = tqts, xxr = xxr }; qypqszService.Add(qyPqModel); } else { qyPqModel.jzsj = jzsj; qyPqModel.tqts = tqts; qyPqModel.xxr = xxr; qypqszService.Update(qyPqModel); } PqPlszjlModel plszjlModel = new PqPlszjlModel(); plszjlModel.kssj = ksrq; plszjlModel.jssj = jsrq; plszjlModel.mx = JsonConvert.SerializeObject(mxList); plszjlModel.yybh = yybh; plszjlModel.qybh = qybh; plszjlService.Add(plszjlModel); tjrqService.BatchSave(ksrq, jsrq, yybh, qybh, mxList, xxr); return(Json(new { code = 200, msg = "" })); }