473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How can I improve my coding style in the following code?

Hi Team,

Please give me a feedback on the below coding. I like to know whether i had improved in writing the .net coding. Thanks in advance.
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data
  2. Imports Offlinemessage
  3.  
  4. Partial Class Offline_Message_Offline_Message
  5.     Inherits System.Web.UI.Page
  6.     Dim ds As New DataSet
  7.     Dim obj As New Offlinemessage
  8.  
  9.     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  10.  
  11.     End Sub
  12.  
  13.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  14.         page_initialization()
  15.     End Sub
  16.     Public Sub page_initialization()
  17.         offlinecountlabel.Visible = True
  18.         OfflinemessageQuery.Visible = True
  19.         Dim str As String
  20.         str = Session("UserAccountNumber")
  21.         DateTextBox.Attributes.Add("onclick", "showCalendarControl(DateTextBox,1)")
  22.         FromDateTextBox.Attributes.Add("onclick", "showCalendarControl(FromDateTextBox,2)")
  23.         ToDateTextBox.Attributes.Add("onclick", "showCalendarControl(ToDateTextBox,2)")
  24.         offlineSearchButton.Attributes.Add("onclientclick", "search_validation()")
  25.         Advancesearchbutton.Attributes.Add("onclientclick", "advancesearch_validation()")
  26.         AdvanceSearchEmailidTextBox.Attributes.Add("onclick", "advancesearch_uservalidation()")
  27.         AdvanceSearchEmailidTextBox.Attributes.Add("onKeyDown", "advancesearch_uservalidation()")
  28.         AdvanceSearchNameTextBox.Attributes.Add("onclick", "advancesearch_nametextbox()")
  29.         AdvanceSearchNameTextBox.Attributes.Add("onKeyDown", "advancesearch_nametextbox()")
  30.         AdvanceSearchPhoneNoTextBox.Attributes.Add("onclick", "AdvanceSearch_PhoneNoTextBox()")
  31.         AdvanceSearchPhoneNoTextBox.Attributes.Add("onKeyDown", "AdvanceSearch_PhoneNoTextBox()")
  32.         Year4monthLabel.Text = CType(2010, Integer)
  33.         yearlabel1.Text = CType(2010, Integer)
  34.         yearLabel2.Text = CType(2011, Integer)
  35.         yearLabel3.Text = CType(2012, Integer)
  36.         yearLabel4.Text = CType(2013, Integer)
  37.     End Sub
  38.  
  39.     Protected Sub offlineSearchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  40.  
  41.         'MonthTextBox.Text
  42.         'YearTextBox
  43.         'FromDateTextBox
  44.         'ToDateTextBox
  45.         'AdvanceSearchNameTextBox
  46.         'AdvanceSearchEmailidTextBox
  47.         'AdvanceSearchPhoneNoTextBox
  48.  
  49.         If DateTextBox.Text <> "" Then
  50.             datewise_search(DateTextBox.Text)
  51.         ElseIf MonthTextBox.Text <> "" Then
  52.             monthwise_search(MonthTextBox.Text)
  53.         ElseIf YearTextBox.Text <> "" Then
  54.             yearwise_search(YearTextBox.Text)
  55.         ElseIf FromDateTextBox.Text <> "" And ToDateTextBox.Text <> "" Then
  56.             from2todatewise_search(FromDateTextBox.Text, ToDateTextBox.Text)
  57.         End If
  58.     End Sub
  59.  
  60.     Public Sub datewise_search(ByVal getdate As String)
  61.         Dim obj As New Offlinemessage
  62.         Dim ds As New DataSet
  63.         'MsgBox(getdate)
  64.         Dim mydate As New Date
  65.         mydate = CDate(getdate)
  66.         Dim str1 As String
  67.         str1 = Format(mydate, "yyyy-MM-dd")
  68.         'MsgBox(str1)
  69.         Dim count As Integer
  70.         'This is for getting count of offline message.
  71.         count = obj.offlinemessage_count(Session("UserAccountNumber"), str1)
  72.         If (count = 0) Then
  73.  
  74.             offlinecountlabel.Text = count & " Number of Offline Messages"
  75.         Else
  76.  
  77.             offlinecountlabel.Text = count & " Number of Offline Messages"
  78.         End If
  79.         ds = Session("Globalds")
  80.         Session("Globalds") = obj.searchdatewise(Session("UserAccountNumber"), str1)
  81.         bindgrid_offlinemessage()
  82.     End Sub
  83.  
  84.     Public Sub monthwise_search(ByVal month As String)
  85.         Dim obj As New Offlinemessage
  86.         Dim mydate As New Date
  87.         Dim count As Integer
  88.         Dim str As String
  89.         Dim ds As New DataSet
  90.         Session("Globalds") = ds
  91.         mydate = CDate(month)
  92.         str = Format(mydate, "yyyy-MM")
  93.         count = obj.offlinemessage_count(Session("UserAccountNumber"), month)
  94.         If (count = 0) Then
  95.             offlinecountlabel.Text = count & " Number of Offline Messages"
  96.         Else
  97.             offlinecountlabel.Text = count & " Number of Offline Messages"
  98.         End If
  99.         Session("Globalds") = obj.searchmonthwise(Session("UserAccountNumber"), str)
  100.         bindgrid_offlinemessage()
  101.     End Sub
  102.  
  103.     Public Sub yearwise_search(ByVal year As String)
  104.         Dim count As Integer
  105.         Dim ds As New DataSet
  106.         Dim obj As New Offlinemessage
  107.         count = obj.offlinemessage_count(Session("UserAccountNumber"), year)
  108.         If (count = 0) Then
  109.             offlinecountlabel.Text = count & " Number of Offline Messages"
  110.         Else
  111.             offlinecountlabel.Text = count & " Number of Offline Messages"
  112.         End If
  113.         ds = Session("Globalds")
  114.         Session("Globalds") = obj.searchyearwise(Session("UserAccountNumber"), year)
  115.         bindgrid_offlinemessage()
  116.     End Sub
  117.  
  118.     Public Sub from2todatewise_search(ByVal fromdate As String, ByVal todate As String)
  119.         Dim frommydate, tomydate As New Date
  120.         Dim fromdatewise, todatewise As String
  121.         Dim ds As New DataSet
  122.         Dim obj As New Offlinemessage
  123.         frommydate = CDate(fromdate)
  124.         tomydate = CDate(todate)
  125.         fromdatewise = Format(frommydate, "yyyy-MM-dd")
  126.         todatewise = Format(tomydate, "yyyy-MM-dd")
  127.         Session("Globalds") = obj.search_from2todatewise(Session("UserAccountNumber"), fromdatewise, todatewise)
  128.         bindgrid_offlinemessage()
  129.  
  130.     End Sub
  131.  
  132.     Public Sub bindgrid_offlinemessage()
  133.         ds = Session("Globalds")
  134.         OfflinemessageGridView.DataSource = ds
  135.         OfflinemessageGridView.DataBind()
  136.  
  137.  
  138.     End Sub
  139.  
  140.     Protected Sub OfflinemessageGridView_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles OfflinemessageGridView.PageIndexChanged
  141.  
  142.     End Sub
  143.  
  144.     Protected Sub OfflinemessageGridView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles OfflinemessageGridView.PageIndexChanging
  145.         OfflinemessageGridView.PageIndex = e.NewPageIndex
  146.         bindgrid_offlinemessage()
  147.  
  148.     End Sub
  149.  
  150.     Protected Sub OfflinemessageGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles OfflinemessageGridView.SelectedIndexChanged
  151.         Dim link As New LinkButton
  152.         Dim obj As New Offlinemessage
  153.         Dim txt As New HiddenField
  154.         Dim mydate As New Date
  155.         Dim ds As New DataSet
  156.         Dim username, userdate As String
  157.         link = CType(OfflinemessageGridView.SelectedRow.Cells(0).FindControl("OfflineMessageCustomerLinkButton"), LinkButton)
  158.         txt = CType(OfflinemessageGridView.SelectedRow.Cells(0).FindControl("OfflineMessageDateandTime"), HiddenField)
  159.         'MsgBox(txt.Value)
  160.         'MsgBox(link.Text)
  161.         username = link.Text
  162.         userdate = txt.Value
  163.         mydate = CDate(userdate)
  164.         'MsgBox(mydate)
  165.         Dim userdates As String
  166.         userdates = Format(mydate, "yyyy-MM-dd HH:mm:ss")
  167.         'MsgBox(userdates)
  168.         'ds = Session("Globalds")
  169.         ds = obj.get_offline_customerdetail(Session("UserAccountNumber"), username, userdates)
  170.         'bindgrid_offlinemessage()
  171.         show_offlinemessage(ds)
  172.     End Sub
  173.  
  174.     Public Sub show_offlinemessage(ByVal ds As DataSet)
  175.         Dim t1, t2 As New TextBox
  176.         t1.Text = ds.Tables(0).Rows(0).Item(0)
  177.         t2.Text = ds.Tables(0).Rows(0).Item(8)
  178.         VisitorFirstNameTextBox.Text = ds.Tables(0).Rows(0).Item(2)
  179.         VisitorLastNameTextBox.Text = ds.Tables(0).Rows(0).Item(3)
  180.         VisitorEmailidTextBox.Text = ds.Tables(0).Rows(0).Item(4)
  181.         VisitorPhonenumberTextBox.Text = ds.Tables(0).Rows(0).Item(5)
  182.         VisitorDateTextBox.Text = ds.Tables(0).Rows(0).Item(7)
  183.         VisitorDepartmentTextBox.Text = ds.Tables(0).Rows(0).Item(9)
  184.         'VisitorCountryTextbox.Text = ds.Tables(0).Rows(0).Item(10)
  185.         OfflinemessageQuery.Text = ds.Tables(0).Rows(0).Item(6)
  186.         If ds.Tables(0).Rows(0).Item(10).ToString.Trim = vbNullString Then
  187.             VisitorCountryTextbox.Text = ""
  188.         Else
  189.             VisitorCountryTextbox.Text = ds.Tables(0).Rows(0).Item(10)
  190.         End If
  191.     End Sub
  192.  
  193.     'This is for Advance Search Criteria.
  194.  
  195.     Protected Sub Advancesearchbutton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Advancesearchbutton.Click
  196.  
  197.         If (AdvanceSearchNameTextBox.Text <> "") Then
  198.             search_byname(AdvanceSearchNameTextBox.Text)
  199.         ElseIf (AdvanceSearchEmailidTextBox.Text <> "") Then
  200.             search_byemailid(AdvanceSearchEmailidTextBox.Text)
  201.         ElseIf (AdvanceSearchPhoneNoTextBox.Text <> "") Then
  202.             search_byContactno(AdvanceSearchPhoneNoTextBox.Text)
  203.         End If
  204.     End Sub
  205.  
  206.     Public Sub search_byname(ByVal customername As String)
  207.         Dim ds As New DataSet
  208.         Dim count As Integer
  209.         count = obj.count_customername(Session("UserAccountNumber"), customername)
  210.         If (count = 0) Then
  211.             'MsgBox("Customer You specified does not exists.....")
  212.             offlinecountlabel.Text = count & " Number of Offline Messages"
  213.         Else
  214.             offlinecountlabel.Text = count & " Number of Offline Messages"
  215.             ds = Session("Globalds")
  216.             Session("Globalds") = obj.search_customername(Session("UserAccountNumber"), customername)
  217.             bindgrid_offlinemessage()
  218.         End If
  219.     End Sub
  220.  
  221.     Public Sub search_byemailid(ByVal emailid As String)
  222.         Dim ds As New DataSet
  223.         Dim count As Integer
  224.         count = obj.count_customeremailid(Session("UserAccountNumber"), emailid)
  225.         If (count = 0) Then
  226.             'MsgBox("Customer with mail id you specified does not exists.....")
  227.             offlinecountlabel.Text = count & " Number of Offline Messages"
  228.         Else
  229.             offlinecountlabel.Text = count & " Number of Offline Messages"
  230.             ds = Session("Globalds")
  231.             Session("Globalds") = obj.search_emailid(Session("UserAccountNumber"), emailid)
  232.             bindgrid_offlinemessage()
  233.         End If
  234.     End Sub
  235.  
  236.     Public Sub search_byContactno(ByVal contact As String)
  237.         Dim ds As New DataSet
  238.         Dim count As Integer
  239.         count = obj.count_Contactno(Session("UserAccountNumber"), contact)
  240.         If (count = 0) Then
  241.             'MsgBox("Customer with contact number you specified does not exists.....")
  242.             offlinecountlabel.Text = count & " Number of Offline Messages"
  243.         Else
  244.             offlinecountlabel.Text = count & " Number of Offline Messages"
  245.             ds = Session("Globalds")
  246.             Session("Globalds") = obj.search_bycontactno(Session("UserAccountNumber"), contact)
  247.             bindgrid_offlinemessage()
  248.         End If
  249.     End Sub
  250. End Class
  251.  
Nov 1 '10 #1
3 1718
The better approach is use Class. And by using the classes it will seperate your Presentation Layer to Business Layer

In this case you can create a class Search and then you can put all the functions for search i-e search_byContactno,search_byName,search_byEmail in the Search class and call these functions from the page.
Nov 11 '10 #2
Hi Buddy,

Thank you. I can able to understand what you are saying. Above mentioned coding was written in code behind vb page. i have also written business layer and database layer. Shall i know what you are trying to say is to create one more class file and get the parameter from code behind page is it correct. please give me feedback.
Nov 13 '10 #3
Hi,

Yes what i want to establish is create search class in your business layer, and call the functions of search class by passing parameters from code behind page (presentation layer), and your database layer will perform the database operations. If you still have some questions then let me know.
thanks
Nov 13 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: evanescent.lurker | last post by:
Hi there, I was wondering is there a point in optimization in code style... I have used to put parenthesis around some php keywords, but they are not needed. For example, I always use: echo(...
18
by: craig | last post by:
I am curious about how many of you prefer style 1 vs. style 2, and why. Are there names for these style? style 1: method { }
63
by: Papadopoulos Giannis | last post by:
Which do you think is best? 1. a) type* p; b) type *p; 2. a) return (var); b) return(var); c) return var;
60
by: Eric | last post by:
I thought it might be fun to run a simple vote to discover the most preferred spacing style for a simple if statement with a single, simple boolean test. By my count, there are 32 possible...
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
39
by: Patrick | last post by:
The c# code style guide that I follow suggests that class variables (fields) be coded with camel casing, like this: int recordId; string name; It also suggests that variables within methods...
29
by: Ron Burd | last post by:
Hi, As my company is moving into C# they are enforcing the use of styling convention in the source code, such as methods naming conventions, newlines, etc. Does someone know of products that...
10
by: kiplring | last post by:
I made a input window derived from System.Windows.Forms.Form. What I use is just one property "inputWindow.Message". But System.Windows.Forms.Form has so many properties, functions, evnets. ...
86
by: PTY | last post by:
Which is better? lst = while lst: lst.pop() OR while len(lst) 0:
1
by: Jim Johnson | last post by:
is this C style coding? I don't seem to see much C++ code in this way. is this a bad programming practice? code seem ugly coding this way. =================
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.