<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="Kesion.APPCode" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Kesion.Course" %>
<%@ Import Namespace="Kesion.Components" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
    bool isLoadPage = true;  //定义页面是否加载
    public string KejianID = string.Empty;
    public string KeJianUrl = string.Empty;
    public string sqlParam = "";
    public int t_free = 0;
    public EpConfig ep = new EpConfig();
    public int CurrPage = new BasicField().GetCurrPage;
    public int PageSize = 10;
    public int recordcount, pagecount;
    public int system = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        Course.CheckMVCVerify("Teacher/CourseList");//判断权限
        if (__user.GroupID == 4)
        {
            sqlParam = "KS_Courseface Where TeachWay=0 and userid=" + __user.UserID;
            system = 2;
        }
        else
        {
            system = 1;
            sqlParam = "KS_Courseface Where TeachWay=0  and schoolid=" + __user.UserID;
        }
        infoInitial();
        string DoMethod = KSCMS.S("do");

        switch (DoMethod)
        {
            case "add":
                if (!EnterPrise.GetTotal("face", 0))
                {
                    Msg.Alert("对不起，您添加的课程数量已达到上限!", KSCMS.GetComeUrl());
                    isLoadPage = false;
                    return;
                }
                new Kesion.Course.Course().CheckFree(0);
                infoInitial();
                break;
            case "verify":
                DataFactory.ExecuteNonQuery("UPDATE [KS_Course] SET [verify] = 0 WHERE system=2 and  courseid =" + __info.courseid);
                KSCMS.Redirect(KSCMS.GetComeUrl());
                break;
            case "modify":
                initialEdit(__info.courseid); //编辑
                break;
            case "del":
                DeleteCourse(__info.courseid.ToString());
                break;
            case "sell":
                //操作上下架
                CommonData.UpdateFieldStatus("KS_Courseface", "IsOff", "courseid", Utils.StrToInt(KSCMS.S("courseid")));
                Msg.Alert("操作成功", BasicField.GetUserUrl("teacher/FaceList"));
                break;
        }
        if (KSCMS.S("action").Equals("save"))
        {
            Utils.TipsDisabled();  //检查是否演示状态
            saveCourse();
        }
        if (KSCMS.S("action").Equals("del"))
        {
            DeleteCourse(KSCMS.S("ids"));
        }
    }
    protected void saveCourse()
    {
        infoInitial();
        Hashtable ht = new Hashtable();
        ht.Add("system", system);
        ht.Add("ClassID", Utils.StrToInt(__info.ClassID));
        /** 多课程分类选择  ***/
        string proids = string.Empty;

        ht.Add("tcid", __info.tcid);
        ht.Add("teacher",BaseFun.GetTeacher(KSCMS.S("teacherlist")));  //主教
        ht.Add("IsOtherTc", Utils.StrToInt(__info.IsOtherTc)); //是否有其他教师    

        if (Utils.StrToInt(__info.IsOtherTc) == 0)
        {
            ht.Add("TeacherName", "");//其他教师名称
        }
        else
        {
            ht.Add("TeacherName", Utils.RemoveXss(__info.techertest));//其他教师名称
        }

        ht.Add("cityid", __info.CityId);
        ht.Add("Provinceid", __info.Provinceid);
        ht.Add("CountyId", __info.CountyId);
        ht.Add("name", __info.TxtName);

        ht.Add("Intro", (__info.TxtIntro));
        ht.Add("Target", (__info.TxtTarget));
        ht.Add("Notice", (__info.TxtNotice));

        ht.Add("recommend", 0);
        ht.Add("popular", 0);
        ht.Add("istop", 0);
        ht.Add("huandeng", 0);
        ht.Add("comment", 0);
        ht.Add("tryout", 0);
        ht.Add("is3g", 0);
        ht.Add("TeachWay", 0);  //授课方式 1为网上授课 0为面授
        ht.Add("shixian", Utils.StrToInt(__info.shixian));//有效期
        ht.Add("seotitle", Utils.RemoveXss(__info.TxtName));
    
        ht.Add("IsExam", 1);//是否有试卷


        if (Utils.StrToInt(__info.regulations) > 100)
        {
            ht.Add("regulations", 100);
        }
        else if (Utils.StrToInt(__info.regulations) <= 0)
        {
            ht.Add("regulations", 0);
        }
        else
        {
            ht.Add("regulations", Utils.StrToInt(__info.regulations));
        }

        ht.Add("IsFree", Utils.StrToInt(__info.RadioButtonList2));//是否免费
        if (Utils.StrToInt(__info.RadioButtonList2) == 0)
        {
            ht.Add("Money", 0); //参考价
            ht.Add("Price_Member", 0); //市场价
            ht.Add("promotion", 0);
            ht.Add("zhekou", 0);   //折扣
        }
        else
        {
            ht.Add("zhekou", __info.zhekou);   //折扣
            ht.Add("Money", Utils.StrToFloat(__info.Money)); //参考价
            ht.Add("Price_Member", Utils.StrToFloat(__info.Price_Member)); //市场价

        }

        ht.Add("photourl", Utils.ChkSQL(__info.DefaultPic));//图片
        ht.Add("IsOff", __info.RBIsOff);//出售方式
                                        //	ht.Add("isBind", 0);
        ht.Add("BeginTime", Utils.ChkSQL(__info.begintime));
        ht.Add("endTime", Utils.ChkSQL(__info.endtime));
        ht.Add("OpenDate", __info.OpenDate);
        ht.Add("faceadd", Utils.ChkSQL(__info.faceadd));
        ht.Add("mapid", Utils.ChkSQL(__info.MapId));
        ht.Add("MaxPerson", __info.MaxPerson);
        if (KSCMS.S("do").Equals("add"))
        {
            Kesion.Controls.CustomFields.DoSchoolFieldSave(ref ht,"course");

            ht.Add("username", __user.UserName);//后台管理者
            DateTime _time = DateTime.Now;
            ht.Add("addTime", _time);
            ht.Add("refreshdate", DateTime.Now);        
              
            if (EnterPrise.GetTotal("face", 1))
            {
                CommonData.Insert("KS_Courseface", ht);
                 int courseId = Utils.StrToInt(CommonData.GetMaxId("KS_CourseFace", "courseid"));
                
                if (__user.GroupID == 3 || __user.GroupID == 3 && new TemporaryVar().SchoolID > 0)
                {
                    int uidd = new TemporaryVar().SchoolID;
                    if (__user.GroupID == 3)
                    {
                        uidd = new TemporaryVar().UserID; ;
                    }
                    DataFactory.ExecuteNonQuery("UPDATE [KS_EnterPrise] SET [FaceTotal] = [FaceTotal] + 1 WHERE UserId = " + uidd);

                }
        
                
                if (ep.GetEpConfig(8) == "0" || Teacher.TcAddIsVeryfy("course") == "0")  //bu需要审核
                {
                    EnterPrise.AddInorOutScore("course", "faceadd", __user.UserName, __user.UserID);
                }
                Kesion.Course.Course.UpdateCourseInfo(__info.courseid.ToString(), 1);  //更新课程数据
                 Kesion.Course.Course.UpdateCourseInfo(courseId.ToString(), 1);  //更新课程数据
                Msg.Alert("恭喜,课程添加成功!", BasicField.GetUserUrl("teacher/FaceList"));
                isLoadPage = false;
                return;
              
            }
            else
            {

                JS.Alert("您添加课数已达上限", BasicField.GetUserUrl("teacher/FaceList"));
                isLoadPage = false;
                return;
            }
        }
        else
        {
            // KSCMS.Die(KSCMS.S("courseid"));
            if (KSCMS.S("CBLaddtime").Equals("1")) //是否更新时间
            {
                ht.Add("refreshdate", DateTime.Now);
            }

            Kesion.Controls.CustomFields.DoSchoolFieldSave(ref ht, "edit");
            
            CommonData.Update("KS_Courseface", ht, "where CourseId=" + __info.courseid);

            Kesion.Course.Course.UpdateCourseInfo(__info.courseid.ToString(), 1);  //更新课程数据

            Msg.Alert("恭喜,课程修改成功!", BasicField.GetUserUrl("teacher/FaceList"));
            isLoadPage = false;
            return;
        }
    }
    private void DeleteCourse(string CourseId)
    {
        if (CourseId == null || CourseId == "0") return;

        CourseId = Utils.FilterIDs(CourseId);
       
        string result=Kesion.Course.Course.DeleteCourse(CourseId,true,true,true,__user.UserID);  //调用删除课程

        Msg.Alert("恭喜,课程删除成功!", KSCMS.GetComeUrl());
        isLoadPage = false;
        return;
    }
    private void CleanCache()
    {
        #region 更新分类缓存
        Kesion.Course.Course.ClearCacheFile("FaceList");
        #endregion
    }

    private void infoInitial()
    {
        if (KSCMS.S("do").Equals("add"))
        {
            __info.Label1 = "添加面授课程";
              __info.begintime = DateTime.Now.ToString();
           __info.endtime =  DateTime.Now.AddMonths(1).ToString();
           __info.OpenDate = DateTime.Now.AddDays(3).ToString();
        }
        else
        {
            __info.Label1 = "修改面授课程信息";
             __info.begintime = KSCMS.S("begintime");
        __info.endtime = KSCMS.S("endtime");
        __info.OpenDate = KSCMS.S("OpenDate");
        }
        __info.TxtName = KSCMS.S("TxtName");//课程名称
        __info.TxtIntro = KSCMS.S("TxtIntro");//课程介绍
        __info.TxtTarget = KSCMS.S("TxtTarget");//课程目标                                                                               
        __info.photourl = KSCMS.S("photourl");//图片
        __info.shixian = KSCMS.S("shixian");
        __info.TxtNotice = KSCMS.S("TxtNotice");//课程公告                                
        __info.RadioButtonList2 = Utils.StrToInt(KSCMS.S("RadioButtonList2")).ToString();//是否免费
        __info.RadioButtonList1 = Utils.StrToInt(KSCMS.S("RadioButtonList1")).ToString();//是否免费
        __info.zhekou = KSCMS.S("zhekou");//折扣        
        __info.Loadzhekou = KSCMS.S("Loadzhekou");//收费折扣
        __info.Price_Member = KSCMS.S("Price_Member");//课程市场价格
        __info.Money = KSCMS.S("Money");//课程参考价
        __info.radiotype = Utils.StrToInt(KSCMS.S("radiotype")).ToString();
        __info.Textppt = KSCMS.S("Textppt");
        __info.ClassID = KSCMS.S("DrpClassID1");//课程分类
        __info.courseid = Utils.StrToInt(KSCMS.S("courseid"));
        __info.dropclass = KSCMS.S("dropclass");
        __info.RBIsOff = Utils.StrToInt(KSCMS.S("RBIsOff").ToString()).ToString();
        __info.regulations = Utils.StrToInt(KSCMS.S("regulations"));
        __info.DefaultPic = KSCMS.S("DefaultPic");
        __info.IsOtherTc = Utils.StrToInt(KSCMS.S("IsOtherTc").ToString()).ToString();
        __info.techertest = KSCMS.S("techertest");
        __info.PanicMoney = Utils.StrToFloat(KSCMS.S("PanicMoney").ToString());
        __info.Provinceid = Utils.StrToInt(KSCMS.S("Provinceid").ToString());
        __info.CityId = Utils.StrToInt(KSCMS.S("CityId").ToString());
        __info.CountyId = Utils.StrToInt(KSCMS.S("CountyId").ToString());
        __info.t_free = 0;
        __info.epDefaultPic = KSCMS.S("epDefaultPic").ToString();

       
        __info.faceadd = KSCMS.S("faceadd");
        __info.MaxPerson = KSCMS.S("MaxPerson");
        __info.MapId = KSCMS.S("MapId");
        __info.tcid = Teacher.getTcID().ToString();
   
    }
    private void initialEdit(int CourseId)
    {
        SqlParam[] param = new SqlParam[1];
        param[0] = new SqlParam("CourseId", CourseId);

        using (DataTable dt = CommonData.GetDataTable("[KS_CourseFace]", "*", param))
        {
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                __info.RBIsOff = dr["IsOff"].ToString();
                __info.CountyId = Utils.StrToInt(dr["CountyId"].ToString());
                __info.Provinceid = Utils.StrToInt(dr["Provinceid"].ToString());
                __info.CityId = Utils.StrToInt(dr["Cityid"].ToString());
                __info.courseid = Utils.StrToInt(dr["courseid"].ToString());
                __info.TxtName = dr["Name"].ToString();//课程名称
                __info.TxtIntro = dr["Intro"].ToString();//课程介绍
                __info.TxtTarget = dr["Target"].ToString();//课程目标                                                                               
                __info.photourl = dr["photourl"].ToString();//图片
                __info.shixian = dr["shixian"].ToString();
                __info.TxtNotice = dr["Notice"].ToString();//课程公告                                
                __info.RadioButtonList2 = Utils.StrToInt(dr["IsFree"].ToString()).ToString();//是否免费
                __info.zhekou = dr["zhekou"].ToString();//折扣        
                __info.Price_Member = Kesion.APPCode.Public.ReturnShopPrice(Utils.StrToDecimal(dr["Price_Member"].ToString()));//课程市场价格
                __info.Money = Kesion.APPCode.Public.ReturnShopPrice(Utils.StrToDecimal(dr["Money"].ToString()));//课程参考价
                __info.ClassID = dr["classid"].ToString();
                //__info.MoreClass = dr["MoreClass"].ToString();
                __info.regulations = dr["regulations"].ToString(); // 试卷状态规定
                __info.IsOtherTc = Utils.StrToInt(dr["IsOtherTc"].ToString()).ToString();//是否其他教师
                __info.techertest = dr["TeacherName"].ToString();  //其他教师                   
                __info.tcid = dr["tcid"].ToString(); //名师ID；
                __info.DefaultPic = dr["photourl"].ToString();
                __info.dropclass = dr["examPleID"].ToString();
                __info.MapId = dr["mapid"].ToString();
                __info.MaxPerson = dr["MaxPerson"].ToString();
                __info.faceadd = dr["faceadd"].ToString();
                __info.begintime = dr["BeginTime"].ToString();
                __info.endtime = dr["EndTime"].ToString();
                __info.OpenDate = dr["OpenDate"].ToString();

            }
        }
    }

    private string initial1(int parentId, int type = 0)
    {
        #region 按分类快速搜索
        string selceted = "," + __info.ClassID + ",";
        if (type == 1)//更多分类
        {
            selceted = "," + __info.MoreClass + ",";
        }
        StringBuilder sb = new StringBuilder();
        using (DataTable dt = EnterPrise.getEpriseBusiness(__user.UserName, 1, 0))
        {
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int depth = Utils.StrToInt(dr[2].ToString());
                    if (depth <= 3)
                    {
                        int id = Utils.StrToInt(dr[0].ToString());
                        string CatetoryName = dr[1].ToString();
                        if (depth == 2)
                        {
                            CatetoryName = "　├ " + CatetoryName;
                        }
                        if (depth == 3)
                        {
                            CatetoryName = "　   　├ " + CatetoryName;
                        }
                        if (selceted.IndexOf("," + id.ToString() + ",") != -1)
                            sb.AppendFormat("<option value=\"{0}\" {2}>{1}</option>", id.ToString(), CatetoryName, "selected");
                        else
                            sb.AppendFormat("<option value=\"{0}\" {2}>{1}</option>", id.ToString(), CatetoryName, "");
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        if (string.IsNullOrEmpty(sb.ToString()))
        {
           
             Msg.Alert("请先设置面授的分类", BasicField.GetUserUrl("teacher/CsMemberClass"));
           
        }
        return sb.ToString();
        //return __info.CourseClass;
        #endregion
    }
    public string DataBinder()
    {
        StringBuilder sb = new StringBuilder();
        int Type = Utils.StrToInt(KSCMS.S("Type"));
        if (!string.IsNullOrEmpty(KSCMS.S("Type")))
        {
            switch (Type)
            {
                case 1:
                    sqlParam += " and verify=0 ";
                    break;
                case 2:
                    sqlParam += " and verify=1 ";
                    break;
                case 3:
                    sqlParam += " and IsOff=1 ";
                    break;
                case 4:
                    sqlParam += " and IsOff=0 ";
                    break;
                case 5:
                    sqlParam += " and isfree=0 ";
                    break;
                case 6:
                    sqlParam += " and isfree=1 ";
                    break;

            }
        }
        if (!string.IsNullOrEmpty(KSCMS.S("TextBox1")))
        {
            sqlParam += " and name like '%" + Utils.ChkSQL(KSCMS.S("TextBox1")) + "%'";
        }
        using (DataTable dt = DataFactory.GetPage("*", sqlParam, "Courseid", "order by  addTime desc", CurrPage, PageSize, out recordcount, out pagecount))
        {
            if (dt.Rows.Count > 0)
            {
              
              foreach (DataRow dr in dt.Rows)
                    {
                        sb.Append(" <li class=\"photo_box_list_li\"><span class=\"checkbtn_box border\"><input type=\"checkbox\"  name=\"ids\" id=\"ids\" value=\"" + dr["courseid"] + "\"   " + ((Convert.ToString(dr["verify"]) == "1") ? "class=\"checkbtn\"" : (Convert.ToString(dr["verify"]) == "0" ? "class=\"checkbtn\"" : " class=\"checkbtn checkno\" disabled")) + " />" +
            "</span>" +
                        "<div class=\"infos-pic\"><i class=\"tips\"  " + (Convert.ToString(dr["verify"]) == "1" ? (Convert.ToString(dr["IsOff"]) == "1" ? "" : "style=\"color: white; background-color:rgba(255,108,0,0.8);\" ") : "") + ">" + (Convert.ToString(dr["verify"]) == "1" ? (Convert.ToString(dr["IsOff"]) == "1" ? "在售" : "停售") : "未审核") + "</i><a href=\"" + (Convert.ToString(dr["verify"]) == "0" ? "javascript:;" : BasicField.GetRewriteUrl("faceview", Utils.StrToInt(dr["courseid"].ToString()))) + "\" target=\"_blank\">" +
                        "<img src=\"" + dr["photourl"].ToString() + "\" onerror=\"this.src='" + (string.IsNullOrEmpty(__info.epDefaultPic) ? "/sysimg/nopic.gif" : __info.epDefaultPic) + "'\"> </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>" +
                        "<div class=\"infoConBox\"><div class=\"infos-title\"><h2 class=\"h5\"><a href=\"" + (Convert.ToString(dr["verify"]) == "0" ? "javascript:;" : BasicField.GetRewriteUrl("faceview", Utils.StrToInt(dr["courseid"].ToString()))) + "\" title=\"" + dr["name"].ToString() + "\" target=\"_blank\">" + Utils.CutStr(dr["name"].ToString(), 15) +"</a>"+
                        (Convert.ToString(dr["recommend"]) == "1" ? "<font class=\"bg1\">荐</font>" : "") +
						(Convert.ToString(dr["popular"]) == "1" ? "<font class=\"bg2\">精</font>" : "") +
						(Convert.ToString(dr["istop"]) == "1" ? "<font class=\"bg3\">头</font>" : "") +
						(Convert.ToString(dr["huandeng"]) == "1" ? "<font class=\"bg4\">幻</font>" : "") +
						(Convert.ToString(dr["is3g"]) == "1" ? "<font class=\"bg5\">3g</font>" : "") +
						"<span class=\"type\">" + (Convert.ToString(dr["isFree"]) == "0" ? "<a mark=\"video\">免费</a>" : "<a mark=\"video\" class=\"redBg\">付费</a>") + "</a></span></h2></div>" +
						"<div class=\"infoTitle\">" +
						"<span class=\"price\">" +
					 (Utils.StrToInt(dr["IsFree"].ToString()) == 0 ? "<font class='green'>免费</font>" : (dr["promotion"].ToString() == "3" ? dr["jifen"].ToString() + "积分" : (dr["promotion"].ToString() == "1" || dr["promotion"].ToString() == "2" ? "¥" + Kesion.APPCode.Public.ReturnShopPrice(Utils.StrToDecimal(dr["PanicMoney"].ToString())) : (Utils.StrToDecimal(dr["price_member"].ToString()) == 0 ? "<font class='green'>免费</font>" : "¥" + Kesion.APPCode.Public.ReturnShopPrice(Utils.StrToDecimal(dr["price_member"].ToString())) + "" + (dr["promotion"].ToString() == "4" ? "+" + dr["jifen"].ToString() + "积分" : ""))))) +
					   "<del>¥" + Kesion.APPCode.Public.ReturnShopPrice(Utils.StrToDecimal(dr["Money"])) + "</del></span><span>" + dr["StudentNum"].ToString() + "人学习</span></div>" +
            			"<div class=\"btns\">" +
            			"<span><a href=\"" + BasicField.GetUserUrl("teacher/CsZlList", "type-1,courseid-" + dr["courseid"].ToString() + ",prt-3") + "\" >资料</a></span>" +
                        "<span><a href=\"" + BasicField.GetUserUrl("teacher/tcsendinfo", "courseid-" + dr["courseid"] + ",coursetype-1") + "\"></i>通知</a></span>" +
                		"<span>" + ((Convert.ToString(dr["verify"]) == "1" ) ? "<a href=\"" + BasicField.GetUserUrl("teacher/FaceList", "do-modify,courseid-" + dr["courseid"].ToString() + "") + "\">编辑</a>" : (Convert.ToString(dr["verify"]) == "0" ? "<a href=\"" + BasicField.GetUserUrl("teacher/FaceList", "do-modify,courseid-" + dr["courseid"].ToString() + "") + "\">编辑</a>" : "")) + "</span>" +
                		"<span>" + (Convert.ToString(dr["verify"]) == "1" ? (Convert.ToString(dr["IsOff"]) == "1" ? "<a href=\"" + BasicField.GetUserUrl("teacher/FaceList", "do-sell,courseid-" + dr["courseid"] + "") + "\" onclick=\"return(confirm('您确定要下架此课程吗?下架后学员将无法再报名此>下架</a>" : "<a href=\"" + BasicField.GetUserUrl("teacher/FaceList", "do-sell,courseid-" + dr["courseid"] + "") + "\">上架</a>") : "") + "</span>" +
                		"<span>" + ((Convert.ToString(dr["verify"]) == "1" ) ? "<a href=\"" + BasicField.GetUserUrl("teacher/FaceList", "do-del,courseid-" + dr["courseid"].ToString() + "") + "\" onclick=\"return(confirm('您确定要删除此课程吗?删除后会影响到您的综合积分'))\">删除</a>" : (Convert.ToString(dr["verify"]) == "0" ? "<a href=\"" + BasicField.GetUserUrl("teacher/FaceList", "do-delete,courseid-" + dr["courseid"].ToString() + "") + "\" onclick=\"return(confirm('您确定要删除此课程吗?'));\">删除</a>" : "")) + "</span>" +
            			"</div></div></li>");
                    }
               
            }
            else
            {
               KSCMS.W("<div class=\"empty\">没有添加任何课程信息</div>");
            }
        }
        return sb.ToString();
    }
   public string GetTeacherList(string tcid)
    {
        string selcected = "";
        StringBuilder sb = new StringBuilder();

        string sql = "select top 100 Tcid,Tname from KS_CosTeacher where verify=1 and tcid in(" + tcid + ") order by tcid desc";

        if (tcid == "0" || string.IsNullOrEmpty(tcid))
        {
            sql = "select top 100 Tcid,Tname from KS_CosTeacher where verify=1 and (userid=" + __user.UserID + " or   schoolid=" + __user.UserID + ") order by tcid desc";
        }
        using (DataTable dt = DataFactory.GetDataTable(sql))
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ListItem lii = new ListItem();

                    if (("," + tcid + ",").IndexOf("," + dr["tcid"].ToString() + ",") != -1 || (new TemporaryVar().GroupID == 4))
                    {
                        selcected = "selected";
                    }
                    else
                    {
                        selcected = "";
                    }
                    sb.AppendFormat("<option value=\"{0}\" {2} >{1}</option>", dr["tcid"].ToString(), dr["tname"].ToString(), selcected);
                }
            }
        }
        return sb.ToString();
    }

    public string GetBanXing()
    {
        string sql1 = "select id,title from KS_CosFaceType";
        StringBuilder sb = new StringBuilder();
        using (DataTable dt = DataFactory.GetDataTable(sql1))
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    string selected = string.Empty;
                    if (Utils.StrToInt(dr["id"].ToString()) == Utils.StrToInt(__info.dropclass))
                    {
                        selected = "selected";
                    }
                    sb.AppendFormat("<option value=\"{0}\" {2}>{1}</option>", dr["id"].ToString(), dr["title"].ToString(), selected);
                }
            }
        }
        return sb.ToString();
    }
    public string GetFenXiao()
    {
        StringBuilder sb = new StringBuilder();
        sb.AppendFormat(@"<option value=""{0}"">{1}</optoin>", "0", "--请选择分校地点--");
        string sql = "select top 15 mapid,name,Address from KS_EnterPriseCampus where status=1 and username='" + __user.UserName + "'  order by id desc ";
        using (DataTable dt = DataFactory.GetDataTable(sql))
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    sb.AppendFormat(@"<option value=""{0}"">{1}</option>", dr["mapid"].ToString() + "|" + dr["Address"].ToString(), dr["name"].ToString());
                }
            }
        }
        return sb.ToString();
    }
</script>

<script>
    function changedo(i) {
        if (i == 0) {
            $("#actiondel").val("search");
        }
    }
</script>

<%
    if (!isLoadPage) return;
	if (KSCMS.S("do") != "modify" && KSCMS.S("do") != "add")
	{
%>
<form name="aspnetForm" method="post" action="<%=BasicField.GetUserUrl("teacher/FaceList")%>" id="aspnetForm">
 
<div class="t_tybox">
 		
 		<div class="tytitle clearfix" style="padding:0;">
            <div class="tabs_header">
                <ul class="tabs clearfix">
                	<li><a href="<%=BasicField.GetUserUrl("teacher/CourseList") %>"><span>点播课程</span></a></li>
                 	<li><a href="<%=BasicField.GetUserUrl("teacher/livelist") %>"><span>直播课程</span></a></li>
                 	<li class="active"><a href="<%=BasicField.GetUserUrl("teacher/facelist") %>"><span>面授课程</span></a></li>
                </ul>
            </div>
            <a href="<%=BasicField.GetUserUrl("teacher/FaceList","do-add") %>" class="addbtn" style="float:right; margin-left:0; margin-right:20px;">+添加面授课程</a>
            <div class="property">
                <div class="name fr">筛选</div>
                <div class="propertyBox">
                    <ul class="tabs clearfix">
                        <span class="screen fl">选择状态：</span>
                        <li <%=KSCMS.S("Type")==""?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/FaceList") %>"><span>所有记录</span></a></li>

						<% if (ep.GetEpConfig("Setting", 8) == "1")  //bu需要审核
                        { %>
                        <li <%=KSCMS.S("Type")=="1"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/FaceList","Type-1") %>"><span><font color="red">待审核</font></span></a></li>
                        <li <%=KSCMS.S("Type")=="2"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/FaceList","Type-2") %>"><span>已审核</span></a></li>
                        <%} %>
                         <li <%=KSCMS.S("Type")=="3"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/FaceList","Type-3") %>"><span>已上架</span></a></li>
                         <li <%=KSCMS.S("Type")=="4"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/FaceList","Type-4") %>"><span>已下架</span></a></li>
                         <li <%=KSCMS.S("Type")=="5"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/FaceList","Type-5") %>"><span>免费</span></a></li>
                         <li <%=KSCMS.S("Type")=="6"?" class='active'":string.Empty %>><a href="<%=BasicField.GetUserUrl("teacher/FaceList","Type-6") %>"><span>付费</span></a></li>
                    </ul>
                </div>
            </div>
            <div class="top_c_sc" style="margin-right:10px;">
                <span>课程名称：</span>
                <input name="TextBox1" type="text" id="TextBox1" class="textbox" />
                <input type="submit" name="Button4" value=" 搜索 " id="Button4" class="button"  onclick="changedo(0)"/>
            </div>
     	</div> 
         <div class="photo_box">
               <ul class="photo_box_list clearfix">
                   <%=DataBinder()  %>  
               </ul>
         </div>          		   
        <div class="cz_btn">        
         	<span><input type="checkbox" class="checkbtn" name="chkall" id="chkall" onclick="CheckAll(this.form);" /><label for="chkall">全部选中</label></span>	
            <span><input type="submit" class="button" value="批量删除" onclick="return (GetIDS('del'));"></span>
			<input type="hidden" value="del" name="action" id="actiondel"> 
        </div> 
	 
<div class="fy_box">
      <%
            #region 分页
            string PageStr = "[KS:PageStr1]";
            BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
            KSCMS.W(PageStr);
            #endregion

         %>
         </div>
         	<div class="clearfix"></div>  
         	       
       </div>
       <div >
			<script type="text/javascript">
			    showtips(' <span>操作说明：<br /></span><span class="tips_cor" style="display:block;margin-top:5px;">1.如果是待审核是不能点击预览的,而且没有上下架的功能！<br>2.如果复选框是<font color="blue">打X</font>，代表是不能点击<br>3.如果审核通过而且后台设置你有删除的功能，那么你确定要执行的将影响你的<font color="blue">综合积分</font></span>');
			</script>
			</div> 
	   </form>

<%}else{Kesion.APPCode.EditorAPI.EchoHead(); %>


  <div class="t_tybox">
    	<div class="ty_title"><span id="Label1"><%=__info.Label1 %></span></div>

    	<script src="/ks_inc/DatePicker/WdatePicker.js"></script>
       
     
  <form name="aspnetForm" method="post" action="<%=BasicField.GetUserUrl("teacher/FaceList","do-"+KSCMS.S("do")+"") %>"" id="Form1">
   <input type="hidden" name="action" id="action" value="save" >
    <input type="hidden" name="courseid" value="<%=__info.courseid %>" >
		 
      <!--选项卡-->	
    <div class="tabs_header">
            <ul class="tabs tabs-spec clearfix">
                 <li class="active"><a href="JavaScript:;"><span>基本信息</span></a></li>
                 <li ><a href="javascript:;"><span>其他选项</span></a></li>
            </ul>
    </div>
        
        <div class="tab-content">
            <div class="tab-pane" style="display:block">
      
             <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="border">
             <tr>
		        <td class="lefttd" height="30" ><font color=red >*</font>课程名称：</td>
		         <td class="tag_left">
	              <input type="text" value="<%=__info.TxtName %>" class="textbox" id="TxtName" name="TxtName">
		         </td>
	          </tr> 
                <tr>
		              <td class="lefttd" height="30" align="right" style="width: 150px">课程类型：</td>
		              <td class="tag_left">
		              <select name="DrpClassID1" id="DrpClassID1">
		              <%=initial1(0) %>
		              </select>

		              </td>          
	              </tr>
                 <tr>
                     	    <%if (UserManage.GetUserInfo().SchoolID==0){ %>
             <td class="lefttd" align="right" style="width: 100px"> <font color=red >*</font>课程主教：</td>
              <td class="tag_left">  
         
                            <select  name="teacherlist" id="teacherlist" style="width: 200px; height: 140px !important; vertical-align: middle;" multiple="multiple">
	                                        <%=GetTeacherList(__info.tcid) %>
	                          </select>   
                              <a href="<%=BasicField.GetUserUrl("teacher/CsTeacher") %> " style="color:#999;">名师管理</a>
                
                              课程助教：
                              <input type="checkbox" class="checkbtn" name="IsOtherTc" value="1" <%=__info.IsOtherTc=="1"?" checked":"" %> onclick="if (this.checked){ $('#otherTeacher').show(); }else{  $('#otherTeacher').hide(); }" />
                              <span id="otherTeacher"<%=__info.IsOtherTc=="1"?"":" style='margin-top:10px;display:none'" %>>
                                <input name="techertest" type="text" style="width:120px;" id="techertest" value="<%=__info.techertest %>" class="textbox" /> 如：王老师      
                              </span>
             </td>          
       </tr>
                 <%} %>
	  <tr>
                    <td class="lefttd" height="30">班型：</td>

                    <td class="tag_left">
                        <select name="dropclass" id="dropclass">
	                      <%=GetBanXing() %>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" height="30"><font color="red">*</font>报名时间：</td>
                    <td class="tag_left">
                     <input name="begintime" type="text" value="<%=__info.begintime %>" id="begintime" class="textbox  Wdate" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd HH:mm:ss&#39;,minDate:&#39;%y-%M-%d&#39;});" /> 
              至 <input name="endtime" type="text" value="<%=__info.endtime %>" id="endtime" class="textbox  Wdate" onclick="WdatePicker({dateFmt:&#39;yyyy-MM-dd HH:mm:ss&#39;,minDate:&#39;%y-%M-%d&#39;});" />     
                    </td>
                </tr>
           
                 <tr>
                 <td class="lefttd" height="30">开课时间：</td>

                  <td class="tag_left">
                 <input name="OpenDate" type="text" value="<%=__info.OpenDate %>" id="OpenDate" class="textbox  Wdate" onclick="WdatePicker();" /> 
              
                </td>

            </tr>
				
                <tr>
                    <td class="lefttd" height="30"><font color="red">*</font>开课地点：</td>
                    <td class="tag_left">
                        <div style="float: left">
                            <input name="faceadd" type="text" value="<%=__info.faceadd %>" id="faceadd" class="textbox" style="width:260px;" />
                        </div>
                        <div style="float: left; line-height: 35px; padding: 0px 10px">快速选择=></div>
                        <div id="ctl00_KSContent_GroupPanel1" style="float: left">
						<select id="fenxiao" name='fenxiao' onchange="shc(this.value)">
						<%=GetFenXiao() %>

						</select>

                        </div><span style="float:left;line-height: 35px;">审核过才出现</span>

                    </td>

                </tr>
            <tr>
                    <td class="lefttd" height="30">经纬度：</td>
                    <td class="tag_left">
                        <input name="MapId" type="text" id="MapId" class="textbox" value="<%=__info.MapId %>" style="width:150px;float: left;" />
                        <a onclick="map()" class="ty_button" style="line-height: 35px;display:inline-block">添加电子地图坐标</a>

                    </td>
                </tr>
                <script type="text/javascript">
                	function map() {
                		window.open("http://api.map.baidu.com/lbsapi/getpoint/index.html", "坐标获取", "width=960px,height=700px;");
                	}
                	function shc(v) {
                		if (v == "0") {
                			jQuery("#MapId").val("");
                			jQuery("#faceadd").val("");
                		} else {
                			var str = v.split('|');
                			jQuery("#MapId").val(str[0]);
                			jQuery("#faceadd").val(str[1]);

                		}
                	}
                </script>
                <tr>
                    <td class="lefttd" height="30"><font color="red">*</font>限报人数：</td>
                    <td class="tag_left">
                        <input name="MaxPerson" type="text" value="<%=__info.MaxPerson %>" id="MaxPerson" class="textbox nopadtext" style="width:60px;" /><span class="tips">如:100</span>
                    </td>
                </tr>
                   <tr>
			            <td class="lefttd" height="30">收费方式：</td>
			            <td class="tag_left">
			            <table id="RadioButtonList2" class="radio" onclick="free()" border="0" >
		                    <tr>
			                    <td style="border:0;min-width:80px"><input type="radio" name="RadioButtonList2" value="0" <%=__info.RadioButtonList2=="0"?"checked":"" %> /><label for="RadioButtonList2_0">免费</label></td>
			                    <td style="border:0;min-width:80px"><input type="radio" name="RadioButtonList2" value="1" <%=__info.RadioButtonList2=="1"?"checked":"" %> /><label for="RadioButtonList2_1">付费</label></td>
		                    </tr>
	                    </table>
	            <script>
		            function free() {
			            var checkrad = jQuery("#RadioButtonList2 :radio[checked]").val();
			            if (checkrad == "0") {
				            jQuery("#Tbody1").css("display", "");
				            jQuery("#Tbody2").css("display", "none");
				            jQuery("#Tbody8").css("display", "none");
				

			            } else {
				            jQuery("#Tbody1").css("display", "none");
				            jQuery("#Tbody2").css("display", "");
				            jQuery("#Tbody8").css("display", "");
			            }
		            }
		            function OtherTc() {
			            var checkrad = jQuery("#ctl00_KSContent_IsOtherTc :radio[checked]").val();
			            if (checkrad == "1") {
				            jQuery("#Tbody4").css("display", "");
			            } else {
				            jQuery("#Tbody4").css("display", "none");
			            }
		            }
	
		            $(document).ready(function(){
			            OtherTc();
			            free();
		
		            })
		
	            </script>
			             </td>
		            </tr>
                  <tbody id="Tbody1" >
                  </tbody>

                  <tbody id="Tbody2"  style="display:none" >
                  <tr>
		            <td class="lefttd" height="30" ><font color=red >*</font>参考价格：</td>
		            <td class="tag_left">
	
		            <input name="Money" type="text" value="<%=__info.Money %>" id="Money" class="textbox" onfocus="zhekouss();" style="width:74px;" /> &nbsp; 元
		            &nbsp; &nbsp; &nbsp; 
		            折扣：<input name="zhekou" type="text" value="<%=__info.zhekou %>" class="textbox" id="zhekou" style="width:30px;" /> 折  

		            </td>
	              </tr>  
	              <tr>
		            <td class="lefttd" height="30" ><font color=red >*</font>课程价格：</td>
		              <td class="tag_left"><input name="Price_Member" type="text" value="<%=__info.Price_Member %>" id="Price_Member" class="textbox" onKeyUp="zhekouss();" onkeydown="zhekouss();" style="width:74px;" /> &nbsp; 元
		             </td>
	              </tr>  
	                </tbody>
					   
                     <tr>
			              <td class="lefttd" height="30" >购买课程有效时限：</td>
			             <td class="tag_left">                  
				             <input name="shixian" type="text" value="<%=__info.shixian %>" id="shixian" class="textbox" style="width:50px;text-align:center;padding-left:0;" /> &nbsp; 天 （设置“0”为不限） 
			              </td>
		              </tr> 
                     <tr>
                        <td class="lefttd">课程图片：</td>
                        <td class="tag_left"> 
                            <table>
                                <tr>
                                <td>
                                    <input id="DefaultPic" name="DefaultPic" width="350px" class="textbox" style="float:left"  type="text" value="<%=__info.DefaultPic%>" />
                                </td>
                                <td style="width:550px;"><%=Kesion.APPCode.UploadAPI.EchoUpload("courseUserPic","DefaultPic") %></td>
                              </tr>
                            </table>
                         </td>
                   </tr>
                   <tr>
		               <td class="lefttd" height="30">课程介绍：</td>
		               <td class="tag_left">
			               <textarea name="TxtIntro" rows="2" cols="20" id="TxtIntro" style="height:200px;width:80%;"><%=__info.TxtIntro %></textarea>
			            <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtIntro", "Basic", 0, false, true, true, false);     %>
			         </td>
		          </tr> 
                  <tr >
                    <td class="lefttd" height="30">出售方式：</td>
                    <td class="tag_left">
                         <table id="RadioButtonList2" class="radio" onclick="free()" border="0" >
		                    <tr>
			                    <td style="border:0;min-width:80px"><input id="RBIsOff_0" type="radio" name="RBIsOff" value="1" <%=__info.RBIsOff=="1"?"checked":"" %> /><label for="RBIsOff_0">上架</label></td>
			                    <td style="border:0;min-width:80px"><input id="RBIsOff_1" type="radio" name="RBIsOff" value="0" <%=__info.RBIsOff=="0"?"checked":"" %> /><label for="RBIsOff_1">下架</label></td>
		                    </tr>
	                    </table>
                    </td>
		        </tr>
            </table>
         
         </div>
         
            <div class="tab-pane" style="display:none">
            <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="border">
	          <tr>
		        <td class="lefttd" height="30" >课程省市：</td>
		         <td class="tag_left">
				             <script src="/plus/area.aspx?pid=<%=__info.Provinceid %>&cityid=<%=__info.CityId %>&CountyID=<%=__info.CountyId %>"></script>
					           <span class="tips">选择课程所在的省份和城市,方便检索。</span>
		         </td>
	          </tr>  
           <tr>
		           <td class="lefttd" height="30">课程目标：</td>
		           <td class="tag_left">
			           <textarea name="TxtTarget" rows="2" cols="20" id="TxtTarget" style="height:200px;width:80%;"><%=__info.TxtTarget %></textarea>
                      <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtTarget", "Basic", 0, false, true, true, false);     %>
			            </td>
		         </tr>
           <tr>
		   <td class="lefttd" height="30">课程公告：</td>
		   <td class="tag_left">
			   <textarea name="TxtNotice" rows="2" cols="20" id="TxtNotice" style="height:200px;width:80%;"><%=__info.TxtNotice %></textarea>
			    <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtNotice", "Basic", 0, false, true, true, false);     %>
			  </td>
		  </tr>
             <tr>
                    <td class="lefttd" height="30" style="width: 102px">
                        更新时间：</td>
                    <td class="tag_left">
                        <span id="CBLaddtime"><input id="CBLaddtime_0" class="checkbtn" type="checkbox" value="1" name="CBLaddtime$0" />
						<label for="ctl00_KSContent_CBLaddtime_0" style="padding-right:3px;padding-top:3px">更新</label></span>
                    </td>
                </tr>
	     </table>
       </div>
       <script>
          $('.tabs-spec li').click(function() {
              $(this).addClass('active').siblings().removeClass('active');
              $('.tab-content>.tab-pane:eq(' + $(this).index() + ')').show().siblings().hide();
          })
       </script>
 <!--选项卡-->	
       </div>
       <div class="cz_btn " style=" padding-left:190px;">
			<span><input type="submit" name="Button2" value="确定保存(O)" onclick="return (CheckForm());" id="Button2" class="button" /></span>
			<span><input type="button" class="button" onclick="window.history.go(-1);"value=" 返 回 "></span>
	   </div>
       <div class="clearfix"></div>
	  </form>

	  </div>
<%} %>
	 <script>
	
	 	$(function () {
	 		if ($(".price_cor font").text() == "免费") {
	 			$(".price_cor font").css("color", "green");
	 		}
	 	})

	
		
	 	function zhekouss() {
	 		var money = document.getElementById('Money').value;
	 		var Price = document.getElementById('Price_Member').value;
	 		var zhekou = (parseFloat(Price / money) * 10).toFixed(1);

	 		if (zhekou == "NaN" || zhekou <= 0) {
	 			zhekou = 0;
	 		} else if (zhekou == "Infinity" || zhekou >= 10) {
	 			zhekou = 10;
	 		}
	 		document.getElementById('zhekou').value = zhekou;
	 	}

	 	function CheckForm() {

	 		if (jQuery('#TxtName').val() == '') {
	 			KesionJS.Alert('课程名称必须输入!', "jQuery('#TxtName').focus()");
	 			return false;
	 		}
	 		var dest = document.getElementById('teacherlist').value;

	 		if (dest == '') {
	 			KesionJS.Alert('请选择课程教师!', "jQuery('#teacherlist').focus()");
	 			return false;
	 		}
	 		var checkrad = jQuery("#RadioButtonList2 :radio[checked]").val();
	 		if (checkrad == "1") {
	 			if ($('#Money').val() == "") {
	 				KesionJS.Alert("请设置参考价格！", "jQuery('#Money').focus()");
	 				return false;
	 			}
	 			if ($('#Price_Member').val() == "") {
	 				KesionJS.Alert("请设置课程价格！", "jQuery('#Price_Member').focus()");
	 				return false;
	 			}
	 			if (parseFloat($('#Price_Member').val()) > parseFloat($('#Money').val())) {
	 				KesionJS.Alert("课程价格不能大于参考价格！", "jQuery('#Price_Member').focus()");
	 				return false;
	 			}
	 		}

	 		return true;
	 	}
</script>