Esempio n. 1
0
        private void LoadPartCountEventItems(DataTable dt)
        {
            PartCountItems.Clear();

            string address = "/Parts/";
            string filter  = "address LIKE '" + address + "*'";

            var rows = DataTable_Functions.GetRows(dt, filter);

            foreach (DataRow row in rows)
            {
                string lastNode = DataTable_Functions.TrakHound.GetLastNode(row);
                if (lastNode == "Event")
                {
                    var item = new Controls.PartCountEventItem();
                    item.ParentPage      = this;
                    item.RemoveClicked  += Item_RemoveClicked;
                    item.SettingChanged += Item_SettingChanged;

                    filter = "address LIKE '" + row["address"].ToString() + "/*'";
                    var eventRows = DataTable_Functions.GetRows(dt, filter);
                    foreach (DataRow eventRow in eventRows)
                    {
                        lastNode = DataTable_Functions.TrakHound.GetLastNode(eventRow);

                        switch (lastNode)
                        {
                        case "EventName": item.EventName = DataTable_Functions.GetRowValue("value", eventRow); break;

                        case "EventValue": item.EventValue = DataTable_Functions.GetRowValue("value", eventRow); break;

                        case "PreviousEventValue": item.PreviousEventValue = DataTable_Functions.GetRowValue("value", eventRow); break;

                        case "ValueType": item.ValueType = GetFormattedValue(DataTable_Functions.GetRowValue("value", eventRow)); break;

                        case "CaptureItemLink": item.CaptureItemLink = DataTable_Functions.GetRowValue("value", eventRow); break;

                        case "CalculationType": item.CalculationType = DataTable_Functions.GetRowValue("value", eventRow); break;

                        case "StaticIncrementValue": item.StaticIncrementValue = DataTable_Functions.GetIntegerFromRow("value", eventRow); break;
                        }
                    }

                    if (!string.IsNullOrEmpty(item.EventName))
                    {
                        PartCountItems.Add(item);
                    }
                }
            }

            // Try loading deprecated configuration
            if (PartCountItems.Count == 0 && rows.Length > 0)
            {
                var item = new Controls.PartCountEventItem();
                item.ParentPage      = this;
                item.RemoveClicked  += Item_RemoveClicked;
                item.SettingChanged += Item_SettingChanged;

                foreach (DataRow row in rows)
                {
                    string lastNode = DataTable_Functions.TrakHound.GetLastNode(row);

                    if (lastNode == "PartsEventValue")
                    {
                        item.EventValue = GetFormattedValue(DataTable_Functions.GetRowValue("value", row));
                    }
                    if (lastNode == "PartsEventName")
                    {
                        item.EventName = DataTable_Functions.GetRowValue("value", row);
                    }
                    else if (lastNode == "PartsCaptureItemLink")
                    {
                        item.CaptureItemLink = DataTable_Functions.GetRowValue("value", row);
                    }
                    else if (lastNode == "CalculationType")
                    {
                        item.CalculationType = DataTable_Functions.GetRowValue("value", row);
                    }
                }

                if (!string.IsNullOrEmpty(item.EventName))
                {
                    PartCountItems.Add(item);
                }
            }
        }