public static List <User> ListUserRecord() { List <User> listUser = new List <User>(); string sqlSelect = "Select * From Users "; SqlConnection sqlConn = new SqlConnection(); sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlSelect, sqlConn); SqlDataReader sqlReader = sqlcmd.ExecuteReader(); while (sqlReader.Read()) { User user = new User(); user.UserId = Convert.ToInt32(sqlReader["UserId"].ToString()); user.Password = sqlReader["Password"].ToString(); listUser.Add(user); } sqlConn.Close(); return(listUser); }
public static void DeleteSoftware(Software software) { string sqlDelete = "Delete From Softwares WHERE SoftwareId=@SoftwareId"; SqlConnection sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlDelete, sqlConn); sqlcmd.Parameters.AddWithValue("@SoftwareId", software.SoftwareId); sqlcmd.Parameters.AddWithValue("@SoftwareName", software.SoftwareName); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); }
public static void DeleteUser(User user) { string sqlDelete = "Delete From Users Where UserId=@UserId"; SqlConnection sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlDelete, sqlConn); sqlcmd.Parameters.AddWithValue("@UserId", user.UserId); sqlcmd.Parameters.AddWithValue("@Password", user.Password); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); }
public static void UpdateUser(User user) { string sqlUpdate = "Update Users " + "SET Password=@Password WHERE UserId=@UserId"; SqlConnection sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlUpdate, sqlConn); sqlcmd.Parameters.AddWithValue("@UserId", user.UserId); sqlcmd.Parameters.AddWithValue("@Password", user.Password); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); }
public static void DeleteEmployee(Employee emp) { string sqlDelete = "Delete From Employees Where EmployeeId=@EmployeeId"; SqlConnection sqlConn = UtilityDB.ConnectDB();//to connect to the database //Customize the sqlCommand object SqlCommand sqlcmd = new SqlCommand(sqlDelete, sqlConn); sqlcmd.Parameters.AddWithValue("@EmployeeId", emp.EmployeeId); sqlcmd.Parameters.AddWithValue("@FirstName", emp.FirstName); sqlcmd.Parameters.AddWithValue("@LastName", emp.LastName); sqlcmd.Parameters.AddWithValue("@JobTitle", emp.JobTitle); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); }
public static Software Searchsoftware(int softwareID) { Software soft = new Software(); string sqlSelect = "Select * From Softwares " + "Where SoftwareId= " + softwareID; SqlConnection sqlconn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlSelect, sqlconn); SqlDataReader sqlReader = sqlcmd.ExecuteReader(); if (sqlReader.Read()) { soft.SoftwareId = Convert.ToInt32(sqlReader["SoftwareId"].ToString()); soft.SoftwareName = sqlReader["SoftwareName"].ToString(); } return(soft); }
public static void DeleteBook(Book book) { string sqlDelete = "Delete From Books Where Isbn=@Isbn"; SqlConnection sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlDelete, sqlConn); sqlcmd.Parameters.AddWithValue("@Isbn", book.Isbn); sqlcmd.Parameters.AddWithValue("@Title", book.Title); sqlcmd.Parameters.AddWithValue("@LimitPrice", book.LimitPrice); sqlcmd.Parameters.AddWithValue("@YearPublished", book.YearPublished); sqlcmd.Parameters.AddWithValue("@QOH", book.QOH); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); }
public static void UpdateSoftware(Software soft) { string sqlUpdate = "Update Softwares " + "SET SoftwareName=@SoftwareName Where SoftwareId=@SoftwareId"; MessageBox.Show(sqlUpdate); SqlConnection sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlUpdate, sqlConn); sqlcmd.Parameters.AddWithValue("@SoftwareId", soft.SoftwareId); sqlcmd.Parameters.AddWithValue("@SoftwareName", soft.SoftwareName); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); }
//Code for User Authentication*************************************** public static Boolean Authentication(int UserId, string Password) { // User user = new User(); string sqlSelect = "Select UserId, Password from Users " + "Where UserId = " + UserId + "AND Password = '******'"; SqlConnection sqlconn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlSelect, sqlconn); SqlDataReader sqlReader = sqlcmd.ExecuteReader(); if (sqlReader.Read()) { return(true); } return(false); }
public static Book SearchBook(int Isbn) { Book book = new Book(); string sqlSelect = "Select * From Books " + "Where Isbn= " + Isbn; SqlConnection sqlconn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlSelect, sqlconn); SqlDataReader sqlReader = sqlcmd.ExecuteReader(); if (sqlReader.Read()) { book.Isbn = Convert.ToInt32(sqlReader["Isbn"].ToString()); book.Title = sqlReader["Title"].ToString(); book.LimitPrice = Convert.ToInt32(sqlReader["LimitPrice"].ToString()); book.YearPublished = Convert.ToInt32(sqlReader["YearPublished"].ToString()); book.QOH = Convert.ToInt32(sqlReader["QOH"].ToString()); } return(book); }
public static void UpdateBook(Book book) { string sqlUpdate = "Update Books " + "SET Title=@Title, LimitPrice=@LimitPrice, YearPublished=@YearPublished, QOH=@QOH Where Isbn=@Isbn "; MessageBox.Show(sqlUpdate); SqlConnection sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlUpdate, sqlConn); sqlcmd.Parameters.AddWithValue("@Isbn", book.Isbn); sqlcmd.Parameters.AddWithValue("@Title", book.Title); sqlcmd.Parameters.AddWithValue("@LimitPrice", book.LimitPrice); sqlcmd.Parameters.AddWithValue("@YearPublished", book.YearPublished); sqlcmd.Parameters.AddWithValue("@QOH", book.QOH); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); }
public static List <Software> listsoftware() { List <Software> list = new List <Software>(); string sqlSelect = "Select SoftwareId, SoftwareName From Softwares"; SqlConnection sqlConn = new SqlConnection(); sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlSelect, sqlConn); SqlDataReader sqlReader = sqlcmd.ExecuteReader(); while (sqlReader.Read()) { Software soft = new Software(); soft.SoftwareId = Convert.ToInt32(sqlReader["SoftwareId"].ToString()); soft.SoftwareName = sqlReader["SoftwareName"].ToString(); list.Add(soft); } sqlConn.Close(); return(list); }
public static User searchUSerRecord(int UserId) { string sqlSelect = "Select * From Users " + "Where UserId= " + UserId; SqlConnection sqlconn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlSelect, sqlconn); SqlDataReader sqlReader = sqlcmd.ExecuteReader(); User user = new User(); if (sqlReader.Read()) { user.UserId = Convert.ToInt32(sqlReader["UserId"].ToString()); user.Password = sqlReader["Password"].ToString(); } else { user = null; } sqlconn.Close(); return(user); }
public static Employee searchRecord(int empId) { string sqlSelect = "Select * From Employees " + "Where EmployeeId= " + empId; SqlConnection sqlconn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlSelect, sqlconn); SqlDataReader sqlReader = sqlcmd.ExecuteReader(); Employee emp = new Employee(); if (sqlReader.Read()) { emp.EmployeeId = Convert.ToInt32(sqlReader["EmployeeId"].ToString()); emp.FirstName = sqlReader["FirstName"].ToString(); emp.LastName = sqlReader["LastName"].ToString(); emp.JobTitle = sqlReader["JobTitle"].ToString(); } else { emp = null; } sqlconn.Close(); return(emp); }
/*******************************************AuthorBook************************************************/ /**********************************Add Data into AuthorBooks******************************************/ public static bool saveauthBook(AuthorBook AuthBook) { bool success = false; try { string sqlInsert = "Insert INTO AuthorBook " + "Values(@AuthorId, @Isbn, @Date)"; SqlConnection sqlconn = UtilityDB.ConnectDB(); SqlCommand sqlCmd = new SqlCommand(sqlInsert, sqlconn); sqlCmd.Parameters.AddWithValue("@AuthorId", AuthBook.AuthorId); sqlCmd.Parameters.AddWithValue("@Isbn", AuthBook.Isbn); sqlCmd.Parameters.AddWithValue("@Date", AuthBook.Date); sqlCmd.ExecuteReader(); sqlconn.Close(); success = true; } catch (SqlException ex) { throw ex; } return(success); }
public static bool SaveEmployee(Employee emp) { bool success = false; try { string sqlInsert = "Insert into Employees " + "Values(@EmployeeId, @FirstName, @LastName, @JobTitle)"; SqlConnection sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlInsert, sqlConn); sqlcmd.Parameters.AddWithValue("@EmployeeId", emp.EmployeeId); sqlcmd.Parameters.AddWithValue("@FirstName", emp.FirstName); sqlcmd.Parameters.AddWithValue("@LastName", emp.LastName); sqlcmd.Parameters.AddWithValue("@JobTitle", emp.JobTitle); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); success = true; } catch (SqlException ex) { throw ex; } return(success); }
public static bool AddUser(User user) { bool success = false; try { string sqlInsert = "Insert into Users " + "Values(@UserId, @Password)"; SqlConnection sqlConn = UtilityDB.ConnectDB(); SqlCommand sqlcmd = new SqlCommand(sqlInsert, sqlConn); sqlcmd.Parameters.AddWithValue("@UserId", user.UserId); sqlcmd.Parameters.AddWithValue("@Password", user.Password); sqlcmd.ExecuteNonQuery(); sqlConn.Close(); success = true; } catch (SqlException ex) { throw ex; } return(success); }