public void Save(T_Room value, ref string msg)
        {
            T_Room valueupdate = new T_Room();

            using (AttMonSysRFIDDataContext dc = new AttMonSysRFIDDataContext(SystemConnection.ConnectionString))
            {
                if (Compare(value))
                {
                    if (value.ID == 0)
                    {
                        dc.T_Rooms.InsertOnSubmit(value);
                        msg = string.Format("{0} " + Environment.NewLine + Environment.NewLine + "{1}" + Environment.NewLine + " {2}" + Environment.NewLine + " {3}", SystemProperties.MessageNotification.Saved, value.RoomCode, value.Description, value.Capacity);
                    }
                    else
                    {
                        valueupdate              = dc.T_Rooms.Where(x => x.ID == value.ID).FirstOrDefault();
                        valueupdate.RoomCode     = value.RoomCode;
                        valueupdate.RoomType     = value.RoomType;
                        valueupdate.Description  = value.Description;
                        valueupdate.Active       = value.Active;
                        valueupdate.Capacity     = value.Capacity;
                        valueupdate.TimeID       = value.TimeID;
                        valueupdate.BuildingCode = value.BuildingCode;
                        msg = string.Format("{0} " + Environment.NewLine + Environment.NewLine + "{1}" + Environment.NewLine + " {2}" + Environment.NewLine + " {3}", SystemProperties.MessageNotification.Updated, valueupdate.RoomCode, valueupdate.Description, valueupdate.Capacity);
                    }
                }
                else
                {
                    msg = string.Format("{0} " + Environment.NewLine + Environment.NewLine + "{1}" + Environment.NewLine + " {2}" + Environment.NewLine + " {3}", SystemProperties.MessageNotification.Exist, value.RoomCode, value.RoomType, value.BuildingCode);
                }
                dc.SubmitChanges();
            }
        }
 public bool Compare(T_Room value)
 {
     using (AttMonSysRFIDDataContext dc = new AttMonSysRFIDDataContext(SystemConnection.ConnectionString))
     {
         return(dc.T_Rooms.Where(x => x.Active == value.Active && x.RoomCode.ToLower() == value.RoomCode.ToLower() && x.RoomType == value.RoomType && x.Description == value.Description && x.BuildingCode == value.BuildingCode && x.Capacity == value.Capacity).FirstOrDefault() == null ? true : false);
     }
 }
        public void Delete(T_Room value, ref string msg)
        {
            T_Room valuedelete = new T_Room();

            using (AttMonSysRFIDDataContext dc = new AttMonSysRFIDDataContext(SystemConnection.ConnectionString))
            {
                valuedelete = dc.T_Rooms.Where(x => x.ID == value.ID).FirstOrDefault();
                dc.T_Rooms.DeleteOnSubmit(valuedelete);
                dc.SubmitChanges();
                msg = string.Format("{0} " + Environment.NewLine + Environment.NewLine + "{1}" + Environment.NewLine + " {2}" + Environment.NewLine + " {3}", SystemProperties.MessageNotification.Deleted, valuedelete.RoomCode, valuedelete.Description, valuedelete.Capacity);
            }
        }
        public T_Room SetRoom()
        {
            T_Room valueret = new T_Room();

            valueret.ID           = isAdd?0:Convert.ToInt64(dgRoom.SelectedRows[0].Cells[0].Value.ToString());
            valueret.RoomCode     = txtRoomCode.Text;
            valueret.RoomType     = cmbRoomType.Text;
            valueret.Description  = txtDescription.Text;
            valueret.Capacity     = Convert.ToInt32(txtCapacity.Value.ToString());
            valueret.Active       = cbActive.Checked;
            valueret.BuildingCode = cmbBuildingCode.Text;
            return(valueret);
        }
示例#5
0
        /// <summary>
        /// Add a new message to the DB.
        /// </summary>
        /// <param name="message">Object with data of the message.</param>
        /// <returns>True if operation is successfull.</returns>
        public bool AddMessage(MessageModel message)
        {
            Log.Debug("AddMessage");

            // Check parameters before addition
            if (!message.IsCorrect() || message.PlayerName.Length > MaxNameLength ||
                message.Text.Length > MaxMessageLength)
            {
                return(false);
            }

            try
            {
                using (var db = new PobezhdatelDbDataContext())
                {
                    // Find room in DB
                    var dbRoom = db.T_Rooms.SingleOrDefault(q => q.Name == message.RoomName);

                    if (dbRoom == null)     // If such room doesn't exist, create it
                    {
                        dbRoom = new T_Room {
                            Name = message.RoomName
                        };

                        db.T_Rooms.InsertOnSubmit(dbRoom);
                    }

                    db.T_Messages.InsertOnSubmit(new T_Message
                    {
                        Text            = message.Text,
                        Timestamp       = message.Timestamp,
                        PlayerName      = message.PlayerName,
                        DicesRollResult = message.DicesRollResult,
                        T_Room          = dbRoom
                    });

                    db.SubmitChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("AddMessage", ex);
                return(false);
            }
        }
 void Delete()
 {
     if (SystemProperties.ShowMessage.MessageQuestion(SystemProperties.MessageNotification.YouWantToDelete, "Room") == DialogResult.Yes && dgRoom.Rows.Count > 0)
     {
         using (Maintenance _maintain = new Maintenance())
         {
             T_Room value = new T_Room();
             value.ID = Convert.ToInt64(dgRoom.SelectedRows[0].Cells[0].Value);
             if (value != null)
             {
                 _maintain.Delete(value, ref MsgReturned);
                 DeleteRoomDevice(value.RoomCode);
                 SystemProperties.ShowMessage.MessageInformation(MsgReturned, "Room");
                 loadRoom();
                 LoadTime();
                 DeleteTime();
             }
         }
     }
 }