// create and preview daily style
 private void day_Click(object sender, RoutedEventArgs e)
 {
     Utils.MakeDay(_printDoc);
     _printDoc.Save("day.c1d");
     // clear and re-load to be sure that all works when document is loaded from file
     _printDoc.Clear();
     _printDoc.Load("day.c1d");
     Preview();
 }
        /// <summary>
        /// Loads style definition to the specified C1PrintDocument control.
        /// </summary>
        /// <param name="printDoc">The <see cref="PrintDocumentWrapper"/> object.</param>
        /// <returns>Returns true at successful loading; false - otherwise.</returns>
        public bool Load(C1PrintDocument printDoc)
        {
            if (String.IsNullOrEmpty(StyleSource))
            {
                return(false);
            }
            printDoc.Clear();

            // load document
            Stream sr = ResourceLoader.GetStream(StyleSource);

            if (sr != null)
            {
                printDoc.Load(sr, DocumentFormat);
                sr.Dispose();
            }
            else
            {
                printDoc.Load(StyleSource, DocumentFormat);
            }

            if (String.IsNullOrEmpty(StyleName))
            {
                // fill name and description from document
                StyleName = (string)printDoc.DocumentInfo.Title;
                if (String.IsNullOrEmpty(StyleName))
                {
                    StyleName = _owner.GetUniqueStyleName();
                }
            }
            if (String.IsNullOrEmpty(_description))
            {
                _description = (string)printDoc.DocumentInfo.Subject;
            }
            return(true);
        }
예제 #3
0
        public bool OpenFile(string filePath, bool addToJumpList = true)
        {
            if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
            {
                OpenFileDialog ofd = new OpenFileDialog();
                if (!string.IsNullOrEmpty(filePath))
                {
                    if (!Directory.Exists(filePath))
                    {
                        filePath = Path.GetDirectoryName(filePath);
                    }
                    if (Directory.Exists(filePath))
                    {
                        ofd.InitialDirectory = filePath;
                    }
                }
                ofd.Filter = "All C1 Documents (*.c1dx;*.c1d;*.c1mdx)|*.c1dx;*.c1d;*.c1mdx|C1 Open XML Documents (*.c1dx)|*.c1dx|C1 Documents (*.c1d)|*.c1d|C1 Open XML Multi Documents (*.c1mdx)|*.c1mdx|All Files (*.*)|*.*";
                bool res = ofd.ShowDialog() == DialogResult.OK;
                filePath = ofd.FileName;
                ofd.Dispose();
                if (!res)
                {
                    return(false);
                }
            }

            object doc = null;
            string ext = Path.GetExtension(filePath).ToLowerInvariant();

            try
            {
                if (ext == ".c1dx")
                {
                    var dx = new C1PrintDocument();
                    dx.Load(filePath, C1DocumentFormatEnum.C1dx);
                    doc = dx;
                }
                else if (ext == ".c1d")
                {
                    var dx = new C1PrintDocument();
                    dx.Load(filePath, C1DocumentFormatEnum.C1d);
                    doc = dx;
                }
                else if (ext == ".c1mdx")
                {
                    var mdx = new C1MultiDocument();
                    mdx.Load(filePath);
                    doc = mdx;
                }
                else
                {
                    MessageBox.Show("Can't open file with \"" + ext + "\" extension.", "C1PrintDocument Viewer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (doc != null)
            {
                Text         = Path.GetFileNameWithoutExtension(filePath);
                rpc.Document = doc;
                if (addToJumpList && CheckFileRegistration())
                {
                    atb.JumpList.AddToRecentCategory(filePath);
                }
                return(true);
            }
            return(false);
        }