Beispiel #1
0
 /// <summary>
 /// 调用下层的删除合同类型的方法
 /// </summary>
 protected override void ExcuteSelf()
 {
     try
     {
         using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
         {
             _DalContractType.DeleteContractType(_ContractTypeId);
             _ContractBookMark.DeleteContractBookMarkByContractTypeID(_ContractTypeId);
             ts.Complete();
         }
     }
     catch
     {
         BllUtility.ThrowException(BllExceptionConst._DbError);
     }
 }
        private void CreateBookMark()
        {
            if (_ContractType.ContractTemplate != null)
            {
                if (!Directory.Exists(_TempWordLocation))
                {
                    Directory.CreateDirectory(_TempWordLocation);
                }
                //生成临时word文档
                byte[]     bytes = _ContractType.ContractTemplate;
                FileStream fs    = new FileStream(_TempWordName, FileMode.Create, FileAccess.Write);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                fs.Close();

                Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
                object nothing    = Type.Missing;
                object localPatho = _TempWordName;
                Microsoft.Office.Interop.Word.Document doc =
                    app.Documents.Add(ref localPatho, ref nothing, ref nothing, ref nothing);
                try
                {
                    //将word的书签写入数据库
                    System.Collections.IEnumerator enu = app.ActiveDocument.Bookmarks.GetEnumerator();
                    _ContractBookMark.DeleteContractBookMarkByContractTypeID(_ContractType.ContractTypeID);
                    while (enu.MoveNext())
                    {
                        Microsoft.Office.Interop.Word.Bookmark bk = (Microsoft.Office.Interop.Word.Bookmark)enu.Current;
                        _ContractBookMark.InsertContractBookMark(
                            new ContractBookMark(0, _ContractType.ContractTypeID, bk.Name));
                    }
                }
                finally
                {
                    doc.Close(ref nothing, ref nothing, ref nothing);
                    app.Quit(ref nothing, ref nothing, ref nothing);
                }
            }
        }