//#region ajax初始化设置 function ajaxInit(WindowLoadModel) { if (jQuery.fn.jquery == "1.4.4") { $.ajaxSetup({ type: "POST", contentType: "application/json", dataType: "json", data: "{}", cache: false, dataFilter: function (data, dataType) { if (data == "") return data; if (dataType == "json") { var model = Sys.Serialization.JavaScriptSerializer.deserialize(data); return model; } if (dataType == "jsonString") { var model = Sys.Serialization.JavaScriptSerializer.deserialize(data); if (model.d != "") model.d = Sys.Serialization.JavaScriptSerializer.deserialize(model.d); return model; } return data; }, error: function (xhr, status) { if (WindowLoadModel != null && WindowLoadModel != undefined) WindowLoadModel.Hide(); if (xhr.responseText != "") { try { var error = jQuery.parseJSON(xhr.responseText); if (error.Message == "Session丢失") { alert("登录信息丢失,请重新登录"); BackHome(); return; } alert(error.Message); } catch (e) { alert(xhr.responseText); } } } }); } else { $.ajaxSetup({ type: "POST", contentType: "application/json", converters: { "* text": window.String, "text html": true, "text json": Sys.Serialization.JavaScriptSerializer.deserialize, "text xml": jQuery.parseXML }, dataType: "json", data: "{}", cache: false, error: function (xhr, status) { } }); } $("select[binding],td[binding],div[binding]").each(function () { var id = this.id; var url = $(this).attr("url"); if (url == undefined) return; var modelId = $(this).attr("modelid"); if (modelId == undefined) return; var modelName = $(this).attr("modelname"); if (modelName == undefined) return; var TopName = $(this).attr("TopName"); var binding = $(this).attr("binding"); if (url == undefined || url == "" || url.indexOf("XXX") > -1) return; if (binding == undefined) return; switch (binding) { case "BindComboBox2": BindComboBox2(this.id, 0, url, modelId, modelName, TopName); break; case "BindComboBox_Class": BindComboBox_Class(this.id, 0, 0, url, modelId, modelName, TopName); break; case "BindComboBox_Teacher": BindComboBox_Teacher(this.id, 0, 0, url, modelId, modelName, TopName); break; case "BindComboBox_KeyName": var KeyName = $(this).attr("KeyName"); var IsAdd = $(this).attr("IsAdd"); if (IsAdd == "true") { IsAdd = true; } else { IsAdd = false; } BindComboBox_KeyName(this.id, KeyName, url, modelId, modelName, TopName, IsAdd); break; default: BindComboBox(this.id, url, modelId, modelName, TopName); } }); } //#endregion //#region 返回首页 function BackHome() { var objwin = window.parent; if (objwin == null) { window.location = '../Login.aspx'; } else { objwin.location = '../Login.aspx'; } } //#endregion //#region Table平均分配未分配的列 function TableAveColWidth(id) { var cols = $("#" + id).find("col"); var width = 0; try { width = parseInt($("#" + id).actual('width')); } catch (e) { return; } //var width = parseInt($("#" + id).width()); var width2 = 0; var i = 0; $(cols).each(function () { var aa = this.style.width; if (aa == null || aa == undefined || aa == "" || aa == "0px") { i++; return true; } if (aa.indexOf("px") > -1) aa = aa.substr(0, aa.length - 2); width2 += parseInt(aa); }); var colWidth = (width - width2) / i; $(cols).each(function () { var aa = this.style.width; if (aa == null || aa == undefined || aa == "" || aa == "0px") { $(this).css("width", colWidth + "px"); } }); } //#endregion //#region JsonTable创建html表格 function JsonTableToHtml(tb) { var html = new Sys.StringBuilder(); var ColIndex = 0; html.append(""); if (tb.Cells.length > 0) { $(tb.Cells).each(function (i) { if (ColIndex == 0) { if (this.IsHader == true) { html.append(""); } else { html.append(""); } } if (this.IsHader == true) { //创建列 html.append(""); } else { html.append(""); } if (ColIndex == tb.ColumnNumber - 1) html.append(""); ColIndex++; if (ColIndex == tb.ColumnNumber) ColIndex = 0; }); if (ColIndex > 0) { for (var i = ColIndex; i < data.d.ColumnNumber; i++) { html.append(""); } if (ColIndex > 0) html.append(""); } } else { $(tb.Rows).each(function (i) { if (this[0].IsHader == true) { html.append(""); } else { html.append(""); } $(this).each(function (j) { if (this.ColSpan > 0 || this.RowSpan > 0) { if (this.IsHader == true) { html.append(""); } else { html.append(""); } } }); html.append(""); }); } html.append("
" + this.CellText + "" + this.CellText + "
" + this.CellText + "" + this.CellText + "
"); return html.toString(); } //#endregion //#region 下拉框或多选框HTML function CreateComboBox(id, ListArray, modelId, modelName, TopName, IsAdd) { var html = new Sys.StringBuilder(); if ($("#" + id).length > 0 && $("#" + id)[0].tagName.toUpperCase() == "SELECT") { if (TopName != undefined && TopName != "") html.append(""); if (IsAdd == true && ListArray == null) html.append(""); $(ListArray).each(function (i) { html.append(""); }); if (IsAdd == true) html.append(""); } else { $(ListArray).each(function (i) { html.append(" "); }); } $('#' + id).html(html.toString()); } //#endregion //#region 绑定下拉框或多选框_无参数 function BindComboBox(id, url, modelId, modelName, TopName) { $.ajax({ url: url, async: false, success: function (data) { CreateComboBox(id, data.d, modelId, modelName, TopName, false); } }); } //#endregion //#region 绑定下拉框或多选框_参数SchId function BindComboBox2(id, SchId, url, modelId, modelName, TopName) { var param = new Object(); param.SchId = SchId; $.ajax({ url: url, data: Sys.Serialization.JavaScriptSerializer.serialize(param), async: false, success: function (data) { CreateComboBox(id, data.d, modelId, modelName, TopName, false); } }); } //#endregion //#region 绑定班级下拉框或多选框_参数SchId,GradeCode function BindComboBox_Class(id, SchId, GradeCode, url, modelId, modelName, TopName) { var param = new Object(); param.GradeCode = GradeCode; $.ajax({ url: url, data: Sys.Serialization.JavaScriptSerializer.serialize(param), async: false, success: function (data) { CreateComboBox(id, data.d, modelId, modelName, TopName, false); } }); } //#endregion //#region 绑定教师下拉框或多选框_参数SchId,DeptId function BindComboBox_Teacher(id, SchId, DeptId, url, modelId, modelName, TopName) { var param = new Object(); param.SchId = SchId; param.DeptId = DeptId; $.ajax({ url: url, data: Sys.Serialization.JavaScriptSerializer.serialize(param), async: false, success: function (data) { CreateComboBox(id, data.d, modelId, modelName, TopName, false); } }); } //#endregion //#region 绑定KeyName下拉框或多选框_参数SchId,KeyName function BindComboBox_KeyName(id, KeyName, url, modelId, modelName, TopName, IsAdd) { var param = new Object(); param.KeyName = KeyName; $.ajax({ url: url, data: Sys.Serialization.JavaScriptSerializer.serialize(param), async: false, success: function (data) { CreateComboBox(id, data.d, modelId, modelName, TopName, IsAdd); } }); } //#endregion //#region 读取Session function ReadSession(key) { var param = new Object(); param.key = key; var value = ""; $.ajax({ url: "../UserService.asmx/GetLoginInfo", data: Sys.Serialization.JavaScriptSerializer.serialize(param), async: false, success: function (data) { value = data.d; } }); return value; } //#endregion //#region 生成查询条件 function CreateWhere(id, model) { model.cs = ""; $("#" + id + " [where]").each(function () { var val = $(this).val(); if (val == "-1" || val == "" || val == undefined || val == "省份" || val == "地级市" || val == "区、县级市、县") return true; if (this.type == "checkbox") { if (this.checked == true) { val = 1; } else { val = 0; } } var where = $(this).attr("where").replace(/@value/g, val); model.cs += " and " + where; }); } //#endregion //#region 生成保存对象 function CreateSaveModel(id, Model) { var error = ""; $("#" + id + " :file[ColRequired]").each(function () { var required = $(this).attr("ColumnRequired"); var ColName = $(this).attr("ColumnName"); if (required == "true" && Model[ColName] == "") { error = "请选择" + $(this).attr("ColumnDesc"); return false; } }); if (error != "") return error; //普通文本框,下拉框,多行文本框 $("#" + id + " :text[ColumnName],#" + id + " select[ColumnName],#" + id + " textarea[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); var ColText = $(this).attr("ColumnText"); var tagName = this.tagName.toUpperCase(); Model[ColName] = $.trim($(this).val()); if (Model[ColName] == null) Model[ColName] = ""; if (Model[ColName] == "-1") Model[ColName] = ""; if (Model[ColName] == "-9999") Model[ColName] = ""; var required = $(this).attr("ColumnRequired"); if (required == "true" && Model[ColName] == "") { if (tagName == "SELECT") { error = "请选择" + $(this).attr("ColumnDesc"); } else { error = $(this).attr("ColumnDesc") + "不能为空"; } return false; } if (tagName == "SELECT" && ColText != undefined && ColText != "") Model[ColText] = $(this).find(":selected").text(); var validType = $(this).attr("validType"); if (validType != undefined && Model[ColName] != "") { if (validType == "date" && JqueryIsData(Model[ColName]) == false) { error = $(this).attr("ColumnDesc") + "必须是日期格式,例2000-01-01"; return false; } if (validType == "email" && JqueryIsEmail(Model[ColName]) == false) { error = $(this).attr("ColumnDesc") + "必须是邮箱格式,例XXX@163.com"; return false; } if (validType == "idcard" && JqueryIsIdentityCard(Model[ColName]) == false) { error = $(this).attr("ColumnDesc") + "格式错误"; return false; } if (validType == "mobile" && JqueryIsPhone(Model[ColName]) == false) { error = $(this).attr("ColumnDesc") + "格式错误"; return false; } } }); //多选列表 $("#" + id + " td[binding],#" + id + " div[binding]").each(function () { var ColName = $(this).attr("ColumnName"); var ColRemark = $(this).attr("ColumnRemark"); var required = $(this).attr("ColumnRequired"); if (typeof (Model[ColName]) == "string") { Model[ColName] = ""; if (ColRemark != undefined && ColRemark != "") Model[ColRemark] = ""; $(this).find(':checked').each(function () { Model[ColName] += $(this).val() + ","; if (ColRemark != undefined && ColRemark != "") Model[ColRemark] += $(this).next().text() + ","; }); if (Model[ColName] != "") Model[ColName] = Model[ColName].substring(0, Model[ColName].length - 1); if (ColRemark != undefined && ColRemark != "" && Model[ColRemark] != "") Model[ColRemark] = Model[ColRemark].substring(0, Model[ColRemark].length - 1); if (required == "true" && Model[ColName] == "") { error = $(this).attr("ColumnDesc") + "至少要选择一项"; return false; } } else { var modelId = $(this).attr("modelid"); var modelName = $(this).attr("modelname"); Array.clear(Model[ColName]); $(this).find(':checked').each(function () { var m = new Object(); m[modelId] = $(this).val(); m[modelName] = $(this).val(); Array.add(Model[ColName], m); }); if (required == "true" && Model[ColName].length == 0) { error = $(this).attr("ColumnDesc") + "至少要选择一项"; return false; } } }); if (error != "") return error; //多选框 $("#" + id + " :checkbox[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); if (this.checked == true) { var TrueValue = $(this).attr("TrueValue"); if (TrueValue == undefined) TrueValue = "true"; if (TrueValue == "true") Model[ColName] = true; Model[ColName] = TrueValue; } else { var FlaseValue = $(this).attr("FlaseValue"); if (FlaseValue == undefined) FlaseValue = "false"; if (FlaseValue == "false") Model[ColName] = false; Model[ColName] = FlaseValue; } }); //单选框 $("#" + id + " :radio:checked[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); Model[ColName] = $(this).attr("ColumnValue"); }); return ""; } //#endregion //#region 生成对象赋值 function CreateGetModel(id, Model) { $("#" + id + " :file[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); var imgid = $(this).attr("imgid"); if (Model[ColName] != "") $("#" + imgid).attr("src", "../" + Model[ColName]); }); //普通文本框,下拉框,多行文本框 $("#" + id + " :text[ColumnName],#" + id + " textarea[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); var ColFormat = $(this).attr("ColumnFormat"); if (ColFormat != undefined && ColFormat != "" && Model[ColName] != null) { if (ColFormat.length == 2 && ColFormat.substr(0, 1) == "d") { $(this).val(parseFloat(Model[ColName].localeFormat("n" + ColFormat.substr(1, 1))).localeFormat("d")); } else { FormatValue = $(this).val(Model[ColName].localeFormat(ColFormat)); } } else { if (Model[ColName] == null) Model[ColName] = ""; $(this).val(Model[ColName]); } }); //普通文本框,下拉框,多行文本框 $("#" + id + " select[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); if (Model[ColName] != null && Model[ColName] != "") $(this).val(Model[ColName]); }); //span $("#" + id + " span[ColumnName],#" + id + " p[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); var ColFormat = $(this).attr("ColumnFormat"); if (ColFormat != undefined && ColFormat != "" && Model[ColName] != null) { if (ColFormat.length == 2 && ColFormat.substr(0, 1) == "d") { $(this).text(parseFloat(Model[ColName].localeFormat("n" + ColFormat.substr(1, 1))).localeFormat("d")); } else { FormatValue = $(this).text(Model[ColName].localeFormat(ColFormat)); } } else { var IsReplaceNewLine = $(this).attr("IsReplaceNewLine"); if (IsReplaceNewLine == "false") { $(this).html(Model[ColName]); } else { $(this).html(ReplaceNewLine(Model[ColName])); } } }); //多选框 $("#" + id + " :checkbox[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); var TrueValue = $(this).attr("TrueValue"); if (TrueValue == undefined) TrueValue = "true"; if (TrueValue != "true") TrueValue = parseInt(TrueValue); var FlaseValue = $(this).attr("FlaseValue"); if (FlaseValue == undefined) FlaseValue = "false"; if (FlaseValue != "false") FlaseValue = parseInt(FlaseValue); if (Model[ColName] == null) { $(this)[0].checked = false; return true; } if (Model[ColName] == true) { $(this)[0].checked = true; return true; } if (Model[ColName] == false) { $(this)[0].checked = false; return true; } if (Model[ColName] == TrueValue) { $(this)[0].checked = true; return true; } if (Model[ColName] == FlaseValue) { $(this)[0].checked = false; return true; } }); //单选框 $("#" + id + " :radio[ColumnName]").each(function () { var ColName = $(this).attr("ColumnName"); var ColValue = $(this).attr("ColumnValue"); if (Model[ColName] == ColValue) $(this)[0].checked = true; }); //多选列表 $("#" + id + " td[binding],#" + id + " div[binding]").each(function () { var ColName = $(this).attr("ColumnName"); $(this).find("input").removeAttr("checked"); var id = this.id; if (typeof (Model[ColName]) == "string") { var modelIds = Model[ColName].split(","); $(modelIds).each(function () { if (this == "") return true; $("#" + id).find("input[code=" + this + "]").attr("checked", "checked"); }); } else { var modelId = $(this).attr("modelid"); $(Model[ColName]).each(function () { if (this[modelId] == "") return true; $("#" + id).find("input[code=" + this + "]").attr("checked", "checked"); }); } }); } //#endregion //#region 清空控件内容 function ClearControlValue(id) { $("#" + id + " :text[ColumnName],textarea[ColumnName]").val(""); } //#endregion //#region 替换SQL字符串关健字 function MaskCodeSql(value) { return value.replace(/from/g, "####"); } //#endregion //#region 还原SQL字符串关健字 function UnMaskCodeSql(value) { return value.replace(/####/g, "from"); } //#endregion //#region 换行 function ReplaceNewLine(value) { if (value == undefined || value == null) return value; if (typeof (value) != "string") return value; return value.replace(/\r\n/g, "
").replace(/\n/g, "
"); } //#endregion //#region Base64 var Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode: function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode: function (string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode: function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } } //#endregion //#region 替换网址 function replaceAll(s, s2) { var url = "http://" + $.url.attr("host"); var port = $.url.attr("port"); if (port != "80") url += ":" + port; return s.replace(new RegExp(url, "gm"), s2); } //#endregion //#region 读取星期1-7 function GetDateWeek(InDate) { var week = InDate.getDay(); if (week == 0) week = 7;parseInt return week; } //#endregion //#region 转换日期 function parseDate(InDate) { return Date.parseInvariant(InDate, "yyyy-MM-dd"); } //#endregion //#region 验证日期 function JqueryIsData(value) { if (value == "") return true; var a = Date.parseInvariant(value, "yyyy-MM-dd"); if (a == null) { return false; } if (a.getFullYear() < 1900) { return false; } return true } //#endregion //#region 验证邮箱地址 function JqueryIsEmail(value) { if (value == "") return true; var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; if (!myreg.test(value)) { return false; } return true; } //#endregion //#region 验证身份证 function JqueryIsIdentityCard(sId) { if (sId == "") return true; var aCity = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" } var iSum = 0; var info = ""; //"你输入的身份证长度或格式错误"; if (!/^\d{17}(\d|x)$/i.test(sId)) return false; sId = sId.replace(/x$/i, "a"); //你的身份证地区非法 if (aCity[parseInt(sId.substr(0, 2))] == null) return false; sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-" + Number(sId.substr(12, 2)); var d = new Date(sBirthday.replace(/-/g, "/")); //身份证上的出生日期非法 if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) return false; for (var i = 17; i >= 0; i--) iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11); //你输入的身份证号非法 if (iSum % 11 != 1) return false; //aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女");//此次还可以判断出输入的身份证号的人性别 return true; } //#endregion //#region 验证邮政编码 function JqueryIsPostalcode(value) { if (value == "") return true; var myreg = /^\d{6}$/; if (!myreg.test(value)) { return false; } return true; } //#endregion //#region 验证电话号码或手机 function JqueryIsPhone(value) { if (value == "") return true; var myreg = /^\d{11}$|\d{8}$|0\d{2,3}-?\d{8}$/; if (!myreg.test(value)) { return false; } return true; } //#endregion //#region 检测文件是否是图片类型 function IsImage(filename) { var extStart = filename.lastIndexOf("."); var ext = filename.substring(extStart, filename.length).toUpperCase(); if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") { return false; } else { return true; } } //#endregion //#region 检测文件是否是Excel function IsExcel(filename) { var extStart = filename.lastIndexOf("."); var ext = filename.substring(extStart, filename.length).toUpperCase(); if (ext != ".XLS" && ext != ".XLSX") { return false; } else { return true; } } //#endregion //#region 检测文件是否是Word function IsWord(filename) { var extStart = filename.lastIndexOf("."); var ext = filename.substring(extStart, filename.length).toUpperCase(); if (ext != ".DOC" && ext != ".DOCX") { return false; } else { return true; } } //#endregion //#region 格式化数字 function FormatNumber(value, num) { return parseFloat(parseFloat(value).localeFormat("n" + num)).localeFormat("d"); } //#endregion