Initial commit

parent 8e24b58e

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddToSpecification", "AddToSpecification\AddToSpecification.csproj", "{DBBDB30D-7BD0-49C3-BC53-40A14700189A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DBBDB30D-7BD0-49C3-BC53-40A14700189A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DBBDB30D-7BD0-49C3-BC53-40A14700189A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBBDB30D-7BD0-49C3-BC53-40A14700189A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBBDB30D-7BD0-49C3-BC53-40A14700189A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CD16526B-4844-49B0-8A28-BE74F090A19D}
EndGlobalSection
EndGlobal
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using RnD.API;
using RnD.Attributes;
using RnD.Model;
using RnD.Model.EF;
using RnD.Model.FWB;
namespace Actions
{
[CustomFunction("AddToSpecification", RnD.Common.Enums.CustomFunctionType.CustomAction)]
public class AddToSpecification : AdvancedCustomFunction, ICustomAction<ICustomContext>
{
private SpecificationCodeMask aSpecificationCodeMask { get; set; }
private string aCreateNewSpecPref { get; set; } = "Create New Specification";
private string aUpdateSpecPref { get; set; } = "Update Specification";
private string aPrefTp { get; set; } = "fwb";
private string aPrefNameSaveToSpec { get; set; } = "fwbSaveToSpec";
private string aPrefNameFrameNumber { get; set; } = "frameNumber";
public AddToSpecification(IAPI aAPI) : base(aAPI)
{
aSpecificationCodeMask = new SpecificationCodeMask(aAPI);
}
public void Execute(ICustomContext aContext)
{
var lMaterial = ((IRequest)aContext.Entity).FormulationMaterial;
var lSaveToSpecPref = DatabaseContext.RndvPref.FirstOrDefault(x => x.PREF_TP == aPrefTp && x.PREF_NAME == aPrefNameSaveToSpec && x.SEQ == 1).PREF_VALUE;
var userId = API.User.GetUser((decimal)aContext.Event.UserName).ID;
var rndtContact = DatabaseContext.RndvContact.FirstOrDefault(c => c.CONTACT == userId);
var userName = string.Join(" ", rndtContact.LAST_NAME, rndtContact.FIRST_NAME, rndtContact.MIDDLE_NAME);
SaveMaterialToSpecification(lMaterial, lSaveToSpecPref, (IRequest)aContext.Entity, userName);
}
public void SaveMaterialToSpecification(IFormulationMaterial aMaterial, string aSaveToSpecPref, IRequest aRequest, string userName)
{
// itereate through all the materials
foreach (var lMat in aMaterial.Materials)
SaveMaterialToSpecification(lMat, aSaveToSpecPref, aRequest, userName);
// check if aMaterial exists in db
RndvSp lSpec = DatabaseContext.RndvSp.FirstOrDefault(x => x.SP_VALUE == aMaterial.MaterialValue);
if (aMaterial.Specification == 0 || (aMaterial.ItemChanged == RnD.Common.Enums.NullableBool.True && aSaveToSpecPref == aCreateNewSpecPref))
{
var lMaterialNumber = aMaterial.MaterialValue;
decimal lFrameNumber = 0;
if (lSpec != null && aSaveToSpecPref == aCreateNewSpecPref)
{
lMaterialNumber = aSpecificationCodeMask.GetCodeMask();
aMaterial.MaterialValue = lMaterialNumber;
lFrameNumber = lSpec.FR;
}
if (lFrameNumber == 0)
{
var rndvPref = DatabaseContext.RndvPref.FirstOrDefault(x => x.PREF_TP == aPrefTp && x.PREF_NAME == aPrefNameFrameNumber && x.SEQ == 1);
lFrameNumber = Convert.ToDecimal(rndvPref?.PREF_VALUE);
}
var lFrames = DatabaseContext.RndvFr.Where(x => x.FR == lFrameNumber);
var lFrame = lFrames.ToList().FirstOrDefault(c => c.ACTIVE == RnD.Common.Enums.NullableBool.True);
if (lFrame == null)
{
Log.Warn($"Frame {lFrameNumber} is not active, cannot create a spec from it!");
return;
}
var newSpecification = API.Specification.CreateSpecification(lMaterialNumber, aMaterial.Description, lFrame.FR_VALUE, Convert.ToDecimal(lFrame.STYPE), lFrame.SP_LC, new List<Tuple<decimal, string>>());
aMaterial.ItemChanged = RnD.Common.Enums.NullableBool.False;
API.FormulaWorkbench.AutoPersistChanges = false;
API.FormulaWorkbench.LinkToSpecification(aMaterial, newSpecification);
API.FormulaWorkbench.AutoPersistChanges = true;
API.FormulaWorkbench.UpdateMaterials(aRequest);
API.FormulaWorkbench.SaveToSpecification(aMaterial);
DatabaseContext.SaveChanges();
#region Custom
var rndtBomHeader = DatabaseContext.RndvBomHeader.FirstOrDefault(c => c.SP == newSpecification.ID);
if (!(rndtBomHeader is null))
{
var rndtPref = DatabaseContext.RndvPref.FirstOrDefault(c => c.DESCRIPTION == "Preference for Unit when SaveToSpec");
if (!(rndtPref is null))
{
rndtBomHeader.UOM = rndtPref.PREF_VALUE;
}
var rndtRqLo = DatabaseContext.RndvRqLo.FirstOrDefault(c => c.RQ == aRequest.ID);
if (!(rndtRqLo is null))
{
rndtBomHeader.LO = (decimal)rndtRqLo.LO;
}
}
var attribute = newSpecification.Attributes.FirstOrDefault(c => c.ShortDescription == "Curator");
if (!(attribute is null))
{
attribute.Value = userName;
}
//var rndvFmMat = DatabaseContext.RndvFmMat.FirstOrDefault(c => c.RQ == aRequest.ID && c.SP == newSpecification.ID);
var rndvBomItems = DatabaseContext.RndvBomItem.Where(c => c.SP == newSpecification.ID);
var rndvFmCPs = DatabaseContext.RndvFmCPs.Where(c => c.RQ == aRequest.ID).ToList();
rndvFmCPs = rndvFmCPs.Where(c => c.MAT != DatabaseContext.RndvFmCPs.Min(x => x.MAT)).ToList();
foreach (var rndvBomItem in rndvBomItems)
{
var rndvFmMat = DatabaseContext.RndvFmMat.FirstOrDefault(c => c.ORDER == rndvBomItem.ITEM_NUMBER && c.RQ == aRequest.ID);
if (rndvFmMat is null) continue;
foreach (var rndvFmCP in rndvFmCPs)
{
if (rndvFmCP.MAT == rndvFmMat.UNIQUE_ID)
{
//var auDescription = string.Empty;
//var auSeq = 0;
if (rndvFmCP.PR_SEQ == 0)
{
rndvBomItem.MIN_QTY = (decimal)rndvFmCP.QUANTITY;
//auDescription = "MinAdmission";
//auSeq = 1;
}
else if (rndvFmCP.PR_SEQ == 1)
{
rndvBomItem.MAX_QTY = (decimal)rndvFmCP.QUANTITY;
//auDescription = "MaxAdmission";
//auSeq = 2;
}
else
{
continue;
}
//var rndvAu = DatabaseContext.RndvAu.ToList()
// .FirstOrDefault(c => c.SHORT_DESC == auDescription && c.ACTIVE == RnD.Common.Enums.NullableBool.True);
//var item = new RndvBomItemAu
//{
// SP = (decimal)newSpecification.ID,
// SP_VERSION = (decimal)newSpecification.Version,
// LO = rndvBomItem.LO,
// BOM_USAGE = rndvBomItem.BOM_USAGE,
// ITEM_NUMBER = rndvBomItem.ITEM_NUMBER,
// ICNODE = rndvBomItem.ICNODE,
// IINODE = rndvBomItem.IINODE,
// AU = rndvAu.AU,
// ALTERNATIVE = 1,
// AU_VERSION = rndvAu.VERSION,
// AUSEQ = auSeq,
// VALUE = $"{rndvFmCP.QUANTITY}"
//};
//DatabaseContext.RndvBomItemAu.Add(item);
}
}
}
DatabaseContext.SaveChanges();
#endregion
Log.Warn($"Specification {newSpecification.ID} created!");
}
else if (aMaterial.ItemChanged == RnD.Common.Enums.NullableBool.True && aSaveToSpecPref == aUpdateSpecPref)
{
aMaterial.ItemChanged = RnD.Common.Enums.NullableBool.False;
API.FormulaWorkbench.UpdateMaterials(aRequest);
API.FormulaWorkbench.SaveToSpecification(aMaterial);
Log.Warn($"Specification {aMaterial.Specification} updated!");
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DBBDB30D-7BD0-49C3-BC53-40A14700189A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AddToSpecification</RootNamespace>
<AssemblyName>AddToSpecification</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NLog">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\NLog.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RDnL.Logger">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RDnL.Logger.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnD.BusinessLayer.EF">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.BusinessLayer.EF.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnD.BusinessLayer.Interfaces">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.BusinessLayer.Interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnD.Common">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.Common.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnD.Customizations.API">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.Customizations.API.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnD.Customizations.Interfaces">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.Customizations.Interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnD.Model.EF">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.Model.EF.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnD.SubstitutionSyntax">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.SubstitutionSyntax.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnD.Uniconnect">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.Uniconnect.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RnDSuiteBackend">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnDSuiteBackend.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AddToSpecification.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SpecificationCodeMask.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AddToSpecification")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AddToSpecification")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dbbdb30d-7bd0-49c3-bc53-40a14700189a")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using RnD.API;
using RnD.Attributes;
using RnD.Model;
namespace Actions
{
[CustomFunction("Specification Code Mask", RnD.Common.Enums.CustomFunctionType.CodeMask, RnD.Common.Enums.CustomFunctionType.SpecificationCodeMask)]
public class SpecificationCodeMask : BaseCodeMask
{
public override string CodeMask { get; set; } = "SP{YYYY}{MM}{DD}-{DayCounter}";
public override bool LogHistory { get; set; } = true;
public SpecificationCodeMask(IAPI aAPI) : base(aAPI)
{
}
}
}
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\bin\Debug\AddToSpecification.dll
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\bin\Debug\AddToSpecification.pdb
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\obj\Debug\AddToSpecification.csproj.AssemblyReference.cache
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\obj\Debug\AddToSpecification.csproj.CoreCompileInputs.cache
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\obj\Debug\AddToSpecification.dll
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\obj\Debug\AddToSpecification.pdb
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\bin\Release\AddToSpecification.dll
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\bin\Release\AddToSpecification.pdb
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\obj\Release\AddToSpecification.csproj.AssemblyReference.cache
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\obj\Release\AddToSpecification.csproj.CoreCompileInputs.cache
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\obj\Release\AddToSpecification.dll
C:\Bryzgalov\Projects\AddToSpecification\AddToSpecification\obj\Release\AddToSpecification.pdb
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment