Пример #1
0
        private void barButtonItemAddFile_ItemClick(object sender, ItemClickEventArgs e)
        {
            var addForm = new FileEditWindow();

            if (addForm.ShowDialog() == DialogResult.OK)
            {
                using (var context = new ConstructionDataContext())
                {
                    context.Database.Log = PrintLog;
                    var file = new File
                    {
                        FileName = addForm.FileName,
                        Type     = addForm.FileType
                    };
                    if (!file.Exists(context))
                    {
                        try
                        {
                            file.Add(context);
                            DisplayFiles();
                        }
                        catch (Exception exception)
                        {
                            ShowException(exception, "Add file failed.");
                        }
                    }
                    else
                    {
                        MessageBox.Show(
                            $"The type of file has existed, please try another name. {file.Type}|{file.FileName}");
                    }
                }
            }
        }
Пример #2
0
        private void barButtonItemSaveAs_ItemClick(object sender, ItemClickEventArgs e)
        {
            var control = GetControl();

            if (control == null)
            {
                return;
            }
            //todo: implement
            var window = new FileEditWindow
            {
                FileName = control.DataEdit.File.FileName + "_Copy",
                FileType = control.DataEdit.File.Type
            };

            if (window.ShowDialog() == DialogResult.OK)
            {
                var file = new File {
                    FileName = window.FileName
                };
                if (file.Exists(control.Context))
                {
                    MessageBox.Show($"The file name {file.FileName} has existed.");
                    return;
                }

                control.DataEdit.SaveAs(window.FileName, window.FileType, window.Description, this, this);
                DisplayFiles();
            }
        }