Hi Imran and welcome ot our forum,
Simple Codeless Solution: let ShP or SQL do the job for you. Kind of a hack, but it works....
Over the years, this has been a very common request. You should search our forum for "Auto ID SharePoint". To reuse the SharePoint ID without writing code, you'll have to do two submits. First, submit to SharePoint and then query SharePoint for the form you Submitted (making sure to include the ID column in the data returned). The query will return a list of items from the SharePoint list and you can then filter this to find the one submitted and copy the ID out and into your main data source (using a rule). Then, let your user fill out the form and perform the final submit. One issue is comparing the file. How do you do this? Well, you can use a hidden field which is set to the username concatenated with the date/time of the first submit. So, you'll need to set this field before the first submit and use it in the query to get the ID back. This isn't totally bulletproof, btu the chance of the same user doing two submits in the same millisecond are, for all intents and purposes, nil. The other issue with this approach is what to do if the user decides not to submit it - well, then you have these zombie files in your SharePoint library. To identify these so you can filter them out (and later delete them), you can just set another hidden field to "Draft" on open. So first submitted form has the value "Draft" for that field. Then, on final submit, the rule should change that field to "Final" (or, whatever). You can then filter your ShP list to only show the Final forms.
What about if there are thousands of forms in the SharePoint form library? Good point! Well, you should archive old forms (and filter them out so they don't show on your default ShP view) or move the data into SQL and use SQL to do the same thing. We provide a Query Web Service (called qWSSP) that does filtered querying of ShP and SQL so that all of the data is not copied to the client, just the data you want. That speeds it up considerably: check out the performance data.
More Complex Solution: use code and GUIDs to do it... (the avove should work, but another approach is to use code and GUIDs - see Hilary's comment! :) )