//============================================================================= private void CreateSheetButton_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn == null) { return; } MainWindow_ViewModel mainVM = btn.DataContext as MainWindow_ViewModel; if (mainVM == null) { return; } DrawingDocument curDoc = mainVM.CurrentDocument; if (curDoc == null) { return; } WarehouseSheet curSheet = curDoc.CurrentSheet as WarehouseSheet; if (curSheet == null || curSheet.SingleSelectedGeometry == null) { return; } SheetGeometry sheetGeometry = curSheet.SingleSelectedGeometry as SheetGeometry; if (sheetGeometry == null) { return; } if (sheetGeometry.BoundSheet != null) { return; } DrawingSheet newSheet = new DrawingSheet(curDoc); if (newSheet != null) { newSheet.Set_Length((UInt32)Utils.GetWholeNumber(sheetGeometry.Length_X), false, false); newSheet.Set_Width((UInt32)Utils.GetWholeNumber(sheetGeometry.Length_Y), false, false); curDoc.AddSheet(newSheet, false); sheetGeometry.BoundSheet = newSheet; curDoc.MarkStateChanged(); } }
//============================================================================= public async Task <bool> OpenDrawing(string strDrawingPath) { DrawingDocument.ClearErrors(); if (string.IsNullOrEmpty(strDrawingPath)) { return(false); } if (!File.Exists(strDrawingPath)) { await this.DisplayMessageDialog("Cant open document \"" + strDrawingPath + "\". File doesnt exist."); return(false); } // bool bIsNewDocOpened = false; try { FileStream fs = new FileStream(strDrawingPath, FileMode.Open); if (fs != null) { BinaryFormatter bf = new BinaryFormatter(); DrawingDocument doc = (DrawingDocument)bf.Deserialize(fs); doc.DisplayDialog = this; doc.Path = strDrawingPath; // save old document if new document is not correct and user dont want to fix it DrawingDocument oldDoc = this.CurrentDocument; // this.CurrentDocument = doc; bool bCorrect = await doc.CheckDocument(true, false); // if opened document is not correct then set old document if (!bCorrect) { this.CurrentDocument = oldDoc; } else { doc.MarkStateChanged(); doc.RemoveAllStatesExceptCurrent(); bIsNewDocOpened = true; // Clear changed sheets guids. DrawingSheet.m_ChangedSheetsGuidsSet.Clear(); } // fs.Close(); fs.Dispose(); } } catch { } // if (DrawingDocument._sDontSupportDocument) { // open document which is not supported SaveChangesDialog_ViewModel saveChanges_VM = new SaveChangesDialog_ViewModel(); saveChanges_VM.Text = "This document has very old version, its not supported. Save this document in this application possibly lead to data loss."; saveChanges_VM.IsSaveButtonVisible = false; saveChanges_VM.IsCancelButtonVisible = false; SaveChangesDialog saveChangesDialog = new SaveChangesDialog(saveChanges_VM); //show the dialog // true - save // false - cancel // null - continue var result = await DialogHost.Show(saveChangesDialog); } else if (DrawingDocument._sBiggerMajorNumber > 0) { await this.DisplayMessageDialog("An error occurred while opening document. Document was created in the new version of the application and doesnt supported in this application version.\nDocument was not opened."); return(false); } else if (DrawingDocument._sNewVersion_StreamRead > 0) { // open new document in old version application SaveChangesDialog_ViewModel saveChanges_VM = new SaveChangesDialog_ViewModel(); saveChanges_VM.Text = "This document was created\\saved in the new version of application. It can be drawn or working incorrect. Save this document in this application possibly lead to data loss."; saveChanges_VM.IsSaveButtonVisible = false; saveChanges_VM.IsCancelButtonVisible = false; SaveChangesDialog saveChangesDialog = new SaveChangesDialog(saveChanges_VM); //show the dialog // true - save // false - cancel // null - continue var result = await DialogHost.Show(saveChangesDialog); } else if (DrawingDocument._sStreamReadException > 0) { // SaveChangesDialog_ViewModel saveChanges_VM = new SaveChangesDialog_ViewModel(); saveChanges_VM.Text = "Exceptions ocurred while open document. It can be drawn or working incorrect. Save this document in this application possibly lead to data loss."; saveChanges_VM.IsSaveButtonVisible = false; saveChanges_VM.IsCancelButtonVisible = false; SaveChangesDialog saveChangesDialog = new SaveChangesDialog(saveChanges_VM); //show the dialog // true - save // false - cancel // null - continue var result = await DialogHost.Show(saveChangesDialog); } else { if (bIsNewDocOpened && this.CurrentDocument != null) { // ENQ number is neccessaru for any kind of export. // Display the message if it is empty. if (string.IsNullOrEmpty(this.CurrentDocument.CustomerENQ)) { await this.DisplayMessageDialog("ENQ number is neccessary for any kind of export. Please go to the Customer Info and input ENQ number."); } else { // Check that ENQ number can be used as a filename for the text file. if (this.CurrentDocument.CustomerENQ.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { await this.DisplayMessageDialog("ENQ number contains incorrect characters for the filename. Please go to the Customer Info and edit ENQ number."); } else if (this.CurrentDocument.NameWithoutExtension != this.CurrentDocument.CustomerENQ) { await this.DisplayMessageDialog("ENQ number is different from the document name. Please use ENQ number as a document name."); } } return(true); } } return(false); }