/// <summary> /// 更新函数 /// </summary> /// <param name="info">Model</param> /// <returns>影响数据物理ID,已存在逻辑主码返回-1</returns> public long UPDATE(Area info) { try { S_area temp = new S_area(); Table <S_area> table = db.GetTable <S_area>(); temp = (from row in db.S_area where row.id == info.ID select row).First(); //temp.id = info.ID; temp.cid = info.Cid; temp.name = info.Name; temp.lng = info.Lng; temp.lat = info.Lat; temp.zoom = info.Zoom; temp.type = info.Type; temp.isused = info.Isused; db.SubmitChanges(); return(temp.id); } catch { return(-2); } }
/// <summary> /// 插入函数 /// </summary> /// <param name="info">Model</param> /// <returns>影响数据物理ID</returns> public long INSERT(Area info) { try { S_area temp = new S_area(); if (SELECT_BY_NAME_ISUSED(info.Name, true) != null) { return(-1); } //temp.id = info.ID; temp.name = info.Name; temp.cid = info.Cid; temp.lng = info.Lng; temp.lat = info.Lat; temp.zoom = info.Zoom; temp.type = info.Type; temp.isused = info.Isused; Table <S_area> table = db.GetTable <S_area>(); table.InsertOnSubmit(temp); db.SubmitChanges(); return(temp.id); } catch { return(-2); } }
/// <summary> /// 根据逻辑使用主码查询,true状态下name不可重复,不包含ID为0条目 /// </summary> /// <param name="name">区域名字</param> /// <returns>结果</returns> public Area SELECT_BY_NAME_ISUSED(string name, bool isused) { try { Area rd = new Area(); S_area temp = (from row in db.S_area where row.name == name && row.isused == isused && row.id != 0 select row).First(); rd.ID = temp.id; rd.Cid = temp.cid; rd.Name = temp.name; rd.Lng = temp.lng; rd.Lat = temp.lat; rd.Zoom = temp.zoom; rd.Type = temp.type; rd.Isused = temp.isused; return(rd); } catch { return(null); } }
/// <summary> /// 根据物理主码查询 /// </summary> /// <param name="id">id</param> /// <returns>结果</returns> public Area SELECT_BY_ID(short id) { try { Area rd = new Area(); S_area temp = (from row in db.S_area where row.id == id select row).First(); rd.ID = temp.id; rd.Cid = temp.cid; rd.Name = temp.name; rd.Lng = temp.lng; rd.Lat = temp.lat; rd.Zoom = temp.zoom; rd.Type = temp.type; rd.Isused = temp.isused; return(rd); } catch { return(null); } }