Beispiel #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="st"></param>
 internal static void ClearBind(Station st)
 {
     if (st.CommuniPort != null)
     {
         Unbind(st, st.CommuniPort);
     }
 }
Beispiel #2
0
        public void BuildHardware()
        {
            Station st = new Station("st", new SocketCommuniType("1234"));
            st.Devices.Add(new TestDevice(0));

            this.Soft.HardwareManager.Stations.Add(st);
        }
Beispiel #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="treeView"></param>
 /// <param name="station"></param>
 /// <returns></returns>
 private static TreeNode AddStationToTreeView(TreeView treeView, Station station)
 {
     string stationName = station.Name;
     TreeNode stationTreeNode = treeView.Nodes.Add(stationName);
     stationTreeNode.ImageIndex = -1;
     stationTreeNode.Tag = station;
     station.Tag = stationTreeNode;
     return stationTreeNode;
 }
Beispiel #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="st"></param>
        public frmDeviceItem(Station st, string deviceType)
            : this()
        {
            if (st == null)
                throw new ArgumentNullException("st");
            this.Station = st;
            this.DeviceType= deviceType;
            this._adeState = ADEStatus.Add;

            this.txtOwnerStatoin.Text = Station.Name;

            //string deviceText = YeHeCommuniServerApp.Default.CommuniSoft.OperaFactory.DeviceDefineCollection.GetDeviceText(deviceType);
            string deviceText = YeHeCommuniServerApp.Default.CommuniSoft.DeviceDefineManager.DeviceDefineCollection.GetDeviceText(deviceType);
            this.txtDeviceType.Text = deviceText;
        }
Beispiel #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="station"></param>
        public frmStationItem(StationCollection stations, Station station)
        {
            this.InitializeComponent();
            this.FillDiscriminateMode();

            BindGroup();
            this._stations = stations;
            this._station = station;

            this.ADEState = ADEState.Edit;

            this.txtStationName.Text = this._station.Name;
            this.GroupID = GetGroupID(this._station.ID);
            this.txtRemark.Text = this._station.Description;

            if (this._station.CommuniType is SocketCommuniType)
            {
                this.rbSocket.Checked = true;
                this.rbSerialPort.Checked = false;
                this.ShowSocketSettingUI();

                SocketCommuniType socketct = this._station.CommuniType as SocketCommuniType;

                if (socketct.DiscriminateMode == DiscriminateMode.ByIPAddress)
                {
                    this.txtStationIP.Text = socketct.IPAddress.ToString();
                }
                this.numLocalPort.Value = socketct.LocalPort;
                this.numRemotePort.Value = socketct.RemotePort;
                this.cmbDiscriminateMode.SelectedValue = socketct.DiscriminateMode;
            }

            if (this._station.CommuniType is SerialCommuniType)
            {
                this.rbSocket.Checked = false;
                this.rbSerialPort.Checked = true;
                this.ShowSerialPortSettingUI();

                SerialCommuniType serialct = this._station.CommuniType as SerialCommuniType;
                this.ucSerialPortSetting1.SerialCommuniType = serialct;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="st"></param>
        /// <param name="cp"></param>
        internal static void Unbind(Station st, CommuniPort cp)
        {
            if (st == null)
                throw new ArgumentNullException("st");
            if (cp == null)
                throw new ArgumentNullException("cp");

            if (st.CommuniPort == null && cp.Station == null)
                return;

            Debug.Assert(
                st.CommuniPort != null &&
                cp.Station != null &&
                st.CommuniPort == cp &&
                cp.Station == st,
                "Unbind(Station, CommuniPort) assert fail");

            st.CommuniPort = null;
            cp.Station = null;
        }
Beispiel #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="station"></param>
        public frmStationItem(StationCollection stations, Station station)
            : this()
        {
            this._stations = stations;
            this._station = station;

            this.ADEState = ADEStatus.Edit;

            SocketCommuniType socketct = this._station.CommuniType as SocketCommuniType;

            this.txtStationName.Text = this._station.Name;
            //this.numOrdinal.Value = this._station.DBStation.Ordinal;
            this.txtRemark.Text = this._station.Description;
            //this.txtStreet.Text = this._station.DBStation.Street;

            if (socketct.DiscriminateMode == DiscriminateMode.ByIPAddress)
            {
                this.txtStationIP.Text = socketct.IPAddress.ToString();
            }
            this.numLocalPort.Value = socketct.LocalPort;
            this.numRemotePort.Value = socketct.RemotePort;
            this.cmbDiscriminateMode.SelectedValue = socketct.DiscriminateMode;
        }
Beispiel #8
0
 public void Update(Station station)
 {
     throw new NotImplementedException();
 }
Beispiel #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="station"></param>
        public object AddStation(Station station)
        {
            string sql = "insert into tblStation(Name, Remark, CommuniTypeContent) values(@n, @r, @c); select @@Identity";
            SqlCommand cmd = new SqlCommand(sql);
            SqlParameter p = null;
            p = new SqlParameter("n", station.Name);
            cmd.Parameters.Add(p);

            p = new SqlParameter("r", station.Description);
            cmd.Parameters.Add(p);

            p = new SqlParameter("c", station.CommuniType.ToXml());
            cmd.Parameters.Add(p);
            object obj = this.ExecuteScalar(cmd);
            int id = Convert.ToInt32(obj);
            //station.ID = GetIdentity();
            station.ID = id;
            return obj;
        }
Beispiel #10
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 = false;
                if (stationDR["Deleted"] != DBNull.Value)
                {
                    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);
                         CommuniType communiType = Xdgk.Communi.CommuniTypeFactory.Create(xml);

                        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 = false;
                if (deviceDR["deleted"] != DBNull.Value)
                {
                    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);
            }
            //}
        }
Beispiel #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="socketCT"></param>
        //private void AddStation(SocketCommuniType socketCT)
        private void AddStation(CommuniType ct)
        {
            // add
            string name = this.txtStationName.Text.Trim();
            string desc = this.txtRemark.Text.Trim();
            Station dbstation = new Station(name, ct);
            //dbstation.Ordinal = (int)this.numOrdinal.Value;
            dbstation.Description = this.txtRemark.Text;
            //dbstation.Street = this.txtStreet.Text.Trim();
            //dbstation.Create();

            _station = dbstation;

            //_station = new CZGRStation(name,
                //socketCT, dbstation);

            //_stations.Add(_station);

            GetCSDBI().AddStation(dbstation);

            Debug.Assert(dbstation.ID > 0);
            YeHeCommuniServerApp.Default.CSDBI.UpdateStationGroup(dbstation.ID,
                this.GroupID);

            // TODO: add station to hardwaremanager
            //
        }
Beispiel #12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="st"></param>
 /// <returns></returns>
 public DialogResult DeleteStation(Station st)
 {
     DialogResult dr = NUnit.UiKit.UserMessage.Ask("delete station?");
     if (dr == DialogResult.OK)
     {
         // TODO: delete station
         //
         HardwareManager.HardwareChanged(HardwareType.Station, st, HardwareChangedType.Delete);
     }
     return dr;
 }
Beispiel #13
0
 public void CommuniPortChanged(Station station)
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="station"></param>
 /// <returns></returns>
 private bool CheckStationConnected(Station station)
 {
     if (station.CommuniPort == null)
     {
         string s = string.Format(strings.StationNotConnect, station.Name);
         NUnit.UiKit.UserMessage.DisplayFailure(s);
         return false;
     }
     return true;
 }
Beispiel #15
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="station"></param>
 public void DeleteStation(Station station)
 {
     string sql = string.Format("update tblStation set stationDeleted = 1 where stationID = " + station.ID);
     DBI.ExecuteScalar(sql);
 }
Beispiel #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="station"></param>
        /// <returns></returns>
        public override DeviceCollection BuildDeviceCollection(Station station)
        {
            DeviceCollection devices = new DeviceCollection();

            string sql = string.Format(
                "select * from tblDevice where DeviceDeleted = 0 and StationID = {0}",
                station.ID
            );
            DataTable deviceTable = DBI.ExecuteDataTable(sql);
            foreach (DataRow row in deviceTable.Rows)
            {
                Device device = BuildDevice(row);
                if (device != null)
                {
                    devices.Add(device);
                }
            }
            return devices;
        }
Beispiel #17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="station"></param>
        /// <param name="dd"></param>
        public void InitForAdd(Station station, DeviceDefine dd)
        {
            if (station == null)
            {
                throw new ArgumentNullException("station");
            }

            if( dd == null )
            {
                throw new ArgumentNullException("dd");
            }

            this.Station = station;
            this.DeviceDefine = dd;
            this._adeState = ADEState.Add;
        }
Beispiel #18
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="st"></param>
 private void CreateDevice(Station st, int stationID)
 {
     DataTable stationDataTable = DB.GetDB().ExecuteStationDataTable();
     DataTable tblDevice = DB.GetDB().ExecuteDeviceDataTable(stationID);
     foreach (DataRow row in tblDevice.Rows)
     {
         string deviceType = row["DeviceType"].ToString();
         IDeviceFactory deviceFactory = soft.DPUManager.FindDeviceFactory(deviceType);
         Device device = deviceFactory.CreateDevice(row);
         if (device != null)
         {
             st.Devices.Add(device);
         }
     }
 }
Beispiel #19
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="st"></param>
        /// <param name="cp"></param>
        private static bool Bind(Station st, CommuniPort cp)
        {
            if (st == null)
                throw new ArgumentNullException("st");
            if (cp == null)
                throw new ArgumentNullException("cp");

            Debug.Assert(st.CommuniPort == null &&
                cp.Station == null,
                "Bind fail, st.CommuniPort or cp.Station not null");

            //Unbind(st, cp);
            st.CommuniPort = cp;
            cp.Station = st;
            return true;
        }
Beispiel #20
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="socketCT"></param>
        private void AddStation(SocketCommuniType socketCT)
        {
            // add
            string name = this.txtStationName.Text.Trim();
            string desc = this.txtRemark.Text.Trim();
            Station dbstation = new Station(name, socketCT);
            //dbstation.Ordinal = (int)this.numOrdinal.Value;
            dbstation.Description = this.txtRemark.Text;
            //dbstation.Street = this.txtStreet.Text.Trim();
            //dbstation.Create();

            _station = dbstation;

            //_station = new CZGRStation(name,
                //socketCT, dbstation);

            //_stations.Add(_station);

            GetCSDBI().AddStation(dbstation);

            // TODO: add station to hardwaremanager
            //
        }
Beispiel #21
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="station"></param>
        public override void EditStation(Station station)
        {
            string sql = "update tblStation set stationName = @name, StationCommuniType = @ct, StationRemark = @remark " +
                " where stationID = @id";
            SqlCommand cmd = new SqlCommand(sql);
            DBIBase.AddSqlParameter(cmd, "name", station.Name);
            DBIBase.AddSqlParameter(cmd, "ct", station.CommuniType.ToXml());
            DBIBase.AddSqlParameter(cmd, "remark", station.Description);
            DBIBase.AddSqlParameter(cmd, "id", station.ID);

            DBI.ExecuteScalar(cmd);
        }
Beispiel #22
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private Station BuildStation(DataRow row)
        {
            string name = row["StationName"].ToString();
            string ctString = row["StationCommuniType"].ToString();
            string remark = row["StationRemark"].ToString().Trim();

            CommuniType ct = CommuniTypeFactory.Create(ctString);
            Station station = new Station(name, ct);
            station.ID = Convert.ToInt32(row["stationID"]);
            station.Description = remark;

            return station;
        }
Beispiel #23
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="station"></param>
 public void CommuniPortChanged(Station station)
 {
     //this.SyncContext.Post(new SendOrPostCallback(CommuniPortChangedSync), station);
     CommuniPortChangedSync(station);
 }
Beispiel #24
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stationSource"></param>
        /// <returns></returns>
        public Xdgk.Communi.Station Create(object stationSource)
        {
            if (stationSource == null)
            {
                throw new ArgumentNullException("stationSource");
            }

            DataRow stationDR = stationSource as DataRow;
            if (stationDR == null)
            {
                string msg = string.Format("stationSource is not a data row");
                throw new ArgumentException(msg);
            }

            int stationID = (int)stationDR["StationID"];
            string stationName = stationDR["Name"].ToString();
            string xml = stationDR["CommuniTypeContent"].ToString().Trim();

            if (xml.Length == 0)
            {
                // TODO: 2010-09-17
                // log error info
                //
                //continue;
            }

            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;

            return station;
        }
Beispiel #25
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ownerStation"></param>
        /// <returns></returns>
        public DialogResult AddDevice(Station ownerStation)
        {
            if (ownerStation == null)
            {
                throw new ArgumentNullException("ownerStation");
            }

            DeviceDefine dd = GetDeviceDefine();
            if (dd == null)
            {
                return DialogResult.Cancel;
            }

            IDeviceForm f = GetDeviceForm(dd);

            f.InitForAdd(ownerStation, dd);
            DialogResult dr = f.ShowDialog();
            if (dr == DialogResult.OK)
            {
                HardwareManager.HardwareChanged(HardwareType.Device,
                    f.Device, HardwareChangedType.Add);
            }
            return dr;
        }
Beispiel #26
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="oldName"></param>
        /// <param name="station"></param>
        /// <returns></returns>
        public object EditStation(string oldName, Station station)
        {
            string sql = "select stationID from tblStation where Name = @n";
            SqlCommand cmd = new SqlCommand(sql);
            SqlParameter p = new SqlParameter("n", oldName);
            cmd.Parameters.Add(p);
            object id = this.ExecuteScalar(cmd);
            int stationId = (int)id;

            return EditStation(stationId, station);
        }
Beispiel #27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="st"></param>
 /// <returns></returns>
 public DialogResult EditStation(Station st)
 {
     if (HardwareManager == null)
     {
         throw new InvalidOperationException("HardwareManager == null");
     }
     IStationForm f = GetStationForm();
     f.InitForEdit(st);
     DialogResult dr = f.ShowDialog();
     if (dr == DialogResult.OK)
     {
         //CommuniSoftFactory.HardwareBuilder.EditStation(st);
         HardwareManager.HardwareChanged(HardwareType.Station, f.Station,
             HardwareChangedType.Edit);
     }
     return dr;
 }
Beispiel #28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="station"></param>
        /// <returns></returns>
        public object EditStation(int stationID, Station station)
        {
            string sql = "update tblStation Set Name = @n, Remark = @r, CommuniTypeContent = @c Where StationID = @id";

            SqlCommand cmd = new SqlCommand(sql);
            SqlParameter p = null;

            p = new SqlParameter("n", station.Name);
            cmd.Parameters.Add(p);

            p = new SqlParameter("r", station.Description);
            cmd.Parameters.Add(p);

            p = new SqlParameter("c", station.CommuniType.ToXml());
            cmd.Parameters.Add(p);

            p = new SqlParameter("id", stationID);
            cmd.Parameters.Add(p);
            return this.ExecuteScalar(cmd);
        }
Beispiel #29
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="newStation"></param>
        public override void AddStation(Station newStation)
        {
            string sql = "insert into tblStation(stationName, stationCommuniType, stationRemark, stationDeleted) values(@name, @ct, @remark, @deleted)";
            SqlCommand cmd = new SqlCommand(sql);
            DBIBase.AddSqlParameter(cmd, "name", newStation.Name);
            DBIBase.AddSqlParameter(cmd, "ct", newStation.CommuniType.ToXml());
            DBIBase.AddSqlParameter(cmd, "remark", newStation.Description);
            DBIBase.AddSqlParameter(cmd, "deleted", 0);

            DBI.ExecuteScalar(cmd);

            newStation.ID = DBI.GetIdentity();
        }
Beispiel #30
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public StationCollection CreateRainStations(CommuniSoft soft)
        {
            string deviceType = "LXRainDevice";

            StationCollection stations = new StationCollection();
            DataTable stTable = LXDBDBI.LXDB.GetRainStationDataTable();
            foreach (DataRow row in stTable.Rows)
            {
                string rainName = row["Rain_Name"].ToString();
                int rainAddress = Convert.ToInt32(row["Rain_addr"]);
                string ipString = row["Rain_IP"].ToString();
                IPAddress ip = IPAddress.Parse(ipString);
                int deviceid = rainAddress;
                int stationid = rainAddress;

                SocketCommuniType ct = new SocketCommuniType(ip);
                Station st = new Station(rainName, ct);
                st.ID = stationid;

                DeviceDefine dd = soft.DeviceDefineManager.
                    DeviceDefineCollection.FindDeviceDefine(deviceType);
                LXRainDevice d = new LXRainDevice(dd,rainAddress);
                d.ID = deviceid;

                st.Devices.Add(d);

                stations.Add(st);
            }
            return stations;
        }