473,382 Members | 1,409 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,382 software developers and data experts.

Help Writing Codes in Class.

10
Hello All,

I have created a .aspx page with 7 text boxes and a save button. On click event following code is fired. It save the property information to sql server and also generate a unique Id for that porperty and fatch that id and show it on that screen. I have created a .cs file for TrustConnectionString as below.

Can someone please help me or guide me, is this a good practice to write code? If not can you please help me how to break this large code into classes or method and call them one by one.

Thanks for your help.



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class Data_Entry___Update_Property : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{



if (!IsPostBack)
{

if (Request.QueryString["id"] != null )
{
lblEditProp.Text = Request.QueryString["id"];
string tid = lblEditProp.Text;
Label1.Text = tid;
Session["Tid"] = tid;
}
if (Session["Tid"] != null)
{
lblEditProp.Text = Session["Tid"].ToString();
string tid = lblEditProp.Text;
Label1.Text = tid;
Session["Tid"] = tid;
}


btnUpdate.Enabled = false;



if (lblEditProp.Text != "" )
{

TrustConnectionString tConnString = new TrustConnectionString();

SqlConnection conn = new SqlConnection(tConnString.ConString);

SqlCommand comm = new SqlCommand("EditProperty", conn);

comm.CommandType = CommandType.StoredProcedure;


SqlParameter paratrustid = new SqlParameter("@trustid", SqlDbType.VarChar);
paratrustid.Value = lblEditProp.Text;
comm.Parameters.Add(paratrustid);


SqlParameter paralocationcode = new SqlParameter("@locationcode", SqlDbType.VarChar);
paralocationcode.Value = int.Parse(Session["Locationid"].ToString());
comm.Parameters.Add(paralocationcode);


SqlParameter paraLocationID = new SqlParameter("@locationid", SqlDbType.VarChar);
paraLocationID.Value = Session["Location"].ToString();
comm.Parameters.Add(paraLocationID);


try
{
conn.Open();
SqlDataReader sdredit = comm.ExecuteReader();

while (sdredit.Read())
{
TtridentSale.Text = sdredit[0].ToString();
TOffer.Text = sdredit[1].ToString();
TAddress.Text = sdredit[2].ToString();
TCity.Text = sdredit[3].ToString();
TState.Text = sdredit[4].ToString();
TZip.Text = sdredit[5].ToString();
TAccountNumber.Text = sdredit[6].ToString();
btnSave.Enabled = false;
btnUpdate.Enabled = true;

}
}

catch (SqlException seq)
{
Label7.Text = seq.Message;
}

finally
{
if (conn.State == ConnectionState.Open)
{

conn.Close();
}
}


}

}
}

protected void btnSave_Click(object sender, EventArgs e)
{

TrustConnectionString tConnString = new TrustConnectionString();

SqlConnection conn = new SqlConnection(tConnString.ConString);
SqlCommand comm = new SqlCommand("insertPropertyInformation_test", conn);

comm.CommandType = CommandType.StoredProcedure;

SqlParameter para1 = new SqlParameter("@Tsale", SqlDbType.VarChar);
para1.Value = TtridentSale.Text;
comm.Parameters.Add(para1);

SqlParameter para2 = new SqlParameter("@Offer", SqlDbType.VarChar);
para2.Value = TOffer.Text;
comm.Parameters.Add(para2);

SqlParameter para3 = new SqlParameter("@propaddress", SqlDbType.VarChar);
para3.Value = TAddress.Text;
comm.Parameters.Add(para3);

SqlParameter para4 = new SqlParameter("@city", SqlDbType.VarChar);
para4.Value = TCity.Text;
comm.Parameters.Add(para4);

SqlParameter para5 = new SqlParameter("@state", SqlDbType.VarChar);
para5.Value = TState.Text.ToUpper();
comm.Parameters.Add(para5);

SqlParameter para6 = new SqlParameter("@zipcode", SqlDbType.VarChar);
para6.Value = TZip.Text;
comm.Parameters.Add(para6);


SqlParameter para7 = new SqlParameter("@locationcode", SqlDbType.VarChar);
para7.Value = int.Parse(Session["Locationid"].ToString());
comm.Parameters.Add(para7);


SqlParameter para8 = new SqlParameter("@locationid", SqlDbType.VarChar);
para8.Value = Session["Location"].ToString();
comm.Parameters.Add(para8);

SqlParameter parax = new SqlParameter("@tid", SqlDbType.Int);
parax.Direction = ParameterDirection.Output;
comm.Parameters.Add(parax);




try
{
conn.Open();
SqlDataReader sdr = comm.ExecuteReader();
Label2.Text = comm.Parameters["@tid"].Value.ToString();
string tidadd = Label2.Text;

Session["Tidadd"] = tidadd; //Session For TrustID


}

catch (SqlException seq)
{
Label7.Text = seq.Message;
}

finally
{
if (conn.State == ConnectionState.Open)
{

conn.Close();


}
}



string str1 = WebConfigurationManager.ConnectionStrings["Trust_Conn"].ConnectionString;

SqlConnection conn1 = new SqlConnection(str1);
SqlCommand comm1 = new SqlCommand("GetDepositeAccountNumber", conn1);
comm1.CommandType = CommandType.StoredProcedure;

SqlParameter para9 = new SqlParameter("@Tsale", SqlDbType.VarChar);
para9.Value = TtridentSale.Text;
comm1.Parameters.Add(para9);

SqlParameter para11 = new SqlParameter("@propaddress", SqlDbType.VarChar);
para11.Value = TAddress.Text;
comm1.Parameters.Add(para11);

SqlParameter para12 = new SqlParameter("@city", SqlDbType.VarChar);
para12.Value = TCity.Text;
comm1.Parameters.Add(para12);

SqlParameter para13 = new SqlParameter("@state", SqlDbType.VarChar);
para13.Value = TState.Text.ToUpper();
comm1.Parameters.Add(para13);

SqlParameter para14 = new SqlParameter("@zipcode", SqlDbType.VarChar);
para14.Value = TZip.Text;
comm1.Parameters.Add(para14);

try
{
conn1.Open();
SqlDataReader sdr1 = comm1.ExecuteReader();
while (sdr1.Read())
{
TAccountNumber.Text = sdr1[0].ToString();

}

conn1.Close();
}
catch (SqlException sqe)
{
Label7.Text = sqe.Message;
}
finally
{
if (conn1.State == ConnectionState.Open)
{

conn1.Close();



}

}




}
Mar 5 '07 #1
0 1342

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

Similar topics

5
by: ArShAm | last post by:
Hi there Please help me to optimize this code for speed I added /O2 to compiler settings I added /Oe to compiler settings for accepting register type request , but it seems that is not allowed...
8
by: Howard | last post by:
My friend is seeking help with some homework writting javascript. Please respond to here address at ghina@hotmail.com Thanks for your help in advance. Write java statement to perform the...
7
by: Dan Trowbridge | last post by:
He everyone, I am just getting started with .NET and I am having a porting problem. I get and error in code that lookssomething like this (really stripped down but you get the idea)... class...
6
by: Ryan | last post by:
Hi, I am confused with how NetworkStream works. My application needs to handle heavy requests sent through TCP socket connection. I use NetworkStream.Read method to get the stream...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
15
by: phillip.s.powell | last post by:
<style> div div table tr td a.navbar, div div table tr td font {display: none;} </style> <div class="navigationbar" style="background-color:Black; position: absolute; left:50%; top:127px;...
2
by: ricky | last post by:
Hi, I am student and I am doing a final year project on Zig-bee. I have to write low energy routing algorithms. I need to write routing algorithm for LEACH. If anybody can help with some links...
0
by: crisscross27 | last post by:
Hi, I found a page called "myflashfetish" where you chan choose mp3 players for my space, well the problem is this, I wanted to place 2 or more players in myspace in a particular place, I read...
3
by: creative1 | last post by:
hi everyone I am using vb6 and access2003 combination. I have divided product codes in several catagories(11,12... ) and then using these catagories to make product codes (11001,11002,...) . For my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.