stringsql=$@"SELECT MAX(ChapterGradeNo) ChapterGradeNo FROM rb_course_chapter where Group_Id ={group_Id} and CourseId ={courseId} and ChapterNo <={chapterNo} and CourseRate ={(int)courseRate}";
,(SELECT COUNT(0) as Num FROM rb_course_chapter c2 WHERE c2.`Status` =0 and c2.CourseId = c.CourseId and c2.CourseRate = c.CourseRate and c2.SortNum <= c.SortNum) AS GrageNum
FROM rb_course_chapter c WHERE c.`Status` =0 and c.CourseId ={courseId}) cc2 on cc.ChapterId =cc2.ChapterId
SET cc.ChapterGradeNo = cc2.GrageNum
WHERE cc.Group_Id ={group_Id} and cc.CourseId ={courseId} and cc.ChapterNo >={chapterNo}";
stringsql=$@"SELECT MAX(Date) AS Date, COUNT(0) as ScrollMinNum FROM rb_scroll_appointment WHERE `Status` =0 and State <>5 and CourseEndTime >='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' and Group_Id ={group_Id} and StuId ={stuId} HAVING COUNT(0) >0";
stringsql=$@"SELECT MAX(Date) AS Date, COUNT(0) as ScrollMinNum FROM rb_scroll_appointment WHERE `Status` =0 and State <>5 and CourseEndTime >='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' and Group_Id ={group_Id} and StuId ={stuId}and GuestId ={guestId}HAVING COUNT(0) >0";
stringsql=$@"UPDATE rb_scroll_appointment SET ChapterNo = ChapterNo +{ChapterNum} WHERE Group_Id ={groupId} and StuId ={stuId} and GuestId ={guestId} ";
//string sql = $@"UPDATE rb_scroll_appointment SET ChapterNo = ChapterNo +{ChapterNum} WHERE Group_Id ={groupId} and StuId ={stuId} and GuestId ={guestId} ";
stringsql=$@"UPDATE rb_scroll_appointment a
SET a.ChapterNo = a.ChapterNo +{ChapterNum},a.CourseGradeId = (SELECT CourseRate FROM rb_course_chapter c WHERE c.Group_Id ={groupId} and c.CourseId =a.LearnCourseId and c.ChapterNo =a.ChapterNo)
,a.CourseGradeNo = (SELECT ChapterGradeNo FROM rb_course_chapter c WHERE c.Group_Id ={groupId} and c.CourseId =a.LearnCourseId and c.ChapterNo =a.ChapterNo)
WHERE a.Group_Id ={groupId} and a.StuId ={stuId} and a.GuestId ={guestId}";
stringsql=$@"SELECT a.Id,a.StuId,a.GuestId,a.OrderId,a.CourseId,s.StuName FROM rb_scroll_appointment a
LEFT JOIN rb_student s on a.StuId = s.StuId
WHERE a.Group_Id ={group_Id} and a.State =3 and a.AppointType =1 and a.ChapterNo ={chapterNo} and a.courseGradeId ={courseGradeId} and s.StuName LIKE '%{stuName}%'
WHERE a.Group_Id ={group_Id} and a.State =3 and a.AppointType =1 and a.CourseGradeNo ={courseGradeNo} and a.CourseGradeId ={courseGradeId} and s.StuName LIKE '%{stuName}%'
,A.LeaveStatus,A.LeaveTime,A.EmployeeTel,A.AccountType,A.Email,A.BaseHourFee,A.BaseHoursEnabled,A.EnableTime,IFNULL(A.DirectSupervisor,0) AS DirectSupervisor
,IFNULL(G.GroupName,'') AS GroupName,IFNULL(s.SName,'') AS SchoolName
,IFNULL(d.DeptId,0) AS Dept_Id,IFNULL(d.DeptName,'') AS DeptName,IFNULL(p.PostId,0) AS Post_Id, IFNULL(p.PostName,'') AS PostName
stringsql=$@"SELECT sog.Student_Id,sog.GuestId,s.StuName as GuestName,og.CourseChapterNo,DATE_FORMAT(sa.Date,'%Y-%m-%d') as AppointDate,sa.AppointNum FROM rb_student_orderguest sog
INNER JOIN rb_order_guest og on sog.GuestId = og.Id
INNER JOIN rb_order o on sog.OrderId = o.OrderId
INNER JOIN rb_student s on sog.Student_Id = s.StuId
INNER JOIN rb_class c on o.ClassId = c.ClassId
inner join rb_course_chapter cc on o.CourseId = cc.CourseId and cc.ParentId =0 and cc.ChapterNo ='{NextChapterNo}' and cc.CourseRate ={CourseGradeId}
inner join rb_course_chapter cc on o.CourseId = cc.CourseId and cc.ParentId =0 and cc.ChapterGradeNo ='{NextChapterGradeNo}' and cc.CourseRate ={CourseGradeId}
LEFT JOIN (
SELECT StuId,MAX(Date) AS Date, COUNT(0) as AppointNum FROM rb_scroll_appointment
WHERE `Status` =0 and State <>5 and CourseEndTime >=NOW() and Group_Id ={group_Id} GROUP BY StuId
) sa on sog.Student_Id = sa.StuId
WHERE o.Group_Id ={group_Id} and sog.`Status` =0 and og.GuestState <>2 and o.OrderState <>3 and c.ClassScrollType =2
and og.TotalChapterNo > og.CourseChapterNo ";
if(NextChapterNo>0){
sql+=$@" and (og.CourseChapterNo + 1 + IFNULL(sa.AppointNum,0)) ={NextChapterNo}";
}
and og.TotalChapterNo > og.CourseChapterNo and (og.CourseChapterNo + 1 + IFNULL(sa.AppointNum,0)) =cc.ChapterNo";