//============================================================================= /// <summary> /// Initialize document template which is used for creating new documents. /// </summary> private void _InitializeDocumentTemplate() { // STEP 1. // Try to read template from the embedded resource. Assembly assembly = Assembly.GetExecutingAssembly(); string resourceName = "RackDrawingApp.Properties.DocumentTemplate.rda"; // Debug code - displays all resources in the assembly. //List<string> strResourcesList = new List<string>(); //foreach (string s in assembly.GetManifestResourceNames()) // strResourcesList.Add(s); if (true) { using (Stream stream = assembly.GetManifestResourceStream(resourceName)) { try { DrawingDocument.ClearErrors(); BinaryFormatter bf = new BinaryFormatter(); m_DocumentTemplate = (DrawingDocument)bf.Deserialize(stream); // Use this template if no errors occurred while read template. if (DrawingDocument._sDontSupportDocument || DrawingDocument._sNewVersion_StreamRead > 0 || DrawingDocument._sStreamReadException > 0) { m_DocumentTemplate = null; } } catch { } } } // STEP 2. // There was problem when read document template from the embedded resource. // Create document template using default constructor and read excel file. if (m_DocumentTemplate == null) { m_DocumentTemplate = new DrawingDocument(this); } // Set parameters. m_DocumentTemplate.CustomerName = UserInfo.CustomerName; m_DocumentTemplate.CustomerENQ = UserInfo.EnqNo; m_DocumentTemplate.CustomerContactNo = UserInfo.CustomerContactNo; m_DocumentTemplate.CustomerEMail = UserInfo.CustomerEmailID; m_DocumentTemplate.CustomerAddress = UserInfo.CustomerBillingAddress; m_DocumentTemplate.CustomerSite = UserInfo.CustomerSiteAddress; }
//============================================================================= 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); }