private void OkButton_Click(object sender, EventArgs e) { if (!ValidateChildren()) { return; } if(Service == null) { service = new Service {ServiceId = Guid.NewGuid()}; } Service.ServiceTypeId = CurrentServiceType.ServiceTypeId; Service.Name = ServiceNameEdit.EditValue as string; DialogResult = DialogResult.OK; Close(); }
public void UpdateServiceAndType(ServiceType serviceType, Service service) { if (serviceType == null && service == null) return; using (IDbConnection connection = CreateConnection()) { using (IDbTransaction transaction = connection.BeginTransaction()) { IDbCommand command = connection.CreateCommand(); command.Transaction = transaction; if (serviceType != null) { #region SQL statement command.CommandText = @" IF NOT EXISTS (SELECT TOP(1) [service_type_id] FROM [dbo].[service_type] WHERE [service_type_id] = @service_type_id) INSERT INTO [dbo].[service_type] ([service_type_id] ,[name]) VALUES (@service_type_id ,@service_type_name) ELSE UPDATE [dbo].[service_type] SET [name] = @service_type_name WHERE [service_type_id] = @service_type_id "; #endregion addParameter(command, "@service_type_id", serviceType.ServiceTypeId); addParameter(command, "@service_type_name", serviceType.Name); command.ExecuteNonQuery(); } if (service != null) { #region SQL statement command.CommandText = @" IF NOT EXISTS (SELECT TOP(1) [service_id] FROM [dbo].[service] WHERE [service_id] = @service_id) INSERT INTO [dbo].[service] ([service_id] ,[service_type_id] ,[name]) VALUES (@service_id ,@service_type_id ,@service_name) ELSE UPDATE [dbo].[service] SET [name] = @service_name ,[service_type_id] = @service_type_id WHERE [service_id] = @service_id "; #endregion command.Parameters.Clear(); addParameter(command, "@service_type_id", service.ServiceTypeId); addParameter(command, "@service_id", service.ServiceId); addParameter(command, "@service_name", service.Name); command.ExecuteNonQuery(); } transaction.Commit(); } } }
public void Select(Service service) { if (service == null) return; SelectService(ServiceTree.Nodes, service); }
public ServiceUpdatedEventArgs(ServiceType serviceType, Service service) { ServiceType = serviceType; Service = service; }
private void SelectService(TreeListNodes nodes, Service sService) { foreach (TreeListNode listNode in nodes) { if (listNode.Nodes.Count > 0) SelectService(listNode.Nodes, sService); ServiceTree service = GetServiceByNode(listNode); if (service == null || service.ParentId == Guid.Empty) continue; if (service.ServiceId == sService.ServiceId) { listNode.Selected = true; return; } } }
private List<Service> GetServices(TreeListNodes nodes) { List<Service> result = new List<Service>(); foreach (TreeListNode listNode in nodes) { if (listNode.Nodes.Count > 0) result.AddRange(GetServices(listNode.Nodes)); ServiceTree service = GetServiceByNode(listNode); if (service == null || service.ParentId == Guid.Empty) continue; Service s = new Service(); s.ServiceId = service.ServiceId; s.Name = service.Name; result.Add(s); } return result; }
private List<Service> GetSelectedServices() { List<Service> result = new List<Service>(); foreach (TreeListNode listNode in ServiceTree.Selection) { ServiceTree service = GetServiceByNode(listNode); if (service == null || service.ParentId == Guid.Empty) continue; Service s = new Service(); s.ServiceId = service.ServiceId; s.Name = service.Name; result.Add(s); } return result; }