Write your own C # framework (23) from scratch-Upload Component instructions for use,

Source: Internet
Author: User
Tags dotnet

Write your own C # framework (23) from scratch-Upload Component instructions for use,
Article navigation

1. Preface 2. Upload Component function description 3. database structure 4. Upload Configuration Management 5. categories used by Upload components 6. Upload Component call Method 7. effect demonstration 8. Summary

 

 

1. Preface

This series uses the upload component developed by July, which is relatively low-profile and has never been written into blogs. In order to thank Him for opening up such a good plug-in, I would like to publicize it for him. In my circle, he is a very good man. He is very proficient in front-end and cannot solve the compatibility problem, backend development is also proficient in a variety of development languages (PHP, C #, VB, JAVA, etc.), with over a hundred large, medium, and small projects developed by hand. If you want to contact him for outsourcing development, you can join the Q group 327360708 to find July.

 

2. Upload Component Function Description

This Upload Component has encapsulated all upload-related functions. When using this component, you only need to use a few simple lines of code, this allows you to inspect image files, verify upload permissions, create folders related to upload paths, upload files, and generate various specifications (scale) According to configurations) image and compression, watermarking, joining data tables, automatically deleting old files and data table records, and re-generating all image files after Configuration modification.

Supports asp.net control, html control, editor (also divided into local upload and remote upload) and swf (this control upload method has not been used, it is not clear how to call it at present, if you have time, please consult July.

 

3. Database Structure

This Upload Component needs to create three data tables

  The upload type table is used to set the types of files that can be uploaded.

  

 

Upload the configuration table. You can see the field description for its purpose. We mainly use it for processing uploaded images, for example, to upload an image, you need to generate those formats (large, medium, small, and recommended images). What are the image specifications (width, height, and quality)? No watermarks are required, according to the proportion of the generated image, the configuration will take effect immediately after the configuration here, and the size of the uploaded image will change accordingly.

  

 

The Upload File Management table records all the File Information uploaded to the server through this Upload Component in the current system, facilitating administrator management operations. For example, after the front-end UI is redesigned, some page image specifications have changed. Under normal circumstances, the designer needs to manually or use some software to re-modify all these images, so that the processing workload is heavy and error-prone, this component can reset the image generation specifications of different sizes in the upload configuration, and then click the regenerate button for all images, the program will generate all the images of the specified type and configuration in this management table according to the new configuration and use the original file names one by one.

  

 

4. Upload Configuration Management

1) log on to the backend management system and choose System Management> basic Settings> upload type settings.

To add and manage various file types that can be uploaded, see

  

  

 

2) System Management = Basic settings = upload Configuration Management

Set various upload rules here. All the parts that need to be called to upload components must be configured here. Obtain the corresponding Id value after creation and bind the record to the developed code. How to use it will be discussed later

Upload configuration list

  

Upload configuration editing page

  

On the ad content management page, we uploaded an ad image.

  

This is the generated image in the upload folder after the upload is successful. You can try to modify the generated specification and upload the image again, or click on the "uploaded file management" page to see the image changes.

  

 3) System Management = Basic settings = uploaded files management

All records uploaded to the server through this Upload Component are displayed here. You can delete unnecessary files directly, or click the "generate all images" button to generate images.

  

 

 

5. Class used by the Upload Component

The class storage path and description used for uploading components (although the original version is hierarchical, but there are not so many files, SQLHelper is used to execute database updates, which seems complicated to me, haha... does it look a little tall? It's hard to understand and complex to look at + _ + ...)

Project Folder path File Name Description
DotNet. Utilities File DirFileHelper. cs Folder and file operation class, mainly used for creating folders, adding and deleting uploaded files, and other related file operation functions
DotNet. Utilities Uploader Uploader. cs Upload class, file upload, check, generation, watermark, and other operations
Solution. DataAccess SubSonic

UploadConfig. cs

UploadFile. cs

UploadType. cs

......

Upload Component data table related entity classes generated by the template, and other data layer operation classes
Solution. Logic. Managers Application UploadFileBll. cs The upload logic class is mainly used for permission check, judgment and processing of uploaded files, database information related to add, modify, delete, and upload components, and associated data tables.
Solution. Logic. Managers SubSonic

UploadConfigBll. cs

UploadFileBll. cs

UploadTypeBll. cs

Several logical files corresponding to the upload tables generated by the T4 template are mainly used by the backend management pages.
Solution. Web. Managers Application FileUpload. ashx Upload interface called by the UI Editor
Solution. Web. Managers Application RemoteUpload. ashx The UI editor uses the remote upload interface (when an image is pasted in the editor, the image is downloaded to the server for remote upload)

 

6. Upload Component call Method

There are three methods in the code to call the upload, one is the ASP. NET control, the other is the html control, and the other is the remote upload (that is, the input remote image Url automatically downloads the update)

ASP. NET control upload call Method

1 // This is placed before the Page_Load function of the cs file, used to generate a Key with it, so that after the upload is complete, the uploaded file management table is bound to the corresponding Id 2 protected string RndKey = RandomHelper. getRndKey (); 3 4 # region upload image 5 // determine the front-end ASP. NET upload control whether to select whether there is an uploaded file 6 if (this. filePhoto. hasFile & this. filePhoto. fileName. length> 3) 7 {8 // bind the upload file on the current page to the record with the upload configuration table Id 7, and call 9 int vid = 7 for the logic-layer function of the Upload Component; // 7 advertisement 10 // ------------------------------------------------------- 11 // create upload object 12 var upload = new UploadFile (); 13 // Call ASP. NET upload control upload function, and get the upload success or failure information 14 result = new UploadFileBll (). upload_AspNet (this. filePhoto. postedFile, vid, RndKey, 15 OnlineUsersBll. getInstence (). getManagerId (), OnlineUsersBll. getInstence (). getManagerCName (), 16 upload); 17 this. filePhoto. dispose (); 18 // ----------------------------------------------------- 19 // indicates that the upload is successful 20 if (result. length = 0) 21 {22 // assign the path uploaded to the server to the corresponding field 23 model of the AD entity. adImg = u Pload. path; 24} 25 else26 {27 // write the error into the log 28 CommonBll. writeLog ("Upload error:" + result); // collect exception information 29 // error prompt 30 return "Upload error! "+ Result; 31} 32} 33 // if it is modified, check whether the user has uploaded the ad image again. if it is deleted from the old image 34 if (model. id> 0) 35 {36 // Delete the old image 37 UploadFileBll. getInstence () 38. upload_DiffFile (AdvertisementTable. id, AdvertisementTable. adImg, AdvertisementTable. tableName, 39 model. id, model. adImg); 40 41 // synchronize the UploadFile upload Table Record, bind the file Id that has just been uploaded to the current record Id42 UploadFileBll. getInstence (). upload_UpdateRs (RndKey, AdvertisementTable. tableName, model. id); 43} 44 45 # endregion

For the code function above, please refer to the annotations. Copy the above Code directly during the call and modify the vid value and the name of the page upload control (Change filePhoto to your own name) the name of the current data table (AdvertisementTable, which has been changed during replacement) and the path field for storing the Upload File (Change AdImg to the corresponding field name of the current data table.

 

Html control upload Method

 

1 # region upload Image 2 // bind the upload file on the current page to the record with the upload configuration table Id 7, and call 3 int vid = 7 for the logic layer function of the upload component; // 7 advertisement 4 // ------------------------------------------------------- 5 // create upload object 6 var upload = new UploadFile (); 7 // call ASP. NET upload control upload function, and get the upload success or failure information 8 result = new UploadFileBll (). upload_Web (vid, RndKey, 9 OnlineUsersBll. getInstence (). getManagerId (), OnlineUsersBll. getInstence (). getManagerCName (), 10 upload, "Html upload Control name"); 11 this. fileP Hoto. dispose (); 12 // ----------------------------------------------------- 13 // if no information is returned, the upload is successful. length = 0) 15 {16 // assign the path uploaded to the server to the corresponding field 17 model of the AD entity. adImg = upload. path; 18} 19 else20 {21 // write the error into the log 22 CommonBll. writeLog ("Upload error:" + result); // collect exception information 23 // error prompt 24 return "Upload error! "+ Result; 25} 26 27 // if it is modified, check whether the user has uploaded the ad image again. if it is deleted from the old image 28 if (model. id> 0) 29 {30 // Delete the old image 31 UploadFileBll. getInstence () 32. upload_DiffFile (AdvertisementTable. id, AdvertisementTable. adImg, AdvertisementTable. tableName, 33 model. id, model. adImg); 34 35 // synchronize the UploadFile upload Table Record, bind the file Id that has just been uploaded to the current record Id36 UploadFileBll. getInstence (). upload_UpdateRs (RndKey, AdvertisementTable. tableName, model. id); 37} 38 39 # endregion

 

Unlike the previous upload function called Upload_Web, this code has not been directly tested. Theoretically, it is correct... (previously, the front-end project was used normally, but the code is different from the framework, so it will not be pasted out)

 

 

Remote upload Method

This upload method must be used with the editor. The editor in the framework has been set, so it is not described in detail.

 

7. effect demonstration

1) Upload the ad image, modify the image configuration, and then generate a new demo.

Before the demo, you should update the code and open AdvertisementEdit. aspx. cs file, find AdvertisementBll. getInstence (). save (this, model): After this code, add the following code. The previously released code forgets to add a new record, and the image record Id is bound synchronously.

1 # region synchronously update the uploaded image table. Bind Id2 if (id = 0) 3 {4 // synchronize the UploadFile upload table record. Bind the uploaded file Id to the current record Id5 UploadFileBll. getInstence (). upload_UpdateRs (RndKey, AdvertisementTable. tableName, model. id); 6} 7 8 # endregionView Code

 

Click Add on the ad content management page.

  

Display effect after adding

  

Generated file and size

  

Go to the upload Configuration Management page to modify the advertisement image configuration, as shown in figure

  

Go to the uploaded file list and click "All images" to regenerate

  

View the image size in the folder, which has changed

  

  

2) upload non-image files

Create a text file and enter the content

  

Modify the ghost file name to bbb.jpg

  

Open the ad image editing window, select a fake image named bbb.jpg, and Click Upload

  

The program will determine that the file is not an image and will not be uploaded

  

 

3) Remote Image Upload demonstration

Copy the image from the browser to the editor and Click Upload image remotely.

  

Click to view the Html code. You can see that the Url is remote

  

Open the remote upload process image page and click OK.

  

Uploaded

  

The image displayed in the editor is uploaded.

  

View Html comparison

  

Check the files uploaded in the folder.

  

 

 

 

8. Summary

Here, the description of the code series is over. Looking back at the solution we have set up, there are still many deviations, and I am not satisfied with it. As the work has become increasingly busy in the recent period, there is no longer much time to take into account the compilation of this series, and some details will not be explained, the Code part can only end in the grass.

Sometimes, when you open the previous chapter, you will feel that the writing is rough, no matter what the text or content is described, there are problems. However, during the compilation process, I did get a lot of improvement. During the process of communicating with many friends and friends, I also learned a lot of new knowledge points, I believe that if the time is sufficient, it will not be the same if I have re-written it. It may be like this chapter, but it will only be described for a knowledge point, which will help you better understand it. In addition, many flowcharts or other related figures that need to be drawn are not drawn, let alone videos. These can only be added later.

For the code part, as some friends have said, due to the use of template generation, the Code is not optimized, and there is a lot of redundant code. For now, use it like this, it is also very convenient to use the template to change it. It does not affect the efficiency of secondary development and maintenance development. You can check whether optimization is performed later.

To learn how to develop this framework, you must first have ASP. if you want to learn about framework development at once without the foundation of NET, it is really difficult. Even if you directly ask me via QQ, it is difficult for me to help you skip the basic and directly learn about framework development. In addition, if you don't read the previous article and want to speed up, you can start with the Code directly. If you are a great god, this is no problem. Otherwise, you don't want to take the time to understand the entire development idea, I can't help you either. Unless you work with me, I will spend a day explaining it to you, so you may get started quickly, I can understand this framework completely (I still need to learn it from the previous article ).

In addition, if you encounter problems during the learning process, you can use Debug to solve the problem by yourself. You can no longer go to Baidu or Google to check the problem, or send your question to the comments of the post, or Email me. Of course, it is more convenient to ask in the QQ group. Many friends are happy to answer your questions. You can also ask me directly, but it has been too busy recently. It is impossible for me to answer all kinds of questions in real time. I have to work myself and support my family.

In the process of learning, you must start from the beginning. If you look at it in the middle, especially in the Code section, you will be confused, because it is derived from the above. Of course, if you do not understand chapter 15 to Chapter 20, you can simply understand the content. You can directly use Chapter 21 instructions to perform operations, or create some data tables by yourself, copy and modify the page several times based on the completed page function, then you will get started quickly. After you are familiar with the development of the framework, you can study some technologies of the underlying application, which makes it easier to understand the framework structure.

 

 

During the above demonstration, we found that there were still some minor bugs, so We reorganized and found the modified files and packed them. Please click to download the updates, or download the solution in the previous chapter again.

Solution: modify content .rar

 

 

Copyright:

This article was originally published by AllEmpty and published in the blog Park. You are welcome to repost it. You must keep this statement without your consent and provide the original article link clearly on the article page,Otherwise, the right to pursue legal liability is reserved.. If you have any questions, you can use1654937@qq.comThank you very much for contacting me.

 

As long as you are interested in learning and making progress together, you can add Q group: 327360708 to this topic.

 

For more information, please refer to blog: http://www.cnblogs.com/EmptyFS/

 


How to Learn programming from scratch

Buy an assembly language in the bookstore to learn it. There is no problem with the basics. I learned assembly language in my freshman year, which is similar to your situation. So I may not necessarily learn any advanced mathematics. Assembly mainly started here, mainly to achieve conversions between the hexadecimal, memory structure, DEBUG, addressing mode, and command system. It will be much easier to learn later. Assembly languages are harder to learn than other languages, but assembly languages are more powerful than other languages, such as viruses. Many of them are compiled in assembly. Recommended Assembly Language
 
How to Learn C language from scratch

Don't be fooled by the training center. When I was a freshman, I was fooled by three hundred. However, when I finally passed the course, I learned how to buy a book and set up a computer, VC ++ 6.0 1 download 1 installation, video, PPT, WORD and other tutorials 1 download a little bit every day, and then do the examination online and offline questions. If you do not understand the Internet, please give answers to the experts!

Related Article

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.