码迷,mamicode.com
首页 > 其他好文 > 详细

原创:甲骨文文字处理助手4.0源码

时间:2014-08-19 18:54:05      阅读:376      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   文件   数据   

本程序主要对记事本进行读写操作。

实现功能如下:

1.添加内容;

2.删除内容;

3.修改内容;

4.查询内容,字符串搜索;

程序截图:

bubuko.com,布布扣

源码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace 甲骨文文字处理助手4._0
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        int flag = 0;
        //编号NO查询实现
        private void button1_Click(object sender, EventArgs e)
        {
            string[] content = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text };
            string[] filelist = File.ReadAllLines("1.txt", Encoding.Default);//获取文件每一行保存到字符串数组中

            string key = textBox1.Text;//key保存所查询内容
            int i = 0;//发现记录数

            //检查查询NO值的长度是否小于2,小于2就提示非法
            if (key.Length < 2)
            {
                MessageBox.Show("查询值非法,所查询NO值不能小于2!");
            }
            else
            {
                for (int linenum = 0; linenum <= filelist.Length - 1; linenum++)//遍历文件查找搜索结果 
                {
                    if (filelist[linenum].IndexOf("NO.=" + key) > -1)
                    {
                        i++;
                        if (i == 1)//只显示查找到记录数的第一组数据
                        {
                            if (linenum == 0)//发现最开始那一条
                            {
                                for (int j = 0; j <= 10; j++)//第一条记录赋值
                                {
                                    content[j] = filelist[j];
                                }
                            }
                            else
                            {
                                for (int m = linenum, j = 0; j <= 10; j++, m++)
                                {
                                    content[j] = filelist[m];
                                }
                            }
                            //查询结果赋值显示
                            textBox2.Text = content[0];
                            textBox3.Text = content[1];
                            textBox4.Text = content[2];
                            textBox5.Text = content[3];
                            textBox6.Text = content[4];
                            textBox7.Text = content[5];
                            textBox8.Text = content[6];
                            textBox9.Text = content[7];
                            textBox10.Text = content[8];
                            textBox11.Text = content[9];
                            textBox12.Text = content[10];
                        }
                        else
                        {
                            MessageBox.Show("查找到两条以上记录,但仅显示了第一条记录!");
                        }
                    }
                }
                if (i == 0)
                {
                    MessageBox.Show("对不起,在1.txt中没有找到该记录!");
                }
                label8.Text = "找到"+Convert.ToString(i) + "条记录";
            }
            //已经添加和未添加记录数计数
            /****************************************************************/
            string[] swall = File.ReadAllLines("1.txt", Encoding.Default);
            int k1 = 0;
            int k2 = 0;
            for (int k = 0; k <= swall.Length - 1; k++)
            {
                if (swall[k].IndexOf("RMK=甲骨文") == -1 && swall[k].IndexOf("RMK=") > -1)
                {
                    k1++;
                }
                else
                    if (swall[k].IndexOf("RMK=甲骨文") > -1)
                    {
                        k2++;
                    }
            }
            label5.Text = k1.ToString() + "";
            label3.Text = k2.ToString() + "";
            /******************************************************************/
        }

        //甲骨文ID查询实现
        private void button2_Click(object sender, EventArgs e)
        {
            string[] content = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text };
            string[] filelist = File.ReadAllLines("1.txt", Encoding.Default);//获取文件每一行保存到字符串数组中

            string key = textBox13.Text;//key保存所查询内容
            int i = 0;//发现记录数

            //检查查询NO值的长度是否小于2,小于2就提示非法
            if (key.Length < 2)
            {
                MessageBox.Show("查询值非法,所查询甲骨文ID不能小于2!");
            }
            else
            {
                for (int linenum = 0; linenum <= filelist.Length - 1; linenum++)//遍历文件查找搜索结果 
                {
                    if (filelist[linenum].IndexOf("id=" + key) > -1)
                    {
                        i++;
                        if (i == 1)//只显示查找到记录数的第一组数据
                        {
                            if (linenum == 10)//发现最开始那一条
                            {
                                for (int n = linenum - 10, j = 0; j <= 10; j++, n++)//第一条记录赋值
                                {
                                    content[j] = filelist[n];
                                }
                            }
                            else
                            {
                                for (int n = linenum - 10, j = 0; j <= 10; j++, n++)
                                {
                                    content[j] = filelist[n];
                                }
                            }
                            //查询结果赋值显示
                            textBox2.Text = content[0];
                            textBox3.Text = content[1];
                            textBox4.Text = content[2];
                            textBox5.Text = content[3];
                            textBox6.Text = content[4];
                            textBox7.Text = content[5];
                            textBox8.Text = content[6];
                            textBox9.Text = content[7];
                            textBox10.Text = content[8];
                            textBox11.Text = content[9];
                            textBox12.Text = content[10];
                        }
                        else
                        {
                            MessageBox.Show("查找到两条记录,但仅显示了第一条记录!");
                        }
                    }
                }
                if (i == 0)
                {
                    MessageBox.Show("对不起,在1.txt中没有找到该记录!");
                }
                label8.Text ="找到"+Convert.ToString(i) + "条记录";
            }
        }

        //添加实现
        private void button3_Click(object sender, EventArgs e)
        {
            //添加辅助
            string[] strs = { "NO.=", "W_C=", "G_C=", "S_C=", "E_C=", "W_E=", "G_E=", "S_E=", "E_E=", "DEF=", "RMK=" };//11条记录
            textBox2.Text = strs[0];
            textBox3.Text = strs[1];
            textBox4.Text = strs[2];
            textBox5.Text = strs[3];
            textBox6.Text = strs[4];
            textBox7.Text = strs[5];
            textBox8.Text = strs[6];
            textBox9.Text = strs[7];
            textBox10.Text = strs[8];
            textBox11.Text = strs[9];
            textBox12.Text = strs[10];
        }

        //确认添加
        private void button10_Click(object sender, EventArgs e)
        {
            string path = "1.txt";
            //判断是否末尾为空
            int mark = 0;
            string[] filelist = File.ReadAllLines(path, Encoding.Default);//程序根目录下打开一个txt文件,并读取每一行
                //检查添加记录是否重复
                for (int linenum = 0; linenum <= linenum - 1; linenum++)
                {
                    if (filelist[linenum]==textBox2.Text.ToString())
                    {
                        mark++;
                    }
                }
                if (mark != 0)
                {
                    MessageBox.Show("1.txt中已经有该NO编号,不能重复添加!");

                }
                else
                {
                    if (filelist[filelist.Length - 1].IndexOf("RMK=") > -1)
                    {
                        File.AppendAllText(path, "\r\n", Encoding.Default);//将字符串追加到文本末
                        File.AppendAllText(path, "\r\n", Encoding.Default);//将字符串追加到文本末
                        //文本追加

                        File.AppendAllText(path, textBox2.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox3.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox4.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox5.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox6.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox7.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox8.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox9.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox10.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox11.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                        File.AppendAllText(path, textBox12.Text, Encoding.Default);//将字符串追加到文本末尾

                        MessageBox.Show("添加成功!");
                    }
                    else
                        if (filelist[filelist.Length - 1].IndexOf(" ") > -1)
                        {
                            File.AppendAllText(path, "\r\n", Encoding.Default);//将字符串追加到文本末
                            //文本追加
                            File.AppendAllText(path, textBox2.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox3.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox4.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox5.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox6.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox7.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox8.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox9.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox10.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox11.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox12.Text , Encoding.Default);//将字符串追加到文本末尾

                            MessageBox.Show("添加成功!");
                        }
                        else
                        {
                            //文本追加
                            File.AppendAllText(path, textBox2.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox3.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox4.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox5.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox6.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox7.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox8.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox9.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox10.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox11.Text + "\r\n", Encoding.Default);//将字符串追加到文本末尾
                            File.AppendAllText(path, textBox12.Text, Encoding.Default);//将字符串追加到文本末尾

                            MessageBox.Show("添加成功!");
                        }
                }
                //已经添加和未添加记录数计数
                /****************************************************************/
                string[] swall = File.ReadAllLines("1.txt", Encoding.Default);
                int k1 = 0;
                int k2 = 0;
                for (int k = 0; k <= swall.Length - 1; k++)
                {
                    if (swall[k].IndexOf("RMK=甲骨文") == -1 && swall[k].IndexOf("RMK=") > -1)
                    {
                        k1++;
                    }
                    else
                        if (swall[k].IndexOf("RMK=甲骨文") > -1)
                        {
                            k2++;
                        }
                }
                label5.Text = k1.ToString() + "";
                label3.Text = k2.ToString() + "";
            /******************************************************************/

        }

        //重置实现
        private void button9_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";//查询NO输入框清空

            //信息清空
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            textBox8.Text = "";
            textBox9.Text = "";
            textBox10.Text = "";
            textBox11.Text = "";
            textBox12.Text = "";

            //甲骨文ID清空
            textBox13.Text = "";

            //文字标签清空
            label3.Text = "-";//已经添加甲骨文信息数
            label5.Text = "-";//未添加甲骨文信息数
            label8.Text = "-";//查询信息数

        }

        //修改实现
        private void button5_Click(object sender, EventArgs e)
        {
            //修改辅助
            string[] content = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text };

            //读一遍文件查找需要修改内容
            string[] filelist = File.ReadAllLines("1.txt", Encoding.Default);//读取文本所有行并保存到字符串数组中     
            int answer =0;//保存查找的那一行数
            for (int linenum = 0; linenum <= filelist.Length - 1; linenum++)//循环读取并打印文件每一行内容
            {
                if (filelist[linenum].IndexOf(textBox2.Text) > -1)//获取"NO."所在的行
                {
                    answer = linenum+1;
                }
            }

            //边读边写进行修改
            FileStream fsr = new FileStream("1.txt", FileMode.Open);//文件读流
            FileStream fsw = new FileStream("2.txt", FileMode.Create, FileAccess.Write);//文件写流
            StreamReader sr = new StreamReader(fsr, Encoding.Default);//读流
            StreamWriter sw = new StreamWriter(fsw, Encoding.Default);//写流
            int j = 0;
            string line;
            fsw.SetLength(0);
            for (int i = 0; i <= filelist.Length - 2; )
            {
                if (i == 0 && answer == 1)//找到修改值而且是第一条记录
                {
                    for (j = 0; j <= 10; j++)
                    {
                        sr.ReadLine();
                        sw.Write(content[j] + "\r\n");
                        i++;
                    }
                }
                else
                    if (i == answer-1)
                    {
                        for (j = 0; j <= 10; j++)
                        {
                            sr.ReadLine();
                            sw.Write(content[j] + "\r\n");
                            i++;
                        }
                    }
                    else 
                    {
                        line = sr.ReadLine();
                        sw.WriteLine(line);
                        i++;
                    }
            }
            sw.Close();
            sr.Close();
            fsw.Close();
            fsr.Close();
            if (File.Exists("2.txt"))
            {
                File.Delete("1.txt");
            }
            File.Move("2.txt", "1.txt");
            //已经添加和未添加记录数计数
            /****************************************************************/
            string[] swall = File.ReadAllLines("1.txt", Encoding.Default);
            int k1 = 0;
            int k2 = 0;
            for (int k = 0; k <= swall.Length - 1; k++)
            {
                if (swall[k].IndexOf("RMK=甲骨文") == -1 && swall[k].IndexOf("RMK=") > -1)
                {
                    k1++;
                }
                else
                    if (swall[k].IndexOf("RMK=甲骨文") > -1)
                    {
                        k2++;
                    }
            }
            label5.Text = k1.ToString() + "";
            label3.Text = k2.ToString() + "";
            /******************************************************************/

            MessageBox.Show("修改成功!");
        }

        //删除实现
        private void button4_Click(object sender, EventArgs e)
        {
            //删除辅助
            string[] content = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text };

            //读一遍文件查找需要删除内容
            string[] filelist = File.ReadAllLines("1.txt", Encoding.Default);//读取文本所有行并保存到字符串数组中     
            int answer = 0;//保存查找的那一行数
            for (int linenum = 0; linenum <= filelist.Length - 1; linenum++)//循环读取并打印文件每一行内容
            {
                if (filelist[linenum].IndexOf(textBox2.Text) > -1)//获取"NO."所在的行
                {
                    answer = linenum + 1;
                }
            }

            //边读边写进行删除
            FileStream fsr = new FileStream("1.txt", FileMode.Open);//文件读流
            FileStream fsw = new FileStream("2.txt", FileMode.Create, FileAccess.Write);//文件写流
            StreamReader sr = new StreamReader(fsr, Encoding.Default);//读流
            StreamWriter sw = new StreamWriter(fsw, Encoding.Default);//写流
            int j = 0;
            string line;
            fsw.SetLength(0);
            for (int i = 0; i <= filelist.Length - 1; )
            {
                if (i == 0 && answer == 1)//找到修改值而且是第一条记录
                {
                    for (j = 0; j <= 10; j++)
                    {
                        sr.ReadLine();
                        i++;
                    }
                    sr.ReadLine();
                    i++;
                }
                else
                    if (i == answer - 1)
                    {
                        for (j = 0; j <= 10; j++)
                        {
                            sr.ReadLine();
                            i++;
                        }
                        sr.ReadLine();
                    }
                    else
                    {
                        line = sr.ReadLine();
                        sw.WriteLine(line);
                        i++;
                    }
            }
            sw.Close();
            sr.Close();
            fsw.Close();
            fsr.Close();
            if (File.Exists("2.txt"))
            {
                File.Delete("1.txt");
            }
            File.Move("2.txt", "1.txt");

            textBox1.Text = "";//查询NO输入框清空

            //信息清空
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            textBox8.Text = "";
            textBox9.Text = "";
            textBox10.Text = "";
            textBox11.Text = "";
            textBox12.Text = "";

            //甲骨文ID清空
            textBox13.Text = "";

            //文字标签清空
            label3.Text = "-";//已经添加甲骨文信息数
            label5.Text = "-";//未添加甲骨文信息数
            label8.Text = "-";//查询信息数     

            //已经添加和未添加记录数计数
            /****************************************************************/
            string[] swall = File.ReadAllLines("1.txt", Encoding.Default);
            int k1 = 0;
            int k2 = 0;
            for (int k = 0; k <= swall.Length - 1; k++)
            {
                if (swall[k].IndexOf("RMK=甲骨文") == -1 && swall[k].IndexOf("RMK=") > -1)
                {
                    k1++;
                }
                else
                    if (swall[k].IndexOf("RMK=甲骨文") > -1)
                    {
                        k2++;
                    }
            }
            label5.Text = k1.ToString() + "";
            label3.Text = k2.ToString() + "";
            /******************************************************************/
            MessageBox.Show("删除成功!");
        }

        //首记录
        private void button6_Click(object sender, EventArgs e)
        {
            string[] content = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text };
            string[] filelist = File.ReadAllLines("1.txt", Encoding.Default);//获取文件每一行保存到字符串数组中
            for (int i = 0; i <= 10; i++) 
            {
                content[i] = filelist[i];
            }
            textBox2.Text = content[0];
            textBox3.Text = content[1];
            textBox4.Text = content[2];
            textBox5.Text = content[3];
            textBox6.Text = content[4];
            textBox7.Text = content[5];
            textBox8.Text = content[6];
            textBox9.Text = content[7];
            textBox10.Text = content[8];
            textBox11.Text = content[9];
            textBox12.Text = content[10];

            //已经添加和未添加记录数计数
            /****************************************************************/
            string[] swall = File.ReadAllLines("1.txt", Encoding.Default);
            int k1 = 0;
            int k2 = 0;
            for (int k = 0; k <= swall.Length - 1; k++)
            {
                if (swall[k].IndexOf("RMK=甲骨文") == -1 && swall[k].IndexOf("RMK=") > -1)
                {
                    k1++;
                }
                else
                    if (swall[k].IndexOf("RMK=甲骨文") > -1)
                    {
                        k2++;
                    }
            }
            label5.Text = k1.ToString() + "";
            label3.Text = k2.ToString() + "";
            /******************************************************************/
        }

        //显示下一条记录
        private void button8_Click(object sender, EventArgs e)
        {
            int i=0;
            string[] content = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text };
            string[] filelist = File.ReadAllLines("1.txt", Encoding.Default);//获取文件每一行保存到字符串数组中
            for (int linenum = 0; linenum <= filelist.Length - 1; linenum++) 
            {
                if ((filelist[linenum].IndexOf(content[0]) > -1))
                {
                    for (flag = linenum + 12, i = 0; i <= 10; flag++, i++)
                    {
                        if (flag <filelist.Length)
                        {
                            content[i] = filelist[flag];
                        }     
                        else 
                        {
                            textBox2.Text = "";
                            textBox3.Text = "";
                            textBox4.Text = "";
                            textBox5.Text = "";
                            textBox6.Text = "";
                            textBox7.Text = "";
                            textBox8.Text = "";
                            textBox9.Text = "";
                            textBox10.Text = "";
                            textBox11.Text = "";
                            textBox12.Text ="";
                            MessageBox.Show("已经到文件末尾,没有下条记录!");
                            break;
                        }
                    }
                    textBox2.Text = content[0];
                    textBox3.Text = content[1];
                    textBox4.Text = content[2];
                    textBox5.Text = content[3];
                    textBox6.Text = content[4];
                    textBox7.Text = content[5];
                    textBox8.Text = content[6];
                    textBox9.Text = content[7];
                    textBox10.Text = content[8];
                    textBox11.Text = content[9];
                    textBox12.Text = content[10];
                    break;
                }
            }
            //已经添加和未添加记录数计数
            /****************************************************************/
            string[] swall = File.ReadAllLines("1.txt", Encoding.Default);
            int k1 = 0;
            int k2 = 0;
            for (int k = 0; k <= swall.Length - 1; k++)
            {
                if (swall[k].IndexOf("RMK=甲骨文") == -1 && swall[k].IndexOf("RMK=") > -1)
                {
                    k1++;
                }
                else
                    if (swall[k].IndexOf("RMK=甲骨文") > -1)
                    {
                        k2++;
                    }
            }
            label5.Text = k1.ToString() + "";
            label3.Text = k2.ToString() + "";
            /******************************************************************/

        }

        //上条记录
        private void button7_Click(object sender, EventArgs e)
        {
            int i = 0;
            string[] content = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text };
            string[] filelist = File.ReadAllLines("1.txt", Encoding.Default);//获取文件每一行保存到字符串数组中
            for (int linenum = 0; linenum <= filelist.Length - 1; linenum++)
            {
                if ((filelist[linenum].IndexOf(content[0]) > -1))
                {
                    for (flag = linenum -12, i = 0; i <= 10; flag++, i++)
                    {
                        if (flag>-10)
                        {
                            content[i] = filelist[flag];
                        }
                        else
                        {
                            textBox2.Text = "";
                            textBox3.Text = "";
                            textBox4.Text = "";
                            textBox5.Text = "";
                            textBox6.Text = "";
                            textBox7.Text = "";
                            textBox8.Text = "";
                            textBox9.Text = "";
                            textBox10.Text = "";
                            textBox11.Text = "";
                            textBox12.Text = "";
                            MessageBox.Show("已经到文件开头,没有上条记录!");
                            break;
                        }
                    }
                    textBox2.Text = content[0];
                    textBox3.Text = content[1];
                    textBox4.Text = content[2];
                    textBox5.Text = content[3];
                    textBox6.Text = content[4];
                    textBox7.Text = content[5];
                    textBox8.Text = content[6];
                    textBox9.Text = content[7];
                    textBox10.Text = content[8];
                    textBox11.Text = content[9];
                    textBox12.Text = content[10];
                    break;

                }
            }
            //已经添加和未添加记录数计数
            /****************************************************************/
            string[] swall = File.ReadAllLines("1.txt", Encoding.Default);
            int k1 = 0;
            int k2 = 0;
            for (int k = 0; k <= swall.Length - 1; k++) 
            {
                if (swall[k].IndexOf("RMK=甲骨文") == -1 && swall[k].IndexOf("RMK=") > -1)
                {
                    k1++;
                }
                else 
                    if (swall[k].IndexOf("RMK=甲骨文") > -1) 
                    {
                        k2++;
                    }   
            }
            label5.Text =k1.ToString()+"";
            label3.Text = k2.ToString() + "";
            /******************************************************************/
        }

        //未修改
        private void button11_Click(object sender, EventArgs e)
        {
            string[] content = { textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text, textBox11.Text, textBox12.Text };
            string[] filelist = File.ReadAllLines("1.txt", Encoding.Default);//获取文件每一行保存到字符串数组中
            int i=0;
            int mark = 0;
            for (int linenum = 0; linenum <= filelist.Length - 1; linenum++)
            {
                if (filelist[linenum].IndexOf("RMK=甲骨文") == -1 && filelist[linenum].IndexOf("RMK=") > -1)
                {
                    for (flag = linenum - 10, i = 0; i <= 10; flag++, i++)
                    {
                        content[i] = filelist[flag];
                    }
                    textBox2.Text = content[0];
                    textBox3.Text = content[1];
                    textBox4.Text = content[2];
                    textBox5.Text = content[3];
                    textBox6.Text = content[4];
                    textBox7.Text = content[5];
                    textBox8.Text = content[6];
                    textBox9.Text = content[7];
                    textBox10.Text = content[8];
                    textBox11.Text = content[9];
                    textBox12.Text = content[10];
                    break;
                }
                else 
                {
                    mark++;
                }
            }
            if (mark == filelist.Length)
            {
                MessageBox.Show("恭喜您,全部修改完毕!\n\n1.txt中已经没有未修改的记录!");
            }
            //已经添加和未添加记录数计数
            /****************************************************************/
            string[] swall = File.ReadAllLines("1.txt", Encoding.Default);
            int k1 = 0;
            int k2 = 0;
            for (int k = 0; k <= swall.Length - 1; k++)
            {
                if (swall[k].IndexOf("RMK=甲骨文") == -1 && swall[k].IndexOf("RMK=") > -1)
                {
                    k1++;
                }
                else
                    if (swall[k].IndexOf("RMK=甲骨文") > -1)
                    {
                        k2++;
                    }
            }
            label5.Text = k1.ToString() + "";
            label3.Text = k2.ToString() + "";
            /******************************************************************/
        }

        private void label15_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.cnblogs.com/xingyunblog/"); 
        }
    }
}
    

 

原创:甲骨文文字处理助手4.0源码,布布扣,bubuko.com

原创:甲骨文文字处理助手4.0源码

标签:style   blog   http   color   os   io   文件   数据   

原文地址:http://www.cnblogs.com/xingyunblog/p/3922546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!