Example
- Last UpdatedAug 18, 2016
- 1 minute read
The following C# sample code illustrates how to define, query, and use the wwMaterialUnits object.
The example populates a list of ingredients and then populates a list with units to which the material has been assigned whenever an item is selected in the list of ingredients. The global variables are defined so that they are available throughout the entire program.
private void SetUnitNames()
{
UnitsLsb.Items.Clear();
AvaliableUnitsLsb.Hide();
CancelBtn.Hide();
wwMaterialUnits LocMatUnits;
LocMatUnits = GetMatUnits();
if (LocMatUnits == null)
return;
for (int ut = 1; ut <= LocMatUnits.Count; ut++)
{
MatUnit = (wwMaterialUnit)LocMatUnits.Item(ut);
UnitsLsb.Items.Add(MatUnit.UnitName);
}
if (UnitsLsb.Items.Count > 0)
UnitsLsb.SelectedIndex = 0;
MaterialIdTxt.Text = MatStatus.GetMaterialId();
}
private wwMaterialUnits GetMatUnits()
{
wwMaterialUnits MatUnits=null;
if (MatStatus.GetMaterialType() == "Ingradiants")
mdbc.QueryMaterialsByType(wwMtrlTypeEnum.wwTypeIngredient);
if (MatStatus.GetMaterialType() == "Finished Goods")
mdbc.QueryMaterialsByType(wwMtrlTypeEnum.wwTypeFinishedGood); if (MatStatus.GetMaterialType() == "Intermediates") mdbc.QueryMaterialsByType(wwMtrlTypeEnum.wwTypeIntermediate);
if (MatStatus.GetMaterialType() == "Other products")
mdbc.QueryMaterialsByType(wwMtrlTypeEnum.wwTypeOther);
if (MatStatus.GetMaterialType() == "All") mdbc.QueryMaterialsByType(wwMtrlTypeEnum.wwTypeAll);
mdbc.QueryMaterialsById("r00-454-4545")
mats = (wwMaterials)mdbc.Materials;
if (mats.Count != 0)
{
Material = (wwMaterial)mats.Item(1);
Material.QueryMaterialUnits();
MatUnits = (wwMaterialUnits)Material.MaterialUnits;
}
return MatUnits;}