1:直接上圖、圖片有點多、我就沒全部上傳了、
(demo、使用方法、數據庫bak)下載:http://pan.baidu.com/s/1ntE5bDn
起源:
之前有好多人問我代碼生成器的源碼、我發了一部分、時間問題、不過那版本的功能和bug說不清楚有多少、現在最新版本支持:
枚舉值、附件上傳
環境配置:window、asp.net 、netframwork4.0 、SqlServer08R2即可
開發技術:jQuery、C#、asp.net、SqlServer、
目的:寫代碼的人都很煩躁每天干重復的工作、很無聊、除了復制就是粘貼、好多就是很累的很累的工作着、
下面版本要實現的功能:權限控制、文件流下載附件、整體項目穿上美觀的框架(和www.10086bank.com)類似 。
前段實現:
直接是JS代碼、密密麻麻的一大坨啊、、、、

var idarray = []; //count array idarray.push(1); //defualt var userid = "feifei", tiptime = 2000, userproid = -1, usertableid = -1; var userproname = ""; $(function () { //點擊名稱列(新增行) var sid = "-1"; $("input[name='txtname']").click(function () { var id = $(this).attr("id"); if (sid == id) { return; } //check is clicked sid = id; id = id.substr(id.length - 1); //get number values AddnewRow(id); }); //點擊提交 $("#btngo").click(function () { var objarray = []; var temps = ""; var mytid = "", mytname = "", isenum = ""; objarray.push("ID#ID#nvarchar#36#1###0#0#0#0"); for (var k = 1; k <= idarray.length; k++) { if ($("#txtname" + k).val() == "" || $("#txtname" + k).val() == "ID" || $("#txtname" + k).val() == "CreatTime") { continue; } temps = ""; //must clear data for down code exq temps = $("#txtname" + k).val() + "#" + $("#txtdescription" + k).val() + "#"; temps = temps + $("#selecttype" + k).find("option:selected").attr("myvalue") + "#" + $("#datalength" + k).val() + "#"; //類型 temps = temps + ($("#checkboxmust" + k).attr("checked") == "checked" ? "1" : "0") + "#"; //bug begin mytid = $("#selectnum" + k).find("option:selected").attr("myid"); if (mytid == "undefined" || mytid == undefined) mytid = ""; mytname = $("#selectnum" + k).find("option:selected").attr("myname"); if (mytname == "undefined" || mytname == undefined) mytname = ""; isenum = $("#selectnum" + k).attr("myenumid"); //獲取次字段是否為枚舉 temps = temps + mytid + "#"; temps = temps + mytname + "#"; temps = temps + isenum + "#"; temps = temps + ($("#checkboxquerylist" + k).attr("checked") == "checked" ? "1" : "0"); //bug end temps = temps + "#"; temps = temps + ($("#selecttype" + k).find("option:selected").attr("myvalue") == "file" ? "1" : "0"); //是否文件 temps = temps + "#"; temps = temps + $("#selecttype" + k).find("option:selected").attr("ENUMITEMVAL"); //枚舉內容 objarray.push(temps); } objarray.push("CreatTime#創建時間#datetime#50#0###0#1#0#0"); if ($("#txttablename").val() == "") { alerttip("請輸入表名!"); return; } if (objarray.length < 1) { alerttip("請輸入完整的數據項!"); return; } //alert(objarray.toString()); //return; waittips(); //等待中...... $.post("ajax/MainAjax.aspx?" + new Date().toTimeString(), { "userproname": userproname, "usertableid": usertableid, "tablename": $("#txttablename").val(), "userid": userid, "type": "new", "data": objarray.toString(), "proid": userproid }, function (data) { if (data.length > 0) { var arrayre = data.split('#'); usertableid = data[0]; asyncbox.tips("成功", 'success', tiptime); window.open("ajax/SQL/" + arrayre[0]); } }); }); //點擊創建按鈕顯示table創建界面 $("#anewpro").click(function () { $("#divnewedit").show(); }); //新項目提交 $("#btnpronews").click(function () { var name = $("#newprobtntext").val(); if (name == "") { alerttip("請輸入項目名稱"); return; } var isp = $("#newprobtncheck").attr("checked") == "checked" ? "1" : "0"; $.post("ajax/myajax.aspx?" + new Date().toTimeString(), { "userproid": userproid, "userid": userid, "type": "new", "name": name, "isp": isp }, function (data) { $("#newprobtntext").val(""); //新增 if (userproid == -1) { Addnewprolist(data, name, isp, "剛才"); success("新增成功!"); } //修改 else if (data == "1") { GetproDT(); userproid = -1; $("#newprobtncheck").attr("checked", false); success("修改成功"); } $("#newprodivpeoplelistitle").hide(); //隱藏面板 }); }); function GetproDT() { $.post("ajax/myajax.aspx?" + new Date().toTimeString(), { "userid": userid, "type": "getprodt" }, function (data) { if (data == "nodata") { return; } var obj = $.parseJSON(data); $("#tbodymylistpro").html(""); for (var i = 0; i < obj.length; i++) Addnewprolist(obj[i].PROID, obj[i].PRONAME, obj[i].ISPUBLICPRO, obj[i].PROCEATETIME) }); } GetproDT(); //創建新表 $("#btnpronewstable").click(function () { usertableid = -1; idarray = []; $("#divmyprolisttable").hide(); $("#divcreatenew").show(); $("#txttablename").val(""); $("#MytbodyContList").html(""); AddnewRow(0); }); //BACK $("#btnback01").click(function () { $("#divmyprolist").show(); $("#divmyprolisttable").hide(); $("#divcreatenew").hide(); }); //back $("#btnback02").click(function () { $("#divmyprolist").hide(); $("#divmyprolisttable").show(); $("#divcreatenew").hide(); $("#txttablename").val(""); GetproTable(); }); //shin peo $("#btnaddnewprodata").click(function () { $("#newprodivpeoplelistitle").show(); $(this).hide(); userproid = -1; }); }); //dom end //具體實現新の行の定法 function AddnewRow(newid) { newid = parseInt(newid) + 1; if (!ckexistd(newid)) { $("#MytbodyContList").append("<tr><td>" + newid + "</td><td class='center'><input type='text' onclick='AddnewRow(" + newid + ")' name='txtname' id='txtname" + newid + "' style='width:99px' /></td><td><input type='text' name='txtdescription' id='txtdescription" + newid + "' /></td><td class='center'><select id='selecttype" + newid + "' onchange='changeType(" + newid + ")' style='width:99px'><option myvalue='nvarchar' selected='selected'>nvarchar</option><option myvalue='int'>int</option><option myvalue='datetime'>datetime</option><option myvalue='float'>float</option><option myvalue='enum'>enum</option><option myvalue='file'>file</option></select><a id='lablea" + newid + "'>長度:<input style='width:40px' type='text' id='datalength" + newid + "' value='50' /></a><select style='width:100px;display:none' myenumid='0' id='selectnum" + newid + "'></select></td><td class='center'><input type='checkbox' checked='checked' name='mycheckbox' id='checkboxquerylist" + newid + "'/></td><td class='center'><input type='checkbox' name='mycheckbox' id='checkboxmust" + newid + "'/></td></tr>"); idarray.push(newid); $("#selecttype" + newid).trigger("liszt:updated"); $("#selecttype" + newid).chosen(); $("#checkboxquerylist" + newid).uniform(); $("#checkboxmust" + newid).uniform(); } } //判斷是否為第二次點擊 function ckexistd(val) { for (var i = (idarray.length - 1); i > -1; i--) { if (idarray[i] == val) return true; } return false; } //下拉列表點擊變換類型 function changeType(id) { var myvalue = $("#selecttype" + id).find("option:selected").attr("myvalue"); if (myvalue == "nvarchar") { $("#lablea" + id).show(); //$("#selectnum" + id).hide(); $("#selectnum" + id + "_chzn").hide(); $("#selectnum" + id).attr("myenumid", "0"); //不是枚舉 } else if (myvalue == "enum") { //$("#selectnum" + id).show(); $("#lablea" + id).hide(); $("#selectnum" + id).attr("myenumid", "1"); //是枚舉 GetUserEnumdata(id); //獲取枚舉列表 $("#selectnum" + id + "_chzn").show(); //顯示chonse } else { $("#lablea" + id).hide(); //$("#selectnum" + id).hide(); $("#selectnum" + id).attr("myenumid", "0"); //不是枚舉 $("#selectnum" + id + "_chzn").hide(); } } //獲取該用戶的所有枚舉LIST ----只是查詢名稱列表 var enumobj = null; function GetUserEnumdata(nid) { enumobj = null;//on time get data from DB if (enumobj == null) { $("#selectnum" + nid).html(""); $.post("ajax/myajax.aspx?" + new Date().toTimeString(), { "userid": userid, "type": "getenumdata" }, function (data) { if (data == "nodata") { alerttip("您還沒有建立枚舉數據、請先建立。"); return; } var obj = $.parseJSON(data); enumobj = obj; alerttip("當前為您查詢出" + obj.length + "條枚舉數據,您還可以自定義添加枚舉"); for (var i = 0; i < obj.length; i++) $("#selectnum" + nid).append("<option myid='" + obj[i].ID + "' myname='" + obj[i].Name + "'>" + obj[i].Name + "</option>"); $("#selectnum" + nid).trigger("liszt:updated"); $("#selectnum" + nid).chosen(); //変更このさまシ obj = null; }); } else { $("#selectnum" + nid).html(""); var obj = enumobj; //$.parseJSON(data); alerttip("當前為您查詢出" + obj.length + "條枚舉數據,您還可以自定義添加枚舉,添加后請刷新頁面獲取才能生效!"); for (var i = 0; i < obj.length; i++) { $("#selectnum" + nid).append("<option myid='" + obj[i].ID + "' myname='" + obj[i].Name + "'>" + obj[i].Name + "</option>"); } $("#selectnum" + nid).trigger("liszt:updated"); $("#selectnum" + nid).chosen(); //変更このさまシ obj = null; } } //查詢某個枚舉下面的所有item function GetEnumItemString(myenumid) { $.post("userajax/TabCompanyOP.aspx", { "type": "getenumitembyid", "myenumid": myenumid, "userid": userid }, function (data) { if (data == "nodata") { alerttip("沒有枚舉項數據!"); return; } var obj = $.parseJSON(data); alerttip("當前為您查詢出" + obj.length + "條枚舉數據,您還可以自定義添加枚舉"); var rebackstring = ""; for (var k = 0; k < obj.length; k++) { if (k == 0) { rebackstring = obj[k].NAME; } else { rebackstring = rebackstring + "#" + obj[k].NAME; } } obj = null; return rebackstring; }); } //項目列表的具體新增方法 function Addnewprolist(proid, name, isp, time) { $("#tbodymylistpro").append("<tr id='trpro" + proid + "'><td>" + name + "</td><td class='center'>" + (isp == 1 ? "公開" : "私人") + "</td><td class='center'>" + time + "</td><td class='center'><a class='btn btn-success' onclick=viewpro('" + name + "','" + proid + "')><i class='icon-zoom-in icon-white'></i>查看</a> <a class='btn btn-info' onclick=editpro('" + proid + "','" + name + "'," + isp + ")><i class='icon-edit icon-white'></i> 編輯 </a> <a class='btn btn-danger' onclick=deletepro('" + proid + "')><i class='icon-trash icon-white'></i> 刪除</a></td></tr>"); } //編輯項目 function editpro(proid, name, isp) { $("#newprodivpeoplelistitle").show(); //顯示面板 $("#btnaddnewprodata").hide(); userproid = proid; $("#newprobtntext").val(name); if (isp == 1 || isp == "1") $("#newprobtncheck").parent().attr("class", "checked"); //控制樣式 else $("#newprobtncheck").parent().attr("class", ""); //控制樣式 } //查看項目 function viewpro(name, proid) { userproname = name; userproid = proid; $("#divmyprolist").hide(); $("#divmyprolisttable").show(); GetproTable(); //獲取數據列表 } //刪除項目 function deletepro(proid) { if (confirm("確定刪除該項目嗎?") == false) return; $.post("ajax/myajax.aspx?" + new Date().toTimeString(), { "userid": userid, "type": "delete", "id": proid }, function (data) { if (data == "1") { $("#trpro" + proid).remove(); success("刪除成功!"); } }); } //獲取項目的Table function GetproTable() { $("#tbodymylistprotable").html(""); $.post("ajax/myajax.aspx?" + new Date().toTimeString(), { "userid": userid, "type": "getprotableDT", "proid": userproid }, function (data) { if (data == "nodata") return; var obj = $.parseJSON(data); //TABLENAME,TABLEID ,CREATTIME for (var k = 0; k < obj.length; k++) { $("#tbodymylistprotable").append("<tr id='trtable" + obj[k].TABLEID + "'><td>" + obj[k].TABLENAME + "</td><td class='center'>" + obj[k].CREATTIME + "</td><td class='center'><a class='btn btn-info' onclick=viewdeletetable('view','" + obj[k].TABLEID + "','" + obj[k].TABLENAME + "')><i class='icon-edit icon-white'></i>查看</a> <a onclick=viewdeletetable('delete','" + obj[k].TABLEID + "','" + obj[k].TABLENAME + "') class='btn btn-danger'><i class='icon-trash icon-white'></i> 刪除</a></td></tr>"); } }); } //查看or刪除表 function viewdeletetable(type, id, name) { if (type == "view") { usertableid = id; $("#txttablename").val(name); $("#divmyprolisttable").hide(); $("#divcreatenew").show(); Getvallist(usertableid); } else if (type == "delete") { if (confirm("確定刪除該表記錄嗎?") == false) return; $.post("ajax/myajax.aspx?" + new Date().toTimeString(), { "userid": userid, "type": "deletetable", "id": id }, function (data) { if (data == "1") { success("刪除成功!"); GetproTable(); } }); } } //點擊一個表獲取所有的字段 function Getvallist(tableid) { $("#MytbodyContList").html(""); idarray = []; //clear data $.post("ajax/myajax.aspx?" + new Date().toTimeString(), { "userid": userid, "type": "getonevallist", "tableid": tableid }, function (data) { if (data == "nodata") return; var obj = $.parseJSON(data); //TABLENAME,TABLEID ,CREATTIME var newid = -1; for (var k = 0; k < obj.length; k++) { if (obj[k].TNAME == "" || obj[k].TNAME == "undefined") continue; newid = (k + 1); $("#MytbodyContList").append("<tr><td>" + newid + "</td><td class='center'><input type='text' value='" + obj[k].TNAME + "' onclick='AddnewRow(" + newid + ")' name='txtname' id='txtname" + newid + "' style='width:99px' /></td><td><input type='text' name='txtdescription' value='" + obj[k].TDESCRIPTION + "' id='txtdescription" + newid + "' /></td><td class='center'><select data-rel='chosen' id='selecttype" + newid + "' onchange='changeType(" + newid + ")' style='width:99px'><option myvalue='nvarchar' selected='selected'>nvarchar</option><option myvalue='int'>int</option><option myvalue='datetime'>datetime</option><option myvalue='float'>float</option><option myvalue='enum'>enum</option><option myvalue='file'>file</option></select><a id='lablea" + newid + "'>長度:<input style='width:40px' type='text' value='" + obj[k].TLENGTH + "' id='datalength" + newid + "' value='" + obj[k].TLENGTH + "' /></a><select style='width:98px;' myenumid='" + obj[k].ISENUM + "' id='selectnum" + newid + "'></select></td><td class='center'><input type='checkbox' name='mycheckbox' id='checkboxquerylist" + newid + "'/></td><td class='center'><input type='checkbox' name='mycheckbox' id='checkboxmust" + newid + "'/></td></tr>"); $("#selecttype" + newid).val(obj[k].SELECTVAL); if (obj[k].SELECTVAL == "nvarchar") { $("#lablea" + newid).show(); $("#selectnum" + newid).hide(); } else if (obj[k].ISENUM == "1") {//是枚舉 $("#lablea" + newid).hide(); $("#selectnum" + newid).show(); //顯示枚舉元素 $("#selectnum" + newid).html(""); $("#selectnum" + newid).attr("myenumid", "1"); //枚舉 $("#selectnum" + newid).append("<option myid='" + obj[k].ENUMID + "' myname='" + obj[k].ENUMNAME + "'>" + obj[k].ENUMNAME + "</option>"); $("#selectnum" + newid).chosen(); } else { $("#lablea" + newid).hide(); $("#selectnum" + newid).hide(); } if (obj[k].TCHECKBOXVAL == "1") { $("#checkboxmust" + newid).attr("checked", true); } if (obj[k].QUERYCOLUMN == "1") { $("#checkboxquerylist" + newid).attr("checked", true); } $("#selecttype" + newid).trigger("liszt:updated"); $("#selecttype" + newid).chosen(); $("#checkboxquerylist" + newid).uniform(); $("#checkboxmust" + newid).uniform(); idarray.push(k + 1); } }); } /////----------------------common JS------------------------------------- //錯誤 var timeoutlength = 3000; function error(name) { $.noty({ "text": name + "</br>" + new Date().toTimeString(), "layout": "topRight", "type": "error", "timeout": timeoutlength }); return; asyncbox.tips(name, 'error', tiptime); } //成功 function success(name) { $.noty({ "text": name + "</br>" + new Date().toTimeString(), "layout": "topRight", "type": "success", "timeout": timeoutlength }); return; asyncbox.tips(name, 'success', tiptime); } //消息 function alerttip(name) { $.noty({ "text": name + "</br>" + new Date().toTimeString(), "layout": "topRight", "type": "success", "timeout": timeoutlength }); //aler return; asyncbox.tips(name, 'alert', tiptime); } //等待 function waittips() { asyncbox.tips("請稍后...!", 'wait', tiptime * 3); }
底層:
CSDAL.NewCSFile(Request.Form.Get("userproname"), Request.Form.Get("tablename") + "OP", Request.Form.Get("tablename"), Server.MapPath("CS/"), list); AjaxDAl.NewCSFileAspx(Request.Form.Get("userproname"), Request.Form.Get("tablename") + "OP", Request.Form.Get("tablename"), Server.MapPath("AJAXFILE/"), list); AjaxDAl.NewCSFileAjaxCS(Request.Form.Get("userproname"), Request.Form.Get("tablename") + "OP", Request.Form.Get("tablename"), Server.MapPath("AJAXFILE/"), list); html.NewHtmlFile(Request.Form.Get("userproname"), Request.Form.Get("tablename"), Request.Form.Get("tablename"), Server.MapPath("HTML/"), list); return SQLDAL.NewSQLFile(Request.Form.Get("tablename"), Server.MapPath("SQL/"), list) + "#" + result;

obj = null; //新增項目 if (type == "new") type = NewPro(); //刪除項目 else if (type == "delete") type = delete(); //獲取項目列表 else if (type == "getprodt") type = getprodt(); //獲取某項目的所有table else if (type == "getprotableDT") type = getprotableDT(); //點擊一個表獲取所有的字段 else if (type == "getonevallist") type = getonevallist(); //刪除表 else if (type == "deletetable") type = deletetable(); //獲取用戶的枚舉值 else if (type == "getenumdata") type = GetEnumData(); //獲取對應的枚舉項 else if (type == "getenumitembyid") type = GetEnumItemData(Request.Form.Get("myenumid"), Request.Form.Get("userid")); else if (type == "deleteitemss") type = deleteitemss(Request.Form.Get("myenumid")).ToString(); else if (type == "changed") type = changed(Request.Form.Get("name"), Request.Form.Get("itemsid"), Request.Form.Get("enumid"), Request.Form.Get("userid")).ToString();
代碼給出的不全、
功能:
生成:
sql代碼 到數據庫執行就好了
ajax處理頁面和底層代碼
cs數據訪問層
前段html以及js代碼
這是演示中生成的前段代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title>ICGS</title> <!-- The styles --> <link href="css/bootstrap-cerulean.css" rel="stylesheet" /> <link type="text/css" href="css/bootstrap-responsive.css" rel="stylesheet" /> <link type="text/css" href="css/charisma-app.css" rel="stylesheet" /> <link type="text/css" href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet" /> <link type="text/css" href='css/fullcalendar.css' rel='stylesheet' /> <link type="text/css" href='css/fullcalendar.print.css' rel='stylesheet' media='print' /> <link type="text/css" href='css/chosen.css' rel='stylesheet' /> <link type="text/css" href='css/uniform.default.css' rel='stylesheet' /> <link type="text/css" href='css/colorbox.css' rel='stylesheet' /> <link type="text/css" href='css/jquery.cleditor.css' rel='stylesheet' /> <link type="text/css" href='css/jquery.noty.css' rel='stylesheet' /> <link type="text/css" href='css/noty_theme_default.css' rel='stylesheet' /> <link type="text/css" href='css/elfinder.min.css' rel='stylesheet' /> <link type="text/css" href='css/elfinder.theme.css' rel='stylesheet' /> <link type="text/css" href='css/jquery.iphone.toggle.css' rel='stylesheet' /> <link type="text/css" href='css/opa-icons.css' rel='stylesheet' /> <link type="text/css" href='css/uploadify.css' rel='stylesheet' /> <link href="js/asyncbox/skins/ZCMS/asyncbox.css" type="text/css" rel="stylesheet" /> <link href="Script/validationEngine/css/validationEngine.jquery.css" rel="stylesheet" type="text/css" /> <!--jquery and javascript begin--> <script type="text/javascript" src="js/jquery-1.8.0.js"></script> <script language="javascript" type="text/javascript" src="Script/My97DatePicker/WdatePicker.js"></script> <script type="text/javascript" src='Script/validationEngine/languages/jquery.validationEngine-zh_CN.js'></script> <script type="text/javascript" src='Script/validationEngine/jquery.validationEngine.js'></script> <script type="text/javascript" src="js/asyncbox/AsyncBox.v1.4.5.js"></script> <script type="text/javascript"> var userid = "feifei", tiptime = 2000, pagesize = 10, TESTTABID = -1; //當前主ID var SLarray = []; //clear data obj var endtime = ""; //common data begin var myidarray = []; //for-----code myidarray.push("name"); myidarray.push("age"); myidarray.push("sex"); myidarray.push("persondoc"); myidarray.push("level"); $(function () { jQuery("#divadd").validationEngine(); //驗證 //新增 $("#btnadd").click(function () { userstabmngID = -1; for (var s = 0; s < myidarray.length; s++) { var fileobj = $("#" + myidarray[s]).html(); if (fileobj == null || fileobj == undefined || fileobj == "") { $("input[myid='" + myidarray[s] + "']").val(""); } else { $("#" + myidarray[s]).attr("path", ""); $("#" + myidarray[s]).html(""); $("#" + myidarray[s]).parent().children("a").hide(); } fileobj = null; } $("label[name='labsting']").hide(); $("input").show(); $("#btnsave").show(); $("#btnedit").hide(); $("#btncancel").show(); $("a[name='adelete']").hide(); $("#divadd").show(); }); //取消新增 $("#btncancel").click(function () { $("#divadd").hide(); $("#divlist").show(); }); //保存方法 $("#btnsave").click(function () { if (!jQuery("#divadd").validationEngine("validate")) { return false; } var temparray = []; for (var s = 0; s < myidarray.length; s++) { if (myidarray[s] == "sex") { temparray.push($("select[myid='" + myidarray[s] + "']").find("option:selected").attr("myval")); continue; } if (myidarray[s] == "level") { temparray.push($("select[myid='" + myidarray[s] + "']").find("option:selected").attr("myval")); continue; } var fileobj = $("#" + myidarray[s]).html(); if (fileobj == null || fileobj == undefined || fileobj == "") { temparray.push($("input[myid='" + myidarray[s] + "']").val()); } else { temparray.push($("#" + myidarray[s]).attr("path") + "#$@#@" + $("#" + myidarray[s]).html()); //path+name } fileobj = null; } $.post("userajax/userstabmngOP.aspx?" + new Date().toTimeString(), { "type": "add", "myidarray": temparray.toString(), "userid": userid, "userstabmngID": userstabmngID }, function (data) { endtime = ""; //時間默認值 userstabmngID = -1; if (data.length == 36) { success("保存成功!"); for (var s = 0; s < myidarray.length; s++) $("input[myid='" + myidarray[s] + "']").val(""); temparray = null; } $("#divadd").hide(); $("#divlist").show(); getlist(); //獲取前20條 }); }); //頁面第一次加載進行渲染 function load() { var obj = $("select[name='SLData']"); $(obj).each(function () { $(this).chosen(); }); } //加載頁面渲染 load(); getlist(); $("#btnmore").click(function () { getlist(); }); //編輯 $("#btnedit").click(function () { $(this).hide(); $("#btnsave").show(); $("label[name='labsting']").hide(); $("input").show(); ckisexts(); }); })//dom end //getone function getone(id) { userstabmngID = id; $("#divadd").show(); $("#divlist").hide(); if (edittype == "view") { $("label[name='labsting']").show(); $("#btnedit").show(); $("input").hide(); $("#btnsave").hide(); $("a[name='adelete']").hide(); $("#btncancel").show(); } else { $("label[name='labsting']").hide(); $("#btnedit").hide(); $("input").show(); $("#btnsave").show(); $("a[name='adelete']").show(); $("#btncancel").show(); } $("a[name='labsh']").show(); $.post("userajax/userstabmngOP.aspx?" + new Date().toTimeString(), { "type": "getone", "id": id }, function (data) { var obj = $.parseJSON(data); if (obj == null || obj == "") { ckisexts(); return; } for (var s = 0; s < myidarray.length; s++) { if (obj[0][myidarray[s]] == "") continue; //附件 if (obj[0][myidarray[s]].indexOf("#$@#@") > -1) { $("#" + myidarray[s]).html(obj[0][myidarray[s]].split("#$@#@")[1]); //name $("#" + myidarray[s]).attr("path", obj[0][myidarray[s]].split("#$@#@")[0]); //path } else { $("input[myid=" + myidarray[s] + "]").val((obj[0][myidarray[s]]).replace(" 0:00:00", "")); $("label[labid='" + myidarray[s] + "']").html((obj[0][myidarray[s]]).replace(" 0:00:00", "")); } try { $("#selecttype" + myidarray[s]).val((obj[0][myidarray[s]]).replace(" 0:00:00", "")); $("#selecttype" + myidarray[s]).trigger("liszt:updated"); $("#selecttype" + myidarray[s]).chosen(); } catch (ex) { } } ckisexts(); }); } //獲取10行數據 function getlist() { //$("#tbodydatalist").html(""); $.post("userajax/userstabmngOP.aspx?" + new Date().toTimeString(), { "type": "getlist", "pagesize": pagesize, "endtime": endtime }, function (data) { if (data == "nodata") { alerttip("無數據、您可以新增數據!"); $("#btnmore").hide(); } var obj = $.parseJSON(data); if (obj.length < pagesize) { $("#btnmore").hide(); } if (endtime == "") $("#tbodydatalist").html(""); for (var i = 0; i < obj.length; i++) { $("#tbodydatalist").append("<tr id='tr" + obj[i].ID + "'><td class='center'>" + obj[i].name.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].age.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].sex.replace(" 0:00:00", "") + "</td><td class='center'><a class='btn btn-success' onclick=domains('view','" + obj[i].ID + "')><i class='icon-zoom-in icon-white'></i>查看</a> <a class='btn btn-info' onclick=domains('edit','" + obj[i].ID + "')><i class='icon-edit icon-white'></i>修改</a> <a class='btn btn-danger' onclick=domains('delete','" + obj[i].ID + "')><i class='icon-trash icon-white'></i> 刪除</a></td></tr>"); if (i == (obj.length - 1)) { endtime = obj[i].CreatTime; } } }) } //domain //檢查附件是否有值 function ckisexts() { var obja = $("a[name='labsh']") $(obja).each(function () { if ($(this).html().length < 2) { $(this).parent().children("a").hide(); } }); } var edittype = "view"; function domains(type, id) { if (type == "delete") { if (confirm("確定刪除嗎?") == false) return; $.post("userajax/userstabmngOP.aspx?" + new Date().toTimeString(), { "type": "delete", "id": id, "userid": userid }, function (data) { if (data == "0") { error("您沒有權限刪除此條數據"); return; } else if (data == "1") { $("#tr" + id).remove(); success("刪除成功!"); } }); } else if (type == "view") { SLarray = []; edittype = "view"; getone(id); } else if (type == "edit") { SLarray = []; edittype = "edit"; getone(id); } } //判斷是否為第二次點擊 function SLexists(myenumid) { for (var i = 0; i < SLarray.length; i++) { if (SLarray[i] == myenumid) return true; } return false; } /////----------------------common JS------------------------------------- //錯誤 var timeoutlength = 3000; function error(name) { $.noty({ "text": name + "</br>" + new Date().toTimeString(), "layout": "topRight", "type": "error", "timeout": timeoutlength }); return; asyncbox.tips(name, 'error', tiptime); } //成功 function success(name) { $.noty({ "text": name + "</br>" + new Date().toTimeString(), "layout": "topRight", "type": "success", "timeout": timeoutlength }); return; asyncbox.tips(name, 'success', tiptime); } //消息 function alerttip(name) { $.noty({ "text": name + "</br>" + new Date().toTimeString(), "layout": "topRight", "type": "success", "timeout": timeoutlength }); //aler return; asyncbox.tips(name, 'alert', tiptime); } //等待 function waittips() { asyncbox.tips("請稍后...!", 'wait', tiptime * 3); } </script> </head> <body> <!-- content starts --> <div class="row-fluid sortable" id="divadd" style="display: none"> <div class="box span12"> <div class="box-header well" data-original-title> <h2> <i class="icon-edit"></i>新增數據</h2> <div class="box-icon"> <a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a> <a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a> </div> </div> <div class="box-content"> <form class="form-horizontal"> <fieldset> <div class="control-group success"> <label class="control-label" for="inputSuccess"> 姓名:</label> <div class="controls"> <input class="validate[required,maxSize[50],custom[noSpecialCaracters]]" myid="name" type="text" /> <label name="labsting" labid="name"> </label> </div> </div> <div class="control-group success"> <label class="control-label" for="inputSuccess"> 年齡:</label> <div class="controls"> <input class="validate[required,custom[integer]]" myid="age" type="text" /> <label name="labsting" labid="age"> </label> </div> </div> <div class="control-group"> <label class="control-label" for="selectError"> 性別:</label> <div class="controls"> <div class="divfeifeisl" style="width: 130px"> <select id="selecttypesex" myid="sex"> <option myval="請選擇">請選擇</option> <option myval="女">女</option> <option myval="男">男</option> </select> </div> </div> </div> <div class="control-group success"> <label class="control-label" for="inputSuccess"> 個人簡歷:</label> <div class="controls"> <a style="cursor: pointer" name="labsh" id="persondoc" path="" isfile="1"></a><a name="adelete" adeleteid="persondoc"> 刪除</a> <span name="fileup" myid="persondoc" class="icon32 icon-color icon-link" title=".icon32 .icon-color .icon-link "></span> </div> </div> <div class="control-group"> <label class="control-label" for="selectError"> 學歷:</label> <div class="controls"> <div class="divfeifeisl" style="width: 130px"> <select id="selecttypelevel" myid="level"> <option myval="請選擇">請選擇</option> <option myval="小學">小學</option> <option myval="初中">初中</option> <option myval="高中">高中</option> <option myval="大學">大學</option> <option myval="研究生">研究生</option> <option myval="博士">博士</option> </select> </div> </div> </div> <div class="form-actions"> <button type="button" class="btn btn-primary" id="btnsave"> 保存</button> <button id="btnedit" class="btn btn-primary" type="button"> 修改</button> <input type="button" class="btn" value="取消" id="btncancel" /> </div> </fieldset> </form> </div> </div> </div> <div class="row-fluid sortable" id="divlist"> <div class="box span12"> <div class="box-header well" data-original-title> <h2> <i class="icon-edit"></i>數據列表</h2> <div class="box-icon"> <a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a> <a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a> </div> </div> <div class="box-content"> <div align="center"> <span class="icon32 icon-color icon-add" id="btnadd"></span> <table class="table table-striped table-bordered bootstrap-datatable datatable"> <thead> <tr> <th> 姓名 </th> <th> 年齡 </th> <th> 性別 </th> <th width="18%"> 操作 </th> </tr> </thead> <tbody id="tbodydatalist"> </tbody> </table> <span class="icon32 icon-color icon-arrowthick-s" id="btnmore"></span> </div> </div> </div> </div> <!-- jQuery UI --> <script src="js/jquery-ui-1.8.21.custom.min.js"></script> <!-- transition / effect library --> <script src="js/bootstrap-transition.js"></script> <!-- alert enhancer library --> <script src="js/bootstrap-alert.js"></script> <!-- modal / dialog library --> <script src="js/bootstrap-modal.js"></script> <!-- custom dropdown library --> <script src="js/bootstrap-dropdown.js"></script> <!-- scrolspy library --> <script src="js/bootstrap-scrollspy.js"></script> <!-- library for creating tabs --> <script src="js/bootstrap-tab.js"></script> <!-- library for advanced tooltip --> <script src="js/bootstrap-tooltip.js"></script> <!-- popover effect library --> <script src="js/bootstrap-popover.js"></script> <!-- button enhancer library --> <script src="js/bootstrap-button.js"></script> <!-- accordion library (optional, not used in demo) --> <script src="js/bootstrap-collapse.js"></script> <!-- carousel slideshow library (optional, not used in demo) --> <script src="js/bootstrap-carousel.js"></script> <!-- autocomplete library --> <script src="js/bootstrap-typeahead.js"></script> <!-- tour library --> <script src="js/bootstrap-tour.js"></script> <!-- library for cookie management --> <script src="js/jquery.cookie.js"></script> <!-- calander plugin --> <script src="js/fullcalendar.min.js"></script> <!-- data table plugin --> <script src="js/jquery.dataTables.min.js"></script> <!-- select or dropdown enhancer --> <script src="js/jquery.chosen.min.js"></script> <!-- checkbox, radio, and file input styler --> <script src="js/jquery.uniform.min.js"></script> <!-- plugin for gallery image view --> <script src="js/jquery.colorbox.min.js"></script> <!-- rich text editor library --> <script src="js/jquery.cleditor.min.js"></script> <!-- notification plugin --> <script src="js/jquery.noty.js"></script> <!-- file manager library --> <script src="js/jquery.elfinder.min.js"></script> <!-- star rating plugin --> <script src="js/jquery.raty.min.js"></script> <!-- for iOS style toggle switch --> <script src="js/jquery.iphone.toggle.js"></script> <!-- autogrowing textarea plugin --> <script src="js/jquery.autogrow-textarea.js"></script> <!-- multiple file upload plugin --> <script src="js/jquery.uploadify-3.1.min.js"></script> <!-- history.js for cross-browser state change on ajax --> <script src="js/jquery.history.js"></script> <!-- application script for Charisma demo --> <script src="js/charisma.js"></script> <script src="Script/ajax_upload.js"></script> <script type="text/javascript" src="Script/fileup.js"></script> </body> </html>
底層:

using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using DBS; using ProMng; namespace ICGSystemWeb.userajax { //ajax底層處理代碼 public partial class userstabmngOPajax : System.Web.UI.Page { //實例化 DBHelper DB = new DBHelper(); userstabmngOP DAL = new userstabmngOP(); protected void Page_Load(object sender, EventArgs e) { object obj = Request.Form.Get("type"); if (obj == null || obj.ToString() == "") { obj = null; Response.Write("nodata"); Response.End(); }//非法請求end string type = obj.ToString(); obj = null; //獲取對應的枚舉項 if (type == "getenumitembyid") type = GetEnumItemData(Request.Form.Get("myenumid"), Request.Form.Get("userid")); //新增 else if (type == "add") type = AddOrUpdateDB(); //獲取用戶定義數量的數據列表 else if (type == "getlist") type = GetTopNumberData(); //獲取一天修改數據 else if (type == "getone") type = getone(Request.Form.Get("id").Trim()); //刪除 else if (type == "delete") type = delete(Request.Form.Get("id"), Request.Form.Get("userid")); Response.Write(type); Response.End(); } //刪除 private string delete(string id, string userid) { return DAL.DeleteDB(id); } //獲取一個 private string getone(string id) { id = CommonData.DataTableToJson(DAL.GetOneDataByGuid(id)); id = id == "" ? "nodata" : id; return id; } //獲取用戶定義數量的數據列表 private string GetTopNumberData() { string endtime = Request.Form.Get("endtime"); if (endtime == "") endtime = DateTime.Now.AddDays(1).ToString(); endtime = CommonData.DataTableToJson(DAL.GetTopNumberData(int.Parse(Request.Form.Get("pagesize")), endtime)); if (endtime == "") endtime = "nodata"; return endtime; } //獲取枚舉項BY ID private string GetEnumItemData(string enumid, string userid) { if (enumid == null || enumid == "" || userid == null || userid == "") return CommonData.nodata; string sql = string.Format("select NAME,VAL from ICGEnumItemTab where enumid='{0}' and userid='{1}' ", enumid, userid); sql = CommonData.DataTableToJson(DB.GetDataTable(sql, null)); if (sql == "") sql = CommonData.nodata; return sql; } private string AddOrUpdateDB() { string[] a = Request.Form.Get("myidarray").Split(','); string guid = Request.Form.Get("userstabmngID"); if (guid == "-1") { guid = Guid.NewGuid().ToString(); DAL.AddDB(guid, a[0], a[1], a[2], a[3], a[4], guid); a = null; return guid; } else { DAL.UpdateDB(guid, a[0], a[1], a[2], a[3], a[4], guid); a = null; return guid; } } } }

using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using DBS; namespace konnichiha { public class UserMngTabOP { //實例化 DBHelper DB = new DBHelper(); //新增 public string AddDB(string ID, string username, string userage, string Gender, string persondoc, string birthday, string guid) { string sql = string.Format("insert into UserMngTab (ID,username,userage,Gender,persondoc,birthday) values(@ID,@username,@userage,@Gender,@persondoc,@birthday)"); SqlParameter[] sqlpara = new SqlParameter[] { new SqlParameter("@ID",ID), new SqlParameter("@username",username), new SqlParameter("@userage",userage), new SqlParameter("@Gender",Gender), new SqlParameter("@persondoc",persondoc), new SqlParameter("@birthday",birthday) }; DB.ExecuteNonQuery(sql, sqlpara); return guid; } //修改 public string UpdateDB(string ID, string username, string userage, string Gender, string persondoc, string birthday, string guid) { string sql = string.Format("update UserMngTab set ID=@ID,username=@username,userage=@userage,Gender=@Gender,persondoc=@persondoc,birthday=@birthday where ID=@guid"); SqlParameter[] para = new SqlParameter[] { new SqlParameter("@ID",ID), new SqlParameter("@username",username), new SqlParameter("@userage",userage), new SqlParameter("@Gender",Gender), new SqlParameter("@persondoc",persondoc), new SqlParameter("@birthday",birthday), new SqlParameter("@guid", guid) }; return DB.ExecuteNonQuery(sql, para).ToString(); } //刪除 public string DeleteDB(string guid) { string sql = string.Format("delete from UserMngTab where ID=@ID"); SqlParameter[] para = new SqlParameter[] { new SqlParameter("@ID", guid) }; return DB.ExecuteNonQuery(sql, para).ToString(); } //獲取一條ID值為guid的數據 public DataTable GetOneDataByGuid(string guid) { string sql = string.Format("select ID, username, userage, Gender, persondoc, birthday, CreatTime from UserMngTab where ID=@guid"); SqlParameter[] para = new SqlParameter[] { new SqlParameter("@guid", guid) }; return DB.GetDataTable(sql, para); } //獲取用戶定義數量的數據列表 public DataTable GetTopNumberData(int pagesize, string endtime) { string sql = string.Format("select top {0} username,Gender,birthday, ID,CreatTime from UserMngTab where CreatTime<'{1}' order by CreatTime DESC", pagesize, endtime); return DB.GetDataTable(sql, null); } } }
數據庫:
create table [userstabmng] ( [ID] nvarchar(36) not null , [name] nvarchar(50) not null , [age] int not null , [sex] nvarchar(500) null , [persondoc] nvarchar(1000) null , [level] nvarchar(500) null , [CreatTime] datetime default(getdate()) null )
最后
個人平台:www.10086bank.com
目前會:Android、.net
喜歡就給個評論吧 謝謝