Вы находитесь на странице: 1из 7

Programming GuideLines

1. String concatenation PLEASE PLEASEPLEASE do not use + to concatenate strings. If you need to build a small string, use string.format() Eg: string myString = string.Format(My name is {0} {1}, John, Doe) If you need to build a longer and more complicated string use the StringBuilder with Append /AppendFormat methods 2. Remove Unused Usings When you create a new ASP.Net page, it comes with a list of Usings, most of which will not be used. You should not be overloading the page by keeping unnecessary Usings. These unnecessary Usings do add up and make the application slower. So, towards the end of your development, remove these Unused Usings. Right click on the Code page Organize Usings Remove Unused Usings

3. ThreadAbortException on Response.Redirect a. When redirecting to a page, if your redirection is in a Try catch block,

Make sure you catch the ThreadAbortException. This is a common exception, and ends up unnecessarily populating our error log See Sample code below: protected void btnCommissions_Click(object sender, EventArgs e) { try { Response.Redirect(string.Format("{0}/BillboardOwner/ContractCommissions.asp?ContractNumber={1} " , ConfigurationManager.AppSettings["AppPathBP"], ContractNumber)); } catch (System.Threading.ThreadAbortException) { }// Do nothing here, as we expected this exception. catch (Exception ex) { Common.LogSQLError(ex.ToString(), "", codeFileName, "btnCommissions_Click"); } } 4. SellerID qualification on all queries a. b. c. d. e. f. g. SellerID needs to be included in all the queries. The SellerID comes from the Session object. SellerID in all the SELECT, UPDATE, AND DELETE queries on tables that have SellerID. Each User is also assigned a unique ContactID. SellerID value is accessible through SessionManager.SellerID ContactID value is accessible through SessionManager.ContactID when querying using a Primary key, use SELLERID

5. All database transactions should be in try catch, log errors to SQL error log (Common.LogSQLError) (We have a Class called Common that logs the errors to the SQLErrorLog table.) 6. Do not use Stored Procedures. Use SQL queries in the code files itself. 7. txtDateCtrl.ascx a. Required Field validator needs to be implemented using properties (look at DateRangeCtrl.ascx) b. When making changes to generic controls like this, the control should not make any direct reference to the caller module. 8. Send SQL Scripts files ONLY for objects that you have changed or created. 9. Do not use Select * From. Instead list the column names. 10. Avoid using Datasets 11. Database layer should not have any business logic. 12. Please use SQLConnectioncn and NOT SQLConnection con. There is nothing wrong with it; its just that we want all of our code to be uniform.

13. Capitalize the SQL Keywords in all of the queries. For example: SELECT, FROM, WHERE, AND OR, ORDER BY, etc 14. Avoid using DISTINCT unless it is necessary. 15. You should not be making any changes to database table schema without BP approval. 16. All Class Names and Pages Name should be created after the Approval from Arjun or Billboard Team Member. 17. All the methods and Events should have proper commenting in it.

Search Page Development Guidelines


Template Page C:\inetpub\wwwroot\bp_Dev3\bpNet\CRM\Organizations.aspx Use this template page on all listing pages with Search Criteria. This is absolutely critical for consistent look and performance.

Mandatory features: Width of the caption bar must be the same as the width of the Search Criteria section # of Records count label Page Index label Paging must be of this style, and appear both on top and bottom of grid Page size should be 100 rows Grid must be in an updatepanel Column header should be sortable where applicable The Search Criteria to Select Top # of rows. o Options should be Top 250 rows, Top 500 rows, Top 1000 rows, Top 2000 rows, All rows

o Default should be 250 SQL query must have a default sort Search Criteria controls must be laid out in tabular columns o When you look at .aspx page, all the search criteria controls in a column should be together. See screenshot above

Saving Search Criteria Search Criteria should not be pre-loaded when coming from Main Menu. It should be pre-loaded only when a user clicks search, then goes to view to record detail, and clicks on back link to come back to the Search listing again. To implement this: o All Menu links from the Main menu will pass a queryString "CalledBy=MainMenu" o When coming to a Listing page from the Main Menu, Delete the last stored SearchCriteria and do not preload the SearchCriteria. See code sample below: if (CalledBy == "MainMenu") { SearchCriteria.Delete(SessionManager.SellerID, SessionManager.ContactID, "NewCompanies"); } else { SetFormSearchCriteria(); } Error Label If there's an error when performing a Search, display error msg on the label Optional Features: Not perform Search on Page Load o Based on how heavy the data and the grid is, sometimes it is wise not to perform Search on Page Load. In that case Do not call the Search() method on Page Load Give a message "Please Click on Search to view records"

Export to Excel

Searching Mechanism The Search Mechanism must be implemented as in this page. This will avoid unnecessary SQL query re-building, and re-binding the resulting data grid The following methods are necessary for the Search mechanism to work /// <summary> /// Builds the SQL query with the filtering expression /// </summary> protected void BuildSearchQuery() /// <summary> /// Binds grid to the datasource

/// Gets sql query from lblSQL to avoid rebuilding the query /// </summary> protected void BindGrid() /// <summary> /// Build the SQL query, and Bind the grid /// </summary> private void Search() protected void btnSearch_Click(object sender, EventArgs e)

The following events are necessary to properly display the Page count and Row count labels protected void grdCompanies_Sorting(object sender, GridViewSortEventArgs e) protected void grdCompanies_PageIndexChanging(object sender, GridViewPageEventArgs e) protected void dsOrganizationDetails_Selected(object sender, SqlDataSourceStatusEventArgs e) Export button protected void btnExporttoExcel_Click(object sender, EventArgs e)

--------------------------------------------------------------------------------------------------------------------------------------------------------

Bikram : Notes Using SVN 1. Do svn update regularly to prevent conflits 2. while committing code put comment like: Opportunity Header: fix for date format saving. 3. Use of Win Merge or Araix Merge or any other tool to compare your latest copy to prevent commit of unnecessary script and code.

Coding Follow up 1. use cmd.parameter.add instead of cmd.parameter.addwithvalue. 2. On Delete put javascript box confirm 3. SQL script use UPPER CASING to QUERY. 4. client side validation for textboxes. Like numeric

Вам также может понравиться