using System; using System.Collections.Generic; using System.Data; using Song.Entities; using Song.ServiceInterfaces; using WeiSha.Common; using WeiSha.Data; using System.Collections.Specialized; using Newtonsoft.Json; using System.Configuration; namespace Song.ServiceImpls { public class CourseCom : ICourse { #region 课程管理 /// /// 添加课程 /// /// 业务实体 public void CourseAdd(Course entity) { entity.Cou_CrtTime = DateTime.Now; Song.Entities.Organization org = Business.Do().OrganCurrent(); if (org != null) { entity.Org_ID = org.Org_ID; entity.Org_Name = org.Org_Name; } //object obj = Gateway.Default.Max(Course._.Cou_Tax, Course._.Org_ID == entity.Org_ID && Course._.Sbj_ID == entity.Sbj_ID && Course._.Cou_PID == entity.Cou_PID); object obj = Gateway.Default.Max(Course._.Cou_Tax, new WhereClip()); entity.Cou_Tax = obj is int ? (int)obj + 1 : 0; //默认为免费课程 entity.Cou_IsFree = true; // if (string.IsNullOrWhiteSpace(entity.Cou_UID)) entity.Cou_UID = WeiSha.Common.Request.UniqueID(); entity.Cou_Level = _ClacLevel(entity); entity.Cou_XPath = _ClacXPath(entity); Gateway.Default.Save(entity); } /// /// 批量添加课程,可用于导入时 /// /// 机构id /// 名称,可以是用逗号分隔的多个名称 /// public Course CourseBatchAdd(int orgid, int sbjid, string names) { //整理名称信息 names = names.Replace(",", ","); List listName = new List(); foreach (string str in names.Split(',')) { string s = str.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", ""); if (s.Trim() != "") listName.Add(s.Trim()); } // int pid = 0; Song.Entities.Course last = null; for (int i = 0; i < listName.Count; i++) { Song.Entities.Course current = CourseIsExist(orgid, sbjid, pid, listName[i]); if (current == null) { current = new Course(); current.Cou_Name = listName[i].Trim(); current.Cou_IsUse = true; current.Org_ID = orgid; current.Sbj_ID = sbjid; current.Cou_PID = pid; current.Cou_IsUse = true; current.Cou_IsFree = true; current.Cou_IsTry = true; //所属老师 if (Extend.LoginState.Accounts.IsLogin) { Song.Entities.Teacher th = Extend.LoginState.Accounts.Teacher; if (th != null) { current.Th_ID = th.Th_ID; current.Th_Name = th.Th_Name; } } this.CourseAdd(current); } last = current; pid = current.Cou_ID; } return last; } /// /// 是否已经存在专业 /// /// /// /// /// public Course CourseIsExist(int orgid, int sbjid, int pid, string name) { WhereClip wc = Course._.Org_ID == orgid; if (sbjid > 0) wc &= Course._.Sbj_ID == sbjid; if (pid >= 0) wc &= Course._.Cou_PID == pid; return Gateway.Default.From().Where(wc && Course._.Cou_Name == name.Trim()).ToFirst(); } /// /// 修改课程 /// /// 业务实体 public void CourseSave(Course entity) { Course old = CourseSingle(entity.Cou_ID); if (old.Cou_PID != entity.Cou_PID) { object obj = Gateway.Default.Max(Course._.Cou_Tax, Course._.Org_ID == entity.Org_ID && Course._.Cou_PID == entity.Cou_PID); entity.Cou_Tax = obj is int ? (int)obj + 1 : 0; } entity.Cou_Level = _ClacLevel(entity); entity.Cou_XPath = _ClacXPath(entity); using (DbTrans tran = Gateway.Default.BeginTrans()) { try { //如果课程原来免费,但是现在不再免费 if (old.Cou_IsFree && !entity.Cou_IsFree) { tran.Update( new Field[] { Student_Course._.Stc_EndTime }, new object[] { DateTime.Now }, Student_Course._.Cou_ID == entity.Cou_ID && Student_Course._.Stc_IsFree == true); } //如果课程更改了专业 if (old.Sbj_ID != entity.Sbj_ID) { tran.Update( new Field[] { Questions._.Sbj_ID, Questions._.Sbj_Name }, new object[] { entity.Sbj_ID, entity.Sbj_Name }, Questions._.Cou_ID == entity.Cou_ID); tran.Update(new Field[] { Outline._.Sbj_ID }, new object[] { entity.Sbj_ID }, Outline._.Cou_ID == entity.Cou_ID); tran.Update( new Field[] { TestPaper._.Cou_Name, TestPaper._.Sbj_ID, TestPaper._.Sbj_Name }, new object[] { entity.Cou_Name, entity.Sbj_ID, entity.Sbj_Name }, TestPaper._.Cou_ID == entity.Cou_ID); } tran.Save(entity); tran.Commit(); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); } } } /// /// 是否为直播课 /// /// /// public bool IsLiveCourse(int couid) { Course cou = this.CourseSingle(couid); if (cou == null) return false; return cou.Cou_ExistLive; } /// /// 是否为直播课 /// /// /// 校验,如果为true,则检索课程下所有章节,有直播章节,则课程为直播课程 /// public bool IsLiveCourse(int couid, bool check) { if (!check) return this.IsLiveCourse(couid); Outline[] outs = Business.Do().OutlineCount(couid, -1, null, 0); bool isExist = false; foreach (Outline o in outs) { if (o.Ol_IsLive) { isExist = true; break; } } Gateway.Default.Update( new Field[] { Course._.Cou_ExistLive }, new object[] { isExist }, Course._.Cou_ID == couid); return isExist; } /// /// 增加课程浏览数 /// /// /// public int CourseViewNum(Course entity, int num) { entity.Cou_ViewNum += num; Gateway.Default.Update( new Field[] { Course._.Cou_ViewNum }, new object[] { entity.Cou_ViewNum++ }, Course._.Cou_ID == entity.Cou_ID); return entity.Cou_ViewNum; } public int CourseViewNum(int couid, int num) { Course course = this.CourseSingle(couid); return CourseViewNum(course, num); } /// /// 删除课程 /// /// 业务实体 public void CourseDelete(Course entity) { if (entity == null) return; //是否有下级 bool isExist = CourseIsChildren(entity.Org_ID, entity.Cou_ID, null); if (isExist) throw new Exception("当前课程下还有子课程,请先删除子课程。"); Song.Entities.Outline[] oul = Business.Do().OutlineAll(entity.Cou_ID, null); Song.Entities.GuideColumns[] gcs = Business.Do().GetColumnsAll(entity.Cou_ID, null); using (DbTrans tran = Gateway.Default.BeginTrans()) { try { this.CourseClear(entity.Cou_ID); tran.Delete(Course._.Cou_ID == entity.Cou_ID); foreach (Song.Entities.Outline ac in oul) { Business.Do().OutlineDelete(ac); } foreach (Song.Entities.GuideColumns gc in gcs) { Business.Do().ColumnsDelete(gc); } tran.Delete(CoursePrice._.Cou_UID == entity.Cou_UID); if (!string.IsNullOrWhiteSpace(entity.Cou_Logo)) { WeiSha.WebControl.FileUpload.Delete("Course", entity.Cou_Logo); } tran.Commit(); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); } } } /// /// 删除,按主键ID; /// /// 实体的主键 public void CourseDelete(int identify) { Song.Entities.Course ol = this.CourseSingle(identify); this.CourseDelete(ol); } /// /// 获取单一实体对象,按主键ID; /// /// 实体的主键 /// public Course CourseSingle(int identify) { return Gateway.Default.From().Where(Course._.Cou_ID == identify).ToFirst(); } /// /// 获取课程名称,如果为多级,则带上父级名称 /// /// /// public string CourseName(int identify) { Course entity = Gateway.Default.From().Where(Course._.Cou_ID == identify).ToFirst(); if (entity == null) return ""; string xpath = entity.Cou_Name; Song.Entities.Course tm = Gateway.Default.From().Where(Course._.Cou_ID == entity.Cou_PID).ToFirst(); while (tm != null) { xpath = tm.Cou_Name + "," + xpath; if (tm.Cou_PID == 0) break; if (tm.Cou_PID != 0) { tm = Gateway.Default.From().Where(Course._.Cou_ID == entity.Cou_PID).ToFirst(); } } return xpath; } /// /// 学员是否购买了该课程 /// /// 课程id /// 学员Id /// 0不管是否过期,1必须是购买时效内的,2必须是购买时效外的 /// public Course IsBuyCourse(int couid, int stid, int state) { WhereClip wc = Student_Course._.Cou_ID == couid && Student_Course._.Ac_ID == stid; wc.And(Student_Course._.Stc_IsTry == false); if (state == 1) wc.And(Student_Course._.Stc_StartTime < DateTime.Now && Student_Course._.Stc_EndTime > DateTime.Now); if (state == 2) wc.And(Student_Course._.Stc_EndTime < DateTime.Now); return Gateway.Default.From() .InnerJoin(Student_Course._.Cou_ID == Course._.Cou_ID) .Where(wc).ToFirst(); } /// /// 学员是否购买了该课程 /// /// /// /// public bool IsBuy(int couid, int stid) { Song.Entities.Course course = Business.Do().CourseSingle(couid); if (course == null || !course.Cou_IsUse) return false; WhereClip wc = Student_Course._.Cou_ID == couid && Student_Course._.Ac_ID == stid; wc.And(Student_Course._.Stc_IsTry == false && Student_Course._.Stc_IsFree == false); wc.And(Student_Course._.Stc_StartTime < DateTime.Now && Student_Course._.Stc_EndTime > DateTime.Now); Student_Course sc = Gateway.Default.From().Where(wc).ToFirst(); return sc != null; } /// /// 学员购买的该课程 /// /// 学员Id /// 用于检索课程的字符 /// 0不管是否过期,1必须是购买时效内的,2必须是购买时效外的 /// public List CourseForStudent(int stid, string sear, int state, bool? istry, int count) { if (stid <= 0) return null; WhereClip wc = Student_Course._.Ac_ID == stid; //Song.Entities.Organization org = Business.Do().OrganCurrent(); //if (org != null) //{ // wc.And(Student_Course._.Org_ID == org.Org_ID); //} if (istry != null) wc.And(Student_Course._.Stc_IsTry == (bool)istry); if (state == 1) { WhereClip wc2 = new WhereClip(); wc2.And(Student_Course._.Stc_StartTime < DateTime.Now && Student_Course._.Stc_EndTime > DateTime.Now); //wc2.Or(Student_Course._.Stc_IsFree == true); wc.And(wc2); } if (state == 2) { //wc.And(Student_Course._.Stc_IsFree == false); wc.And(Student_Course._.Stc_EndTime < DateTime.Now); } if (!string.IsNullOrWhiteSpace(sear)) wc.And(Course._.Cou_Name.Like("%" + sear + "%")); return Gateway.Default.From() .InnerJoin(Student_Course._.Cou_ID == Course._.Cou_ID) .Where(wc).OrderBy(Student_Course._.Stc_StartTime.Desc).ToList(count); } /// /// 获取所有课程 /// /// 所在机构id /// 教师id /// /// public List CourseAll(int orgid, int sbjid, int thid, bool? isUse) { return CourseCount(orgid, sbjid, thid, -1, null, isUse, -1); } /// /// 某个课程的学习人数 /// /// 课程id /// 是否取全部值,如果为false,则仅取当前正在学习的 /// public int CourseStudentSum(int couid, bool? isAll) { WhereClip wc = new WhereClip(); if (couid > 0) wc.And(Student_Course._.Cou_ID == couid); if (isAll == null || isAll == false) { wc.And(Student_Course._.Stc_StartTime <= DateTime.Now); wc.And(Student_Course._.Stc_EndTime > DateTime.Now); } return Gateway.Default.Count(wc); } /// /// 清除课程的内容 /// /// public void CourseClear(int identify) { //删除章节 List outline = Gateway.Default.From().Where(Outline._.Cou_ID == identify).ToList(); if (outline != null && outline.Count > 0) { foreach (Song.Entities.Outline ol in outline) { Business.Do().OutlineClear(ol.Ol_ID); Business.Do().OutlineDelete(ol.Ol_ID); } } //删除试卷 List tps = Gateway.Default.From().Where(TestPaper._.Cou_ID == identify).ToList(); if (tps != null && tps.Count > 0) { foreach (Song.Entities.TestPaper t in tps) Business.Do().PagerDelete(t.Tp_Id); } //考试指南 List gcs = Gateway.Default.From().Where(GuideColumns._.Cou_ID == identify).ToList(); if (gcs != null && gcs.Count > 0) { foreach (Song.Entities.GuideColumns t in gcs) Business.Do().ColumnsDelete(t); } //清理试题 List ques = Gateway.Default.From().Where(Questions._.Cou_ID == identify).ToList(); if (ques != null && ques.Count > 0) { foreach (Song.Entities.Questions c in ques) Business.Do().QuesDelete(c.Qus_ID); } } public int CourseOfCount(int orgid, int sbjid, int thid) { WhereClip wc = new WhereClip(); if (orgid > 0) wc.And(Course._.Org_ID == orgid); if (sbjid > 0) { WhereClip wcSbjid = new WhereClip(); List list = Business.Do().TreeID(sbjid); foreach (int l in list) wcSbjid.Or(Course._.Sbj_ID == l); wc.And(wcSbjid); } if (thid > 0) wc.And(Course._.Th_ID == thid); return Gateway.Default.Count(wc); } /// /// 获取指定个数的课程列表 /// /// 所在机构id /// 教师id /// /// 取多少条记录,如果小于等于0,则取所有 /// public List CourseCount(int orgid, int sbjid, int thid, int pid, string sear, bool? isUse, int count) { WhereClip wc = new WhereClip(); if (orgid > 0) wc.And(Course._.Org_ID == orgid); if (sbjid > 0) { WhereClip wcSbjid = new WhereClip(); List list = Business.Do().TreeID(sbjid); foreach (int l in list) wcSbjid.Or(Course._.Sbj_ID == l); wc.And(wcSbjid); } if (thid > 0) wc.And(Course._.Th_ID == thid); if (pid > 0) wc.And(Course._.Cou_ID == pid); if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); return Gateway.Default.From().Where(wc) .OrderBy(Course._.Cou_Tax.Desc).ToList(count); //如果是采用多个教师对应一个课程,用下面的方法 //count = count < 1 ? int.MaxValue : count; //if (thid < 1) //{ // WhereClip wc = Course._.Org_ID == orgid; // if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); // return Gateway.Default.From().Where(wc).OrderBy(Course._.Cou_Tax.Desc).ToList(); //} //return Gateway.Default.From() // .InnerJoin(Teacher_Course._.Cou_ID == Course._.Cou_ID) // .Where(Teacher_Course._.Th_ID == thid) // .OrderBy(Course._.Cou_Tax.Desc).ToList(); } public List CourseCount(int orgid, int sbjid, string sear, bool? isUse, int count) { WhereClip wc = new WhereClip(); if (orgid > 0) wc.And(Course._.Org_ID == orgid); if (sbjid > 0) { WhereClip wcSbjid = new WhereClip(); List list = Business.Do().TreeID(sbjid); foreach (int l in list) wcSbjid.Or(Course._.Sbj_ID == l); wc.And(wcSbjid); } if (!string.IsNullOrWhiteSpace(sear)) wc.And(Course._.Cou_Name.Like("%" + sear + "%")); if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); return Gateway.Default.From().Where(wc) .OrderBy(Course._.Cou_Tax.Desc).ToList(count); } /// /// 获取指定个数的课程列表 /// /// 机构id /// 专业id /// 教师id /// 是否有直播课 /// /// /// /// public List CourseCount(int orgid, int sbjid, int thid, bool? islive, string sear, bool? isUse, int count) { WhereClip wc = new WhereClip(); if (orgid > 0) wc.And(Course._.Org_ID == orgid); if (sbjid > 0) { WhereClip wcSbjid = new WhereClip(); List list = Business.Do().TreeID(sbjid); foreach (int l in list) wcSbjid.Or(Course._.Sbj_ID == l); wc.And(wcSbjid); } if (thid > 0) wc.And(Course._.Th_ID == thid); if (islive != null) wc.And(Course._.Cou_ExistLive == (bool)islive); if (!string.IsNullOrWhiteSpace(sear)) wc.And(Course._.Cou_Name.Like("%" + sear + "%")); if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); return Gateway.Default.From().Where(wc) .OrderBy(Course._.Cou_Tax.Desc).ToList(count); } /// /// 获取指定个数的课程列表 /// /// 所在机构id /// 专业id,等于0取所有 /// /// /// 排序方式,默认null按排序顺序,flux流量最大优先,def推荐、流量,tax排序号,new最新,rec推荐 /// /// public List CourseCount(int orgid, int sbjid, string sear, bool? isUse, string order, int count) { WhereClip wc = new WhereClip(); if (orgid > 0) wc.And(Course._.Org_ID == orgid); if (sbjid > 0) { WhereClip wcSbjid = new WhereClip(); List list = Business.Do().TreeID(sbjid); foreach (int l in list) wcSbjid.Or(Course._.Sbj_ID == l); wc.And(wcSbjid); } if (!string.IsNullOrWhiteSpace(sear)) wc.And(Course._.Cou_Name.Like("%" + sear + "%")); if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); OrderByClip wcOrder = new OrderByClip(); if (order == "flux") wcOrder = Course._.Cou_ViewNum.Desc; if (order == "def") wcOrder = Course._.Cou_IsRec.Desc & Course._.Cou_ViewNum.Asc; if (order == "tax") wcOrder = Course._.Cou_Tax.Desc & Course._.Cou_CrtTime.Desc; if (order == "new") wcOrder = Course._.Cou_CrtTime.Desc; //最新发布 if (order == "rec") wcOrder = Course._.Cou_IsRec.Desc & Course._.Cou_Tax.Desc & Course._.Cou_CrtTime.Desc; return Gateway.Default.From().Where(wc) .OrderBy(wcOrder).ToList(count); } public bool CourseIsChildren(int orgid, int couid, bool? isUse) { WhereClip wc = new WhereClip(); if (orgid > 0) wc.And(Course._.Org_ID == orgid); if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); int count = Gateway.Default.Count(wc && Course._.Cou_PID == couid); return count > 0; } /// /// 分页取课程信息 /// /// /// /// /// /// /// /// /// public List CoursePager(int orgid, int thid, bool? isUse, string searTxt, int size, int index, out int countSum) { WhereClip wc = new WhereClip(); if (orgid > 0) wc.And(Course._.Org_ID == orgid); if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); if (!string.IsNullOrWhiteSpace(searTxt)) wc.And(Course._.Cou_Name.Like("%" + searTxt + "%")); if (thid > 0) wc.And(Course._.Th_ID == thid); countSum = Gateway.Default.Count(wc); return Gateway.Default.From().Where(wc).OrderBy(Course._.Cou_Tax.Desc).ToList(size, (index - 1) * size); //如果是采用多个教师对应一个课程,用下面的方法 //if (thid < 1) //{ // countSum = Gateway.Default.Count(wc); // return Gateway.Default.From().Where(wc).OrderBy(Course._.Cou_Tax.Desc).ToList(size, (index - 1) * size); //} //else //{ // countSum = Gateway.Default.From() // .InnerJoin(Teacher_Course._.Cou_ID == Course._.Cou_ID) // .Where(Teacher_Course._.Th_ID == thid) // .OrderBy(Course._.Cou_Tax.Desc).Count(); // return Gateway.Default.From() // .InnerJoin(Teacher_Course._.Cou_ID == Course._.Cou_ID) // .Where(Teacher_Course._.Th_ID == thid) // .OrderBy(Course._.Cou_Tax.Desc).ToList(size, (index - 1) * size); //} } public List CoursePager(int orgid, int sbjid, int thid, bool? isUse, string searTxt, string order, int size, int index, out int countSum) { WhereClip wc = Course._.Org_ID == orgid; if (sbjid > 0) { WhereClip wcSbjid = new WhereClip(); List list = Business.Do().TreeID(sbjid); foreach (int l in list) wcSbjid.Or(Course._.Sbj_ID == l); wc.And(wcSbjid); } if (thid > 0) wc.And(Course._.Th_ID == thid); if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); if (!string.IsNullOrWhiteSpace(searTxt)) wc.And(Course._.Cou_Name.Like("%" + searTxt + "%")); countSum = Gateway.Default.Count(wc); OrderByClip wcOrder = new OrderByClip(); if (order == "flux") wcOrder = Course._.Cou_ViewNum.Desc; if (order == "def") wcOrder = Course._.Cou_IsRec.Desc && Course._.Cou_ViewNum.Asc; if (order == "tax") wcOrder = Course._.Cou_Tax.Desc && Course._.Cou_CrtTime.Desc; if (order == "new") wcOrder = Course._.Cou_CrtTime.Desc; //最新发布 if (order == "rec") wcOrder = Course._.Cou_IsRec.Desc && Course._.Cou_Tax.Desc && Course._.Cou_CrtTime.Desc; return Gateway.Default.From().Where(wc).OrderBy(wcOrder).ToList(size, (index - 1) * size); } public List CoursePager(int orgid, int sbjid, string searTxt, string order, int size, int index, out int countSum) { WhereClip wc = Course._.Org_ID == orgid; if (sbjid > 0) { WhereClip wcSbjid = new WhereClip(); List list = Business.Do().TreeID(sbjid); foreach (int l in list) wcSbjid.Or(Course._.Sbj_ID == l); wc.And(wcSbjid); } wc.And(Course._.Cou_IsUse == true); if (!string.IsNullOrWhiteSpace(searTxt)) { //wc.And(Course._.Cou_Name.Like("%" + searTxt + "%")); string[] arrData = searTxt.Split(','); WhereClip wc2 = new WhereClip(); for (int i = 0; i < arrData.Length; i++) { wc2.Or(Course._.Cou_Name.Like("%" + arrData[i] + "%")); } wc.And(wc2); } else { wc.And(Course._.Cou_Name.Like("")); } countSum = Gateway.Default.Count(wc); OrderByClip wcOrder = new OrderByClip(); if (order == "flux") wcOrder = Course._.Cou_ViewNum.Desc; if (order == "def") wcOrder = Course._.Cou_IsRec.Desc && Course._.Cou_ViewNum.Asc; if (order == "tax") wcOrder = Course._.Cou_Tax.Desc && Course._.Cou_CrtTime.Desc; if (order == "new") wcOrder = Course._.Cou_CrtTime.Desc; //最新发布 if (order == "rec") wcOrder = Course._.Cou_IsRec.Desc && Course._.Cou_Tax.Desc && Course._.Cou_CrtTime.Desc; return Gateway.Default.From().Where(wc).OrderBy(wcOrder).ToList(size, (index - 1) * size); } /// /// 分页获取 /// /// /// 专业id,多个id用逗号分隔 /// /// /// /// /// /// public List CoursePager(int orgid, string sbjid, bool? isUse, string searTxt, string order, int size, int index, out int countSum) { return this.CoursePager(orgid, sbjid, isUse, null, searTxt, order, size, index, out countSum); } /// /// 分页获取 /// /// /// /// /// 是否是直播课 /// /// /// /// /// /// public List CoursePager(int orgid, string sbjid, bool? isUse, bool? isLive, string searTxt, string order, int size, int index, out int countSum) { WhereClip wc = Course._.Org_ID == orgid; if (!string.IsNullOrWhiteSpace(sbjid)) { WhereClip wcSbjid = new WhereClip(); foreach (string tm in sbjid.Split(',')) { if (string.IsNullOrWhiteSpace(tm)) continue; int sbj = 0; int.TryParse(tm, out sbj); if (sbj == 0) continue; wcSbjid.Or(Course._.Sbj_ID == sbj); //当前专业的下级专业也包括 List list = Business.Do().TreeID(sbj); foreach (int l in list) wcSbjid.Or(Course._.Sbj_ID == l); } wc.And(wcSbjid); } if (isUse != null) wc.And(Course._.Cou_IsUse == (bool)isUse); if (order == "live") isLive = true; if (isLive != null) wc.And(Course._.Cou_ExistLive == (bool)isLive); if (!string.IsNullOrWhiteSpace(searTxt)) wc.And(Course._.Cou_Name.Like("%" + searTxt.Trim() + "%")); countSum = Gateway.Default.Count(wc); OrderByClip wcOrder = new OrderByClip(); if (order == "flux") wcOrder = Course._.Cou_ViewNum.Desc; if (order == "def") wcOrder = Course._.Cou_IsRec.Desc && Course._.Cou_ViewNum.Asc; if (order == "tax") wcOrder = Course._.Cou_Tax.Desc && Course._.Cou_CrtTime.Desc; if (order == "new") wcOrder = Course._.Cou_CrtTime.Desc; //最新发布 if (order == "rec") wcOrder = Course._.Cou_IsRec.Desc && Course._.Cou_Tax.Desc && Course._.Cou_CrtTime.Desc; if (order == "free") { wc.And(Course._.Cou_IsFree == true); wcOrder = Course._.Cou_IsFree.Desc & Course._.Cou_Tax.Desc; } //if (order == "live") wc.And(); return Gateway.Default.From().Where(wc).OrderBy(wcOrder).ToList(size, (index - 1) * size); } /// /// 将当前项目向上移动;仅在当前对象的同层移动,即同一父节点下的对象向前移动; /// /// /// 如果已经处于顶端,则返回false;移动成功,返回true public bool CourseUp(int id) { //当前对象 Course current = Gateway.Default.From().Where(Course._.Cou_ID == id).ToFirst(); int tax = (int)current.Cou_Tax; //下一个对象,即弟弟对象;弟弟不存则直接返回false; Course next = Gateway.Default.From() .Where(Course._.Cou_Tax > tax) .OrderBy(Course._.Cou_Tax.Asc).ToFirst(); if (next == null) return false; //交换排序号 current.Cou_Tax = next.Cou_Tax; next.Cou_Tax = tax; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save(current); tran.Save(next); tran.Commit(); return true; } catch { tran.Rollback(); throw; } finally { tran.Close(); } } } /// /// 将当前项目向下移动;仅在当前对象的同层移动,即同一父节点下的对象向后移动; /// /// /// 如果已经处于顶端,则返回false;移动成功,返回true public bool CourseDown(int id) { //当前对象 Course current = Gateway.Default.From().Where(Course._.Cou_ID == id).ToFirst(); int tax = (int)current.Cou_Tax; //上一个对象,即兄长对象;兄长不存则直接返回false; Course prev = Gateway.Default.From() .Where(Course._.Cou_Tax < tax) .OrderBy(Course._.Cou_Tax.Desc).ToFirst(); if (prev == null) return false; //交换排序号 current.Cou_Tax = prev.Cou_Tax; prev.Cou_Tax = tax; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save(current); tran.Save(prev); tran.Commit(); return true; } catch { tran.Rollback(); throw; } finally { tran.Close(); } } } #region 私有方法 /// /// 计算当前对象在多级分类中的层深 /// /// /// private int _ClacLevel(Song.Entities.Course entity) { //if (entity.Cou_PID == 0) return 1; int level = 1; Song.Entities.Course tm = Gateway.Default.From().Where(Course._.Cou_ID == entity.Cou_PID).ToFirst(); while (tm != null) { level++; if (tm.Cou_PID == 0) break; if (tm.Cou_PID != 0) { tm = Gateway.Default.From().Where(Course._.Cou_ID == tm.Cou_PID).ToFirst(); } } entity.Cou_Level = level; Gateway.Default.Save(entity); List childs = Gateway.Default.From().Where(Course._.Cou_PID == entity.Cou_ID).ToList(); foreach (Course s in childs) { _ClacLevel(s); } return level; } /// /// 计算当前对象在多级分类中的路径 /// /// /// private string _ClacXPath(Song.Entities.Course entity) { //if (entity.Cou_PID == 0) return ""; string xpath = ""; Song.Entities.Course tm = Gateway.Default.From().Where(Course._.Cou_ID == entity.Cou_PID).ToFirst(); while (tm != null) { xpath = tm.Cou_ID + "," + xpath; if (tm.Cou_PID == 0) break; if (tm.Cou_PID != 0) { tm = Gateway.Default.From().Where(Course._.Cou_ID == tm.Cou_PID).ToFirst(); } } entity.Cou_XPath = xpath; Gateway.Default.Save(entity); List childs = Gateway.Default.From().Where(Course._.Cou_PID == entity.Cou_ID).ToList(); foreach (Course s in childs) { _ClacXPath(s); } return xpath; } #endregion #endregion #region 课程关联管理(与学生或教师) /// /// 获取选学人数最多的课程列表,从多到少 /// /// 机构Id /// 专业id /// 取多少条 /// public DataSet CourseHot(int orgid, int sbjid, int count) { string sql = @"select top {count} ISNULL(b.count,0) as 'count', c.* from course as c left join (SELECT cou_id, count(cou_id) as 'count' FROM [Student_Course] group by cou_id ) as b on c.cou_id=b.cou_id where org_id={orgid} and {sbjid} order by [count] desc"; count = count <= 0 ? int.MaxValue : count; sql = sql.Replace("{count}", count.ToString()); sql = sql.Replace("{orgid}", orgid.ToString()); //按专业选取(包括专业的下级专业) string sbjWhere = string.Empty; if (sbjid > 0) { List sbjids = Business.Do().TreeID(sbjid); for (int i = 0; i < sbjids.Count; i++) { sbjWhere += "sbj_id=" + sbjids[i] + " "; if (i < sbjids.Count - 1) sbjWhere += " or "; } } sql = sql.Replace("{sbjid}", sbjid > 0 ? "(" + sbjWhere + ")" : "1=1"); return Gateway.Default.FromSql(sql).ToDataSet(); } /// /// 某个学生是否正在学习某个课程 /// /// /// /// public bool StudyIsCourse(int stid, int couid) { Song.Entities.Student_Course sc = Gateway.Default.From() .Where(Student_Course._.Ac_ID == stid && Student_Course._.Cou_ID == couid && Student_Course._.Stc_IsTry==false && Student_Course._.Stc_StartTime < DateTime.Now && Student_Course._.Stc_EndTime > DateTime.Now) .ToFirst(); return sc != null; } /// /// 学生购买课程的记录项 /// /// 学员Id /// 课程id /// public Student_Course StudentCourse(int stid, int couid) { return Gateway.Default.From().Where(Student_Course._.Ac_ID == stid && Student_Course._.Cou_ID == couid) .ToFirst(); } /// /// 课程学习 /// /// 学生Id /// 课程id /// public void CourseBuy(int stid, int couid, float money, DateTime startTime, DateTime endTime) { Song.Entities.Student_Course sc = new Student_Course(); sc.Ac_ID = stid; sc.Cou_ID = couid; sc.Stc_Money = money; sc.Stc_StartTime = startTime; sc.Stc_EndTime = endTime; Song.Entities.Organization org = Business.Do().OrganCurrent(); sc.Org_ID = org.Org_ID; sc.Stc_CrtTime = DateTime.Now; //获取职业病培训数据 zybPxEntities zybPxEntities = new zybPxEntities(); Song.Entities.Accounts st = Extend.LoginState.Accounts.CurrentUser; zybPxEntities.pxrName = st.Ac_AccName; zybPxEntities.pxkc = couid.ToString(); zybPxEntities.enterpriseId = st.Ac_qyid; zybPxEntities.pxDate = sc.Stc_StartTime.ToString(); string peixun = JsonConvert.SerializeObject(zybPxEntities); /* string str = "";//http://36.133.51.104:8911/dzzyb/a/zybTjxx/insertTjxx System.Net.WebClient zybTj = new System.Net.WebClient(); zybTj.Encoding = System.Text.Encoding.UTF8; NameValueCollection nvls = new NameValueCollection(); nvls.Add("peixun", peixun); byte[] bts = zybTj.UploadValues(str, nvls); string result = System.Text.Encoding.UTF8.GetString(bts);*/ Gateway.Default.Save(sc); } /// /// 购买课程 /// /// 学生与课程的关联对象 public Student_Course Buy(Student_Course stc) { Course course = Gateway.Default.From().Where(Course._.Cou_ID == stc.Cou_ID).ToFirst(); if (course == null) throw new Exception("要购买的课程不存在!"); Accounts st = Gateway.Default.From().Where(Accounts._.Ac_ID == stc.Ac_ID).ToFirst(); if (st == null) throw new Exception("当前学员不存在!"); //判断学员与课程是否在一个机构下, //if (st.Org_ID != course.Org_ID) throw new Exception("当前员员与课程不隶属同一机构,不可选修!"); // Song.Entities.Organization org = Business.Do().OrganCurrent(); stc.Org_ID = org.Org_ID; stc.Stc_CrtTime = DateTime.Now; stc.Stc_IsTry = false; Gateway.Default.Save(stc); return stc; } /// /// 购买课程 /// /// 学员id /// 课程id /// 价格项 /// public Student_Course Buy(int stid, int couid, Song.Entities.CoursePrice price) { Course course = Gateway.Default.From().Where(Course._.Cou_ID == couid).ToFirst(); if (course == null) throw new Exception("要购买的课程不存在!"); Accounts st = Gateway.Default.From().Where(Accounts._.Ac_ID == stid).ToFirst(); if (st == null) throw new Exception("当前学员不存在!"); //余额是否充足 decimal money = st.Ac_Money; //资金余额 int coupon = st.Ac_Coupon; //卡券余额 int mprice = price.CP_Price; //价格,所需现金 int cprice = price.CP_Coupon; //价格,可以用来抵扣的卡券 bool tm = money >= mprice || money >= (mprice - (coupon > cprice ? cprice : coupon)); if (!tm) throw new Exception("资金余额或卡券不足"); //计算需要扣除的金额,优先扣除券 cprice = cprice >= coupon ? coupon : cprice; //减除的卡券数 mprice = mprice - cprice; //减除的现金数 //判断学员与课程是否在一个机构下, //if (st.Org_ID != course.Org_ID) throw new Exception("当前员员与课程不隶属同一机构,不可选修!"); //*********************生成流水账的操作对象 Song.Entities.MoneyAccount ma = new Song.Entities.MoneyAccount(); Song.Entities.CouponAccount ca = new Song.Entities.CouponAccount(); ma.Ac_ID = ca.Ac_ID = stid; ma.Ma_Money = mprice; //购买价格 ca.Ca_Value = cprice; //要扣除的卡券 //购买结束时间 DateTime start = DateTime.Now, end = DateTime.Now; if (price.CP_Unit == "日" || price.CP_Unit == "天") end = start.AddDays(price.CP_Span); if (price.CP_Unit == "周") end = start.AddDays(price.CP_Span * 7); if (price.CP_Unit == "月") end = start.AddMonths(price.CP_Span); if (price.CP_Unit == "年") end = start.AddYears(price.CP_Span); //int span = (end - start).Days; ma.Ma_From = ca.Ca_From = 4; ma.Ma_Source = ca.Ca_Source = "购买课程"; ma.Ma_Info = ca.Ca_Info = "购买课程:" + course.Cou_Name + ";" + DateTime.Now.ToString("yyyy-MM-dd") + " 至 " + end.ToString("yyyy-MM-dd"); //*************** //生成学员与课程的关联 Song.Entities.Student_Course sc = Business.Do().StudentCourse(stid, couid); if (sc == null) { sc = new Entities.Student_Course(); sc.Stc_CrtTime = DateTime.Now; } sc.Cou_ID = couid; sc.Ac_ID = stid; sc.Stc_Money = price.CP_Price; sc.Stc_StartTime = DateTime.Now; sc.Stc_EndTime = end; sc.Stc_IsFree = false; sc.Stc_IsTry = false; Song.Entities.Organization org = Business.Do().OrganCurrent(); sc.Org_ID = org.Org_ID; // ma.Ma_IsSuccess = true; if (mprice > 0) Business.Do().MoneyPay(ma); if (cprice > 0) Business.Do().CouponPay(ca); //分润 Business.Do().Distribution(course, st, mprice, cprice); Gateway.Default.Save(sc); return sc; } /// /// 免费学习 /// /// 学习ID /// 课程ID /// public Student_Course FreeStudy(int stid, int couid) { return FreeStudy(stid, couid, DateTime.Now, DateTime.Now.AddYears(101)); } /// /// 免费学习 /// /// 学习ID /// 课程ID /// 免费时效的开始时间 /// 免费时效的结束时间 /// public Student_Course FreeStudy(int stid, int couid, DateTime? start, DateTime end) { Song.Entities.Student_Course sc = Business.Do().StudentCourse(stid, couid); if (sc == null) { sc = new Entities.Student_Course(); sc.Stc_StartTime = start == null ? DateTime.Now : (DateTime)start; zybPxEntities zybPxEntities = new zybPxEntities(); Song.Entities.Accounts st = Extend.LoginState.Accounts.CurrentUser; zybPxEntities.pxrName = st.Ac_Name; zybPxEntities.pxkc = couid.ToString(); zybPxEntities.enterpriseId = st.Ac_qyid; zybPxEntities.pxDate = sc.Stc_StartTime.ToString("yyyy-MM-dd hh:mm:ss"); zybPxEntities.ygId = st.Ac_ygid; List zybList = new List(); zybList.Add(zybPxEntities); string peixun = JsonConvert.SerializeObject(zybList); //http://36.133.51.104:8911 正式 //http://localhost:8080 测试 //string str = "http://36.133.51.104:8911/dzzyb/a/zybPx/insertPx"; string str = ConfigurationManager.AppSettings["zyb_insertPx"] + "dzzyb/a/zybPx/insertPx"; System.Net.WebClient zybTj = new System.Net.WebClient(); zybTj.Encoding = System.Text.Encoding.UTF8; NameValueCollection nvls = new NameValueCollection(); nvls.Add("peixun", peixun); byte[] bts = null; string result; try { bts = zybTj.UploadValues(str, nvls); result = System.Text.Encoding.UTF8.GetString(bts); } catch (Exception e) { result = ""; } } sc.Stc_CrtTime = DateTime.Now; sc.Cou_ID = couid; sc.Ac_ID = stid; sc.Stc_StartTime = start == null ? sc.Stc_StartTime : (DateTime)start; sc.Stc_EndTime = end; sc.Stc_IsFree = true; sc.Stc_IsTry = false; Song.Entities.Organization org = Business.Do().OrganCurrent(); if (org != null) sc.Org_ID = org.Org_ID; Gateway.Default.Save(sc);//1 return sc; } /// /// 课程试用 /// /// /// public Student_Course Tryout(int stid, int couid) { //生成学员与课程的关联 Song.Entities.Student_Course sc = Business.Do().StudentCourse(stid, couid); if (sc == null) { sc = new Entities.Student_Course(); } sc.Cou_ID = couid; sc.Ac_ID = stid; sc.Stc_StartTime = DateTime.Now; sc.Stc_EndTime = DateTime.Now.AddYears(100); sc.Stc_IsFree = false; sc.Stc_IsTry = true; Song.Entities.Organization org = Business.Do().OrganCurrent(); sc.Org_ID = org.Org_ID; sc.Stc_CrtTime = DateTime.Now; Gateway.Default.Save(sc); return sc; } /// /// 是否试用该课程 /// /// /// /// public bool IsTryout(int couid, int stid) { WhereClip wc = Student_Course._.Cou_ID == couid && Student_Course._.Ac_ID == stid; wc &= Student_Course._.Stc_IsTry == true; Student_Course sc = Gateway.Default.From().Where(wc).ToFirst(); return sc != null; } /// /// 直接学习该课程 /// /// 课程id /// 学员id /// 如果是免费或限时免费、或试学的课程,可以学习并返回true,不可学习返回false public bool Study(int couid, int stid) { Song.Entities.Course course = Business.Do().CourseSingle(couid); if (course == null || !course.Cou_IsUse) return false; //获取学员与课程的关联 Song.Entities.Student_Course sc = Business.Do().StudentCourse(stid, couid); if (sc == null) { //免费 if (course.Cou_IsFree) { sc = this.FreeStudy(stid, couid); } else { //限时免费 if (course.Cou_IsLimitFree) { DateTime freeEnd = course.Cou_FreeEnd.AddDays(1).Date; if (course.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now) { sc = this.FreeStudy(stid, couid, DateTime.Now, course.Cou_FreeEnd.AddDays(1).Date); course.Cou_IsFree = true; } } else { //试学 if (course.Cou_IsTry) sc = this.Tryout(stid, couid); } } return course.Cou_IsFree || course.Cou_IsTry; } else { bool isbuy = this.IsBuy(couid, stid); if (isbuy) return true; //课程免费 if (course.Cou_IsFree) { sc = this.FreeStudy(stid, couid, null, DateTime.Now.AddYears(101)); return true; } else { //限时免费 if (course.Cou_IsLimitFree) { DateTime freeEnd = course.Cou_FreeEnd.AddDays(1).Date; if (course.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now) { sc = this.FreeStudy(stid, couid, null, course.Cou_FreeEnd.AddDays(1).Date); return true; } } else { //试学 if (course.Cou_IsTry) { sc = this.Tryout(stid, couid); return true; } } } return false; } } /// 取消课程学习 /// /// /// public void DelteCourseBuy(int stid, int couid) { //Gateway.Default.Delete(Student_Course._.Ac_ID == stid && Student_Course._.Cou_ID == couid); using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Delete(Student_Course._.Ac_ID == stid && Student_Course._.Cou_ID == couid); tran.Update(new Field[] { Accounts._.Ac_CurrCourse }, new object[] { -1 }, Accounts._.Ac_ID == stid && Accounts._.Ac_CurrCourse == couid); tran.Commit(); Extend.LoginState.Accounts.Refresh(stid); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); } } } /// /// 获取某个教师关联的课程 /// /// /// /// public List Course4Teacher(int thid, int count) { count = count < 1 ? int.MaxValue : count; return Gateway.Default.From() .InnerJoin(Teacher_Course._.Cou_ID == Course._.Cou_ID) .Where(Teacher_Course._.Th_ID == thid) .OrderBy(Course._.Cou_Tax.Desc).ToList(count); } /// /// 学习某个课程的学员 /// /// /// /// /// /// /// /// public Accounts[] Student4Course(int couid, string stname, string stmobi, int size, int index, out int countSum) { WhereClip wc = Student_Course._.Cou_ID == couid; if (!string.IsNullOrWhiteSpace(stname) && stname.Trim() != "") wc.And(Accounts._.Ac_Name.Like("%" + stname + "%")); if (!string.IsNullOrWhiteSpace(stmobi) && stmobi.Trim() != "") { WhereClip wcOr = new WhereClip(); wcOr.Or(Accounts._.Ac_MobiTel1.Like("%" + stmobi + "%")); wcOr.Or(Accounts._.Ac_MobiTel2.Like("%" + stmobi + "%")); wc.And(wcOr); } countSum = Gateway.Default.From().InnerJoin(Student_Course._.Ac_ID == Accounts._.Ac_ID) .Where(wc).OrderBy(Accounts._.Ac_LastTime.Desc).Count(); return Gateway.Default.From() .InnerJoin(Student_Course._.Ac_ID == Accounts._.Ac_ID) .Where(wc).OrderBy(Accounts._.Ac_LastTime.Desc).ToArray(size, (index - 1) * size); } #endregion #region 价格管理 /// /// 添加价格记录 /// /// 业务实体 public void PriceAdd(CoursePrice entity) { object obj = Gateway.Default.Max(CoursePrice._.CP_Tax, CoursePrice._.Cou_UID == entity.Cou_UID); entity.CP_Tax = obj is int ? (int)obj + 1 : 0; Song.Entities.Organization org = Business.Do().OrganCurrent(); if (org != null) entity.Org_ID = org.Org_ID; //校验是否已经存在,同一个时间单位,只准设置一个 CoursePrice cp = Gateway.Default.From().Where(CoursePrice._.Cou_UID == entity.Cou_UID && CoursePrice._.CP_Span == entity.CP_Span && CoursePrice._.CP_Unit == entity.CP_Unit).ToFirst(); if (cp != null) throw new Exception(string.Format("{0}{1}的价格已经设置过,请修改之前设置", entity.CP_Span, entity.CP_Unit)); Gateway.Default.Save(entity); PriceSetCourse(entity.Cou_UID); } /// /// 将产品价格写入到课程所在的表,取第一条价格 /// /// 课程UID public void PriceSetCourse(string uid){ CoursePrice[] prices = PriceCount(0, uid, true, 0); if (prices.Length > 0) { CoursePrice p = prices[0]; Song.Entities.Course course = Gateway.Default.From().Where(Course._.Cou_UID == uid).ToFirst(); if (course != null) { course.Cou_Price = p.CP_Price; course.Cou_PriceSpan = p.CP_Span; course.Cou_PriceUnit = p.CP_Unit; Gateway.Default.Save(course); } } } /// /// 修改价格记录 /// /// 业务实体 public void PriceSave(CoursePrice entity) { //校验是否已经存在,同一个时间单位,只准设置一个 CoursePrice cp = Gateway.Default.From().Where(CoursePrice._.Cou_UID == entity.Cou_UID && CoursePrice._.CP_ID != entity.CP_ID && CoursePrice._.CP_Span == entity.CP_Span && CoursePrice._.CP_Unit == entity.CP_Unit).ToFirst(); if (cp != null) throw new Exception(string.Format("{0}{1}的价格已经设置过,请修改之前设置", entity.CP_Span, entity.CP_Unit)); Gateway.Default.Save(entity); PriceSetCourse(entity.Cou_UID); } /// /// 删除价格记录 /// /// 业务实体 public void PriceDelete(CoursePrice entity) { Gateway.Default.Delete(entity); PriceSetCourse(entity.Cou_UID); } /// /// 删除,按主键ID; /// /// 实体的主键 public void PriceDelete(int identify) { CoursePrice p = Gateway.Default.From().Where(CoursePrice._.CP_ID == identify).ToFirst(); if (p != null) PriceDelete(p); } /// /// 删除,按全局唯一标识 /// /// public void PriceDelete(string uid) { Gateway.Default.Delete(CoursePrice._.Cou_UID == uid); PriceSetCourse(uid); } /// /// 获取单一实体对象,按主键ID; /// /// 实体的主键 /// public CoursePrice PriceSingle(int identify) { return Gateway.Default.From().Where(CoursePrice._.CP_ID == identify).ToFirst(); } /// /// 获取价格记录 /// /// /// /// /// /// public CoursePrice[] PriceCount(int couid, string uid, bool? isUse, int count) { WhereClip wc = new WhereClip(); if (isUse != null) wc &= CoursePrice._.CP_IsUse == (bool)isUse; if (!string.IsNullOrWhiteSpace(uid)) { wc &= CoursePrice._.Cou_UID == uid; } else { wc &= CoursePrice._.Cou_ID == couid; } return Gateway.Default.From().Where(wc).OrderBy(CoursePrice._.CP_Tax.Asc).ToArray(count); } /// /// 将当前项目向上移动;仅在当前对象的同层移动,即同一父节点下的对象这前移动; /// /// /// 如果已经处于顶端,则返回false;移动成功,返回true public bool PriceUp(int id) { //当前对象 CoursePrice current = Gateway.Default.From().Where(CoursePrice._.CP_ID == id).ToFirst(); int tax = (int)current.CP_Tax; //上一个对象,即兄长对象;兄长不存则直接返回false; CoursePrice prev = Gateway.Default.From().Where(CoursePrice._.CP_Tax < tax && CoursePrice._.Cou_UID == current.Cou_UID) .OrderBy(CoursePrice._.CP_Tax.Desc).ToFirst(); if (prev == null) return false; //交换排序号 current.CP_Tax = prev.CP_Tax; prev.CP_Tax = tax; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save(current); tran.Save(prev); tran.Commit(); return true; } catch { tran.Rollback(); throw; } finally { tran.Close(); } } } /// /// 将当前项目向下移动;仅在当前对象的同层移动,即同一父节点下的对象这前移动; /// /// /// 如果已经处于顶端,则返回false;移动成功,返回true public bool PriceDown(int id) { //当前对象 CoursePrice current = Gateway.Default.From().Where(CoursePrice._.CP_ID == id).ToFirst(); int tax = (int)current.CP_Tax; //下一个对象,即弟弟对象;弟弟不存则直接返回false; CoursePrice next = Gateway.Default.From().Where(CoursePrice._.CP_Tax > tax && CoursePrice._.Cou_UID == current.Cou_UID) .OrderBy(CoursePrice._.CP_Tax.Asc).ToFirst(); if (next == null) return false; //交换排序号 current.CP_Tax = next.CP_Tax; next.CP_Tax = tax; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save(current); tran.Save(next); tran.Commit(); return true; } catch { tran.Rollback(); throw; } finally { tran.Close(); } } } #endregion } }