Ejemplo n.º 1
0
        public CheckResult SaveFile(FileBlobViewModel model)
        {
            if (!model.IsChanged)
            {
                return(new CheckResult(model));
            }

            using (var db = DB.GetContext())
            {
                var check = FileBlobValidator.ValidateSaveView(db, model);
                if (check.Failed)
                {
                    return(check);
                }

                KeyBinder key = new KeyBinder();
                try
                {
                    FileBlobRepository.SaveBlobView(db, key, model);
                    db.SaveChanges();
                    key.BindKeys();
                    model.IsChanged = false;
                    return(new CheckResult(model));
                }
                catch (Exception ex)
                {
                    key.RollbackKeys();
                    return(new CheckResult(ex));
                }
            }
        }
        public SelectDocTemplateDialog(Window owner, IEnumerable <FileBlobViewModel> templates, FileBlobViewModel defaultTemplate)
        {
            InitializeComponent();
            Owner = owner;

            _templates = new BindingList <FileBlobViewModel>();
            foreach (var item in templates)
            {
                _templates.Add(item);
            }

            // Add a no-template option.
            FileBlob noTemplate = new FileBlob(templates.First().Model.Connection);

            noTemplate.id   = -1;
            noTemplate.Name = "NONE";

            FileBlobViewModel noVm = new FileBlobViewModel(noTemplate, null);

            _templates.Insert(0, noVm);
            if (defaultTemplate == null)
            {
                _selectedTemplate = noVm;
            }
            else
            {
                _selectedTemplate = defaultTemplate;
            }
        }
        public static void SaveBlobView(DSModel db, KeyBinder key, FileBlobViewModel model)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (model.BlobID == 0)
            {
                throw new ArgumentException("BlobID cannot be 0!", "model");
            }

            string sql = @"
                UPDATE file_blobs f
                SET
                  f.BlobName = @BlobName, f.BlobDescription = @BlobDescription, f.BlobExtension = @BlobExtension
                WHERE
                  f.BlobID = @BlobID;";

            db.ExecuteNonQuery(sql,
                               new MySqlParameter("BlobID", model.BlobID),
                               new MySqlParameter("BlobName", model.BlobName),
                               new MySqlParameter("BlobDescription", model.BlobDescription),
                               new MySqlParameter("BlobExtension", model.BlobExtension));
        }
Ejemplo n.º 4
0
        public CheckResult DeleteFile(FileBlobViewModel model)
        {
            FileBlobModel mod = new FileBlobModel();

            mod.BlobID = model.BlobID;

            return(this.DeleteFile(mod));
        }
Ejemplo n.º 5
0
        public static CheckResult ValidateSaveView(DSModel db, FileBlobViewModel model)
        {
            CheckResult res = new CheckResult(model);

            if (string.IsNullOrWhiteSpace(model.BlobName))
            {
                res.AddError("File name cannot bet empty!", model.GetName(p => p.BlobName));
            }
            if (string.IsNullOrWhiteSpace(model.BlobExtension))
            {
                res.AddError("File extension cannot be empty!", model.GetName(p => p.BlobExtension));
            }

            return(res);
        }
Ejemplo n.º 6
0
        public CheckResult PreviewFile(FileBlobViewModel model)
        {
            CheckResult res = new CheckResult(model);

            using (var db = DB.GetContext())
            {
                var file = FileBlobRepository.GetBlob(db, model.BlobID);
                if (file == null)
                {
                    res.AddError("No such file!", string.Empty);
                    return(res);
                }

                string directory = Path.Combine(Environment.CurrentDirectory, "files");
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string fileName = Path.Combine(directory, ExtensionMethods.SafeFileName(file.BlobName) + file.BlobExtension);
                if (File.Exists(fileName))
                {
                    try
                    {
                        File.Delete(fileName);
                    }
                    catch (Exception ex)
                    {
                        return(new CheckResult(ex));
                    }
                }

                try
                {
                    File.WriteAllBytes(fileName, file.BlobData);
                    ProcessStartInfo info = new ProcessStartInfo(fileName);
                    info.UseShellExecute = true;
                    Process.Start(info);
                    return(res);
                }
                catch (Exception ex)
                {
                    return(new CheckResult(ex));
                }
            }
        }
Ejemplo n.º 7
0
        void gridViewFiles_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            FileBlobViewModel mod = gridViewFiles.GetRow(e.RowHandle) as FileBlobViewModel;

            if (mod == null)
            {
                return;
            }

            if (e.Clicks == 2 || e.Column.Name == col_Preview.Name)
            {
                var res = this.Manager.PreviewFile(mod);
                if (res.Failed)
                {
                    Mess.Error(res.Message);
                }
            }
            else if (e.Column.Name == col_Delete.Name)
            {
                if (Mess.Question("Are you sure you want to delete this file?") == DialogResult.Yes)
                {
                    var res = this.Manager.DeleteFile(mod);
                    if (res.Failed)
                    {
                        Mess.Error(res.Message);
                    }
                    else
                    {
                        this.Manager.RefreshFileList();
                    }
                }
            }
            else if (e.Column.Name == col_Edit.Name)
            {
                if (XF_FileBlobNewEdit.F_ShowEdit(mod.BlobID) == DialogResult.Yes)
                {
                    this.Manager.RefreshFileList();
                }
            }
        }
 private void okButton_Click(object sender, RoutedEventArgs e)
 {
     _selectedTemplate = (FileBlobViewModel)templateListBox.SelectedItem;
     this.DialogResult = true;
     Close();
 }