function jsCallInputSheetTypeDetail() {

};

jsCallInputSheetTypeDetail.PageState = null;
jsCallInputSheetTypeDetail.userID = App.CurrentUser().UserID;
jsCallInputSheetTypeDetail.userName = App.CurrentUser().UserName;

$(function() {
    $("#htxtDescription").ikeEditor({ width: 570 });
    $("#htxtCNName").focus();
    jsCallInputSheetTypeDetail.PageState = q("PageState");
    if (jsCallInputSheetTypeDetail.PageState == "Add") {
        if (q("TypeID") != null) {
            $("#htxtParentTypeName").val(q("TypeName"));
            $("#hhidParentTypeID").val(q("TypeID"));
        }
    }
    if (jsCallInputSheetTypeDetail.PageState == "Edit") {
        $("#adminPower,#UserInfomation").show();
        jsCallInputSheetTypeDetail.BindDataByID(); /*修改时初始化控件*/
    }
});

/*确定*/
jsCallInputSheetTypeDetail.ConfirmBtnClick = function() {
    var result = -1;
    var formIndex = q("FormIndex");
    var loadAction = q("LoadAction");
    var strName = $.trim($("#htxtCNName").val()).split('\"').join('“'); strName = strName.split('\'').join('‘');
    var strEName = $.trim($("#htxtENName").val()).split('\"').join('“'); strEName = strEName.split('\'').join('‘');
    if (strName != "") {
        var entity = jsEntity.CreateEntityByTableName_access("eOA_fip_CallInputSheetType");
        entity.Fields.ParentID = $("#hhidParentTypeID").val() == "" ? 0 : $("#hhidParentTypeID").val();
        entity.Fields.CNName = strName;
        entity.Fields.ENName = strEName;
        entity.Fields.Remark = $("#htxtDescription").value() == "" ? null : escape($("#htxtDescription").value());
        entity.Fields.EndFlag = $("#hrdoIsStop").attr("checked") ? 1 : 0;

        if (jsCallInputSheetTypeDetail.PageState == "Edit") {
            entity.Fields.ID = $("#hideID").val();
            entity.Fields.LastModifier = jsCallInputSheetTypeDetail.userName;
            entity.Fields.LastModifierID = jsCallInputSheetTypeDetail.userID;
            entity.Fields.LastModifyTime = "@Time";
            result = entity.Update(entity);
        }
        else {
            entity.Fields.CreatorID = jsCallInputSheetTypeDetail.userID;
            entity.Fields.Creator = jsCallInputSheetTypeDetail.userName;
            entity.Fields.CreateTime = "@Time";
            result = entity.Insert(entity);
        }
        DBReader.DisposeEntity(entity);
        if (result) {
            alert("操作成功！");
            if (loadAction != null && loadAction != undefined) {
                //ShowWindow.opener.execScript(formIndex,"jsBDesignIndex.freshItemPage('tab-CallInputSheet','"+loadAction+"')");
                ShowWindow.opener.execScript(formIndex, loadAction);
            }
            ShowWindow.close();
        }
        else {
            alert("操作失败！");
        }
    }
    else {
        alert("名称不能为空！");
    }
    result, formIndex, loadAction, strName, strEName = null;
    CollectGarbage();
};

/*取消*/
jsCallInputSheetTypeDetail.Cancel = function() {
    ShowWindow.close();
};

/*清空所属上级*/
jsCallInputSheetTypeDetail.resetDataItem = function() {
    $("#htxtParentTypeName").val("");
    $("#hhidParentTypeID").val("");
};

/*根据类型ID获得实体*/
jsCallInputSheetTypeDetail.GetTypeById = function(typeID) {
    var strSql = "select t.*,ownerTable.CNName as ParentName  from eOA_fip_CallInputSheetType as t left join eOA_fip_CallInputSheetType as ownerTable on t.ParentID=ownerTable.ID where t.ID=" + typeID;
    var entity = DBReader.selectSqlForJson(strSql);
    return entity;
};

/*修改页面时绑定控件*/
jsCallInputSheetTypeDetail.BindDataByID = function() {
    var currentSelType = q("TypeID");
    var entity = $.parseJSON("[{" + jsCallInputSheetTypeDetail.GetTypeById(currentSelType) + "}]"); ;
    $("#htxtParentTypeName").val(entity[0].table[0].ParentName);
    $("#hhidParentTypeID").val(entity[0].table[0].ParentID);
    $("#htxtLable").val(entity[0].table[0].Number);
    $("#hhidLable").val(entity[0].table[0].Number);
    $("#htxtCNName").val(entity[0].table[0].CNName);
    $("#htxtENName").val(entity[0].table[0].ENName);
    $("#htxtDescription").value(entity[0].table[0].Remark != null ? unescape(entity[0].table[0].Remark) : "");

    $("#createUserName").html(entity[0].table[0].Creator);
    $("#createUserID").val(entity[0].table[0].CreatorID);
    $("#createTime").html(entity[0].table[0].CreateTime);
    $("#updateUserName").html(entity[0].table[0].LastModifier);
    $("#updateUserID").val(entity[0].table[0].LastModifierID);
    $("#updateTime").html(entity[0].table[0].LastModifyTime);

    $("#hideID").val(entity[0].table[0].ID);
    if (entity[0].table[0].EndFlag == 1) {
        $("#hrdoIsStop").attr("checked", true);
    }
    else {
        $("#hrdoIsStop").attr("checked", false);
    }

    DBReader.DisposeEntity(entity);
    entity = null;
    currentSelBillType = null;
    CollectGarbage();
};

/*选择上级弹出框*/
$(function() {
    $("#htxtParentTypeName").addtionInfo({ customFunction: function(me) {
        $(me).click(function() {
            /*弹出框*/
            if (jsCallInputSheetTypeDetail.PageState == "Edit") {
                $(me).dialog({
                    id: '_tree_ParentType' + parseInt(Math.random() * 10000),
                    title: '所属上级',
                    width: 260,
                    height: 500,
                    cover: true,
                    page: "frmCallInputSheetTypeTree.htm?hideID=" + $("#hideID").val() + "",
                    isclick: false
                });
            }
            else {
                $(me).dialog({
                    id: '_tree_ParentType' + parseInt(Math.random() * 10000),
                    title: '所属上级',
                    width: 260,
                    height: 500,
                    cover: true,
                    page: "frmCallInputSheetTypeTree.htm",
                    isclick: false
                });
            }
        });
    } 
    });
});
/*根据弹出框中双击选择的上级设置类型值*/
function SetValue(id, text) {
    $("#htxtParentTypeName").val(text);
    $("#hhidParentTypeID").val(id);
}
