using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using AMS.BO;
namespace AMS.DAL
{
public class DoctorsDAL:DALTemplateClass
{
private SqlConnection myConn;
public DoctorsBO DoctorOperations(DoctorsBO objBO)
{
// Create Instance of Connection and Command Object
myConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["AMSDB"]);
SqlCommand myComm = new SqlCommand("AMS_Doctors_Operations", myConn);
SqlDataAdapter da = new SqlDataAdapter();
// Mark the Command as a SPROC
myComm.CommandType = CommandType.StoredProcedure;
myComm.Parameters.AddWithValue("@DoctorId", objBO.DoctorId);
myComm.Parameters.AddWithValue("@Hid", objBO.Hid);
myComm.Parameters.AddWithValue("@UserId", objBO.UserId);
myComm.Parameters.AddWithValue("@SalutationId", objBO.SalutationId);
myComm.Parameters.AddWithValue("@FirstName", objBO.FirstName);
myComm.Parameters.AddWithValue("@LastName", objBO.LastName);
myComm.Parameters.AddWithValue("@MiddleName", objBO.MiddleName);
myComm.Parameters.AddWithValue("@SSN", objBO.SSN);
myComm.Parameters.AddWithValue("@DOB", objBO.DOB);
myComm.Parameters.AddWithValue("@Gender", objBO.Gender);
myComm.Parameters.AddWithValue("@Age", objBO.Age);
myComm.Parameters.AddWithValue("@Address", objBO.Address);
myComm.Parameters.AddWithValue("@City", objBO.City);
myComm.Parameters.AddWithValue("@State", objBO.State);
myComm.Parameters.AddWithValue("@ZipCode", objBO.ZipCode);
myComm.Parameters.AddWithValue("@Email", objBO.Email);
myComm.Parameters.AddWithValue("@HomePhone", objBO.HomePhone);
myComm.Parameters.AddWithValue("@WorkPhone", objBO.WorkPhone);
myComm.Parameters.AddWithValue("@Mobile", objBO.Mobile);
myComm.Parameters.AddWithValue("@Fax", objBO.Fax);
myComm.Parameters.AddWithValue("@SpecilizationId", objBO.SpecilizationId);
myComm.Parameters.AddWithValue("@RegistrationNumber", objBO.RegistrationNumber);
myComm.Parameters.AddWithValue("@LicenceNumber", objBO.LicenceNumber);
myComm.Parameters.AddWithValue("@Type", objBO.Type);
// Open the connection and execute the Command
try
{
myConn.Open();
if (objBO.Type == "Insert" || objBO.Type == "Update")
{
myComm.ExecuteNonQuery();
objBO.DoctorId = 1;
}
if (objBO.Type == "SelectAll" || objBO.Type == "SelectById" || objBO.Type=="SelectByUserId"
|| objBO.Type == "SelectByHospitalId" || objBO.Type == "Search" )
{
DataSet ds = new DataSet();
da.SelectCommand = myComm;
da.Fill(ds);
objBO.DoctorsDS = ds;
}
return objBO;
}
catch (Exception ex)
{
MessageDescription = ex.Message;
return null;
}
finally
{
myConn.Close();
myComm.Dispose();
da.Dispose();
}
}
public DataSet GetSpecilizations()
{
// Create Instance of Connection and Command Object
myConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["AMSDB"]);
SqlCommand myComm = new SqlCommand("AMS_Specializations_Operations", myConn);
SqlDataAdapter da = new SqlDataAdapter();
// Mark the Command as a SPROC
// Open the connection and execute the Command
try
{
DataSet ds = new DataSet();
da.SelectCommand = myComm;
da.Fill(ds);
return ds;
}
catch (Exception ex)
{
MessageDescription = ex.Message;
return null;
}
finally
{
myConn.Close();
myComm.Dispose();
da.Dispose();
}
}
}
}
Connection DB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace AMS.DAL
{
public class ConnectionDB
{
private static SqlConnection _dbConnection;
public static void CloseConnection()
{
if (_dbConnection.State != ConnectionState.Closed)
{
_dbConnection.Close();
}
}
public static SqlConnection GetConnection()
{
_dbConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["AMSDB"]);
_dbConnection.Open();
return _dbConnection;
}
}
}
web.config
>appSettings>
>add key="AMSDB" value="server=SYS;User Id=sa;Password=123456;database=AMSDBNew;Connection Timeout=10000;"/>
>!--
>add key="autoSuggestConnectionString" value="server=.\SQLEXPRESS;Integrated Security=SSPI;database=northwind;provider=SQLNCLI.1"/>
>add key="DocId" value="1"/>
>add key="HId" value="2"/>
>add key="CompanyID" value="31"/>
>add key="ContactPersonID" value="23"/>
>add key="PhysicalPathofPDF" value="D:\AMS\\AMSWeb\\Documents\\"/>
>!-- EMail Credentials -->
>add key="networkCredentialMailId" value="gajulamk@gmail.com"/>
>add key="networkCredentialMailPassword" value="gajula"/>
>add key="defaultFromMailId" value="ams.gajulamk@gmail.com"/>
>add key="smtpClient" value="smtp.gmail.com"/>
>add key="port" value="587"/>
>!-- End EMail-->
>/appSettings>
>connectionStrings/>
>system.web>
>!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
>customErrors mode="Off"/>
>compilation debug="true">
>assemblies>
>add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
>add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
>add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
>add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
?add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
>add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
>/assemblies>
>/compilation>