예제 #1
0
        private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OrderSetting os = new OrderSetting();

            if (os.ShowDialog() == DialogResult.OK)
            {
                UserOrder order = new UserOrder(os.Hour, os.Minute);

                foreach (UserOrder temp in _orders)
                {
                    if (temp.GetTime() == order.GetTime())
                    {
                        Helper.ShowMessageBox("提示", "已添加该时间命令");
                        return;
                    }
                }
                Add(order);
            }
        }
        //保存预约配置
        public void SaveOrderConfig(List <UserOrder> _orders)
        {
            if (_orders != null && _orders.Count > 0)
            {
                XmlDocument config = new XmlDocument();
                XmlNode     root   = config.CreateNode(XmlNodeType.Element, "Root", null);
                config.AppendChild(root);

                for (int i = 0; i < _orders.Count; i++)
                {
                    UserOrder currentOrder = _orders[i];

                    XmlNode time      = config.CreateNode(XmlNodeType.Element, "DelayTime", null);
                    XmlNode timeValue = config.CreateNode(XmlNodeType.Element, "TimeValue", null);
                    timeValue.InnerText = currentOrder.GetTime();

                    time.AppendChild(timeValue);

                    for (int count_opreation = 0; count_opreation < currentOrder.Operations.Count; count_opreation++)
                    {
                        UserOperation operation = currentOrder.Operations[count_opreation];

                        XmlNode operationNode = config.CreateNode(XmlNodeType.Element, "Operation", null);

                        XmlNode operationName = config.CreateNode(XmlNodeType.Element, "OperationName", null);
                        operationName.InnerText = operation.Name;

                        XmlNode operationType = config.CreateNode(XmlNodeType.Element, "OperationType", null);
                        operationType.InnerText = operation.OpreationType.ToString();

                        XmlNode operationDataType = config.CreateNode(XmlNodeType.Element, "OperationDataType", null);
                        operationDataType.InnerText = operation.DataType.ToString();

                        XmlNode operationData = config.CreateNode(XmlNodeType.Element, "OperationData", null);
                        operationData.InnerText = operation.Data.Trim();

                        XmlNode operationTime = config.CreateNode(XmlNodeType.Element, "OperationTime", null);
                        operationTime.InnerText = operation.DelayTime.ToString();

                        XmlNode operationSetting = config.CreateNode(XmlNodeType.Element, "OperationSetting", null);
                        if (operation.Setting as ComSetting != null)
                        {
                            SaveComSetting(config, operation, operationSetting);
                        }
                        else if (operation.Setting as NetworkSetting != null)
                        {
                            SaveIPSetting(config, operation, operationSetting);
                        }

                        operationNode.AppendChild(operationName);
                        operationNode.AppendChild(operationType);
                        operationNode.AppendChild(operationDataType);
                        operationNode.AppendChild(operationData);
                        operationNode.AppendChild(operationTime);
                        operationNode.AppendChild(operationSetting);

                        time.AppendChild(operationNode);
                    }
                    root.AppendChild(time);
                }
                config.Save(_timelineConfig);
            }
        }