我已经设计了awinforms Application和Ihave writte [英] Ihave designed awinforms Application and Ihave writte

查看:66
本文介绍了我已经设计了awinforms Application和Ihave writte的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个winforms应用程序,我编写了所有代码,只有一件事让我困惑。我正在设计管理商店的东西。我有一个表'stock',列 [ID,Name,Cost_px,Selling_px,Quantity] ,另一个表'sales',列 [date, ID,名称,数量,px_sold,收入] 。我有一个表格( ID,数量,price_sold )来输入销售额并连接到销售表格。

我能做什么库存表中的数量会根据销售的数量自动减少。

例如。产品ID = 1,price_sold(一个单位)= 20000,数量= 8.这是输入'sales'表,'stock'表中的数量自动减少8。

怎么样?我这样做。

谢谢你.nice tyme。

I have designed a winforms Application and I have written all the code except one thing has confused me. I am designing something to manage a shop. I have a table 'stock' with columns [ID,Name,Cost_px,Selling_px,Quantity], Another table 'sales' with columns [date,ID,Name,Quantity,px_sold,income]. I have a form(ID,quantity,price_sold) to enter sales and its connected to the 'sales' table.
What can I do so that Quantity in the 'stock' table is reduced automatically by the number of units sold.
eg. product ID=1, price_sold(one unit) = 20000, quantity = 8. this is entered into the 'sales' table, and quantity in the 'stock' table reduced by 8 automatically.
how can I do this.
Thank you.nice tyme.

推荐答案

你可以用CURSOR [ ^ ]。 简单示例 [ ^ ]。



FYI

SQL Server游标替代方案 [ ^ ]



在前端,你必须写逻辑(内部循环,你有根据您的要求,根据Item& quantity& execute构建查询。但我推荐后端方式。
You could do this backend by using CURSOR[^]. A simple example[^] for you.

FYI
SQL Server Cursor Alternatives[^]

In front end, you have to write logic(inside loop, you have to build the query based on Item & quantity & execute) based on your requirement. But I recommend the backend way.


你没有这么说,但我会假设你将数据存储在SQL数据库中。



当一件物品(或其集合)被出售时,如你所说,你需要记录销售,但你还需要修改该物品的库存记录。



有两个值得关注的数据库概念:

1. 存储过程。存储过程允许您执行从一个应用程序调用调用的多个连续数据库数据管理步骤。因此,当前您的应用程序正在调用数据库来记录销售,您将更改它以调用已售出物品存储过程 - 然后将销售额插入销售表并更新库存记录,然后再将控制权返回你的申请。



2. 交易。事务确保一组相关的数据库更新,如果任何一个失败,那么没有一个持续存在 - 使数据库保持内部一致状态。



希望有所帮助,
Chris
You don't say so, but I'll assume that you're storing your data in an SQL database.

When an item (or collection thereof) is sold, as you've said, you need to record the sale but also you need to amend the stock record for that item.

There are two database concepts worth looking at for this:
1. Stored Procedures. A stored procedure allows you to do multiple consecutive database data management steps invoked from one application call. So, where currently your application is calling into the database to record the sale, you'd change it to invoke the 'item sold' stored procedure - which in turn inserts the sale into the sales table and updates the stock record before returning control to your application.

2. Transactions. Transactions ensure that of a set of related database updates if any one fails then none persist - leaving the database in an internally consistent state.

Hope that helps,
Chris


您必须在按钮点击或任何其他事件上编写代码,以减少使用更新查询销售的单位数。
you must write the code on button click or any other event to reduce the no of units sold using update query.


这篇关于我已经设计了awinforms Application和Ihave writte的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆