Solution to the Problem of deleting basic data in the business system ., Business basics
It has been around for several years in the blog garden. Although it is amateur. But I did learn a lot from my blog. Today, I made a blog myself. As my first blog, I wrote about the problems and solutions I encountered when I made my own business system. I hope you will not spray me.
It may take some time to build your own client. Basic data deletion is frequently encountered. It seems that many systems cannot be deleted. It's just a flag and cannot be used.
I think physical deletion is harmless if there is no associated data for newly added data. Let's take a look at my methods. It is also similar to the recycle bin function of Windows. Please give me some advice.
Let's take a look at it first. Add the DotNotBar toggle control in the form and set the filter conditions. When deleted, put it in the recycle bin. When you click Delete in the recycle bin, the system searches for the associated data. For example, C # + EF:
Private void bindingNavigatorDeleteItem_Click (object sender, EventArgs e) {if (tProductBindingSource. Current! = Null) {if (! SwitchButtonItem1.Value & MessageUtil. ShowYesNoAndTips ("are you sure you want to delete this item? After deletion, the product will be placed in the product recycle bin! ") = DialogResult. yes) {var one = (t_Product) tProductBindingSource. current); one. enable = false; db. saveChanges ();} else {try {var one = (t_Product) tProductBindingSource. current); var more = db. t_Product.AsNoTracking (). where (p => p. productID = one. productID ). select (p => new {n = p.s _ RKDetail. count () + p.s _ SellDetail. count () + p.s _ Stock. count () + p. t_ChangeStock.Count ()}); if (more. firstOr Default (). n = 0) {db. t_Product.Remove (one); db. saveChanges ();} else MessageUtil. showWarning ("this item data has been associated with inventory records and cannot be physically deleted! But it can be changed to new product data and used. ");} Catch (Exception err) {MessageUtil. ShowError (" An error occurred while deleting this item! It can be changed to new product data and used. Error Message: "+ err. Message) ;}} buttonx?click (null, null );}}
In fact, it is to find the number of other table rows associated with the data and add them. As long as the value is not 0, it indicates that there is associated data and cannot be deleted. Then, a prompt is displayed.