/// <summary> /// 新增一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(Class_TeachSubject model) { StringBuilder sql = new StringBuilder(); sql.Append("insert into [dbo].[Class_TeachSubject] ([ClassId],[TeachSubject],[Delflag],[CreateDate])"); sql.Append(" values (@ClassId,@TeachSubject,@Delflag,@CreateDate)"); sql.Append(" set @Id=@@IDENTITY"); SqlParameter[] cmdParams = new SqlParameter[]{ new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id, Direction = ParameterDirection.Output }, new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId }, new SqlParameter("@TeachSubject", SqlDbType.Int, 4) { Value = model.TeachSubject }, new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag }, new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate } }; int result = Convert.ToInt32(MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams)); model.Id = Convert.ToInt32(cmdParams[0].Value); return result; }
/// <summary> /// 获取数据集 /// </summary> /// <param name="where"></param> /// <param name="orderBy"></param> /// <returns></returns> public List<Class_TeachSubject> GetList(string where, string orderBy) { StringBuilder sql = new StringBuilder(); sql.Append("select * from [dbo].[Class_TeachSubject]"); if (!string.IsNullOrEmpty(where)) sql.Append(" where " + where); if (!string.IsNullOrEmpty(orderBy)) sql.Append(" order by " + orderBy); List<Class_TeachSubject> list = new List<Class_TeachSubject>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Class_TeachSubject model = new Class_TeachSubject(); ConvertToModel(reader, model); list.Add(model); } } return list; }
public JsonResult EditClass(string id, string Title, string TraningId, string PlanId, string SignUpStartTime, string SignUpEndTime , string OpenClassFrom, string OpenClassTo, string ClassForm, string LimitPeopleCnt, string Address , string Content, string Subject, string StudyLevel, string TeachGrade, string TeachRank, string OrganRange , string Status) { try { var bll = new Class_DetailBLL(); var model = bll.GetModel(id.ToInt()); model.Title = Title; model.TraningId = TraningId.ToInt(); model.PlanId = PlanId.ToInt(); model.SignUpStartTime = SignUpStartTime.ToDateTime(); model.SignUpEndTime = SignUpEndTime.ToDateTime(); model.OpenClassFrom = OpenClassFrom.ToDateTime(); model.OpenClassTo = OpenClassTo.ToDateTime(); model.ClassForm = ClassForm.ToInt(); model.People = 0; model.LimitPeopleCnt = LimitPeopleCnt.ToInt(); model.Address = Address; model.Content = Content; model.Subject = Subject.Contains("all") ? true : false; model.StudyLevel = StudyLevel.Contains("all") ? true : false; ; model.TeachGrade = TeachGrade.Contains("all") ? true : false; ; model.TeachRank = TeachRank.Contains("all") ? true : false; model.OrganRange = OrganRange.Contains("all") ? "0" : OrganRange; ; model.ManagerId = SiteCache.Instance.ManagerId; model.Status = Status.ToInt(); model.CreateDate = DateTime.Now; bll.Update(model); Member_ClassRegisterBLL member_ClassRegisterBLL = new Member_ClassRegisterBLL(); List<Member_ClassRegister> member_ClassRegisterList = member_ClassRegisterBLL.GetList("ClassId='" + id + "'", ""); if (member_ClassRegisterList != null && member_ClassRegisterList.Count > 0) { foreach (Member_ClassRegister m in member_ClassRegisterList) { m.Delflag = true; member_ClassRegisterBLL.Update(m); } } if (!model.StudyLevel)//不是全部则建立关联数据 { var arr = StudyLevel.Split(','); var section = new Class_StudySectionBLL(); var oldSection = section.GetList(" Delflag=0 and ClassId=" + model.Id, ""); foreach (var old in oldSection) { var oldId = old.StudySection.ToString(); var exists = arr.Where(s => s == oldId); if (exists == null || exists.Count() == 0)//旧的在新的里面不存,则删除 { old.Delflag = true; section.Update(old); } } foreach (var item in arr)//新的在旧的里面不存在,则新加 { var newid = item.ToInt(); var exists = oldSection.Where(s => s.StudySection == newid && s.Delflag == false); if (exists == null || exists.Count() == 0)// { var classSection = new Dianda.AP.Model.Class_StudySection(); classSection.ClassId = model.Id; classSection.CreateDate = DateTime.Now; classSection.Delflag = false; classSection.StudySection = item.ToInt(); section.Add(classSection); } } } if (!model.Subject)//不是全部则建立关联数据 { var arr = Subject.Split(','); var section = new Class_TeachSubjectBLL(); var oldSection = section.GetList(" Delflag=0 and ClassId=" + model.Id, ""); foreach (var old in oldSection) { var oldId = old.TeachSubject.ToString(); var exists = arr.Where(s => s == oldId); if (exists == null || exists.Count() == 0)//旧的在新的里面不存,则删除 { old.Delflag = true; section.Update(old); } } foreach (var item in arr) { var newid = item.ToInt(); var exists = oldSection.Where(s => s.TeachSubject == newid && s.Delflag == false); if (exists == null || exists.Count() == 0)// { var teachSubject = new Dianda.AP.Model.Class_TeachSubject(); teachSubject.ClassId = model.Id; teachSubject.CreateDate = DateTime.Now; teachSubject.Delflag = false; teachSubject.TeachSubject = item.ToInt(); section.Add(teachSubject); } } } if (!model.TeachGrade)//不是全部则建立关联数据 { var arr = TeachGrade.Split(','); var section = new Class_TeachGradeBLL(); var oldSection = section.GetList(" Delflag=0 and ClassId=" + model.Id, ""); foreach (var old in oldSection) { var oldId = old.TeachGrade.ToString(); var exists = arr.Where(s => s == oldId); if (exists == null || exists.Count() == 0)//旧的在新的里面不存,则删除 { old.Delflag = true; section.Update(old); } } foreach (var item in arr) { var newid = item.ToInt(); var exists = oldSection.Where(s => s.TeachGrade == newid && s.Delflag == false); if (exists == null || exists.Count() == 0)// { var classSection = new Dianda.AP.Model.Class_TeachGrade(); classSection.ClassId = model.Id; classSection.CreateDate = DateTime.Now; classSection.Delflag = false; classSection.TeachGrade = item.ToInt(); section.Add(classSection); } } } if (!model.TeachRank)//不是全部则建立关联数据 { var arr = TeachRank.Split(','); var section = new Class_TeachRankBLL(); var oldSection = section.GetList(" Delflag=0 and ClassId=" + model.Id, ""); foreach (var old in oldSection) { var oldId = old.TeachRank.ToString(); var exists = arr.Where(s => s == oldId); if (exists == null || exists.Count() == 0)//旧的在新的里面不存,则删除 { old.Delflag = true; section.Update(old); } } foreach (var item in arr) { var newid = item.ToInt(); var exists = oldSection.Where(s => s.TeachRank == newid && s.Delflag == false); if (exists == null || exists.Count() == 0)// { var classSection = new Dianda.AP.Model.Class_TeachRank(); classSection.ClassId = model.Id; classSection.CreateDate = DateTime.Now; classSection.Delflag = false; classSection.TeachRank = item.ToInt(); section.Add(classSection); } } } if (Status == "2")//为提交状态时,新建审核记录 { var apply = new Dianda.AP.Model.Class_ApplyApplication(); apply.ClassId = id.ToInt(); apply.AccountId = SiteCache.Instance.LoginInfo.UserId; apply.Remark = "提交审核"; apply.CreateDate = DateTime.Now; var applyBll = new Class_ApplyApplicationBLL(); applyBll.Add(apply); } return Json(new { Code = 0, Msg = "提交成功" }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { return Json(new { Code = -1, Msg = ex.Message }, JsonRequestBehavior.AllowGet); } }
public JsonResult CreateClass(string Title, string TraningId, string PlanId, string SignUpStartTime, string SignUpEndTime , string OpenClassFrom, string OpenClassTo, string ClassForm, string People, string LimitPeopleCnt, string Address , string Content, string Subject, string StudyLevel, string TeachGrade, string TeachRank, string OrganRange , string OrganId, string Status, string PartitionId) { try { var model = new Dianda.AP.Model.Class_Detail(); model.Title = Title; model.TraningId = TraningId.ToInt(); model.PlanId = PlanId.ToInt(); model.SignUpStartTime = SignUpStartTime.ToDateTime(); model.SignUpEndTime = SignUpEndTime.ToDateTime(); model.OpenClassFrom = OpenClassFrom.ToDateTime(); model.OpenClassTo = OpenClassTo.ToDateTime(); model.ClassForm = ClassForm.ToInt(); model.People = People.ToInt(); model.LimitPeopleCnt = LimitPeopleCnt.ToInt(); model.Address = Address; model.Content = Content; model.Subject = Subject.Contains("all") ? true : false; model.StudyLevel = StudyLevel.Contains("all") ? true : false; ; model.TeachGrade = TeachGrade.Contains("all") ? true : false; ; model.TeachRank = TeachRank.Contains("all") ? true : false; model.OrganRange = OrganRange.Contains("all") ? "0" : OrganRange; ; model.ManagerId = SiteCache.Instance.ManagerId; model.Status = Status.ToInt(); model.CreateDate = DateTime.Now; model.OrganId = OrganId.ToInt(); model.PartitionId = PartitionId.ToInt(); model.Display = true; var bll = new Dianda.AP.BLL.Class_DetailBLL(); var cid = bll.Add(model); if (!model.Subject)//不是全部则建立关联数据 { var arr = Subject.Split(','); var subject = new Class_TeachSubjectBLL(); foreach (var item in arr) { var classSubject = new Dianda.AP.Model.Class_TeachSubject(); classSubject.ClassId = cid; classSubject.CreateDate = DateTime.Now; classSubject.Delflag = false; classSubject.TeachSubject = item.ToInt(); subject.Add(classSubject); } } if (!model.StudyLevel)//不是全部则建立关联数据 { var arr = StudyLevel.Split(','); foreach (var item in arr) { var section = new Class_StudySectionBLL(); var teachSection = new Dianda.AP.Model.Class_StudySection(); teachSection.ClassId = cid; teachSection.CreateDate = DateTime.Now; teachSection.Delflag = false; teachSection.StudySection = item.ToInt(); section.Add(teachSection); } } if (!model.TeachGrade)//不是全部则建立关联数据 { var arr = TeachGrade.Split(','); var section = new Class_TeachGradeBLL(); foreach (var item in arr) { var classSection = new Dianda.AP.Model.Class_TeachGrade(); classSection.ClassId = cid; classSection.CreateDate = DateTime.Now; classSection.Delflag = false; classSection.TeachGrade = item.ToInt(); section.Add(classSection); } } if (!model.TeachRank)//不是全部则建立关联数据 { var arr = TeachRank.Split(','); var section = new Class_TeachRankBLL(); foreach (var item in arr) { var classSection = new Dianda.AP.Model.Class_TeachRank(); classSection.ClassId = cid; classSection.CreateDate = DateTime.Now; classSection.Delflag = false; classSection.TeachRank = item.ToInt(); section.Add(classSection); } } if (Status == "2")//为提交状态时,新建审核记录 { var apply = new Dianda.AP.Model.Class_ApplyApplication(); apply.ClassId = cid; apply.AccountId = SiteCache.Instance.LoginInfo.UserId; apply.Remark = "提交审核"; apply.CreateDate = DateTime.Now; var applyBll = new Class_ApplyApplicationBLL(); applyBll.Add(apply); } return Json(new { Code = 0, Msg = "提交成功" }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { return Json(new { Code = -1, Msg = ex.Message }, JsonRequestBehavior.AllowGet); } }
/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(Class_TeachSubject model) { return dal.Update(model) > 0; }
/// <summary> /// 新增一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Add(Class_TeachSubject model) { return dal.Add(model) > 0; }
/// <summary> /// 获取分页数据集 /// </summary> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="where"></param> /// <param name="orderBy"></param> /// <param name="recordCount"></param> /// <returns></returns> public List<Class_TeachSubject> GetList(int pageSize, int pageIndex, string where, string orderBy, out int recordCount) { if (string.IsNullOrEmpty(orderBy)) throw new ArgumentNullException(); StringBuilder sb = new StringBuilder(); sb.Append("select count(1) from [dbo].[Class_TeachSubject]"); if (!string.IsNullOrEmpty(where)) sb.Append(" where " + where); recordCount = Convert.ToInt32(MSEntLibSqlHelper.ExecuteScalarBySql(sb.ToString())); int start = (pageIndex - 1) * pageSize + 1; int end = pageIndex * pageSize; StringBuilder sql = new StringBuilder(); sql.Append("select * from (select *,ROW_NUMBER() over (order by " + orderBy + ") as [RowNum] from [dbo].[Class_TeachSubject]"); if (!string.IsNullOrEmpty(where)) sql.Append(" where " + where); sql.Append(") as T where [RowNum] between " + start + " and " + end); List<Class_TeachSubject> list = new List<Class_TeachSubject>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Class_TeachSubject model = new Class_TeachSubject(); ConvertToModel(reader, model); list.Add(model); } } return list; }
private void ConvertToModel(IDataReader reader, Class_TeachSubject model) { if (reader["Id"] != DBNull.Value) model.Id = Convert.ToInt32(reader["Id"]); if (reader["ClassId"] != DBNull.Value) model.ClassId = Convert.ToInt32(reader["ClassId"]); if (reader["TeachSubject"] != DBNull.Value) model.TeachSubject = Convert.ToInt32(reader["TeachSubject"]); if (reader["Delflag"] != DBNull.Value) model.Delflag = Convert.ToBoolean(reader["Delflag"]); if (reader["CreateDate"] != DBNull.Value) model.CreateDate = Convert.ToDateTime(reader["CreateDate"]); }
/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(Class_TeachSubject model) { StringBuilder sql = new StringBuilder(); sql.Append("update [dbo].[Class_TeachSubject] set "); sql.Append("[ClassId]=@ClassId,[TeachSubject]=@TeachSubject,[Delflag]=@Delflag,[CreateDate]=@CreateDate"); sql.Append(" where [Id]=@Id"); SqlParameter[] cmdParams = new SqlParameter[] { new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id }, new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId }, new SqlParameter("@TeachSubject", SqlDbType.Int, 4) { Value = model.TeachSubject }, new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag }, new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate } }; return MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams); }
/// <summary> /// 取得一条记录 /// </summary> /// <param name="id"></param> /// <param name="where"></param> /// <returns></returns> public Class_TeachSubject GetModel(int id, string where) { string sql = "select * from [dbo].[Class_TeachSubject] where [Id]=@Id"; if (!string.IsNullOrEmpty(where)) sql += " and " + where; SqlParameter[] cmdParams = new SqlParameter[]{ new SqlParameter("@Id", SqlDbType.Int, 4) { Value = id } }; using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql, cmdParams)) { if (reader.Read()) { Class_TeachSubject model = new Class_TeachSubject(); ConvertToModel(reader, model); return model; } else { return null; } } }