Example #1
0
        public static void LoadFile(int userId, string path)
        {
            try
            {
                var name      = System.IO.Path.GetFileNameWithoutExtension(path);
                var expansion = System.IO.Path.GetExtension(path).ToLower();
                var binary    = FileToBinary(path);
                var size      = new System.IO.FileInfo(path);

                if (DataMethod.CheckFile(name, expansion, userId))
                {
                    if (MessageBox.Show("Данный файл уже существует в вашем хранилище. Желаете заменить его?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        DataMethod.ReplaceFile(name, expansion, (int)size.Length, binary, userId);
                    }
                }
                else
                {
                    DataMethod.InsertFile(name, expansion, (int)size.Length, binary, false, userId);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        public static void DownloadFile(int userId, int fileId)
        {
            try
            {
                using (var saveFileDialog = new SaveFileDialog())
                {
                    FileStruct fileStruct = DataMethod.GetFile(fileId);

                    saveFileDialog.Title    = "Скачивание файла";
                    saveFileDialog.FileName = fileStruct.name + fileStruct.extension;

                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        BinaryToFile(saveFileDialog.FileName, fileStruct.binary);

                        DataMethod.InsertFileChanges(userId, fileId, "Файл был скачен.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }