public List<Visitors> GetListVisitors() { List<Visitors> list = new List<Visitors>(); Visitors ins; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT f.*,fd.FieldName FROM Visitors f inner join Fields fd on f.FieldsId = fd.FieldsId", con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins = new Visitors(); ins.VisitorsId = Convert.ToInt32(drI["VisitorsId"]); ins.ClientId = Convert.ToInt32(drI["ClientId"]); ins.ClientNo = drI["ClientNo"].ToString(); ins.VisitorNo = drI["VisitorNo"].ToString(); ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]); ins.SendReceived = Convert.ToBoolean(drI["SendReceived"]); list.Add(ins); } } drI.Close(); con.Close(); return list; }
public Visitors InsertVisitors(Visitors ins) { //...Get User and Date Data... string strTrx = "Insert_Visitors"; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); //...Command Interface... SqlCommand cmdI = con.CreateCommand(); SqlTransaction trx; trx = con.BeginTransaction(strTrx); cmdI.Connection = con; cmdI.Transaction = trx; try { //...Insert Picture... //...Insert Record... cmdI.Parameters.Clear(); cmdI.CommandText = "f_Admin_Insert_Visitors"; //cmdI.Connection.Open(); cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@ClientId", ins.ClientId); cmdI.Parameters.AddWithValue("@ClientNo", ins.ClientNo); cmdI.Parameters.AddWithValue("@Email", ins.VisitorNo); cmdI.Parameters.AddWithValue("@Passwords", ins.ModifiedDate); cmdI.Parameters.AddWithValue("@Approved", ins.SendReceived); //...Return new ID... ins.VisitorsId = (int)cmdI.ExecuteScalar(); //...Commit Transaction... trx.Commit(); cmdI.Connection.Close(); } catch (SqlException ex) { if (trx != null) trx.Rollback(); //...Save Error to Log... Functions func = new Functions(); func.LogError(ex.ToString()); } finally { //...Check for close and respond accordingly.. if (con.State != ConnectionState.Closed) { con.Close(); } //...Clean up... con.Dispose(); cmdI.Dispose(); trx.Dispose(); } return ins; }
public Visitors UpdateVisitors(Visitors ins) { //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); SqlCommand cmdI = con.CreateCommand(); cmdI.Connection = con; //...Update Picture... //...Update Record... cmdI.Parameters.Clear(); cmdI.CommandText = "f_Admin_Update_Visitors"; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@VisitorsID", ins.VisitorsId); cmdI.Parameters.AddWithValue("@ClientId", ins.ClientId); cmdI.Parameters.AddWithValue("@ClientNo", ins.ClientNo); cmdI.Parameters.AddWithValue("@Email", ins.VisitorNo); cmdI.Parameters.AddWithValue("@Passwords", ins.ModifiedDate); cmdI.Parameters.AddWithValue("@Approved", ins.SendReceived); cmdI.ExecuteNonQuery(); cmdI.Connection.Close(); return ins; }
public Visitors GetVisitors(int VisitorsId) { Visitors ins = new Visitors(); //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM Visitors WHERE VisitorsId =" + VisitorsId, con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins.VisitorsId = Convert.ToInt32(drI["VisitorsId"]); ins.ClientId = Convert.ToInt32(drI["ClientId"]); ins.ClientNo = drI["ClientNo"].ToString(); ins.VisitorNo = drI["VisitorNo"].ToString(); ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]); ins.SendReceived = Convert.ToBoolean(drI["SendReceived"]); } } drI.Close(); con.Close(); return ins; }