namespace ReplaceCode
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.label1 = new System.Windows.Forms.Label();
this.richTextBoxSourceTempalte = new System.Windows.Forms.RichTextBox();
this.label2 = new System.Windows.Forms.Label();
this.richTextBoxResult = new System.Windows.Forms.RichTextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBoxNumber = new System.Windows.Forms.TextBox();
this.buttonE = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.richTextBoxValue = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(25, 270);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 12);
this.label1.TabIndex = 0;
this.label1.Text = "模板:";
//
// richTextBoxSourceTempalte
//
this.richTextBoxSourceTempalte.Location = new System.Drawing.Point(72, 222);
this.richTextBoxSourceTempalte.Name = "richTextBoxSourceTempalte";
this.richTextBoxSourceTempalte.Size = new System.Drawing.Size(245, 96);
this.richTextBoxSourceTempalte.TabIndex = 1;
this.richTextBoxSourceTempalte.Text = " <SearchGridTable>\n <CaptionName>${1}</CaptionName>\n <Visible>false</Visib" +
"le>\n <ListName>${2}</ListName>\n <Enabled>false</Enabled>\n <OrderBy>${in" +
"dex}</OrderBy>\n </SearchGridTable>\n";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(25, 476);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(29, 12);
this.label2.TabIndex = 2;
this.label2.Text = "结果";
//
// richTextBoxResult
//
this.richTextBoxResult.Location = new System.Drawing.Point(72, 424);
this.richTextBoxResult.Name = "richTextBoxResult";
this.richTextBoxResult.Size = new System.Drawing.Size(245, 151);
this.richTextBoxResult.TabIndex = 3;
this.richTextBoxResult.Text = "";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(7, 341);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(59, 12);
this.label3.TabIndex = 4;
this.label3.Text = "开始序号:";
//
// textBoxNumber
//
this.textBoxNumber.Location = new System.Drawing.Point(72, 338);
this.textBoxNumber.Name = "textBoxNumber";
this.textBoxNumber.Size = new System.Drawing.Size(245, 21);
this.textBoxNumber.TabIndex = 5;
this.textBoxNumber.Text = "1";
//
// buttonE
//
this.buttonE.Location = new System.Drawing.Point(242, 378);
this.buttonE.Name = "buttonE";
this.buttonE.Size = new System.Drawing.Size(75, 23);
this.buttonE.TabIndex = 6;
this.buttonE.Text = "执行";
this.buttonE.UseVisualStyleBackColor = true;
this.buttonE.Click += new System.EventHandler(this.buttonE_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(25, 93);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(29, 12);
this.label4.TabIndex = 7;
this.label4.Text = "参数";
//
// richTextBoxValue
//
this.richTextBoxValue.Location = new System.Drawing.Point(72, 13);
this.richTextBoxValue.Name = "richTextBoxValue";
this.richTextBoxValue.Size = new System.Drawing.Size(245, 203);
this.richTextBoxValue.TabIndex = 8;
this.richTextBoxValue.Text = resources.GetString("richTextBoxValue.Text");
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(695, 587);
this.Controls.Add(this.richTextBoxValue);
this.Controls.Add(this.label4);
this.Controls.Add(this.buttonE);
this.Controls.Add(this.textBoxNumber);
this.Controls.Add(this.label3);
this.Controls.Add(this.richTextBoxResult);
this.Controls.Add(this.label2);
this.Controls.Add(this.richTextBoxSourceTempalte);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox richTextBoxSourceTempalte;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.RichTextBox richTextBoxResult;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBoxNumber;
private System.Windows.Forms.Button buttonE;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.RichTextBox richTextBoxValue;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ReplaceCode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonE_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
string Result = string.Empty;
string Template = this.richTextBoxSourceTempalte.Text;
string ItemResult = string.Empty;
int Step =Convert.ToInt32(this.textBoxNumber.Text);
int ItemStep = 1;
foreach (string item in this.richTextBoxValue.Lines)
{
if (!string.IsNullOrWhiteSpace(item.Trim()))
{
if (item.Contains(','))
{
string[] arr = item.Split(',');
ItemResult = Template;
ItemResult = ItemResult.Replace("${index}", Step.ToString());
ItemStep = 1;
foreach (string subitem in arr)
{
ItemResult = ItemResult.Replace("${" + ItemStep.ToString() + "}", subitem);
ItemStep++;
}
Result += ItemResult;
}
else
{
Template = Template.Replace("${index}", Step.ToString());
Result += Template.Replace("${1}", item);
}
}
Step++;
}
this.richTextBoxResult.Text = Result;
}
}
}