コード例 #1
0
 public RuRunningType GetRunningType(string RunningTypeCode)
 {
     try {
         RuRunningType runningType = Context.RuRunningType.Where(x => x.Code == RunningTypeCode).FirstOrDefault();
         if (runningType != null)
         {
             return(runningType);
         }
         else
         {
             //CreateRunningType(runningType);
             return(runningType);
         }
     } catch (Exception e) {
         throw e;
     }
 }
コード例 #2
0
 public string CreateRunningType(RuRunningType RunningType)
 {
     try
     {
         RuRunningType runningType = new RuRunningType();
         runningType.Code            = RunningType.Code;
         runningType.Name            = RunningType.Name;
         runningType.RunningNoFormat = "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}[RUNNING]";
         runningType.RunningNoDigit  = RunningType.RunningNoDigit;
         runningType.Active          = true;
         runningType.CreatedBy       = "System";
         runningType.CreatedDate     = DateTime.Now;
         Context.RuRunningType.Add(runningType);
         Context.SaveChanges();
         return(runningType.Code);
     }
     catch (Exception ex) {
         throw ex;
     }
 }
コード例 #3
0
        public RuRunningNo CreateRunningNo(RuRunningType runningType, params string[] parameter)
        {
            int         Count         = parameter.Length;
            RuRunningNo CreateRunning = new RuRunningNo();

            CreateRunning.RunningTypeCode = runningType.Code;
            if (Count > 0 && Count <= parameter.Length)
            {
                if (Count >= 1)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[0]))
                    {
                        CreateRunning.Parameter1 = parameter[0];
                    }
                }
                if (Count >= 2)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[1]))
                    {
                        CreateRunning.Parameter2 = parameter[1];
                    }
                }
                if (Count >= 3)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[2]))
                    {
                        CreateRunning.Parameter3 = parameter[2];
                    }
                }
                if (Count >= 4)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[3]))
                    {
                        CreateRunning.Parameter4 = parameter[3];
                    }
                }
                if (Count >= 5)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[4]))
                    {
                        CreateRunning.Parameter5 = parameter[4];
                    }
                }
                if (Count >= 6)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[5]))
                    {
                        CreateRunning.Parameter6 = parameter[5];
                    }
                }
                if (Count >= 7)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[6]))
                    {
                        CreateRunning.Parameter7 = parameter[6];
                    }
                }
                if (Count >= 8)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[7]))
                    {
                        CreateRunning.Parameter8 = parameter[7];
                    }
                }
                if (Count >= 9)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[8]))
                    {
                        CreateRunning.Parameter9 = parameter[8];
                    }
                }
                if (Count >= 10)
                {
                    if (!string.IsNullOrWhiteSpace(parameter[9]))
                    {
                        CreateRunning.Parameter10 = parameter[9];
                    }
                }
            }
            CreateRunning.RunningNo   = 0;
            CreateRunning.Active      = true;
            CreateRunning.CreatedBy   = "Ru";
            CreateRunning.CreatedDate = DateTime.Now;
            Context.RuRunningNo.Add(CreateRunning);
            Context.SaveChanges();
            return(CreateRunning);
        }
コード例 #4
0
        public ReturnMessageDTO GenerateRunningNo(string runningCode, params string[] parameter)
        {
            ReturnMessageDTO returnMessageDTO = new ReturnMessageDTO();

            try
            {
                //get running type and check null and not null
                RuRunningType runningType = RunningTypeService.GetRunningType(runningCode);

                //check running no มันคือการ get ข้อมูมลจาก database
                if (runningType == null)
                {
                    throw new Exception("Not found running Tpye!!");
                }
                RuRunningNo Running = Context.RuRunningNo.Where(x => x.RunningTypeCode == runningCode).FirstOrDefault();
                // ถ้ามัน ไม่มี วิ่งไป create แล้วส่งกลับมาเป็น RunningType
                Running = CheckParameter(parameter.Length, runningCode, parameter);
                if (Running == null)
                {
                    CreateRunningNo(runningType, parameter);
                    returnMessageDTO = GenerateRunningNo(runningCode, parameter);
                    return(returnMessageDTO);
                }
                // ถ้าเจอ ก็ update ในนี้แหล่ะ
                else
                {
                    Running = CheckParameter(parameter.Length, runningCode, parameter);
                }

                if (Running.Active == true && Running != null)
                {
                    //if (checkParameter(runningType, parameter) == true)
                    //{
                    Running.RunningNo++;
                    Running.UpdatedDate = DateTime.Now;
                    Running.UpdatedBy   = "RunningNoService";
                    string runningDigit = Running.RunningNo.ToString().PadLeft(runningType.RunningNoDigit, '0');
                    string result       = string.Format(runningType.RunningNoFormat
                                                        , Running.Parameter1
                                                        , Running.Parameter2
                                                        , Running.Parameter3
                                                        , Running.Parameter4
                                                        , Running.Parameter5
                                                        , Running.Parameter6
                                                        , Running.Parameter7
                                                        , Running.Parameter8
                                                        , Running.Parameter9
                                                        , Running.Parameter10
                                                        ).Replace("[RUNNING]", runningDigit);
                    Context.RuRunningNo.Update(Running);
                    Context.SaveChanges();
                    returnMessageDTO.Code        = result;
                    returnMessageDTO.TypeCode    = Running.RunningTypeCode;
                    returnMessageDTO.TypeName    = runningType.Name;
                    returnMessageDTO.Digit       = runningType.RunningNoDigit;
                    returnMessageDTO.Format      = runningType.RunningNoFormat;
                    returnMessageDTO.CreatedDate = Running.UpdatedDate;
                    returnMessageDTO.Message     = "RunningNo Created Success!!";
                    return(returnMessageDTO);
                    //}
                    //else
                    //{
                    //    CreateRunningNo(runningType, parameter);
                    //    return returnMessageDTO;
                    //}
                }
                throw new NotImplementedException();
            }
            catch (Exception e)
            {
                returnMessageDTO.Message = e.Message;
                return(returnMessageDTO);

                throw e;
            }
        }