由于当做作业任务交上去后老师严重不满意,缺乏数据结构的运用。

故而修改,讲所有数据库的部分全部删除。改成数组、链表以及文件操作。


主要代码如下:

LoginForm:

C#实现_______个人记账程序__修改_C#

核心代码如下:



string currentAccount = " ";
private void btnRegister_Click(object sender, EventArgs e)
{
    RegisterForm rForm = new RegisterForm();
    rForm.lg = this; //将当前窗口传递给注册窗口
    rForm.ShowDialog();
}
/// <summary>
/// 功能:用来接收注册页面传递来的用户,并显示在文本框上
/// 时间:2013/9/15
/// 作者:余颜凯
/// </summary>
/// <param name="name"></param>
public void getUserName(string name)
{
    textName.Text = name;
}
/// <summary>
/// 功能:以登陆的账户名字为账本文件名
/// </summary>
/// <returns></returns>
public string userNameForAccountFile()
{
    return currentAccount;
}
/// <summary>
/// 功能:获得保存的密码(点击了保存账号密码的checkbox)
/// 作者:余颜凯
/// 时间:2013/9/19,2013/10/14
/// </summary>
public void getPassword()
{
    //从文件中读取已注册的用户
    Users users = new Users();
    users.readFile();
    //查找标示位为"1"的数据
    for(int i = 0;i < users.userCount;i++)
    {
        if(users.userList[i].Tag == "1")
        {
            textName.Text = users.userList[i].userName;
            textPassword.Text = users.userList[i].userPassword;
        }
    }
                                                                                                                                                                                                                                                                                                                    
}
/// <summary>
/// 功能:保存用户名和密码到文件
/// 作者:余颜凯
/// 时间:2013/10/14
/// </summary>
public void savePassword()
{
    //从文件中读取已注册的用户
    Users users = new Users();
    users.readFile();
    //查找要保存的数据名
    for (int i = 0; i < users.userCount; i++)
    {
        if (users.userList[i].Tag == "1")
        {
            if (users.userList[i].userName != textName.Text.Trim())
            {
                users.userList[i].Tag = "0";
            }
                                                                                                                                                                                                                                                                                                                            
        }
        else if (users.userList[i].userName == textName.Text.Trim())
        {
            users.userList[i].Tag = "1";
        }
                                                                                                                                                                                                                                                                                                                         
    }
    //还要存盘
    users.saveFile();
}
/// <summary>
/// 不足:没用重用登陆按钮的功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLogin_Click(object sender, EventArgs e)
{
    bool isNotEmpty = CheckEmpty();
    //如果能通过检查,
    if (isNotEmpty == true)
    {
        Users users = new Users();
        users.readFile();
        int count = 0;
        for(int i = 0;i < users.userCount; i++)
        {
            if(users.userList[i].userName == textName.Text.Trim())
            {
                currentAccount = textName.Text.Trim();
                count =1;
                break;
            }
        }
                                                                                                                                                                                                                                                                                                                         
        if (count == 1)
        {
            if (ckbRemember.Checked == true)
            {
               this.savePassword();
            }
            //登陆成功就打开主窗口
            MainForm mForm = new MainForm();
            mForm.Show();
            //只能因此父窗口(LoginForm)
            this.Hide();
         }
                                                                                                                                                                                                                                                                                                                             
        else//数据库中无数据,version2.0:users.txt中无数据
        {
            labelAllError.Visible = true;
        }
    }
}
/// <summary>
/// 功能:检查登陆时数据的合法性
/// 作者:余颜凯
/// 时间:2013/9/19
/// </summary>
/// <returns></returns>
private bool CheckEmpty()
{
    //默认为不为空
    bool result = true;
    if (textName.Text.Trim() == String.Empty)
    {
        labelNameError.Visible = true;
        result = false;
    }
    else
    {
        labelNameError.Visible = false;
    }
    if (textPassword.Text.Trim() == String.Empty)
    {
        labelPasswordError.Visible = true;
        result = false;
    }
    else
    {
        labelPasswordError.Visible = false;
    }
    return result;
}
private void LoginForm_Load(object sender, EventArgs e)
{
    getPassword();
}
private void btnQuitSave_Click(object sender, EventArgs e)
{
    //从文件中读取已注册的用户
    Users users = new Users();
    users.readFile();
    //查找要保存的数据名
    for (int i = 0; i < users.userCount; i++)
    {
        if (users.userList[i].userName == textName.Text.Trim())
        {
            users.userList[i].Tag = "0";
        }
    }
    //还要存盘
    users.saveFile();
    this.textName.Text = string.Empty;
    this.textPassword.Text = string.Empty;
}

单条记录FinanceRecord类,如下:

class RecordList
    {
        public FinanceRecord pHead;
        public FinanceRecord Head
        {
            get
            {
                return Head;
            }
        }
        private int intNum;
        public int ListLength
        {
            get
            {
                return intNum;
            }
        }
        public RecordList(FinanceRecord e)
        {
            pHead = null;
            intNum = 0;
            FinanceRecord tempNode, newNode;
            newNode = new FinanceRecord(e.consumeIndex, e.consumeDate, e.consumeType, e.consumeType, e.consumeMoney, e.consumeInformation);
            newNode.NextRecord = null;
            intNum++;
            //无头结点的链表
            if (pHead == null)
            {
                pHead = newNode;
            }
            else
            {
                //从未赋值的tempNode知道,此时它还无.nextRecord属性
                tempNode = pHead;
                while (tempNode.NextRecord != null)
                {
                    tempNode = tempNode.NextRecord;
                }
                tempNode.NextRecord = newNode;
            }
        }
    }

所有记录也单独写一个类,方便进行增删查改。

/// <summary>
   /// 该类用于查询结果用链表保存
   /// </summary>
                                                                                                                                                                                                                                      
    public class FinanceLog
    {
        const long MaxCount = 10240000;
        public FinanceRecord[] recordList = new FinanceRecord[MaxCount];
        //实际记录数量
        int intCount = 0;
        public int recordCount
        {
            get { return intCount; }
        }
        //当前指针,以后方便利用流水号
        int intCurrrent = -1;
        public int selectIndex
        {
            get
            {
                return intCurrrent;
            }
            set
            {
                intCurrrent = value;
            }
        }
        public FinanceLog()
        {
            intCount = 0;
        }
        /// <summary>
        /// 功能:将文件中的每条记录读入内存,同时获取文件中记录的个数
        /// 作者:余颜凯
        /// 时间:2013/10/14
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        public bool readFile(string FileName)
        {
            bool Tag = true;
            string strLine = "";
            string[] recordData;
            FinanceRecord data;
            try
            {
                StreamReader AccountFile = new StreamReader("..\\..\\Properties\\accountBook" + FileName + ".txt", Encoding.GetEncoding("gb2312"));
                while (!AccountFile.EndOfStream)
                {
                    strLine = AccountFile.ReadLine();
                    recordData = strLine.Split(' ');
                    if (strLine != "" &&  recordData!=null)
                    {
                            data = new FinanceRecord(recordData[0].Trim(), recordData[1].Trim(), recordData[2].Trim(), recordData[3].Trim(), recordData[4].Trim(), recordData[5].Trim());
                            recordList[intCount++] = data;
                    }
                }
                                                                                                                                                                                                                                                   
                AccountFile.Close();
            }
            catch
            {
                Tag = false;
            }
            return Tag;
        }
        /// <summary>
        /// 功能:保存内存中的记录到文件
        /// 作者:余颜凯
        /// 时间:2013/10/14
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        public bool saveFile(string FileName)
        {
            bool Tag = true;
            try
            {
                StreamWriter accountFile = new StreamWriter("..\\..\\Properties\\accountBook" + FileName + ".txt", false, Encoding.GetEncoding("gb2312"));
                for (int i = 0; i < intCount; i++)
                {
                    accountFile.WriteLine(recordList[i].consumeIndex.Trim() + " " + recordList[i].consumeDate.Trim() + " " +
                        recordList[i].consumeType.Trim() + " " + recordList[i].consumeCatagory.Trim() + " " + recordList[i].consumeMoney.Trim() + " " + recordList[i].consumeInformation.Trim());
                }
                accountFile.Close();
            }
            catch
            {
                Tag = false;
            }
            return Tag;
        }    
        /// <summary>
        /// 功能:供AddForm添加记录时调用
        /// 作者:余颜凯
        /// 时间:2013/10/14
        /// </summary>
        /// <param name="consumeIndex"></param>
        /// <param name="consumeDate"></param>
        /// <param name="consumeType"></param>
        /// <param name="consumeCatagory"></param>
        /// <param name="consumeMoney"></param>
        /// <param name="consumeInformation"></param>
        /// <returns></returns>
        public bool Add(string consumeIndex,string consumeDate,string consumeType,string consumeCatagory,string consumeMoney,string consumeInformation)
        {
            bool Tag = true;
            FinanceRecord fr = new FinanceRecord(consumeIndex,consumeDate,consumeType,consumeCatagory,consumeMoney,consumeInformation);
            recordList[intCount++] = fr;
            return Tag;
        }
        /// <summary>
        /// 功能:供隐藏面的修改键调用
        /// 作者:余颜凯
        /// 时间:2013/10/14
        /// </summary>
        /// <param name="fr"></param>
        /// <param name="consumeIndex"></param>
        /// <param name="consumeDate"></param>
        /// <param name="consumeType"></param>
        /// <param name="consumeCatagory"></param>
        /// <param name="consumeMoney"></param>
        /// <param name="consumeInformation"></param>
        /// <returns></returns>
        public bool Update(FinanceRecord fr,string consumeIndex, string consumeDate, string consumeType, string consumeCatagory, string consumeMoney, string consumeInformation)
        {
            bool Tag = true;
            for(int i = 0 ;i< intCount ; i++)
            {
                //消费日期,类别,收支项目,金额作为判断标准
                if (recordList[i].consumeDate == fr.consumeDate && recordList[i].consumeType == fr.consumeType
                    && recordList[i].consumeCatagory == fr.consumeCatagory && recordList[i].consumeMoney == fr.consumeMoney)
                {
                    FinanceRecord fr1 = new FinanceRecord(consumeIndex, consumeDate, consumeType, consumeCatagory, consumeMoney, consumeInformation);
                    recordList[i] = fr1;
                    Tag = true;
                    break;
                }
                else
                {
                    Tag = false;
                }
            }
                                                                                                                                                                                                                                               
            return Tag;
        }
        //查找和删除要考虑效率所以使用了 链表
        /// <summary>
        /// 功能:保存查找到的记录
        /// 作者:余颜凯
        /// 时间:2013/10/14
        /// </summary>
                                                                                                                                                                                                                                           
    }



注册:

C#实现_______个人记账程序__修改_C#_02

//用来保存登陆窗口,便于跨窗口传送数据
        public LoginForm lg;     
private void btnRegister_Click(object sender, EventArgs e)
        {
            bool isNotEmpty = CheckEmpty();
                                                                                                                                                                                                                                 
            //如果能通过检查,
            if (isNotEmpty == true)
            {
                if (getResist() == true)
                {
                    MessageBox.Show("用户已经注册,请重新输入用户名!");
                    textName.SelectAll();
                    textName.Focus();
                }
                else
                {
                    //在users.txt末尾添加记录
                    User data = new User(textName.Text.Trim(),textPassword.Text.Trim(),"0");
                    Users u = new Users();
                    //先读一遍文件是为了获取当前总用户的数量
                    u.readFile();
                    if (u.Add(data) == true)
                    {
                        //用户总数量知道后,先用Add()把新注册的用户加入当先用户类型的数组
                        //之后就存盘即可
                        u.saveFile();
                        MessageBox.Show("成功注册了一个用户");
                        lg.getUserName(textName.Text.Trim());
                        //lg.savePassword();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("由于文件原因,注册失败!");
                    }                 
                }
                                                                                                                                                                                                                      
            }
        }
        /// <summary>
        /// 功能:检验是否已经注册
        /// 时间:2013/9/21,2013/10/14
        /// 作者:余颜凯
        /// </summary>
        /// <returns></returns>
        public bool getResist()
        {
            bool isRegist = false;
            Users users = new Users();
            users.readFile();
            for (int i = 0; i < users.userCount; i++)
            {
                if (users.userList[i].userName == textName.Text.Trim())
                {
                    isRegist = true;
                }
            }
            return isRegist;
        }
                                                                                                                                                                                                                            
        /// <summary>
        /// 功能:判断注册页面文本框是否为空
        /// 时间:2013/9/15
        /// 作者:余颜凯
        /// </summary>
        /// <returns></returns>
        private bool CheckEmpty()
        {
            //默认为不为空
            bool result = true;
            if (textName.Text.Trim() == String.Empty)
            {
                labelNameError.Visible = true;
                result= false;
            }
            else
            {
                labelNameError.Visible = false;
            }
            if (textPassword.Text.Trim() == String.Empty)
            {
                labelPasswordError.Visible = true;
                result= false;
            }
            else
            {
                labelPasswordError.Visible = false;
            }
            if (textConfirmPassword.Text.Trim() == String.Empty)
            {
                labelConfirmError.Visible = true;
                result= false;
            }
            else
            {
                //验证密码不为空,但是又不相同
                if (textPassword.Text.Trim() != textConfirmPassword.Text.Trim())
                {
                    //MessageBox.Show("两次输入的密码不一致");
                    labelConfirmError.Text = "     两次密码不同";
                    labelConfirmError.Visible = true;
                    result = false;
                }
                else
                {
                   //labelConfirmError.Text = "     密码不能为空";
                    labelConfirmError.Visible = false;
                                                                                                                                                                                                                                       
                }
            }
            return result;
        }



管理注册用户,以及进行登录验证:单独写一个Users类

public class User
   {
                                                                                                                                                                                               
       public string userName;
       public string userPassword;
       public string Tag = "0";
       public User(string userName,string userPassword,string Tag)
       {
           this.userName = userName;
           this.userPassword = userPassword;
           this.Tag = Tag;
       }
   }
                                                                                                                                                                                           
   public class Users
   {
       //最多读取1024条数据,最多1024个用户
       const int MaxCount = 1024;
       public User[] userList = new User[MaxCount];
                                                                                                                                                                                               
       //用户数量
       int intCount = 0;
       public int userCount
       {
           get
           {
               return intCount;
           }
       }
       public Users()
       {
           intCount = 0;
       }
                                                                                                                                                                                               
       public bool readFile()
       {
           bool Tag = true;
           string strLine = "";
           string[] lstData;
           User userData;
           try
           {
               StreamReader userFile = new StreamReader("..\\..\\Properties\\users.txt", Encoding.Default);
               while (!userFile.EndOfStream)
               {
                   strLine = userFile.ReadLine();
                   lstData = strLine.Split(' ');
                   if (lstData.Length == 3)
                   {
                       userData = new User(lstData[0], lstData[1], lstData[2]);
                       userList[intCount++] = userData;
                   }
                }
               userFile.Close();
           }
           catch
           {
               Tag = false;
           }
           return Tag;
       }
       //注册用户添加记录
       public bool Add(User data)
       {
           bool Tag = true;
           //用户名作为唯一标示
           for (int i = 0; i < intCount; i++)
           {
               if (userList[i].userName == data.userName)
               {
                   Tag = false;
                   break;
               }
               if (Tag)
               {
                   userList[intCount] = data;
               }
           }
           intCount++;
           return Tag;
       }
       public bool saveFile()
       {
           bool Tag = true;
           try
           {
               StreamWriter userFile = new StreamWriter("..\\..\\Properties\\users.txt");
               for (int i = 0; i < intCount; i++)
               {
                   userFile.WriteLine(userList[i].userName + " " + userList[i].userPassword
                       + " " + userList[i].Tag.Trim());
               }
               userFile.Close();
           }
           catch
           {
               Tag = false;
           }
           return Tag;
       }     
   }



主界面上的增删查改:

删除:

if (dataViewControl.SelectedRows.Count != 0)
{
    //先把数据读入链表:
    //多次debug,能读入链表
    string strLine = "";
    FinanceRecord pHead = null,tempNode, newNode;;
    int intNum = 0;//记录数
    string[] recordData;
    FinanceRecord data;
    try
    {
        StreamReader AccountFile = new StreamReader("..\\..\\Properties\\accountBook" + "\\aa" + ".txt", Encoding.GetEncoding("gb2312"));
        while (!AccountFile.EndOfStream)
        {
            strLine = AccountFile.ReadLine();
            recordData = strLine.Split(' ');
            if (strLine != "" && recordData != null)
            {
                data = new FinanceRecord(recordData[0].Trim(), recordData[1].Trim(), recordData[2].Trim(), recordData[3].Trim(), recordData[4].Trim(), recordData[5].Trim());
                newNode = new FinanceRecord(data.consumeIndex, data.consumeDate,data.consumeType,
                    data.consumeCatagory, data.consumeMoney, data.consumeInformation);
                newNode.NextRecord = null;
                intNum++;
                //无头结点的链表
                if (pHead == null)
                {
                    pHead = newNode;
                }
                else
                {
                    //从未赋值的tempNode知道,此时它还无.nextRecord属性
                    tempNode = pHead;
                    while (tempNode.NextRecord != null)
                    {
                        tempNode = tempNode.NextRecord;
                    }
                    tempNode.NextRecord = newNode;
                }
                                                                                                                                                                                         
            }
        }
        AccountFile.Close();
    }
    catch
    {
        MessageBox.Show("Something Wrong Happens", "温馨提示");
    }
    //上面已经完成了读入工作,intNum是数据的总量,pHead头结点(不是头指针)
    //temp保存上一节点,lst不停往下寻找
    bool tag = false;//用来标记删除是否成功
    FinanceRecord lst,temp=null;
    lst = pHead;
    while (lst!= null)
    {
        //下面这条语是为了调试过程中测试是否读取了全部得数据
        //MessageBox.Show(lst.consumeDate);
        //下面这个算法并不适合删除头结点,所以必须先处理头结点!
        bool b0 = (dataViewControl.SelectedRows[0].Cells[1].Value.ToString().Trim().Equals(pHead.consumeDate.ToString()))
            && (dataViewControl.SelectedRows[0].Cells[2].Value.ToString().Trim().Equals(pHead.consumeType.ToString()))
            && (dataViewControl.SelectedRows[0].Cells[3].Value.ToString().Trim().Equals(pHead.consumeCatagory.ToString()))
            && (dataViewControl.SelectedRows[0].Cells[4].Value.ToString().Trim().Equals(pHead.consumeMoney.ToString()));
        if (b0)
        {
            lst = pHead.NextRecord;
            pHead = lst;
            tag = true;
            break;
        }
        //找到就在链表里先进行删除,没找到就继续找
        bool b1 = (dataViewControl.SelectedRows[0].Cells[1].Value.ToString().Trim().Equals(lst.consumeDate.ToString()))
            && (dataViewControl.SelectedRows[0].Cells[2].Value.ToString().Trim().Equals(lst.consumeType.ToString()))
            && (dataViewControl.SelectedRows[0].Cells[3].Value.ToString().Trim().Equals(lst.consumeCatagory.ToString()))
            && (dataViewControl.SelectedRows[0].Cells[4].Value.ToString().Trim().Equals(lst.consumeMoney.ToString()));
        if (b1)
        {
            temp.NextRecord = temp.NextRecord.NextRecord;
            tag = true;
            break;
        }
        temp = lst;
        lst = lst.NextRecord;
    }
    //用来检验删除操作后,整个链表是否正常,用头结点判断就好了
    //MessageBox.Show(pHead.consumeDate);
    //之后进行简单的遍历方式写入文件就好
    FinanceRecord round=pHead;
    try
    {
        StreamWriter accountFile1 = new StreamWriter("..\\..\\Properties\\accountBook" + "\\aa" + ".txt", false, Encoding.GetEncoding("gb2312"));
        for (int i = 0; i < intNum-1; i++)
        {
            accountFile1.WriteLine(round.consumeIndex.Trim() + " " + round.consumeDate.Trim() + " " +
                round.consumeType.Trim() + " " + round.consumeCatagory.Trim() + " " + round.consumeMoney.Trim() + " " + round.consumeInformation.Trim());
            round = round.NextRecord;
        }
        accountFile1.Close();
    }
    catch
    {
        MessageBox.Show("Something Wrong Happens","温馨提示");
    }
    //在进行删除操作:
                                                                                                                                                                            
        if (tag == true)
        {
            MessageBox.Show("删除成功");
            //但是dataGridView并没有刷新显示
            showTotalMoney();
            GetGridviewAll();
        }
        else
        {
            MessageBox.Show("删除失败");
        }
}


主界面上的其他功能:修改(更新),添加(插入),查询:

C#实现_______个人记账程序__修改_C#_03

    private void MainForm_Load(object sender, EventArgs e)
    {
        // TODO: 这行代码将数据加载到表“financeProjectDataSet.Consume”中,可以根据需要移动或删除它。
        //this.consumeTableAdapter.Fill(this.financeProjectDataSet.Consume);
        GetGridviewAll();
        comboBoxSort.SelectedIndex = 0;
        comboBoxDir.SelectedIndex = 0;
        //取消默认选中第一行
        dataViewControl.ClearSelection();
        //隐藏面板的
        //开始的时候让底部面板隐藏
        panelEdit.Visible = false;
        this.btnHide.Location = new Point(this.btnHide.Location.X, this.btnHide.Location.Y - 134);
        this.Size = new Size(this.Width, 533);
        comboBoxLei.SelectedIndex = 0;
        comboBoxItem.SelectedIndex = 0;
        //加载消费条目时间
        for (int i = 1992; i < 2092; i++)
        {
            comboBoxDateYear.Items.Add(i.ToString());
        }
        for (int i = 1; i <= 12; i++)
        {
            comboBoxDateMonth.Items.Add(i.ToString());
        }
        comboBoxDateYear.SelectedIndex = 0;
        comboBoxDateMonth.SelectedIndex = 0;
        //comboBoxDate.Items.Add("1");
        //comboBoxDateMonth.SelectedIndex = 0;
        //for (int i = 1; i <= 31; i++)
        //{
        //    comboBoxDate.Items.Add(i.ToString());
        //}
        showTotalMoney();
        btnDelete.Enabled = false;
    }
    /// <summary>
    /// 功能:显示当前的时间
    /// 时间:2013/9/16
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void timeDate_Tick(object sender, EventArgs e)
    {
        DateTime dt = DateTime.Now;
        String date = dt.ToLongDateString();
        String time = dt.ToLongTimeString();
        labelTime.Text = date + time;
    }
    /// <summary>
    /// 功能:隐藏或者显示底部编辑框架
    /// 时间:2013/9/20
    /// 作者:余颜凯
    /// 补充:后来又将此函数的功能单独写成一个函数了
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnHide_Click(object sender, EventArgs e)
    {
        //667 
        //134
        //if (this.Size.Height == 667)//之前是展开的窗口,点该按钮后变成收起状态
        //{
        //    this.Size = new Size(this.Width, 533);
        //    panelEdit.Visible = false;
        //    this.btnHide.Location = new Point(this.btnHide.Location.X, this.btnHide.Location.Y - 134);
        //    this.btnHide.Text = "详细信息";
        //}
        //else
        //{
        //    this.Size = new Size(this.Width, 667);
        //    panelEdit.Visible = true;
        //    this.btnHide.Text =  "收起信息";
        //    this.btnHide.Location = new Point(this.btnHide.Location.X, this.btnHide.Location.Y + 134);
        //}
        //上面代码已经被浓缩成函数(方便重用)
        //默认的时候是隐藏的,即该按钮的文字是"详细信息"
        if (btnHide.Text == "详细信息")
        {
            hidePanel(false);
        }
        else
            hidePanel(true);
    }
    /// <summary>
    /// 功能:隐藏窗口
    /// 时间:2013/9/21
    /// 作者:余颜凯
    /// </summary>
    private bool hidePanel(bool hide)
    {
        //传入的hide如果为true表明是要隐藏现在这个窗口
        if (hide == true)
        {
            this.Size = new Size(this.Width, 533);
            panelEdit.Visible = false;
            this.btnHide.Location = new Point(this.btnHide.Location.X, this.btnHide.Location.Y - 134);
            this.btnHide.Text = "详细信息";
            panelEdit.Enabled = false;
        }
        else
        {
            this.Size = new Size(this.Width, 667);
            panelEdit.Visible = true;
            this.btnHide.Text = "收起信息";
            this.btnHide.Location = new Point(this.btnHide.Location.X, this.btnHide.Location.Y + 134);
            return false;
        }
        return true;
    }
    /// <summary>
    /// 功能:低端下拉窗口的修改
    /// 时间:2013/9/20
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnEdit_Click(object sender, EventArgs e)
    {
        string date = comboBoxDateYear.Text.Trim() + "/" + comboBoxDateMonth.Text.Trim() + "/" + comboBoxDate.Text.Trim();
        FinanceLog log = new FinanceLog();
        log.readFile("//aa");
        //保存当前选中中项目
        FinanceRecord fr;
        //保存以作判断,便于找到要修改的元素
        fr = new FinanceRecord("0", dataViewControl.SelectedRows[0].Cells[1].Value.ToString().Trim(), dataViewControl.SelectedRows[0].Cells[2].Value.ToString().Trim(),
            dataViewControl.SelectedRows[0].Cells[3].Value.ToString().Trim(), dataViewControl.SelectedRows[0].Cells[4].Value.ToString().Trim(),
            dataViewControl.SelectedRows[0].Cells[5].Value.ToString().Trim());
        //更新该元素
        bool bl = log.Update(fr, "0", date.Trim(), comboBoxLei.Text.Trim(), comboBoxItem.Text.Trim(), textBoxJin.Text.Trim(), textBoxDescription.Text.Trim());
        if (bl == true)
        {
            log.saveFile("//aa");
            MessageBox.Show("更新成功", "温馨提示");
            //但是dataGridView并没有刷新显示
            GetGridviewAll();
            showTotalMoney();
            //取消选中,是为了方便下一次修改
            dataViewControl.ClearSelection();
            hidePanel(true);
        }
        else
        {
            MessageBox.Show("更新失败!(这种情况基本排除,所以不做过多处理)");
        }
    }
    /// <summary>
    /// 功能:在下拉框中显示选中的详细信息
    /// 时间:2013/9/20
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void dataViewControl_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        btnDelete.Enabled = true;
        toolStripButtonDelete.Enabled = true;
        //将隐藏框里的文字和图片换掉
        labelItemSelected.Text = "已选中一条记录";
        //显示图像
        //1.尝试失败
        //pictureBoxItemSelected.BackgroundImage.Dispose();
        pictureBoxItemSelected.SizeMode = PictureBoxSizeMode.StretchImage;
        //pictureBoxItemSelected.BackgroundImage = System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory+"..\\..\\p_w_picpaths\\ItemSelected.png");
        pictureBoxItemSelected.Load(AppDomain.CurrentDomain.BaseDirectory + "..\\..\\p_w_picpaths\\ItemSelected.png");
        //在隐藏面板中显示选中行的信息
        //流水号
        textBoxLiu.Text = dataViewControl.SelectedRows[0].Cells[0].Value.ToString();
        //日期
        string actDate = dataViewControl.SelectedRows[0].Cells[1].Value.ToString();
        //在dataView中显示的是1999/9/9 (获取的格式也是这样)
        //分离出 年、月、日
        DateTime dt = Convert.ToDateTime(actDate);
        //对于combox的显示项目,可以用Item.
        comboBoxDateYear.Text = dt.Year.ToString().Trim();
        comboBoxDateMonth.Text = dt.Month.ToString().Trim();
        comboBoxDate.Text = dt.Day.ToString().Trim();
        //选择收入还是支出
        if ("收入" == dataViewControl.SelectedRows[0].Cells[2].Value.ToString().Trim())
        {
            comboBoxLei.SelectedIndex = 0;
        }
        else comboBoxLei.SelectedIndex = 1;
        //收支项目,多次测验发现,必须写已有的固定项目,才能正确显现
        comboBoxItem.SelectedItem = dataViewControl.SelectedRows[0].Cells[3].Value.ToString().Trim();
        //金额
        textBoxJin.Text = dataViewControl.SelectedRows[0].Cells[4].Value.ToString().Trim();
        //作为收支项目的补充
        textBoxDescription.Text = dataViewControl.SelectedRows[0].Cells[5].Value.ToString().Trim();
    }
    /// <summary>
    /// 功能:选中收入还是支出的时候给出相应的项目变化
    /// 时间:2012/9/20
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void comboBoxLei_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBoxLei.SelectedIndex == 0)//选中的为收入
        {
            comboBoxItem.Items.Clear();//清空收入
            comboBoxItem.Items.Add("兼职");
            comboBoxItem.Items.Add("银行利息");
            comboBoxItem.Items.Add("基金收益");
            comboBoxItem.Items.Add("奖学金");
            comboBoxItem.Items.Add("其他收入");
        }
        else //如果选中为支出
        {
            comboBoxItem.Items.Clear();
            comboBoxItem.Items.Add("娱乐");
            comboBoxItem.Items.Add("吃饭");
            comboBoxItem.Items.Add("学习");
            comboBoxItem.Items.Add("购物");
        }
        comboBoxItem.SelectedIndex = 0;
    }
    /// <summary>
    /// 功能:获得总的收入和支出
    /// 时间:2013/9/20,2013/10/14
    /// 作者:余颜凯
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    private double getTotalMoney(string type)
    {
        double total = 0;
        double temp;
        FinanceLog log = new FinanceLog();
        log.readFile("\\aa");
        for (int i = 0; i < log.recordCount; i++)
        {
            if (type == "收入" && log.recordList[i].consumeType == "收入")
            {
                temp = System.Convert.ToDouble(log.recordList[i].consumeMoney);
                total += temp;
            }
            if (type == "支出" && log.recordList[i].consumeType == "支出")
            {
                temp = System.Convert.ToDouble(log.recordList[i].consumeMoney);
                total += temp;
            };
        }
        return total;
    }
    /// <summary>
    /// 功能:主界面上总金额显示功能打包,方便其他类重用
    /// 时间:2013/9/21,2013/10/14
    /// 作者:余颜凯
    /// </summary>
    public void showTotalMoney()
    {
        double income = 0, consume = 0;
        consume = getTotalMoney("支出");
        income = getTotalMoney("收入");
        textBoxIn.Text = income.ToString();
        textBoxOut.Text = consume.ToString();
        textBoxAll.Text = (income - consume).ToString();
        if ((income - consume) >= 0)
        {
            textBoxAll.ForeColor = System.Drawing.Color.Lime;
        }
        else
            textBoxAll.ForeColor = System.Drawing.Color.Red;
    }
    /// <summary>
    /// 功能:将刷新dataView的功能封装
    /// 时间:2013/9/21,,2013/10/14
    /// 作者:余颜凯
    /// </summary>
    public void GetGridviewAll()
    {
        FinanceLog log = new FinanceLog();
        //string nn = lg.userNameForAccountFile();
        bool a = log.readFile("\\aa");
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        string[] hh = new string[] { "流水号", "消费日期", "类别", "收支项目", "金额", "备注" };
        DataColumn[] columns = new DataColumn[6];
        DataRow[] rows = new DataRow[log.recordCount];
        for (int i = 0; i < 6; i++)
        {
            columns[i] = new DataColumn(hh[i], typeof(string));
            dt.Columns.Add(columns[i]);
        }
        for (int j = 0; j < log.recordCount; j++)
        {
            rows[j] = dt.NewRow();
            rows[j][0] = log.recordList[j].consumeIndex;
            rows[j][1] = log.recordList[j].consumeDate;
            rows[j][2] = log.recordList[j].consumeType;
            rows[j][3] = log.recordList[j].consumeCatagory;
            rows[j][4] = log.recordList[j].consumeMoney;
            rows[j][5] = log.recordList[j].consumeInformation;
            dt.Rows.Add(rows[j]);
        }
        //this.financeProjectDataSet.Tables.Add(dt);
        ds.Tables.Add(dt);
        dataViewControl.DataSource = ds.Tables[0];
        //取消默认选中第一行
        dataViewControl.ClearSelection();
        //把删除键设为不可用
        btnDelete.Enabled = false;
        toolStripButtonDelete.Enabled = false;
    }
    /// <summary>
    /// 功能:根据类型查询,把查询到的结果放入链表(因为能查询多少个数量未知)
    /// 后来发现用链表实现存在一个问题,所以采用了一个简单处理,和数据库子查询中查到一条添加一条原理一样
    ///
    /// 作者:余颜凯
    /// 时间:2013/10/16
    /// </summary>
    /// <param name="search"></param>
    public void SearchData(string search)
    {
        //思想 改变dataViewControl的DataSource即可
        FinanceLog log = new FinanceLog();
        //string nn = lg.userNameForAccountFile();
        bool a = log.readFile("\\aa");
        //records = new RecordList();
        //现在找到的数据全部在records中
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        string[] hh = new string[] { "流水号", "消费日期", "类别", "收支项目", "金额", "备注" };
        //dataViewControl.Columns.Add();
        DataColumn[] columns = new DataColumn[6];
        DataRow[] rows = new DataRow[log.recordCount];
        for (int i = 0; i < 6; i++)
        {
            columns[i] = new DataColumn(hh[i], typeof(string));
            dt.Columns.Add(columns[i]);
        }
        int ss = 1;
        for (int i = 0; i < log.recordCount; i++)
        {
            if (search == "收入")
            {
                if (log.recordList[i].consumeType == "收入")
                {
                    rows[ss] = dt.NewRow();
                    rows[ss][0] = log.recordList[i].consumeIndex;
                    rows[ss][1] = log.recordList[i].consumeDate;
                    rows[ss][2] = log.recordList[i].consumeType;
                    rows[ss][3] = log.recordList[i].consumeCatagory;
                    rows[ss][4] = log.recordList[i].consumeMoney;
                    rows[ss][5] = log.recordList[i].consumeInformation;
                    dt.Rows.Add(rows[ss]);
                    ss++;
                }
            }
            else
            {
                if (log.recordList[i].consumeType == "支出")
                {
                    rows[ss] = dt.NewRow();
                    rows[ss][0] = log.recordList[i].consumeIndex;
                    rows[ss][1] = log.recordList[i].consumeDate;
                    rows[ss][2] = log.recordList[i].consumeType;
                    rows[ss][3] = log.recordList[i].consumeCatagory;
                    rows[ss][4] = log.recordList[i].consumeMoney;
                    rows[ss][5] = log.recordList[i].consumeInformation;
                    dt.Rows.Add(rows[ss]);
                    ss++;
                }
            }
        }
        ds.Tables.Add(dt);
        dataViewControl.DataSource = ds.Tables[0];
        //取消默认选中第一行
        dataViewControl.ClearSelection();
        //把删除键设为不可用
        btnDelete.Enabled = false;
        toolStripButtonDelete.Enabled = false;
    }
    private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        //在关闭子窗口的同时还要关闭父窗口
        //并且还要给出关闭子窗口的确认确认
        DialogResult result = MessageBox.Show("请是否确认是否要退出系统!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
        while (result == DialogResult.OK)
        {
            this.Dispose();
            Application.Exit();
        }
        {
            e.Cancel = true;
        }
    }
    //已修复---bug1:每一次增删查找后,就要对总收入,总支出,净收入进行重新计算
    /// <summary>
    /// 不选中条目,按钮被提醒
    /// 该按钮只负责激活 修改面板和面板上的选项
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnUpdate_Click(object sender, EventArgs e)
    {
        //先选中条目记录,然后才谈修改不修改的问题
        if (dataViewControl.SelectedRows.Count != 0)
        {
            //并且面板先前得是关闭的
            if (this.Size.Height == 533)
            {
                //要修改必须先打开下面的操作条目面板
                hidePanel(false);
                //每点一次这个修改按钮,那个"详细信息"按钮下移一次,功能不对
            }
            this.panelEdit.Enabled = true;
        }
        else
        {
            MessageBox.Show("请您先选中一条记录,再来修改", "温馨提示");
        }
    }
    private void btnInsert_Click(object sender, EventArgs e)
    {
        AddForm addForm = new AddForm();
        addForm.mf = this;
        addForm.ShowDialog();
    }
    /// <summary>
    /// 换一钟写法:不选中项目,按钮不可用
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnDelete_Click(object sender, EventArgs e)
    {
        if (dataViewControl.SelectedRows.Count != 0)
        {
            //先把数据读入链表:
            //多次debug,能读入链表
            string strLine = "";
            FinanceRecord pHead = null,tempNode, newNode;;
            int intNum = 0;//记录数
            string[] recordData;
            FinanceRecord data;
            try
            {
                StreamReader AccountFile = new StreamReader("..\\..\\Properties\\accountBook" + "\\aa" + ".txt", Encoding.GetEncoding("gb2312"));
                while (!AccountFile.EndOfStream)
                {
                    strLine = AccountFile.ReadLine();
                    recordData = strLine.Split(' ');
                    if (strLine != "" && recordData != null)
                    {
                        data = new FinanceRecord(recordData[0].Trim(), recordData[1].Trim(), recordData[2].Trim(), recordData[3].Trim(), recordData[4].Trim(), recordData[5].Trim());
                        newNode = new FinanceRecord(data.consumeIndex, data.consumeDate,data.consumeType,
                            data.consumeCatagory, data.consumeMoney, data.consumeInformation);
                        newNode.NextRecord = null;
                        intNum++;
                        //无头结点的链表
                        if (pHead == null)
                        {
                            pHead = newNode;
                        }
                        else
                        {
                            //从未赋值的tempNode知道,此时它还无.nextRecord属性
                            tempNode = pHead;
                            while (tempNode.NextRecord != null)
                            {
                                tempNode = tempNode.NextRecord;
                            }
                            tempNode.NextRecord = newNode;
                        }
                                                                                                                                                                                 
                    }
                }
                AccountFile.Close();
            }
            catch
            {
                MessageBox.Show("Something Wrong Happens", "温馨提示");
            }
            //上面已经完成了读入工作,intNum是数据的总量,pHead头结点(不是头指针)
            //temp保存上一节点,lst不停往下寻找
            bool tag = false;//用来标记删除是否成功
            FinanceRecord lst,temp=null;
            lst = pHead;
            while (lst!= null)
            {
                //下面这条语是为了调试过程中测试是否读取了全部得数据
                //MessageBox.Show(lst.consumeDate);
                //下面这个算法并不适合删除头结点,所以必须先处理头结点!
                bool b0 = (dataViewControl.SelectedRows[0].Cells[1].Value.ToString().Trim().Equals(pHead.consumeDate.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[2].Value.ToString().Trim().Equals(pHead.consumeType.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[3].Value.ToString().Trim().Equals(pHead.consumeCatagory.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[4].Value.ToString().Trim().Equals(pHead.consumeMoney.ToString()));
                if (b0)
                {
                    lst = pHead.NextRecord;
                    pHead = lst;
                    tag = true;
                    break;
                }
                //找到就在链表里先进行删除,没找到就继续找
                bool b1 = (dataViewControl.SelectedRows[0].Cells[1].Value.ToString().Trim().Equals(lst.consumeDate.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[2].Value.ToString().Trim().Equals(lst.consumeType.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[3].Value.ToString().Trim().Equals(lst.consumeCatagory.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[4].Value.ToString().Trim().Equals(lst.consumeMoney.ToString()));
                if (b1)
                {
                    temp.NextRecord = temp.NextRecord.NextRecord;
                    tag = true;
                    break;
                }
                temp = lst;
                lst = lst.NextRecord;
            }
            //用来检验删除操作后,整个链表是否正常,用头结点判断就好了
            //MessageBox.Show(pHead.consumeDate);
            //之后进行简单的遍历方式写入文件就好
            FinanceRecord round=pHead;
            try
            {
                StreamWriter accountFile1 = new StreamWriter("..\\..\\Properties\\accountBook" + "\\aa" + ".txt", false, Encoding.GetEncoding("gb2312"));
                for (int i = 0; i < intNum-1; i++)
                {
                    accountFile1.WriteLine(round.consumeIndex.Trim() + " " + round.consumeDate.Trim() + " " +
                        round.consumeType.Trim() + " " + round.consumeCatagory.Trim() + " " + round.consumeMoney.Trim() + " " + round.consumeInformation.Trim());
                    round = round.NextRecord;
                }
                accountFile1.Close();
            }
            catch
            {
                MessageBox.Show("Something Wrong Happens","温馨提示");
            }
            //在进行删除操作:
                                                                                                                                                                    
                if (tag == true)
                {
                    MessageBox.Show("删除成功");
                    //但是dataGridView并没有刷新显示
                    showTotalMoney();
                    GetGridviewAll();
                }
                else
                {
                    MessageBox.Show("删除失败");
                }
        }
    }
    private void btnFind_Click(object sender, EventArgs e)
    {
        SearchForm searchForm = new SearchForm();
        searchForm.mf = this;
        searchForm.ShowDialog();
    }
    /// <summary>
    /// 功能:菜单栏上的关于作者
    /// 时间:2013/9/23
    /// 作者: 余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ToolStripMenuItem1_Click(object sender, EventArgs e)
    {
        AboutAuthor ab = new AboutAuthor();
        ab.ShowDialog();
    }
    /// <summary>
    /// 功能:菜单栏上的帮助里面的关于程序
    /// 时间:2013/9/23
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ToolStripMenuItem2_Click(object sender, EventArgs e)
    {
        MessageBox.Show("    本程序是建立在北风网一个老师的C#家庭理财系统的基础上,仿制而成。"
            + "那个程序那老师并没有写完,并且也存在很多不合理和有问题的地方,按照他所讲的,进行了完善,补充,写出了本程序。"
        + "\n\n    虽然没有太多的原创新,不过在本次独立完成程序的过程中收获也是颇丰."
        + "\n\n    我并不在乎老师给我多少分儿, 我比较在意,老师拿什么眼光看我这样的行为,"
        + "或者说看修改老师代码或者照着参考书敲程序的孩子。\n\n    最后,感谢很多人,很多事儿,我讨厌啰嗦,不说了。", "程序说明");
    }
    private void ToolStripMenuItemImport_Click(object sender, EventArgs e)
    {
    }
    private void ToolStripMenuItemExport_Click(object sender, EventArgs e)
    {
    }
    /// <summary>
    /// 功能:菜单栏上的退出
    /// 时间:2013/9/23
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ToolStripMenuItemQuit_Click(object sender, EventArgs e)
    {
        this.Dispose();
        Application.Exit();
    }
    /// <summary>
    /// 功能:工具栏上的关于作者
    /// 时间:2013/9/23
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripButton2_Click(object sender, EventArgs e)
    {
        AboutAuthor ab = new AboutAuthor();
        ab.ShowDialog();
    }
    /// <summary>
    /// 功能:工具栏上的增加按钮
    /// 时间:2013/9/23
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripButtonAdd_Click(object sender, EventArgs e)
    {
        AddForm addForm = new AddForm();
        addForm.mf = this;
        addForm.ShowDialog();
    }
    /// <summary>
    /// 工具栏上的查找
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripButtonsearch_Click(object sender, EventArgs e)
    {
        SearchForm searchForm = new SearchForm();
        searchForm.mf = this;
        searchForm.ShowDialog();
    }
    /// <summary>
    /// 功能:工具栏上的删除键
    /// 时间:2013/9/23
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripButtonDelete_Click(object sender, EventArgs e)
    {
        if (dataViewControl.SelectedRows.Count != 0)
        {
            //先把数据读入链表:
            //多次debug,能读入链表
            string strLine = "";
            FinanceRecord pHead = null, tempNode, newNode; ;
            int intNum = 0;//记录数
            string[] recordData;
            FinanceRecord data;
            try
            {
                StreamReader AccountFile = new StreamReader("..\\..\\Properties\\accountBook" + "\\aa" + ".txt", Encoding.GetEncoding("gb2312"));
                while (!AccountFile.EndOfStream)
                {
                    strLine = AccountFile.ReadLine();
                    recordData = strLine.Split(' ');
                    if (strLine != "" && recordData != null)
                    {
                        data = new FinanceRecord(recordData[0].Trim(), recordData[1].Trim(), recordData[2].Trim(), recordData[3].Trim(), recordData[4].Trim(), recordData[5].Trim());
                        newNode = new FinanceRecord(data.consumeIndex, data.consumeDate, data.consumeType,
                            data.consumeCatagory, data.consumeMoney, data.consumeInformation);
                        newNode.NextRecord = null;
                        intNum++;
                        //无头结点的链表
                        if (pHead == null)
                        {
                            pHead = newNode;
                        }
                        else
                        {
                            //从未赋值的tempNode知道,此时它还无.nextRecord属性
                            tempNode = pHead;
                            while (tempNode.NextRecord != null)
                            {
                                tempNode = tempNode.NextRecord;
                            }
                            tempNode.NextRecord = newNode;
                        }
                    }
                }
                AccountFile.Close();
            }
            catch
            {
                MessageBox.Show("Something Wrong Happens", "温馨提示");
            }
            //上面已经完成了读入工作,intNum是数据的总量,pHead头结点(不是头指针)
            //temp保存上一节点,lst不停往下寻找
            bool tag = false;//用来标记删除是否成功
            FinanceRecord lst, temp = null;
            lst = pHead;
            while (lst != null)
            {
                //下面这条语是为了调试过程中测试是否读取了全部得数据
                //MessageBox.Show(lst.consumeDate);
                //下面这个算法并不适合删除头结点,所以必须先处理头结点!
                bool b0 = (dataViewControl.SelectedRows[0].Cells[1].Value.ToString().Trim().Equals(pHead.consumeDate.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[2].Value.ToString().Trim().Equals(pHead.consumeType.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[3].Value.ToString().Trim().Equals(pHead.consumeCatagory.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[4].Value.ToString().Trim().Equals(pHead.consumeMoney.ToString()));
                if (b0)
                {
                    lst = pHead.NextRecord;
                    pHead = lst;
                    tag = true;
                    break;
                }
                //找到就在链表里先进行删除,没找到就继续找
                bool b1 = (dataViewControl.SelectedRows[0].Cells[1].Value.ToString().Trim().Equals(lst.consumeDate.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[2].Value.ToString().Trim().Equals(lst.consumeType.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[3].Value.ToString().Trim().Equals(lst.consumeCatagory.ToString()))
                    && (dataViewControl.SelectedRows[0].Cells[4].Value.ToString().Trim().Equals(lst.consumeMoney.ToString()));
                if (b1)
                {
                    temp.NextRecord = temp.NextRecord.NextRecord;
                    tag = true;
                    break;
                }
                temp = lst;
                lst = lst.NextRecord;
            }
            //用来检验删除操作后,整个链表是否正常,用头结点判断就好了
            //MessageBox.Show(pHead.consumeDate);
            //之后进行简单的遍历方式写入文件就好
            FinanceRecord round = pHead;
            try
            {
                StreamWriter accountFile1 = new StreamWriter("..\\..\\Properties\\accountBook" + "\\aa" + ".txt", false, Encoding.GetEncoding("gb2312"));
                for (int i = 0; i < intNum - 1; i++)
                {
                    accountFile1.WriteLine(round.consumeIndex.Trim() + " " + round.consumeDate.Trim() + " " +
                        round.consumeType.Trim() + " " + round.consumeCatagory.Trim() + " " + round.consumeMoney.Trim() + " " + round.consumeInformation.Trim());
                    round = round.NextRecord;
                }
                accountFile1.Close();
            }
            catch
            {
                MessageBox.Show("Something Wrong Happens", "温馨提示");
            }
            //在进行删除操作:
            if (tag == true)
            {
                MessageBox.Show("删除成功");
                //但是dataGridView并没有刷新显示
                showTotalMoney();
                GetGridviewAll();
            }
            else
            {
                MessageBox.Show("删除失败");
            }
        }
    }
    /// <summary>
    /// 功能:工具栏上的修改按钮
    /// 时间:2013/9/23
    /// 作者:余颜凯
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripButtonUpdate_Click(object sender, EventArgs e)
    {
        //先选中条目记录,然后才谈修改不修改的问题
        if (dataViewControl.SelectedRows.Count != 0)
        {
            //并且面板先前得是关闭的
            if (this.Size.Height == 533)
            {
                //要修改必须先打开下面的操作条目面板
                hidePanel(false);
                //每点一次这个修改按钮,那个"详细信息"按钮下移一次,功能不对
            }
            this.panelEdit.Enabled = true;
        }
        else
        {
            MessageBox.Show("请您先选中一条记录,再来修改", "温馨提示");
        }
    }
    private void Version10ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        MessageBox.Show("    想走近路的人却走了远路。"
            + "这个版本就是在Version 1.0的基础上将所有数据库实现的操作全部换成文件+数据结构实现。"
        + "\n\n    如果我还有什么要说的,那只有一句:"
        + "\n\n    按要求作答,多看老师的代码,之后独立思考。", "程序说明");
    }
    private void Version10ToolStripMenuItem1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("1.新增和修改记录时,还需要一个时间合法性判断,避免出现11月31号类似的错误"
                  + "\n\n2.多次查找和删除的效率优化"
                  + "\n\n3.排序的实现:按日期,按类别,按收支项目"
                  + "\n\n4.修改密码功能"
                  + "\n\n5.流水号没有利用起来"
                  + "\n\n6.没有根据用户建立自己的账本文件", "程序说明");
    }
    private void comboBoxDateMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (comboBoxDateMonth.SelectedIndex)
        {
            case 3:
            case 5:
            case 8:
            case 10: comboBoxDate.Items.Clear();
                for (int i = 1; i <= 30; i++)
                {
                    comboBoxDate.Items.Add(i.ToString());
                }
                comboBoxDate.SelectedIndex = 0;
                break;
            case 1:
                if ((Int32.Parse(comboBoxDateYear.Text.Trim()) % 4 == 0 && Int32.Parse(comboBoxDateYear.Text.Trim()) % 100 != 0)
                           || Int32.Parse(comboBoxDateYear.Text.Trim()) % 400 == 0)
                {
                    comboBoxDate.Items.Clear();
                    for (int i = 1; i <= 29; i++)
                    {
                        comboBoxDate.Items.Add(i.ToString());
                    }
                    comboBoxDate.SelectedIndex = 0;
                }
                else
                {
                    comboBoxDate.Items.Clear();
                    for (int i = 1; i <= 28; i++)
                    {
                        comboBoxDate.Items.Add(i.ToString());
                    }
                    comboBoxDate.SelectedIndex = 0;
                }
                ; break;
            case 0:
            case 2:
            case 4:
            case 6:
            case 7:
            case 9:
            case 11:
                comboBoxDate.Items.Clear();
                for (int i = 1; i <= 31; i++)
                {
                    comboBoxDate.Items.Add(i.ToString());
                }
                comboBoxDate.SelectedIndex = 0;
                break;
        }
    }
    private void comboBoxDateYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        //tag为0 表示非闰年,即正常年
        int tag = 0;
        if ((Int32.Parse(comboBoxDateYear.Text.Trim()) % 4 == 0 && Int32.Parse(comboBoxDateYear.Text.Trim()) % 100 != 0)
                           || Int32.Parse(comboBoxDateYear.Text.Trim()) % 400 == 0)
            tag = 1;
        if (comboBoxDateMonth.SelectedIndex == 1)
        {
            if (tag == 0)
            {
                comboBoxDate.Items.Clear();
                for (int i = 1; i <= 28; i++)
                {
                    comboBoxDate.Items.Add(i.ToString());
                }
                comboBoxDate.SelectedIndex = 0;
            }
            else
            {
                comboBoxDate.Items.Clear();
                for (int i = 1; i <= 29; i++)
                {
                    comboBoxDate.Items.Add(i.ToString());
                }
                comboBoxDate.SelectedIndex = 0;
            }
        }
    }
}



AddFor如下:

C#实现_______个人记账程序__修改_C#_04


public LoginForm lg;
//保留主菜单
public MainForm mf;
private void AddForm_Load(object sender, EventArgs e)
{
    comboBoxLei.SelectedIndex = 0;
    comboBoxItem.SelectedIndex = 0;
    //加载消费条目时间
    for (int i = 1992; i < 2092; i++)
    {
        comboBoxDateYear.Items.Add(i.ToString());
    }
    for (int i = 1; i <= 12; i++)
    {
        comboBoxDateMonth.Items.Add(i.ToString());
    }
    //for (int i = 1; i <= 31; i++)
    //{
    //    comboBoxDate.Items.Add(i.ToString());
    //}
}
private void comboBoxLei_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBoxLei.SelectedIndex == 0)//选中的为收入
    {
        comboBoxItem.Items.Clear();//清空收入
        comboBoxItem.Items.Add("兼职");
        comboBoxItem.Items.Add("银行利息");
        comboBoxItem.Items.Add("基金收益");
        comboBoxItem.Items.Add("奖学金");
        comboBoxItem.Items.Add("其他收入");
    }
    else //如果选中为支出
    {
        comboBoxItem.Items.Clear();
        comboBoxItem.Items.Add("娱乐");
        comboBoxItem.Items.Add("吃饭");
        comboBoxItem.Items.Add("学习");
        comboBoxItem.Items.Add("购物");
    }
    comboBoxItem.SelectedIndex = 0;
}
/// <summary>
/// 功能:添加新收支记录
/// 时间:2013/9/21,2013/10/15
/// 作者:余颜凯
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAdd_Click(object sender, EventArgs e)
{
    //解决3件事儿:1.数据库,2.dataGridView 3.totalmoney
    bool isNull = IsNotNull();//判断是否为空
    if (isNull)
    {
        string date = comboBoxDateYear.Text.Trim() + "/" + comboBoxDateMonth.Text.Trim() + "/" + comboBoxDate.Text.Trim();
        FinanceLog log = new FinanceLog();
        log.readFile("//aa");
        log.Add("5", date.Trim(), comboBoxLei.Text.Trim(), comboBoxItem.Text.Trim(), textBoxJin.Text.Trim(), textBoxDescription.Text.Trim());
        log.saveFile("//aa");
        MessageBox.Show("成功插入一条信息");
        log.readFile("//aa");
        mf.GetGridviewAll();//功能类似
        mf.showTotalMoney();
        this.Close();
    }
    else
    {
        MessageBox.Show("请按要求输入");
    }
}
//判断是否为空(添加的记录不能为空)
public bool IsNotNull()
{
    bool isnull = true;
    if (comboBoxDateYear.Text.Trim() == string.Empty)
    {
        isnull = false;
    }
    if (comboBoxDateMonth.Text.Trim() == string.Empty)
    {
        isnull = false;
    }
    if (comboBoxDate.Text.Trim() == string.Empty)
    {
        isnull = false;
    }
    if (comboBoxLei.Text.Trim() == string.Empty)
    {
        isnull = false;
    }
    if (comboBoxItem.Text.Trim() == string.Empty)
    {
        isnull = false;
    }
    if (textBoxJin.Text.Trim() == string.Empty)
    {
        isnull = false;
    }
    //由于在Version2.0中数据是以文件的行读取的
    if (textBoxDescription.Text.Trim() == string.Empty)
    {
        isnull = false;
    }
    return isnull;
}
private void comboBoxDateYear_SelectedIndexChanged(object sender, EventArgs e)
{
    //tag为0 表示非闰年,即正常年
    int tag = 0;
    if ((Int32.Parse(comboBoxDateYear.Text.Trim()) % 4 == 0 && Int32.Parse(comboBoxDateYear.Text.Trim()) % 100 != 0)
                       || Int32.Parse(comboBoxDateYear.Text.Trim()) % 400 == 0)
        tag = 1;
    if (comboBoxDateMonth.SelectedIndex == 1)
    {
        if (tag == 0)
        {
            comboBoxDate.Items.Clear();
            for (int i = 1; i <= 28; i++)
            {
                comboBoxDate.Items.Add(i.ToString());
            }
            comboBoxDate.SelectedIndex = 0;
        }
        else
        {
            comboBoxDate.Items.Clear();
            for (int i = 1; i <= 29; i++)
            {
                comboBoxDate.Items.Add(i.ToString());
            }
            comboBoxDate.SelectedIndex = 0;
        }
    }
}
private void comboBoxDateMonth_SelectedIndexChanged(object sender, EventArgs e)
{
    switch (comboBoxDateMonth.SelectedIndex)
    {
        case 3:
        case 5:
        case 8:
        case 10: comboBoxDate.Items.Clear();
            for (int i = 1; i <= 30; i++)
            {
                comboBoxDate.Items.Add(i.ToString());
            }
            comboBoxDate.SelectedIndex = 0;
            break;
        case 1:
            if ((Int32.Parse(comboBoxDateYear.Text.Trim()) % 4 == 0 && Int32.Parse(comboBoxDateYear.Text.Trim()) % 100 != 0)
                       || Int32.Parse(comboBoxDateYear.Text.Trim()) % 400 == 0)
            {
                comboBoxDate.Items.Clear();
                for (int i = 1; i <= 29; i++)
                {
                    comboBoxDate.Items.Add(i.ToString());
                }
                comboBoxDate.SelectedIndex = 0;
            }
            else
            {
                comboBoxDate.Items.Clear();
                for (int i = 1; i <= 28; i++)
                {
                    comboBoxDate.Items.Add(i.ToString());
                }
                comboBoxDate.SelectedIndex = 0;
            }
            ; break;
        case 0:
        case 2:
        case 4:
        case 6:
        case 7:
        case 9:
        case 11:
            comboBoxDate.Items.Clear();
            for (int i = 1; i <= 31; i++)
            {
                comboBoxDate.Items.Add(i.ToString());
            }
            comboBoxDate.SelectedIndex = 0;
            break;
    }
}


查找:

C#实现_______个人记账程序__修改_C#_05

public MainForm mf;
        string ss = string.Empty;
        public SearchForm()
        {
            InitializeComponent();
        }
                                                             
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 功能:单选框的文字判断查询方法,之后调用主界面的dataView显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (ss == "全部")
            {
                mf.GetGridviewAll();
            }
            else
            {
                //FinanceLog log =new FinanceLog();
                //log.readFile("\\aa");
                mf.SearchData(ss);
            }
            this.Close();
        }
        private void SearchForm_Load(object sender, EventArgs e)
        {
            ss = radioButtonIn.Text.Trim();
        }
        private void radioButtonIn_CheckedChanged(object sender, EventArgs e)
        {
            ss = radioButtonIn.Text.Trim();
        }
        private void radioButtonOut_CheckedChanged(object sender, EventArgs e)
        {
            ss = radioButtonOut.Text.Trim();
        }
        private void radioButtonAll_CheckedChanged(object sender, EventArgs e)
        {
            ss = radioButtonAll.Text.Trim();
        }