public void AddRow() { if (RoomStates.Count() > 0) { if (RoomStates[RoomStates.Count() - 1].Name == null && RoomStates[RoomStates.Count() - 1].Color == null) { new MessageWindow(thiswindow, "有空行还未填写").ShowDialog(); return; } else if (RoomStates[RoomStates.Count() - 1].Name == null) { new MessageWindow(thiswindow, "房间状态不能为空").ShowDialog(); return; } } RoomStateModel rt = new RoomStateModel() { StateID = Guid.NewGuid(), Color = "默认(灰色)" }; RoomStates.Add(rt); }
public void UpdateData() { if (RoomStates[RoomStates.Count() - 1].Name == null && RoomStates[RoomStates.Count() - 1].Color == null) { new MessageWindow(thiswindow, "有空行还未填写").ShowDialog(); return; } else if (RoomStates[RoomStates.Count() - 1].Name == null) { new MessageWindow(thiswindow, "房间状态不能为空").ShowDialog(); return; } Guid[] names = new Guid[GetRoomStates.Count()]; for (int i = 0; i < GetRoomStates.Count(); i++) { names[i] = GetRoomStates[i].StateID; } using (RetailContext context = new RetailContext()) { foreach (RoomStateModel rs in RoomStates) { if (names.Contains(rs.StateID)) { string sql = string.Format("update RoomStates set Name = '{0}',Color = '{1}' where UPPER(HEX([StateID]))='{2}'", rs.Name, rs.Color, rs.StateID.ConvertGuid()); context.Database.ExecuteSqlCommand(sql); } else { context.RoomStates.Add(rs); } } context.SaveChanges(); } LoadData(); }