Added alarm notes
WIP Fanuc tool table WIP Siemens Active program fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
using Step.Model.DTOModels.AlarmModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
@@ -85,7 +85,7 @@ namespace Step.Database.Controllers
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
public void InsertNewAlarmUser(List<AlarmUserModel> loggedUser)
|
||||
{
|
||||
dbCtx.AlarmUsers.AddRange(loggedUser);
|
||||
@@ -93,7 +93,7 @@ namespace Step.Database.Controllers
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public AlarmsData GetAlarmsData(int pageSize)
|
||||
public DTOAlarmsData GetAlarmsData(int pageSize)
|
||||
{
|
||||
// Get page numbers
|
||||
int pagesNumbers = dbCtx.AlarmOccurrences.Count() / pageSize;
|
||||
@@ -102,17 +102,69 @@ namespace Step.Database.Controllers
|
||||
// Get first alarm date
|
||||
DateTime date = firstAlarm == null ? DateTime.Now : firstAlarm.TimeStamp;
|
||||
|
||||
return new AlarmsData
|
||||
return new DTOAlarmsData
|
||||
{
|
||||
Pages = pagesNumbers,
|
||||
FirstDate = date
|
||||
};
|
||||
}
|
||||
|
||||
public struct AlarmsData
|
||||
|
||||
public AlarmDescriptionsModel FindById(int id)
|
||||
{
|
||||
public int Pages;
|
||||
public DateTime FirstDate;
|
||||
return dbCtx
|
||||
.AlarmDescriptions
|
||||
.Where(x => x.AlarmId == id)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
#region NOTES
|
||||
|
||||
public AlarmNoteModel FindNoteById(int noteId)
|
||||
{
|
||||
return dbCtx
|
||||
.AlarmsNotes
|
||||
.Where(x => x.NoteId == noteId)
|
||||
.Include("User")
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public DTOAlarmNoteModel CreateNote(int userId, int alarmDescId, DTONewAlarmNoteModel newNote)
|
||||
{
|
||||
// Create model
|
||||
AlarmNoteModel note = new AlarmNoteModel()
|
||||
{
|
||||
Message = newNote.Message,
|
||||
DateTime = DateTime.Now,
|
||||
AlarmDescriptionId = alarmDescId,
|
||||
UserId = userId
|
||||
};
|
||||
// Add & save into database
|
||||
dbCtx.AlarmsNotes.Add(note);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
// Populate user data
|
||||
dbCtx.Entry(note).Reference(x => x.User).Load();
|
||||
dbCtx.Users.Attach(note.User);
|
||||
|
||||
return (DTOAlarmNoteModel)note;
|
||||
}
|
||||
|
||||
public DTOAlarmNoteModel UpdateNote(AlarmNoteModel note, DTONewAlarmNoteModel newNote)
|
||||
{
|
||||
note.Message = newNote.Message;
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return (DTOAlarmNoteModel)note;
|
||||
}
|
||||
|
||||
public void DeleteNote(int noteId)
|
||||
{
|
||||
AlarmNoteModel note = FindNoteById(noteId);
|
||||
dbCtx.AlarmsNotes.Remove(note);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
#endregion NOTES
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,6 @@ namespace Step.Database.Controllers
|
||||
return lastMaintenances;
|
||||
}
|
||||
|
||||
|
||||
public PerformedMaintenanceModel PerformeMaintenance(uint counterValue, int maintenanceId, int userId)
|
||||
{
|
||||
PerformedMaintenanceModel performed = new PerformedMaintenanceModel()
|
||||
@@ -52,8 +51,8 @@ namespace Step.Database.Controllers
|
||||
MaintainerId = userId
|
||||
};
|
||||
|
||||
dbCtx.PerformedMaintenances.Add(performed);
|
||||
|
||||
dbCtx.PerformedMaintenances.Add(performed);
|
||||
|
||||
// Commit changes
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
@@ -113,14 +112,14 @@ namespace Step.Database.Controllers
|
||||
{
|
||||
MaintenanceModel dbMaint = FindById(maintenanceId);
|
||||
|
||||
if(dbMaint != null)
|
||||
if (dbMaint != null)
|
||||
{
|
||||
dbMaint.Title = newMaint.Title;
|
||||
dbMaint.Description = newMaint.Description;
|
||||
dbMaint.Deadline = newMaint.Deadline;
|
||||
dbMaint.Interval = newMaint.Interval;
|
||||
dbMaint.UnitOfMeasure = newMaint.UnitOfMeasure;
|
||||
|
||||
|
||||
// Commit changes
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
@@ -147,7 +146,7 @@ namespace Step.Database.Controllers
|
||||
.ToList();
|
||||
|
||||
// Find database rows that has to be deleted
|
||||
List<MaintenanceModel> toDeleteMaint = dbMaintenances.Where(x => x.UserId == null &&
|
||||
List<MaintenanceModel> toDeleteMaint = dbMaintenances.Where(x => x.UserId == null &&
|
||||
!MaintenancesConfig.Select(y => y.Id).Contains(x.MaintenanceId)
|
||||
).ToList();
|
||||
|
||||
@@ -175,7 +174,7 @@ namespace Step.Database.Controllers
|
||||
old.MaintenanceId = x.Id;
|
||||
old.Deadline = x.Deadline;
|
||||
old.Interval = x.Intervall.TotalMinutes;
|
||||
old.Type = (MAINTENANCE_TYPE) Enum.Parse(typeof(MAINTENANCE_TYPE), x.Type);
|
||||
old.Type = (MAINTENANCE_TYPE)Enum.Parse(typeof(MAINTENANCE_TYPE), x.Type);
|
||||
old.CounterId = x.CouterId;
|
||||
old.UnitOfMeasure = (MAINTENANCE_UNIT_OF_MEASURE)Enum.Parse(typeof(MAINTENANCE_UNIT_OF_MEASURE), x.UnitOfMeasure);
|
||||
return old;
|
||||
@@ -195,7 +194,7 @@ namespace Step.Database.Controllers
|
||||
Type = (MAINTENANCE_TYPE)Enum.Parse(typeof(MAINTENANCE_TYPE), x.Type),
|
||||
CounterId = x.CouterId,
|
||||
CreationDate = DateTime.Now,
|
||||
UnitOfMeasure = (MAINTENANCE_UNIT_OF_MEASURE) Enum.Parse(typeof(MAINTENANCE_UNIT_OF_MEASURE),x.UnitOfMeasure),
|
||||
UnitOfMeasure = (MAINTENANCE_UNIT_OF_MEASURE)Enum.Parse(typeof(MAINTENANCE_UNIT_OF_MEASURE), x.UnitOfMeasure),
|
||||
UserId = null,
|
||||
LastExpirationDate = null
|
||||
})
|
||||
@@ -237,7 +236,7 @@ namespace Step.Database.Controllers
|
||||
.MaintenancesNotes
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
public List<DTOMaintenanceNoteModel> GetNotesByMaintId(int maintenanceId)
|
||||
{
|
||||
return dbCtx
|
||||
@@ -255,7 +254,7 @@ namespace Step.Database.Controllers
|
||||
LastName = x.User.LastName,
|
||||
Username = x.User.Username
|
||||
}
|
||||
})
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -288,7 +287,7 @@ namespace Step.Database.Controllers
|
||||
return (DTOMaintenanceNoteModel)note;
|
||||
}
|
||||
|
||||
public void DeleteMessage(int noteId)
|
||||
public void DeleteNote(int noteId)
|
||||
{
|
||||
MaintenanceNoteModel note = FindNoteById(noteId);
|
||||
dbCtx.MaintenancesNotes.Remove(note);
|
||||
@@ -296,6 +295,10 @@ namespace Step.Database.Controllers
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
#endregion Notes
|
||||
|
||||
#region Attachment
|
||||
|
||||
public List<MaintenanceFileModel> FindAttachmentByMaintenance(int maintenanceId)
|
||||
{
|
||||
return dbCtx
|
||||
@@ -312,7 +315,7 @@ namespace Step.Database.Controllers
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public MaintenanceFileModel AddAttachment(string fileName, string localFileName ,int maintenanceId, int userId)
|
||||
public MaintenanceFileModel AddAttachment(string fileName, string localFileName, int maintenanceId, int userId)
|
||||
{
|
||||
MaintenanceFileModel file = new MaintenanceFileModel()
|
||||
{
|
||||
@@ -345,10 +348,11 @@ namespace Step.Database.Controllers
|
||||
dbCtx.MaintenanceFiles.Remove(attachment);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
|
||||
if (File.Exists(MAINTENANCE_ATTACHMENT_PATH + attachment.LocalFileName))
|
||||
File.Delete(MAINTENANCE_ATTACHMENT_PATH + attachment.LocalFileName);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion Attachment
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ namespace Step.Database.Controllers
|
||||
{
|
||||
DbNcShankModel shank = FindShankWithTools(shankId);
|
||||
// Get only families id
|
||||
int[] ids = shank.Tools.Select(x => x.FamilyId).ToArray();
|
||||
short[] ids = shank.Tools.Select(x => x.FamilyId).ToArray();
|
||||
|
||||
return FindFamilies() // Get Families
|
||||
.Where(x => ids.Contains(x.FamilyId)) // Filter by ids
|
||||
@@ -265,7 +265,7 @@ namespace Step.Database.Controllers
|
||||
return dtoTools;
|
||||
}
|
||||
|
||||
public DbNcToolModel AddTool(DTONewNcToolModel dtoTool, int toolId)
|
||||
public DbNcToolModel AddTool(DTONewNcToolModel dtoTool, short toolId)
|
||||
{
|
||||
// Copy data
|
||||
DbNcToolModel dbTool = (DbNcToolModel)dtoTool;
|
||||
@@ -303,7 +303,7 @@ namespace Step.Database.Controllers
|
||||
return tool;
|
||||
}
|
||||
|
||||
public DbNcToolModel UpdateToolOffset(int toolId, int position, int offsetId)
|
||||
public DbNcToolModel UpdateToolOffset(int toolId, int position, short offsetId)
|
||||
{
|
||||
DbNcToolModel tool = FindTool(toolId);
|
||||
|
||||
@@ -378,7 +378,7 @@ namespace Step.Database.Controllers
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public DbNcShankModel AddShank(DTONewNcShankModel shank, int shankId = 0)
|
||||
public DbNcShankModel AddShank(DTONewNcShankModel shank, short shankId = 0)
|
||||
{
|
||||
DbNcShankModel dbShank = (DbNcShankModel)shank;
|
||||
|
||||
@@ -465,7 +465,7 @@ namespace Step.Database.Controllers
|
||||
return FindMagazinePosition(magazineId, positionId);
|
||||
}
|
||||
|
||||
public DTONcShankModel LoadToolIntoShank(DbNcToolModel tool, int shankId)
|
||||
public DTONcShankModel LoadToolIntoShank(DbNcToolModel tool, short shankId)
|
||||
{
|
||||
dbCtx.Tools.Attach(tool);
|
||||
// Set tool shankId
|
||||
|
||||
Reference in New Issue
Block a user