/// <summary> /// /// </summary> public void Save() { bool hasParent; int parentID; GetParentID(out hasParent, out parentID); if (IsAdd()) { WaterUserDBI.InsertWaterUser( this.Name, this.Remark, this.WaterUserType.WaterUserTypeID, // TODO: parentwater is null // hasParent, parentID, this.WaterUserLevel.WaterUserLevelID); this.WaterUserID = WaterUserDBI.GetWaterUserID(this.Name); } else { WaterUserDBI.UpdateWaterUser(this.WaterUserID, this.Name, this.Remark, this.WaterUserType.WaterUserTypeID, hasParent, parentID, //this.ParentWaterUser.WaterUserID, this.WaterUserLevel.WaterUserLevelID); } // add wateruser channel map // int[] channelIDs = this.ChannelCollection.GetChannelIDs(); WaterUserChannelMapDBI.Associate(WaterUserID, channelIDs); // add wateruser in device // int[] inIDs = this.InDeviceCollection.GetDeviceIDs(); WaterUserInDBI.AssociateWaterUserInDevice(this.WaterUserID, inIDs); // add wateruser out device // int[] outIDs = this.OutDeviceCollection.GetDeviceIDs(); WaterUserOutDBI.AssociateWaterUserOutDevice(WaterUserID, outIDs); }
/// <summary> /// /// </summary> /// <param name="waterUserDI"></param> /// <returns></returns> static public ChannelCollection CreateChannelCollection(int waterUserID) { // waterUserID -> channelID[] -> channelCollection // ChannelCollection ccs = new ChannelCollection(); int[] channelIDs = WaterUserChannelMapDBI.GetChannelIDs(waterUserID); if (channelIDs.Length > 0) { DataTable tbl = ChannelDBI.GetChannelDataTable(channelIDs); foreach (DataRow row in tbl.Rows) { ChannelClass cc = CreateChannel(row); ccs.Add(cc); } } return(ccs); }