asp.net无限级添加及修改对象

<script type="text/javascript">

 

     var CreateNumber = "";

    function checkResponsible(index) {
        CreateNumber = index;
        var str = "/views/Test/UserinfoList.aspx?";
        var width = 750;
        var height = 520;
        window.Telligent_Modal.Open(str, width, height, callbackHandler2);
        return false;
    }
    //从对话框获得数据
    function callbackHandler2(res) {
        var names = "";
        var ids = "";
        var txt_Approinter1 = document.getElementById("inp_accreditation" + CreateNumber);
        var HiddenField11 = document.getElementById("inp_hd_accreditationID" + CreateNumber);
        txt_Approinter1.value = "";
        try {
            for (var i = 0; i < res.length; i++) {
                names += res[i].UserName;
                names += ",";
                ids += res[i].SysUserID;
                ids += ",";
            }
            txt_Approinter1.value = names.substring(0, names.length - 1);
            HiddenField11.value = ids.substring(0, ids.length - 1);
        } catch (e) {
            alert("请选择团队成员");
        }
    }
    function sortChanges(value, index) {
        document.getElementById("inp_hdf_Priority" + index).value = value
    }
    function TaskChanges(value, index) {
        document.getElementById("inp_hdf_taskdif" + index).value = value;
    }
    function createId() {
        return Math.round(Math.random() * 1000000);
    }
    function insert() {
        var table = document.getElementById('taskList');
        var NewRow = table.insertRow();
        NewRow.id = createId();
     
        var taskId = table.rows.length - 1;
        var cell2 = NewRow.insertCell();

        cell2.innerHTML = '<input type="hidden" id ="no' + NewRow.id + '" name ="no" value="' + NewRow.id + '" ><table id="yy"><tr><td style="text-align:left"><img src="Image/titlLog.gif"/><img src="http://www.cnblogs.com/Images/TaskImg/close.png" onclick="del(' + NewRow.id + ')"/></td></tr><tr><td><table class="Contents"><tr><td>项目名称;</td><td><input id="inp_projectName' + NewRow.id + '" type="text"/></td><td>委派人:</td><td><input id="inp_accreditation' + NewRow.id + '" type="text" /><img src="Image/person.jpg" onclick="checkResponsible(' + NewRow.id + ')"/><input type="hidden" name="tasks" id="inp_hd_accreditationID' + NewRow.id + '" /></td></tr><tr><td>开始时间:</td><td><input id="startTime' + NewRow.id + '"  type="text" onfocus="WdatePicker({isShowClear:true,readOnly:false})"  /></td><td>结束时间:</td><td><input type="text" id="endTime' + NewRow.id + '"onfocus="WdatePicker({isShowClear:true,readOnly:false})" /></td></tr><tr><td>项目描述:</td><td colspan="3"><textarea  class="Textarea"  id="inp_display' + NewRow.id + '"   ></textarea></td></tr></table></td></tr></table>'
      
    }
    function save() {
       
        if (!CreateTask()) {
            return;
        }
        try {
            document.getElementById('<%=BUT_OK.ClientID%>').click();
        }
        catch (e) {
            alert('Error');
        }
    }
    function del(id) {

        var table = document.getElementById("taskList");
        var flag = 0;
        for (i = 0; i <= table.rows.length; i++) {
            if (document.getElementsByName("no")[i].value == id) {
                document.getElementById('<%=delTask.ClientID%>').value = document.getElementById('<%=delTask.ClientID%>').value + id + '\;';
                table.deleteRow(i);
                flag = i;
                break;
            }
        }

    }
    function CreateTask() {

        var rows = document.getElementById('taskList').rows;

        var result = '';
        var valueTable = '';
        var autoorder = 0;
        var IDArray = '';
       
 
        for (i = 0; i < rows.length; i++) {
            var id = rows[i].id;
            if (id == "") {

                id = document.getElementsByName("no")[i].value;
            }
            autoorder = i + 1;
            var cells = rows[i].cells;

 

            if (cells[0].all('inp_projectName' + id).value == '') {
                alert('第' + autoorder + '项任务名称不能为空!');
                cells[0].all('inp_projectName' + id).focus();
                return false;
            }
            if (cells[0].all('inp_accreditation' + id).value == '') {
                alert('第' + autoorder + '项委派人不能为空!');
                cells[0].all('inp_accreditation' + id).focus();
                return false;
            }
            if (cells[0].all('inp_hd_accreditationID' + id).value == '') {
                 cells[0].all('inp_accreditation' + id).focus();
                alert('第' + autoorder + '项委派不支持填写,请选择!');
                return false;
            }
            if (cells[0].all('startTime' + id).value == '') {
                alert('第' + autoorder + '项开始时间不能为空!'); 
                cells[0].all('startTime' + id).focus();
                return false;
            }
            if (cells[0].all('endTime' + id).value == '') {
                alert('第' + autoorder + '项结束时间不能为空!'); 
                cells[0].all('endTime' + id).focus();
                return false;
            }
//            if (cells[0].all('inp_display' + id).value == '') {
//                alert('第' + autoorder + '项任务描述不能为空!'); 
//                cells[0].all('inp_display' + id).focus();
//                return false;
//            }
            if (cells[0].all('no' + id).value == '') {
                alert('');
                return false;
            }

            var BeginTime = document.getElementById('<%=txt_TStartTime.ClientID%>').innerText;
            var endTime = document.getElementById('<%=Txt_TendTime.ClientID%>').innerText;

            BeginTime = BeginTime.substr(0, 10);
            endTime = endTime.substr(0, 10);

            var arys = BeginTime.split('-');
            var times = arys[0] + arys[1] + arys[2]
            times = times.replace(" ", "0")

            var arye = endTime.split('-');
            var timese = arye[0] + arye[1] + arye[2]
            timese = timese.replace(" ", "0")

            var ISBTime = cells[0].all('startTime' + id).value;
            var ISDTime = cells[0].all('endTime' + id).value;

            ISBTime = ISBTime.substr(0, 10);
            ISDTime = ISDTime.substr(0, 10);


            var isarys = ISBTime.split('-');
            var istimes = isarys[0] + isarys[1] + isarys[2]
            istimes = istimes.replace(" ", "0")

            var idarye = ISDTime.split('-');
            var idtimese = idarye[0] + idarye[1] + idarye[2]
            idtimese = idtimese.replace(" ", "0")

 

            if (istimes > idtimese) {
                alert('第' + autoorder + '项开始与结束时间写入有误!'); 
                cells[0].all('startTime' + id).focus();
                return;
            }

            if (istimes >= times) {

            }
            else {
                alert('第' + autoorder + '项开始时间不能超项目开始时间!'); 
                cells[0].all('startTime' + id).focus();
                return false;
            }
            if (idtimese <= timese) {

            }
            else {
                alert('第' + autoorder + '项结束时间不能超过项目结束时间!');
                cells[0].all('endTime' + id).focus();
                return false;
            }
        

 

            try {
                var rowTable = cells[0].all('inp_projectName' + id).value + ',' + cells[0].all('inp_accreditation' + id).value + ',' + cells[0].all('inp_hd_accreditationID' + id).value + ',' + cells[0].all('startTime' + id).value + ',' + cells[0].all('endTime' + id).value + ',' + cells[0].all('inp_display' + id).value + ',' + cells[0].all('no' + id).value + 'ほ';
              
                valueTable = valueTable + rowTable;
            }
            catch (e) {


            }
        }
        
        document.getElementById('<%=HiddenField1.ClientID %>').value = valueTable;

        return true;
    }
</script>

posted on 2011-09-05 23:02  风夜  阅读(170)  评论(0编辑  收藏  举报