コード例 #1
0
        public void AddRow()
        {
            if (RoomTypes.Count() > 0)
            {
                if (RoomTypes[RoomTypes.Count() - 1].Name == null && RoomTypes[RoomTypes.Count() - 1].Color == null)
                {
                    new MessageWindow(thiswindow, "有空行还未填写").ShowDialog();
                    return;
                }
                else if (RoomTypes[RoomTypes.Count() - 1].Name == null)
                {
                    new MessageWindow(thiswindow, "房间状态不能为空").ShowDialog();
                    return;
                }
            }
            RoomType rt = new RoomType()
            {
                ID    = Guid.NewGuid(),
                Color = "默认(灰色)"
            };

            RoomTypes.Add(rt);
        }
コード例 #2
0
        public void UpdateData()
        {
            if (RoomTypes[RoomTypes.Count() - 1].Name == null && RoomTypes[RoomTypes.Count() - 1].Cap <= 0)
            {
                new MessageWindow(thiswindow, "有空行还未填写").ShowDialog();
                return;
            }
            else if (RoomTypes[RoomTypes.Count() - 1].Name == null)
            {
                new MessageWindow(thiswindow, "房间状态不能为空").ShowDialog();
                return;
            }
            Guid[] names = new Guid[GetRoomTypes.Count()];
            for (int i = 0; i < GetRoomTypes.Count(); i++)
            {
                names[i] = GetRoomTypes[i].ID;
            }
            using (RetailContext context = new RetailContext())
            {
                foreach (RoomType rs in RoomTypes)
                {
                    if (names.Contains(rs.ID))
                    {
                        string sql = string.Format("update RoomTypes set Name = '{0}',Cap = {1} where UPPER(HEX([ID]))='{2}'", rs.Name, rs.Cap, rs.ID.ConvertGuid());
                        context.Database.ExecuteSqlCommand(sql);
                    }
                    else
                    {
                        context.RoomTypes.Add(rs);
                    }
                }
                context.SaveChanges();
            }


            LoadData();
        }