Programmer Item Maintenance: Item Batch Table OnColumnChange event v2: Difference between revisions
Content added Content deleted
(Created page with " ==Version Info== *AutoCount Accounting 2.0 *Tested version: 2.0.1.100 ==Introduction== In Item Maintenance, when changes is made to the form, two events below will be trigge...") |
mNo edit summary |
||
Line 15: | Line 15: | ||
==Sample code to add events to Item Batch table== |
==Sample code to add events to Item Batch table== |
||
This sample code illustrates how programmer can locate the DataTable of Item Batch. |
This sample code illustrates how programmer can locate the DataTable of Item Batch.<br/> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
<syntaxhighlight lang="csharp"> |
<syntaxhighlight lang="csharp"> |
||
public void OnFormInitialize(object sender, AutoCount.Stock.Item.FormStockItem.LayoutFormInitializeEventArgs e) |
public void OnFormInitialize(object sender, AutoCount.Stock.Item.FormStockItem.LayoutFormInitializeEventArgs e) |
||
Line 26: | Line 26: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
===Create the event OnColumnChanged for Item Batch=== |
|||
<syntaxhighlight lang="csharp" highlight="1, 34"> |
<syntaxhighlight lang="csharp" highlight="1, 34"> |
||
private void TblItemBatch_ColumnChanged(object sender, DataColumnChangeEventArgs e) |
private void TblItemBatch_ColumnChanged(object sender, DataColumnChangeEventArgs e) |
Revision as of 09:17, 16 July 2018
Version Info
- AutoCount Accounting 2.0
- Tested version: 2.0.1.100
Introduction
In Item Maintenance, when changes is made to the form, two events below will be triggered
public void OnItemColumnChanged(AutoCount.Stock.Item.StockItemColumnChangedEventArgs e)
public void OnItemUomColumnChanged(AutoCount.Stock.Item.StockItemUomColumnChangedEventArgs e)
However, these two events that are provided for the value changed of the column is for "Master" and "Detail" tables.
Item Batch data is not held in these two tables.
Therefore, to capture the changes of Item Batch table, programmer needs to add the OnColumnChanged event to the Item Batch table.
Sample code to add events to Item Batch table
This sample code illustrates how programmer can locate the DataTable of Item Batch.
And create OnColumnChanged event when it successfully finding the Item Batch Table.
Add the event at Item Maintenance Form Initialize
public void OnFormInitialize(object sender, AutoCount.Stock.Item.FormStockItem.LayoutFormInitializeEventArgs e)
{
CreateItemBatchTableColumnChangedEvent(e);
}
Create the event OnColumnChanged for Item Batch
private void TblItemBatch_ColumnChanged(object sender, DataColumnChangeEventArgs e)
{
if (e.Column.ColumnName == "BatchNo")
{
if (e.ProposedValue.Equals("") || e.ProposedValue.Equals(DBNull.Value))
{
//Do something when BatchNo is empty
return;
}
else
{
//Do something when BatchNo is not empty
AutoCount.AppMessage.ShowMessage(
string.Format("BatchNo is changed to {0}.\nDescription:{1}",
e.ProposedValue, e.Row["Description"]));
}
}
}
//Method Entry Point
private void CreateItemBatchTableColumnChangedEvent(AutoCount.Stock.Item.FormStockItem.LayoutFormInitializeEventArgs e)
{
DevExpress.XtraGrid.GridControl gcItemBatch = GetItemBatchGridControl(e);
if (gcItemBatch == null || gcItemBatch.DataSource == null)
{
AutoCount.AppMessage.ShowMessage("Fail to add Column Change to ItemBatch");
return;
}
else if (gcItemBatch.DataSource is DataTable)
{
DataTable tblItemBatch = gcItemBatch.DataSource as DataTable;
//Create Item Batch Table event
tblItemBatch.ColumnChanged += TblItemBatch_ColumnChanged;
}
else
{
AutoCount.AppMessage.ShowMessage("Fail to add Column Change to ItemBatch");
}
}
Find the GridControl in the TabPage of e.TabControlMaster
private DevExpress.XtraGrid.GridControl GetItemBatchGridControl(AutoCount.Stock.Item.FormStockItem.LayoutFormInitializeEventArgs e)
{
DevExpress.XtraLayout.LayoutGroup grpTabItemBatch = null;
DevExpress.XtraLayout.LayoutControlItem layoutItemBatch = null;
string findTabPageName = "lygItemBatch";
//Find the TabPage of "Item Batch"
for (int i = 1; i < e.TabControlMaster.TabPages.Count; i++)
{
if (e.TabControlMaster.TabPages[i].Name == findTabPageName)
{
grpTabItemBatch = e.TabControlMaster.TabPages[i];
}
}
if (grpTabItemBatch == null)
{
AutoCount.AppMessage.ShowMessage("Item Batch Tab Page not found.");
return null;
}
else
{
//If grpTabItemBatch.Items[0] is not LayoutControlItem, the object will be null
if (grpTabItemBatch.Items.Count > 0)
{
layoutItemBatch = grpTabItemBatch.Items[0] as DevExpress.XtraLayout.LayoutControlItem;
}
//If layoutItemBatch.Control.Controls[0] is not GridControl, the object will be null
if (layoutItemBatch != null && layoutItemBatch.Control.Controls.Count > 0)
{
return layoutItemBatch.Control.Controls[0] as DevExpress.XtraGrid.GridControl;
}
else
{
AutoCount.AppMessage.ShowMessage("Item Batch Grid Control not found.");
return null;
}
}
}
Go to top
|
Resources For AutoCount Software Developers
|