Other Languages - Enable the invoice button after creating two lines in purch line form

Asked By Atul on 28-Nov-11 07:50 AM
Earn up to 30 extra points for answering this tough question.
Hi,
    I am working on purch order form,in that the requirement is when i create a purches order and item in grid net amount is suppose 120.so when i do the invoicing of that on line tab (i added the one more field invoice amount as requirement)
and in that field will be same as net amount by default but i can edit the amount.My question start from here..If i put the invoice amount less than the net amount(consider 40) then two lines should be created when i click on ok button on main form in grid with one value as 40 --invoice ,80--open..and i can do the invoice for 80 again.so my invoice button should again enable and i can do the invoice for the rest. where should i write the code for this.?please help me in this.

Thanks,
 
Anil Kumar replied to Atul on 28-Nov-11 08:56 AM
Hi Atul,

Look for the code below to create an Invoice in GridView using C# and asp.net:

<asp:GridView ID="InvoiceView" runat="server" AutoGenerateColumns="False"
        Width="671px"  CellPadding="3" GridLines="Vertical" BackColor="White"
        BorderColor="#999999" BorderStyle="None" BorderWidth="1px" Height="193px"
        onrowcommand="InvoiceView_RowCommand" onrowcreated="InvoiceView_RowCreated"
        onrowdatabound="InvoiceView_RowDataBound">
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <Columns>
          <asp:TemplateField HeaderText="S#">
          <ItemTemplate>
         
          <asp:Label ID="sno" Text='<%# Container.DataItemIndex + 1  %>'  runat="server" > </asp:Label>
        </ItemTemplate>
        
             </asp:TemplateField>

          <asp:TemplateField HeaderText="Item Name">
        <ItemTemplate>
          <asp:TextBox ID="itemname" runat="server" ></asp:TextBox>
        </ItemTemplate>
          
          </asp:TemplateField>

          
          <asp:TemplateField HeaderText="Qty">
          <ItemTemplate>
          
          <asp:TextBox ID="qty"   runat="server" ></asp:TextBox>
          
          </ItemTemplate>
          
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Price">
          
          <ItemTemplate>
          
          <asp:TextBox ID="price" runat="server" ></asp:TextBox>
          
          </ItemTemplate>
          
          </asp:TemplateField>
          
        </Columns>
        
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#0000A9" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#000065" />
        
      </asp:GridView>

[CODE BEHIND]

    public partial class invoice : System.Web.UI.Page
    {
      int i = 1;
       PointofSaleEntities1 pos;
       public void bind()
       {
         pos = new PointofSaleEntities1();

         var cat = from a in pos.invoices select a ;
         InvoiceView.DataSource = cat;
         InvoiceView.DataBind();


       }





      protected void Page_Load(object sender, EventArgs e)
      {
        bind();
      }

The above GridView only displays with a binding data source, so you have to give a data source to it. You can create a dummy data source such as a DataTable with 10 empty datarows. Then 10 rows will be shown in GridView, but without any binding value.

For inserting values to database, you can loop GridView to do inserting row by row:

foreach (GridViewRow gvr in InvoiceView.Rows)
{
    string sno = ((Label)gvr.FindControl("sno")).Text;
    string name = ((TextBox)gvr.FindControl("itemname")).Text;
    //other txt
    //do inserting by ado.net or some other ways
}

For calculation, just use above way to get related values and calculate them to get result and do inserting.

Hope this helps you.
Do update us again.
Thank you
Anil