ERP general attachment management function design and implementation

Source: Internet
Author: User

In the ERP system, you need to manage the attachments uploaded by users for documents, such as VAT invoices, return invoices, and ROHS inspection reports, A general attachment management module is designed to manage uploaded attachments.

Data Table Design

 If Object_id ( 'Dbo. attachment' ) Is   Not   Null      Drop   Table DBO. Attachment Go  Create   Table DBO. Attachment ( Index          Int   Not   Null , Mastertable nvarchar (50) Default ('' ) Not   Null , Masterkey Decimal (10) Default (0 )) Not   Null , Filetype nvarchar (10) Default ( '' ) Not   Null , Filepath nvarchar (250) Null , Createddate datetime Null , Createdby nvarchar (10) Null , Reviseddate datetimeNull , Revisedby nvarchar (10) Null , Description nvarchar (60) Null , Keysegment1 nvarchar (30) Null , Keysegment2 nvarchar (30) Null , Keysegment3 nvarchar (30) Null , Keysegment4 nvarchar (30) Null , Keysegment5 nvarchar (30) Null , Size           Decimal (18) Null , File Image Null , Uploadedby nvarchar (10) Null , Uploadeddate datetime Null , Md5hash nvarchar (32) Null , Constraint Pk_attachment Primary   Key ( Index , Mastertable, masterkey )) Go 
 
 

Five key segments are used to find attachments, which is equivalentArticleIs used to mark the approximate content of the attachment. The actual search function of the attachment content is not provided here, but only the configured key segment is searched and compared. In another project, data solution, I searched for the file byte stream stored in SQL Server and tried it.

Four required fields, created by, created date, revised by, and revised date, are used to record the users who create and modify attachments, and play a role in IT audit. In the ERP system, the log table basically has these four fields for analysis and audit.

Filetype is a custom file type that can be uploaded, such as a fax file TIF, an image file JPG/BMP/GIF, and an office file word/EXCEL/PPT.

There is also a common cross-platform file format PDF.

Note that there is a number 8 on the last button in the toolbar, indicating that this customer has eight attachment files attached. Click this button to bring up the attachment management window.

You can add or delete attachments in the toolbar.

When there are a large number of attachments, you also need to write a general attachment browsing tool to view the attachment content.

Execute the function samfab or sqaptr and open the attachment browser.Program.

Find the customer ID 001, and you can see that it has 8 attachments, which are grouped and presented here.

Double-click an attachment icon file. File Explorer can open its content for you to browse online. If you want to save the attachment to your local computer, you can select the attachment and click the export button in the toolbar. The Save As dialog box appears to save the attachment document for you.

The tree on the left is read from a configuration file, which saves the data table category for loading to different module groups.

The method for reading this file is the LINQ to XML technology. After mastering the LINQ technology, the complex reading and writing functions can be completed in a few simple words,CodeSimple and easy to maintain.

 String SQL = Kingston. systemadminstration. properties. Resources. libraryexplorer; Byte [] Array = encoding. ASCII. getbytes (SQL); memorystream stream = New Memorystream (array); xdocument Doc = xdocument. Load (Stream ); String Library = Doc. Root. Name. tostring (); Treeview. beginupdate (); Treeview. nodes. Clear (); ultratreenode root = New Ultratreenode (library, library); root. Tag = "Library" ; Root. leftimages. Add (imglist. Images [0]); Foreach (Xelement Node In Doc. Root. Elements () {ultratreenode module = New Ultratreenode (node. Name. tostring (), node. Name. tostring (); module. Tag = "Module" ; Module. leftimages. Add (imglist. Images [1]); Foreach (Xelement tableIn Node. Elements () {ultratreenode tablenode = New Ultratreenode (table. Attribute ( "Name" ). Value, table. Attribute ( "Name" ). Value); tablenode. Tag = "Table" ; Tablenode. leftimages. add (imglist. images [2]); module. nodes. add (tablenode);} root. nodes. add (module);} Treeview. nodes. add (Root); Treeview. endupdate ();

The source file is embedded in the Assembly. When being read, it is a string. xdocument can accept a file name or a byte stream. Therefore, I will convert it into a stream in the first few sentences for LINQ to parse.

 

In system settings, a parameter controls how attachments are stored. Whether the system saves the attachment path or the attachment content (byte stream ).

, Set attachment save into database in the last item of control checklist, that is, save the byte stream of the attachment to the data (image) field. This option will affect the database size, but it also has good portability.

Take the file stored locally as an example. It only performs a simple copy action on the file. The Code is as follows:

 
Attachmententity attachment = item. TagAsAttachmententity; savefiledialog savedialog =NewSavefiledialog (); savedialog. Filter ="Excel 97-2003 | *. xls | Microsoft Word | *. Doc | Adobe PDF | *. pdf | all file | *.*"; Savedialog. filename = attachment. filepath;If(Savedialog. showdialog () = dialogresult. OK ){StringFilename = savedialog. filename;If(!String. Isnullorwhitespace (attachment. filepath) {file. Copy (attachment. filepath, savedialog. filename );}}

VB or Delphi Program habits, will drag a savefiledialog component (Component) to the interface, and then directly reference here. I prefer to directly create a savefiledialog here and use it to dispose it when it is used up. Use it and burn it. When talking about the employment relationship between people in the movie, this sentence is often used and discarded when it is used up.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.