Exemplo n.º 1
0
        public IHttpActionResult QueryBadTypeByUIDAPI(int uuid)
        {
            var dto = new ExceptionTypeVM();

            dto = AutoMapper.Mapper.Map <ExceptionTypeVM>(QualityService.QueryBadTypeByUID(uuid));
            return(Ok(dto));
        }
        public string AddExceptionType(ExceptionTypeVM newType)
        {
            string result = "";

            try
            {
                string fatherNode = "";
                if (!string.IsNullOrEmpty(newType.Second_Type))
                {
                    fatherNode = newType.Second_Type;
                }
                else if (!string.IsNullOrEmpty(newType.First_Type))
                {
                    fatherNode = newType.First_Type;
                }

                string sql = string.Format(@"
                            IF EXISTS (
                            SELECT TOP 1 1 FROM dbo.QualityAssurance_ExceptionType
                            WHERE TypeName=N'{0}' AND Flowchart_Master_UID = N'{6}')
                            BEGIN
                                SELECT N'已存在同名的类型,请检查。' AS Message
                            END
                            ELSE
                            BEGIN
                            DECLARE @NewOrgCode NVARCHAR(50),
		                            @fatherCode NVARCHAR(50),
		                            @NowMaxCode INT
			
                            SET @fatherCode='{1}'
                            IF NOT EXISTS (SELECT TOP 1 1 FROM dbo.QualityAssurance_ExceptionType WHERE Project=N'{5}'  AND EnableFlag=1 )
                            BEGIN
                            SET @NewOrgCode='001000000'
                            END
                            ELSE
                            IF ISNULL(@fatherCode,'')=''
                            BEGIN
                                SELECT @NowMaxCode =MAX(CONVERT(INT,Org_TypeCode)) 
							    FROM dbo.QualityAssurance_ExceptionType	
							    WHERE  Project=N'{5}' and  Org_TypeCode LIKE '%000000'
                                
                                SET @NewOrgCode=CONVERT(NVARCHAR(50),@NowMaxCode+1000000)
                            END	
                            ElSE IF @fatherCode LIKE '%000000'
                            BEGIN
	                            SELECT @NowMaxCode=MAX(CONVERT(INT,Org_TypeCode)) FROM dbo.QualityAssurance_ExceptionType
	                            WHERE Project=N'{5}' and   Org_TypeCode LIKE SUBSTRING(@fatherCode,1,3)+'%000'
		
	                            SET @NewOrgCode=CONVERT(NVARCHAR(50),@NowMaxCode+1000)
                            END
                            ELSE IF @fatherCode LIKE '%000'
                            BEGIN
	                            SELECT @NowMaxCode=MAX(CONVERT(INT,Org_TypeCode)) FROM dbo.QualityAssurance_ExceptionType
	                            WHERE  Project=N'{5}' and  Org_TypeCode LIKE SUBSTRING(@fatherCode,1,6)+'%'
		
	                            SET @NewOrgCode=CONVERT(NVARCHAR(50),@NowMaxCode+1)
                            END

                            IF LEN(@NewOrgCode)=7
                            BEGIN
	                            SET @NewOrgCode='00'+@NewOrgCode
                            END  
                            ELSE IF LEN(@NewOrgCode)=8
                            BEGIN
	                            SET @NewOrgCode='0'+@NewOrgCode
                            END 
	
                            INSERT INTO dbo.QualityAssurance_ExceptionType
	                                (   TypeName ,
	                                    ShortName ,
	                                    EnableFlag ,
	                                    Creator_UID ,
	                                    Create_Date ,
	                                    Modified_UID ,
	                                    Modified_Date ,
	                                    Org_TypeCode ,
	                                    TypeClassify,
                                        Project,
                                        Flowchart_Master_UID
	                                )
                            VALUES  (   N'{0}' , -- TypeName - nvarchar(50)
	                                    N'{2}' , -- ShortName - nvarchar(20)
	                                    1 , -- EnableFlag - bit
	                                    {3} , -- Creator_UID - int
	                                    GETDATE() , -- Create_Date - datetime
	                                    {3} , -- Modified_UID - int
	                                    GETDATE() , -- Modified_Date - datetime
	                                    @NewOrgCode , -- Org_TypeCode - nvarchar(50)
	                                    N'{4}' , -- TypeClassify - nvarchar(50),
                                        N'{5}',
                                        {6}
	                                )
	                            SELECT 'Success' AS Message
                            END", newType.TypeName.Trim(), fatherNode, newType.ShortName, newType.Creator_UID, newType.TypeClassify, newType.Project, newType.Flowchart_Master_UID);

                result = DataContext.Database.SqlQuery <string>(sql).ToArray()[0];
            }
            catch (Exception ex)
            {
                result = "Error";
                log.Error(ex);
            }

            return(result);
        }