Beispiel #1
0
        private void btnAppendix_Click(object sender, EventArgs e)
        {
            var index = (int)ddlWord.SelectedValue;

            FileAppendix f;

            if (index == -1)
            {
                f = new FileAppendix();
            }
            else
            {
                f = (FileAppendix)_appendix.Appendixs[index];
            }

            using (OpenFileDialog file = new OpenFileDialog())
            {
                if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (index == -1)
                    {
                        if (_appendix.Appendixs == null)
                        {
                            _appendix.Appendixs = new List <ToWord.Appendix>();
                        }

                        f.Type     = 1;
                        f.Title    = file.SafeFileName.Substring(0, file.SafeFileName.LastIndexOf("."));
                        f.FileName = new Content()
                        {
                            ConType = "附件中附件", ConContent = file.FileName
                        };
                        f.FilePath = file.FileName;
                        _appendix.Appendixs.Add(f);
                        DDLSource source = new DDLSource()
                        {
                            Index = _appendix.Appendixs.Count - 1, Text = "【文件】" + f.Title
                        };
                        dDLSourceBindingSource.List.Add(source);
                    }
                    else
                    {
                        _appendix.Appendixs[index] = f;
                        ((DDLSource)dDLSourceBindingSource.Current).Text = "【文件】" + f.Title;
                        BindDDL();
                    }
                }
            }
        }
Beispiel #2
0
        private void AddAppendixFiles(FileAppendix fa)
        {
            var style = config.FontStyles.Find(w => w.FontName == "附件题目");

            word.AddContent(fa.Title, style);

            if (fa.FilePath.EndsWith(".xls") || fa.FilePath.EndsWith(".xlsx"))
            {
                word.AddExcel(fa.FilePath);
            }
            else
            {
                word.AddImage(fa.FilePath);
            }
        }
Beispiel #3
0
        private void btnAppendix_Click(object sender, EventArgs e)
        {
            DataVerifier dv = new DataVerifier();

            dv.Check(n == null, "请先添加通知模板再添加附件");

            if (dv.Pass)
            {
                var index = (int)ddlWord.SelectedValue;

                FileAppendix f = null;

                if (index == -1)
                {
                    f = new FileAppendix();
                }
                else
                {
                    dv.Check(n.Appendixs[index].Type != 1, "修改附件时请选择对应的附件类型");
                    if (dv.Pass)
                    {
                        f = (FileAppendix)n.Appendixs[index];
                    }
                }

                if (dv.Pass)
                {
                    using (OpenFileDialog file = new OpenFileDialog())
                    {
                        if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            if (index == -1)
                            {
                                f.Type     = 1;
                                f.Title    = file.SafeFileName.Substring(0, file.SafeFileName.LastIndexOf("."));
                                f.FileName = new Content()
                                {
                                    ConType = "附件", ConContent = file.FileName
                                };
                                f.FilePath = file.FileName;
                                if (n.Appendixs == null)
                                {
                                    n.Appendixs = new List <Appendix>();
                                }
                                n.Appendixs.Add(f);
                                DDLSource source = new DDLSource()
                                {
                                    Index = n.Appendixs.Count - 1, Text = "【文件】" + f.Title
                                };
                                dDLSourceBindingSource.List.Add(source);
                            }
                            else
                            {
                                n.Appendixs[index] = f;
                                ((DDLSource)dDLSourceBindingSource.Current).Text = "【文件】" + f.Title;
                                BindDDL();
                            }
                        }
                    }
                }
            }

            dv.ShowMsgIfFailed();
        }