两个button,三个textBox,一个richTextBox功能要求:在textBox1中输入 100000000
在textBox2中输入 50000
在textBox3中输入 111111按button1则生成以下格式的数据填充至richTextBox1中,
100000001 111111
100000002 111111
100000003 111111
100000004 111111
100000005 111111
100000006 111111
……………………
……………………
……………………
……………………
100049997 111111
100049998 111111
100049999 111111
100050000 111111一共5万条记录,
按button2将richTextBox1中文本保存到硬盘中。还有一个清除richTextBox1文本的按钮。由于我公司使用的业务系统垃圾啊,每张卡的编码都要经写卡器读一次来初始化,靠,那几百万张卡怎么读哦。
用这个方法我可以直接将文本数据导入到SQL中的表内,111111表示金卡,222222表示银卡,以此类推。

解决方案 »

  1.   

    保存成from1.cs,然后打开就可执行了。    public partial class Form1 : Form
        {
            private bool _Cancel = false;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Button button2;
            private System.Windows.Forms.TextBox textBox1;
            private System.Windows.Forms.TextBox textBox2;
            private System.Windows.Forms.TextBox textBox3;
            private System.Windows.Forms.RichTextBox richTextBox1;
            private System.Windows.Forms.Button button3;        public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {        }        private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    this._Cancel = false;
                    long startNumber = long.Parse(textBox1.Text);
                    long generateCount = long.Parse(textBox2.Text) + 1;
                    string value = textBox3.Text;
                    for (long i = 1; i < generateCount; i++)
                    {
                        this.richTextBox1.AppendText((startNumber + i).ToString() + Environment.NewLine);
                        if (this._Cancel) break;
                    }
                }
                catch (Exception e2)
                {
                    MessageBox.Show(e2.Message);
                }
            }        private void button2_Click(object sender, EventArgs e)
            {
                this.richTextBox1.Clear();
            }        private void button3_Click(object sender, EventArgs e)
            {
                this._Cancel = true;
            }        private void InitializeComponent()
            {
                this.button1 = new System.Windows.Forms.Button();
                this.button2 = new System.Windows.Forms.Button();
                this.textBox1 = new System.Windows.Forms.TextBox();
                this.textBox2 = new System.Windows.Forms.TextBox();
                this.textBox3 = new System.Windows.Forms.TextBox();
                this.richTextBox1 = new System.Windows.Forms.RichTextBox();
                this.button3 = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(242, 13);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(93, 23);
                this.button1.TabIndex = 0;
                this.button1.Text = "产生数据";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // button2
                // 
                this.button2.Location = new System.Drawing.Point(242, 52);
                this.button2.Name = "button2";
                this.button2.Size = new System.Drawing.Size(93, 23);
                this.button2.TabIndex = 1;
                this.button2.Text = "清除数据";
                this.button2.UseVisualStyleBackColor = true;
                this.button2.Click += new System.EventHandler(this.button2_Click);
                // 
                // textBox1
                // 
                this.textBox1.Location = new System.Drawing.Point(75, 16);
                this.textBox1.Name = "textBox1";
                this.textBox1.Size = new System.Drawing.Size(100, 21);
                this.textBox1.TabIndex = 2;
                this.textBox1.Text = "100000000 ";
                // 
                // textBox2
                // 
                this.textBox2.Location = new System.Drawing.Point(75, 54);
                this.textBox2.Name = "textBox2";
                this.textBox2.Size = new System.Drawing.Size(100, 21);
                this.textBox2.TabIndex = 3;
                this.textBox2.Text = "50000 ";
                // 
                // textBox3
                // 
                this.textBox3.Location = new System.Drawing.Point(75, 92);
                this.textBox3.Name = "textBox3";
                this.textBox3.Size = new System.Drawing.Size(100, 21);
                this.textBox3.TabIndex = 4;
                this.textBox3.Text = "111111 ";
                // 
                // richTextBox1
                // 
                this.richTextBox1.Location = new System.Drawing.Point(75, 144);
                this.richTextBox1.Name = "richTextBox1";
                this.richTextBox1.Size = new System.Drawing.Size(260, 99);
                this.richTextBox1.TabIndex = 5;
                this.richTextBox1.Text = "";
                // 
                // button3
                // 
                this.button3.Location = new System.Drawing.Point(242, 92);
                this.button3.Name = "button3";
                this.button3.Size = new System.Drawing.Size(93, 23);
                this.button3.TabIndex = 6;
                this.button3.Text = "停止产生数据";
                this.button3.UseVisualStyleBackColor = true;
                this.button3.Click += new System.EventHandler(this.button3_Click);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(397, 273);
                this.Controls.Add(this.button3);
                this.Controls.Add(this.richTextBox1);
                this.Controls.Add(this.textBox3);
                this.Controls.Add(this.textBox2);
                this.Controls.Add(this.textBox1);
                this.Controls.Add(this.button2);
                this.Controls.Add(this.button1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.Load += new System.EventHandler(this.Form1_Load);
                this.ResumeLayout(false);
                this.PerformLayout();        }    }
      

  2.   

    代码中:
    this.richTextBox1.AppendText((startNumber + i).ToString() + Environment.NewLine);
    改为
    this.richTextBox1.AppendText((startNumber + i).ToString() + value + Environment.NewLine);
      

  3.   

    如果觉得等待时间长(在添加数据时可能不能及时显示,你可以循环里加Applicaton.DoEvents();语句
      

  4.   


    我印象里的csdn是解答问题交流的地方,上面的话怎么看怎么像雇佣劳动力。
      

  5.   


    在电子表格生成,必须要用到记事本来处理。
    在记事本里1万条的记录应用查找替换都会死机,所以我才想到用C#的I/O来处理。
      

  6.   

    这种代码不好理解,像这样在代码里面指定  richTextBox的属性不是所见所得,调整它的大小还要在这里改几次才成功。      
                  this.richTextBox1.Location = new System.Drawing.Point(75, 144);
                this.richTextBox1.Name = "richTextBox1";
                this.richTextBox1.Size = new System.Drawing.Size(260, 99);
    能否在form里面添加我要求里面的几个控件,然后写事件的代码,这样的话就比较容易理解,我也比较能领悟。我现在在外面,没有vs2005打开来调试,等明天我回到家或公司才能调试。
      

  7.   


                    long startNumber = long.Parse(textBox1.Text);
                    long generateCount = long.Parse(textBox2.Text);
                    for (long i = 1; i < generateCount+1; i++)
                    {
                        this.richTextBox1.AppendText((startNumber + i).ToString() + textBox3.Text+Environment.NewLine);
                    }
    这种代码效率不高,数据如果超过5万等,通过多线程调用方法操作
    或数据先保为文件,再读取到eichtextbox里
    richTextBox1.LoadFile(fileName, RichTextBoxStreamType.PlainText);richTextBox1.SaveFile( "temp.rtf" );
                    stream = new FileStream("temp.rtf", FileMode.Open, FileAccess.Read);
                    int size = Convert.ToInt32(stream.Length);
                    Byte[] rtf = new Byte[size];
                    stream.Read(rtf, 0, size);                conn = new SqlConnection("");
                    conn.Open();
                    cmd = new SqlCommand("UPDATE TABLE SET A=@A WHERE ID=1", conn);
                    SqlParameter paramRTF = 
                        new SqlParameter("@A",
                        SqlDbType.Image,
                        rtf.Length,
                        ParameterDirection.Input,
                        false,
                        0,0,null,
                        DataRowVersion.Current,
                        rtf);
                    cmd.Parameters.Add(paramRTF);
                    int rowsUpdated = Convert.ToInt32(cmd.ExecuteNonQuery());
                          
      

  8.   

    我记得还有种东西叫 Excel?虽然不是很对题,但至少可以实现。
      

  9.   


    在textBox1中输入 100000000 
    在textBox2中输入 50000 
    在textBox3中输入 111111 是由用户输入的,不能在textBox固定的,因为不单是5万条记录,共有几百万条记录啊,我只是想每次生成5万条记录,存在记事本里,我每次导入SQL库中,如果每一次这样的操作时间很快的话,我就可以改为每次生成10万条甚至30万、50万条记录。
      

  10.   

    在asp.net中实现的你可以修改一下:public static  List<string> lists = new List<string>();
            /// <summary>
            /// 显示生成的数据
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void Button1_Click(object sender, EventArgs e)
            {
                string text1 = this.TextBox1.Text;
                int count = Convert.ToInt32(this.TextBox2.Text);
                string text3 = this.TextBox3.Text;
                int len = 0;
                string context = string.Empty;
                for (int i = 1; i <= count; i++)
                {
                    len = i.ToString().Length;
                    context = text1.Substring(0, text1.Length - len) + i.ToString() + " " + text3;
                    lists.Add(context);
                    Response.Write(context+"<br/>");
                }
            }
            /// <summary>
            /// 保存生成的数据
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void Button2_Click(object sender, EventArgs e)
            {
                if (lists.Count > 0)
                {
                    string path = @"F:\context.txt";
                    StreamWriter writer = new StreamWriter(path);
                    foreach (string context in lists)
                    {
                        writer.WriteLine(context);
                    }
                    writer.Close();
                }
                else
                {
                    Response.Write("没有要写入的数据");
                }
            }
      

  11.   

    第一个bejon给的代码调试产生错误,wuyq11提出的代码的执行效率问题,chen_ya_ping的代码不是完整的。按理说我应该否决我前面“100分给一个人”的话,现在只能这样分:
    bejon  40,其余两个各30.其他发表无营养文字的无资格评头论足,如果你们想学习的,就静静看人家的帖子,别JJWW。至于dylike哥说“可惜你上个帖只给了5分,我却了花了N久打的代码。这次没激情帮了。”,在这里我只能说声对不起,因为我第一次发帖并不知道可以自己设置分数。