Êóðñîâàÿ ðàáîòà: Ðàçðàáîòêà ïðîãðàììû "Ôîðìèðîâàíèå è ïðîâåðêà êîíòðîëüíîé ñóììû êëàñòåðîâ"
HDDGroup.HeaderAlignment = HorizontalAlignment.Left;
HDDGroup.Name = "HardDrive(s)";
//Adds the search group...
listView1.Groups.Add(HDDGroup);
int i = 0;
foreach (HardDrive x in hdCollection)
{
AddItemToListview(HDDGroup, i, x.Model.ToString(), 0, "1");
i++; }
HDDGroup = null; }
private void AddItemToListview(ListViewGroup GroupName, int IndexNumber, string ItemName, int ImageIndex, string ItemTAG)
{
ListViewItem NewItem = new ListViewItem();
ListViewItem.ListViewSubItem NewSubItem = new ListViewItem.ListViewSubItem();
NewSubItem.Text = IndexNumber.ToString();
NewSubItem.Name = "Subitem1";
NewItem.SubItems.Add(NewSubItem);
NewItem.SubItems.Add(NewSubItem);
NewItem.Name = ItemName;
NewItem.Text = ItemName;
NewItem.Group = GroupName;
NewItem.ImageIndex = ImageIndex;
NewItem.Tag = ItemTAG;
listView1.Items.Add(NewItem);
NewItem = null;
NewSubItem = null;
// Group = null; }
private void WriteHDDText()
{
HardDrive Hd = null;
bool fail = false;
try
{
Hd = (HardDrive)hdCollection[int.Parse(listView1.SelectedItems[0].SubItems[1].Text)]; }
catch (Exception)
{
Hd = null;
fail = true; }
if (fail != true)
{
Hd = (HardDrive)hdCollection[int.Parse(listView1.SelectedItems[0].SubItems[1].Text)];
double size_temp = double.Parse(Hd.Size);
if (analiz == false)
{
richTextBox1.Clear();
richTextBox1.Text = ("\n" +
"Model:\n" +
"--------------------------------------------------------\n" +
"Model : " + Hd.Model.ToString() + "\n" +
"Type : " + Hd.Type.ToString() + "\n" +
"Serial No. : " + Hd.SerialNo.ToString() + "\n" +
"Firmware Revision : " + Hd.FirmwareRevision.ToString() + "\n" +
"\n" +
"Characteristics:\n" +
"--------------------------------------------------------\n" +
"Media Type : " + Hd.MediaType.ToString() + "\n" +
"Partitions : " + Hd.Partitions.ToString() + "\n" +
"Signature : " + Hd.Signature.ToString() + "\n" +
"Size : " + Hd.Size.ToString() + " Byte (" + Math.Round((((size_temp / 1024) / 1024) / 1024), 2) + " GB)" + "\n" +
"\n" +
"Status : " + Hd.Status.ToString() + "\n" +
"\n" +
"Tracks:\n" +
"--------------------------------------------------------\n" +
"Total Cylinders : " + Hd.TotalCylinders.ToString() + "\n" +
"Total Heads : " + Hd.TotalHeads.ToString() + "\n" +
"Total Sectors : " + Hd.TotalSectors.ToString() + "\n" +
"Total Tracks : " + Hd.TotalTracks.ToString() + "\n" +
"Bytes Pr. Sector : " + Hd.BytesPerSector.ToString() + "\n" +
"Sector Pr. Tracks : " + Hd.SectorsPerTrack.ToString() + "\n" +
"Tracks Pr. Cylinder : " + Hd.TracksPerCylinder.ToString() + "\n"
); }
else
{
richTextBox2.Clear();
richTextBox2.Text = ("\n" +
"Model:\n" +
"--------------------------------------------------------\n" +
"Model : " + Hd.Model.ToString() + "\n" +
"Type : " + Hd.Type.ToString() + "\n" +
"Serial No. : " + Hd.SerialNo.ToString() + "\n" +
"Firmware Revision : " + Hd.FirmwareRevision.ToString() + "\n" +
"\n" +
"Characteristics:\n" +
"--------------------------------------------------------\n" +
"Media Type : " + Hd.MediaType.ToString() + "\n" +
"Partitions : " + Hd.Partitions.ToString() + "\n" +
"Signature : " + Hd.Signature.ToString() + "\n" +
"Size : " + Hd.Size.ToString() + " Byte (" + Math.Round((((size_temp / 1024) / 1024) / 1024), 2) + " GB)" + "\n" +
"\n" +
"Status : " + Hd.Status.ToString() + "\n" +
"\n" +
"Tracks:\n" +
"--------------------------------------------------------\n" +
"Total Cylinders : " + Hd.TotalCylinders.ToString() + "\n" +
"Total Heads : " + Hd.TotalHeads.ToString() + "\n" +
"Total Sectors : " + Hd.TotalSectors.ToString() + "\n" +
"Total Tracks : " + Hd.TotalTracks.ToString() + "\n" +
"Bytes Pr. Sector : " + Hd.BytesPerSector.ToString() + "\n" +
"Sector Pr. Tracks : " + Hd.SectorsPerTrack.ToString() + "\n" +
"Tracks Pr. Cylinder : " + Hd.TracksPerCylinder.ToString() + "\n"
); }
size_temp = 0;
}
Hd = null;
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
int selected_index;
try
{
//MessageBox.Show(listView1.SelectedItems[0].Tag.ToString());
selected_index = listView1.SelectedItems[0].Index;
switch (listView1.SelectedItems[0].Tag.ToString())
{
case "1":
WriteHDDText();
break;
} }
catch (Exception)
{
//Do nothing
} }
private void button1_Click(object sender, EventArgs e)
{
if (analiz == false)
analiz = true;
else
analiz = false;
GetHardDiskInfo();
WriteHDDText();
}
private void button2_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
}
//Form2.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
namespace kurs_pogulyat
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
//CRC 32
private void button1_Click(object sender, EventArgs e)
{
// ×èòàåì ôàéë test.txt
System.IO.FileStream stream1 = System.IO.File.OpenRead(textBox1.Text.ToString());
textBox3.Text=(string.Format("{0:X}", CalculateCRC(stream1))).ToString();
}
/// <summary>
/// Âû÷èñëåíèå CRC32
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
public static uint CalculateCRC(System.IO.Stream stream)
{
const int buffer_size = 1024;
const uint POLYNOMIAL = 0xEDB88320;
uint result = 0xFFFFFFFF;
uint Crc32;
byte[] buffer = new byte[buffer_size];
uint[] table_CRC32 = new uint[256];
unchecked
{
// Èíèöèàëèàçàöèÿ òàáëèöû
for (int i = 0; i < 256; i++)
{
Crc32 = (uint)i;
for (int j = 8; j > 0; j--)
{
if ((Crc32 & 1)==1)
Crc32 = (Crc32 >> 1) ^ POLYNOMIAL;
else
Crc32 >>= 1;
}
table_CRC32[i] = Crc32;
}
/
// ×òåíèå èç áóôåðà
int count = stream.Read(buffer, 0, buffer_size);
// Âû÷èñëåíèå CRC
while (count > 0)
{
for (int i = 0; i < count; i++)
{
result = ((result) >> 8)
^ table_CRC32[(buffer[i])
^ ((result) & 0x000000FF)];