/// <summary> /// 获得记录条数 /// </summary> /// <param name="Cou_ID"></param> /// <returns></returns> public int GetListCount(int Cou_ID) { string str = "Cou_ID="+Cou_ID; LabMS.BLL.ProCourse bProCourse = new LabMS.BLL.ProCourse(); List<LabMS.Model.ProCourse> list = new List<LabMS.Model.ProCourse>(); list=bProCourse.GetModelList(str); return list.Count; }
public void ProcessRequest(HttpContext context) { try { string strJson = System.Web.HttpContext.Current.Server.UrlDecode(context.Request.Form.ToString()); LabMS.Model.CourseJson json = (LabMS.Model.CourseJson)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strJson, typeof(LabMS.Model.CourseJson)); ExtendBLL.Course course = new ExtendBLL.Course(); if (course.Exists(" Course_Code = @Code",new System.Data.SqlClient.SqlParameter("@Code",json.Code))) { throw new Exception("课程号已经存在"); } LabMS.BLL.ProCourse proCourse = new LabMS.BLL.ProCourse(); LabMS.Model.Course courseModel = new LabMS.Model.Course();//课程 LabMS.Model.ProCourse proCourseModel = new LabMS.Model.ProCourse();//专业课程 courseModel.Course_Code = json.Code; courseModel.Course_ExprientHouse = json.Hour; courseModel.Course_Name = json.Name; courseModel.CourseType = json.Type; courseModel.EnglishName = json.EnglishName; courseModel.Course_House =json.CourseHouse.ToString();//课时 courseModel.ID = course.Add(courseModel); proCourseModel.Cou_ID = courseModel.ID;//取出课程ID,存专业课程表 foreach (LabMS.Model.MajorJson major in json.Majors) { proCourseModel.ProID = major.ID; proCourse.Add(proCourseModel); } context.Response.ContentType = "application/json"; context.Response.Write("{success: true}"); } catch (Exception ex) { context.Response.ContentType = "application/json"; context.Response.Write("{error: true, msg: '" + System.Web.HttpContext.Current.Server.UrlEncode(ex.Message) + "'}"); } }
public void ProcessRequest(HttpContext context) { try { if (string.IsNullOrEmpty(context.Request.QueryString["ID"].ToString())) { context.Response.ContentType = "application/json"; context.Response.Write("{error: true}"); } string courseID = context.Request.QueryString["ID"]; LabMS.Model.CourseJson json = new LabMS.Model.CourseJson(); json.ID = int.Parse(courseID); LabMS.BLL.ProCourse BProCourse = new LabMS.BLL.ProCourse(); ExtendBLL.Class eClass = new ExtendBLL.Class(); List<LabMS.Model.ProCourse> listPC = new List<LabMS.Model.ProCourse>(); listPC = BProCourse.GetModelList("Cou_ID=" + courseID); foreach (LabMS.Model.ProCourse proCourse in listPC) { LabMS.Model.MajorJson major = new LabMS.Model.MajorJson(); major.ID = proCourse.ProID.Value; major.Name = eClass.ProessionalNameByID(major.ID); json.Majors.Add(major); } string strJson = Newtonsoft.Json.JavaScriptConvert.SerializeObject(json);//序列化,把JSON转化为string类型 context.Response.ContentType = "application/json"; context.Response.Write(strJson); /* System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("{Majors: ["); //sb.Append("{"); //sb.Append("ID: "); //JSON格式为:{Majors:[{ID:1231,Name:'sfsds'},{ID:1111,Name:'lkjo'}]} for (int i = 0; i < listPC.Count; i++) { int Pid = int.Parse(listPC[i].ProID.Value.ToString()); string PName = eClass.ProessionalNameByID(Pid); sb.Append("{"); sb.Append("ID: "); sb.Append(Pid); sb.Append(","); sb.Append("Name: "); sb.Append(PName); if (i != listPC.Count - 1) { sb.Append(","); } else { sb.Append("}"); sb.Append("]"); sb.Append("}"); } } //sb.Append("'1231'"); //sb.Append(","); //sb.Append("Name: "); //sb.Append("'sfsds'"); //sb.Append("}"); //sb.Append(","); //sb.Append("{"); //sb.Append("ID: "); //sb.Append("'1111'"); //sb.Append(","); //sb.Append("Name: "); //sb.Append("'lkjo'"); //sb.Append("}"); //sb.Append("]}"); context.Response.ContentType = "application/json"; context.Response.Write(sb.ToString()); //返回值*/ } catch { context.Response.ContentType = "application/json"; context.Response.Write("{error: true}"); } }
public void ProcessRequest(HttpContext context) { try { string strJson = System.Web.HttpContext.Current.Server.UrlDecode(context.Request.Form.ToString()); LabMS.Model.CourseJson json = (LabMS.Model.CourseJson)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strJson, typeof(LabMS.Model.CourseJson)); ExtendBLL.Course course = new ExtendBLL.Course(); LabMS.BLL.ProCourse proCourse = new LabMS.BLL.ProCourse(); LabMS.Model.Course courseModel = new LabMS.Model.Course();//课程 LabMS.Model.ProCourse proCourseModel = new LabMS.Model.ProCourse();//专业课程 courseModel.ID = json.ID; courseModel.Course_Code = json.Code; courseModel.Course_ExprientHouse = json.Hour; courseModel.Course_Name = json.Name; courseModel.CourseType = json.Type; courseModel.EnglishName = json.EnglishName; courseModel.Course_House = json.CourseHouse.ToString();//课时 course.Update(courseModel); proCourseModel.Cou_ID = courseModel.ID;//取出课程ID,存专业课程表 #region 没有选择专业,把数据库中存在的专业都删掉 if (json.Majors.Count == 0) { int Cou_ID=int.Parse(proCourseModel.Cou_ID.Value.ToString()); if (course.GetListCount (Cou_ID) == 0) { } else { if (course.DeleteProCourseByCouseID(Cou_ID) != true) { throw new Exception("删除课程出错!"); } } } #endregion else { //把原来的删掉,重新加入 string str = "Delete from ProCourse where Cou_ID="+proCourseModel.Cou_ID; Maticsoft.DBUtility.DbHelperSQL.ExecuteSql(str); foreach (LabMS.Model.MajorJson major in json.Majors) { proCourseModel.ProID = major.ID; proCourse.Add(proCourseModel); } } context.Response.ContentType = "application/json"; context.Response.Write("{success: true}"); } catch (Exception ex) { context.Response.ContentType = "application/json"; context.Response.Write("{error: true, msg: '" + System.Web.HttpContext.Current.Server.UrlEncode(ex.Message) + "'}"); } }