public ReturnMenu DeleteByID(int _ID) { ReturnMenu returnMenu = new ReturnMenu(); try { // Gọi vào DB để lấy dữ liệu. using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection()) { using (SqlCommand cmd = new SqlCommand("", sqlConnection)) { cmd.CommandText = "sp_tMenu_DeleteByID"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = _ID; cmd.ExecuteNonQuery(); returnMenu.Code = "00"; returnMenu.Message = "Cập nhật dữ liệu thành công."; } } } catch (Exception ex) { returnMenu.Code = "99"; returnMenu.Message = "Lỗi xử lý dữ liệu: " + ex.ToString(); returnMenu.Total = 0; returnMenu.lstMenu = null; mylog4net.Error("", ex); } return(returnMenu); }
public ReturnMenu Insert(Menu menu) { ReturnMenu returnMenu = new ReturnMenu(); try { using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection()) { using (SqlCommand cmd = new SqlCommand("", sqlConnection)) { cmd.CommandText = "sp_tMenu_InsertUpdate"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = menu.ID; cmd.Parameters.Add(new SqlParameter("@MenuName", SqlDbType.NVarChar)).Value = menu.MenuName; cmd.Parameters.Add(new SqlParameter("@DisplayName", SqlDbType.NVarChar)).Value = menu.DisplayName; cmd.Parameters.Add(new SqlParameter("@ParentMenuID", SqlDbType.Int)).Value = menu.ParentMenuID; cmd.Parameters.Add(new SqlParameter("@isActive", SqlDbType.Int)).Value = menu.isActive; cmd.Parameters.Add(new SqlParameter("@UrlLink", SqlDbType.VarChar)).Value = menu.UrlLink; cmd.ExecuteNonQuery(); returnMenu.Code = "00"; returnMenu.Message = "Cập nhật dữ liệu thành công."; } } } catch (Exception ex) { returnMenu.Code = "99"; returnMenu.Message = "Lỗi xử lý dữ liệu: " + ex.ToString(); returnMenu.Total = 0; returnMenu.lstMenu = null; mylog4net.Error("", ex); } return(returnMenu); }
public ReturnMenu GetbyID(int ID) { List <Menu> lstMenu = null; Menu menu = null; ReturnMenu returnMenu = new ReturnMenu(); try { using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection()) { using (SqlCommand cmd = new SqlCommand("", sqlConnection)) { //cmd.Connection = _sqlConnection; cmd.CommandText = "sp_tMenu_SelectByID"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = ID; using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd, sqlConnection)) { if (sqlDr.HasRows) { lstMenu = new List <Menu>(); while (sqlDr.Read()) { menu = new Menu(); menu.ID = int.Parse(sqlDr["ID"].ToString()); menu.MenuName = sqlDr["MenuName"].ToString(); menu.DisplayName = sqlDr["DisplayName"].ToString(); menu.ParentMenuID = int.Parse(sqlDr["ParentMenuID"].ToString()); menu.isActive = int.Parse(sqlDr["isActive"].ToString()); menu.UrlLink = sqlDr["UrlLink"].ToString(); lstMenu.Add(menu); } returnMenu.Code = "00"; returnMenu.Message = "Lấy dữ liệu thành công."; returnMenu.lstMenu = lstMenu; } else { returnMenu.Code = "01"; returnMenu.Message = "Không tồn tại bản ghi nào."; returnMenu.Total = 0; returnMenu.lstMenu = null; } } } } } catch (Exception ex) { returnMenu.Code = "99"; returnMenu.Message = "Lỗi xử lý dữ liệu: " + ex.ToString(); returnMenu.Total = 0; returnMenu.lstMenu = null; mylog4net.Error("", ex); } return(returnMenu); }
public ReturnMenu SelectMenuLevel2() { List <Menu> lstMenu = null; Menu menu = null; ReturnMenu returnMenu = new ReturnMenu(); try { using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection()) { using (SqlCommand cmd = new SqlCommand("", sqlConnection)) { cmd.CommandText = "sp_tMenu_SelectAllMenu"; cmd.CommandType = CommandType.StoredProcedure; using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd)) { //if (float.Parse(cmd.Parameters["P_RETURN_CODE"].Value.ToString()) > 0) //{ if (sqlDr.HasRows) { lstMenu = new List <Menu>(); while (sqlDr.Read()) { menu = new Menu(); menu.ID = int.Parse(sqlDr["ID"].ToString()); menu.MenuName = sqlDr["MenuName"].ToString(); menu.DisplayName = sqlDr["DisplayName"].ToString(); menu.ParentMenuID = int.Parse(sqlDr["ParentMenuID"].ToString()); menu.isActive = int.Parse(sqlDr["isActive"].ToString()); menu.UrlLink = sqlDr["UrlLink"].ToString(); if (menu.isActive == 1) { lstMenu.Add(menu); } } returnMenu.Code = "00"; returnMenu.Message = "Lấy dữ liệu thành công."; returnMenu.lstMenu = lstMenu; } else { returnMenu.Code = "01"; returnMenu.Message = "Không tồn tại bản ghi nào."; returnMenu.Total = 0; returnMenu.lstMenu = null; } } } } } catch (Exception ex) { returnMenu.Code = "99"; returnMenu.Message = "Lỗi xử lý dữ liệu: " + ex.ToString(); returnMenu.Total = 0; returnMenu.lstMenu = null; mylog4net.Error("", ex); } return(returnMenu); }