Example #1
0
        /// <summary>
        /// Execute the command within its own thread
        /// </summary>
        /// <param name="Elem"></param>
        ///
        public void Execute(MM_Element Elem)
        {
            //Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
            String InCmd = Command;

            //Replace the {word} with the values for that element
            int Bracket = InCmd.IndexOf("{");

            while (Bracket > -1)
            {
                String InWord  = InCmd.Substring(Bracket + 1, InCmd.IndexOf("}", Bracket) - Bracket - 1);
                Object InValue = null;
                foreach (MemberInfo mI in Elem.GetType().GetMember(InWord))
                {
                    if (mI is FieldInfo)
                    {
                        InValue = (mI as FieldInfo).GetValue(Elem);
                    }
                    else if (mI is PropertyInfo)
                    {
                        InValue = (mI as PropertyInfo).GetValue(Elem, null);
                    }
                }
                InCmd   = InCmd.Substring(0, Bracket) + InValue.ToString() + InCmd.Substring(InCmd.IndexOf('}', Bracket) + 1);
                Bracket = InCmd.IndexOf("{");
            }

            //Now, send our command if appropriate
            if (MM_Server_Interface.SendCommand(InCmd, "") == CheckState.Unchecked)
            {
                MessageBox.Show("Unable to send command. Please retry.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        /// <summary>
        /// When the user presses enter, update our value
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewCtl_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != '\r' && e.KeyChar != '\n')
            {
                (sender as TextBox).Modified = true;
                return;
            }



            XmlElement xElem = (XmlElement)(sender as Control).Tag;

            if (xElem.HasAttribute("OnChange"))
            {
                Object       SourceObj = SourceElement.BaseElement;
                String[]     splStr    = xElem.Attributes["DataSource"].Value.Split('.');
                FieldInfo    fI        = null;
                PropertyInfo pI        = null;
                for (int a = 0; a < splStr.Length - 1; a++)
                {
                    fI = SourceObj.GetType().GetField(splStr[a]);
                    if (fI != null)
                    {
                        pI = null;
                    }
                    else
                    {
                        pI = SourceObj.GetType().GetProperty(splStr[a]);
                    }

                    if (fI != null)
                    {
                        SourceObj = fI.GetValue(SourceObj);
                    }
                    else
                    {
                        SourceObj = pI.GetValue(SourceObj);
                    }
                }
                fI = SourceObj.GetType().GetField(splStr[splStr.Length - 1]);
                if (fI == null)
                {
                    pI = SourceObj.GetType().GetProperty(splStr[splStr.Length - 1]);
                }
                //FieldInfo fI = SourceElement.BaseElement.GetType().GetField(xElem.Attributes["DataSource"].Value);
                try
                {
                    object OutVal  = Convert.ChangeType(((TextBox)sender).Text.Trim(), fI != null ? fI.FieldType : pI.PropertyType);
                    object LastVal = fI != null?fI.GetValue(SourceObj) : pI.GetValue(SourceObj);

                    if (LastVal == null)
                    {
                        LastVal = "(null)";
                    }

                    if (!OneLineViewer.ValueChanges.ContainsKey(SourceElement.BaseElement))
                    {
                        OneLineViewer.ValueChanges.Add(SourceElement.BaseElement, OutVal);
                    }
                    if (MM_Server_Interface.SendCommand(ParseCommand(xElem.Attributes["OnChange"].Value, OutVal), LastVal.ToString()) == CheckState.Unchecked)
                    {
                        MessageBox.Show(String.Format("Unable to send command: Set value '{0}' for [{1}]", ((TextBox)sender).Text, xElem.Attributes["DataSource"].Value), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("Unable to write value '{0}' for [{1}] ({2})", ((TextBox)sender).Text, xElem.Attributes["DataSource"].Value, ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            (sender as TextBox).Modified = false;
            this.Focus();



            /*MM_OneLine_RecordLocator FoundLoc = null;
             * foreach (MM_OneLine_RecordLocator rLoc in Locators)
             *  if (rLoc.Name == xElem.Attributes["DataSource"].Value)
             *      FoundLoc = rLoc;
             * if (FoundLoc != null)
             * {
             *  String TargetDataSource = "";
             *  XmlNode FoundNode = xElem;
             *  int Subscript = Convert.ToInt32(RetrievedValues["Subscript"]);
             *  while (FoundNode.Name != "ControlPanel")
             *      FoundNode = FoundNode.ParentNode;
             *  if ((FoundNode = FoundNode.SelectSingleNode("AdditionalDataSource/DataSource[@Name='" + xElem.Attributes["DataSource"].Value + "']")) != null)
             *  {
             *      TargetDataSource = FoundNode.ParentNode.Attributes["Name"].Value;
             *      Subscript = Convert.ToInt32(RetrievedValues[FoundNode.ParentNode.SelectSingleNode("DataSource[@ColumnName='__SUB']").Attributes["Name"].Value]);
             *  }
             *
             *  //Overide subscript if needed
             *  if (xElem.HasAttribute("Subscript"))
             *      Subscript = Convert.ToInt32(RetrievedValues[xElem.Attributes["Subscript"].Value]);
             *
             *  String OldValue = RetrievedValues[FoundLoc.Name].ToString();
             *  Data_Integration.MMServer.UpdateValue(QueryGUID, Subscript, FoundLoc.ColumnName, FoundLoc.Name, (sender as TextBox).Text, OldValue, SourceElement.BaseElement.Substation.Name, SourceElement.ElemType.ToString(), SourceElement.BaseElement.Name, TargetDataSource);
             *  (sender as TextBox).Modified = false;
             *  this.Focus();
             * }*/
        }
Example #3
0
        /// <summary>
        /// Handle clicking on the item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewCtl_Click(object sender, EventArgs e)
        {
            if (Editable)
            {
                return;
            }
            XmlElement xElem = (XmlElement)(sender as Control).Tag;

            if (!xElem.HasAttribute("OnClick") && !xElem.HasAttribute("OnChange"))
            {
                return;
            }

            //Process any change commands
            if (xElem.HasAttribute("OnChange"))
            {
                String OutCmd;
                String LastValue = "(null)";
                if (sender is CheckBox)
                {
                    OutCmd = ParseCommand(xElem.Attributes["OnChange"].Value, ((CheckBox)sender).Checked);
                }
                else
                {
                    OutCmd = ParseCommand(xElem.Attributes["OnChange"].Value, null);
                }
                if (sender is CheckBox)
                {
                    ((CheckBox)sender).Checked ^= true;
                    LastValue = ((CheckBox)sender).Checked.ToString();
                }

                CheckState Resp = MM_Server_Interface.SendCommand(OutCmd, LastValue);
                if (Resp == CheckState.Checked)
                {
                    if (!OneLineViewer.ValueChanges.ContainsKey(SourceElement.BaseElement))
                    {
                        OneLineViewer.ValueChanges.Add(SourceElement.BaseElement, OutCmd);
                    }
                }
                else if (Resp == CheckState.Unchecked)
                {
                    MessageBox.Show("Unable to send command. Please retry.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            //Process all of our commands
            if (xElem.HasAttribute("OnClick"))
            {
                foreach (String str in xElem.Attributes["OnClick"].Value.Split('|'))
                {
                    String[] Cmd = str.Split('(', ')', '/');
                    String   TargetDataSource = "";
                    XmlNode  FoundNode        = xElem;
                    while (FoundNode.Name != "ControlPanel")
                    {
                        FoundNode = FoundNode.ParentNode;
                    }
                    if (xElem.HasAttribute("DataSource") && ((FoundNode = FoundNode.SelectSingleNode("AdditionalDataSource/DataSource[@Name='" + xElem.Attributes["DataSource"].Value + "']")) != null))
                    {
                        TargetDataSource = FoundNode.ParentNode.Attributes["Name"].Value;
                    }

                    else if (Cmd[0] == "Close")
                    {
                        this.Close();
                    }
                }
            }
        }