<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Config" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Kesion.Course" %>
<script runat="server" type="text/C#">

    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
     
    int recordcount, pagecount;
    int PageIndex = new BasicField().GetCurrPage;
    int pagesize = 10;

    protected DataRow dr;
    private string GetVal(string fieldName)
    {
        if (dr != null)
        {
            return dr[fieldName].ToString();
        }
        else
        {
            return string.Empty;
        }
    }
    
    public static int Verify = 0;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        __info.Button2 = "确定保存(O)";
        string action = KSCMS.S("action");
        switch(action)
        {
            case "add"://新增
                if (KSCMS.S("adorup") == "adorup") 
                {
                    addorup();
                }
                break;
            case "del"://删除
                deleteSj(KSCMS.S("ids"));
                break;
            case "modify"://修改
                if (KSCMS.S("adorup") == "adorup")
                {
                    addorup();
                }
                else
                {
                    initialEdit(Utils.StrToInt(KSCMS.S("id")));
                }
                break;
        }
    }
    //添加（编辑）
    protected void addorup()
    { 
        Hashtable ht = new Hashtable();
        ht.Add("title", Utils.ChkSQL(KSCMS.S("TxtName")));
        //ht.Add("Content", Utils.ChkSQL(this.TxtIntro.Text));
        if (Utils.StrToInt(Teacher.getTeacherConfig(7)) == 1)
        {
            ht.Add("Verify", 0);
        }
        else
        {
            ht.Add("Verify", 1);
            ht.Add("VerifyTime", DateTime.Now);
        }
        ht.Add("IdCard", KSCMS.S("TxtIdCard"));
        ht.Add("CertificateNumber", KSCMS.S("TxtCertificateNumber"));
        ht.Add("PhotoUrl", Utils.ChkSQL(KSCMS.S("photourl")));
        if (KSCMS.S("action").Equals("add"))
        {
            int tcid=Utils.StrToInt(DataFactory.GetOnlyValue("select top 1 tcid from KS_CosTeacher where Field='" + __user.UserName + "'"));
            ht.Add("Flag", 1);
            ht.Add("adddate", DateTime.Now);
            ht.Add("userid", UserManage.GetUserInfo().UserID);//提供者
            ht.Add("TcID", tcid);
            CommonData.Insert("KS_CosTeacherCertificate", ht);
            if (Utils.StrToInt(Teacher.getTeacherConfig(7)) == 0)
            {
                EnterPrise.AddInorOutScore("rz", "rzadd", __user.UserName, __user.UserID);
                //Kesion.Course.Teacher.AddTcScore(9, UserManage.GetUserInfo().UserName, UserManage.GetUserInfo().UserID);
            }
            //新增学历证书的情况下
            Kesion.APPCode.Public.CountInfo(tcid, "teacherxueli");
            
            Msg.Alert("恭喜,学历证书添加成功!", BasicField.GetUserUrl("teacher/TcDegreeCertificate"));
        }
        else
        {
            CommonData.Update("KS_CosTeacherCertificate", ht, " where  ID=" + Utils.StrToInt(KSCMS.S("id")));
            Msg.Alert("恭喜,学历证书修改成功!", BasicField.GetUserUrl("teacher/TcDegreeCertificate"));
        }
    }
    //编辑初始化
    private void initialEdit(int WorkID)
    { 
        __info.Button2 = "确定修改(O)";

        SqlParam[] param = new SqlParam[1];
        param[0] = new SqlParam("ID", WorkID);

        using (DataTable dt = CommonData.GetDataTable("[KS_CosTeacherCertificate]", "*", param))
        {
            if (dt.Rows.Count > 0)
            {
                dr = dt.Rows[0];
                //this.TxtName.Text = dr["title"].ToString();
                //this.TxtIntro.Text = dr["Remarks"].ToString();
                //this.TxtCertificateNumber.Text = dr["CertificateNumber"].ToString();
                //this.TxtIdCard.Text = dr["IdCard"].ToString();
                //this.photourl.Text = dr["PhotoUrl"].ToString();
                //DefaultFile = dr["FjUrl"].ToString();
                Verify = Utils.StrToInt(dr["Verify"].ToString());
                 
            }
        }
    }
    //删除
    private void deleteSj(string WorkID)
    {
        if (WorkID == null || WorkID == "0") return;
        WorkID = Utils.FilterIDs(WorkID);
        using (DataTable dt = DataFactory.GetDataTable("select ID,Verify,tcid from KS_CosTeacherCertificate Where Flag=1 and userid=" + UserManage.GetUserInfo().UserID + " and  ID in(" + WorkID + ")"))
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int id = Utils.StrToInt(dr["ID"].ToString());

                    Hashtable ht = new Hashtable();
                    ht.Add("ID", id);
                    if (dr["Verify"].ToString() == "1")
                    {
                        //减少积分
                        EnterPrise.AddInorOutScore("rz", "rzdel", __user.UserName, __user.UserID);
                        //Kesion.Course.Teacher.MinuTcScore(10, UserManage.GetUserInfo().UserName, UserManage.GetUserInfo().UserID);
                    }
                    CommonData.Delete("[KS_CosTeacherCertificate]", ht);
                    //删除学历证书的情况下
                    Kesion.APPCode.Public.CountInfo(Utils.StrToInt(dr["tcid"].ToString()), "teacherxueli");
                }
            }
        }
        Msg.Alert("删除成功!", BasicField.GetUserUrl("teacher/TcDegreeCertificate"));
    }
    
</script> 
<%if (KSCMS.S("action") != "add" && KSCMS.S("action") != "modify")
  { %>
     <div ID="ListPanel"  Width="100%">
          <%if (Utils.StrToInt(Teacher.getTeacherConfig(5))==1) 
            {          
         %>   
         <div class="t_tybox"> 
            <div class="tytitle clearfix"><h4 class="lf">学历证书管理</h4><a href="<%=BasicField.GetUserUrl("teacher/TcDegreeCertificate","action-add") %>" class="addbtn">+添加学历证书</a>
            </div>   
            <%} %> 
            <div class="clear blank10"></div>
            <table id="tablist" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
              	<tr align="center" class="title">             
                     <td width="6%">序号</td>
                     <td width="6%">状态</td>
                     <td width="40%">名称</td>                  
                     <td width="12%">添加时间</td>
                     <td width="20%">操作</td>
              	</tr>   
                <%
                    string sqlParam = "KS_CosTeacherCertificate where  Flag=1 and  userID=" + UserManage.GetUserInfo().UserID + "";
                    using (DataTable dt = DataFactory.GetPage("*", sqlParam, "ID", "order by  adddate desc", PageIndex, pagesize, out recordcount, out pagecount))
                    {
                        if (dt.Rows.Count > 0)
                        {
                            int i = 0;
                            foreach(DataRow dr in dt.Rows)
                            {
                                i++;
                %>
                 <TR class="tdbg sort bar">
                     <td  align="center">
               		    <%=i.ToString()%>
                     </td>
                     <td class="Ctd" align="center">
			           <%= Utils.StrToInt(dr["verify"])==1?"<font color='red'>已审核</font>":Utils.StrToInt(dr["verify"])==2?"审核不通过":"正在审核"%>
				     </td>
		             <td class="tag_left lefticon">            
               		    <font class="fonths"><%= (dr["title"]) %></font>
                     </td> 
                     <td width="135">
				        <%=Utils.StrToDateTime(dr["adddate"].ToString()) %>
				     </td>
			         <td>
                 	    <div class="gl_btn">
                         <%=Utils.StrToInt(dr["verify"].ToString())==1?"<span>--</span><span class=\"span5\" style=\"width:50%\"><a href='"+BasicField.GetUserUrl("teacher/TcDegreeCertificate","action-del,ids-"+dr["id"])+"'  onclick=\"return(confirm('您确定要删除该学历证书吗?'));\"><i class=\"iconfont\">&#xe731;</i>删除</a></span>":Utils.StrToInt(dr["verify"].ToString())==2?"<span class=\"span4\" style=\"width:50%\"><a href='"+BasicField.GetUserUrl("teacher/TcDegreeCertificate","action-modify,id-"+dr["id"])+"'   ><i class=\"iconfont\">&#xe620;</i>编辑</a></span> <span class=\"span5\" style=\"width:50%\"><a href='"+BasicField.GetUserUrl("teacher/TcDegreeCertificate","action-del,ids-"+dr["id"])+"'  onclick=\"return(confirm('您确定要删除该学历证书吗?'));\"><i class=\"iconfont\">&#xe731;</i>删除</a></span>":"<span>--</span><span class=\"span5\" style=\"width:50%\"><a href='"+BasicField.GetUserUrl("teacher/TcDegreeCertificate","action-del,ids-"+dr["id"])+"'  onclick=\"return(confirm('您确定要删除该学历证书吗?'));\"><i class=\"iconfont\">&#xe731;</i>删除</a></span>"%>
                        </div>
                     </td>
			     </TR>
                <%
						} 
					}
					else {
						KSCMS.W(@"<tr class='tdbg'><td class=ctd style='text-align:center' colspan=5><div class=empty>暂无学历证书！</div></td> </td>");
					}
				}
				%> 
            </table>
            <div ID="Panel1"  Width="100%">
              
            </div>
            <div class="fy_box" style="border-top:0px; padding-top:0px">
				<%
                #region 分页
                string PageStr = "[KS:PageStr1]";
                BasicField.ReplaceFilterPage(ref PageStr, PageIndex, pagesize, pagecount, recordcount);
                KSCMS.W(PageStr);
                #endregion
                %>
            </div>
	    	<div class="clear"></div>
         </div> 
         <div style="padding:10px 0px 0px;">
			<script type="text/javascript">
			    showtips(' <span>操作说明：<br /></span><span class="tips_cor" style="display:block;margin-top:5px;">如果审核通过而且后台设置你有删除的功能，那么你确定要执行的将影响你的<font color="blue">综合积分</font></span>');
			</script>
		 </div> 
		 <%}else if(KSCMS.S("action")=="add"||KSCMS.S("action")=="modify"){ %>
            <div class="t_tybox">
                 <div class="ty_title">添加学历证书</div>
                 <form action="{$GetCurrUrl}"  method="post">
                    <div class="tips" style="padding:10px 0px; font-size:14px">
                        <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="border"> 
                            <tr>
                                <td align="right" class="lefttd" height="30" width="120">学历证书名称：</td>
                                <td class="tag_left"><input type="text" name="TxtName" ID="TxtName" Class="textbox"  Width="300px" value="<%=GetVal("title") %>" ></input>
                                    <font color=red >*</font>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" class="lefttd" height="30" width="120">学历证书编号：</td>
                                <td class="tag_left"><input type="text" name="TxtCertificateNumber" ID="TxtCertificateNumber" class="textbox" value="<%=GetVal("CertificateNumber") %>"  Width="300px"></input>
                                    <font color=red >*</font>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" class="lefttd" height="30" width="120">身份证号码：</td>
                                <td class="tag_left"><input type="text" name="TxtIdCard" ID="TxtIdCard" class="textbox" value="<%=GetVal("IdCard") %>"  Width="300px" MaxLength="18"></input>
                                    <font color=red >*</font>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" class="lefttd" height="30" >上传学历证书图片：</td>
                                <td class="tag_left">
                                   <input type="text" name="photourl" ID="photourl" value="<%=GetVal("PhotoUrl") %>" class="textbox"  style="float:left"></input>   
                                 
                                 <input style="display:none" type="button" class="ty_button" onclick="OpenThenSetValue('../plus/Include/SelectFile.aspx?ChannelID=1', 680, 340, window, jQuery('#photourl')[0]);" value="选择图片" />
                                
                                  <div class="clear" style="height:10px;"></div>
                                  <%=Kesion.APPCode.UploadAPI.EchoUpload("courseUserPic","photourl") %> 	
                                </td>
                            </tr>
                            <%if(Verify==2){ %>
                            <tr>
                                 <td align="right" class="lefttd" height="30" >备注：</td>
                                 <td class="tag_left"><textarea type="text" name="TxtIntro" ID="TxtIntro" TextMode="MultiLine" Width="90%" Height="200px"   ><%=GetVal("Remarks") %> </textarea>
                                    <%Kesion.APPCode.EditorAPI.EchoHead(); %>
                                    <% Kesion.APPCode.EditorAPI.EchoEditor("editor", "TxtIntro", "Basic",0,false,true,false,false);%>
                                 </td>
                            </tr>
                            <%} %>
                        </table>
                        <input type="hidden" name="adorup" value="adorup" />
                        <div class="clear blank10"></div>
                        <div class="cz_btn nofloat t-a-center">
                           <span><input type="submit"  ID="Button2" onclick="return(CheckForm())" class="button"  value="<%=__info.Button2 %>"  /></span>
                           <span><input type="button" class="button" onclick="window.history.go(-1);"value=" 返 回 "></span>
                        </div> 
                    </div>
                 </form>
                 <div class="clear blank20"></div>
           </div>
         <%} %>
		 <script> 
            function CheckForm() {
                if (jQuery('#TxtName').val() == '') {
                    KesionJS.Alert('学历证书名称必须输入!', "jQuery('#TxtName').focus()");
                    return false;
                }
                if (jQuery('#TxtCertificateNumber').val() == '') {
                    KesionJS.Alert('学历证书编号必须输入!', "jQuery('#TxtCertificateNumber').focus()");
                    return false;
                }
                if (jQuery('#TxtIdCard').val() == '') {
                    KesionJS.Alert('身份证号码必须输入!', "jQuery('#TxtIdCard').focus()");
                    return false;
                }
                if (jQuery('#photourl').val() == '') {
                    KesionJS.Alert('请选择上传图片!', "jQuery('#photourl').focus()");
                    return false;
                }
                return true;
            }
         </script>
