public static string GetName(DBObject tableInfo, int ID, string defValue = "--", bool addLink = true, bool addIDPrefix = false) { if (ID < 1) { return(defValue); } string query = string.Format("SELECT {0} FROM {1} (NOLOCK) WHERE {2}={3}", tableInfo.NameColumn, tableInfo.TableName, tableInfo.IDColumn, ID); DataTable dt = CustomQueries.GetDataTableFromQuery(query); if (dt.Rows.Count == 0) { return(defValue); } defValue = dt.Rows[0][tableInfo.NameColumn].ToString(); if (tableInfo.FromResource) { defValue = ResourceManager.GetResource(defValue); } defValue = addIDPrefix ? string.Format("#{0} - {1}", ID, defValue) : defValue; if (addLink) { defValue = string.Format("<a href='/{0}-detail/{1}?Popup=1' class='popup'>{2}</a>", tableInfo.TableName.ToLower(), ID, defValue); } return(defValue); }
public static DataTable GetLookupData(DBObject tableInfo, string filter = null, OrderBy sortOrder = OrderBy.Name, bool addIDPrefix = false) { string query = string.Format("SELECT {0} AS {3}, {1} AS {4} FROM {2} (NOLOCK)", tableInfo.IDColumn, tableInfo.NameColumn, tableInfo.TableName, addIDPrefix ? "ID" : tableInfo.IDColumn, addIDPrefix ? "Name" : tableInfo.NameColumn); if (!string.IsNullOrEmpty(filter)) { query = string.Concat(query, " WHERE ", filter); } if (sortOrder != OrderBy.Default) { query = string.Concat(query, " ORDER BY ", sortOrder == OrderBy.Name ? tableInfo.NameColumn : string.Concat(tableInfo.IDColumn, " DESC")); } string key = string.Concat("lookup", query.GetHashCode().ToString("X")); DataTable dt = CustomQueries.GetDataTableFromQuery(query); if (tableInfo.FromResource && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { dr[1] = ResourceManager.GetResource(dr[1].ToSureString()); } } return(dt); }
private DataTable GetData(string sortExpression, int pageIndex, int pageSize, out int totalRows) { bool forExport = pageSize == 0; if (forExport) pageSize = ConfigManager.Current.MaxExportRows; DataTable dt = CustomQueries.GetStuffByPage("admGetProductsByPage", GetFilter(), sortExpression, pageIndex + 1, pageSize, "*", out totalRows); if (forExport) grdData.GlobalizeDataTable(ref dt); return dt; }
public static Company getCompanyById(int id) { using (SQLiteConnection conn = new Connection().conn) { Company newCompany = new Company(); conn.Open(); string stm = new CustomQueries().GetCompanyById(id); SQLiteCommand cmd = new SQLiteCommand(stm, conn); SQLiteDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { newCompany = new Company(Convert.ToInt32(rdr["id"]), rdr["name"].ToString(), rdr["address"].ToString()); } conn.Close(); return(newCompany); }; }
public static UserRole getRoleById(int id) { UserRole newUserRole = new UserRole(); using (SQLiteConnection conn = new Connection().conn) { conn.Open(); string stm = new CustomQueries().GetRoleById(id); SQLiteCommand cmd = new SQLiteCommand(stm, conn); SQLiteDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { newUserRole = new UserRole( Convert.ToInt32(rdr["Id"]), rdr["Role_Name"].ToString() ); } conn.Close(); return(newUserRole); }; }