Solution to the Problem of deleting basic data in the business system ., Business basics

Source: Internet
Author: User

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.

 

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.