TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dhimesh Parmar
NA
126
14.6k
I need suggestion optimised code for this program?
Feb 27 2018 11:44 PM
this is my code but i need more optimised code for this task
any budy can help for this task.
//This is Dal File
using
System;
using
System.Collections.Generic;
using
System.Data.SqlClient;
using
System.Linq;
using
System.Web;
using
HTML.Common;
using
HTML.BE;
using
System.Data;
namespace
HTML.DAL
{
public
class
clsUserDal:clsUserCommon
{
public
int
AddUser(clsUserBE objUserBE)
{
try
{
SqlCommand cmd =
new
SqlCommand(
"userIUD"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"Action"
,
"INSERT"
);
// cmd.Parameters.AddWithValue("userid", objUserBE.userId);
cmd.Parameters.AddWithValue(
"name"
, objUserBE.name);
cmd.Parameters.AddWithValue(
"emailid"
, objUserBE.emailid);
cmd.Parameters.AddWithValue(
"mobilenumber"
, objUserBE.mobilenumber);
cmd.Parameters.AddWithValue(
"status"
, objUserBE.status);
cmd.Parameters.AddWithValue(
"createOn"
, objUserBE.createdOn);
cmd.Parameters.AddWithValue(
"modifyOn"
, objUserBE.modifiedOn);
return
ExecuteNonQueryByCommand(cmd);
}
catch
(Exception ex)
{
HttpContext.Current.Trace.Warn(
"Error = "
+ ex.Message);
HttpContext.Current.Trace.Warn(
"StackTrace = "
+ ex.StackTrace);
}
return
0;
}
public
int
UpdateUser(clsUserBE objUserBE)
{
try
{
SqlCommand cmd =
new
SqlCommand(
"userIUD"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"Action"
,
"UPDATE"
);
cmd.Parameters.AddWithValue(
"userId"
, objUserBE.userId);
cmd.Parameters.AddWithValue(
"name"
, objUserBE.name);
cmd.Parameters.AddWithValue(
"emailid"
, objUserBE.emailid);
cmd.Parameters.AddWithValue(
"mobilenumber"
, objUserBE.mobilenumber);
cmd.Parameters.AddWithValue(
"modifyOn"
, objUserBE.modifiedOn);
return
ExecuteNonQueryByCommand(cmd);
}
catch
(Exception ex)
{
HttpContext.Current.Trace.Warn(
"Error = "
+ ex.Message);
HttpContext.Current.Trace.Warn(
"StackTrace = "
+ ex.StackTrace);
}
return
0;
}
public
int
DeleteClient(clsUserBE objUserBE)
{
try
{
SqlCommand cmd =
new
SqlCommand(
"userIUD"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"Action"
,
"DELETE"
);
cmd.Parameters.AddWithValue(
"userId"
, objUserBE.userId);
return
ExecuteNonQueryByCommand(cmd);
}
catch
(Exception ex)
{
HttpContext.Current.Trace.Warn(
"Error = "
+ ex.Message);
HttpContext.Current.Trace.Warn(
"StackTrace = "
+ ex.StackTrace);
}
return
0;
}
public
int
selectUser(clsUserBE objUserBE) {
try
{
SqlCommand cmd =
new
SqlCommand(
"userIUD"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"Action"
,
"SELECT"
);
cmd.Parameters.AddWithValue(
"userId"
, objUserBE.userId);
return
ExecuteNonQueryByCommand(cmd);
}
catch
(Exception ex)
{
HttpContext.Current.Trace.Warn(
"Error = "
+ ex.Message);
HttpContext.Current.Trace.Warn(
"StackTrace = "
+ ex.StackTrace);
}
return
0;
}
public
clsUserBE getUserByid(
int
id)
{
clsUserBE c =
new
clsUserBE();
SqlCommand cmd =
new
SqlCommand();
cmd.CommandText =
"select * from Users where userId= "
+ id;
DataSet ds = ExecuteSelect(cmd);
if
(ds.Tables[0].Rows.Count > 0)
{
c.userId = (
int
)ds.Tables[0].Rows[0][
"userId"
];
c.name = Convert.ToString(ds.Tables[0].Rows[0][
"name"
]);
c.emailid = Convert.ToString(ds.Tables[0].Rows[0][
"emailid"
]);
c.mobilenumber= Convert.ToString(ds.Tables[0].Rows[0][
"mobilenumber"
]);
}
return
c;
}
public
int
userStatusA(clsUserBE c)
{
try
{
SqlCommand cmd =
new
SqlCommand(
"useAID"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"Action"
,
"ActiveUser"
);
cmd.Parameters.AddWithValue(
"userId"
, c.userId);
cmd.Parameters.AddWithValue(
"status"
, c.status);
cmd.Parameters.AddWithValue(
"modifyOn"
, c.modifiedOn);
return
ExecuteNonQueryByCommand(cmd);
}
catch
(Exception ex)
{
HttpContext.Current.Trace.Warn(
"Error = "
+ ex.Message);
HttpContext.Current.Trace.Warn(
"StackTrace = "
+ ex.StackTrace);
}
return
0;
}
public
int
userStatusI(clsUserBE c)
{
try
{
SqlCommand cmd =
new
SqlCommand(
"useAID"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"Action"
,
"DeactiveUser"
);
cmd.Parameters.AddWithValue(
"userId"
, c.userId);
cmd.Parameters.AddWithValue(
"status"
, c.status);
cmd.Parameters.AddWithValue(
"modifyOn"
, c.modifiedOn);
return
ExecuteNonQueryByCommand(cmd);
}
catch
(Exception ex)
{
HttpContext.Current.Trace.Warn(
"Error = "
+ ex.Message);
HttpContext.Current.Trace.Warn(
"StackTrace = "
+ ex.StackTrace);
}
return
0;
}
public
int
userStatusD(clsUserBE c)
{
try
{
SqlCommand cmd =
new
SqlCommand(
"useAID"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"Action"
,
"DeleteUser"
);
cmd.Parameters.AddWithValue(
"userId"
, c.userId);
cmd.Parameters.AddWithValue(
"status"
, c.status);
cmd.Parameters.AddWithValue(
"modifyOn"
, c.modifiedOn);
return
ExecuteNonQueryByCommand(cmd);
}
catch
(Exception ex)
{
HttpContext.Current.Trace.Warn(
"Error = "
+ ex.Message);
HttpContext.Current.Trace.Warn(
"StackTrace = "
+ ex.StackTrace);
}
return
0;
}
//public clsUserBE deleteUser(int id)
//{
// clsUserBE c = new clsUserBE();
// SqlCommand cmd = new SqlCommand();
// cmd.CommandText = "delete from Users where userId= " + id;
// DataSet ds = ExecuteSelect(cmd);
// return c;
//}
public
DataSet getdata()
{
SqlCommand cmd =
new
SqlCommand();
cmd.CommandText =
" select * from Users where status!=2"
;
return
ExecuteSelect(cmd);
}
public
clsUserDal()
{
//
// TODO: Add constructor logic here
//
}
}
}
//this is common file
using
System;
using
System.Collections.Generic;
using
System.Configuration;
using
System.Data;
using
System.Data.SqlClient;
using
System.Linq;
using
System.Web;
namespace
HTML.Common
{
public
class
clsUserCommon
{
public
string
ConnectionString = ConfigurationManager.ConnectionStrings[
"MyDB"
].ToString();
public
int
ExecuteNonQueryByCommand(SqlCommand cmd)
{
SqlConnection con =
new
SqlConnection(ConnectionString);
con.Open();
cmd.Connection = con;
int
intRetval = cmd.ExecuteNonQuery();
con.Close();
return
intRetval;
}
public
DataSet ExecuteSelect(SqlCommand cmd)
{
SqlConnection con =
new
SqlConnection(ConnectionString);
con.Open();
cmd.Connection = con;
SqlDataAdapter sdp =
new
SqlDataAdapter(cmd);
DataSet dt =
new
DataSet();
sdp.Fill(dt);
con.Close();
return
dt;
}
}
}
this
is
aspx.cs file
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
HTML.DAL;
using
HTML.BE;
using
System.Data;
using
System.Text;
using
System.Data.SqlClient;
public
partial
class
html : System.Web.UI.Page
{
clsUserBE userBE=
new
clsUserBE();
clsUserDal userDAL=
new
clsUserDal();
public
DataSet ds =
null
;
protected
void
Page_Load(
object
sender, EventArgs e)
{
ds = userDAL.getdata();
//if (Request.QueryString["userId"] != "" && Convert.ToInt32(Request.QueryString["userId"]) > 0)
//{
// int x = Convert.ToInt32(Request.QueryString["userId"]);
// userBal = userDAL.deleteUser(x);
//}
if
(Request.QueryString[
"userId"
] !=
""
&& Convert.ToInt32(Request.QueryString[
"userId"
]) > 0 && Request.QueryString[
"action"
] ==
"ActiveUser"
)
{
// int x = Convert.ToInt32(Request.QueryString["userId"]);
userBE.userId = Convert.ToInt32(Request.QueryString[
"userId"
]);
userDAL.UpdateUser(userBE);
userBE.status = 1;
userBE.modifiedOn = DateTime.Now;
userDAL.userStatusA(userBE);
Response.Redirect(
"html.aspx"
);
//userBal = userDAL.userStatusA(x);
}
else
if
(Request.QueryString[
"userId"
] !=
""
&& Convert.ToInt32(Request.QueryString[
"userId"
]) > 0 && Request.QueryString[
"action"
] ==
"DeactiveUser"
)
{
userBE.userId = Convert.ToInt32(Request.QueryString[
"userId"
]);
userDAL.UpdateUser(userBE);
userBE.status = 0;
userBE.modifiedOn = DateTime.Now;
userDAL.userStatusI(userBE);
Response.Redirect(
"html.aspx"
);
}
else
if
(Request.QueryString[
"userId"
] !=
""
&& Convert.ToInt32(Request.QueryString[
"userId"
]) > 0 && Request.QueryString[
"action"
] ==
"DeleteUser"
)
{
userBE.userId = Convert.ToInt32(Request.QueryString[
"userId"
]);
userDAL.UpdateUser(userBE);
userBE.status = 2;
userBE.modifiedOn = DateTime.Now;
userDAL.userStatusD(userBE);
Response.Redirect(
"html.aspx"
);
}
}
}
Reply
Answers (
1
)
Unable to find Postgres datasource in EntityDataModel Wizard
Remove duplicates