Exemplo n.º 1
0
        /// <summary>
        /// 自动创建dbset
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateDBSet_Click(object sender, EventArgs e)
        {
            List <TableModel> list = new List <TableModel>();

            foreach (DataGridViewRow row in gvTables.Rows)
            {
                TableModel item = (TableModel)row.DataBoundItem;
                if (item.IsMap)
                {
                    //获取表注释
                    item.Description = DBHelper.GetColumn(ConnectionString, item.Name).FirstOrDefault().TableDescription;
                    list.Add(item);
                }
            }
            StringBuilder strDBSet = new StringBuilder();

            foreach (var item in list)
            {
                strDBSet.AppendLine("///<summary>");
                strDBSet.AppendLine("///" + item.Description);
                strDBSet.AppendLine("///</summary>");
                strDBSet.AppendLine("public  DbSet<" + item.Name + "> " + item.Name + " { get; set; }");
            }

            ShowText m = new ShowText();

            m.SetTextContent(strDBSet.ToString());
            m.Show();
        }
Exemplo n.º 2
0
        private void btnCreateServerType_Click(object sender, EventArgs e)
        {
            List <TableModel> list = new List <TableModel>();

            foreach (DataGridViewRow row in gvTables.Rows)
            {
                TableModel item = (TableModel)row.DataBoundItem;
                if (item.IsMap)
                {
                    list.Add(item);
                }
            }
            StringBuilder strServerType = new StringBuilder();

            foreach (var item in list)
            {
                strServerType.AppendLine("[ServiceKnownType(typeof(" + item.Name + "))]");
            }

            ShowText m = new ShowText();

            m.SetTextContent(strServerType.ToString());
            m.Show();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建接口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateInterface_Click(object sender, EventArgs e)
        {
            List <TableModel> list = new List <TableModel>();
            string            db   = tbDataOperate.Text;

            foreach (DataGridViewRow row in gvTables.Rows)
            {
                TableModel item = (TableModel)row.DataBoundItem;
                if (item.IsMap)
                {
                    //获取表注释
                    item.Description = DBHelper.GetColumn(ConnectionString, item.Name).FirstOrDefault().TableDescription;
                    list.Add(item);
                }
            }
            StringBuilder strInterface = new StringBuilder();
            var           actionList   = Enum <Operate> .AsEnumerable();

            foreach (var item in list)
            {
                //interface
                foreach (var action in actionList)
                {
                    string actionName = action.GetText().Replace("{Model}", item.NoPrefixName);
                    strInterface.AppendLine("///<summary>");
                    strInterface.AppendLine("///" + DBHelper.ActionText[action] + ":" + item.Description);
                    strInterface.AppendLine("///</summary>");

                    switch (action)
                    {
                    case Operate.Add:
                        strInterface.AppendLine(" ///<param name=\"model\">要添加的model</param>");
                        strInterface.AppendLine(" ///<returns>受影响的行数</returns>");
                        strInterface.AppendLine("[OperationContract]");
                        strInterface.AppendLine(" Result<int> " + actionName + "(" + item.Name + " model);");
                        break;

                    case Operate.Edit:
                        strInterface.AppendLine(" ///<param name=\"model\">要修改的model</param>");
                        strInterface.AppendLine(" ///<returns>受影响的行数</returns>");
                        strInterface.AppendLine("[OperationContract]");
                        strInterface.AppendLine(" Result<int> " + actionName + "(" + item.Name + " model);");
                        break;

                    case Operate.Delete:
                        strInterface.AppendLine(" ///<param name=\"ids\">要删除的Id集合</param>");
                        strInterface.AppendLine(" ///<returns>受影响的行数</returns>");
                        strInterface.AppendLine("[OperationContract]");
                        strInterface.AppendLine(" Result<int> " + actionName + "(List<long> ids);");
                        break;

                    case Operate.List:
                        strInterface.AppendLine(" ///<param name=\"qc\">查询条件</param>");
                        strInterface.AppendLine(" ///<returns>符合条件的数据集合</returns>");
                        strInterface.AppendLine("[OperationContract]");
                        strInterface.AppendLine(" Result<List<" + item.Name + ">> " + actionName + "(QueryCondition qc);");
                        break;

                    case Operate.Detail:
                        strInterface.AppendLine(" ///<param name=\"id\">数据Id</param>");
                        strInterface.AppendLine(" ///<returns>数据详情model</returns>");
                        strInterface.AppendLine("[OperationContract]");
                        strInterface.AppendLine(" Result<" + item.Name + "> " + actionName + "(long id);");
                        break;

                    default:
                        break;
                    }
                }
            }
            strInterface.AppendLine("");
            strInterface.AppendLine("");
            strInterface.AppendLine("");
            foreach (var item in list)
            {
                //proxy
                foreach (var action in actionList)
                {
                    string actionName = action.GetText().Replace("{Model}", item.NoPrefixName);
                    strInterface.AppendLine("///<summary>");
                    strInterface.AppendLine("///" + DBHelper.ActionText[action] + ":" + item.Description);
                    strInterface.AppendLine("///</summary>");
                    switch (action)
                    {
                    case Operate.Add:
                        strInterface.AppendLine(" ///<param name=\"model\">要添加的model</param>");
                        strInterface.AppendLine(" ///<returns>受影响的行数</returns>");

                        strInterface.AppendLine(" public Result<int> " + actionName + "(" + item.Name + " model)");
                        strInterface.AppendLine(" {");
                        strInterface.AppendLine("  return base.Channel." + actionName + "(model);");
                        strInterface.AppendLine(" }");
                        break;

                    case Operate.Edit:
                        strInterface.AppendLine(" ///<param name=\"model\">要修改的model</param>");
                        strInterface.AppendLine(" ///<returns>受影响的行数</returns>");

                        strInterface.AppendLine(" public Result<int> " + actionName + "(" + item.Name + " model)");
                        strInterface.AppendLine(" {");
                        strInterface.AppendLine("  return base.Channel." + actionName + "(model);");
                        strInterface.AppendLine(" }");
                        break;

                    case Operate.Delete:
                        strInterface.AppendLine(" ///<param name=\"ids\">要删除的Id集合</param>");
                        strInterface.AppendLine(" ///<returns>受影响的行数</returns>");

                        strInterface.AppendLine(" public Result<int> " + actionName + "(List<long> ids)");
                        strInterface.AppendLine(" {");
                        strInterface.AppendLine("  return base.Channel." + actionName + "(ids);");
                        strInterface.AppendLine(" }");
                        break;

                    case Operate.List:
                        strInterface.AppendLine(" ///<param name=\"qc\">查询条件</param>");
                        strInterface.AppendLine(" ///<returns>符合条件的数据集合</returns>");

                        strInterface.AppendLine(" public Result<List<" + item.Name + ">> " + actionName + "(QueryCondition qc)");
                        strInterface.AppendLine(" {");
                        strInterface.AppendLine("  return base.Channel." + actionName + "(qc);");
                        strInterface.AppendLine(" }");
                        break;

                    case Operate.Detail:
                        strInterface.AppendLine(" ///<param name=\"id\">数据Id</param>");
                        strInterface.AppendLine(" ///<returns>数据详情model</returns>");

                        strInterface.AppendLine(" public Result<" + item.Name + "> " + actionName + "(long id)");
                        strInterface.AppendLine(" {");
                        strInterface.AppendLine("  return base.Channel." + actionName + "(id);");
                        strInterface.AppendLine(" }");
                        break;

                    default:
                        break;
                    }
                }
            }
            ShowText m = new ShowText();

            m.SetTextContent(strInterface.ToString() + "");
            m.Show();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 创建service
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateService_Click(object sender, EventArgs e)
        {
            List <TableModel> list = new List <TableModel>();
            string            db   = tbDataOperate.Text;

            foreach (DataGridViewRow row in gvTables.Rows)
            {
                TableModel item = (TableModel)row.DataBoundItem;
                if (item.IsMap)
                {
                    //获取表注释
                    item.Description = DBHelper.GetColumn(ConnectionString, item.Name).FirstOrDefault().TableDescription;
                    list.Add(item);
                }
            }

            StringBuilder strClass   = new StringBuilder();
            var           actionList = Enum <Operate> .AsEnumerable();

            foreach (var item in list)
            {
                //class
                foreach (var action in actionList)
                {
                    strClass.AppendLine("///<summary>");
                    strClass.AppendLine("///" + DBHelper.ActionText[action] + ":" + item.Description);
                    strClass.AppendLine("///</summary>");
                    string actionName = action.GetText().Replace("{Model}", item.NoPrefixName);
                    string data       = "result.Data = -1;";
                    switch (action)
                    {
                    case Operate.Add:
                        strClass.AppendLine(" /// <param name=\"model\">要添加的model</param>");
                        strClass.AppendLine(" /// <returns>受影响的行数</returns>");

                        strClass.AppendLine("public  Result<int> " + actionName + "(" + item.Name + " model)");
                        strClass.AppendLine("{");
                        strClass.AppendLine("Result<int> result = new Result<int>();");
                        strClass.AppendLine("try");
                        strClass.AppendLine("{");
                        strClass.AppendLine("var rows = " + db + "<" + item.Name + ">.Get().Add(model);");
                        strClass.AppendLine(" result.Data = rows;");
                        strClass.AppendLine("result.Flag = EResultFlag.Success;");
                        strClass.AppendLine(" WriteLog(AdminModule." + item.NoPrefixName + ".GetText(), SystemRight.Add.GetText(), \"新增" + item.Description + ": \" + model.Id );");
                        break;

                    case Operate.Edit:
                        strClass.AppendLine(" /// <param name=\"model\">要修改的model</param>");
                        strClass.AppendLine(" /// <returns>受影响的行数</returns>");

                        strClass.AppendLine("public  Result<int> " + actionName + "(" + item.Name + " model)");
                        strClass.AppendLine("{");
                        strClass.AppendLine("Result<int> result = new Result<int>();");
                        strClass.AppendLine("try");
                        strClass.AppendLine("{");
                        strClass.AppendLine("var rows = " + db + "<" + item.Name + ">.Get().Update(model);");
                        strClass.AppendLine("result.Data = rows;");
                        strClass.AppendLine("result.Flag = EResultFlag.Success;");
                        strClass.AppendLine(" WriteLog(AdminModule." + item.NoPrefixName + ".GetText(), SystemRight.Modify.GetText(), \"修改" + item.Description + ": \" + model.Id );");

                        break;

                    case Operate.Delete:
                        strClass.AppendLine(" /// <param name=\"ids\">要删除的Id集合</param>");
                        strClass.AppendLine(" /// <returns>受影响的行数</returns>");

                        strClass.AppendLine("public  Result<int> " + actionName + "(List<long> ids)");
                        strClass.AppendLine("{");
                        strClass.AppendLine("Result<int> result = new Result<int>();");
                        strClass.AppendLine("try");
                        strClass.AppendLine("{");
                        strClass.AppendLine("var models = " + db + "<" + item.Name + ">.Get().GetList(i => ids.Contains(i.Id)).ToList();");
                        strClass.AppendLine("var rows = " + db + "<" + item.Name + ">.Get().DeleteRange(models);");
                        strClass.AppendLine("result.Data = rows;");
                        strClass.AppendLine("result.Flag = EResultFlag.Success;");
                        strClass.AppendLine(" WriteLog(AdminModule." + item.NoPrefixName + ".GetText(), SystemRight.Delete.GetText(), \"批量删除" + item.Description + ": \" + rows );");

                        break;

                    case Operate.List:
                        strClass.AppendLine(" /// <param name=\"qc\">查询条件</param>");
                        strClass.AppendLine(" /// <returns>符合条件的数据集合</returns>");

                        strClass.AppendLine("public Result<List<" + item.Name + ">> " + actionName + "(QueryCondition qc)");
                        strClass.AppendLine("{");
                        strClass.AppendLine(" qc = AddDefault(qc);");
                        strClass.AppendLine(" Result<List<" + item.Name + ">> result = new Result<List<" + item.Name + ">>();");
                        strClass.AppendLine("try");
                        strClass.AppendLine("{");
                        strClass.AppendLine("result = hc.Plat.Common.Service.DataOperate.QueryListSimple<" + item.Name + ">(context, qc);");
                        data = "result.Data = null;";
                        break;

                    case Operate.Detail:
                        strClass.AppendLine(" /// <param name=\"id\">数据Id</param>");
                        strClass.AppendLine(" /// <returns>数据详情model</returns>");

                        strClass.AppendLine("public Result<" + item.Name + "> " + actionName + "(long id)");
                        strClass.AppendLine("{");
                        strClass.AppendLine(" Result<" + item.Name + "> result = new Result<" + item.Name + ">();");
                        strClass.AppendLine("try");
                        strClass.AppendLine("{");
                        strClass.AppendLine(" var model = " + db + "<" + item.Name + ">.Get().GetModel(id);");
                        strClass.AppendLine("result.Data = model;");
                        strClass.AppendLine("result.Flag = EResultFlag.Success;");
                        data = "result.Data = null;";
                        break;

                    default:
                        break;
                    }
                    strClass.AppendLine(" }");
                    strClass.AppendLine("catch (Exception ex)");
                    strClass.AppendLine("{");
                    strClass.AppendLine(data);
                    strClass.AppendLine("result.Flag = EResultFlag.Failure;");
                    strClass.AppendLine("result.Exception = new ExceptionEx(ex, \"" + actionName + "\");");
                    strClass.AppendLine("}");
                    strClass.AppendLine("return result;");
                    strClass.AppendLine("}");
                }
            }

            ShowText m = new ShowText();

            m.SetTextContent(strClass.ToString() + "");
            m.Show();
        }