예제 #1
0
        private void Button4_Click(object sender, EventArgs e)
        {
            Form2 testDialog = new Form2();

            listView1.BeginUpdate();               //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度

            ListViewItem lvi = new ListViewItem();

            //lvi.ImageIndex = 1;     //通过与imageList绑定,显示imageList中第i项图标



            if (testDialog.ShowDialog(this) == DialogResult.OK)            //弹出窗口
            {
                Listdata data = new Listdata();
                data = testDialog.get_data();

                list_num++;
                lvi.Text = list_num.ToString();

                lvi.SubItems.Add(data.operating);
                lvi.SubItems.Add(data.short_name);
                lvi.SubItems.Add(data.file_start.ToString());
                lvi.SubItems.Add(data.disk_start.ToString());
                lvi.SubItems.Add(data.data_size.ToString());
                lvi.SubItems.Add(data.full_name);
                lvi.Checked = true;

                listView1.Items.Add(lvi);                //列表显示数据
            }
            testDialog.Dispose();

            listView1.EndUpdate();              //结束数据处理,UI界面一次性绘制。
        }
예제 #2
0
        //向磁盘写入数据
        private void Button3_Click(object sender, EventArgs e)
        {
            byte[] WriteByte = new byte[512];
            for (uint i = 0; i < 512; i++)
            {
                WriteByte[i] = 0xFF;
            }
            Listdata execute_data = new Listdata();

            //if (DiskOpen == false)
            //{
            //	MessageBox.Show(this, "磁盘未打开", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Question);
            //	return;
            //}

            if (MessageBox.Show(this, "确定要执行操作?此操作无法撤销!", "提示信息:", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
            {
                button3.Text = "执行";
                return;
            }

            button3.Text = "停止";

            for (int i = 0; i < listView1.CheckedItems.Count; i++)    //遍历整个列表
            {
                if (listView1.CheckedItems[i].Checked)                //判断是否复选
                {
                    execute_data.full_name  = listView1.Items[i].SubItems[6].Text;
                    execute_data.operating  = listView1.Items[i].SubItems[1].Text;
                    execute_data.file_start = Convert.ToUInt32(listView1.Items[i].SubItems[3].Text);
                    execute_data.disk_start = Convert.ToUInt32(listView1.Items[i].SubItems[4].Text);
                    execute_data.data_size  = Convert.ToUInt32(listView1.Items[i].SubItems[5].Text);

                    //写入磁盘
                    if (execute_data.operating == "写入" || execute_data.operating == "擦除")
                    {
                        if (execute_data.data_size == 0 && execute_data.operating == "写入")
                        {
                            MessageBox.Show(this, "文件无内容或不存在", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Question);
                            continue;
                        }

                        for (uint SurplusLen = 0; SurplusLen < execute_data.data_size; SurplusLen += 512)
                        {
                            if (execute_data.operating == "写入")
                            {
                                //读取数据
                                WriteByte = FileBin.BinRead(execute_data.full_name, SurplusLen + execute_data.file_start, 512);
                            }
                            //将数据写入流
                            cipan.WriteSector(WriteByte, (SurplusLen / 512) + execute_data.disk_start);

                            //将当前流中的数据写入磁盘
                            cipan.Refresh();

                            //更新进度条
                            progressBar1.Step = (int)(SurplusLen * 100 / execute_data.data_size);
                            progressBar1.PerformStep();
                        }
                        MessageBox.Show(this, "文件写入完成", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Question);
                    }
                    else if (execute_data.operating == "读取")
                    {
                        /*读取数据*/
                        for (uint SurplusLen = 0; SurplusLen < execute_data.data_size; SurplusLen += 512)
                        {
                            //读取磁盘数据
                            WriteByte = cipan.ReadSector((SurplusLen / 512) + execute_data.disk_start);

                            //写入文件
                            FileBin.Write(execute_data.full_name, (SurplusLen / 512) + execute_data.disk_start, WriteByte);

                            //更新进度条
                            progressBar1.Step = (int)(SurplusLen * 100 / execute_data.data_size);
                            progressBar1.PerformStep();
                        }
                        MessageBox.Show(this, "磁盘读取完成", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Question);
                    }
                }
            }
            button3.Text = "执行";
        }