Ejemplo n.º 1
0
        /// <summary>
        /// 复制plc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void click_Copy_Device(object sender, RoutedEventArgs e)
        {
            DC_DEVICE device  = (DC_DEVICE)(sender as FrameworkElement).Tag;
            DC_DEVICE copyDev = new DC_DEVICE()
            {
                CHANNEL      = device.CHANNEL,
                CRA_ID       = device.CRA_ID,
                DESCRIPTION  = device.DESCRIPTION,
                ENABLE       = device.ENABLE,
                IP_ADDRESS   = device.IP_ADDRESS,
                MAC_ADDRESS  = device.MAC_ADDRESS,
                S7CONNECTION = device.S7CONNECTION,
                NAME         = device.NAME,
                NUM          = device.NUM,
                SERVER_ID    = device.SERVER_ID,
                Configs      = new ObservableCollection <DC_DATA_CONFIG>()
            };

            dC_Service.InsertDCDevice(copyDev);
            DC_SERVER server = Servers.First(s => s.Devices.Contains(device));

            server.Devices.Add(copyDev);
            foreach (var config in device.Configs)
            {
                DC_DATA_CONFIG copyConfig = new DC_DATA_CONFIG()
                {
                    IDENTITY_COLUMN      = config.IDENTITY_COLUMN,
                    CONVERTER            = config.CONVERTER,
                    DESCRIPTION          = config.DESCRIPTION,
                    DEVICE_ID            = copyDev.ID,
                    ENABLE               = config.ENABLE,
                    FIELD_DATA_LENGTH    = config.FIELD_DATA_LENGTH,
                    FIELD_DATA_PRECISION = config.FIELD_DATA_PRECISION,
                    FIELD_DATA_SCALE     = config.FIELD_DATA_SCALE,
                    FIELD_DATA_TYPE      = config.FIELD_DATA_TYPE,
                    MEMORY_ADDRESS       = config.MEMORY_ADDRESS,
                    TABLE_NAME           = config.TABLE_NAME,
                    SUBSCRIPTION         = config.SUBSCRIPTION,
                    TABLE_USER           = config.TABLE_USER,
                    NAME           = config.NAME,
                    NUM            = config.NUM,
                    FIELD_NAME     = config.FIELD_NAME,
                    IDENTITY_VALUE = config.IDENTITY_VALUE,
                };
                dC_Service.InsertDataConfig(copyConfig);
                dC_Service.InsertRealData(copyConfig.ID);
                copyDev.Configs.Add(copyConfig);
            }
        }
Ejemplo n.º 2
0
 private void btn_OK_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(Config.NUM))
     {
         MessageBox.Show("编号不能为空。");
         return;
     }
     try
     {
         if (IsModify)
         {
             dC_Service.ModifyDataConfig(Config);
         }
         else
         {
             dC_Service.InsertDataConfig(Config);
             dC_Service.InsertRealData(Config.ID);
         }
         MessageBox.Show("操作成功。");
         this.DialogResult = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show("操作失败。" + ex.Message);
     }
 }