public void saveRecord(string filename, int position, MyRecord c)
        {
            bw = new BinaryWriter(File.Open(filename, FileMode.OpenOrCreate, FileAccess.Write));
            int startingPosition = position * (sizeof(int) * rozmiar_ciagu + sizeof(bool));

            bw.BaseStream.Position = startingPosition;

            int[] values = c.getValues();

            bw.Write(c.getKey());

            bool status  = c.isDeleted();
            int  pointer = c.getOverflowPointer();

            bw.Write(status);
            bw.Write(pointer);
            int counter = 0;

            for (int i = startingPosition + (2 * sizeof(int) + 1);
                 i < startingPosition + (sizeof(int) * rozmiar_ciagu + 1);
                 i += sizeof(int))
            {
                bw.Write(values[counter]);
                counter++;
            }
            bw.Close();
        }
Exemplo n.º 2
0
        private void addNewRecord()
        {
            int[] values = new int[record_size];
            labelStatus.Content = "";
            try
            {
                int key = Int32.Parse(textBoxKey.Text);

                values[0] = Int32.Parse(textBoxFirst.Text); values[1] = Int32.Parse(textBoxSecond.Text);
                values[2] = Int32.Parse(textBoxThird.Text); values[3] = Int32.Parse(textBoxFourth.Text);
                values[4] = Int32.Parse(textBoxFifth.Text); values[5] = Int32.Parse(textBoxSixth.Text);
                values[6] = Int32.Parse(textBoxSeventh.Text); values[7] = Int32.Parse(textBoxEighth.Text);
                values[8] = Int32.Parse(textBoxNineth.Text); values[9] = Int32.Parse(textBoxTenth.Text);

                if (action == 'N')
                {
                    savesCounter = 0;
                    loadsCounter = 0;
                    if (key > 0)
                    {
                        c = new MyRecord(key, values);
                        logic.addRecord(c, ref savesCounter, ref loadsCounter);
                    }
                }
                else if (action == 'E')
                {
                    c = new MyRecord(key, values, c.getOverflowPointer(), c.isDeleted());
                    logic.Edit(c, FileName);
                }
            }
            catch (Exception ex)
            {
                labelStatus.Content = "Błąd!";
            }
        }