/// <summary> /// 获取所有分组 /// </summary> /// <returns></returns> public static List <Proj_Group> GetAllGroupsFromDB() { string sql = "select g.id as id, g.name as name, g.description as description " + "from Proj_Group g where g.isdeleted ='N' order by g.name"; DataTable dt = null; try { dt = SqliteHelper.MainDbHelper.GetDataTable(sql, null); } catch (Exception ex) { CommonUtil.Alert("错误提示", "无法获取分组信息. \r\n" + ex.Message); } if (dt != null) { List <Proj_Group> allGroups = new List <Proj_Group>(); foreach (DataRow row in dt.Rows) { Proj_Group g = new Proj_Group(); g.Id = (string)row["id"]; g.Name = (string)row["name"]; g.Description = (string)row["description"]; allGroups.Add(g); } return(allGroups); } return(null); }
/// <summary> /// 根据Id获取分组 /// </summary> /// <param name="id"></param> /// <returns></returns> public static Proj_Group GetGroupInfoByIdFromDB(string id) { string sql = "select g.id as id, g.name as name, g.description as description " + "from Proj_Group g where g.isdeleted ='N' and g.id = :id"; Dictionary <string, object> p2vs = new Dictionary <string, object>(); p2vs.Add("id", id); DataTable dt = null; try { dt = SqliteHelper.MainDbHelper.GetDataTable(sql, p2vs); } catch (Exception ex) { CommonUtil.Alert("错误提示", "无法获取分组信息. Id = " + id + "\r\n" + ex.Message); } if (dt != null) { if (dt.Rows.Count > 0) { DataRow row = dt.Rows[0]; Proj_Group g = new Proj_Group(); g.Id = (string)row["id"]; g.Name = (string)row["name"]; g.Description = (string)row["description"]; return(g); } } return(null); }
/// <summary> /// 保存更新组 /// </summary> /// <param name="newGroup"></param> /// <returns></returns> public static bool UpdateGroup(Proj_Group group) { string addSql = "update Proj_Group set name=:name, description=:description " + "where id=:id"; Dictionary <string, object> p2vs = new Dictionary <string, object>(); p2vs.Add("id", group.Id); p2vs.Add("name", group.Name); p2vs.Add("description", group.Description); return(SqliteHelper.MainDbHelper.ExecuteSql(addSql, p2vs)); }
/// <summary> /// 添加新组 /// </summary> /// <param name="newGroup"></param> /// <returns></returns> public static string AddNewGroup(Proj_Group newGroup) { string id = Guid.NewGuid().ToString(); string addSql = "insert into Proj_Group(id, name, description) " + "values(:id, :name, :description)"; Dictionary <string, object> p2vs = new Dictionary <string, object>(); p2vs.Add("id", id); p2vs.Add("name", newGroup.Name); p2vs.Add("description", newGroup.Description); if (SqliteHelper.MainDbHelper.ExecuteSql(addSql, p2vs)) { return(id); } else { return(null); } }