Programmer Item Maintenance: Item Batch Table OnColumnChange event v2: Difference between revisions

From AutoCount Resource Center
Content added Content deleted
mNo edit summary
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:


==Introduction==
==Introduction==
In Item Maintenance, when changes is made to the form, two events below will be triggered
In Item Maintenance, when changes of data is made to the form, two events below are triggered
<syntaxhighlight lang="csharp">
<syntaxhighlight lang="csharp">
public void OnItemColumnChanged(AutoCount.Stock.Item.StockItemColumnChangedEventArgs e)
public void OnItemColumnChanged(AutoCount.Stock.Item.StockItemColumnChangedEventArgs e)
public void OnItemUomColumnChanged(AutoCount.Stock.Item.StockItemUomColumnChangedEventArgs e)
public void OnItemUomColumnChanged(AutoCount.Stock.Item.StockItemUomColumnChangedEventArgs e)
</syntaxhighlight>
</syntaxhighlight>
However, these two events that are provided for the value changed of the column is for "Master" and "Detail" tables.
However, these two events that are provided for the value changed of the column is on "Master" and "Detail" tables.<br/>
'''Item Batch''' data is not held in these two tables.<br/>
'''Item Batch''' data is not held in neither of these two tables.<br/>
Therefore, to capture the changes of Item Batch table, programmer needs to add the OnColumnChanged event to the Item Batch table.
Therefore, to capture the data changes of Item Batch table, programmer can add the '''OnColumnChanged''' event to the Item Batch table.


==Sample code to add events to Item Batch table==
==Sample code to add events to Item Batch table==
Line 18: Line 18:
And create '''OnColumnChanged''' event when it successfully finding the Item Batch Table.
And create '''OnColumnChanged''' event when it successfully finding the Item Batch Table.


===Add the event at Item Maintenance Form Initialize===
===Add the event '''OnFormInitialize''' at Item Maintenance===
<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 27: Line 27:


===Create the event OnColumnChanged for Item Batch===
===Create the event OnColumnChanged for Item Batch===
<syntaxhighlight lang="csharp" highlight="1, 29">
<syntaxhighlight lang="csharp" highlight="1, 31">
private void TblItemBatch_ColumnChanged(object sender, DataColumnChangeEventArgs e)
private void TblItemBatch_ColumnChanged(object sender, DataColumnChangeEventArgs e)
{
{
Line 50: Line 50:
private void CreateItemBatchTableColumnChangedEvent(AutoCount.Stock.Item.FormStockItem.LayoutFormInitializeEventArgs e)
private void CreateItemBatchTableColumnChangedEvent(AutoCount.Stock.Item.FormStockItem.LayoutFormInitializeEventArgs e)
{
{
//Get the GridControl that holds the DataTable of Item Batch
DevExpress.XtraGrid.GridControl gcItemBatch = GetItemBatchGridControl(e);
DevExpress.XtraGrid.GridControl gcItemBatch = GetItemBatchGridControl(e);

if (gcItemBatch != null && gcItemBatch.DataSource != null && gcItemBatch.DataSource is DataTable)
if (gcItemBatch != null && gcItemBatch.DataSource != null && gcItemBatch.DataSource is DataTable)
{
{

Latest revision as of 02:59, 17 July 2018

Version Info

  • AutoCount Accounting 2.0
  • Tested version: 2.0.1.100

Introduction

In Item Maintenance, when changes of data is made to the form, two events below are 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 on "Master" and "Detail" tables.
Item Batch data is not held in neither of these two tables.
Therefore, to capture the data changes of Item Batch table, programmer can 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 OnFormInitialize at Item Maintenance

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)
{
    //Get the GridControl that holds the DataTable of Item Batch
    DevExpress.XtraGrid.GridControl gcItemBatch = GetItemBatchGridControl(e);

    if (gcItemBatch != null && gcItemBatch.DataSource != null && 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 menu

Go to top
Resources For AutoCount Software Developers