I didnt spend too much time on it… Here is quick way
PS: Code does not follow best practices such as row rules what not… just quick dirty.
// **************************************************
// Custom code for TimePhasForm
// Created: 12/4/2017 9:09:10 AM
//
extern alias Erp_Contracts_BO_PartPlantSearch;
extern alias Erp_Contracts_BO_Part;
extern alias Ice_Adapters_DynamicReport;
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 Infragistics.Win.UltraWinGrid;
using System.Drawing;
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 edvTimePhas;
private EpiDataView edvPartPlant;
private EpiDataView edvPart;
private EpiDataView edvMisc;
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
DataTable allOrders;
DataTable allJobs;
DataTable allPOs;
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
this.edvTimePhas = ((EpiDataView)(this.oTrans.EpiDataViews["TimePhas"]));
this.edvTimePhas.EpiViewNotification += new EpiViewNotification(this.edvTimePhas_EpiViewNotification);
this.edvPartPlant = ((EpiDataView)(this.oTrans.EpiDataViews["PartPlant"]));
this.edvPartPlant.EpiViewNotification += new EpiViewNotification(this.edvPartPlant_EpiViewNotification);
this.edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
this.edvPart.EpiViewNotification += new EpiViewNotification(this.edvPart_EpiViewNotification);
this.edvMisc = ((EpiDataView)(this.oTrans.EpiDataViews["Misc"]));
this.edvMisc.EpiViewNotification += new EpiViewNotification(this.edvMisc_EpiViewNotification);
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
InitializeBAQData();
// 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.edvTimePhas.EpiViewNotification -= new EpiViewNotification(this.edvTimePhas_EpiViewNotification);
this.edvTimePhas = null;
this.edvPartPlant.EpiViewNotification -= new EpiViewNotification(this.edvPartPlant_EpiViewNotification);
this.edvPartPlant = null;
this.edvPart.EpiViewNotification -= new EpiViewNotification(this.edvPart_EpiViewNotification);
this.edvPart = null;
this.edvMisc.EpiViewNotification -= new EpiViewNotification(this.edvMisc_EpiViewNotification);
this.edvMisc = null;
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void TimePhasForm_Load(object sender, EventArgs args)
{
// Add Event Handler Code
TimePhasForm.Text = TimePhasForm.Text + " 21.11.10";
EpiCheckBox chkSugs = (EpiCheckBox)csm.GetNativeControlReference("cdf4e0c8-4643-4c8b-9aaf-a53c47ce9985");
EpiCheckBox chkTrns = (EpiCheckBox)csm.GetNativeControlReference("7ceb719a-f574-4989-bf03-18263d5719f4");
EpiCheckBox chkPlan = (EpiCheckBox)csm.GetNativeControlReference("7f8e2894-a0c1-4ce6-a392-7bd7fc1faba0");
chkSugs.Checked = false;
chkTrns.Checked = false;
chkPlan.Checked = false;
// Allows it to work with Open With...
if (oTrans.CurrentPart != string.Empty) {
oTrans.Refresh();
}
}
// Will load data and store it in memory
private void InitializeBAQData()
{
using (DynamicQueryAdapter adDynamic = new DynamicQueryAdapter(this.oTrans))
{
adDynamic.BOConnect();
Ice.BO.QueryExecutionDataSet parameters = new Ice.BO.QueryExecutionDataSet();
adDynamic.ExecuteByID("CODE-TPI-AllOrders", parameters);
allOrders = adDynamic.QueryResults.Tables[0].Copy();
adDynamic.ExecuteByID("CODE-TPI-AllJobs", parameters);
allJobs = adDynamic.QueryResults.Tables[0].Copy();
adDynamic.ExecuteByID("CODE-TPI-AllPOs", parameters);
allPOs = adDynamic.QueryResults.Tables[0].Copy();
}
}
private void UpdateFields()
{
if (edvTimePhas.dataView.Table.Rows.Count <= 0)
{
return;
}
// Only Add Columns back if they dont exist
if (!edvTimePhas.dataView.Table.Columns.Contains("ProjectID"))
{
DataColumn dcProject = new DataColumn("ProjectID");
edvTimePhas.dataView.Table.Columns.Add(dcProject);
DataColumn dcBlanket = new DataColumn("Blanket Order");
edvTimePhas.dataView.Table.Columns.Add(dcBlanket);
EpiUltraGrid grdTimePhas = (EpiUltraGrid)csm.GetNativeControlReference("7908565c-cc3c-43d1-b85b-9921ad88fb89");
for (int i = 0; i < grdTimePhas.DisplayLayout.Bands[0].Columns.Count; i++) grdTimePhas.DisplayLayout.Bands[0].Columns[i].CellActivation = Activation.NoEdit;
grdTimePhas.DisplayLayout.Bands[0].Columns["Blanket Order"].Hidden = true;
grdTimePhas.DisplayLayout.Bands[0].Columns["ProjectID"].Header.VisiblePosition = 8;
}
using (DynamicQueryAdapter adDynamic = new DynamicQueryAdapter(TimePhasForm))
{
adDynamic.BOConnect();
foreach (DataRow tp in edvTimePhas.dataView.Table.Rows)
{
if (tp["ProjectID"].ToString() != string.Empty)
{
continue;
}
if (tp["PONum"].ToString() != string.Empty && tp["PONum"].ToString() != "0")
{
string where = string.Format("PORel_PONum = {0} AND PORel_POLine = {1} AND PORel_PORelNum = {2}", tp["PONum"].ToString(), tp["POLine"].ToString(), tp["PORelNum"].ToString());
DataRow[] rows = allPOs.Select(where, "PORel_PONum ASC");
if (rows != null)
{
tp["ProjectID"] = rows[0]["PORel_ProjectID"];
}
}
else if (tp["JobNum"].ToString() != string.Empty)
{
string where = string.Format("JobHead_JobNum = '{0}'", tp["JobNum"].ToString());
DataRow[] rows = allJobs.Select(where, "JobHead_JobNum ASC");
if (rows != null)
{
tp["ProjectID"] = rows[0]["JobHead_ProjectID"];
}
}
else if (tp["OrderNum"].ToString() != string.Empty && tp["OrderNum"].ToString() != "0")
{
string where = string.Format("OrderDtl_OrderNum = {0} AND OrderDtl_OrderLine = {1}", tp["OrderNum"].ToString(), tp["OrderLine"].ToString());
DataRow[] rows = allOrders.Select(where, "OrderDtl_OrderNum ASC");
if (rows != null)
{
tp["ProjectID"] = rows[0]["OrderDtl_ProjectID"];
tp["Blanket Order"] = rows[0]["OrderHed_CheckBox03"];
}
}
}
}
EpiUltraGrid grdTimePhas2 = (EpiUltraGrid)csm.GetNativeControlReference("7908565c-cc3c-43d1-b85b-9921ad88fb89");
foreach (Infragistics.Win.UltraWinGrid.UltraGridRow line in grdTimePhas2.Rows)
{
if (line.Cells["Blanket Order"].Value != DBNull.Value && Convert.ToBoolean(line.Cells["Blanket Order"].Value))
{
line.Appearance.BackColor = Color.Yellow;
line.Appearance.BackColorDisabled = Color.Yellow;
line.CellAppearance.BackColor = Color.Yellow;
line.CellAppearance.BackColorDisabled = Color.Yellow;
}
}
}
private void edvPartPlant_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 && args.Row > -1 && args.BruteForce == false)
{
UpdateFields();
}
}
private void edvPart_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.Row > -1))
{
// UpdateFields();
}
}
private void edvTimePhas_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 && args.Row > -1 && args.ReEvaluateRowRules == true)
{
UpdateFields();
}
}
private void edvMisc_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 && args.Row > -1 && args.BruteForce == false)
{
if (args.Sender is EpiCheckBox && oTrans.CurrentPart != string.Empty)
{
UpdateFields();
}
}
}
}