Dynamically Changing MasterPage
Changing MasterPage Dynamically
In real-time we may come across scenario where depending on the particular group of users we need to show different layout, colors, themes, functionalities and so on. To achieve this there are various ways, maintain the settings for each user in table , maintain the cookies and so on.
In .net the best way to achieve this is to change master page dynamically where the master pages will have different layout , different look and feel for different users. This we can achieve by following below mentioned steps.
1. All the WebPages will be inherited form System.UI.Web.Page base class
2. In page directive we have a property to set masterpage file
3. Once we attach any master page to any child, first all the controls of the master page are instantiated, then child page controls are instantiated
4. If we want to apply master page in code behind file ,the page’s master page property needs to be applied in Onpreinit method only.
5. After instantiating controls, child page load will be called first, then the master page will be loaded.
To change master page dynamically we need to follow the below mentioned process/method
1. Create one separate class file as public, which will inherits System.UI.Web.Page base class
2. Override the Page base class method onPreinit(), in this method set the master page property of the page, give the name of the master page file which you want to apply
3. At the end of the onPreinit() method call the base class onpreinit method
4. Inherit the newly created class in all of your web pages.
5. To provide the custom master page, we may use cookies, sessions or the values stored from database, it depends on how we want to manage the customization.

Illustration
Merging Image and text in a single gridview cell
Neither you can add image in DataGridViewTextBoxColumn nor you can add text in DataGridViewImageColumn so merging text and image in the same cell in datagridview is bit tricky. To achieve this you can create your own control inheriting from “DataGridViewTextBoxColumn” and overriding paint method. Or you can track the grid view’s paint event and write the below functionality
Private Sub GridView1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GridView1.Paint
Dim count As Integer = 0
Dim xCordinate As Integer = _
GridView1.GetColumnDisplayRectangle(GridView1.Columns(“column1”).Index, True).X + 11
1. For count = GridView1.FirstDisplayedScrollingRowIndex To (GridView1.FirstDisplayedScrollingRowIndex + 7)
2. If count < GridView1.Rows.Count Then
3. Dim rct As Rectangle = GridView1.GetRowDisplayRectangle(count, True)
4. Dim rct2 As New Rectangle(xCordinate, rct.Y, 26, 25)
5. e.Graphics.DrawImageUnscaledAndClipped(My.Resources.Image1, rct2)
End If
Next
End Sub
Here are the details of steps mentioned above
1. Looping thorough the rows which comes under visible area. Here in the sample code we have 8 rows visible at a time rest are coming under horizontal scroll. So we loop through only those rows starting from “FirstDisplayedScrollingRowIndex “ and paint cell with an added image.
3. Get the rectangle dimension of each row. This is to set the y coordinate of each image we are going to paint manually
4. Get the rectangle dimension of the area under which we want to paint the image.
Here the left coordinate of rct2 is set by taking the X coordinate of the DataGridViewTextBoxColumn under which we are going to paint the image and adding 11 pixels to accommodate the text.
Y coordinate is the Y coordinate of each row
Width and height of rct2 is the dimension of the image we are going to paint
5. “DrawImageUnscaledAndClipped” draws the image without scaling it and clipped by the rectangle passed as a second parameter
Splitting DICOM file in to HEADER and DATA
What is DICOM?
Digital Imaging and Communications in Medicine (DICOM) is a standard for storing, handling, printing, and transmitting information in medical imaging. DICOM internally defines network communications protocol that uses TCP/IP to communicate between systems. DICOM files can be exchanged between two systems that are capable of receiving image and patient data in DICOM format. Proposed by National Electrical Manufacturers Association (NEMA) (www.nema.org)
A DICOM file contains a header and the image data. The header stores information about the patient’s name, the type of scan, position and dimension of image and lots of other data. The image data part contains all the image information.
SPLITTING DICOM Image:
We can split the DICOM image in to header(Demographics) and data(Image) parts using java with the help of dcm4che API.
HEADER PART:
Ø First we have to open the DICOM image for reading using IOStream.
Ø Create a DICOM Object from the stream we opened for reading.
Ø Remove the Pixel Data from the DICOM Object. Now this DICOM Object only containing header information.
Ø Write the DICOM Object in to a separate file.
DATA PART:
Ø First we have to open the DICOM image for reading using streams.
Ø Create a DICOM Object from the stream we opened for reading.
Ø Read only Pixel Data from the DICOM Object and store in DICOM Element and write it in another file using byte array.
Tips to create an effective proposal
1. While writing the proposal keep in mind who is the audience. Is it a technical person, an end user, a finance guy or maybe a combination? Tailor it to suit their needs. This basic rule holds good for any document for that matter, always keep in mind who will read it.
2. A good introduction goes a long way in setting the tone of the proposal. The introduction should tell about the problem and the solution that your proposal intends to solve. It should also tell what to expect from the proposal.
3. Important points in the proposal should be bulleted, highlighted, colored or whatever it takes to make them jump out of the pages. Don’t make it look like a credit card’s hidden terms and conditions.
4. Keep it short. If the buyer has received ten proposals, probably she’ll pick up the shortest one first.
5. Leave the finances for the later sections, if money is not your selling point. If you can convince you have understood and can solve a problem effectively, the buyer shouldn’t bother much about it.
6. Your company’s profile should not appear in the first few pages. The buyer probably knows about that if she asked you to submit a proposal. It can be a part of the appendix at best.
7. Do a spelling and grammar check. Do not submit a proposal without a table of content.
How to grow in an organization
I read a story in my high school English book written by a famous Indian author (I forgot the name) – There was an old blind man who used to work in a grocery store. He was very good at mathematics. He used to sit next to the shop owner. Whenever a customer bought goods from the shop, the owner would speak out the product list. The old man would quickly calculate the total amount payable with his impeccable strong hold on mathematics. He also had a good memory and knew the prices of all the products. One day when he came to the shop, he came to know that the owner had bought a new device called a calculator. The calculator could do all the maths and much faster! Slowly the old man became obsolete. The owner had not asked him to leave but he felt he was not doing much at the shop and became restless.
One day when he was sitting next to the owner as usual, with the owner doing all the maths on the calculator, the owner wanted to know the price of a product. The old man of course had this information handy through years of working in the shop. In fact he also knew how much quantity of that product was in the shop. From that day his role changed, he would advice the owner on inventory management, cost price and selling price of each product.
A few days later on being asked by someone what was he still doing in the shop, when the owner now had the calculator, the old man said that he had been promoted to be a manager!
The morale of the story is simple. To grow in an organization, make yourself replaceable. Grow your fellow employees to take your place. Growing your team should be the higher objective, and you’ll see that your own growth was a natural consequence.
A practical approach to project effort estimate
It’s called an estimate because it’s bound to change as the development progresses, and as both the partners (the customer and the service provider) get a better understanding of the project. The use of the word partners takes significant importance since mutual trust and understanding is necessary for a project to be successful. At CircleSource we follow a simple two step process –
a. The sales team, which includes a technical specialist, estimates based on the available product overview and provides ball park figures to the customer. These are typically an order of magnitude estimates, e.g. 6 to 8 person months or $10,000-15,000. This estimate includes a list of features to be developed, development methodology, deliverables and time lines.
b. During the first 2-3 weeks, CircleSource puts its best efforts at gathering business objectives and requirement of the product. A Software Requirement Specification or wireframes or screen mock-ups are created during this time. Based on this, we provide revised estimates to the customer which becomes the point of reference to the overall project cost and time. This is also the time when we provide business and technology suggestions, based on our experience, to improve the product. Both the sales team and the project lead are involved in this stage.
With the advent of Agile, where the entire product development is broken down into 2-3 weeks iterations, it has become easy to provide a realistic view of the project timelines to the customer. We provide iteration based releases to get continual suggestions and changes from the customer. However, a basic pre-requisite of Agile is that whenever the requirements change, the iteration plan needs to be revised and communicated to the customer. We have to act as trusted advisors to the customers, consult them on the feature addition versus time and cost balance, and keep them updated on a daily basis on the progress. Since the basic nature of estimates is dynamic, prompt and effective communication is the key for success.
Process Training during Induction
It is a celebrated fact that software development is no longer an art but a science where results can be predicted to a high degree of accuracy, thanks to the processes or quality management system of an organization. The QMS of any organization is an integral part of its DNA, which predicts and maintains consistency of quality in the projects.
Each organization has its own unique set of processes and tools. At CircleSource we have created our own Software Development Methodology customized to suit the kind of product development we undertake in our organization. This is a simple one page document, figuratively explaining the various phases and associated deliverables. We use two main tools - SVN for version control and Trac for project management. We have customized both these tools to our needs. Besides, we have many other documented processes e.g. Release Management, Roll out of the application on the production server, Pre Release Checks.
The key is the dissemination of this information to the employees on a continual basis. It takes extreme importance for new joinees who have to be quickly taken under the wings of CircleSource’ QMS. We provide training to all new employees on our tools and processes, and strive to do this within a week of their inception. No employee can be part of a live project unless he/she has undergone these trainings. This initiative, which is a combined effort of the HR/Quality Team/Engineering Team of CircleSource, ensures that our team adheres to processes and delivers value from day one of the project!
Let’s have a look at the TIMEDIFF() function in MySQL:
TIMEDIFF(expr1,expr2) - TIMEDIFF() returns expr1 - expr2 expressed as a time value. expr1 and expr2 are time or date-and-time expressions, but both must be of the same type.
It seems that when TimeDiff is performed on 2 dates that exceed 36 days then a warning is thrown, and the resulting value is always capped to 838.
For example:
select time_format(timediff(’2009-02-05 00:00:00′,’2009-01-01 00:00:00′),’%H’) as TimeDifference
If you execute the above query MySQL will return 838 instead of returning 840 (35 X 24 = 840).
The reason is precisely because TIME type in MySQL has an upper bound of 838:59:59. TIME values may range from ‘-838:59:59′ to ‘838:59:59′.
By using TIMESTAMPDIFF() function you can get around with this problem.
Let’s have a look at the TIMESTAMPDIFF() function in MySQL:
TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) - Returns datetime_expr2 - datetime_expr1, where datetime_expr1 and datetime_expr2 are date or datetime expressions. One expression may be a date and the other a datetime; a date value is treated as a datetime having the time part '00:00:00' where necessary. The unit for the result (an integer) is given by the unit argument. The legal values for unit are FRAC_SECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
It is bit confusing timediff and timestampdiff expects the times in opposite order.
Now let’s try timestampdiff() with same dates
select timestampdiff(hour,’2009-01-01 00:00:00′,’2009-02-05 00:00:00′) as TimeDifference
If you execute the above query MySQL will return 840. Even if the difference is more than 840 it will not throw any exceptions or any warning. Hence we can use TIMESTAMPDIFF() function where the difference is more than 838 and can get the output in any of FRAC_SECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
There you have it … I hope you enjoyed this article. Please leave comments / suggestions / questions if you have.
Building Connection string (ADO.NET)
Building Connection string
Introduction:
As we know we use to build the connection strings by copying the existing connection string and renaming the DatsourceName,UserName,Password like that but here we will be discussing about how to build the connection string without copy paste.
Approach:
There is a way to build the connection string for any database which DotNet supports.
1.Open a notepad
And save it as somename.udl where udl (Universal Data Link) is the extension the udl files are used to build the connection string we can directly use the udl file to open the connection to the database
2. Then you can find the file with the following icon as shown below
3. Now open this file by double click it will be as shown below
Now select the provider what ever you like from the list and click next in my case I am selecting the Oledb SqlProvider and clicking next
4.Then you can see the screen as below
then we need to provide the server name ,username if you are not using windows authentication and check the allow saving password option for saving the password in the file now select the database to which you need the connection and then click ok.
Note: - You can find the database list if the details provided by you are valid
5. Now the connection string is ready
How to use this:
1.You can directly use the udl file to open the connection and connect to the database but the limitation is it is supported
by oledb Providers only.Sample code
OleDbConnection connection = new OleDbConnection("File Name= D:\\connection.udl");
OleDbCommand command = new OleDbCommand("select * from Cities",connection);
OleDbDataReader reader;
try
{
connection.Open();
reader = command.ExecuteReader();
while (reader.Read())
{
ListBox1.Items.Add(reader["Cities"].ToString());
ListBox2.Items.Add(reader["Cities"].ToString());
}
ListBox1.DataBind();
ListBox2.DataBind();
}
catch (Exception error)
{ }
finally
{
connection.Close();
}
2. You can directly get the connection string from the file and we can use directly in our code
Open the file with notepad as shown below
And there you can find your connection string like this
[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Password=mypassword;Persist Security Info=True;User ID=username;Initial
Catalog=datbasename;Data Source=servername
Conclusion: -
By using this udl files we can build connection string for any type of database easily.
Dynamically creation of web controls and binding Validations Using ASP.NET
CreatingDynamicControls_Source
Introduction:-
As we know we can bind the controls to our page (aspx) in 2 ways
1. Statically :- Binding the controls while Designing
2. Dynamically :- Binding the controls at runtime
Everyone know how to bind statically but there may be some cases where we need to bind the control dynamically .One of those cases is when our controls are keep on changing like I have a registration site in which the control type may keep on changing then I may need to go for binding the controls dynamically .
Approach:
For binding the controls I need the data what are the controls I want to bind and what is the id to be given and what are the properties to be provided etc.,
This can be provided by 2 ways









