Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I HAVE A SCANERI THAT THER IS DEFAULT ADMIN IN TABLE AND THIS ADMIN ADD FURHTER SUPERVIOSR,MANAGERS AND SENIOR MANAGERS THEN WHEN ADMIN FIRST TIME LOGIN AND CREATE ACCOUNTS OF SUPERVISOR,MANAGER,DIRECTOR

AND HERE IS THE TABLE

SQL
UserID	UserName Password UserTypeID	DepID	FullName CreateDate	DocID	Email	                  PhoneNumber	DesigID
51	Noreen	Fatima	    2	       NULL	NULL	2014-02-04 	NULL	noreen.fatimaa@gmail.com    324234234	4
52	Admin	Docum	    1	       NULL	NULL	NULL	NULL	NULL		                                3
53	Sundus   Khan	    1	        2	NULL	2014-02-04 	NULL	Sunduskhan@hotmail.com	031545646456	1
54	Hira	Mansoor	    1	        2	NULL	2014-02-04 	NULL	hiramansoor@gmail.com	0315546464	2
55	Sana	Khan	    1	        2	NULL	2014-02-04 	NULL	sanakhan@gmail.com	2043829429304	3
56	sundus	sundus	    1	        2	NULL	2014-02-04 	NULL	Sunduskhan@hotmail.com	87687678678	1


here depid 2 is computer science and design id 1=supervsior 2=manager 3=senior manager 4=basic user

so when admin login and want to create again account of supervsior and their department is computer sciecne . . now there this is not a logic

beacuse supervsior account with department omputer science already exist so why admin create another supervsior with same department

i use this sp

SQL
ALTER procedure [dbo].[spadminreg]
@UserName nvarchar(50),
@Password nvarchar(50),

@UserTypeID int,
@DepID int,
@DesigID int,


@emailaddress nvarchar(50),
@PhoneNumber nvarchar(50)

as
if EXISTS(SELECT 1  from Designation where DesigID=@DepID)
begin
select @DesigID as 'SuperVisor'
end
else if EXISTS (select 2 from Designation where DesigID=@DesigID)
begin
select @DesigID as 'Manager'
end
 else if EXISTS (select 3 from Designation where DesigID=@DesigID)
begin
select @DesigID as 'Senior Manager'
end
 else
insert into [Userss](UserName,Password,UserTypeID,DepID,CreateDate,DesigID,Email ,PhoneNumber)
values
(@UserName,@Password,@UserTypeID,@DepID,GETDATE(),@DesigID,@emailaddress,@PhoneNumber)


and it works for me

but when i fill textboxes and select same deisgnation with same department like deisgnation 2 and same department 2

then this record not add in table but in .aspx form it show me

"account add succesfully"

and i want to show failed in label

this is code

C#
 protected void Btn_SignUp_Click(object sender, EventArgs e)
        {
            try
            {

                c1.SignUp(nametxt.Value, passtxt.Value, Convert.ToInt32(DropDownList1.SelectedValue), Convert.ToInt32(DropDownList2.SelectedValue),Convert.ToInt32(DropDownList3.SelectedValue),mailtxt.Value,numbtxt.Value);
                //GridView1.DataSource=ca.viewadmin();
                Lbe6.Visible = true;
                 Lbe6.Text = ("Account Successfully Created");
                //  GridView1.DataBind();
            }
            catch
            {
                lbe5.Visible = true;

               lbe5.Text = ("SIGNUP FAILED.PLEASE TRY AGAIN");

            }
            nametxt.Value = "";
            passtxt.Value = "";
            
            mailtxt.Value = "";
            numbtxt.Value = "";

        }
    }

public void SignUp(string Username, string Password, int UserTypeID, int DepID, int desigid,string emailaddress , string PhoneNumber )
        {
            db.ExecuteNonQuery("spadminreg", new object[] { Username,Password, UserTypeID, DepID,desigid,  emailaddress,PhoneNumber });
        }



please help meee i will very thankful
Posted
Updated 4-Feb-14 3:16am
v3

1 solution

ALTER procedure [dbo].[spadminreg]
@UserName nvarchar(50),
@Password nvarchar(50),
 
@UserTypeID int,
@DepID int,
@DesigID int,
 

@emailaddress nvarchar(50),
@PhoneNumber nvarchar(50)
 
as
if EXISTS(SELECT 1  from Designation where DesigID==@DepID)
begin
select @DesigID as 'SuperVisor'
end
else if(select 2 from Designation where DesigID==@DesigID)
begin
select @DesigID as 'Manager'
end
else if(select 3 from Designation where DesigID==@DesigID)
begin
select @DesigID as 'Senior Manager'
end
else 
insert into [Userss](UserName,Password,UserTypeID,DepID,CreateDate,DesigID,Email ,PhoneNumber)
values
(@UserName,@Password,@UserTypeID,@DepID,GETDATE(),@DesigID,@emailaddress,@PhoneNumber)


Edit: Added Code Block for Formatting and Readability.
 
Share this answer
 
v3
Comments
thatraja 4-Feb-14 8:35am    
Suggestion : Format the query using Code-block
Diya Ayesa 4-Feb-14 8:49am    
ok i try this sp
and it works for me

ALTER procedure [dbo].[spadminreg]
@UserName nvarchar(50),
@Password nvarchar(50),

@UserTypeID int,
@DepID int,
@DesigID int,
@emailaddress nvarchar(50),
@PhoneNumber nvarchar(50)

as
if EXISTS(SELECT 1 from Designation where DesigID=@DepID)
begin
select @DesigID as 'SuperVisor'
end
else if EXISTS (select 2 from Designation where DesigID=@DesigID)
begin
select @DesigID as 'Manager'
end
else if EXISTS (select 3 from Designation where DesigID=@DesigID)
begin
select @DesigID as 'Senior Manager'
end
else
insert into [Userss](UserName,Password,UserTypeID,DepID,CreateDate,DesigID,Email ,PhoneNumber)
values
(@UserName,@Password,@UserTypeID,@DepID,GETDATE(),@DesigID,@emailaddress,@PhoneNumber)



but
but when i fill textboxes and select same deisgnation with same department like deisgnation 2 and same department 2

then this record not add in table but in .aspx form it show me

"account add succesfully"

and i want to show failed in label

this is code

protected void Btn_SignUp_Click(object sender, EventArgs e)
{
try
{

c1.SignUp(nametxt.Value, passtxt.Value, Convert.ToInt32(DropDownList1.SelectedValue), Convert.ToInt32(DropDownList2.SelectedValue),Convert.ToInt32(DropDownList3.SelectedValue),mailtxt.Value,numbtxt.Value);
//GridView1.DataSource=ca.viewadmin();
Lbe6.Visible = true;
Lbe6.Text = ("Account Successfully Created");
// GridView1.DataBind();
}
catch
{
lbe5.Visible = true;

lbe5.Text = ("SIGNUP FAILED.PLEASE TRY AGAIN");

}
nametxt.Value = "";
passtxt.Value = "";

mailtxt.Value = "";
numbtxt.Value = "";

}
}

public void SignUp(string Username, string Password, int UserTypeID, int DepID, int desigid,string emailaddress , string PhoneNumber )
{
db.ExecuteNonQuery("spadminreg", new object[] { Username,Password, UserTypeID, DepID,desigid, emailaddress,PhoneNumber });
}


please help meee i will very thankful
thatraja 4-Feb-14 8:59am    
You replied to wrong person. Do onething. Update this details in your question(In comments, code format looks bad). And notify that person.
Diya Ayesa 4-Feb-14 9:13am    
ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900