ITOO cascading deletion of Master/Slave tables and itoo-level master/Slave tables

Source: Internet
Author: User

ITOO cascading deletion of Master/Slave tables and itoo-level master/Slave tables

The score system has a requirement that the data dictionary has a master-slave table. It requires that the information of the master table be deleted along with the information of the slave table (in connection with the cascading deletion of news comments when the news is deleted in niudi ), in the previous version, only the data in the master table is deleted according to the name of the master table data. If there is a duplicate name, verification is required (it is not reasonable ), now, you need to delete the slave table based on the ID of the master table, and the ID of the master table can also be obtained from the page.

My idea: the html of the master table references two JavaScript codes of the master table and the click method of the button called by the master table has the same name, but it can only find one method to execute it, result After the primary table is deleted, no response is returned from the table.

Later, Li you gave me the idea: Delete the deletion code method triggered by writing the js Code from the table to the master table. The result is the same as the above and only the first method is executed. After the communication, danmei calls the delete method from the table controller in the controller deletion method of the master table and cannot get the value. Finally, let's talk to Liu Jie and Xiao na: Modify the deletion method of the master table, pass the two entities of the master and slave table as parameters, and grant the IDs of the master table obtained from the page to them respectively, the update method for cyclic Master/Slave tables is implemented at Layer B,

# Region DeleteTypeByTypeID -- the slave table information is deleted at the same time when the master table is created. (The master and slave tables are used as parameters) -Li Liping-21:37:40 /// <summary> // The slave table information is deleted at the same time when the master table is created. (The master and slave tables are used as parameters) /// </summary> /// <param name = "listtype"> data type entity set </param> /// <param name = "listValue"> specific data types value entity set </param> /// <returns> indicates whether the object is successfully deleted, success is True, failure is False </returns> public bool DeleteTypeByTypeID (List <DictionaryTypeViewModel> listtype, List <DictionaryViewModel> listValue) {try {// annotation added to the configuration file, call layer B to instantiate DictionaryBll bll = new DictionaryBll (); // first Delete the slave table and then the attached master table, add the table data to be deleted in a loop to the for (int countValue = 0; countValue <listValue. count; countValue ++) {// create an entity rule for deleting specific values of the data dictionary type. ResultDictionaryEntity tempValue = new ResultDictionaryEntity () {isDeleted = 1 // modify the field to 1 after deletion, pseudo deletion, the database still has this record}; Guid typeID = listtype [countValue]. dictionaryTypeId; // The primary table ID assigned to the foreign key of the slave table // call the underlying update method bll. currentDal. update (tempValue, u => u. resultDictionaryTypeEntity_dictionaryTypeId = typeID, "isDeleted");} // bll. dbSession. saveChanges (); // return true; // the data of the master table to be deleted in a loop is added to the for (int count = 0; count <listtype. count; count ++) {// create and delete the object rule ResultDictionaryTypeEntity temptype = new ResultDictionaryTypeEntity () {isDeleted = 1 }; // Delete the data dictionary type Guid typeId = listtype [count]. dictionaryTypeId; // call the underlying update method this. currentDal. update (temptype, u => u. dictionaryTypeId = typeId, "isDeleted");} // save information, return True this. dbSession. saveChanges (); return true;} catch (Exception ex) {// throw new Exception (ex. message) ;}# endregion

Later controller (here we will add the two viewmodels in the master-slave table to the set to be deleted, and assign the master table IDs to the query conditions when the table is deleted)

# Region DeleteType -- delete data dictionary information -- Li Liping -- 22:16:42 // <summary> // delete data dictionary information /// </summary> // <param name = "listData"> data dictionary set </param> // <returns> bool value </returns> // public bool DeleteType etype (IList <int> listData) public bool DeleteType () {// obtain the course information to be added string strTypeName = Request. form ["dictionaryTypeId"]; // extract the Guid of the course to be added by means of cutting. string [] strTypeNameList = strTypeName. split (new Char [] {','}); // store the id to be deleted in an object set for (int I = 0; I <strTypeNameList. count (); I ++) {Guid tempStr = new Guid (strTypeNameList [I]); // call the underlying Method Add listType. add (new DictionaryTypeViewModel (); listDictionary. add (new DictionaryViewModel (); listType [I]. dictionaryTypeId = tempStr; listDictionary [I]. resultDictionaryTypeEntity_dictionaryTypeId = tempStr;} // call the server Method -- delete the data dictionary information bool IsDeleteSuccess = iDictionary according to the Guid. deleteTypeByTypeID (listType, listDictionary); return IsDeleteSuccess;} # endregion

And js Code

// Batch Delete -- Li Liping -- 2015-7-13 22: 18: 31 function del () {// select at least one row of Data var rows =$ ('# dg '). datagrid ('getselections'); // determines whether to select the row if (! Rows | rows. length = 0) {$. messager. alert ('reminder ',' select at least one row of Data! ', 'Info'); return;} // obtain the var strId of the row selected from the table; // return the value to the submitted Delete parameter (type name) cyclically, n rows $. each (rows, function (I, n) {if (I = 0) {strId = "dictionaryTypeId =" + n. dictionaryTypeId;} else {strId + = "dictionaryTypeId =" + n. dictionaryTypeId ;}}); $. messager. confirm ('hprompt ',' Do you want to delete the selected data? ', Function (r) {// if no, the interface if (! R) {return;} if (strId! = Null) {// submit. The DeleteType Delete type method in controller is called $. ajax ({type: "POST", async: false, url: "/DictionaryType/DeleteType", data: strId, success: function (data) {if (data = "True") {$. messager. show ({title: 'success prompt ', msg: 'success Message deleted! ', Timeout: 5000, showType: 'slide'}); $ (' # dg '). datagrid ('reload');} else {$. messager. alert ('prompt information', 'deletion failed. Please try again! ', 'Error ')}}});}});}

Similar to others.

We solved a problem in two days. This is a process of constantly improving the way we think about the problem and accumulating it step by step.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.