private void NextButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (FCB.IorO() == IOState.IO)
                {
                    FCB.updateRecCancel();
                }
                //FCB.seekRec(1, 1);
                //CurrentSector++;
                BackButton.IsEnabled = true;

                if (GoToIntegerUpDown.Value >= FCB.GetFileDescription().EofRecNr)
                {
                    NextButton.IsEnabled = false;
                }
                GoToIntegerUpDown.Value++;
                GoTo();
            }
            catch (Exception exp)
            {
                ErrorHandling.ShowError(exp.Message);
                NextButton.IsEnabled = false;
            }
        }
        private void ReadRecord()
        {
            ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).ClearFields();

            if (GoToIntegerUpDown.Value != FCB.GetFileDescription().EofRecNr)
            {
                switch (FCB.IorO())
                {
                case IOState.IO:
                    if (IsStore())
                    {
                        Store temp = new Store();
                        FCB.readRec(temp, 1);
                        ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).Record = temp;
                    }
                    else if (IsProduct())
                    {
                        Product temp = new Product();
                        FCB.readRec(temp, 1);
                        ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).Record = temp;
                    }
                    else if (IsEmployee())
                    {
                        Employee temp = new Employee();
                        FCB.readRec(temp, 1);
                        ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).Record = temp;
                    }
                    break;

                case IOState.O:
                    if (IsStore())
                    {
                        Store temp = new Store();
                        FCB.readRec(temp);
                        ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).Record = temp;
                    }
                    else if (IsProduct())
                    {
                        Product temp = new Product();
                        FCB.readRec(temp);
                        ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).Record = temp;
                    }
                    else if (IsEmployee())
                    {
                        Employee temp = new Employee();
                        FCB.readRec(temp);
                        ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).Record = temp;
                    }
                    break;

                default:
                    throw new Exception("Unknown format to read/write from file.");
                }
            }
        }
        public RecordsWindow(FCB fcb)
        {
            try
            {
                InitializeComponent();
                FCB = fcb;
                InitRecordFields();
                InitAvailableButtons();

                CurrentRecordNumber = 0;
                InitData();
                MaxRecord = (int)FCB.GetFileDescription().FileSize *(1020 / (int)FCB.GetFileDescription().MaxRecSize);
                GoToIntegerUpDown.Maximum = MaxRecord;
            }
            catch (Exception exp)
            {
                ErrorHandling.ShowError(exp.Message);
                this.Close();
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            try
            {
                int structSize = Marshal.SizeOf(typeof(VolumeHeader));
                Console.WriteLine("Marshal.SizeOf(typeof(VolumeHeader) == " + structSize);

                Disk d = new Disk();
                Console.WriteLine("\nMake Disk:");
                Console.WriteLine(ToStringProperty(d.GetVolumeHeader()));

                d.Createdisk("disk1", "oshri");
                Console.WriteLine("\nCreate Disk:");
                Console.WriteLine(ToStringProperty(d.GetVolumeHeader()));
                d.Mountdisk("disk1");
                if (d.Ismounted(d.myDiskPointer))
                {
                    Console.WriteLine("Mounted!");
                }
                d.Createfile("f1", "meir", "F", Store.size(), 50, "I", 0);

                FCB fcb = d.Openfile("f1", "meir", "IO");
                fcb.seekRec(0, (int)fcb.GetFileDescription().FileAddr - 4 + 20);
                Store str  = new Store("", "", "", "");
                Store str2 = new Store("", "", "", "");
                fcb.readRec(str, 1);
                str = new Store("123", "aaa", "aaa", "aaa");
                fcb.updateRec(str);
                fcb.seekRec(1, -1);
                fcb.readRec(str2, 0);
                fcb.Closefile();

                DirEntry newdir = d.GetDirEntry(0);
                d.Format("oshri");
                Console.WriteLine("\nFormat Disk:");
                Console.WriteLine(ToStringProperty(d.GetVolumeHeader()));
                d.Unmountdisk(d.myDiskPointer);
                if (d.Ismounted(d.myDiskPointer))
                {
                    Console.WriteLine("Mounted!");
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Message);
                Console.ResetColor();
            }
        }
        private void LastButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (FCB.IorO() == IOState.IO)
                {
                    FCB.updateRecCancel();
                }
                //FCB.seekRec(0, (int)FCB.GetFileDescription().FileAddr - 4 + (int)FCB.GetFileDescription().EofRecNr - 1);
                //               FCB.seekRec(0, (int)FCB.GetFileDescription().EofRecNr - 1);
                GoToIntegerUpDown.Value = (int)FCB.GetFileDescription().EofRecNr;

                GoTo();
                NextButton.IsEnabled = false;
                BackButton.IsEnabled = true;
            }
            catch (Exception exp)
            {
                ErrorHandling.ShowError(exp.Message);
            }
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IRecord rec = ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).Record;
                if (CurrentRecordNumber == FCB.GetFileDescription().EofRecNr)
                {
                    FCB.writeRec(rec);
                }
                else
                {
                    FCB.updateRec(rec);
                }
                ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).ClearFields();
                BackButton.IsEnabled = true;
                MessageBox.Show("Record Saved", "Info", MessageBoxButton.OK, MessageBoxImage.Information);

                //CurrentSector++;

                //if (CurrentSector > FCB.GetFileDescription().EofRecNr || CurrentSector < 0)
                //{
                //    //FCB.seekRec(0,0);
                //    //CurrentSector = 0;
                //    ((IRecordUserControl)RecordDetailsStackPanel.Children[0]).ClearFields();

                //    BackButton.IsEnabled = false;
                //    NextButton.IsEnabled = true;
                //}
                GoToIntegerUpDown.Value++;
                GoTo();
                //ReadRecord();
            }
            catch (Exception exp)
            {
                ErrorHandling.ShowError(exp.Message);
            }
        }
 private bool IsEmployee()
 {
     return(FCB.GetFileDescription().ActualRecSize == Employee.size());
 }
 private bool IsStore()
 {
     return(FCB.GetFileDescription().ActualRecSize == Store.size());
 }
 private bool IsProduct()
 {
     return(FCB.GetFileDescription().ActualRecSize == Product.size());
 }