Ejemplo n.º 1
0
        private void ERIMenuItem_Click(object sender, EventArgs e)
        {
            DataBaseForm form = new DataBaseForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                if (treeView1.SelectedNode.Level == 0 && logicParametrs.Length > 0)
                {
                    treeView1.Nodes[0].Nodes.Add($"{form.ERIName} ({logicParametrs[0]})");
                    currentElements.ElementsList.Add(new Element(form.ERIName, logicParametrs[0]));
                    currentElements.ElementsList[currentElements.ElementsList.Count - 1].SetLyambdaAndCalculateP(form.lymbda);
                    logicParametrs = logicParametrs.Remove(0, 1);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            String regex = getRegex();

            if (txtSql.Text.Trim().Length == 0)
            {
                lbState.Text = "待处理文本为空!";
                return;
            }

            String top   = "StringBuilder sbSql = new StringBuilder();";
            String start = "sbSql.Append(\" ";
            String end   = " \"); ";

            String        bottom  = "";// "return sbSql.toString();";
            StringBuilder builder = new StringBuilder();

            if (!formatType.Equals("Net"))
            {
                top   = "StringBuilder sbSql = new StringBuilder();";
                start = "sbSql.append(\" ";
            }
            String[] lines = txtSql.Lines;
            String   str   = txtSql.Text;

            if (formatType.Equals("Net"))
            {
                str = str.Replace(":", "@");
            }
            else
            {
                str = str.Replace("@", ":");
            }


            builder.AppendLine(top);
            MatchCollection matches = Regex.Matches(str, regex);

            foreach (String line in lines)
            {
                if (line.Trim().Length == 0)
                {
                    continue;
                }
                String lineTemp = line.TrimEnd();
                if (formatType.Equals("Net"))
                {
                    lineTemp = lineTemp.Replace(":", "@");
                }
                else
                {
                    lineTemp = lineTemp.Replace("@", ":");
                }

                builder.AppendLine(start + lineTemp + end);
            }
            builder.AppendLine(bottom);

            if (raMyBatis.Checked)
            {
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        String para           = match.Value.Trim();
                        String paraForMyBatis = fomartParameterForMyBatis(para);
                        builder.Replace(para, paraForMyBatis);
                    }
                }
                builder.AppendLine("return sbSql.toString();");
            }
            else
            {
                StringBuilder paraBuilder = new StringBuilder();
                if (matches.Count > 0)
                {
                    if (formatType.Equals("Net"))
                    {
                        paraBuilder.AppendLine("List<SqlParameter> parametersList = new List<SqlParameter>();");
                    }
                    else
                    {
                        paraBuilder.AppendLine("Map<String, Object> parameters = new HashMap();");
                    }

                    List <String> paras = new List <string>();

                    foreach (Match match in matches)
                    {
                        String para = match.Value.Trim();

                        if (para.Length > 1)
                        {
                            para = para.Substring(1);
                        }
                        if (paras.Contains(para))
                        {
                            continue;
                        }



                        String paraTemp = DataBaseForm.formatPara(para);
                        if (formatType.Equals("Net"))
                        {
                            paraBuilder.AppendLine("parametersList.Add(new SqlParameter(\"@" + para + "\", entity." + paraTemp + "));");
                        }
                        else
                        {
                            paraBuilder.AppendLine("parameters.put(\"" + para + "\", entity.get" + paraTemp + "());");
                        }
                        paras.Add(para);
                    }
                    if (formatType.Equals("Net"))
                    {
                        paraBuilder.AppendLine("SqlParameter[] parameters = parametersList.ToArray();");
                    }
                }
                builder.AppendLine();
                builder.AppendLine(paraBuilder.ToString().Trim());
            }



            //paraBuilder.ToString().Split("")


            txtSql.Text = builder.ToString();

            lbState.Text = "封装成功!";
        }