开发者

A few questions regarding web based c#programming with visual studio 2010 and mysql

I'm making a web based inventory database that is connected to mysql, and I currently have a purchase order(PO) page for incoming stocks, delivery receipt(DR) page for outgoing stocks and a stock list page.

In the PO page is a grid view of my PO table connected to mysql with edit and delete enabled and the edit is linked to a separate page. Same goes with the DR page. Stock page has a grid view of Stock table connected to mysql with only edit enabled.

I have a separate add new page 开发者_如何学JAVAand edit page for PO and DR. Both add and edit pages have details view in them. Here are my questions.

1. How do I automatically insert records that are inserted in the add page using details view for both PO and DR to Stock table. My stock table looks like this:

Stock_ID | Date | PO_ID | DR_ID | Product_ID | Stock_In | Stock_Out | Stock_Balance |

What I want to happen is that when I enter either a new DR or PO, it'll go to the stock table automatically as well as their respective tables and the stock balance will adjust automatically.

2. In my details view of add new PO, I edited the details view so that when you choose a supplier and product you get to choose from a drop down list that is connected to their respective table, how do I limit what product the user can choose in regards to the supplier he /she chooses. Let's say that I choose supplier 1 and the products he supplies are products 1 and 2. What I want to happen is that when I choose supplier 1 the products that I can choose are limited to products 1 and 2.

This is the link to my AddPO source code

http://pastebin.com/download.php?i=5AaqHSc4

This is the link to my AddPO.cs source code

http://pastebin.com/download.php?i=Mz8GdLfx


Edit

  1. The InsertCommand should be fired when a LinkButton with CommandName="Insert" is clicked, which you have at the bottom of the form. You can try querying any error messages during the ItemInserted event using DetailsViewInsertedEventArgs.ExceptionHandled to check if there was an unhandled exception, and DetailsViewInsertedEventArgs .Exception to get the details of that exception. Does it work if you remove all of your logic you have placed in the ItemInserting event?

  2. Your SqlDataSource for the products DropDown should have a parameter of SupplierId, and your SelectCommand should filter based on that parameter.

Example code for SqlDataSource:

<asp:SqlDataSource ID="SqlDataSource1"
        SelectCommand="Select * from Products Where SupplierId=@SupplierId">
    <SelectParameters>
        <asp:Parameter Name="SupplierId" />
    </SelectParameters>
</asp:SqlDataSource>

Example binding code (replace with correct control id's):

protected void SqlDataSource1_Selecting(
       object sender, SqlDataSourceSelectingEventArgs e)
{
    DropDown SupplierDropDown = 
        MyDetailsView.FindControl("SupplierDropDown") as DropDown;
    e.Arguments["SupplierId"] = SupplierDropDown.SelectedValue;
}

Old

  1. If your data is connected to a DataSource control, set the InsertStatement or OnInsert event to the appropriate code to handle inserting according to your spec. If you're binding the DetailsView programmatically, then you will need to handle the ItemInserting event of the DetailsView, or use custom logic in your submit button. See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.iteminserting.aspx for more information.

  2. Use a ControlParameter on your data source of the products DropDown, tied the selected value of the Supplier DropDown. Then set AutoPostBack=True on the suppliers DropDown, so any time a selection is made, the products list is updated accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜