Work in Progress
parent
e0c98b87f4
commit
13fb6b577d
31
Parts.cs
31
Parts.cs
|
@ -1,37 +1,24 @@
|
|||
using System;
|
||||
using appsrv.attributes;
|
||||
using sharpwawi.models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace sharpwawi
|
||||
{
|
||||
public static class Parts
|
||||
public class Parts
|
||||
{
|
||||
[WebCallable]
|
||||
public static Part Create(){
|
||||
return new Part();
|
||||
}
|
||||
public WaWi WaWi { get; }
|
||||
|
||||
[WebCallable]
|
||||
public static Part ByKey(String key){
|
||||
return new Part();
|
||||
}
|
||||
|
||||
|
||||
static Part[] parts = CreateParts(10000);
|
||||
|
||||
static Part[] CreateParts(int count)
|
||||
public Parts(WaWi waWi)
|
||||
{
|
||||
Part[] parts = new Part[count];
|
||||
for (int n = 0; n < parts.Length; n++)
|
||||
parts[n] = new Part();
|
||||
return parts;
|
||||
WaWi = waWi;
|
||||
}
|
||||
|
||||
[WebCallable]
|
||||
public static Part[] TestParts()
|
||||
{
|
||||
return parts;
|
||||
public Part this[string key]{
|
||||
get => throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
35
WaWi.cs
35
WaWi.cs
|
@ -1,13 +1,46 @@
|
|||
using System;
|
||||
using appsrv.attributes;
|
||||
using sharpwawi.models;
|
||||
using mapper.configuration;
|
||||
|
||||
namespace sharpwawi
|
||||
{
|
||||
public static class WaWi
|
||||
public class WaWi
|
||||
{
|
||||
public readonly Parts Parts;
|
||||
|
||||
|
||||
Configuration mapperConfiguration;
|
||||
|
||||
|
||||
public WaWi()
|
||||
{
|
||||
Parts = new Parts(this);
|
||||
|
||||
PrepareMapper();
|
||||
}
|
||||
|
||||
private void PrepareMapper()
|
||||
{
|
||||
mapperConfiguration = new Configuration()
|
||||
.AddClass(typeof(Entity))
|
||||
.AddClass(typeof(Part))
|
||||
.AddClass(typeof(Assembly))
|
||||
.AddClass(typeof(AssemblyComponent));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[WebCallable]
|
||||
public static String Version { get; } = "V0.0.1";
|
||||
|
||||
[WebCallable]
|
||||
public static String CurrentTime => DateTime.Now.ToString();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace sharpwawi.models
|
||||
{
|
||||
public class Assembly
|
||||
{
|
||||
public Part Part { get; private set; }
|
||||
public int Revision { get; private set; }
|
||||
|
||||
IList<AssemblyComponent> components = new List<AssemblyComponent>();
|
||||
|
||||
protected Assembly()
|
||||
{
|
||||
}
|
||||
|
||||
internal Assembly(Part part)
|
||||
{
|
||||
Part = part;
|
||||
Revision = part.HighestAssemblyRevision + 1;
|
||||
}
|
||||
|
||||
public int Count => components.Count;
|
||||
public AssemblyComponent this[int n] => components[n];
|
||||
|
||||
public AssemblyComponent this[Part component]{
|
||||
get {
|
||||
foreach (AssemblyComponent assemblyComponent in components)
|
||||
{
|
||||
if (assemblyComponent.Component.Equals(component))
|
||||
return assemblyComponent;
|
||||
}
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsComponent(Part component){
|
||||
foreach (AssemblyComponent assemblyComponent in components){
|
||||
if (assemblyComponent.Component.Equals(component))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Assembly Clone(){
|
||||
Assembly clone = Part.CreateAssembly();
|
||||
|
||||
foreach (AssemblyComponent assemblyComponent in components)
|
||||
clone.AddComponent(assemblyComponent.Component, assemblyComponent.Quantity);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a qunatity of a component to the Assembly.
|
||||
* Returns true if the component is new to the assembly, false if just the quantity changed
|
||||
*
|
||||
**/
|
||||
public bool AddComponent(Part component, double quantity)
|
||||
{
|
||||
if (ContainsComponent(component))
|
||||
{
|
||||
this[component].Quantity += quantity;
|
||||
return false;
|
||||
} else {
|
||||
components.Add(new AssemblyComponent(this, component, quantity));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveComponent(AssemblyComponent component)
|
||||
{
|
||||
components.Remove(component);
|
||||
}
|
||||
public void RemoveComponent(Part component){
|
||||
RemoveComponent(this[component]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
namespace sharpwawi.models
|
||||
{
|
||||
public class AssemblyComponent
|
||||
{
|
||||
public Assembly Assembly { get; private set; }
|
||||
public Part Component { get; private set; }
|
||||
public double Quantity { get; set; }
|
||||
|
||||
public AssemblyComponent()
|
||||
{
|
||||
}
|
||||
|
||||
public AssemblyComponent(Assembly assembly,Part component, double quantity)
|
||||
{
|
||||
this.Assembly = assembly;
|
||||
this.Component = component;
|
||||
this.Quantity = quantity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Assembly.GetHashCode() ^ Component.GetHashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals()
|
||||
*
|
||||
* check if an AssemblyComponent instance describes the same Part as Component of an Assembly
|
||||
* Differenting Quantities are ignored!
|
||||
*
|
||||
**/
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is AssemblyComponent)
|
||||
{
|
||||
AssemblyComponent other = (AssemblyComponent)obj;
|
||||
return Assembly.Equals(other.Assembly) && Component.Equals(other.Component);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -17,6 +17,12 @@ namespace sharpwawi.models
|
|||
Name = "unnamed entity";
|
||||
Description = "";
|
||||
}
|
||||
public Entity(String key,String name)
|
||||
{
|
||||
Key = key;
|
||||
Name = name;
|
||||
Description = "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,23 +1,35 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace sharpwawi.models
|
||||
{
|
||||
public class Part : Entity
|
||||
{
|
||||
static Random random = new Random();
|
||||
public ISet<Assembly> Assemblies { get; private set; } = new HashSet<Assembly>();
|
||||
|
||||
public Part()
|
||||
{
|
||||
Key = String.Format("P{0:0######}",random.Next() % 10000000);
|
||||
}
|
||||
|
||||
public int NextRandom()
|
||||
public Part(String key,String name)
|
||||
:base(key,name)
|
||||
{
|
||||
return random.Next();
|
||||
}
|
||||
|
||||
public String Enhance(int n)
|
||||
{
|
||||
return string.Format("ENH({0})", n);
|
||||
public int HighestAssemblyRevision {
|
||||
get {
|
||||
int highest = 0;
|
||||
foreach (Assembly assembly in Assemblies)
|
||||
if (assembly.Revision > highest)
|
||||
highest = assembly.Revision;
|
||||
return highest;
|
||||
}
|
||||
}
|
||||
|
||||
public Assembly CreateAssembly(){
|
||||
Assembly assembly = new Assembly(this);
|
||||
Assemblies.Add(assembly);
|
||||
return assembly;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace sharpwawi.models.stock
|
||||
{
|
||||
public class StockLocation
|
||||
{
|
||||
StockLocation location;
|
||||
public StockLocation Location => location;
|
||||
|
||||
string name;
|
||||
public String Name { get => name; set => name = value; }
|
||||
|
||||
|
||||
List<StockLocation> containingLocations = new List<StockLocation>();
|
||||
|
||||
protected StockLocation()
|
||||
{
|
||||
}
|
||||
|
||||
protected StockLocation(string name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public StockLocation(StockLocation location,String name)
|
||||
:this(name)
|
||||
{
|
||||
this.location = location;
|
||||
this.location.AddContainedLocation(this);
|
||||
}
|
||||
|
||||
public int LocatorLevel
|
||||
{
|
||||
get {
|
||||
if (location == null)
|
||||
return 0;
|
||||
return location.LocatorLevel + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public String Locator
|
||||
{
|
||||
get {
|
||||
if (location != null)
|
||||
return String.Format("{0}/{1}", location.Locator, name);
|
||||
else
|
||||
return String.Format("/{0}", name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void AddContainedLocation(StockLocation containedLocation)
|
||||
{
|
||||
containingLocations.Add(containedLocation);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
namespace sharpwawi.models.stock
|
||||
{
|
||||
public class StockShelf : StockLocation
|
||||
{
|
||||
public Part Part { get; set; }
|
||||
public double Quantity { get; set; }
|
||||
|
||||
protected StockShelf()
|
||||
{
|
||||
}
|
||||
|
||||
public StockShelf(StockLocation stockLocation,String name)
|
||||
:base(stockLocation,name)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
namespace sharpwawi.models.stock
|
||||
{
|
||||
public class WareHouse : StockLocation
|
||||
{
|
||||
protected WareHouse()
|
||||
{
|
||||
}
|
||||
|
||||
public WareHouse(String name)
|
||||
:base(name)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -28,6 +28,9 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Transactions" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
@ -35,11 +38,17 @@
|
|||
<Compile Include="Parts.cs" />
|
||||
<Compile Include="models\Part.cs" />
|
||||
<Compile Include="models\Entity.cs" />
|
||||
<Compile Include="models\stock\StockLocation.cs" />
|
||||
<Compile Include="models\stock\StockShelf.cs" />
|
||||
<Compile Include="models\stock\WareHouse.cs" />
|
||||
<Compile Include="models\Assembly.cs" />
|
||||
<Compile Include="models\AssemblyComponent.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="www\" />
|
||||
<Folder Include="models\" />
|
||||
<Folder Include="www\articles\" />
|
||||
<Folder Include="models\stock\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="www\index.hfrm">
|
||||
|
@ -69,6 +78,10 @@
|
|||
<Project>{FD508FE5-5879-4C60-91D8-CA408E06361F}</Project>
|
||||
<Name>sharp-application-server</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\sharp-mapper\sharp-mapper.csproj">
|
||||
<Project>{3933EA69-8110-49A0-8D01-9C7A5176E9A1}</Project>
|
||||
<Name>sharp-mapper</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Loading…
Reference in New Issue