Hybrids
Hybrids are set in the Save() method of the BusinessObject. Hybrids should be using the proper HybridType-class .
For creating a new Hybrid class, the next steps should be followed (Example class: ART):
Add a new Hybrid value, in the HybridType-class
public enum HybridType
{
BEL,
PERS,
ART,
//....
}
Create a new class HybridName, extending HybridBase, in the Hybrid class
public class HybridArt : HybridBase
{
private DataRow row;
private DataRow Rows;
{
get
{
if (row != null)
return row; // cached
var dt = Sql.SelectTable("select * from art where hybrid = '{0}'", this.Hybrid);
if (dt.Rows.Count > 0)
row = dt.Rows[0]; // cache it
return row;
}
}
public string ArtNr { get; private set; }
public override string InfoModuleId { get { return "modInfoArt"; } }
public HybridArt()
{ }
public HybridArt(string value)
: base(value)
{
if (this.Type != HybridType.ART)
throw new ArgumentException(string.Format("Hybrid type is invalid. Actual value: {0}, expected value: {1}", this.Type.ToString(), HybridType.ART.ToString()));
ArtNr = this.Keys[0].ToString();
}
public static HybridArt FromBarcode39Hybrid(string barcode39Hybrid)
{
return new HybridArt(barcode39Hybrid.Replace(Constants.HybridSeparatorInCode39, Framework.Constants.HybridSeparator, count: 1));
}
public override DataRow GetRow()
{
return Row;
}
public override string GetSearchString()
{
return Row != null
? Row["suchwort"].ToString()
: null;
}
}
Add hybrid-type to HybridExtensions
First in the GetHybrid-Method
public static HybridBase GetHybrid(string hybrid)
{
if (string.IsNullOrWhiteSpace(hybrid))
throw new ArgumentNullException("hybrid");
hybrid = FixHybrid(hybrid);
var hybridType = GetHybridType(hybrid);
switch (hybridType)
{
case HybridType.ART: return new HybridArt(hybrid);
case HybridType.BEL: return new HybridBel(hybrid);
case HybridType.PERS: return new HybridPers(hybrid);
//....
}
//....
}
Then in the ConvertBarcode39Hybrid -Method
public static string ConvertBarcode39Hybrid(string code39Hybrid)
{
if (string.IsNullOrEmpty(code39Hybrid))
throw new ArgumentNullException("code39Hybrid");
var hybridType = GetHybridType(code39Hybrid, Constants.HybridSeparatorInCode39);
switch (hybridType)
{
case HybridType.ART:
return HybridArt.FromBarcode39Hybrid(code39Hybrid).ToString();
case HybridType.BEL:
return HybridBel.FromBarcode39Hybrid(code39Hybrid).ToString();
case HybridType.PERS:
return HybridPers.FromBarcode39Hybrid(code39Hybrid).ToString();
//....
}
return null;
}
The hybrid can be obtained using the Get() method from the HybridType-class, as followed:
protected virtual void FillPKs()
{
// qs_fehlerlog
foreach (var newRow in tSet.qs_fehlerlog)
{
// fill-in PK = nr
if (newRow.IsnrNull())
{
newRow.nr = ParaUtils.GetNextQSFehlerlogNr(1);
}
// set hybrid
switch (newRow.verurs_typ)
{
case 30: //Material = Artikel
newRow.verurs_hybrid = HybridType.ART.Get(newRow.cf_verursacher);
break;
}
//....
}
}
Last updated