コード例 #1
0
        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();
        }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
        public void Select(Service service)
        {
            if (service == null) return;

            SelectService(ServiceTree.Nodes, service);
        }
コード例 #4
0
 public ServiceUpdatedEventArgs(ServiceType serviceType, Service service)
 {
     ServiceType = serviceType;
     Service = service;
 }
コード例 #5
0
        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;
                }
            }
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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;
        }