Dot Net Project Code
1) Table Creation
CREATE TABLE [dbo].[Batches](
[Bat
[BatchNo] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FromTiming] [datetime] NULL,
[ToTiming] [datetime] NULL,
[EnteredBy] [bigint] NULL,
[EnteredDate] [datetime] NULL,
[UpdatedBy] [bigint] NULL,
[UpdateDate] [datetime] NULL,
[IsActive] [bit] NULL,
CONSTRAINT [PK_Batches] PRIMARY KEY CLUSTERED
(
2) Stored Procedure:
create procedure [dbo].[USP_IDFU_Baches]
(@Type char(1)=null,
@Batchid bigint=null,
@BatchNo varchar(20)=null,
@FromTiming datetime=null,
@ToTiming datetime=null,
@EnteredBy bigint=null,
@EnteredDate datetime=null,
@UpdatedBy bigint=null,
@UpdateDate datetime=null,
@IsActive bit=null)
as
if(@type='I')begin
insert into Batches(BatchNo,FromTiming,ToTiming,EnteredBy,EnteredDate,UpdatedBy,
UpdateDate,IsActive)
values(@BatchNo,@FromTiming,@ToTiming,@EnteredBy,@EnteredDate,@UpdatedBy,
@UpdateDate,1)
end
if(@type='D')
begin
declare @sts bit
select @sts=isactive from Batches where batchid=@batchid
if(@sts=1) begin
update Batches set isactive=0 where batchid=@batchid
end
else begin
update Batches set isactive=1 where batchid=@batchid
end
end
if(@type='F')begin
select *from Batches where IsActive =1
end
if(@type='U')begin
update Batches set BatchNo=@BatchNo,FromTiming=@FromTiming,ToTiming=@ToTiming,
EnteredBy=@EnteredBy,EnteredDate=@EnteredDate,UpdatedBy=@UpdatedBy,
UpdateDate=@UpdateDate,IsActive=@IsActive where batchid=@batchid
end
if(@type='SF')begin
select * from TranieeBatches s where s.batchid=@batchid
end
3) Class file Creation:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
namespace VBOMS.API
{
public class Batches:DbManager
{
# region veriables
private Int64 _BatchID;
private string _BatchNo;
private string _FromTiming;
private string _ToTiming;
private Int64 _EnteredBy;
private DateTime _EnterDate;
private Int64 _UpdatedBy;
private DateTime _UpdateDate;
private bool _IsActive;
#endregion
#region properties
public Int64 BatchID
{
get { return _BatchID; }
set { _BatchID = value; }
}
public string BatchNo
{
get { return _BatchNo; }
set { _BatchNo = value; }
}
public string FromTiming
{
get { return _FromTiming; }
set { _FromTiming = value; }
}
public string ToTiming
{
get { return _ToTiming; }
set { _ToTiming = value; }
}
public Int64 EnteredBy
{
get { return _EnteredBy; }
set { _EnteredBy = value; }
}
public DateTime EnterDate
{
get { return _EnterDate; }
set { _EnterDate = value; }
}
public Int64 UpdatedBy
{
get { return _UpdatedBy; }
set { _UpdatedBy = value; }
}
public DateTime UpdateDate
{
get { return _UpdateDate; }
set { _UpdateDate = value; }
}
public bool IsActive
{
get { return _IsActive; }
set { _IsActive = value; }
}
#endregion
#region functions
public bool Save()
{
try
{
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","I"),
new SqlParameter("@BatchID",this.BatchID),
new SqlParameter("@BatchNo",this.BatchNo),
new SqlParameter("@FromTiming",this.FromTiming),
new SqlParameter("@ToTiming",this.ToTiming),
new SqlParameter("@EnteredBy",this.EnteredBy),
new SqlParameter("@EnteredDate",this.EnterDate),
new SqlParameter("@UpdatedBy",this.UpdatedBy),
new SqlParameter("@UpDateDate",this.UpdateDate),
new SqlParameter("@IsActive",this.IsActive)
};
int result = ExecuteNonQuery("USP_IDFU_Baches", parameter);
if (result > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
public bool Update()
{
try
{
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","U"),
new SqlParameter("@BatchID",this.BatchID),
new SqlParameter("@BatchNo",this.BatchNo),
new SqlParameter ("@FromTiming",this.FromTiming),
new SqlParameter("@ToTiming",this.ToTiming),
new SqlParameter("@EnteredBy",this.EnteredBy),
new SqlParameter("@EnteredDate",this.EnterDate),
new SqlParameter("@UpdatedBy",this.UpdatedBy),
new SqlParameter("@UpDateDate",this.UpdateDate),
new SqlParameter("@IsActive",this.IsActive)
};
int result = ExecuteNonQuery("USP_IDFU_Baches", parameter);
if (result > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
public bool Delete()
{
try
{
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","D"),
new SqlParameter("@BatchID",this.BatchID),
new SqlParameter("@IsActive",this.IsActive)
};
int result = ExecuteNonQuery("USP_IDFU_Baches", parameter);
if (result > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
public DataSet Fecth()
{
try
{
DbManager objDb = new DbManager();
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","F"),
//new SqlParameter("@BatchID",this.BatchID),
//new SqlParameter("@BatchNo",this.BatchNo),
//new SqlParameter ("@FromTimings",this.FromTiming),
//new SqlParameter("@ToTiming",this.ToTiming),
//new SqlParameter("@EnteredBy",this.EnteredBy),
//new SqlParameter("@EnterDate",this.EnterDate),
//new SqlParameter("@UpdatedBy",this.UpdatedBy),
//new SqlParameter("@UpDateDate",this.UpdateDate),
//new SqlParameter("@IsActive",this.IsActive)
};
DataSet ds=objDb.ExecuteDataSet("USP_IDFU_Baches", parameter);
return ds;
}
catch (Exception ex)
{
throw;
}
}
public DataSet SelectFecth()
{
try
{
DbManager objDb = new DbManager();
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","SF"),
//new SqlParameter("@BatchID",this.BatchID),
//new SqlParameter("@BatchNo",this.BatchNo),
//new SqlParameter ("@FromTimings",this.FromTiming),
//new SqlParameter("@ToTiming",this.ToTiming),
//new SqlParameter("@EnteredBy",this.EnteredBy),
//new SqlParameter("@EnterDate",this.EnterDate),
//new SqlParameter("@UpdatedBy",this.UpdatedBy),
//new SqlParameter("@UpDateDate",this.UpdateDate),
//new SqlParameter("@IsActive",this.IsActive)
};
DataSet ds = objDb.ExecuteDataSet("USP_IDFU_Baches", parameter);
return ds;
}
catch (Exception ex)
{
throw;
}
}
#endregion
}
}
4) DB Manager:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace VBOMS.API
{
public class DbManager
{
SqlConnection objCon;
SqlCommand objCmd;
SqlDataAdapter objAd;
DataSet objDS;
private void Connection()
{
objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
if (objCon.State == ConnectionState.Closed)
objCon.Open();
}
public int ExecuteNonQuery(string objStr, SqlParameter[] parameter)
{
try
{
Connection();
objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = objStr;
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Parameters.AddRange(parameter);
int result = objCmd.ExecuteNonQuery();
objCon.Close();
return result;
}
catch (Exception ex)
{
throw;
}
}
public object ExecuteScalar(string objStr, SqlParameter[] parameter)
{
try
{
objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = objStr;
objCmd.CommandType = CommandType.StoredProcedure;
Connection();
objCmd.Parameters.AddRange(parameter);
object result = objCmd.ExecuteScalar();
objCon.Close();
return result;
}
catch (Exception ex)
{
throw;
}
}
public DataSet ExecuteDataSet(string objStr, SqlParameter[] parameter)
{
try
{
objCmd = new SqlCommand();
objDS = new DataSet();
Connection();
objCmd.CommandText = objStr;
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Connection = objCon;
objCmd.Parameters.AddRange(parameter);
objAd = new SqlDataAdapter();
objAd.SelectCommand = objCmd;
objAd.Fill(objDS);
return objDS;
}
catch (Exception ex)
{
throw;
}
}
}
}
5) ASPX Form:
Ø Form Design:
Ø Source Code: (frmBatches.aspx)
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="frmBatches.aspx.cs" Inherits="VBOMS.frmBatches"
MasterPageFile="VBOMS.Master" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="vbContentPlaceHolder">
<table align="center">
<tr align="center">
<td align="right">
BatchNotd>
<td>
:td>
<td>
<asp:TextBox ID="txtBatchNo" runat="server">asp:TextBox>
td>
tr>
<tr align="center">
<td align="right">
FromTimingtd>
<td>
:td>
<td>
<asp:TextBox ID="txtFromTiming" runat="server">asp:TextBox>
td>
tr>
<tr align="center">
<td align="right">
ToTimingtd>
<td >
:td>
<td>
<asp:TextBox ID="txtToTiming" runat="server">asp:TextBox>
td>
tr>
<tr>
<td colspan="3" align="center">
<asp:HiddenField ID="hdnBatchesId" runat="server" />
td>
tr>
<tr align="center">
<td align="center" colspan="3">
<asp:Button ID="btnSave" runat="server" CssClass="buttonStyle" Text="Save" OnClick="btnSave_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="buttonStyle" OnClick="btnCancel_Click" CausesValidation="False" />
td>
tr>
<tr>
<td align="center" colspan="3">
<asp:Label ID="lblmessage" runat="server" Text="lblMessage" BackColor="White">asp:Label>td>
tr>
<tr>
<td align="center" colspan="3">
<table align="center" border="0" cellpadding="2" cellspacing="0">
<tr>
<td>
<asp:GridView ID="gvBatches" runat="server" AutoGenerateColumns="false"
OnRowDeleting="gvBatches_RowDeleting" OnRowEditing="gvBatches_RowEditing" >
<Columns>
<asp:BoundField DataField="BatchNo" HeaderText="BatchNo" />
<asp:BoundField DataField="FromTiming" HeaderText="FromTiming" />
<asp:BoundField DataField="ToTiming" HeaderText="ToTiming" />
<asp:BoundField DataField="BatchId" HeaderText="BatchId" ItemStyle-CssClass="hidecolumn"
HeaderStyle-CssClass="hidecolumn" />
<asp:ButtonField ButtonType="Link" HeaderText="Edit" Text="Edit" CommandName="edit" />
<asp:ButtonField ButtonType="Link" Text="Delete" CommandName="Delete" />
Columns>
asp:GridView>
td>
tr>
table>
td>
tr>
table>
asp:Content>
Ø frmBatches.Aspx.Cs
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 VBOMS.API;
namespace VBOMS
{
public partial class frmBatches : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillBatches();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
Batches objBatch = new Batches();
objBatch.BatchNo = txtBatchNo.Text;
objBatch.FromTiming = txtFromTiming.Text;
objBatch.ToTiming = txtToTiming.Text;
objBatch.EnterDate = DateTime.UtcNow.AddHours(5.5);
objBatch.UpdateDate = DateTime.UtcNow.AddHours(5.5);
objBatch.IsActive = true;
bool result = false;
objBatch.BatchID = onvert.ToInt32(Request.QueryString["BatchId"]);
if (hdnBatchesId.Value=="")
{
result = objBatch.Save();
}
else
{
objBatch.BatchID = Convert.ToInt32(hdnBatchesId.Value);
result = objBatch.Update();
}
if (result)
{
lblmessage.Text = "Updated Successfully";
ClearControlsData();
FillBatches();
}
else
{
lblmessage.Text = "Already Exist";
}
}
public void FillBatches()
{
Batches objBatch = new Batches();
DataSet objDS = new DataSet();
objDS = objBatch.Fecth();
if (objDS.Tables[0].Rows.Count > 0)
{
gvBatches.DataSource = objDS;
gvBatches.DataBind();
}
}
private void ClearControlsData()
{
txtBatchNo.Text = "";
txtFromTiming.Text = "";
txtToTiming.Text = "";
}
protected void gvBatches_RowEditing(object sender, GridViewEditEventArgs e)
{
txtBatchNo.Text = gvBatches.Rows[e.NewEditIndex].Cells[0].Text;
txtFromTiming.Text = gvBatches.Rows[e.NewEditIndex].Cells[1].Text;
txtToTiming.Text = gvBatches.Rows[e.NewEditIndex].Cells[2].Text;
hdnBatchesId.Value = gvBatches.Rows[e.NewEditIndex].Cells[3].Text;
}
protected void btnCancel_Click(object sender, EventArgs e)
{
ClearControlsData();
}
protected void gvBatches_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Batches objbatch = new Batches();
objbatch.BatchID = Convert.ToInt32(gvBatches.Rows[e.RowIndex].Cells[3].Text);
if (objbatch.Delete())
{
lblmessage.Text = "Status Changed Succuessfully";
FillBatches();
}
}
}
}
6) Web Config:
configSections>
<connectionStrings>
<add name="conStr" connectionString="data source=VIJAY\DATASERVER;user id=sa;pwd=vb_123;database=VBOMS"/>
<add name="VBOMSConnectionString1" connectionString="Data Source=VIJAY\DATASERVER;Initial Catalog=VBOMS;User ID=sa;Password=vb_123" providerName="System.Data.SqlClient"/>
connectionStrings>
How to Fill Data in DropDownList:
public void FillOccupation()
{
OccupationDetails objOd = new OccupationDetails();
DataSet ds = new DataSet();
ds = objOd.Fetch();
if (ds.Tables[0].Rows.Count > 0)
{
ddlOccupation.DataValueField = "OccupationId";
ddlOccupation.DataTextField = "OccupationName";
ddlOccupation.DataSource = ds;
ddlOccupation.DataBind();
ddlOccupation.Items.Insert(0, "Select");
}
}
How to Fill Data in GridView:
public void FillOccupation()
{
OccupationDetails objOc = new OccupationDetails();
DataSet objDs = new DataSet();
objDs = objOc.Fetch();
if (objDs.Tables[0].Rows.Count > 0)
{
gvOccupation.DataSource = objDs;
}
else
{
gvOccupation.DataSource = null;
}
gvOccupation.DataBind();
}
Row Editing and Deleting:
protected void gvOccupation_RowEditing(object sender,GridViewEditEventArgs e)
{
txtOccupation.Text = gvOccupation.Rows[e.NewEditIndex].Cells[0].Text;
hdnOccupationId.Value = gvOccupation.Rows[e.NewEditIndex].Cells[1].Text;
}
protected void gvOccupation_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
OccupationDetails objOc = new OccupationDetails();
objOc.OccupationId = Convert.ToInt32(gvOccupation.Rows[e.RowIndex].Cells[01].Text);
if (objOc.Delete())
{
lblMessage.Text = "Status Changed Successfully";
FillOccupation();
}
}
FrmRegistration.aspx:
Under Save Button:
protected void btnSave_Click(object sender, EventArgs e)
{
Registration objReg = new Registration();
objReg.FirstName = txtFirstName.Text;
objReg.LastName = txtLastName.Text;
objReg.DOB = Convert.ToDateTime(txtDOB.Text);
objReg.Gender = rblGender.Text;
objReg.PhoneNo = txtPhoneNo.Text;
objReg.EmailId = txtEmailId.Text;
objReg.OccupationId = Convert.ToInt32(ddlOccupation.SelectedItem.Value);
objReg.TechnologyId = Convert.ToInt32(ddlTechnology.SelectedValue);
objReg.ReferenceID = Convert.ToInt32(ddlReference.SelectedValue);
objReg.IsOnline = rblIsOnline.SelectedValue;
if (objReg.save())
{
Address objAdd = new Address();
objAdd.TraineeID = objReg.TraineeId;
objAdd.CurrentLocation = txtCurrentLocation.Text;
objAdd.Country = ddlCountry.SelectedItem.Text;
objAdd.PinCode = Convert.ToInt32(txtPinCode.Text);
objAdd.EnteredDate = DateTime.UtcNow.AddHours(5.5);
objAdd.UpdatedDate = DateTime.UtcNow.AddHours(5.5);
if (objAdd.Save())
{
bool isEduSaved = false;
EducationDetails objEdu = new EducationDetails();
objEdu.TraineeID = Convert.ToInt16(objAdd.TraineeID);
objEdu.EnterDate = DateTime.UtcNow.AddHours(5.5);
objEdu.UpdateDate = DateTime.UtcNow.AddHours(5.5);
foreach (GridViewRow row in gvEducationType.Rows)
{
objEdu.EducationTypeId = row.Cells[0].Text == " " ? Convert.ToInt16(0) : Convert.ToInt16(row.Cells[0].Text);
TextBox txtCour = (TextBox)row.FindControl("txtCourse");
objEdu.Course = txtCour.Text;
TextBox txtUniName = (TextBox)row.FindControl("txtUniversity");
objEdu.University = txtUniName.Text;
TextBox txtYearPass = (TextBox)row.FindControl("txtYearOfPassing");
objEdu.YearOfPassing = Convert.ToDateTime(txtYearPass.Text);
TextBox txtAggrigate = (TextBox)row.FindControl("txtAggregate");
objEdu.Aggregate = float.Parse(txtAggrigate.Text);
isEduSaved = objEdu.Save();
}
if (isEduSaved)
{
Certification objCer = new Certification();
objCer.Technology = txtTechnology.Text;
objCer.CoursePeriod = Convert.ToDateTime(txtCoursePeriod.Text);
objCer.EnteredDate = DateTime.UtcNow.AddHours(5.5);
objCer.UpdatedDate = DateTime.UtcNow.AddHours(5.5);
if (objCer.Save())
{
string strBody = "WelCome To ViswgnaBharathi" +
" Welcome to Viswgna Bharathi, Your Userid : " + txtEmailId.Text + " Password : " + txtPassword.Text + "";
if (Utility.SendMail(txtEmailId.Text, "vkouru@viswgnabharathi.com", "Your Registration is Successful", strBody))
{
lblMessage.Text = "Message Send Successfully";
}
else
{
lblMessage.Text = "Message Sending Failed";
}
}
else
{
lblMessage.Text = "Already Existed";
}
}
else
{
lblMessage.Text = "Please check your details once again";
}
}
}
}
frmLogin.aspx:
Under Login Button:
protected void btnLoging_Click(object sender, EventArgs e)
{
UserLogin objlogin = new UserLogin();
objlogin.UserName = txtUsername.Text;
objlogin.Password = txtPassword.Text;
if (objlogin.CheckLoginDetails())
{
lblmessage.Text = "Login SuccessFully";
}
else
{
lblmessage.Text = "Invalid User";
}
}
CheckLoginDetails()
public bool CheckLoginDetails()
{
SqlParameter[] objSqlParams = new SqlParameter[]
{
new SqlParameter("@Type","CL"),
new SqlParameter("@UserName",this.UserName),
new SqlParameter("@PassWord",this.Password)
};
DataSet objDs = ExecuteDataSet("USP_IDFU_UserLogin", objSqlParams);
if (objDs.Tables[0].Rows.Count > 0)
{
return true;
}
else
return false;
//return (objDs.Tables[0].Rows.Count > 0);
}
StorePrcedure:
ALTER procedure [dbo].[USP_IDFU_UserLogin]
(@Type char(1)=null,
@UserId bigint=null,
@UserName varchar(50)=null,
@PassWord varchar(30)=null,
@EnterDate datetime=null,
@UpdatedDate datetime=null,
@IsActive bit=null)
as
if(@Type='I')begin
insert into UserLogin(UserName,PassWord,EnterDate,UpdatedDate,IsActive)
values(@UserName,@PassWord,@EnterDate,@UpdatedDate,@IsActive)
end
if(@Type='D')begin
delete from UserLogin where UserId=@UserId
end
if(@Type='F')begin
select *from UserLogin where UserName=@UserName and PassWord=@PassWord
end
if(@Type='U')begin
update UserLogin set UserName=@UserName,PassWord=@PassWord,EnterDate=@EnterDate,
UpdatedDate=@UpdatedDate,IsActive=@IsActive where UserId=@UserId
end
if(@type='CL')begin
select * from UserLogin where UserName=@UserName and PassWord=@PassWord
end
Dot Net Project Code
1) Table Creation
CREATE TABLE [dbo].[Batches](
[BatchId] [bigint] IDENTITY(1,1) NOT NULL,
[BatchNo] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FromTiming] [datetime] NULL,
[ToTiming] [datetime] NULL,
[EnteredBy] [bigint] NULL,
[EnteredDate] [datetime] NULL,
[UpdatedBy] [bigint] NULL,
[UpdateDate] [datetime] NULL,
[IsActive] [bit] NULL,
CONSTRAINT [PK_Batches] PRIMARY KEY CLUSTERED
(
2) Stored Procedure:
create procedure [dbo].[USP_IDFU_Baches]
(@Type char(1)=null,
@Batchid bigint=null,
@BatchNo varchar(20)=null,
@FromTiming datetime=null,
@ToTiming datetime=null,
@EnteredBy bigint=null,
@EnteredDate datetime=null,
@UpdatedBy bigint=null,
@UpdateDate datetime=null,
@IsActive bit=null)
as
if(@type='I')begin
insert into Batches(BatchNo,FromTiming,ToTiming,EnteredBy,EnteredDate,UpdatedBy,
UpdateDate,IsActive)
values(@BatchNo,@FromTiming,@ToTiming,@EnteredBy,@EnteredDate,@UpdatedBy,
@UpdateDate,1)
end
if(@type='D')
begin
declare @sts bit
select @sts=isactive from Batches where batchid=@batchid
if(@sts=1) begin
update Batches set isactive=0 where batchid=@batchid
end
else begin
update Batches set isactive=1 where batchid=@batchid
end
end
if(@type='F')begin
select *from Batches where IsActive =1
end
if(@type='U')begin
update Batches set BatchNo=@BatchNo,FromTiming=@FromTiming,ToTiming=@ToTiming,
EnteredBy=@EnteredBy,EnteredDate=@EnteredDate,UpdatedBy=@UpdatedBy,
UpdateDate=@UpdateDate,IsActive=@IsActive where batchid=@batchid
end
if(@type='SF')begin
select * from TranieeBatches s where s.batchid=@batchid
end
3) Class file Creation:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
namespace VBOMS.API
{
public class Batches:DbManager
{
# region veriables
private Int64 _BatchID;
private string _BatchNo;
private string _FromTiming;
private string _ToTiming;
private Int64 _EnteredBy;
private DateTime _EnterDate;
private Int64 _UpdatedBy;
private DateTime _UpdateDate;
private bool _IsActive;
#endregion
#region properties
public Int64 BatchID
{
get { return _BatchID; }
set { _BatchID = value; }
}
public string BatchNo
{
get { return _BatchNo; }
set { _BatchNo = value; }
}
public string FromTiming
{
get { return _FromTiming; }
set { _FromTiming = value; }
}
public string ToTiming
{
get { return _ToTiming; }
set { _ToTiming = value; }
}
public Int64 EnteredBy
{
get { return _EnteredBy; }
set { _EnteredBy = value; }
}
public DateTime EnterDate
{
get { return _EnterDate; }
set { _EnterDate = value; }
}
public Int64 UpdatedBy
{
get { return _UpdatedBy; }
set { _UpdatedBy = value; }
}
public DateTime UpdateDate
{
get { return _UpdateDate; }
set { _UpdateDate = value; }
}
public bool IsActive
{
get { return _IsActive; }
set { _IsActive = value; }
}
#endregion
#region functions
public bool Save()
{
try
{
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","I"),
new SqlParameter("@BatchID",this.BatchID),
new SqlParameter("@BatchNo",this.BatchNo),
new SqlParameter("@FromTiming",this.FromTiming),
new SqlParameter("@ToTiming",this.ToTiming),
new SqlParameter("@EnteredBy",this.EnteredBy),
new SqlParameter("@EnteredDate",this.EnterDate),
new SqlParameter("@UpdatedBy",this.UpdatedBy),
new SqlParameter("@UpDateDate",this.UpdateDate),
new SqlParameter("@IsActive",this.IsActive)
};
int result = ExecuteNonQuery("USP_IDFU_Baches", parameter);
if (result > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
public bool Update()
{
try
{
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","U"),
new SqlParameter("@BatchID",this.BatchID),
new SqlParameter("@BatchNo",this.BatchNo),
new SqlParameter ("@FromTiming",this.FromTiming),
new SqlParameter("@ToTiming",this.ToTiming),
new SqlParameter("@EnteredBy",this.EnteredBy),
new SqlParameter("@EnteredDate",this.EnterDate),
new SqlParameter("@UpdatedBy",this.UpdatedBy),
new SqlParameter("@UpDateDate",this.UpdateDate),
new SqlParameter("@IsActive",this.IsActive)
};
int result = ExecuteNonQuery("USP_IDFU_Baches", parameter);
if (result > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
public bool Delete()
{
try
{
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","D"),
new SqlParameter("@BatchID",this.BatchID),
new SqlParameter("@IsActive",this.IsActive)
};
int result = ExecuteNonQuery("USP_IDFU_Baches", parameter);
if (result > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
public DataSet Fecth()
{
try
{
DbManager objDb = new DbManager();
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","F"),
//new SqlParameter("@BatchID",this.BatchID),
//new SqlParameter("@BatchNo",this.BatchNo),
//new SqlParameter ("@FromTimings",this.FromTiming),
//new SqlParameter("@ToTiming",this.ToTiming),
//new SqlParameter("@EnteredBy",this.EnteredBy),
//new SqlParameter("@EnterDate",this.EnterDate),
//new SqlParameter("@UpdatedBy",this.UpdatedBy),
//new SqlParameter("@UpDateDate",this.UpdateDate),
//new SqlParameter("@IsActive",this.IsActive)
};
DataSet ds=objDb.ExecuteDataSet("USP_IDFU_Baches", parameter);
return ds;
}
catch (Exception ex)
{
throw;
}
}
public DataSet SelectFecth()
{
try
{
DbManager objDb = new DbManager();
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@type","SF"),
//new SqlParameter("@BatchID",this.BatchID),
//new SqlParameter("@BatchNo",this.BatchNo),
//new SqlParameter ("@FromTimings",this.FromTiming),
//new SqlParameter("@ToTiming",this.ToTiming),
//new SqlParameter("@EnteredBy",this.EnteredBy),
//new SqlParameter("@EnterDate",this.EnterDate),
//new SqlParameter("@UpdatedBy",this.UpdatedBy),
//new SqlParameter("@UpDateDate",this.UpdateDate),
//new SqlParameter("@IsActive",this.IsActive)
};
DataSet ds = objDb.ExecuteDataSet("USP_IDFU_Baches", parameter);
return ds;
}
catch (Exception ex)
{
throw;
}
}
#endregion
}
}
4) DB Manager:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace VBOMS.API
{
public class DbManager
{
SqlConnection objCon;
SqlCommand objCmd;
SqlDataAdapter objAd;
DataSet objDS;
private void Connection()
{
objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
if (objCon.State == ConnectionState.Closed)
objCon.Open();
}
public int ExecuteNonQuery(string objStr, SqlParameter[] parameter)
{
try
{
Connection();
objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = objStr;
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Parameters.AddRange(parameter);
int result = objCmd.ExecuteNonQuery();
objCon.Close();
return result;
}
catch (Exception ex)
{
throw;
}
}
public object ExecuteScalar(string objStr, SqlParameter[] parameter)
{
try
{
objCmd = new SqlCommand();
objCmd.Connection = objCon;
objCmd.CommandText = objStr;
objCmd.CommandType = CommandType.StoredProcedure;
Connection();
objCmd.Parameters.AddRange(parameter);
object result = objCmd.ExecuteScalar();
objCon.Close();
return result;
}
catch (Exception ex)
{
throw;
}
}
public DataSet ExecuteDataSet(string objStr, SqlParameter[] parameter)
{
try
{
objCmd = new SqlCommand();
objDS = new DataSet();
Connection();
objCmd.CommandText = objStr;
objCmd.CommandType = CommandType.StoredProcedure;
objCmd.Connection = objCon;
objCmd.Parameters.AddRange(parameter);
objAd = new SqlDataAdapter();
objAd.SelectCommand = objCmd;
objAd.Fill(objDS);
return objDS;
}
catch (Exception ex)
{
throw;
}
}
}
}
5) ASPX Form:
Ø Form Design:
Ø Source Code: (frmBatches.aspx)
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="frmBatches.aspx.cs" Inherits="VBOMS.frmBatches"
MasterPageFile="VBOMS.Master" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="vbContentPlaceHolder">
<table align="center">
<tr align="center">
<td align="right">
BatchNotd>
<td>
:td>
<td>
<asp:TextBox ID="txtBatchNo" runat="server">asp:TextBox>
td>
tr>
<tr align="center">
<td align="right">
FromTimingtd>
<td>
:td>
<td>
<asp:TextBox ID="txtFromTiming" runat="server">asp:TextBox>
td>
tr>
<tr align="center">
<td align="right">
ToTimingtd>
<td >
:td>
<td>
<asp:TextBox ID="txtToTiming" runat="server">asp:TextBox>
td>
tr>
<tr>
<td colspan="3" align="center">
<asp:HiddenField ID="hdnBatchesId" runat="server" />
td>
tr>
<tr align="center">
<td align="center" colspan="3">
<asp:Button ID="btnSave" runat="server" CssClass="buttonStyle" Text="Save" OnClick="btnSave_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="buttonStyle" OnClick="btnCancel_Click" CausesValidation="False" />
td>
tr>
<tr>
<td align="center" colspan="3">
<asp:Label ID="lblmessage" runat="server" Text="lblMessage" BackColor="White">asp:Label>td>
tr>
<tr>
<td align="center" colspan="3">
<table align="center" border="0" cellpadding="2" cellspacing="0">
<tr>
<td>
<asp:GridView ID="gvBatches" runat="server" AutoGenerateColumns="false"
OnRowDeleting="gvBatches_RowDeleting" OnRowEditing="gvBatches_RowEditing" >
<Columns>
<asp:BoundField DataField="BatchNo" HeaderText="BatchNo" />
<asp:BoundField DataField="FromTiming" HeaderText="FromTiming" />
<asp:BoundField DataField="ToTiming" HeaderText="ToTiming" />
<asp:BoundField DataField="BatchId" HeaderText="BatchId" ItemStyle-CssClass="hidecolumn"
HeaderStyle-CssClass="hidecolumn" />
<asp:ButtonField ButtonType="Link" HeaderText="Edit" Text="Edit" CommandName="edit" />
<asp:ButtonField ButtonType="Link" Text="Delete" CommandName="Delete" />
Columns>
asp:GridView>
td>
tr>
table>
td>
tr>
table>
asp:Content>
Ø frmBatches.Aspx.Cs
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 VBOMS.API;
namespace VBOMS
{
public partial class frmBatches : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillBatches();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
Batches objBatch = new Batches();
objBatch.BatchNo = txtBatchNo.Text;
objBatch.FromTiming = txtFromTiming.Text;
objBatch.ToTiming = txtToTiming.Text;
objBatch.EnterDate = DateTime.UtcNow.AddHours(5.5);
objBatch.UpdateDate = DateTime.UtcNow.AddHours(5.5);
objBatch.IsActive = true;
bool result = false;
objBatch.BatchID = onvert.ToInt32(Request.QueryString["BatchId"]);
if (hdnBatchesId.Value=="")
{
result = objBatch.Save();
}
else
{
objBatch.BatchID = Convert.ToInt32(hdnBatchesId.Value);
result = objBatch.Update();
}
if (result)
{
lblmessage.Text = "Updated Successfully";
ClearControlsData();
FillBatches();
}
else
{
lblmessage.Text = "Already Exist";
}
}
public void FillBatches()
{
Batches objBatch = new Batches();
DataSet objDS = new DataSet();
objDS = objBatch.Fecth();
if (objDS.Tables[0].Rows.Count > 0)
{
gvBatches.DataSource = objDS;
gvBatches.DataBind();
}
}
private void ClearControlsData()
{
txtBatchNo.Text = "";
txtFromTiming.Text = "";
txtToTiming.Text = "";
}
protected void gvBatches_RowEditing(object sender, GridViewEditEventArgs e)
{
txtBatchNo.Text = gvBatches.Rows[e.NewEditIndex].Cells[0].Text;
txtFromTiming.Text = gvBatches.Rows[e.NewEditIndex].Cells[1].Text;
txtToTiming.Text = gvBatches.Rows[e.NewEditIndex].Cells[2].Text;
hdnBatchesId.Value = gvBatches.Rows[e.NewEditIndex].Cells[3].Text;
}
protected void btnCancel_Click(object sender, EventArgs e)
{
ClearControlsData();
}
protected void gvBatches_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Batches objbatch = new Batches();
objbatch.BatchID = Convert.ToInt32(gvBatches.Rows[e.RowIndex].Cells[3].Text);
if (objbatch.Delete())
{
lblmessage.Text = "Status Changed Succuessfully";
FillBatches();
}
}
}
}
6) Web Config:
configSections>
<connectionStrings>
<add name="conStr" connectionString="data source=VIJAY\DATASERVER;user id=sa;pwd=vb_123;database=VBOMS"/>
<add name="VBOMSConnectionString1" connectionString="Data Source=VIJAY\DATASERVER;Initial Catalog=VBOMS;User ID=sa;Password=vb_123" providerName="System.Data.SqlClient"/>
connectionStrings>
How to Fill Data in DropDownList:
public void FillOccupation()
{
OccupationDetails objOd = new OccupationDetails();
DataSet ds = new DataSet();
ds = objOd.Fetch();
if (ds.Tables[0].Rows.Count > 0)
{
ddlOccupation.DataValueField = "OccupationId";
ddlOccupation.DataTextField = "OccupationName";
ddlOccupation.DataSource = ds;
ddlOccupation.DataBind();
ddlOccupation.Items.Insert(0, "Select");
}
}
How to Fill Data in GridView:
public void FillOccupation()
{
OccupationDetails objOc = new OccupationDetails();
DataSet objDs = new DataSet();
objDs = objOc.Fetch();
if (objDs.Tables[0].Rows.Count > 0)
{
gvOccupation.DataSource = objDs;
}
else
{
gvOccupation.DataSource = null;
}
gvOccupation.DataBind();
}
Row Editing and Deleting:
protected void gvOccupation_RowEditing(object sender,GridViewEditEventArgs e)
{
txtOccupation.Text = gvOccupation.Rows[e.NewEditIndex].Cells[0].Text;
hdnOccupationId.Value = gvOccupation.Rows[e.NewEditIndex].Cells[1].Text;
}
protected void gvOccupation_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
OccupationDetails objOc = new OccupationDetails();
objOc.OccupationId = Convert.ToInt32(gvOccupation.Rows[e.RowIndex].Cells[01].Text);
if (objOc.Delete())
{
lblMessage.Text = "Status Changed Successfully";
FillOccupation();
}
}
FrmRegistration.aspx:
Under Save Button:
protected void btnSave_Click(object sender, EventArgs e)
{
Registration objReg = new Registration();
objReg.FirstName = txtFirstName.Text;
objReg.LastName = txtLastName.Text;
objReg.DOB = Convert.ToDateTime(txtDOB.Text);
objReg.Gender = rblGender.Text;
objReg.PhoneNo = txtPhoneNo.Text;
objReg.EmailId = txtEmailId.Text;
objReg.OccupationId = Convert.ToInt32(ddlOccupation.SelectedItem.Value);
objReg.TechnologyId = Convert.ToInt32(ddlTechnology.SelectedValue);
objReg.ReferenceID = Convert.ToInt32(ddlReference.SelectedValue);
objReg.IsOnline = rblIsOnline.SelectedValue;
if (objReg.save())
{
Address objAdd = new Address();
objAdd.TraineeID = objReg.TraineeId;
objAdd.CurrentLocation = txtCurrentLocation.Text;
objAdd.Country = ddlCountry.SelectedItem.Text;
objAdd.PinCode = Convert.ToInt32(txtPinCode.Text);
objAdd.EnteredDate = DateTime.UtcNow.AddHours(5.5);
objAdd.UpdatedDate = DateTime.UtcNow.AddHours(5.5);
if (objAdd.Save())
{
bool isEduSaved = false;
EducationDetails objEdu = new EducationDetails();
objEdu.TraineeID = Convert.ToInt16(objAdd.TraineeID);
objEdu.EnterDate = DateTime.UtcNow.AddHours(5.5);
objEdu.UpdateDate = DateTime.UtcNow.AddHours(5.5);
foreach (GridViewRow row in gvEducationType.Rows)
{
objEdu.EducationTypeId = row.Cells[0].Text == " " ? Convert.ToInt16(0) : Convert.ToInt16(row.Cells[0].Text);
TextBox txtCour = (TextBox)row.FindControl("txtCourse");
objEdu.Course = txtCour.Text;
TextBox txtUniName = (TextBox)row.FindControl("txtUniversity");
objEdu.University = txtUniName.Text;
TextBox txtYearPass = (TextBox)row.FindControl("txtYearOfPassing");
objEdu.YearOfPassing = Convert.ToDateTime(txtYearPass.Text);
TextBox txtAggrigate = (TextBox)row.FindControl("txtAggregate");
objEdu.Aggregate = float.Parse(txtAggrigate.Text);
isEduSaved = objEdu.Save();
}
if (isEduSaved)
{
Certification objCer = new Certification();
objCer.Technology = txtTechnology.Text;
objCer.CoursePeriod = Convert.ToDateTime(txtCoursePeriod.Text);
objCer.EnteredDate = DateTime.UtcNow.AddHours(5.5);
objCer.UpdatedDate = DateTime.UtcNow.AddHours(5.5);
if (objCer.Save())
{
string strBody = "WelCome To ViswgnaBharathi" +
" Welcome to Viswgna Bharathi, Your Userid : " + txtEmailId.Text + " Password : " + txtPassword.Text + "";
if (Utility.SendMail(txtEmailId.Text, "vkouru@viswgnabharathi.com", "Your Registration is Successful", strBody))
{
lblMessage.Text = "Message Send Successfully";
}
else
{
lblMessage.Text = "Message Sending Failed";
}
}
else
{
lblMessage.Text = "Already Existed";
}
}
else
{
lblMessage.Text = "Please check your details once again";
}
}
}
}
frmLogin.aspx:
Under Login Button:
protected void btnLoging_Click(object sender, EventArgs e)
{
UserLogin objlogin = new UserLogin();
objlogin.UserName = txtUsername.Text;
objlogin.Password = txtPassword.Text;
if (objlogin.CheckLoginDetails())
{
lblmessage.Text = "Login SuccessFully";
}
else
{
lblmessage.Text = "Invalid User";
}
}
CheckLoginDetails()
public bool CheckLoginDetails()
{
SqlParameter[] objSqlParams = new SqlParameter[]
{
new SqlParameter("@Type","CL"),
new SqlParameter("@UserName",this.UserName),
new SqlParameter("@PassWord",this.Password)
};
DataSet objDs = ExecuteDataSet("USP_IDFU_UserLogin", objSqlParams);
if (objDs.Tables[0].Rows.Count > 0)
{
return true;
}
else
return false;
//return (objDs.Tables[0].Rows.Count > 0);
}
StorePrcedure:
ALTER procedure [dbo].[USP_IDFU_UserLogin]
(@Type char(1)=null,
@UserId bigint=null,
@UserName varchar(50)=null,
@PassWord varchar(30)=null,
@EnterDate datetime=null,
@UpdatedDate datetime=null,
@IsActive bit=null)
as
if(@Type='I')begin
insert into UserLogin(UserName,PassWord,EnterDate,UpdatedDate,IsActive)
values(@UserName,@PassWord,@EnterDate,@UpdatedDate,@IsActive)
end
if(@Type='D')begin
delete from UserLogin where UserId=@UserId
end
if(@Type='F')begin
select *from UserLogin where UserName=@UserName and PassWord=@PassWord
end
if(@Type='U')begin
update UserLogin set UserName=@UserName,PassWord=@PassWord,EnterDate=@EnterDate,
UpdatedDate=@UpdatedDate,IsActive=@IsActive where UserId=@UserId
end
if(@type='CL')begin
select * from UserLogin where UserName=@UserName and PassWord=@PassWord
end
Comments
Post a Comment