Batch delete data

Development tools and key technologies: Visual Studio and C # and javascript

Author: Huang Can

Write time: 2019.5.7

Batch delete data, you need to get the selected data, determine what the selected data is greater than zero, the selected data is greater than zero; otherwise the data is not selected, the user is prompted to select the data to be deleted. If the selected data is greater than zero, we need to declare a string by string to splice and dividing the selected data, because the bulk delete can select unlimited data, so a for loop, loop selected data with a symbol to splice id be spliced ​​into the selected data string

Here Insert Picture Description

Since substring () method for extracting a character string intermediary between two specified index, the substring (start, stop) method returns a character substring comprises at the start, but does not include the character at the stop, so to remove the last symbol. After completion string stitching, write a message asking the user to determine ask whether you want to delete the selected information. Users click OK, the post method using jquery controller request, key-value pairs used for mass participation with the controller, function parentheses custom name in English or a controller for receiving empty pass over the message to return the page displayed for the user, the method of execution controller after deleting the data need to re-load the data query, data is redirected to the first page displayed to the user viewing

Here Insert Picture Description

Methods controller

Receiving a string parameter passing over the selected data, declare a string message to return the data to the user viewing the page. Two int type declaration, a record for the number of deleted pieces of data successfully, a number of data records to delete failed, determines whether the string is empty, empty data is abnormal is prompted, not empty the splicing with Split The divided stitching id good sign, as an array of strings is spliced, so it should declare an array of strings
Here Insert Picture Description

Foreach loop string data, id is divided good string inside the splice. Trapping try and catch exceptions, the string type data into int type data, the data query according to the Employees table selection data ID, then delete query the employee data table

Here Insert Picture Description

User roles and user tables with a single list of data deletion, as if there is no new time with new user roles and user list table information, you do not need to query list with user roles and user tables based on the user ID obtained delete information

The new time if there are new user lists and user roles table, you need to get to the user's user ID, user query role in the role list detailed information to be deleted according to the obtained user ID, and then delete query out of the role of the user detailed information, also you need to delete user information according to the obtained user ID of the user query tables need to remove the user information, check out after.

Delete the employee table, user roles list, the user table information, you need to save the database, increasing the number of self-delete after a successful save

Here Insert Picture Description

catch is a catch exceptions

Data from abnormal, then it increases the number of deleted data, the first step to declare a string to the user to watch how many total data delete, delete success how many, how many delete failed

Finally, the need to prompt the user data passed to json javascript to display the form page prompts the user to watch

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_44542088/article/details/89928686