Display a part image in a customization - Example Video

Here’s an example video of displaying a part image in a dashboard customization. The same idea can be applied to any screen or image type.


And of course the code:


public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	private EpiDataView edvV_PartImage_1View;
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	Erp.Adapters.ImageAdapter imageAdapter;

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.edvV_PartImage_1View = ((EpiDataView)(this.oTrans.EpiDataViews["V_PartImage_1View"]));
		this.edvV_PartImage_1View.EpiViewNotification += new EpiViewNotification(this.edvV_PartImage_1View_EpiViewNotification);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls

		imageAdapter = new Erp.Adapters.ImageAdapter(oTrans);
		imageAdapter.BOConnect();
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		this.edvV_PartImage_1View.EpiViewNotification -= new EpiViewNotification(this.edvV_PartImage_1View_EpiViewNotification);
		this.edvV_PartImage_1View = null;
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal
		imageAdapter.Dispose();
		imageAdapter = null;
		// End Custom Code Disposal
	}

	private void edvV_PartImage_1View_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
		{
			if ((args.Row > -1))
			{
				var imageBytes = imageAdapter.GetOriginalImage(view.dataView[args.Row]["Image_ImageID"].ToString());
                System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBytes);
				partIb.Image = System.Drawing.Image.FromStream(ms);
			}
		}
	}
2 Likes

Thanks great video! :grinning:

But I guess I was looking for (and maybe also for the BAQreports) is that the thumbnail of the image be able to be a BAQ column…

Like add an image field to the BAQ ? so the images get shown on each line, not by clicking a line and show then the image…(but thanks it is a good start! ) So the reporting could use this as well… (like a report showing customer parts list with their pictures in a dashboard, or printed)

Pierre

Pierre

Maybe the Image Column wizard could create the foundation, and some custom code would replace the image with one from the file referenced.

There are two ways to get it into a BAQ report.

The easy way is to make a subreport that uses a data source that reads from the database directly. You could pass the subreport the image id and have it display the part image. The great thing about this method is it’s a generic subreport that can be reused any place you wanted to display an image like travelers or employee badges.

The other approach is to add a calculated field to the baq and append the image data to the filed in a GetList post process directive. Something like this:

            using (var imageSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ImageSvcContract>(Db))
            {
                var resultDt = result.Tables["Results"];
                foreach (DataRow row in resultDt.Rows)
                {
                    row["Calculated_ImageContent"] = Convert.ToBase64String(imageSvc.GetOriginalImage(row["Image_ImageID"].ToString()));

                }

            }

image

1 Like