public Permission GetPermission(int PermissionID) { //...Create New Instance of Object... Permission ins = new Permission(); //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM l_Permission WHERE PermissionID =" + PermissionID, con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins.PermissionID = Convert.ToInt32(drI["PermissionID"]); ins.Permissions = Convert.ToString(drI["Permission"]); } } //...Close Connections... drI.Close(); con.Close(); //...Return... return ins; }
public List<Permission> GetAllPermission() { //...Create New Instance of Object... List<Permission> list = new List<Permission>(); Permission ins; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM l_Permission", con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins = new Permission(); ins.PermissionID = Convert.ToInt32(drI["PermissionID"]); ins.Permissions = Convert.ToString(drI["Permission"]); list.Add(ins); } } //...Close Connections... drI.Close(); con.Close(); //...Return... return list; }
public Permission Insert(Permission ins) { //...Get User and Date Data... string ModifiedDate = string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now); string EmployeeId = Convert.ToString(HttpContext.Current.Session["Username"]); string strTrx = "KwikPayIns_" + EmployeeId; //...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 Record... cmdI.CommandText = StoredProcedures.PermissionInsert; cmdI.CommandType = System.Data.CommandType.StoredProcedure; //cmdI.Parameters.AddWithValue("@PermissionID", ins.PermissionID); cmdI.Parameters.AddWithValue("@Permission", ins.Permissions); //...Return new ID ins.PermissionID = (int)cmdI.ExecuteScalar(); trx.Commit(); cmdI.Connection.Close(); } catch (SqlException ex) { if (trx != null) trx.Rollback(); } 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 Permission Update(Permission ins) { //...Get User and Date Data... // string ModifiedDate = string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now); // string EmployeeId = Convert.ToString(HttpContext.Current.Session["Username"]); //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); SqlCommand cmdI = con.CreateCommand(); cmdI.Connection = con; //...Update Record... cmdI.Parameters.Clear(); cmdI.CommandText = StoredProcedures.PermissionUpdate; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@PermissionID", ins.PermissionID); cmdI.Parameters.AddWithValue("@Permission", ins.Permissions); cmdI.ExecuteNonQuery(); cmdI.Connection.Close(); return ins; }