Hi
Please can somebody put me out of my misery - I’ve tried multiple ways to get this working, and I give up!
Basically inside the method btnPrintPartLabel_Click, I would like to get data from the Part record. I wish to get the value from Part.EngPartCat_c and Part.EngPartSubCat_c. With current code, I get no errors on compile or runtime but the sCategory variable always remains blank.
Many Thanks
Mark
// **************************************************
// Custom code for InventoryQtyAdjustForm
// Created: 18/08/2017 14:39:46
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Erp.BO;
using Ice.BO;
using System.Text;
public class Script
{
// ** Wizard Insert Location - Do Not Remove ‘Begin/End Wizard Added Module Level Variables’ Comments! **
// Begin Wizard Added Module Level Variables **
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
private EpiDataView edvPart;
private PartAdapter partAD ;
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
this.btnPrintBinLabel.Click += new System.EventHandler(this.btnPrintBinLabel_Click);
this.btnPrintPartLabel.Click += new System.EventHandler(this.btnPrintPartLabel_Click);
EpiDataView edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
edvPart.dataView.Table.Columns.Add("Category");
edvPart.dataView.Table.Columns.Add("SubCategory", typeof(string));
//partAD = new PartAdapter( oTrans ) ;
//partAD.BOConnect() ;
// End Wizard Added Custom Method Calls
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
this.btnPrintBinLabel.Click -= new System.EventHandler(this.btnPrintBinLabel_Click);
this.btnPrintPartLabel.Click -= new System.EventHandler(this.btnPrintPartLabel_Click);
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
this.edvPart = null;
//partAD.Dispose() ;
partAD = null ;
// End Custom Code Disposal
}
private void btnPrintBinLabel_Click(object sender, System.EventArgs args)
{
string [] Lines = new string [4];
string FileName = string.Empty;
string LabelPrinter = "";
string LabelReport = "EngineeringBinLabel.btw";
string OutputPath = @"\\EpicorAPP01\BarTender\Commander\EngineeringBin\";
DateTime cNow = DateTime.Now;
EpiCombo cmbWhse = (EpiCombo)csm.GetNativeControlReference("17fd807c-51fc-431c-a72c-e300fb8208ac");
EpiTextBox txtBinNum = (EpiTextBox)csm.GetNativeControlReference("5a5538e6-53a1-4cc4-8de5-569c6b8e70c1");
EpiTextBox txtDescription = (EpiTextBox)csm.GetNativeControlReference("a030367f-9dbd-4b73-9efc-e39ef8628478");
string sWhse = cmbWhse.Text;
string sBinNum = txtBinNum.Text;
string sDescription = txtDescription.Text;
if(sWhse != "Engineering Stock")
{
EpiMessageBox.Show("Only intended for Engineering Parts");
return;
}
FileName = OutputPath + "EngBinLabel" + cNow.ToString ("_yyyy-MM-dd_HHmmss") + ".bt";
LabelPrinter = @"\\BV-PC-001\DYMO";
using (var OutFile = new System.IO.StreamWriter(new System.IO.FileStream(FileName,System.IO.FileMode.Create)))
{
Lines[0] = "%BTW% ";
Lines[0] = Lines [0] + "/AF=\"" ;
Lines[0] = Lines [0] + @"\\epicorapp01\BarTender\Commander\EngineeringBin\" + LabelReport +"\"";
Lines[0] = Lines [0] + @" /D=""<Trigger File Name>"" /PRN=";
Lines[0] = Lines [0] + "\"" + LabelPrinter + "\"";
Lines[0] = Lines [0] + @" /DBTEXTHEADER=3 /R=3 /P";
Lines[1] = "%END%";
Lines[2] = "\"BinNum\",\"Description\"";
StringBuilder sb = new StringBuilder();
if (sBinNum.IndexOfAny(new char[] { '"', ',' }) != -1)
sb.AppendFormat("\"{0}\"", sBinNum.Replace("\"", "\"\""));
else
sb.Append(sBinNum);
sb.Append(",");
if (sDescription.IndexOfAny(new char[] { '"', ',' }) != -1)
sb.AppendFormat("\"{0}\"", sDescription.Replace("\"", "\"\""));
else
sb.Append(sDescription);
Lines[3] = sb.ToString();
OutFile.WriteLine(Lines[0]);
OutFile.WriteLine(Lines[1]);
OutFile.WriteLine(Lines[2]);
OutFile.WriteLine(Lines[3]);
}
}
private void btnPrintPartLabel_Click(object sender, System.EventArgs args)
{
string [] Lines = new string [4];
string FileName = string.Empty;
string LabelPrinter = "";
string LabelReport = "EngineeringPartLabel.btw";
string OutputPath = @"\\EpicorAPP01\BarTender\Commander\EngineeringPart\";
DateTime cNow = DateTime.Now;
EpiTextBox txtPartNum = (EpiTextBox)csm.GetNativeControlReference("138c27f2-8793-4d33-bb53-e1f5a753909a");
EpiTextBox txtDescription = (EpiTextBox)csm.GetNativeControlReference("f59e7876-bacd-4314-b354-bae4f83ebf9c");
string sPartNum = txtPartNum.Text;
string sDescription = txtDescription.Text;
string sCategory = string.Empty;
// Check if the Part is an Engineering part, if not then return
if(sPartNum.Length < 3)
{
EpiMessageBox.Show("Only intended for Engineering Parts");
return;
}
string First3Letters = sPartNum.Substring(0, 3);
if(First3Letters != "ENG")
{
EpiMessageBox.Show("Only intended for Engineering Parts");
return;
}
// Lookup Part Eng Category, and add into dataView
partAD = new PartAdapter( oTrans ) ;
partAD.BOConnect() ;
try
{
partAD.ClearData() ;
partAD.GetByID(sPartNum);
edvPart.dataView[0]["Category"] = partAD.PartData.Part[0]["EngPartCat_c"] ;
//sCategory = edvPart.dataView[0]["EngPartCat_c"].ToString();
sCategory = partAD.PartData.Part[0]["AnalysisCode"].ToString();
}
catch (Exception ex)
{
}
partAD.Dispose() ;
partAD = null ;
EpiMessageBox.Show("cat = " + sCategory);
//EpiCombo txtCategory = (EpiCombo)csm.GetNativeControlReference("fc9a3fb0-dd3f-4d09-9d65-724d41f1c4e2");
//BAQCombo txtSubCategory = (BAQCombo)csm.GetNativeControlReference("50be7f9f-96ec-489c-8457-9f81078443ea");
//string sSubCategory = txtSubCategory.Text;
FileName = OutputPath + "EngPartLabel" + cNow.ToString ("_yyyy-MM-dd_HHmmss") + ".bt";
LabelPrinter = @"\\BV-PC-001\DYMO";
/*using (var OutFile = new System.IO.StreamWriter(new System.IO.FileStream(FileName,System.IO.FileMode.Create)))
{
Lines[0] = "%BTW% ";
Lines[0] = Lines [0] + "/AF=\"" ;
Lines[0] = Lines [0] + @"\\epicorapp01\BarTender\Commander\EngineeringPart\" + LabelReport +"\"";
Lines[0] = Lines [0] + @" /D=""<Trigger File Name>"" /PRN=";
Lines[0] = Lines [0] + "\"" + LabelPrinter + "\"";
Lines[0] = Lines [0] + @" /DBTEXTHEADER=3 /R=3 /P";
Lines[1] = "%END%";
Lines[2] = "\"PartNum\",\"Description\",\"Category\",\"SubCategory\"";
StringBuilder sb = new StringBuilder();
if (sPartNum.IndexOfAny(new char[] { '"', ',' }) != -1)
sb.AppendFormat("\"{0}\"", sPartNum.Replace("\"", "\"\""));
else
sb.Append(sPartNum);
sb.Append(",");
if (sDescription.IndexOfAny(new char[] { '"', ',' }) != -1)
sb.AppendFormat("\"{0}\"", sDescription.Replace("\"", "\"\""));
else
sb.Append(sDescription);
sb.Append(",");
if (sCategory.IndexOfAny(new char[] { '"', ',' }) != -1)
sb.AppendFormat("\"{0}\"", sCategory.Replace("\"", "\"\""));
else
sb.Append(sCategory);
sb.Append(",");
if (sSubCategory.IndexOfAny(new char[] { '"', ',' }) != -1)
sb.AppendFormat("\"{0}\"", sSubCategory.Replace("\"", "\"\""));
else
sb.Append(sSubCategory);
Lines[3] = sb.ToString();
OutFile.WriteLine(Lines[0]);
OutFile.WriteLine(Lines[1]);
OutFile.WriteLine(Lines[2]);
OutFile.WriteLine(Lines[3]);
}*/
}
}