ICG_System之全自动代码生成器V2.0版本

大家好!

 早在2014年本人就已经利用业余时间开发自己的ICG之代码生成器系统、依靠bootstrap的崛起本人也在不断完善此应用、目的是为了减少开发人员的工作量、

减少不必要的复制粘贴操作,该系统已经到了V2.0版本;目前功能如下:

server端:创建项目、创建表、设计器功能、生产【js、html、ajax、dal、sql】等文件、枚举管理、依靠用户输入的字段名称自动转换为英文字段等功能;

client端:数据查询、文件上传、int float 字符型等类型的数据校验、必填数据项的校验、数据分页、数据新增、数据修改等功能;

该系统运行环境:window+IIS+framwork+MYSQL/MSSQL

接下来介绍一下本人开发的系统的架构图:

看图说话了、、系统的大致结构是这样的:

server段生成代码流程是:

分享一下主要设计器的界面:

 

生成的主要的JS代码:

var userid = "df9d3eb8-48d7-45bc-bfcf-06f471a7344d", tiptime = 2000, pagesize = 10, TESTTABID = -1;  //当前主ID
var SLarray = []; //clear data obj
var endtime = "";

//common data begin
var myidarray = [];
//for-----code
myidarray.push("Number");
myidarray.push("name");
myidarray.push("sex");
myidarray.push("mobiletel");
myidarray.push("QQNumber");
myidarray.push("studyclass");
$(function () {
    jQuery("#divadd").validationEngine(); //验证
    $("select").trigger("liszt:updated");
    $("select").chosen();
    //新增
    $("#btnadd").click(function () {
        StudentID = -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();
        $("select").val("请选择");
        $("select").trigger("liszt:updated");
        $("select").chosen();
        $("#divadd").show();
        $("#divlist").hide();
    });
    //自动搜索(文本框)
    $("input[name='icginputsearch']").change(function () {
        var obj = $("input[name='icginputsearch']");
        var para = [];
        endtime = "";
        if (obj != null) {
            $(obj).each(function () {
                if ($(this).val() != "")
                    para.push({ "key": $(this).attr("myid"), "val": $(this).val() });
            });
        }
        obj = $("select[name='selectcontorl']");
        if (obj != null) {
            $(obj).each(function () {
                para.push({ "key": $(this).attr("myid"), "val": $(this).find("option:selected").text() });
            });
        }
        getjsonserach(para, endtime);
    });
    //自动搜索(下拉框)
    $("select[name='selectcontorl']").change(function () {
        var obj = $("input[name='icginputsearch']");
        var para = [];
        endtime = "";
        if (obj != null) {
            $(obj).each(function () {
                if ($(this).val() != "")
                    para.push({ "key": $(this).attr("myid"), "val": $(this).val() });
            });
        }
        obj = $("select[name='selectcontorl']");
        if (obj != null) {
            $(obj).each(function () {
                para.push({ "key": $(this).attr("myid"), "val": $(this).find("option:selected").text() });
            });
        }
        getjsonserach(para, endtime);
    });
    function getjsonserach(para, endtime) {
        $.post("userajax/StudentOP.aspx?" + new Date().getTime() + "" + Math.random(), { "type": "searchbyjson", "data": JSON.stringify(para), "pagesize": pagesize, "endtime": endtime }, function (data) {
            if (data == "nodata") {
                alerttip("无此条件数据!");
                $(".odd").remove();
                $("#btnmore").hide();
                $("#tbodydatalist").html("");
                return false;
            }
            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].Number.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].name.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].sex.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].mobiletel.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].QQNumber.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].studyclass.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>View</a>&nbsp;<a class='btn btn-info' onclick=domains('edit','" + obj[i].ID + "')><i class='icon-edit icon-white'></i>Edit</a>&nbsp;<a class='btn btn-danger' onclick=domains('delete','" + obj[i].ID + "')><i class='icon-trash icon-white'></i> Delete</a></td></tr>");

                if (i == (obj.length - 1)) {
                    endtime = obj[i].CreatTime;
                }
            }
        });
    }
    //取消新增
    $("#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;
            }
            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/StudentOP.aspx?" + new Date().getTime() + "" + Math.random(), { "type": "add", "myidarray": temparray.toString(), "userid": userid, "StudentID": StudentID }, function (data) {
            endtime = ""; //时间默认值
            StudentID = -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();
        $(".divfeifeisl").show();
        $("a[name='adelete']").show();
        ckisexts();
    });


})//dom end
//getone
function getone(id) {
    StudentID = id; $("#divadd").show();


    $("#divlist").hide();



    if (edittype == "view") {
        $("label[name='labsting']").show();
        $("#btnedit").show();
        $("input").hide();
        $("#btnsave").hide();
        $("a[name='adelete']").hide();
        $(".divfeifeisl").hide();
        $("#btncancel").show();
    }
    else {
        $("label[name='labsting']").hide();
        $("#btnedit").hide();
        $("input").show();
        $("#btnsave").show();
        $("a[name='adelete']").show();
        $(".divfeifeisl").show();
        $("#btncancel").show();
    }


    $("a[name='labsh']").show();

    $.post("userajax/StudentOP.aspx?" + new Date().getTime() + "" + Math.random(), { "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/StudentOP.aspx?" + new Date().getTime() + "" + Math.random(), { "type": "getlist", "pagesize": pagesize, "endtime": endtime }, function (data) {
        if (data == "nodata") {
            alerttip("无数据、您可以新增数据!");
            $(".odd").remove();
            $("#btnmore").hide();
            return false;
        }

        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].Number.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].name.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].sex.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].mobiletel.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].QQNumber.replace(" 0:00:00", "") + "</td><td class='center'>" + obj[i].studyclass.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>View</a>&nbsp;<a class='btn btn-info' onclick=domains('edit','" + obj[i].ID + "')><i class='icon-edit icon-white'></i>Edit</a>&nbsp;<a class='btn btn-danger' onclick=domains('delete','" + obj[i].ID + "')><i class='icon-trash icon-white'></i> Delete</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/StudentOP.aspx?" + new Date().getTime() + "" + Math.random(), { "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;
}

var imgarr = ["jpg", "png", "bmp", "jpeg", "gif"];
function ebin(info) {
    //普通文本
    if (info.indexOf("#$@#@") == -1)
        return info;

    var isimg = false;
    info = info.toLowerCase();

    var tmp = info.split("#$@#@")[1].split(".")[1];//last chars

    for (var i = 0; i < imgarr.length; i++) {
        if (imgarr[i] == tmp) {
            return "<img name='imgusr' src='ajax/" + info.split("#$@#@")[0] + "' alt='" + info.split("#$@#@")[1] + "'  style='height:24px;width:24px' />"
        }
    }

    //doc docx xls xlsx pdf ...
    return "<img name='imgsys' src='img/ico/" + tmp + ".png' alt='cc.name'  style='height:24px;width:24px'/>";
}

/////----------------------common JS-------------------------------------
//错误
var timeoutlength = 3000;
var palce = "bottomRight";
function error(name) {
    $.noty({ "text": name, "layout": palce, "type": "error", "timeout": timeoutlength });
    return;
    //asyncbox.tips(name, 'error', tiptime);
}
//成功
function success(name) {
    $.noty({ "text": name, "layout": palce, "type": "success", "timeout": timeoutlength });
    return;
    //asyncbox.tips(name, 'success', tiptime);
}
//消息
function alerttip(name) {
    $.noty({ "text": name, "layout": palce, "type": "success", "timeout": timeoutlength });  //aler
    return;
    //asyncbox.tips(name, 'alert', tiptime);
}
//等待
function waittips() {
    //asyncbox.tips("please wait...!", 'wait', tiptime * 3);
}
View Code

生成的主要的MYSQL代码:

 

DROP TABLE IF EXISTS `Student`;
create table  `Student`
(
`ID`   varchar(36)  primary key  not null  , 
`Number`  varchar(20) not null  , 
`name`  varchar(30) not null  , 
`sex`  varchar(500) null  , 
`mobiletel`  varchar(50) null  , 
`QQNumber`  varchar(15) null  , 
`studyclass`  varchar(50) null  , 
`CreatTime`  datetime    
);
ALTER TABLE `Student` CHANGE COLUMN `CreatTime` `CreatTime` TIMESTAMP NULL DEFAULT now()  ;

 

图片上传的有点多! 最终生成的demo如下:

http://182.92.155.97:8096/stu.html

http://182.92.155.97:8096/tch.html

有什么好的建议请联系我、谢谢!

以上。

 

posted @ 2017-06-27 14:34 araki 阅读(...) 评论(...) 编辑 收藏