Merge branch 'feature/Osai_ToolTable' into develop
# Conflicts: # Libs/CMS_CORE_Library.dll # Step.Core/ThreadsFunctions.cs # Step.Core/ThreadsHandler.cs # Step.Database/DatabaseContext.cs # Step.Database/Migrations/201806220920193_InitMigration.Designer.cs # Step.Database/Migrations/201806220920193_InitMigration.cs # Step.Database/Migrations/201807120908403_InitMigration.Designer.cs # Step.Database/Migrations/201807120908403_InitMigration.cs # Step.Database/Migrations/201807120908403_InitMigration.resx # Step.Database/Migrations/201807251330036_InitMigration.Designer.cs # Step.Database/Migrations/201807251330036_InitMigration.cs # Step.Database/Step.Database.csproj # Step.Model/Constants.cs # Step.NC/NcHandler.cs # Step/Listeners/ListenersHandler.cs # Step/Step.csproj
This commit is contained in:
@@ -0,0 +1,445 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels.ToolModels;
|
||||
using Step.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.Linq;
|
||||
|
||||
namespace Step.Database.Controllers
|
||||
{
|
||||
public class NcToolManagerController : IDisposable
|
||||
{
|
||||
public DatabaseContext dbCtx;
|
||||
|
||||
public NcToolManagerController()
|
||||
{
|
||||
// Initialize database context
|
||||
dbCtx = new DatabaseContext();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public List<DbNcFamilyModel> FindFamilies()
|
||||
{
|
||||
List<DbNcFamilyModel> families = dbCtx
|
||||
.Families
|
||||
.Include("Tools")
|
||||
.ToList();
|
||||
|
||||
return families;
|
||||
}
|
||||
|
||||
public List<DTONcFamilyModel> GetFamilies()
|
||||
{
|
||||
List<DbNcFamilyModel> dbFamilies = FindFamilies();
|
||||
|
||||
return dbFamilies
|
||||
.Select(x => (DTONcFamilyModel)x)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<DbNcFamilyModel> FindFamiliesByShankId(int shankId)
|
||||
{
|
||||
DbNcShankModel shank = FindShankWithTools(shankId);
|
||||
// Get only families id
|
||||
int[] ids = shank.Tools.Select(x => x.FamilyId).ToArray();
|
||||
|
||||
return FindFamilies() // Get Families
|
||||
.Where(x => ids.Contains(x.FamilyId)) // Filter by ids
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public DbNcToolModel FindTool(int toolId)
|
||||
{
|
||||
return dbCtx.Tools
|
||||
.Where(x => x.ToolId == toolId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public DbNcShankModel FindShankWithTools(int shankId)
|
||||
{
|
||||
return dbCtx.Shanks
|
||||
.Include("Tools")
|
||||
.Where(x => x.ShankId == shankId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public DbNcFamilyModel FindFamily(int familyId)
|
||||
{
|
||||
return dbCtx
|
||||
.Families
|
||||
.Where(x => x.FamilyId == familyId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public List<DbNcToolModel> FindToolsWithDependencies()
|
||||
{
|
||||
List<DbNcToolModel> tools = dbCtx
|
||||
.Tools
|
||||
.Include("Family")
|
||||
.Include("Shank")
|
||||
.ToList();
|
||||
|
||||
return tools;
|
||||
}
|
||||
|
||||
public List<DbNcToolModel> FindToolsByShankIdWithDependencies(int shankId)
|
||||
{
|
||||
List<DbNcToolModel> tools = FindToolsWithDependencies()
|
||||
.Where(x => x.ShankId == shankId)
|
||||
.ToList();
|
||||
|
||||
return tools;
|
||||
}
|
||||
|
||||
public List<DbNcToolModel> FindTools()
|
||||
{
|
||||
List<DbNcToolModel> tools = dbCtx
|
||||
.Tools
|
||||
.ToList();
|
||||
|
||||
return tools;
|
||||
}
|
||||
|
||||
public List<DTONcToolModel> GetTools()
|
||||
{
|
||||
List<DbNcToolModel> dbTools = FindToolsWithDependencies();
|
||||
|
||||
return dbTools
|
||||
.Select(x => (DTONcToolModel)x)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<DbNcShankModel> FindShanks()
|
||||
{
|
||||
List<DbNcShankModel> shanks = dbCtx
|
||||
.Shanks
|
||||
.Include("MagazinePosition")
|
||||
.ToList();
|
||||
|
||||
return shanks;
|
||||
}
|
||||
|
||||
public DbNcShankModel FindShanksByPositions(int magazineId, int positionId)
|
||||
{
|
||||
DbNcShankModel shank = FindShanks()
|
||||
.Where(x => x.MagazineId == magazineId && x.PositionId == positionId)
|
||||
.FirstOrDefault();
|
||||
|
||||
return shank;
|
||||
}
|
||||
|
||||
public List<DTONcShankModel> GetShanks()
|
||||
{
|
||||
// Get shank from database
|
||||
List<DbNcShankModel> dbShanks = dbCtx
|
||||
.Shanks
|
||||
.Include("Tools")
|
||||
.ToList();
|
||||
|
||||
// Populate db shanks
|
||||
List<DTONcShankModel> dtoShanks = dbShanks
|
||||
.Select(x => (DTONcShankModel)x)
|
||||
.ToList();
|
||||
// new List<DTONcShankModel>();
|
||||
//foreach (var shank in dbShanks)
|
||||
//{
|
||||
// //dbCtx.Shanks.Attach(shank);
|
||||
// DTONcShankModel dtoShank = (DTONcShankModel)shank;
|
||||
|
||||
// dtoShanks.Add(dtoShank);
|
||||
//}
|
||||
|
||||
return dtoShanks;
|
||||
}
|
||||
|
||||
public DTONcShankModel GetShank(int shankId)
|
||||
{
|
||||
// Get shank from database
|
||||
DbNcShankModel dbShank = dbCtx
|
||||
.Shanks
|
||||
.Where(x => x.ShankId == shankId)
|
||||
.Include("Tools")
|
||||
.FirstOrDefault();
|
||||
|
||||
// Convert into DTOModel
|
||||
DTONcShankModel dtoShanks = (DTONcShankModel)dbShank;
|
||||
|
||||
return dtoShanks;
|
||||
}
|
||||
|
||||
public List<DbNcMagazinePositionModel> FindMagazinesPositions()
|
||||
{
|
||||
List<DbNcMagazinePositionModel> positions = dbCtx
|
||||
.MagazinePositions
|
||||
.ToList();
|
||||
|
||||
return positions;
|
||||
}
|
||||
|
||||
public List<DbNcMagazinePositionModel> FindMagazinePositions(byte magId)
|
||||
{
|
||||
return dbCtx
|
||||
.MagazinePositions
|
||||
.Where(x => x.MagazineId == magId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
public List<DTONcMagazinePositionModel> GetMagazinePositions(byte magId)
|
||||
{
|
||||
// Get only magazine positions that match with magazineId
|
||||
List<DTONcMagazinePositionModel> magPos = FindMagazinePositions(magId).Select(x => (DTONcMagazinePositionModel)x).ToList();
|
||||
// Get&filter shanks by magazineId in order to get only mounted shanks in the current magazineId
|
||||
List<DbNcShankModel> shanks = dbCtx.Shanks.Where(x => x.MagazineId == magId).ToList();
|
||||
|
||||
foreach(DbNcShankModel shank in shanks)
|
||||
{
|
||||
// Populate magazinePosition shank Id
|
||||
magPos
|
||||
.Where(x => x.PositionId == shank.PositionId)
|
||||
.FirstOrDefault()
|
||||
.ShankId = shank.ShankId;
|
||||
}
|
||||
// Convert in DTOModel and return
|
||||
return magPos;
|
||||
}
|
||||
|
||||
public DbNcMagazinePositionModel FindMagazinePosition(byte magId, byte posId)
|
||||
{
|
||||
DbNcMagazinePositionModel positions = dbCtx
|
||||
.MagazinePositions
|
||||
.Where(x => x.MagazineId == magId && x.PositionId == posId)
|
||||
.FirstOrDefault();
|
||||
|
||||
return positions;
|
||||
}
|
||||
|
||||
public List<DTONcShankModel> GetMountedShanks(int magazineId)
|
||||
{
|
||||
List<DTONcShankModel> dtoShanks = GetShanks()
|
||||
.Where(x => x.MagazineId != null)
|
||||
.ToList();
|
||||
|
||||
return dtoShanks;
|
||||
}
|
||||
|
||||
public List<DbNcToolModel> GetMountedTools()
|
||||
{
|
||||
List<DbNcToolModel> tools = FindToolsWithDependencies()
|
||||
.Where(x => x.Shank.MagazineId != null)
|
||||
.ToList();
|
||||
|
||||
return tools;
|
||||
}
|
||||
|
||||
public List<DTONcShankModel> GetAvailableShanks()
|
||||
{
|
||||
List<DTONcShankModel> dtoShanks = GetShanks()
|
||||
.Where(x => x.MagazineId == null && x.Tools.Count > 0)
|
||||
.ToList();
|
||||
|
||||
return dtoShanks;
|
||||
}
|
||||
|
||||
public DbNcToolModel AddTool(DTONewNcToolModel dtoTool)
|
||||
{
|
||||
DbNcToolModel tool = (DbNcToolModel)dtoTool;
|
||||
dbCtx.Tools.Add(tool);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
// Get foreign key data
|
||||
dbCtx.Entry(tool).Reference(x => x.Family).Load();
|
||||
dbCtx.Entry(tool).Reference(x => x.Shank).Load();
|
||||
|
||||
return tool;
|
||||
}
|
||||
|
||||
public DbNcToolModel UpdateTool(int toolId, DTONewNcToolModel dtoTool)
|
||||
{
|
||||
DbNcToolModel tool = FindTool(toolId);
|
||||
|
||||
tool.Status = ((DbNcToolModel)dtoTool).Status;
|
||||
var shankId = tool.ShankId;
|
||||
|
||||
// Update db model
|
||||
SupportFunctions.CopyProperties(dtoTool, tool);
|
||||
tool.ShankId = shankId;
|
||||
|
||||
// Save
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return tool;
|
||||
}
|
||||
|
||||
public void DeleteTool(int toolId)
|
||||
{
|
||||
DbNcToolModel tool = FindTool(toolId);
|
||||
DeleteTool(tool);
|
||||
}
|
||||
|
||||
public void DeleteTool(DbNcToolModel tool)
|
||||
{
|
||||
dbCtx.Tools.Remove(tool);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public DbNcFamilyModel AddFamily(DTONewNcFamilyModel family)
|
||||
{
|
||||
DbNcFamilyModel dbFamily = (DbNcFamilyModel)family;
|
||||
dbCtx.Families.Add(dbFamily);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return dbFamily;
|
||||
}
|
||||
|
||||
public DbNcFamilyModel UpdateFamily(int familyId, DTONewNcFamilyModel family)
|
||||
{
|
||||
DbNcFamilyModel dbFamily = FindFamily(familyId);
|
||||
// Copy data from NewModel to DbModel
|
||||
SupportFunctions.CopyProperties(family, dbFamily);
|
||||
// Set cooling byte
|
||||
dbFamily.CoolingByte = ((DbNcFamilyModel)family).CoolingByte;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
// Connect tools data
|
||||
dbCtx.Entry(dbFamily).Collection(x => x.Tools).Load();
|
||||
|
||||
return dbFamily;
|
||||
}
|
||||
|
||||
public void DeleteFamily(DbNcFamilyModel family)
|
||||
{
|
||||
dbCtx.Families.Attach(family);
|
||||
dbCtx.Families.Remove(family);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public DbNcShankModel AddShank(DTONewNcShankModel shank)
|
||||
{
|
||||
DbNcShankModel dbShank = (DbNcShankModel)shank;
|
||||
dbCtx.Shanks.Add(dbShank);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
|
||||
return dbShank;
|
||||
}
|
||||
|
||||
public DbNcShankModel UpdateShank(int shankId, DTONewNcShankModel dtoShank)
|
||||
{
|
||||
DbNcShankModel ncShank = FindShankWithTools(shankId);
|
||||
|
||||
return UpdateShank(ncShank, dtoShank);
|
||||
}
|
||||
|
||||
public DbNcShankModel UpdateShank(DbNcShankModel dbShank, DTONewNcShankModel dtoShank)
|
||||
{
|
||||
dbShank.MagazinePositionType = dtoShank.MagazinePositionType;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
dbCtx.Entry(dbShank).Collection(x => x.Tools).Load();
|
||||
|
||||
return dbShank;
|
||||
}
|
||||
|
||||
public DbNcShankModel DeleteShank(int shankId)
|
||||
{
|
||||
DbNcShankModel shank = FindShankWithTools(shankId);
|
||||
DeleteShank(shank);
|
||||
|
||||
return shank;
|
||||
}
|
||||
|
||||
public void DeleteShank(DbNcShankModel shank)
|
||||
{
|
||||
dbCtx.Shanks.Remove(shank);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public DbNcMagazinePositionModel UpdatePosition(DbNcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos)
|
||||
{
|
||||
dbCtx.MagazinePositions.Attach(dbPos);
|
||||
dbPos.Type = dtoPos.Type;
|
||||
dbPos.Disabled = dtoPos.Disabled;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return dbPos;
|
||||
}
|
||||
|
||||
public DbNcMagazinePositionModel LoadShankInMagazine(byte magazineId, byte positionId, DbNcShankModel shank)
|
||||
{
|
||||
dbCtx.Shanks.Attach(shank);
|
||||
// Set ids with new positions
|
||||
shank.MagazineId = magazineId;
|
||||
shank.PositionId = positionId;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return FindMagazinePosition(magazineId, positionId);
|
||||
}
|
||||
|
||||
public DbNcMagazinePositionModel UnloadShankInMagazine(byte magazineId, byte positionId, DbNcShankModel shank)
|
||||
{
|
||||
dbCtx.Shanks.Attach(shank);
|
||||
// set id to null
|
||||
shank.MagazineId = null;
|
||||
shank.PositionId = null;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return FindMagazinePosition(magazineId, positionId);
|
||||
}
|
||||
|
||||
public DTONcShankModel LoadToolIntoShank(DbNcToolModel tool, int shankId)
|
||||
{
|
||||
dbCtx.Tools.Attach(tool);
|
||||
// Set tool shankId
|
||||
tool.ShankId = shankId;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return GetShank(shankId);
|
||||
}
|
||||
|
||||
public DTONcShankModel UnloadToolFromShank(DbNcToolModel tool)
|
||||
{
|
||||
dbCtx.Tools.Attach(tool);
|
||||
int? shankId = tool.ShankId;
|
||||
// Set to null shankId
|
||||
tool.ShankId = null;
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return GetShank(shankId.Value);
|
||||
}
|
||||
|
||||
public void SetupMagazinePositions(List<DbNcMagazinePositionModel> config)
|
||||
{
|
||||
dbCtx.MagazinePositions.AddRange(config);
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public void UpdateToolsData(List<DbNcToolModel> tools)
|
||||
{
|
||||
foreach (var tool in tools)
|
||||
{
|
||||
DbNcToolModel tmpTool = dbCtx.Tools.Where(x => x.ToolId == tool.ToolId).FirstOrDefault();
|
||||
tmpTool = tool;
|
||||
}
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,14 @@ namespace Step.Database
|
||||
public DbSet<MaintenanceFileModel> MaintenanceFiles { get; set; }
|
||||
public DbSet<FavoriteUserSoftkeyModel> FavoriteUserSoftkeys { get; set; }
|
||||
|
||||
public DbSet<DbNcFamilyModel> Families { get; set; }
|
||||
public DbSet<DbNcShankModel> Shanks { get; set; }
|
||||
public DbSet<DbNcToolModel> Tools { get; set; }
|
||||
public DbSet<DbNcMagazinePositionModel> MagazinePositions { get; set; }
|
||||
|
||||
// Create migration string
|
||||
public static string CONNECTION_STRING = "Server = " + "localhost" + "; Database=" + DATABASE_NAME +";Uid="+ DATABASE_USER +";Pwd="+ DATABASE_PWD +";";
|
||||
public static string CONNECTION_STRING = "Server = " + "localhost" + "; Database=" + DATABASE_NAME + ";Uid=" + DATABASE_USER + ";Pwd=" + DATABASE_PWD + ";";
|
||||
|
||||
// public static string CONNECTION_STRING = "Server = " + ServerStartupConfig.DatabaseAddress + "; Database=" + DATABASE_NAME +";Uid="+ DATABASE_USER +";Pwd="+ DATABASE_PWD +";";
|
||||
|
||||
public DatabaseContext()
|
||||
@@ -77,25 +83,19 @@ namespace Step.Database
|
||||
AllFunctionalityDisabled = functionsAccess.FindAllFunctionsAndDisableAll();
|
||||
}
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException ex)
|
||||
{
|
||||
if (ex.Number == 0)
|
||||
{
|
||||
//dbContext.Database.Initialize(true);
|
||||
}
|
||||
else if (ex.Number == 1042) // Can't find MySQLServer
|
||||
{
|
||||
Manage(ERROR_LEVEL.FATAL, ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
Manage(ERROR_LEVEL.ERROR, ex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Manage(ERROR_LEVEL.FATAL, ex);
|
||||
}
|
||||
|
||||
|
||||
//catch (MySql.Data.MySqlClient.MySqlException ex)
|
||||
//{
|
||||
// if (ex.Number == 1042) // Can't find MySQLServer
|
||||
// Manage(ERROR_LEVEL.FATAL, ex);
|
||||
// else
|
||||
// Manage(ERROR_LEVEL.ERROR, ex);
|
||||
//}
|
||||
}
|
||||
|
||||
public static void FindOrCreateMachineUniqueId()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// <auto-generated />
|
||||
namespace Step.Database.Migrations
|
||||
{
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Data.Entity.Migrations;
|
||||
using System.Data.Entity.Migrations.Infrastructure;
|
||||
using System.Resources;
|
||||
|
||||
[GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")]
|
||||
public sealed partial class InitMigration : IMigrationMetadata
|
||||
{
|
||||
private readonly ResourceManager Resources = new ResourceManager(typeof(InitMigration));
|
||||
|
||||
string IMigrationMetadata.Id
|
||||
{
|
||||
get { return "201807251330036_InitMigration"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.Source
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.Target
|
||||
{
|
||||
get { return Resources.GetString("Target"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
namespace Step.Database.Migrations
|
||||
{
|
||||
using System;
|
||||
using System.Data.Entity.Migrations;
|
||||
|
||||
public partial class InitMigration : DbMigration
|
||||
{
|
||||
public override void Up()
|
||||
{
|
||||
CreateTable(
|
||||
"dbo.family",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
name = c.String(unicode: false),
|
||||
type = c.Byte(nullable: false),
|
||||
right_size = c.Byte(nullable: false),
|
||||
left_size = c.Byte(nullable: false),
|
||||
tcp_table = c.Byte(nullable: false),
|
||||
gamma = c.Byte(nullable: false),
|
||||
rotation_type = c.Byte(nullable: false),
|
||||
cooling_byte = c.Byte(nullable: false),
|
||||
max_speed = c.Int(nullable: false),
|
||||
max_load = c.Byte(nullable: false),
|
||||
min_load_pct_autoload = c.Byte(nullable: false),
|
||||
max_load_pct_autoload = c.Byte(nullable: false),
|
||||
dynamic_compensation = c.Byte(nullable: false),
|
||||
min_load_dynamic_comp = c.Byte(nullable: false),
|
||||
max_load_dynamic_comp = c.Byte(nullable: false),
|
||||
life_type = c.Byte(nullable: false),
|
||||
nominal_life = c.Int(nullable: false),
|
||||
revive_delta = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.tool",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
offset_length = c.Int(nullable: false),
|
||||
residual_life = c.Int(nullable: false),
|
||||
residual_revive = c.Int(nullable: false),
|
||||
status = c.Byte(nullable: false),
|
||||
family_id = c.Int(nullable: false),
|
||||
shank_id = c.Int(),
|
||||
offsetId1 = c.Int(),
|
||||
offsetId2 = c.Int(),
|
||||
offsetId3 = c.Int(),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.family", t => t.family_id, cascadeDelete: true)
|
||||
.ForeignKey("dbo.shank", t => t.shank_id)
|
||||
.Index(t => t.family_id)
|
||||
.Index(t => t.shank_id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.shank",
|
||||
c => new
|
||||
{
|
||||
magazine_id = c.Byte(),
|
||||
position_id = c.Byte(),
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
balluf = c.Int(),
|
||||
magazine_position_type = c.Byte(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.magazine_position", t => new { t.magazine_id, t.position_id })
|
||||
.Index(t => new { t.magazine_id, t.position_id });
|
||||
|
||||
CreateTable(
|
||||
"dbo.magazine_position",
|
||||
c => new
|
||||
{
|
||||
magazine_id = c.Byte(nullable: false),
|
||||
position_id = c.Byte(nullable: false),
|
||||
type = c.Byte(nullable: false),
|
||||
disabled = c.Boolean(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => new { t.magazine_id, t.position_id });
|
||||
|
||||
CreateTable(
|
||||
"dbo.function_access",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
name = c.String(unicode: false),
|
||||
write_level_min = c.Int(nullable: false),
|
||||
read_level_min = c.Int(nullable: false),
|
||||
area = c.String(unicode: false),
|
||||
enabled = c.Boolean(nullable: false),
|
||||
plc_id = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.machine",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
name = c.String(unicode: false),
|
||||
unique_id = c.String(unicode: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.machine_user",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
machine_id = c.Int(nullable: false),
|
||||
user_id = c.Int(nullable: false),
|
||||
role_id = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.machine", t => t.machine_id, cascadeDelete: true)
|
||||
.ForeignKey("dbo.role", t => t.role_id, cascadeDelete: true)
|
||||
.ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
|
||||
.Index(t => new { t.machine_id, t.user_id }, unique: true, clustered: true, name: "unique_machine_user")
|
||||
.Index(t => t.role_id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.role",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
name = c.String(unicode: false),
|
||||
level = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.user",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
username = c.String(nullable: false, unicode: false),
|
||||
first_name = c.String(unicode: false),
|
||||
last_name = c.String(unicode: false),
|
||||
password = c.String(unicode: false),
|
||||
security_stamp = c.String(unicode: false),
|
||||
language = c.String(unicode: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.maintenance_file",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
file_name = c.String(unicode: false),
|
||||
local_file_name = c.String(unicode: false),
|
||||
maintenance_id = c.Int(nullable: false),
|
||||
user_id = c.Int(),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.maintenance", t => t.maintenance_id, cascadeDelete: true)
|
||||
.ForeignKey("dbo.user", t => t.user_id)
|
||||
.Index(t => t.maintenance_id)
|
||||
.Index(t => t.user_id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.maintenance",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
intervall = c.Double(),
|
||||
deadline = c.DateTime(nullable: false, precision: 0),
|
||||
type = c.Int(nullable: false),
|
||||
counter_id = c.Int(nullable: false),
|
||||
title = c.String(unicode: false),
|
||||
description = c.String(unicode: false),
|
||||
unit_of_measure = c.Int(),
|
||||
creation_date = c.DateTime(nullable: false, precision: 0),
|
||||
last_expiration_date = c.DateTime(precision: 0),
|
||||
user_id = c.Int(),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.user", t => t.user_id)
|
||||
.Index(t => t.user_id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.maintenance_note",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
message = c.String(unicode: false),
|
||||
user_id = c.Int(nullable: false),
|
||||
maintenance_id = c.Int(nullable: false),
|
||||
timestamp = c.DateTime(nullable: false, precision: 0),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.maintenance", t => t.maintenance_id, cascadeDelete: true)
|
||||
.ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
|
||||
.Index(t => t.user_id)
|
||||
.Index(t => t.maintenance_id);
|
||||
|
||||
CreateTable(
|
||||
"dbo.performed_maintenance",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
date = c.DateTime(nullable: false, precision: 0),
|
||||
counter_value = c.Int(nullable: false),
|
||||
maintenance = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.maintenance", t => t.maintenance, cascadeDelete: true)
|
||||
.Index(t => t.maintenance);
|
||||
|
||||
CreateTable(
|
||||
"dbo.session",
|
||||
c => new
|
||||
{
|
||||
id = c.Int(nullable: false, identity: true),
|
||||
token = c.String(unicode: false),
|
||||
machine_user_id = c.Int(nullable: false),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.machine_user", t => t.machine_user_id, cascadeDelete: true)
|
||||
.Index(t => t.machine_user_id);
|
||||
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
DropForeignKey("dbo.session", "machine_user_id", "dbo.machine_user");
|
||||
DropForeignKey("dbo.performed_maintenance", "maintenance", "dbo.maintenance");
|
||||
DropForeignKey("dbo.maintenance_note", "user_id", "dbo.user");
|
||||
DropForeignKey("dbo.maintenance_note", "maintenance_id", "dbo.maintenance");
|
||||
DropForeignKey("dbo.maintenance_file", "user_id", "dbo.user");
|
||||
DropForeignKey("dbo.maintenance_file", "maintenance_id", "dbo.maintenance");
|
||||
DropForeignKey("dbo.maintenance", "user_id", "dbo.user");
|
||||
DropForeignKey("dbo.machine_user", "user_id", "dbo.user");
|
||||
DropForeignKey("dbo.machine_user", "role_id", "dbo.role");
|
||||
DropForeignKey("dbo.machine_user", "machine_id", "dbo.machine");
|
||||
DropForeignKey("dbo.tool", "shank_id", "dbo.shank");
|
||||
DropForeignKey("dbo.shank", new[] { "magazine_id", "position_id" }, "dbo.magazine_position");
|
||||
DropForeignKey("dbo.tool", "family_id", "dbo.family");
|
||||
DropIndex("dbo.session", new[] { "machine_user_id" });
|
||||
DropIndex("dbo.performed_maintenance", new[] { "maintenance" });
|
||||
DropIndex("dbo.maintenance_note", new[] { "maintenance_id" });
|
||||
DropIndex("dbo.maintenance_note", new[] { "user_id" });
|
||||
DropIndex("dbo.maintenance", new[] { "user_id" });
|
||||
DropIndex("dbo.maintenance_file", new[] { "user_id" });
|
||||
DropIndex("dbo.maintenance_file", new[] { "maintenance_id" });
|
||||
DropIndex("dbo.machine_user", new[] { "role_id" });
|
||||
DropIndex("dbo.machine_user", "unique_machine_user");
|
||||
DropIndex("dbo.shank", new[] { "magazine_id", "position_id" });
|
||||
DropIndex("dbo.tool", new[] { "shank_id" });
|
||||
DropIndex("dbo.tool", new[] { "family_id" });
|
||||
DropTable("dbo.session");
|
||||
DropTable("dbo.performed_maintenance");
|
||||
DropTable("dbo.maintenance_note");
|
||||
DropTable("dbo.maintenance");
|
||||
DropTable("dbo.maintenance_file");
|
||||
DropTable("dbo.user");
|
||||
DropTable("dbo.role");
|
||||
DropTable("dbo.machine_user");
|
||||
DropTable("dbo.machine");
|
||||
DropTable("dbo.function_access");
|
||||
DropTable("dbo.magazine_position");
|
||||
DropTable("dbo.shank");
|
||||
DropTable("dbo.tool");
|
||||
DropTable("dbo.family");
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -70,17 +70,17 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controllers\UserSoftkeysController.cs" />
|
||||
<Compile Include="Controllers\FunctionsAccessController.cs" />
|
||||
<Compile Include="Controllers\MachinesController.cs" />
|
||||
<Compile Include="Controllers\MaintenancesController.cs" />
|
||||
<Compile Include="Controllers\NcToolManagerController.cs" />
|
||||
<Compile Include="Controllers\SessionsController.cs" />
|
||||
<Compile Include="Controllers\UsersController.cs" />
|
||||
<Compile Include="Controllers\MachinesUsersController.cs" />
|
||||
<Compile Include="DatabaseContext.cs" />
|
||||
<Compile Include="Migrations\201807120908403_InitMigration.cs" />
|
||||
<Compile Include="Migrations\201807120908403_InitMigration.Designer.cs">
|
||||
<DependentUpon>201807120908403_InitMigration.cs</DependentUpon>
|
||||
<Compile Include="Migrations\201807251330036_InitMigration.cs" />
|
||||
<Compile Include="Migrations\201807251330036_InitMigration.Designer.cs">
|
||||
<DependentUpon>201807251330036_InitMigration.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\Configuration.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -116,8 +116,8 @@
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Migrations\201807120908403_InitMigration.resx">
|
||||
<DependentUpon>201807120908403_InitMigration.cs</DependentUpon>
|
||||
<EmbeddedResource Include="Migrations\201807251330036_InitMigration.resx">
|
||||
<DependentUpon>201807251330036_InitMigration.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
Reference in New Issue
Block a user