CREATE TABLE [dbo].[Hotel](
[Hid] [int] IDENTITY(1,1) Primary Key,
[RoomType] [int] NULL,
[HotelName] [varchar](50) NULL,
[HDescription] [varchar](5000) NULL,
[Amount] [decimal](6, 2) NULL)
CREATE Procedure [dbo].[USPHotel]
@Hid int,
@HotelName varchar(50),
@RoomType int,
@Description varchar(5000),
@Amount decimal(6,2),
@Flag int
as
if(@Flag=1) -- Insert
begin
insert into Hotel(RoomType,HotelName,HDescription,Amount)values(@RoomType,@HotelName,@Description,@Amount)
end
if(@Flag=2) ---Update
begin
update Hotel set RoomType=@RoomType,HotelName=@HotelName,HDescription=@Description,Amount=@Amount where Hid=@Hid
end
if(@Flag=3) ---- delete
begin
delete from Hotel where Hid=@Hid
end
public class clsHotel
{
public int Hid { get; set; }
public string HotelName { get; set; }
public int RoomType { get; set; }
public string Description { get; set; }
public decimal Amount { get; set; }
public int Flag { get; set; }
}
public List<clsHotel> GetHotelDetails()
{
try
{
List<clsHotel> _lstHotel = new List<clsHotel>();
clsHotel _H = null;
if (_con.State != System.Data.ConnectionState.Open)
_con.Open();
SqlCommand _cmd = _con.CreateCommand();
_cmd.CommandText = "Select * From Hotel";
SqlDataReader _Reader = _cmd.ExecuteReader();
while (_Reader.Read())
{
_H = new clsHotel();
_H.Hid = Convert.ToInt32(_Reader["Hid"]);
_H.HotelName = _Reader["HotelName"].ToString();
_H.RoomType = Convert.ToInt32(_Reader["RoomType"]);
_H.Description = _Reader["HDescription"].ToString();
_H.Amount = Convert.ToDecimal(_Reader["Amount"]);
_lstHotel.Add(_H);
}
return _lstHotel;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (_con.State != System.Data.ConnectionState.Closed)
_con.Close();
}
}
[Hid] [int] IDENTITY(1,1) Primary Key,
[RoomType] [int] NULL,
[HotelName] [varchar](50) NULL,
[HDescription] [varchar](5000) NULL,
[Amount] [decimal](6, 2) NULL)
CREATE Procedure [dbo].[USPHotel]
@Hid int,
@HotelName varchar(50),
@RoomType int,
@Description varchar(5000),
@Amount decimal(6,2),
@Flag int
as
if(@Flag=1) -- Insert
begin
insert into Hotel(RoomType,HotelName,HDescription,Amount)values(@RoomType,@HotelName,@Description,@Amount)
end
if(@Flag=2) ---Update
begin
update Hotel set RoomType=@RoomType,HotelName=@HotelName,HDescription=@Description,Amount=@Amount where Hid=@Hid
end
if(@Flag=3) ---- delete
begin
delete from Hotel where Hid=@Hid
end
public class clsHotel
{
public int Hid { get; set; }
public string HotelName { get; set; }
public int RoomType { get; set; }
public string Description { get; set; }
public decimal Amount { get; set; }
public int Flag { get; set; }
}
public List<clsHotel> GetHotelDetails()
{
try
{
List<clsHotel> _lstHotel = new List<clsHotel>();
clsHotel _H = null;
if (_con.State != System.Data.ConnectionState.Open)
_con.Open();
SqlCommand _cmd = _con.CreateCommand();
_cmd.CommandText = "Select * From Hotel";
SqlDataReader _Reader = _cmd.ExecuteReader();
while (_Reader.Read())
{
_H = new clsHotel();
_H.Hid = Convert.ToInt32(_Reader["Hid"]);
_H.HotelName = _Reader["HotelName"].ToString();
_H.RoomType = Convert.ToInt32(_Reader["RoomType"]);
_H.Description = _Reader["HDescription"].ToString();
_H.Amount = Convert.ToDecimal(_Reader["Amount"]);
_lstHotel.Add(_H);
}
return _lstHotel;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (_con.State != System.Data.ConnectionState.Closed)
_con.Close();
}
}
public string InsertHotel(clsHotel _H)
{
try
{
if (_con.State != System.Data.ConnectionState.Open)
_con.Open();
SqlCommand _cmd = new SqlCommand("USPHotel", _con);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.Add(new SqlParameter("@Hid", _H.Hid));
_cmd.Parameters.Add(new SqlParameter("@HotelName", _H.HotelName));
_cmd.Parameters.Add(new SqlParameter("@RoomType", _H.RoomType));
_cmd.Parameters.Add(new SqlParameter("@Description", _H.Description));
_cmd.Parameters.Add(new SqlParameter("@Amount", _H.Amount));
_cmd.Parameters.Add(new SqlParameter("@Flag", 1));
if (_cmd.ExecuteNonQuery() > 0)
return "Record Sucessfully Saved";
else
return "Record not Afftected to DataBase";
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (_con.State != System.Data.ConnectionState.Closed)
_con.Close();
}
}
public string UpdateHotel(clsHotel _H)
{
try
{
if (_con.State != System.Data.ConnectionState.Open)
_con.Open();
SqlCommand _cmd = new SqlCommand("USPHotel", _con);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.Add(new SqlParameter("@Hid", _H.Hid));
_cmd.Parameters.Add(new SqlParameter("@HotelName", _H.HotelName));
_cmd.Parameters.Add(new SqlParameter("@RoomType", _H.RoomType));
_cmd.Parameters.Add(new SqlParameter("@Description", _H.Description));
_cmd.Parameters.Add(new SqlParameter("@Amount", _H.Amount));
_cmd.Parameters.Add(new SqlParameter("@Flag", 2));
if (_cmd.ExecuteNonQuery() > 0)
return "Record Sucessfully Updated";
else
return "Record not Afftected to DataBase";
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (_con.State != System.Data.ConnectionState.Closed)
_con.Close();
}
}
public string DeleteHotel(int HID)
{
try
{
if (_con.State != System.Data.ConnectionState.Open)
_con.Open();
SqlCommand _cmd = new SqlCommand("USPHotel", _con);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.Add(new SqlParameter("@Hid", HID));
_cmd.Parameters.Add(new SqlParameter("@HotelName", ""));
_cmd.Parameters.Add(new SqlParameter("@RoomType", "0"));
_cmd.Parameters.Add(new SqlParameter("@Description", ""));
_cmd.Parameters.Add(new SqlParameter("@Amount", "0"));
_cmd.Parameters.Add(new SqlParameter("@Flag", 3));
if (_cmd.ExecuteNonQuery() > 0)
return "Records Sucessfully Delete";
else
return "Records not Afftected to DataBase";
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (_con.State != System.Data.ConnectionState.Closed)
_con.Close();
}
}
No comments:
Post a Comment