示例#1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void okButton_Click(object sender, EventArgs e)
 {
     if (VerifyAddress())
     {
         if (ADEState == ADEState.Edit)
         {
             EditDevice();
         }
         else
         {
             DeviceDefine dd = YeHeCommuniServerApp.Default.CommuniSoft.DeviceDefineManager.DeviceDefineCollection.FindDeviceDefine(this.DeviceType);
             //this.Device = new Device(dd, "", this.Address);
             this.Device        = DeviceFactory.Create(dd, "", this.Address);
             this.Device.Remark = this.txtRemark.Text;
             AddDevice();
         }
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     else
     {
         NUnit.UiKit.UserMessage.DisplayFailure("已经存在相同地址");
     }
 }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="soft"></param>
        public override void Build(CommuniSoft soft)
        {
            System.Collections.Hashtable idStationMap = new System.Collections.Hashtable();
            // build station
            //
            foreach (DataRow stationDR in _stationDataTable.Rows)
            {
                bool isStationDeleted = Convert.ToBoolean(stationDR["Deleted"]);
                if (!isStationDeleted)
                {
                    string stationName    = stationDR["Name"].ToString();
                    bool   isExistStation = soft.HardwareManager.Stations.ExistName(stationName, null);
                    if (!isExistStation)
                    {
                        string xml = stationDR["CommuniTypeContent"].ToString().Trim();
                        if (xml.Length == 0)
                        {
                            // TODO: 2010-09-17
                            // log error info
                            //
                            continue;
                        }

                        int stationID = (int)stationDR["StationID"];

                        XmlDataDocument doc = new XmlDataDocument();
                        doc.LoadXml(xml);
                        XmlNode     node        = doc.SelectSingleNode("socketcommunitype");
                        CommuniType communiType = Xdgk.Communi.XmlBuilder.XmlSocketCommuniBuilder.Build(node);

                        Station station = new Station(stationName, communiType);
                        station.ID = stationID;
                        idStationMap.Add(stationID, station);
                        soft.HardwareManager.Stations.Add(station);
                    }
                }
            }

            // build device
            //
            foreach (DataRow deviceDR in _deviceDataTable.Rows)
            {
                bool isDeviceDeleted = Convert.ToBoolean(deviceDR["Deleted"]);
                if (isDeviceDeleted)
                {
                    continue;
                }

                //if (!isDeviceDeleted)
                //{
                int    stationID     = (int)deviceDR["StationID"];
                int    deviceID      = (int)deviceDR["DeviceID"];
                string deviceType    = deviceDR["DeviceType"].ToString();
                string addressString = deviceDR["Address"].ToString().Trim();

                if (addressString.Length == 0)
                {
                    continue;
                }

                int address = Convert.ToInt32(addressString);

                Station st = idStationMap[stationID] as Station;
                //if (st != null)
                //{
                //    st.Devices.Add(device);
                //}
                if (st == null)
                {
                    continue;
                }

                //DeviceDefine dd = soft.DeviceDefineCollection.FindDeviceDefine(deviceType);
                DeviceDefine dd = soft.DeviceDefineManager.DeviceDefineCollection.FindDeviceDefine(deviceType);
                if (dd == null)
                {
                    bool exist = soft.UnDefineDeviceType.Exist(deviceType);
                    if (!exist)
                    {
                        soft.UnDefineDeviceType.Add(deviceType);
                        string msg = string.Format(strings.UnDefineDeviceType, deviceType);
                        NUnit.UiKit.UserMessage.Display(msg);
                    }
                    continue;
                }

                //Xdgk.Communi.Device device = new Device(dd, "", address);
                Xdgk.Communi.Device device = DeviceFactory.Create(dd, "", address);

                //Xdgk.Communi.Device device = new Device(deviceType, address);
                //string t = soft.OperaFactory.DeviceDefineCollection.GetDeviceText(deviceType);
                //device.Text = t;
                device.ID = deviceID;

                //Station st = soft.HardwareManager.GetStation(stationName);
                st.Devices.Add(device);

                DataTable tbl = DB.FormulaDB.GetFormulaDataTable(device.ID);
                YeHeCommuniServerApp.Default.DevieFormaulCollectionMapCollection.AddDevice(device.ID, tbl.Rows);
            }
            //}
        }