Invoice Print in vb.net or c# - c#

I'm making a simple one-form Invoice bill printing, below is the screenshot to illustrate it.
I want to generate a report from the existing form after entering the data, simply static without database. Only the combo-box values are fetched from the database.
How can I generate that report after clicking the print button. The resultant report should not have combo-box, it should simply have a label instead of it.

I would always prefer to generate html files as reports. Its very flexible and printer friendly.
Create a html template with place holders and just replace with your required data.

You can do it via html like cloudlight suggest. But I have done it in another way using richtextboxcontrol. This is the link for the class file.
http://support.microsoft.com/kb/812425
I did receipt printing for POS machine before, I found it very easy to create a rtf file as my template. Then using the richtextboxcontrol, i read in the rtf file content, and replace the segment I want to changes.
For example, if name is a variable, in my rtf file, I would put something like <NAME>, after reading, all I need to do is to use string.replace.
Depends on how you customized it, I did it to the extend that I was able to change single variable and multiple lines of item using the same template.

Related

Compare word documents(.docx) with a document template(.dotx)

Is there any way I can compare a word document(.docx) with a document template(.dotx) generated in microsoft word.
I want to do this comparison programmatically using c#.
I want to compare both documents word to word so that I can determine to which template the document belongs. I don't just want to compare the size of both but I want to compare the contents also.
By this comparison I want get the following results.
From which document template the document is generated.
In the document template, I want to check that at which place a particular information is stored.
Say for example I want to search for the communication information of a person, then I want to traverse the document and check that At which position the template has the area/section for Address.(i.e. Top left corner, top center, In a paragraph, In body etc)
In same way I want to extract other information too, Like Link to other documents etc.
After getting those positions I want to get that Information from the .Docx file.
Say, If I found that the Address in the top-left and there are five links referring to other documents in five different paragraphs. Then what I want is to get the Address and save it to a variable. After that I want to replace those link contents from placeholders to Actual hyperLinks. i.e If a Link is referring to Doc-A then Instead of just showing a Plain text I want replace it with A hyperlink to Doc-A.
Any suggestions?
Thank You.
Your question is rather too vague and involved to give a really good answer, however...
To find out from which template a document was generated the object model provides the property: Document.AttachedTemplate with will return the full file name. This is certainly better than comparing word-by-word (which is also very time-consuming)
The Word object model also provides the method CompareDocuments (belongs to the Word.Application class). This will "highlight" differences in the text content of two documents.
Links will be found in the Document.Hyperlinks collection
Getting the position of things is a bit chancy with Word and it depends on what you really mean by "top-left", etc. Better would be to construct the templates using content controls, form fields and/or bookmarks so that you can uniquely identify important sections. However, Word does provide the Range.get_Information method that can return relative and absolute positions on the page if that's what you really want.

Retrieve text from database and format it on the front end of the website

I have some text currently stored in my database table as nvarchar.
I am currently retrieving the text using a stored procedure and binding it to a literal within a gridview on the front end.
What I would like to do is to retrieve the text and then format it , like inserting line spaces and making
certain area bold. Is it possible to do so ? Can anyone give me an idea of how it can be done ?
One idea thats striking me is to use XML while storing the text . But even if I do that how would I make a certain part of the text bold and include line spaces.
So currently, my text is stored in the database table column nvarchar(max) as:
This is the heading this is the content
What I would like to do is to display the above within a gridview like:
**This is a Heading** (heading in bold)
This is the content
The simplest method (one I have used several times) is to store the html in the table like this:
<h1>This is the heading</h1>This is the content
You will have to add special handling for working with html, but it works just fine.
You can also store the header string in one field, and body in another.
Short of that, you would have to have some indicator telling the front which part of the string should be bolded, etc. and that can get very complex
Short answer is that this is possible but takes some work.
You first need to decide in what format are you going to store the data and how can you specify format on the client side, before text is entered into database.
If you have WYSIWYG editor for text – html conversion you can try storing the HTML. This will be the easiest way in terms of storage.
If you decide to use this method note that you’ll need to do a lot of validation on the server to avoid cross site scripting attacks. Shortly put – make sure the HTML you get on the server doesn’t contain any javascript or any tags apart from those you want to support.
Its better to use Editor of AJAX Toolkit, doesnt required any other thing, its a complete editor, you can even color your font as u wanted.

How to tell height of paragraph in OpenXML?

I'm generating an MS Word document from user data. The data is placed in a container which is serialized to XML, and the resulting XML is converted to OpenXML using XSLT. There are a few minor changes done programmatically in C# to generate the Word document, as they can't be done with XSLT.
There is a user requirement that an item be placed completely on one page without any associated data being split onto another page. Sometimes one item will fill up an entire page, and sometimes I can fit three or four items on one page (I need to insert a separator (horizontal rule) between items that fit on the same page.)
Is there a way to determine whether or not one item or OpenXML paragraph will fit entirely on the "current" page? This can be either via C# or XSLT, and I can work something out.
Unfortunately, the only way this can be reliably done is to actually render the output, including all of the font sizes, bolding, kerning and all that. Which means you have to do the pagination in Word, and then save it back to the OpenXML.

C# HTML entities from XML string in DataGridView

I'm working with a Web Service that returns an XML string. I need to display the contents of the XML string in a DataGridView to users.
The XML string resembles something like this:
<Field id="13598" type="1"><p><strong>This </strong>is our <em>response</em></p></Field>
So far, I've managed to format output that's something like this which is displayed in my DataGridView:
e.g.
<p><strong>This </strong>is our <em>statement</em></p>
Using System.Net.WebUtility.HtmlDecode
Is there a way for me to display the formatted text in the DataGridView?
e.g.
This is our statement
I'm hoping to achieve useability as the intended users of the program might not be familiar with HTML.
I would've just removed the entities, but I need to retain them as they will be required for writing to an XML string later on as well, due to any editing.
e.g.
<p><strong>This</strong> is our updated <em>statement</em></p>
I've been toying with the idea of using a new form with a TextBox to enable editing as some of these strings might be much longer than this, and could contain other forms of formatting such as bullet points and the like. I'm not too sure how to go about with this. I'm not entirely sure if what I'm hoping to achieve is possible. If not, are there alternative methods for me to achieve this?
You could use the WebBrowser control, and set its content using the NavigateToString method

Integrating Visio exported XAML into Silverlight application

It is possible to export Microsoft Visio drawings as a Website containing Silverlight content. This is described on this blog-post.
The output of such an export are the following:
xaml_1.xaml (contains the structure of the control)
data.xml (contains all text content such as labels, etc)
several java-script files
*.htm pages with a Silverlight container
other files such as *.css and images
I would like to integrate the exported XAML code into another existing Silverlight application. I found this blog-post telling me how to load XAML code dynamically during runtime.
What I would like to know is how to "merge" the XAML-file and the data.xml and how I can get a reference to the items of the XAML code, in order to change certain texts...
In the associated xaml js file (eg xaml_1.js) there's a handleMouseUp function that reads the shape ID from the (XAML) 'name' string and then calls OnShapeClick in frameset.js. This method, which is common to all of the js-based Save as web output types, then calls other methods to populate the details table or retrieve hyperlinks found in data.xml. If you have a look at the FindShapeXML function in frameset.js you'll see that it gets the appropriate data based on the page and shape IDs (note that shape IDs are unique to a page as per Visio itself).
In terms of creating data-bound or dynamic shape text, one workaround for the glyphs issue that #slfan highlights is prevent the text from being output. For example, prior to running Save As Web in Visio, you could loop through all of the shapes and set their HideText ShapeSheet cell to true. This will prevent all of the glyphs xaml being generated and you'll still have access to the text string in data.xml. I guess you wouldn't then benefit from the correct font scaling, but it depends on your scenario. If it was really important to get the scale right then you could parse the RenderTransform attribute (which is described in attribute syntax rather than property element syntax) of the glyph elements.
Glyphs are there (I'm guessing) because it mirrors how Visio works in the application ie in Visio you can select individual characters within a shape's text and apply different fonts and formatting, but if you don't need that, I'd be tempted to ditch the glyphs collection and just use a TextBlock as #slfan suggests.
I think you have to tweak the generated XAML a little bit. Unfortunately Visio generates glyphs for every single character. If you want to change the text at runtime, you will have to remove this glyphs and add the required controls (e.g. TextBlock) yourself.
You can load the XAML into Silverlight with XamlReader.Load. A good description you find here: http://blogs.silverlight.net/blogs/msnow/archive/2008/10/09/silverlight-tip-of-the-day-60-how-to-load-a-control-straight-from-xaml.aspx.
All JavaScript and HTML files you can ignore, the XML-file you need to identify your controls. The ID's in the XML refer to the corresponding elements in the XAML-file.

Categories

Resources