Пример #1
0
        /// <summary>
        /// 导入
        /// </summary>
        private void toolStripButton_DataInput_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string            path    = this.openFileDialog1.FileName;
                StreamReader      sr      = new StreamReader(path, Encoding.Default);
                XmlSerializer     xml     = new XmlSerializer(typeof(AccountCollection));
                AccountCollection accColl = null;
                try
                {
                    accColl = (AccountCollection)xml.Deserialize(sr);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("被损坏的数据文件或不合法的数据格式,无法导入!!\n:" + ex.Message);
                    return;
                }
                finally
                {
                    if (sr == null)
                    {
                        sr.Close();
                    }
                }

                File.Copy(path, this.user.PathOfDataFile_Account, true);

                if (accColl != null)
                {
                    this.user.AccountMagr.AccoutList = accColl;
                }
                this.FormAccountManage_Load(null, null);
            }
        }
Пример #2
0
        /// <summary>
        /// 保存列表中的内容
        /// </summary>
        private void SaveListViewToFile()
        {
            AccountCollection accCollect = new AccountCollection();

            foreach (ListViewItem item in this.listView1.Items)
            {
                Account acc = new Account();
                acc.OwnerName    = item.SubItems[1].Text;
                acc.BankbookNum  = item.SubItems[2].Text;
                acc.CardNum      = item.SubItems[3].Text;
                acc.StartDate    = DateTime.Parse(item.SubItems[4].Text);
                acc.BankName     = item.SubItems[5].Text;
                acc.MoneyType    = item.SubItems[6].Text;
                acc.AccountType  = item.SubItems[7].Text;
                acc.IniBlance    = double.Parse(item.SubItems[8].Text);
                acc.RemainBlance = double.Parse(item.SubItems[9].Text);
                acc.Remark       = item.SubItems[10].Text;

                accCollect.Add(acc);
            }

            this.user.AccountMagr.AccoutList = accCollect;
            this.user.AccountMagr.SaveDataToFile(this.user.PathOfDataFile_Account);
        }
Пример #3
0
        /// <summary>
        /// 从文件读取帐户管理数据
        /// </summary>
        /// <param name="pathOfDataFile">数据文件路径</param>
        public bool LoadDataFromFile(string pathOfDataFile)
        {
            StreamReader  sr  = new StreamReader(pathOfDataFile, Encoding.Default);
            XmlSerializer xml = new XmlSerializer(typeof(AccountCollection));

            try
            {
                this.accountList = (AccountCollection)xml.Deserialize(sr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }

            return(true);
        }