locked
I want to generate an invoice RRS feed

  • Question

  • I have a windows form which contains comboboxes and a list view, i want to generate an invoice which will take data from the combobox selection and items in the list view and also text boxes and show the data on another form where there will be a print button. The data will be in order. What should i use. Plz help

     

    Sunday, August 21, 2011 10:49 AM

Answers

  • Also, I got a simple code example that allows you to do the following:

    • Create invoice
    • Add invoice lines
    • Book invoice
    • Get invoice PDF
    private void InvoiceTest()
    {
    // Create current invoice
    IDebtor debtor = session.Debtor.FindByNumber("1");
    ICurrentInvoice cinv = session.CurrentInvoice.Create(debtor);
     cinv.Heading = "Test invoice";
    
    // Add first line
    IProduct prod1 = session.Product.FindByNumber("101");
    ICurrentInvoiceLine line1 = session.CurrentInvoiceLine.Create(cinv);
     line1.Product = prod1;
     line1.Description = prod1.Name;
     line1.Quantity = 2.0m;
     line1.UnitNetPrice = prod1.SalesPrice;
    
    // Add second line
    IProduct prod2 = session.Product.FindByNumber("102");
    ICurrentInvoiceLine line2 = session.CurrentInvoiceLine.Create(cinv);
     line2.Product = prod2;
     line2.Description = prod2.Name;
     line2.Quantity = 1.0m;
     line2.UnitNetPrice = prod2.SalesPrice;
    
    // Book invoice
    IInvoice inv = cinv.Book();
    
    // Retrieve PDF
    byte[] pdfData = inv.GetPdf();
    
    // save PDF
    string fileName = @"d:\invoice_" + inv.Number.ToString() + ".pdf";
    int length = pdfData.Length;
    using (System.IO.FileStream stream = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
     {
     stream.Write(pdfData, 0, length);
     }
     }
    

    Note that this code only works if you have set up customers, products and sales prices. Also, error handling has not been incorporated into this example.
    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Helen Zhou Friday, September 2, 2011 3:32 AM
    Wednesday, August 24, 2011 4:14 AM
    • Use crystal reports to create a invoice.
    • use rich-text-box

    You can use rich-text-box to show your data , rich-text-box will allow you to format your text just like in MS Word.

    Add your invoice details line by line to the rich-text-box

    Example of rich-text-box formationg.

    http://www.daniweb.com/software-development/vbnet/threads/98273

    Dim Position As Int16 = 0
    Dim string1 As String = "This is string1. Font=Arial: FontSize=14: Color=Blue" & vbNewLine
    Dim myFont As New Font("Arial", 14, FontStyle.Regular, GraphicsUnit.Point)
    Dim myColor As Color = Color.Blue
    rtb.Select(Position, 0)
    rtb.SelectionFont = myFont
    rtb.SelectionColor = myColor
    rtb.SelectedText = string1
    Position += string1.Length
    


    Printing Rich-Text-Box

    http://www.daniweb.com/software-development/vbnet/threads/182444

    http://support.microsoft.com/kb/811401

     

     

     

     


    Please mark those posts as answer which answers your question. Faraz
    • Marked as answer by Helen Zhou Friday, September 2, 2011 3:32 AM
    Sunday, August 21, 2011 12:01 PM
  • Hi Qasim,

    Beside the information form Faraz that add invoice details line by line to the rich-text-box, you may also need to know how to pass data from on Form to another Form. Passing Data Between Forms

    Or try my simple demo that may explain this more clearly:

    Suppose there're 2 forms, Form1 contains the ComboBoxes, listView, TextBoxes, (I will use 2 TextBoxes for simple the sample) and also a button(btnSubmit) that goint to submit the selected data to the other form (form2). Form2 contains the RichTextBox to list the items selected in the Form1, Form2 also contains a button to print the selected data but I will ignore that since Faraz has stated how to print a RichTextBox.

    in Form2, set the RichTextBox's Modifiers property to Public, so that in Form1, it can access the RichTextBoxes of form2.

        private void button1_Click(object sender, EventArgs e)
        {
          Form2 frm2 = new Form2();
          frm2.Show();
          frm2.richTextBox1.AppendText(textBox1.Text + "\n");
          frm2.richTextBox1.AppendText(textBox2.Text + "\n");
        }

    Sincerely,


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by Helen Zhou Friday, September 2, 2011 3:32 AM
    Wednesday, August 24, 2011 3:48 AM

All replies

    • Use crystal reports to create a invoice.
    • use rich-text-box

    You can use rich-text-box to show your data , rich-text-box will allow you to format your text just like in MS Word.

    Add your invoice details line by line to the rich-text-box

    Example of rich-text-box formationg.

    http://www.daniweb.com/software-development/vbnet/threads/98273

    Dim Position As Int16 = 0
    Dim string1 As String = "This is string1. Font=Arial: FontSize=14: Color=Blue" & vbNewLine
    Dim myFont As New Font("Arial", 14, FontStyle.Regular, GraphicsUnit.Point)
    Dim myColor As Color = Color.Blue
    rtb.Select(Position, 0)
    rtb.SelectionFont = myFont
    rtb.SelectionColor = myColor
    rtb.SelectedText = string1
    Position += string1.Length
    


    Printing Rich-Text-Box

    http://www.daniweb.com/software-development/vbnet/threads/182444

    http://support.microsoft.com/kb/811401

     

     

     

     


    Please mark those posts as answer which answers your question. Faraz
    • Marked as answer by Helen Zhou Friday, September 2, 2011 3:32 AM
    Sunday, August 21, 2011 12:01 PM
  • Hi Qasim,

    Beside the information form Faraz that add invoice details line by line to the rich-text-box, you may also need to know how to pass data from on Form to another Form. Passing Data Between Forms

    Or try my simple demo that may explain this more clearly:

    Suppose there're 2 forms, Form1 contains the ComboBoxes, listView, TextBoxes, (I will use 2 TextBoxes for simple the sample) and also a button(btnSubmit) that goint to submit the selected data to the other form (form2). Form2 contains the RichTextBox to list the items selected in the Form1, Form2 also contains a button to print the selected data but I will ignore that since Faraz has stated how to print a RichTextBox.

    in Form2, set the RichTextBox's Modifiers property to Public, so that in Form1, it can access the RichTextBoxes of form2.

        private void button1_Click(object sender, EventArgs e)
        {
          Form2 frm2 = new Form2();
          frm2.Show();
          frm2.richTextBox1.AppendText(textBox1.Text + "\n");
          frm2.richTextBox1.AppendText(textBox2.Text + "\n");
        }

    Sincerely,


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by Helen Zhou Friday, September 2, 2011 3:32 AM
    Wednesday, August 24, 2011 3:48 AM
  • Also, I got a simple code example that allows you to do the following:

    • Create invoice
    • Add invoice lines
    • Book invoice
    • Get invoice PDF
    private void InvoiceTest()
    {
    // Create current invoice
    IDebtor debtor = session.Debtor.FindByNumber("1");
    ICurrentInvoice cinv = session.CurrentInvoice.Create(debtor);
     cinv.Heading = "Test invoice";
    
    // Add first line
    IProduct prod1 = session.Product.FindByNumber("101");
    ICurrentInvoiceLine line1 = session.CurrentInvoiceLine.Create(cinv);
     line1.Product = prod1;
     line1.Description = prod1.Name;
     line1.Quantity = 2.0m;
     line1.UnitNetPrice = prod1.SalesPrice;
    
    // Add second line
    IProduct prod2 = session.Product.FindByNumber("102");
    ICurrentInvoiceLine line2 = session.CurrentInvoiceLine.Create(cinv);
     line2.Product = prod2;
     line2.Description = prod2.Name;
     line2.Quantity = 1.0m;
     line2.UnitNetPrice = prod2.SalesPrice;
    
    // Book invoice
    IInvoice inv = cinv.Book();
    
    // Retrieve PDF
    byte[] pdfData = inv.GetPdf();
    
    // save PDF
    string fileName = @"d:\invoice_" + inv.Number.ToString() + ".pdf";
    int length = pdfData.Length;
    using (System.IO.FileStream stream = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
     {
     stream.Write(pdfData, 0, length);
     }
     }
    

    Note that this code only works if you have set up customers, products and sales prices. Also, error handling has not been incorporated into this example.
    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Helen Zhou Friday, September 2, 2011 3:32 AM
    Wednesday, August 24, 2011 4:14 AM