Process the draft application form of the workflow module in the Winform development framework.
When we develop the workflow module, sometimes we do not want to submit approval during the application process, so we can save it as a draft for further filling or submission, therefore, the draft function is more practical. Otherwise, for some applications with more content filled in, the user will be scolded for entering a lot of data each time. From the perspective of the user, the saved draft function is friendly. This article describes how to use a common storage method in the workflow module to store and display information about the draft application form.
1. fill in the application form
Before submitting an application, we generally need to fill in relevant information, as shown in the following interface.
This form does not record much information, but it is also necessary to provide the function of saving as draft. All our application forms provide this standard function.
Or a complicated application form.
In the past, I saved a draft, copied the record to the formal application form, and set it to the draft State. This method can be implemented, but it is difficult to process it in a unified manner, this article describes all the drafts stored in a table. We define some fields to store JSON data corresponding to the information. When necessary, resolve them to the corresponding objects one by one, in this way, we can encapsulate the logic of [Save as draft] in the base class form.
2. Draft function implementation
First, we define a data table that stores draft information, either for a single table or for a Master/Slave table. We can store it as a corresponding JSON field. The data table of the design draft is as follows.
In the Basic Form filled in the application form, we define the interface as follows.
Then, we provide a general business draft save handler in the base class for the subclass to call.
/// <Summary> /// Save the draft /// </summary> /// <param name = "title"> draft title </param> /// <param name = "mainJson"> main business form data </param> // <param name = "detailJson"> business form data from the table (null if no data exists) </param> /// <param name = "detailJson2"> business form data from the table (null if none exist) </param> /// <param name = "detailJson3"> business form data from the table (null if none exist) </param> // <returns> </returns> protected virtual void SaveDraft (string title, string mainJson, string detailJson = null, String detailJson2 = null, string detailJson3 = null) {var formInfo = BLLFactory <BLL. form>. instance. findByID (this. formID); ArgumentCheck. begin (). notNull (formInfo, "form object"); var infoDraft = new ApplyDraftInfo (); if (! String. isNullOrEmpty (this. draftId) {infoDraft. ID = this. draftId; // update if existing} infoDraft. bizDraftJson = mainJson; infoDraft. bizDraftJson2 = detailJson; infoDraft. bizDraftJson3 = detailJson2; infoDraft. bizDraftJson4 = detailJson3; infoDraft. form_ID = this. formID; infoDraft. formName = formInfo. formName; infoDraft. category = formInfo. category; infoDraft. title = title; infoDraft. creator = LoginUserInfo. ID; infoDraft. createTime = DateTime. now; var flag = BLLFactory <ApplyDraft>. instance. insertUpdate (infoDraft, infoDraft. ID); MessageDxUtil. showTips ("save draft-" + (flag? "Successful": "failed"); if (flag) {this. DialogResult = System. Windows. Forms. DialogResult. OK ;}}
We can see that the draft can be added or updated. If an existing draft is edited again, no other record is added, but the original record is modified.
The following page shows how to process an application for a common single table.
How is the functional code used to save the draft implemented?
/// <Summary> /// Save the draft for processing /// </summary> private void btnSaveDraft_Click (object sender, EventArgs e) {string title = string. format ("{0} payment application form [{1}] (draft)", LoginUserInfo. fullName, DateTime. now. toShortDateString (); var info = tempInfo; // you must use an existing local variable because some information may be appended with SetInfo (info); info. creator = base. loginUserInfo. ID; info. createTime = DateTime. now; // Save the draft: Convert the object information to JSON to save the SaveDraft (title, info. toJson ());}
Here, you can actually get the corresponding form information and convert it to JSON storage.
For example, the reimbursement page for the expense and expense details is as follows.
So what are the differences in the processing of drafts?
In the subclass of the application form, click Save As draft to process the event. The Code is as follows.
/// <Summary> // Save the processing of the draft application form /// </summary> private void btnSaveDraft_Click (object sender, EventArgs e) {string title = string. format ("{0}'s {1} reimbursement application form [{2}] (draft)", LoginUserInfo. fullName, this.txt Category. text, DateTime. now. toShortDateString (); var info = tempInfo; // you must use an existing local variable because some information may be appended with SetInfo (info); info. creator = base. loginUserInfo. ID; info. createTime = DateTime. now; // get expense details var list = GetDetailList (); // Save the draft for processing: if there are multiple details, you can add them to the SaveDraft (title, info. toJson (), list. toJson ());}
Here we need to convert the object of expense information and detail information into a JSON object, and then uniformly call the save draft function of the base class.
For loading draft information and restoring it to display the actual form information, our processing code is to parse the JSON object, convert it to the actual form object, and then assign a value to display the interface, as shown in the following code.
After this is done, we can store and display drafts in the actual application business.
3. interface code generation
The above code is relatively simple, but we can use the code generation tool Database2Sharp to generate the interface code to develop the workflow module more efficiently, at the same time, save the draft, attachment processing and other code are generated together, you can use it directly.
For the master-slave table interface, you can still use the code generation tool to quickly generate the workflow interface.
For how to use this function, I will introduce the process in detail later.
Workflow series of WInform development framework:
Simple WorkFlow Design Based on Winform development framework
Table Design and Analysis of the workflow module in the Winform development framework
Business form development of the workflow module in the Winform development framework
Approval and signing of the workflow module in the Winform development framework
Workflow module approval and signing in Winform development framework (2)
Implement business approval for the workflow module in the Winform development framework with reference to the enterprise approval business
Process the draft application form of the workflow module in the Winform development framework