Exemple #1
0
 /// <summary>
 /// by 王延领
 /// date:2017-11-20
 /// </summary>
 /// <param name="_dt"></param>
 /// <param name="_strNamespace">命名空间</param>
 /// <param name="_dataContext">数据库操作上线文</param>
 public CreateDomain(DataTable _dt, string _strNamespace, string _dataContext)
 {
     strNamespace = _strNamespace;
     dataContext  = _dataContext;
     dt           = _dt;
     dtName       = dt.TableName;
     modeName     = dtName + "Model";
     #region 生成的查询条件
     foreach (DataRow dr in dt.Rows)
     {
         string dataType = dr["DataType"].ToString();
         if (dr["IsQuery"].ToString().ToLower() == "true" && dataType != "datetime")
         {
             string columuName  = dr["name"].ToString();
             string _columuName = columuName.Substring(0, 1).ToLower() + columuName.Substring(1);
             checkString.AppendFormat("{0} {1},", CreateHelper.GetCsType(dataType), _columuName);
             query.AppendFormat("            if ({0}.HasValue)", _columuName);
             query.AppendLine();
             query.AppendFormat("                sql += string.Format(\" and {0} = '{1}'\", {2}.Value);", columuName, "{0}", _columuName);
             query.AppendLine();
         }
         else if (dr["IsQuery"].ToString().ToLower() == "true" && dataType == "datetime")
         {
             string columuName = dr["name"].ToString();
             checkString.Append(" DateTime? sd, DateTime? ed,");
             query.AppendLine("            if (!Convert.ToDateTime(sd).IsEmpty())");
             query.AppendFormat("                sql += string.Format(\" And {0}>'{1}'\", Convert.ToDateTime(sd).ToString(\"yyyy-MM-dd 0:00\"));", columuName, "{0}");
             query.AppendLine();
             query.AppendLine("            if (!Convert.ToDateTime(ed).IsEmpty())");
             query.AppendFormat("                sql += string.Format(\" And {0}<'{1}'\", Convert.ToDateTime(ed).ToString(\"yyyy-MM-dd 23:59:59\"));", columuName, "{0}");
             query.AppendLine();
         }
         #endregion
     }
 }
Exemple #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            TreeNode node = new TreeNode();

            try
            {
                SqlConnection conn = new SqlConnection(sql_connectstring.Replace("Provider=sqloledb;", ""));
                conn.Open();
                List <string> ulist = CreateHelper.GetTable(conn, "U").ToList();
                List <string> vlist = CreateHelper.GetTable(conn, "V").ToList();
                node.Text = "表";
                treeView1.Nodes.Add(node);
                ulist.ForEach(l =>
                {
                    TreeNode unode = new TreeNode();
                    unode.Text     = l;

                    node.Nodes.Add(unode);
                });
                TreeNode node1 = new TreeNode();
                node1.Text = "试图";
                treeView1.Nodes.Add(node1);
                vlist.ForEach(l =>
                {
                    TreeNode vnode = new TreeNode();
                    vnode.Text     = l;
                    node1.Nodes.Add(vnode);
                });
                treeView1.CheckBoxes = true;
            }
            catch (Exception ex)
            { }
        }
        /// <summary>
        ///
        /// by 王延领
        /// date:2017-11-20
        /// </summary>
        /// <param name="_dt"></param>
        /// <param name="_strNamespace">命名空间</param>
        /// <param name="_projectName">项目模块名称</param>
        /// <param name="_functionNme">功能名称</param>
        public CreateControllers(DataTable _dt, string _strNamespace, string _projectName, string _functionNme)
        {
            strNamespace = _strNamespace;
            projectName  = _projectName;
            functionNme  = _functionNme;
            dt           = _dt;
            //表名
            dtName = dt.TableName;
            //表名(首字母小写)
            _dtName   = dtName.Substring(0, 1).ToLower() + dtName.Substring(1);
            modelName = dtName + "Model";

            #region 遍历datatable  可读性有点低哈,为了实现设计代码的时候就没做太多设计
            foreach (DataRow dr in dt.Rows)
            {
                string defaultVal = dr["DefaultVal"].ToString();
                string dataType   = dr["DataType"].ToString();
                #region 查询条件
                if (dr["IsQuery"].ToString().ToLower() == "true" && dataType != "datetime")
                {
                    string columuName  = dr["name"].ToString();
                    string _columuName = columuName.Substring(0, 1).ToLower() + columuName.Substring(1);
                    query.AppendFormat("{0},", _columuName);
                    checkString.AppendFormat("{0} {1},", CreateHelper.GetCsType(dataType), _columuName);
                }
                else if (dr["IsQuery"].ToString().ToLower() == "true" && dataType == "datetime")
                {
                    query.Append("sd,ed,");
                    checkString.Append(" DateTime? sd, DateTime? ed,");
                }
                #endregion
                #region 初始化
                if (!string.IsNullOrEmpty(defaultVal))
                {
                    string name = dr["name"].ToString();
                    if (defaultVal == "当前时间")
                    {
                        defaultValue.AppendFormat("            model.{0} = DateTime.Now;", name);
                    }
                    else if (defaultVal == "登入人")
                    {
                        defaultValue.AppendFormat("            model.{0} = Platform.Core.PlatformContext.CurrentUser.UserName;", name);
                    }
                    defaultValue.AppendLine();
                }
                #endregion
            }
            #endregion
        }
Exemple #4
0
 private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (e.Node.Parent != null && e.Node.Parent.Text == "表")
     {
         tabName = e.Node.Text;
         DataTable dt = CreateHelper.GetSyscolumns(sql_connectstring.Replace("Provider=sqloledb;", ""), e.Node.Text);
         this.dataGridView1.DataSource          = dt;    //数据源
         this.dataGridView1.AutoGenerateColumns = false; //不自动
     }
     else if (e.Node.Parent != null && e.Node.Parent.Text == "试图")
     {
         tabName = e.Node.Text;
         DataTable dt = CreateHelper.GetVSyscolumns(sql_connectstring.Replace("Provider=sqloledb;", ""), e.Node.Text);
         this.dataGridView1.DataSource          = dt;    //数据源
         this.dataGridView1.AutoGenerateColumns = false; //不自动
     }
 }
Exemple #5
0
        private void 单表生成ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)this.dataGridView1.DataSource;

            if (dt != null && dt.Rows.Count > 0)
            {
                dt.TableName = tabName;
                jsonHelper.WriteFile(CreateHelper.getPath(tabName), tabName + ".js", jsonHelper.ToJson(dt, true));
            }
            if (CreateFunc(dt))
            {
                MessageBox.Show("生成成功!!!!");
            }
            else
            {
                MessageBox.Show("生成失败!!!!");
            }
        }
 public bool Setmapping()
 {
     #region  射 ,依赖注入,权限自行复制粘贴不是使用类
     StringBuilder sb = new StringBuilder();
     sb.AppendLine("        protected override void RegisterBuilder(ContainerBuilderWrapper builder)");
     sb.AppendLine("        {");
     sb.AppendLine("            base.RegisterBuilder(builder);");
     sb.AppendFormat("            builder.RegisterType<{0}Service>().As<I{0}Service>();", dtName);
     sb.AppendLine();
     sb.AppendLine("        }");
     sb.AppendLine("        public override void Initialize()");
     sb.AppendLine("        {");
     sb.AppendLine("            base.Initialize();");
     sb.AppendFormat("            AutoMapper.Mapper.CreateMap<{0}Model, {0}>();", dtName);
     sb.AppendLine();
     sb.AppendFormat("            AutoMapper.Mapper.CreateMap<{0}, {0}Model>();", dtName);
     sb.AppendLine();
     sb.AppendLine("        }");
     sb.AppendFormat(" [RoleName( \"{0}:管理\",\"{0}:添加\", \"{0}:编辑\",\"{0}:查询\", \"{0}:删除\")]", functionNme);
     #endregion
     File.WriteAllText(CreateHelper.getPath(dtName) + "//" + dtName + "Context.cs", sb.ToString());
     return(false);
 }
Exemple #7
0
        private void 批量生成ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <TreeNode> listNodes = new List <TreeNode>();

            foreach (TreeNode node in treeView1.Nodes)
            {
                if (node.Text == "表")
                {
                    foreach (TreeNode childnode in node.Nodes)
                    {
                        if (childnode.Checked)
                        {
                            tabName = childnode.Text;
                            DataTable dt = CreateHelper.GetSyscolumns(sql_connectstring.Replace("Provider=sqloledb;", ""), childnode.Text);
                            dt.TableName = tabName;
                            CreateFunc(dt);
                        }
                    }
                }
                else
                {
                    foreach (TreeNode childnode in node.Nodes)
                    {
                        if (childnode.Checked)
                        {
                            tabName = childnode.Text;
                            DataTable dt = CreateHelper.GetVSyscolumns(sql_connectstring.Replace("Provider=sqloledb;", ""), childnode.Text);
                            dt.TableName = tabName;
                            CreateFunc(dt);
                        }
                    }
                }

                //  FindCheckNode(node, listNodes);
            }
            MessageBox.Show("生成成功!!!!");
        }
        public bool setController()
        {
            StringBuilder sb = new StringBuilder();

            #region controller生成模版(没有提供的T4模版,暂时这样处理吧)
            if (dt != null && dt.Rows.Count > 0)
            {
                sb.AppendLine("using System;");
                sb.AppendLine("using Kendo.Mvc.UI;");
                sb.AppendLine("using System.Web.Mvc;");
                sb.AppendLine("using System.Collections.Generic;");
                sb.AppendLine("using RTSafe.Platform.Module.Mvc;");
                sb.AppendLine("using RTSafe.Platform.Module.Attributes;");
                sb.AppendLine();
                sb.AppendFormat("using {0}.Models;", strNamespace);
                sb.AppendLine();
                sb.AppendFormat("using {0}.Domain;", strNamespace);
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendFormat("namespace {0}.Controllers", strNamespace);
                sb.AppendLine();
                sb.AppendLine("{");
                sb.AppendLine();
                sb.AppendFormat("    [ControllerDescription(\"{0}\", \"{1}\")]", projectName, functionNme);
                sb.AppendLine();
                sb.AppendLine("    [Authorize]");
                sb.AppendLine();
                sb.AppendFormat("    public class {0}Controller : ModuleController", dtName);
                sb.AppendLine();
                sb.AppendLine("    {");
                sb.AppendFormat("        I{0}Service {1};", dtName, _dtName);
                sb.AppendLine();
                sb.AppendFormat("        public {0}Controller(I{0}Service _{1}Service)", dtName, _dtName);
                sb.AppendLine();
                sb.AppendLine("        {");
                sb.AppendFormat("            this.{0} = _{0}Service;", _dtName);
                sb.AppendLine();
                sb.AppendLine("        }");
                sb.AppendFormat("        [ActionDescription(\"{0}管理\",\" /{1}/{1}List)\"]", functionNme, dtName);
                sb.AppendLine();
                sb.AppendFormat("        [RoleName(\"管理员\",\"{0}:查询\")]", functionNme);
                sb.AppendLine();
                sb.AppendFormat("        public ActionResult {0}List()", dtName);
                sb.AppendLine();
                sb.AppendLine("        {");
                sb.AppendLine("            return View();");
                sb.AppendLine("        }");
                sb.AppendLine();
                sb.AppendFormat("        public ActionResult {0}Add(Guid? id)", dtName);
                sb.AppendLine();
                sb.AppendLine("        {");
                sb.AppendFormat("            {0} model = new {0}();", modelName);
                sb.AppendLine();
                sb.AppendLine(defaultValue.ToString());
                sb.AppendLine("            if (id.HasValue)");
                sb.AppendFormat("                model = {0}.Get(id.Value);", _dtName);
                sb.AppendLine();
                sb.AppendLine("            return PartialView(model);");
                sb.AppendLine("        }");
                sb.AppendLine("        [HttpPost]");
                sb.AppendLine();
                sb.AppendFormat("        [RoleName(\"管理员\", \"{0}:添加\")]", functionNme);
                sb.AppendLine();
                sb.AppendFormat("        public ActionResult {0}Add({0}Model model)", dtName);
                sb.AppendLine();
                sb.AppendLine("        {");
                sb.AppendLine("            int re = 0;");
                sb.AppendLine("            if (ModelState.IsValid)");
                sb.AppendLine("            {");
                sb.AppendLine("                if (model != null)");
                sb.AppendLine("                {");
                string pkid = dt.Rows[0]["name"].ToString();
                sb.AppendLine();
                sb.AppendFormat("                    if (model.{0} != Guid.Empty)", pkid);
                sb.AppendLine();
                sb.AppendFormat("                        re = {0}.Edit(model);", _dtName);
                sb.AppendLine();
                sb.AppendLine("                    else");
                sb.AppendLine("                    {");
                sb.AppendFormat("                        model.{0} = Guid.NewGuid();", pkid);
                sb.AppendLine();
                sb.AppendFormat("                        re = {0}.Add(model);", _dtName);
                sb.AppendLine();
                sb.AppendLine("                    }");
                sb.AppendLine("                    if (re > 0)");
                sb.AppendLine("                        return AjaxResult(success: re > 0, data: model, ajaxDataTypes: AjaxDataTypes.Json);");
                sb.AppendLine("                }");
                sb.AppendLine("                return AjaxResult(success: false, data: null, ajaxDataTypes: RTSafe.Platform.Module.Mvc.AjaxDataTypes.Json);");
                sb.AppendLine("            }");
                sb.AppendLine("            else");
                sb.AppendLine("            {");
                sb.AppendLine("                ModelState.AddModelError(\"erro\", \"验证不通过,请检查输入\");");
                sb.AppendLine("            }");
                sb.AppendLine("            return PartialView(model);");
                sb.AppendLine("        }");
                sb.AppendLine();
                // sb.AppendFormat("        [ActionDescription(\"{0}\", \"/{1}/{1}Query\")]");
                //sb.AppendLine();
                sb.AppendFormat("        [RoleName(\"管理员\", \"{0}:查询\")]", functionNme);
                sb.AppendLine();
                sb.AppendFormat("        public ActionResult {0}Query(Guid? id)", dtName);
                sb.AppendLine();
                sb.AppendLine("        {");
                sb.AppendFormat("            {0} model = new {0}();", modelName);
                sb.AppendLine();
                sb.AppendLine("            if (id.HasValue)");
                sb.AppendLine();
                sb.AppendFormat("                model = {0}.Get(id.Value);", _dtName);
                sb.AppendLine();
                sb.AppendLine("            return View(model);");
                sb.AppendLine("        }");
                sb.AppendLine("        [HttpPost]");
                sb.AppendFormat("        [RoleName(\"管理员\", \"{0}:删除\")]", functionNme);
                sb.AppendLine();
                sb.AppendFormat("        public ActionResult {0}Delete(Guid id)", dtName);
                sb.AppendLine();
                sb.AppendLine("        {");
                sb.AppendLine("            if (id == Guid.Empty)");
                sb.AppendLine("                return Json(new { success = false });");
                sb.AppendFormat("            int re = {0}.Delete(id);", _dtName);
                sb.AppendLine();
                sb.AppendLine("            return Json(new { success = re > 0 });");
                sb.AppendLine("        }");
                sb.AppendFormat("        public ActionResult ListPage([DataSourceRequest]  DataSourceRequest dsRequest,{0})", checkString.ToString().TrimEnd(','));
                sb.AppendLine();
                sb.AppendLine("        {");
                sb.AppendLine("            var size = dsRequest.PageSize;");
                sb.AppendLine("            var index = dsRequest.Page;");
                sb.AppendLine("            var total = 0;");
                sb.AppendFormat("            var modelWrapper = {1}.GetAllPage(index, size, {0} out total);", query.ToString(), _dtName);
                sb.AppendLine();
                sb.AppendLine("            var rs = new DataSourceResult();");
                sb.AppendLine("            rs.Data = modelWrapper;");
                sb.AppendLine("            rs.Total = total;");
                sb.AppendLine("            return Json(rs);");
                sb.AppendLine("        }");
                sb.AppendLine("    }");
                sb.AppendLine("}");
            }
            #endregion
            File.WriteAllText(CreateHelper.getPath(dtName) + "//Controllers" + "//" + dtName + "Controller.cs", sb.ToString());

            return(false);
        }
Exemple #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            string ls_databasetype = "";
            string ls_myoledbconn = "";
            string ls_datasource = "", ls_username = "", ls_password = "", ls_servername = "";

            ls_databasetype = cmb_dbtype.Text.Trim();
            ls_username     = tb_username.Text.Trim();
            ls_password     = tb_pass.Text.Trim();
            ls_servername   = tb_server.Text.Trim();
            ls_datasource   = tb_database.Text.Trim();

            if (ls_databasetype.Length <= 0)
            {
                MessageBox.Show("请选择数据库类型!", "提示");
                cmb_dbtype.Focus();
                return;
            }
            if (ls_username.Length <= 0)
            {
                MessageBox.Show("请输入用户名!", "提示");
                tb_pass.Focus();
                return;
            }
            //CreateHelper.db_DisConnect();
            switch (ls_databasetype)
            {
            case "SQL SERVER":
                if (ls_servername.Length <= 0)
                {
                    MessageBox.Show("请输入服务器名!", "提示");
                    tb_server.Focus();
                    return;
                }
                if (ls_datasource.Length <= 0)
                {
                    MessageBox.Show("请输入数据库名!", "提示");
                    tb_server.Focus();
                    return;
                }
                ls_myoledbconn = "Provider=sqloledb;Data Source=" + ls_servername + ";Initial Catalog=" + ls_datasource + ";User Id=" + ls_username + ";Password="******"";
                break;

            case "ORACLE":
                if (ls_datasource.Length <= 0)
                {
                    MessageBox.Show("请输入服务名称!", "提示");
                    tb_server.Focus();
                    return;
                }
                ls_myoledbconn = "Provider=msdaora;Data Source=" + ls_datasource + ";User Id=" + ls_username + ";Password="******"";
                break;

            case "DB2":
                if (ls_servername.Length <= 0)
                {
                    MessageBox.Show("请输入服务器IP地址!", "提示");
                    tb_server.Focus();
                    return;
                }
                //检测是否是正确的IP地址
                if (Regex.IsMatch(ls_servername, @"^[1-2]{0,1}\d{0,2}\.[1-2]{0,1}\d{0,2}\.[1-2]{0,1}\d{0,2}\.[1-2]{0,1}\d{0,2}$") == false)
                {
                    MessageBox.Show("请输入正确的IP地址,如192.168.90.38", "提示");
                    tb_server.Text = "";
                    tb_server.Focus();
                    return;
                }
                if (ls_datasource.Length <= 0)
                {
                    MessageBox.Show("请输入数据库名!", "提示");
                    tb_server.Focus();
                    return;
                }
                ls_myoledbconn = "Provider=IBMDADB2.1;Data Source=" + ls_datasource + ";Mode=ReadWrite;Network Address=" + ls_servername + ";Default Schema=" + ls_username + ";Persist Security Info=True;User ID=" + ls_username + ";password="******"";
                break;

            default:
                break;
            }
            if (ls_myoledbconn.Length <= 0)
            {
                return;
            }

            CreateHelper.db_SetConnstring(ls_databasetype, ls_myoledbconn, ls_username);
            if (CreateHelper.db_Connect() == false)
            {
                MessageBox.Show("数据库连接失败!", "提示");
                return;
            }
            SqlType           = ls_databasetype;
            SqlConnectString  = ls_myoledbconn;
            SqlDataBaseName   = ls_datasource;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemple #10
0
        public void setViewList()
        {
            string        namesp = strNamespace.Substring(strNamespace.LastIndexOf('.') + 1).TrimEnd('s');
            StringBuilder sb     = new StringBuilder();

            #region 模版权限
            sb.AppendLine("@{");
            sb.AppendFormat("    PlatformContext.ApplicationScreen.Title = \"{0}管理\";", functionNme);
            sb.AppendLine();
            sb.AppendLine("    Layout = \"~/Views/Shared/KLayouts/_GridViewLayout.cshtml\";");
            sb.AppendFormat("    var admin = User.IsInRole(\"{0}.管理员\");", namesp);
            sb.AppendLine();
            sb.AppendFormat("    var add = User.IsInRole(\"{0}.{1}:添加\");", namesp, functionNme);
            sb.AppendLine();
            sb.AppendFormat("    var edit = User.IsInRole(\"{0}.{1}:编辑\");", namesp, functionNme);
            sb.AppendLine();
            sb.AppendFormat("    var del = User.IsInRole(\"{0}.{1}:删除\");", namesp, functionNme);
            sb.AppendLine();
            sb.AppendLine("}");
            #endregion

            #region 样式
            sb.AppendLine("<style>");
            sb.AppendLine("    .s-search {");
            sb.AppendLine("        padding-top: 5px;");
            sb.AppendLine("        padding-bottom: 5px;");
            sb.AppendLine("        background-color: #ffffff;");
            sb.AppendLine("        border: 0px;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    table {");
            sb.AppendLine("        width: 100%;");
            sb.AppendLine("        border: 1px solid #cccccc;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .tabtable {");
            sb.AppendLine("        width: 100%;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    th {");
            sb.AppendLine("        background-color: #f9f9f9;");
            sb.AppendLine("        text-align: center;");
            sb.AppendLine("        vertical-align: middle;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .k-grid td, .k-grid th {");
            sb.AppendLine("        border-width: 0px 1px 1px 0px;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    table th {");
            sb.AppendLine("        margin: 0px;");
            sb.AppendLine("        padding: 0px;");
            sb.AppendLine("        line-height: 30px;");
            sb.AppendLine("        text-align: center;");
            sb.AppendLine("        border-bottom: 1px solid #cccccc;");
            sb.AppendLine("        border-right: 1px solid #cccccc;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    table td {");
            sb.AppendLine("        margin: 0px;");
            sb.AppendLine("        padding: 0px;");
            sb.AppendLine("        line-height: 30px;");
            sb.AppendLine("        text-align: center;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .textright {");
            sb.AppendLine("        text-align: right;");
            sb.AppendLine("        display: inline-block;");
            sb.AppendLine("        float: right;");
            sb.AppendLine("    }");
            sb.AppendLine("    .textcolor {");
            sb.AppendLine("        color: red;");
            sb.AppendLine("        font-size: 12px;");
            sb.AppendLine("    }");
            sb.AppendLine("    .tsuccess {");
            sb.AppendLine("        color: #27b605;");
            sb.AppendLine("        font-weight: bold;");
            sb.AppendLine("    }");
            sb.AppendLine("    .twning {");
            sb.AppendLine("        color: #ff6a00;");
            sb.AppendLine("        font-weight: bold;");
            sb.AppendLine("    }");
            sb.AppendLine("</style>");
            #endregion
            #region 工具栏
            sb.AppendFormat("{0}section ToolsBar{{", "@");
            sb.AppendLine();
            sb.AppendFormat("    {0}if (admin||add){{", "@");
            sb.AppendLine();
            sb.AppendFormat("        {0}Html.CommandButton(\"添加\", \"k-add\", \"{1}Add(null)\", \"btnAdd\", true)", "@", dtName);
            sb.AppendLine();
            sb.AppendLine("    }");
            sb.AppendLine("}");
            #endregion
            #region 查询
            sb.AppendFormat("{0}section Search{{", "@");
            sb.AppendLine();
            sb.AppendLine(checkString.ToString());
            sb.AppendLine("}");
            #endregion
            #region grid
            sb.AppendLine("<div style=\"margin:auto;\">");
            sb.AppendFormat("    {0}(", "@");
            sb.AppendLine();
            sb.AppendFormat(" Html.Kendo().Grid<{0}.Models.{1}Model>()", strNamespace, dtName);
            sb.AppendFormat("      .Name(\"{0}Data\")", dtName);
            sb.AppendLine("  .Columns(cols =>");
            sb.AppendLine("             {");
            string pkname = dt.Rows[0]["name"].ToString();
            sb.AppendLine(listGrid.ToString());
            sb.AppendFormat("                 cols.Bound(col => col.{1}).Title(\"操作\").Sortable(false).TextAlignCenter().ClientTemplate({0}<text>", "@", pkname);
            sb.AppendLine();
            sb.AppendLine("            @if (admin || edit)");
            sb.AppendLine("            {");

            sb.AppendFormat("                @Html.CommandButton(\"编辑\", \"s-i-edit\", \"{0}Add('${{{1}}}')\")", dtName, pkname);
            sb.AppendLine();
            sb.AppendLine("            }");
            sb.AppendLine("            @if (admin || del)");
            sb.AppendLine("            {");
            sb.AppendFormat("                @Html.CommandButton(\"删除\", \"s-i-del\", \"{0}Delete('${{{1}}}')\")", dtName, pkname);
            sb.AppendLine();
            sb.AppendLine("            }");
            sb.AppendFormat("            @Html.CommandButton(\"查看\", \"s-i-check\", \"{0}Query('${{{1}}}')\")", dtName, pkname);
            sb.AppendLine();
            sb.AppendLine("                </text>);");
            sb.AppendLine("             }).Pageable()");
            sb.AppendLine("                                             .DataSource(dataSource => dataSource");
            sb.AppendLine("                                             .Ajax()");

            sb.AppendLine("                                             .PageSize(20)");
            sb.AppendLine("                                             .ServerOperation(true)");
            sb.AppendLine("                                             .Events(events =>");
            sb.AppendLine("                                             {");
            sb.AppendLine("                                             //events.Error(\"errorHandler\");");
            sb.AppendLine("                                             })");
            sb.AppendLine("                                             .Read(read =>");
            sb.AppendLine("                                             {");
            sb.AppendFormat("                                             read.Action(\"ListPage\", \"{0}\");", dtName);
            sb.AppendLine();
            sb.AppendLine("                                             read.Data(\"searchdata\");");
            sb.AppendLine("                                              })");
            sb.AppendLine("                                             )");
            sb.AppendLine("             )");
            sb.AppendLine("</div>");
            #endregion
            #region 脚本
            sb.AppendLine("@section Scripts{");
            sb.AppendLine("    <script src=\"@Url.Content(\"~/KScripts/jquery.kendo.extend.js\")\"></script>");
            sb.AppendLine("    <script>");
            sb.AppendLine("            function researchdata() {");
            sb.AppendLine(researchData.ToString());
            sb.AppendLine("        }");
            sb.AppendLine("        function searchdata() {");
            sb.AppendLine(searchData.ToString());

            sb.AppendFormat("            return {{{0} }};", searchDataStr.ToString().TrimEnd(','));
            sb.AppendLine();
            sb.AppendLine("        }");
            sb.AppendLine("        function Search() {");

            sb.AppendFormat("            $(\"#{0}Data\").data(\"kendoGrid\").dataSource.read({{ page: 1 }});", dtName);
            sb.AppendLine();
            sb.AppendLine("            if ($(\".k-pager-numbers a\").eq(0)) {");
            sb.AppendLine("                var page = $(\".k-pager-numbers a\").eq(0).attr(\"data-page\");");
            sb.AppendLine("                if (page != null && page == \"1\") {");
            sb.AppendLine("                    $(\".k-pager-numbers a\").eq(0).click();");
            sb.AppendLine("                }");
            sb.AppendLine("            }");
            sb.AppendLine("        }");
            sb.AppendFormat("        function {0}Query(id) {{", dtName);
            sb.AppendLine();
            sb.AppendLine("            kendo.showDialog({");
            sb.AppendFormat("                id: \"{0}Query\",", dtName);
            sb.AppendLine();
            sb.AppendFormat("                title: \"{0}信息\",", functionNme);
            sb.AppendLine();
            sb.AppendLine("                content: {");
            sb.AppendFormat("                    url: \"/{0}/{0}Query\",", dtName);
            sb.AppendLine();
            sb.AppendLine("                    data: { id: id },");
            sb.AppendLine("                    complete: function (data) {");
            sb.AppendLine("                        if (!data.success) {");
            sb.AppendLine("                            alert(\"没有查到相应数据,请检查相应数据是否已经删除!\")");
            sb.AppendLine("                        }");
            sb.AppendLine("                    }");
            sb.AppendLine("                }");
            sb.AppendLine("            })");
            sb.AppendLine("        }");
            sb.AppendFormat("        function {0}Add(id) {{", dtName);
            sb.AppendLine();

            sb.AppendLine("            kendo.showDialog({");
            sb.AppendFormat("                id: \"{0}ADD\",", dtName);
            sb.AppendLine();
            sb.AppendFormat("                title: id ? \"{0}编辑\" : \"{0}新增\",", functionNme);
            sb.AppendLine();
            sb.AppendLine("                content: {");
            sb.AppendFormat("                    url: \"/{0}/{0}Add\",", dtName);
            sb.AppendLine();
            sb.AppendLine("                    data: { id: id },");
            sb.AppendLine("                    complete: function (data) {");
            sb.AppendLine("                        if (data.success) {");
            sb.AppendLine("                            alert(\"操作成功!\");");
            sb.AppendFormat("                            $(\"#{0}Data\").data(\"kendoGrid\").dataSource.read();", dtName);
            sb.AppendLine();
            sb.AppendLine("                        }");
            sb.AppendLine("                        else {");
            sb.AppendLine("                            alert(\"操作失败!\")");
            sb.AppendLine("                        }");
            sb.AppendLine("                    }");
            sb.AppendLine("                },");
            sb.AppendLine("            });");
            sb.AppendLine("        }");
            sb.AppendFormat("        function {0}Delete(id) {{", dtName);
            sb.AppendLine();
            sb.AppendLine("            if (confirm(\"确认要删除该条信息吗?\")) {");
            sb.AppendLine("                $.ajax({");
            sb.AppendLine("                    type: \"POST\",");
            sb.AppendFormat("                    url: \"/{0}/{0}Delete\",", dtName);
            sb.AppendLine();
            sb.AppendLine("                    data: { id: id },");
            sb.AppendLine("                    success: function (re) {");
            sb.AppendLine("                        if (re.success) {");
            sb.AppendLine("                            alert(\"删除成功!\");");
            sb.AppendFormat("                            $(\"#{0}Data\").data(\"kendoGrid\").dataSource.read();", dtName);
            sb.AppendLine();
            sb.AppendLine("                        } else {");
            sb.AppendLine("                            alert(\"删除失败!\");");
            sb.AppendLine("                        }");
            sb.AppendLine("                    }");
            sb.AppendLine("                });");
            sb.AppendLine("            }");
            sb.AppendLine("        }");
            sb.AppendLine("        function DownloadFile(filenames) {");
            sb.AppendLine("            kendo.showDialog({");
            sb.AppendLine("                title: \"下载文档列表\",");
            sb.AppendLine("                content: {");
            sb.AppendLine("                    url: \"/Demo/DownLoadFiles\",");
            sb.AppendLine("                    data: { names: filenames }");
            sb.AppendLine("                },");
            sb.AppendLine("            })");
            sb.AppendLine("        }");
            sb.AppendLine("    </script>");
            sb.AppendLine("}");
            #endregion
            File.WriteAllText(CreateHelper.getPath(dtName) + "//Views" + "//" + dtName + "List.cshtml", sb.ToString());
        }
Exemple #11
0
        public void setViewAdd()
        {
            StringBuilder sb = new StringBuilder();

            #region 模版
            sb.AppendFormat("{0}{{", "@");
            sb.AppendLine();
            sb.AppendFormat("    PlatformContext.ApplicationScreen.Title = \"{0}管理\";", functionNme);
            sb.AppendLine();
            //sb.AppendFormat("    Layout = \"~/Views/Shared/KLayouts/_GridViewLayout.cshtml\";");
            //sb.AppendLine();
            sb.AppendLine("}");
            #endregion
            #region 样式
            sb.AppendLine("<style>");
            sb.AppendLine("    .inline-label1 {");
            sb.AppendLine("        width: 45%;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .block-label1 {");
            sb.AppendLine("        width: 94%;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .k-edit-form-container .block-label1 .label1 {");
            sb.AppendLine("        width: 14%;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .ko-UploadPic-file {");
            sb.AppendLine("        float: left;");
            sb.AppendLine("        margin-right: 10px;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .ko-upload-filelist {");
            sb.AppendLine("        margin-top: 10px;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .ko-upload-container .k-upload-status {");
            sb.AppendLine("        display: none;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .ko-upload-container .k-header {");
            sb.AppendLine("        background-color: transparent;");
            sb.AppendLine("        border: none;");
            sb.AppendLine("    }");
            sb.AppendLine("");
            sb.AppendLine("    .ko-upload-container .k-dropzone {");
            sb.AppendLine("        padding: 0 0 0 0;");
            sb.AppendLine("    }");
            sb.AppendLine("</style>");
            #endregion
            sb.AppendLine("<script type=\"text/javascript\">");
            sb.AppendLine("    $(function () {");
            sb.AppendFormat("        if ($(\"#{0}\").val().length == 0) {{", dt.Rows[0][0].ToString());
            sb.AppendLine();
            sb.AppendFormat("            $(\"#{0}\").val(\"00000000-0000-0000-0000-000000000000\");", dt.Rows[0][0].ToString());
            sb.AppendLine();
            sb.AppendLine("        }");
            sb.AppendLine("    })");
            sb.AppendLine("</script>");
            sb.AppendLine("@Html.AjaxEditorForm(width: 800, isDialog: false)");

            File.WriteAllText(CreateHelper.getPath(dtName) + "//Views" + "//" + dtName + "Add.cshtml", sb.ToString());
            File.WriteAllText(CreateHelper.getPath(dtName) + "//Views" + "//" + dtName + "Query.cshtml", sb.ToString());
        }
Exemple #12
0
        public bool setDomainService()
        {
            #region 业务服务处理层模版
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("using System;");
            sb.AppendLine("using System.Linq;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using SafetySupervision.SuperviseDataAccess;");
            sb.AppendLine("using SafetySupervision.SuperviseDataAccess.Entities;");
            sb.AppendLine();
            sb.AppendFormat("using {0}.Models;", strNamespace);
            sb.AppendLine();
            sb.AppendFormat("namespace {0}.Domain", strNamespace);
            sb.AppendLine();
            sb.AppendLine("{");
            sb.AppendLine();
            sb.AppendLine(GetDomainInterface().ToString());
            sb.AppendFormat("    public class {0}Service : I{0}Service", dtName);
            sb.AppendLine();
            sb.AppendLine("    {");
            sb.AppendFormat("        {0} dbContext = new {0}();", dataContext);
            sb.AppendLine();
            sb.AppendFormat("        public {0}Service()", dtName);
            sb.AppendLine();
            sb.AppendLine("        {");
            sb.AppendLine(" ");
            sb.AppendLine("        }");
            sb.AppendLine();

            sb.AppendFormat("        public {0} Get(Guid id)", modeName);
            sb.AppendLine("        {");
            sb.AppendLine();
            sb.AppendFormat("            var entity = dbContext.{0}.First(p => p.{1} == id);", dtName, dt.Rows[0]["name"].ToString());
            sb.AppendLine();
            sb.AppendFormat("            return entity.ToViewModel<{0}>();", modeName);
            sb.AppendLine();
            sb.AppendLine("        }");
            sb.AppendFormat("        public int Add({0} model)", modeName);
            sb.AppendLine("        {");
            sb.AppendFormat("            {0} ent = model.ToORMEntity<{0}>();", dtName);
            sb.AppendLine();
            sb.AppendFormat("            int re = dbContext.{0}.Insert(ent);", dtName);
            sb.AppendLine();
            sb.AppendLine("            return re;");
            sb.AppendLine("        }");
            sb.AppendFormat("        public int Edit({0} model)", modeName);
            sb.AppendLine();
            sb.AppendLine("        {");
            sb.AppendFormat("            var ent = model.ToORMEntity<{0}>();", dtName);
            sb.AppendLine();
            sb.AppendFormat("            int re = dbContext.{0}.Update(ent);", dtName);
            sb.AppendLine();
            sb.AppendLine("            return re;");
            sb.AppendLine("        }");
            sb.AppendLine("        public int Delete(Guid id)");
            sb.AppendLine("        {");
            sb.AppendFormat("            return dbContext.{0}.Delete(id);", dtName);
            sb.AppendLine();
            sb.AppendLine("        }");
            sb.AppendLine();
            sb.AppendFormat("        public List<{0}> GetAllPage(int index, int size,{1} out int total)", modeName, checkString.ToString());
            sb.AppendLine();
            sb.AppendLine("        {");
            sb.AppendFormat("            string sql = {0}\"select * from {1}  where 1=1 \";", "@", dtName);
            sb.AppendLine();
            sb.AppendLine(query.ToString());
            sb.AppendLine("            try");
            sb.AppendLine("            {");
            sb.AppendLine("                var query = dbContext.CustomSql(sql).SetSelectRange(size * (index - 1), size);");
            sb.AppendLine("                total = query.GetTotalForPaging();");
            sb.AppendFormat("                return query.OrderBy(\" CreateTime Desc\").ToList<{0}>();", modeName);
            sb.AppendLine();
            sb.AppendLine("            }");
            sb.AppendLine("            catch (Exception ex)");
            sb.AppendLine("            {");
            sb.AppendLine("                total = 0;");
            sb.AppendLine("                return null;");
            sb.AppendLine("            }");
            sb.AppendLine("        }");
            sb.AppendLine("    }");
            sb.AppendLine("}");
            #endregion
            File.WriteAllText(CreateHelper.getPath(dtName) + "//Domain" + "//" + dtName + "Service.cs", sb.ToString());
            return(false);
        }
Exemple #13
0
        public bool setModel()
        {
            try
            {
                StringBuilder sb     = new StringBuilder();
                string        tbname = dt.TableName;
                sb.AppendLine("using System;");
                sb.AppendLine("using System.Web.Mvc;");
                sb.AppendLine("using System.ComponentModel;");
                sb.AppendLine("using RTSafe.Platform.Core;");
                sb.AppendLine("using System.ComponentModel.DataAnnotations;");
                sb.AppendLine("using RTSafe.Platform.KMvcControl.Attributes;");
                sb.AppendLine();
                sb.AppendFormat("namespace {0}.Models", nameSpace);
                sb.AppendLine();
                sb.AppendLine("{");
                sb.AppendFormat("    public class {0}Model : MapperModel", tbname);
                sb.AppendLine();
                sb.AppendLine("    {");
                if (dt != null || dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        string name = dr["name"].ToString();
                        sb.AppendLine();
                        sb.AppendFormat("        [DisplayName(\"{0}\")]", dr["DisplayName"].ToString());
                        sb.AppendLine();
                        string l    = dr["Length"].ToString();
                        string dtyp = dr["DataType"].ToString();
                        bool   n    = (dtyp == "nvarchar" || dtyp == "varchar" || dtyp == "char" || dtyp == "nchar");
                        if (dr["IsNull"].ToString().ToLower() == "false")
                        {
                            sb.AppendLine("        [Required(ErrorMessage = \"{0}不能为空\")] ");
                            if (n)
                            {
                                sb.AppendFormat("        [StringLength({0},MinimumLength = 1, ErrorMessage =\"{{0}}长度在{{2}}-{{1}}之间\")]", l);
                                sb.AppendLine();
                            }
                        }
                        else if (dr["IsNull"].ToString().ToLower() != "false" && n)
                        {
                            sb.AppendFormat("        [StringLength({0}, ErrorMessage = \"{1}长度不可超出{0}\")]", l, "{0}");
                            sb.AppendLine();
                        }
                        if (dr["HiddenInput"].ToString().ToLower() != "true" || dt.Rows.IndexOf(dr) == 0)
                        {
                            sb.AppendLine("        [HiddenInput(DisplayValue=false)]");
                        }

                        if (name == "LineID")
                        {
                            sb.AppendLine("        [SelectList(\"/Inspect/GetLine?all=0\",");
                            sb.AppendLine("             HttpVerbs.Post,");
                            sb.AppendLine("             DataValueField = \"LineID\",");
                            sb.AppendLine("             DataTextField = \"Name\",");
                            sb.AppendLine("             DataType = \"DropDownList\")]");
                        }
                        else if (name == "SegmentID")
                        {
                            sb.AppendLine("        [SelectList(\"/Inspect/GetSegment?all=0\",");
                            sb.AppendLine("             HttpVerbs.Post,");
                            sb.AppendLine("             CascadeFrom = \"LineID\",");
                            sb.AppendLine("             DataValueField = \"SegmentID\",");
                            sb.AppendLine("             DataTextField = \"Name\",");
                            sb.AppendFormat("             Data = {0}\"function(){{", "@");
                            sb.AppendLine();
                            sb.AppendLine("                        return { lineId: $(\"\"#LineID\"\").val() };");
                            sb.AppendLine("                    }\",");
                            sb.AppendLine("             DataType = \"DropDownList\")]");
                        }
                        else if (name == "SiteID")
                        {
                            sb.AppendLine("        [SelectList(\"/Inspect/GetSegment?all=0\",");
                            sb.AppendLine("             HttpVerbs.Post,");
                            sb.AppendLine("             CascadeFrom = \"SegmentID\",");
                            sb.AppendLine("             DataValueField = \"SiteID\",");
                            sb.AppendLine("             DataTextField = \"Name\",");
                            sb.AppendFormat("             Data = {0}\"function(){{", "@");
                            sb.AppendLine();
                            sb.AppendLine("                        return { segmentID: $(\"\"#SegmentID\"\").val() };");
                            sb.AppendLine("                    }\",");
                            sb.AppendLine("             DataType = \"DropDownList\")]");
                        }
                        else if (!string.IsNullOrEmpty(dr["SelectList"].ToString()) && string.IsNullOrEmpty(dr["SelectData"].ToString()))
                        {
                            sb.AppendFormat("        [SelectList(\"{0}\",HttpVerbs.Post,DataValueField = \"{1}\",DataTextField = \"Name\",DataType = \"DropDownList\")]", dr["SelectList"].ToString(), name);
                            sb.AppendLine();
                        }
                        else if (!string.IsNullOrEmpty(dr["SelectData"].ToString()) && !string.IsNullOrEmpty(dr["SelectList"].ToString()))
                        {
                            string[] SelectData = dr["SelectData"].ToString().Split(':');
                            sb.AppendFormat("        [SelectList(\"{0}\",HttpVerbs.Post, CascadeFrom = \"{4}\",  DataValueField = \"{1}\",DataTextField = \"Name\",Data ={2}\"function(){{return {{ {3}: $(\"\"#{4}\"\").val() }}; }}\",DataType = \"DropDownList\")]", dr["SelectList"].ToString(), name, "@", SelectData[0], SelectData[1]);
                            sb.AppendLine();
                        }
                        if (dr["DataType"].ToString() == "datetime")
                        {
                            sb.AppendLine("        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = \"{0:yyyy-MM-dd}\")]");
                        }
                        string da = dr["DefaultAttribute"].ToString();
                        if (!string.IsNullOrEmpty(da))
                        {
                            string[] daArray = da.Split('|');
                            foreach (string das in daArray)
                            {
                                if (string.IsNullOrEmpty(das))
                                {
                                    break;
                                }
                                sb.AppendFormat("        [{0}]", das);
                                sb.AppendLine();
                            }
                        }
                        string regular = dr["Regular"].ToString();
                        if (!string.IsNullOrEmpty(regular))
                        {
                            sb.AppendFormat("        [RegularExpression({0}\"{1}\")]", "@", regular);
                            sb.AppendLine();
                        }
                        sb.AppendFormat("        public {0} {1} {{ get; set; }}", CreateHelper.GetCsType(dr["DataType"].ToString()), name);
                        sb.AppendLine();
                    }
                }
                sb.AppendLine("        }");
                sb.AppendLine("}");
                File.WriteAllText(CreateHelper.getPath(tbname) + "//Models" + "//" + tbname + "Model.cs", sb.ToString());
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }