コード例 #1
0
 protected override void RenderView(IndentStringBuilder builder, T_Field f, AssignOperatorInfo? op, IndentStringBuilder opValue)
 {
     if (op.HasValue)
     {
         builder.AppendFormat(".{0} {1} {2}",f.Name, op.GetDescription(), opValue);
     }
     else
     {
         builder.AppendFormat(".{0}", f.Name);
     }
 }
コード例 #2
0
        protected virtual void RenderView(IndentStringBuilder builder, T_Field f,AssignOperatorInfo?  op, IndentStringBuilder rightBuilder)
        {
            var p = "";
            if (rightBuilder != null) p = rightBuilder.ToString();

            //builder.AppendFormat(".{0}({1})", f.Name, p);

            builder.AppendFormat(".{0}", f.Name);

            if (op.HasValue)
            {
                builder.AppendFormat("{0}{1}",op.Value.GetDescription(),rightBuilder.ToString());
            }
        }
コード例 #3
0
 protected override void RenderView(IndentStringBuilder builder, T_Field f,AssignOperatorInfo? op, IndentStringBuilder opValue)
 {
     //base.RenderView(builder, f, rightBuilder);
     if (opValue != null && opValue.Length > 0)
     {
         builder.AppendFormat(".{0}({1})",f.Name, opValue.ToString());
     }
     else
     {
         if (f.Type is T_EventType)
         {
             builder.AppendFormat(".{0}", f.Name);
         }
         else if (f.Type is T_ValidateType)
         {
             builder.AppendFormat(".{0}", f.Name);
         }
         else
         {
             builder.AppendFormat(".{0}()", f.Name);
         }
     }
 }
コード例 #4
0
        protected virtual void RenderView(IndentStringBuilder builder, T_Method m, IndentStringBuilder paras)
        {
            var p = "";
            if (paras != null) p = paras.ToString();

            builder.AppendFormat(".{0}({1})", m.Name, p);
        }
コード例 #5
0
ファイル: SqlEditFrm.cs プロジェクト: koksaver/CodeHelper
        private void btnGenCCFlowService_Click(object sender, EventArgs e)
        {
            List<ParseErrorInfo> errors;

            ContextMenu contextMenu;

            DataViewDB dvDB;

            SqlParser.Instance().Parse(this.textEditorControl.Document.TextContent, 0, out dvDB, out errors, out contextMenu);

            textEditorControl_Output.Document.TextContent = null;
            if (dvDB == null)
            {
                OnError(SqlParser.Instance().Errors.ToList());
            }
            if (dvDB != null)
            {
                SelectContext.Root = dvDB.Context;
                OnError(dvDB.Errors);
                dvDB.InitOption();
                dvDB.Context.Wise(null);

                var search = GeneratorUtil.ClassName(this.txtName.Text.Trim());
                var dtoName = string.Format("{0}_ConditionDto", GeneratorUtil.ClassName(this.txtName.Text.Trim()));
                var dtoName_variable = GeneratorUtil.VariableName(dtoName);
                var domainName = string.Format("{0}_Condition", GeneratorUtil.ClassName(this.txtName.Text.Trim()));
                var domainName_variable = GeneratorUtil.VariableName(domainName);
                var action = GeneratorUtil.ClassName(this.txtName.Text.Trim());
                var retrunInfoDto_class = "ReturnInfoDto";
                if (dvDB.IsPager)
                {
                    retrunInfoDto_class = "PageOfReturnDto";
                }
                this.ModelInfo = dvDB.Context.Unions[0].Context.TableJoinInfos[0].RightModelInfo;

                var orders = dvDB.OrderPairs;

                //获得对应的model
                var modelName = "unknown";
                var paras = dvDB.Context.Parameters;

                modelName = GeneratorUtil.ClassName(this.txtResultModel.Text.Trim());
                var varModelName = Helper.GetVarName(modelName);

                var serviceDict = new Dictionary<string, string>();
                var result_list = false;
                var result_wraper = true;

                foreach (var op in dvDB.Options)
                {
                    if (op.Name.StartsWith(":"))
                    {
                        serviceDict.Add(op.Name.Substring(1), op.Value);
                    }
                    else if (op.Name.Equals("result_list", StringComparison.OrdinalIgnoreCase))
                    {
                        bool.TryParse(op.Value, out result_list);
                    }
                    else if (op.Name.Equals("result_wraper", StringComparison.OrdinalIgnoreCase))
                    {
                        bool.TryParse(op.Value, out result_wraper);
                    }
                }

                if (serviceDict.Count == 0)
                    return;

                var modelFields = new Dictionary<string, FieldInfo>();

                foreach (var field in dvDB.Context.Unions[0].Context.ReturnFields.OrderByName())
                {
                    if (field is MutiField)
                    {
                        var muti_fieds = field as MutiField;
                        foreach (var f in muti_fieds.AllFields.OrderByName())
                        {
                            var field_name = string.IsNullOrWhiteSpace(f.Alias) ? f.FullName : f.Alias;
                            field_name = GeneratorUtil.ClassName(field_name);
                            if (field_name.LastIndexOf(".") > -1)
                            {
                                field_name = field_name.Substring(field_name.LastIndexOf(".") + 1);
                            }

                            modelFields.Add(field_name, f);
                        }
                    }
                    else
                    {
                        var field_name = string.IsNullOrWhiteSpace(field.Alias) ? field.FullName : field.Alias;
                        field_name = GeneratorUtil.ClassName(field_name);
                        if (field_name.LastIndexOf(".") > -1)
                        {
                            field_name = field_name.Substring(field_name.LastIndexOf(".") + 1);
                        }
                        var nullAble = field.NullAble ? "?" : "";
                        if (field.SystemType.Equals("string", StringComparison.OrdinalIgnoreCase))
                        {
                            nullAble = "";
                        }
                        modelFields.Add(field_name, field);
                    }
                }

                //验证返回字段是否合法
                foreach (var srv in serviceDict)
                {
                    var ss = srv.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var s in ss)
                    {
                        if (!modelFields.ContainsKey(s))
                        {
                            MessageBox.Show(string.Format("结果集中没有该字段:{0} {1}", srv.Key, s));
                            return;
                        }
                    }
                }

                var builder = new IndentStringBuilder();

                foreach (var srv in serviceDict)
                {
                    builder.AppendFormatLine("[OperationContract]");
                    builder.AppendFormatLine("[WithoutAuthorization]");
                    builder.AppendFormatLine("[FaultContractAttribute(typeof(UnAuthorization))]");
                    builder.AppendFormat("List<KeyValuePair<string, string>> {0}(", srv.Key);
                    var fields = srv.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    for (var index = 0; index < paras.Count(); index++)
                    {
                        var para = paras[index];
                        builder.AppendFormat("string {0}", para.VariableName);
                        if (index != paras.Count() - 1)
                        {
                            builder.AppendFormat(", ", para);
                        }
                    }
                    builder.AppendFormatLine(");");
                    builder.AppendLine();
                }

                foreach (var srv in serviceDict)
                {
                    builder.AppendFormat("public List<KeyValuePair<string, string>> {0}(", srv.Key);

                    var fields = srv.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    for (var index = 0; index < paras.Count(); index++)
                    {
                        var para = paras[index];
                        builder.AppendFormat("string {0}", para.VariableName);
                        if (index != paras.Count() - 1)
                        {
                            builder.AppendFormat(", ");
                        }
                    }
                    builder.AppendFormatLine(")");
                    builder.IncreaseIndentLine("{");

                    builder.AppendFormatLine("try");
                    builder.IncreaseIndentLine("{");
                    builder.AppendFormat("var ret = _appService.{0}(", action);
                    for (var index = 0; index < paras.Count(); index++)
                    {
                        var para = paras[index];
                        var parseString = para.VariableName;
                        if (para.DbType == CodeHelper.Core.Parse.ParseResults.DataViews.DbType.Guid)
                        {
                            parseString = string.Format("Guid.Parse({0})", para.VariableName);
                        }
                        else if (para.DbType == CodeHelper.Core.Parse.ParseResults.DataViews.DbType.Int)
                        {
                            parseString = string.Format("Int.Parse({0})", para.VariableName);
                        }
                        builder.AppendFormat("{0}", parseString);
                        if (index != paras.Count() - 1)
                        {
                            builder.AppendFormat(", ");
                        }
                    }
                    builder.AppendFormatLine(");");
                    if (!result_list)
                    {
                        if (result_wraper)
                        {
                            builder.AppendLine("if (ret == null || ret.Data == null)");
                            builder.AppendLine("\treturn null;");
                        }
                        else
                        {
                            builder.AppendLine("if (ret == null)");
                            builder.AppendLine("\treturn null;");
                        }
                    }
                    else
                    {
                        if (result_wraper)
                        {
                            builder.AppendLine("if (ret == null || ret.Data == null || ret.Data.Count() < 1)");
                            builder.AppendLine("\treturn null;");
                        }
                        else
                        {
                            builder.AppendLine("if (ret == null || ret.Data.Count() < 1)");
                            builder.AppendLine("\treturn null;");
                        }
                    }
                    builder.AppendLine();

                    builder.AppendLine("List<KeyValuePair<string, string>> kvs = new List<KeyValuePair<string, string>>();");

                    if (!result_list)
                    {
                        builder.Append("kvs.Add(new KeyValuePair<string, string>(");
                        for (var index = 0; index < fields.Count(); index++)
                        {
                            var field = fields[index];
                            if (modelFields[field].DbType == CodeHelper.Core.Parse.ParseResults.DataViews.DbType.String)
                            {
                                if (result_wraper)
                                {
                                    builder.AppendFormat("ret.Data.{0}", field);
                                }
                                else
                                {
                                    builder.AppendFormat("ret.{0}", field);
                                }
                            }
                            else
                            {
                                if (result_wraper)
                                {
                                    builder.AppendFormat("ret.Data.{0}.ToString()", field);
                                }
                                else
                                {
                                    builder.AppendFormat("ret.{0}.ToString()", field);
                                }
                            }
                            if (index != fields.Count() - 1)
                            {
                                builder.AppendFormat(", ");
                            }
                        }
                        builder.AppendLine("));");
                    }
                    else
                    {
                        if (result_wraper)
                        {
                            builder.Append("kvs.AddRange(ret.Data.Select(o => new KeyValuePair<string, string>(");
                        }
                        else
                        {
                            builder.Append("kvs.AddRange(ret.Select(o => new KeyValuePair<string, string>(");
                        }
                        for (var index = 0; index < fields.Count(); index++)
                        {
                            var field = fields[index];
                            if (modelFields[field].DbType == CodeHelper.Core.Parse.ParseResults.DataViews.DbType.String)
                            {
                                builder.AppendFormat("o.{0}", field);
                            }
                            else
                            {
                                builder.AppendFormat("o.{0}.ToString()", field);
                            }
                            if (index != fields.Count() - 1)
                            {
                                builder.AppendFormat(", ");
                            }
                        }
                        builder.AppendLine(")));");
                    }

                    builder.AppendLine("return kvs.AddDefaultItem();");
                    builder.DecreaseIndentLine("}");
                    builder.AppendFormatLine("catch( Exception ex)");
                    builder.IncreaseIndentLine("{");
                    builder.AppendLine("LogHelper.Error(ex);");
                    builder.AppendLine("return null;");
                    builder.DecreaseIndentLine("}");
                    builder.DecreaseIndentLine("}");
                    builder.AppendLine();
                }

                textEditorControl_Output.Document.TextContent = builder.ToString();// dvDB.Context.Render();
                var frm = new ShowCodeFrm();
                frm.SetText(textEditorControl_Output.Document.TextContent);
                frm.Show();
                textEditorControl_Output.Refresh();
            }
        }