예제 #1
0
        /// <summary>
        /// Редактирование диска
        /// </summary>
        /// <param name="oldDiskNumber"></param>
        /// <param name="newDiskInfo"></param>
        public void EditDisk(DiskInfo oldDiskNumber, DiskInfo newDiskInfo)
        {
            if (oldDiskNumber.Number != newDiskInfo.Number)
            {
                int testIndex;
                try
                {
                    testIndex = FindDisk(newDiskInfo);
                }
                catch (MyException)
                {
                    testIndex = -1;
                }

                if (testIndex != -1)
                {
                    throw new MyException(string.Format("Диск номером {0} уже существует", newDiskInfo.Number));
                }
            }

            this.mDiskInfo.RemoveAt(FindDisk(oldDiskNumber));
            this.mDiskInfo.Add(newDiskInfo);
            SortDisks();
            Save();
        }
예제 #2
0
        public AddEditDiskForm(MainForm mainForm, AddEditState currentState, FilmotecClass filmotecClass, SettingClass settingClass, DiskInfo editDiskInfo, int selectedIndex)
        {
            InitializeComponent();

            m_MainForm      = mainForm;
            m_CurrentState  = currentState;
            m_FilmotecClass = filmotecClass;
            m_SettingClass  = settingClass;
            m_OldDiskInfo   = editDiskInfo;
            m_SelectedIndex = selectedIndex;
        }
예제 #3
0
        /// <summary>
        /// Удаление диска
        /// </summary>
        /// <param name="deleteDiskInfo"></param>
        public void DeleteDisk(DiskInfo deleteDiskInfo)
        {
            int deleteIndex = FindDisk(deleteDiskInfo);

            this.mDiskInfo.RemoveAt(deleteIndex);

            deleteIndex = 0;
            while (deleteIndex < this.mFilmInfo.Count)
            {
                if (this.mFilmInfo[deleteIndex].Number == deleteDiskInfo.Number)
                {
                    this.mFilmInfo.RemoveAt(deleteIndex);
                }
                else
                {
                    deleteIndex++;
                }
            }

            SortDisks();
            Save();
        }
예제 #4
0
        /// <summary>
        /// Загрузить базы данных из файла
        /// </summary>
        /// <returns>Success - true, oherwise - false</returns>
        private void Load()
        {
            this.mDiskInfo = new List <DiskInfo>();
            this.mFilmInfo = new List <FilmInfo>();

            var fi = new FileInfo(this.mPathDb);

            if (!fi.Exists)
            {
                return;
            }

            FileStream fs          = File.OpenRead(this.mPathDb);
            var        bytesBuffer = new byte[fs.Length];

            fs.Read(bytesBuffer, 0, (int)fs.Length);
            fs.Close();
            fs.Dispose();

            byte[] rez = UnpackXML(bytesBuffer);

            if (rez.Length > 0)
            {
                string text = Encoding.GetEncoding("windows-1251").GetString(rez);

                string[] parseText = text.Split(new[] { "^^!!&&^^" }, StringSplitOptions.None);

                var diskStr = new string[0];
                if (parseText.Length > 0 && parseText[0].Length > 0)
                {
                    diskStr = parseText[0].Split(new[] { "^!&^" }, StringSplitOptions.None);
                }

                var filmStr = new string[0];
                if (parseText.Length > 1 && parseText[1].Length > 0)
                {
                    filmStr = parseText[1].Split(new[] { "^!&^" }, StringSplitOptions.None);
                }

                for (int i = 0; i < diskStr.Length; i += 2)
                {
                    if (i + 1 < diskStr.Length)
                    {
                        var diskInfo = new DiskInfo {
                            Number = Convert.ToInt32(diskStr[i])
                        };
                        if (diskStr[i + 1] == "Buy")
                        {
                            diskInfo.Info = DiskType.Buy;
                        }
                        else if (diskStr[i + 1] == "OwnR")
                        {
                            diskInfo.Info = DiskType.OwnR;
                        }
                        else if (diskStr[i + 1] == "OwnRW")
                        {
                            diskInfo.Info = DiskType.OwnRW;
                        }
                        else
                        {
                            diskInfo.Info = DiskType.Empty;
                        }

                        this.mDiskInfo.Add(diskInfo);
                    }
                }

                for (int i = 0; i < filmStr.Length; i += 4)
                {
                    if (i + 3 < filmStr.Length)
                    {
                        GenreType genre = Helper.StringToGenre(filmStr[i + 3]);

                        var filmInfo = new FilmInfo
                        {
                            Number = Convert.ToInt32(filmStr[i]),
                            Name   = filmStr[i + 1],
                            Info   = filmStr[i + 2],
                            Genre  = genre
                        };
                        this.mFilmInfo.Add(filmInfo);
                    }
                }
            }
            else
            {
                throw new MyException("Файл с сохранённой информацией повреждён");
            }
        }
예제 #5
0
 /// <summary>
 /// Найти фильм по номеру диска и названию
 /// </summary>
 private int FindDisk(DiskInfo findDiskInfo)
 {
     return(FindDisk(findDiskInfo.Number));
 }
예제 #6
0
        /// <summary>
        /// Кнопка подтверждения
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                Convert.ToInt32(textBoxDiskNumber.Text);
            }
            catch
            {
                MessageBox.Show("Непонятный номер диска", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                textBoxDiskNumber.Focus();
                return;
            }

            var newDiskInfo = new DiskInfo
            {
                Number = Convert.ToInt32(textBoxDiskNumber.Text)
            };

            if (comboBoxDiskInfo.SelectedIndex == 0)
            {
                newDiskInfo.Info = DiskType.Buy;
            }
            else if (comboBoxDiskInfo.SelectedIndex == 1)
            {
                newDiskInfo.Info = DiskType.OwnR;
            }
            else
            {
                newDiskInfo.Info = DiskType.OwnRW;
            }

            try
            {
                if (m_CurrentState == AddEditState.Add)
                {
                    m_FilmotecClass.AddDisk(newDiskInfo);
                    if (m_SettingClass.IsCloseDiskForm)
                    {
                        Close();
                    }
                    else
                    {
                        textBoxDiskNumber.Text = (Convert.ToInt32(textBoxDiskNumber.Text) + 1).ToString();
                        comboBoxDiskInfo.Focus();
                    }
                }
                else
                {
                    m_FilmotecClass.EditDisk(m_OldDiskInfo, newDiskInfo);
                    if (checkBoxIsChangeFilms.Checked)
                    {
                        FilmInfo[] changeFilms = m_FilmotecClass.GetFilmInfo(m_OldDiskInfo.Number, string.Empty, string.Empty);
                        foreach (FilmInfo fi in changeFilms)
                        {
                            m_FilmotecClass.EditFilm(fi, new FilmInfo
                            {
                                Info   = fi.Info,
                                Name   = fi.Name,
                                Number = newDiskInfo.Number
                            });
                        }
                    }
                    m_MainForm.NewDiskNumber = newDiskInfo.Number;
                    Close();
                }
            }
            catch (MyException ex)
            {
                MessageBox.Show(ex.Message, "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Произошла непредвиденная ошибка: \r\n\r\n" + ex.Message + "\r\n\r\nСообщите разработчикам", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }