473,544 Members | 1,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help Writing Codes in Class.

10 New Member
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 TrustConnection String 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.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Data.Sql Client;
using System.Web.Conf iguration;

public partial class Data_Entry___Up date_Property : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{



if (!IsPostBack)
{

if (Request.QueryS tring["id"] != null )
{
lblEditProp.Tex t = Request.QuerySt ring["id"];
string tid = lblEditProp.Tex t;
Label1.Text = tid;
Session["Tid"] = tid;
}
if (Session["Tid"] != null)
{
lblEditProp.Tex t = Session["Tid"].ToString();
string tid = lblEditProp.Tex t;
Label1.Text = tid;
Session["Tid"] = tid;
}


btnUpdate.Enabl ed = false;



if (lblEditProp.Te xt != "" )
{

TrustConnection String tConnString = new TrustConnection String();

SqlConnection conn = new SqlConnection(t ConnString.ConS tring);

SqlCommand comm = new SqlCommand("Edi tProperty", conn);

comm.CommandTyp e = CommandType.Sto redProcedure;


SqlParameter paratrustid = new SqlParameter("@ trustid", SqlDbType.VarCh ar);
paratrustid.Val ue = lblEditProp.Tex t;
comm.Parameters .Add(paratrusti d);


SqlParameter paralocationcod e = new SqlParameter("@ locationcode", SqlDbType.VarCh ar);
paralocationcod e.Value = int.Parse(Sessi on["Locationid "].ToString());
comm.Parameters .Add(paralocati oncode);


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


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

while (sdredit.Read() )
{
TtridentSale.Te xt = 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.Enabl ed = true;

}
}

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

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

conn.Close();
}
}


}

}
}

protected void btnSave_Click(o bject sender, EventArgs e)
{

TrustConnection String tConnString = new TrustConnection String();

SqlConnection conn = new SqlConnection(t ConnString.ConS tring);
SqlCommand comm = new SqlCommand("ins ertPropertyInfo rmation_test", conn);

comm.CommandTyp e = CommandType.Sto redProcedure;

SqlParameter para1 = new SqlParameter("@ Tsale", SqlDbType.VarCh ar);
para1.Value = TtridentSale.Te xt;
comm.Parameters .Add(para1);

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

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

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

SqlParameter para5 = new SqlParameter("@ state", SqlDbType.VarCh ar);
para5.Value = TState.Text.ToU pper();
comm.Parameters .Add(para5);

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


SqlParameter para7 = new SqlParameter("@ locationcode", SqlDbType.VarCh ar);
para7.Value = int.Parse(Sessi on["Locationid "].ToString());
comm.Parameters .Add(para7);


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

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




try
{
conn.Open();
SqlDataReader sdr = comm.ExecuteRea der();
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 = WebConfiguratio nManager.Connec tionStrings["Trust_Conn "].ConnectionStri ng;

SqlConnection conn1 = new SqlConnection(s tr1);
SqlCommand comm1 = new SqlCommand("Get DepositeAccount Number", conn1);
comm1.CommandTy pe = CommandType.Sto redProcedure;

SqlParameter para9 = new SqlParameter("@ Tsale", SqlDbType.VarCh ar);
para9.Value = TtridentSale.Te xt;
comm1.Parameter s.Add(para9);

SqlParameter para11 = new SqlParameter("@ propaddress", SqlDbType.VarCh ar);
para11.Value = TAddress.Text;
comm1.Parameter s.Add(para11);

SqlParameter para12 = new SqlParameter("@ city", SqlDbType.VarCh ar);
para12.Value = TCity.Text;
comm1.Parameter s.Add(para12);

SqlParameter para13 = new SqlParameter("@ state", SqlDbType.VarCh ar);
para13.Value = TState.Text.ToU pper();
comm1.Parameter s.Add(para13);

SqlParameter para14 = new SqlParameter("@ zipcode", SqlDbType.VarCh ar);
para14.Value = TZip.Text;
comm1.Parameter s.Add(para14);

try
{
conn1.Open();
SqlDataReader sdr1 = comm1.ExecuteRe ader();
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 1346

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

Similar topics

5
3522
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 and if I remove register type for "l" , time of generating codes doesn't change the original code makes some files , but I removed that section to...
8
2064
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 following 1) Total 11 -element array a into the first portion of array b, which
7
3464
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 dt { std::deque< class dt > dtdq; };
6
3311
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 data. The
1
3696
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am...
15
3838
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; margin-left: -400px; width: 800px; height: 26px"> <!-- CODE GOES HERE --> </div>
2
4993
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 where I can find basics on how to write routing algorithms. It will be great. I have tried to search alot on google but can't find any good links....
0
2800
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 another sources how to do that, so i tried to add "position:absolute;left:525px;top:250", i succeed moving the first player but i couldn´t move the second,...
3
1049
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 daily closing report I want to see totals of all catagories belonging to one catagory group. I want to retrieve sum of particular group of catagories....
0
7365
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7772
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7709
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5297
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1841
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
988
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.