示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.ShowDialog();
            if (sfd.FileName != "")
            {
                FileStream      _fs     = new FileStream(sfd.FileName, FileMode.Create);
                infoStudent     info    = new infoStudent();
                BinaryFormatter bf      = new BinaryFormatter();
                FileStream      fs      = new FileStream(tbPath.Text, FileMode.OpenOrCreate);
                string          content = "";
                while (fs.Position != fs.Length)
                {
                    info     = (infoStudent)bf.Deserialize(fs);
                    info.DTB = (float)(info.Math + info.Literature) / 2;
                    bf.Serialize(_fs, info);
                    content += "\r\nMSSV: " + info.MSSV + "\r\nHọ Tên: " + info.Name +
                               "\r\nSố Điện thoại: " + info.NumberPhone + "\r\nToán: " + info.Math + "\r\nVăn: " + info.Literature
                               + "\r\nĐiểm Trung Bình: " + info.DTB + "\r\n";
                }
                tbWrite.Text = content;
                fs.Close();
            }
        }
示例#2
0
 //
 //
 private void btRead_Click(object sender, EventArgs e)
 {
     if (check(tbMSSV.Text, tbName.Text, tbnumberPhone.Text, tbMath.Text, tbLiterature.Text) == 1)
     {
         infoStudent info = new infoStudent();
         info.MSSV        = tbMSSV.Text;
         info.Name        = tbName.Text;
         info.NumberPhone = tbnumberPhone.Text;
         info.Math        = float.Parse(tbMath.Text);
         info.Literature  = float.Parse(tbLiterature.Text);
         try
         {
             BinaryFormatter bf  = new BinaryFormatter();
             SaveFileDialog  sfd = new SaveFileDialog();
             sfd.ShowDialog();
             if (sfd.FileName != "")
             {
                 FileStream fs = new FileStream(sfd.FileName, FileMode.Append);
                 bf.Serialize(fs, info);
                 fs.Close();
                 MessageBox.Show("Thêm Học Viên Thành Công");
             }
         }
         catch
         {
             MessageBox.Show("Thêm Học Viên Không Thành Công");
         }
     }
 }
示例#3
0
        private void btWrite_Click(object sender, EventArgs e)
        {
            infoStudent     info = new infoStudent();
            BinaryFormatter bf   = new BinaryFormatter();
            OpenFileDialog  ofd  = new OpenFileDialog();

            ofd.ShowDialog();
            if (ofd.FileName != "")
            {
                FileStream fs = new FileStream(ofd.FileName, FileMode.OpenOrCreate);
                tbPath.Text = ofd.FileName;
                string content = "";
                while (fs.Position != fs.Length)
                {
                    info     = (infoStudent)bf.Deserialize(fs);
                    content += "\r\nMSSV: " + info.MSSV + "\r\nHọ Tên: " + info.Name +
                               "\r\nSố Điện thoại: " + info.NumberPhone + "\r\nToán: " + info.Math + "\r\nVăn: " + info.Literature + "\r\n";
                }
                RichTextBox.Text = content;
                fs.Close();
            }
        }