iT邦幫忙

2021 iThome 鐵人賽

DAY 29
0
自我挑戰組

從Agile PLM 移轉 Aras PLM大小事系列 第 29

29.移轉 Aras PLM大小事-額外編碼取號(3)

最後講一段讀取下一碼流水號的作法
1.根據前端解析到的選項,每一個屬性相加之後,在流水號之前的都是前墜碼,之後的尾碼
2.找出對應的Sequence_TBL主鍵名稱name,則開始讀取下一碼
3.拆出流水碼的位數,並從目前值往上遞增
4.重新組成編號

public string GetNextNumber(Sequence_TBL sequence,bool save)
{
    
    int count = (int)sequence.current_number;
    int padding = sequence.digit == null ? 0 :(int)sequence.digit;
    sequence.current_number = count ;
    string water_number = sequence.digit==0? "": sequence.current_number.ToString().PadLeft(padding, '0');
    if (sequence.digit == 1 && sequence.current_number > 9)
    {
        char c = Convert.ToChar((int)sequence.current_number-9 + 64);
        water_number = c.ToString();
    }
    string item_number = sequence.forward + water_number + sequence.suffix;

    var MaxItemNumber = SeqHistoryRepo.FindMax(sequence.forward, sequence.suffix);
    if(MaxItemNumber != null)
    {
        if (string.Compare(item_number, MaxItemNumber.item_number.Trim()) < 0)
        {
            item_number = MaxItemNumber.item_number.Trim();
        }
    }

    if (sequence.digit != 0)
    {

        //當號碼已存在則跳下一碼
        var seqHistory = SeqHistoryRepo.Find(item_number);
        while (seqHistory != null)
        {
            //判斷是否超過最後一個序號
            if (string.Compare(item_number, MaxItemNumber.item_number.Trim()) < 0)
            {
                seqHistory = SeqHistoryRepo.Find(MaxItemNumber.item_number);
            }
            else
            {
                count = (int)sequence.current_number;
                padding = sequence.digit == null ? 0 : (int)sequence.digit;
                sequence.current_number = count + sequence.increase;
                water_number = sequence.digit == 0 ? "" : sequence.current_number.ToString().PadLeft(padding, '0');
                if (sequence.digit == 1 && sequence.current_number > 9)
                {
                    char c = Convert.ToChar((int)sequence.current_number - 9 + 64);
                    water_number = c.ToString();
                }
                item_number = sequence.forward + water_number + sequence.suffix;

                seqHistory = SeqHistoryRepo.Find(item_number);

                //判斷是否超過最後一個序號
                if (string.Compare(item_number, MaxItemNumber.item_number.Trim()) < 0)
                {
                    seqHistory = SeqHistoryRepo.Find(MaxItemNumber.item_number);
                }
            }

        }
    }
    if (save == true)
    {
        this.UnitOfWork.Commit();
    }
    return item_number;
}

上一篇
28. 移轉 Aras PLM大小事 - 額外編碼取號(2)
下一篇
30.移轉 Aras PLM大小事-結語
系列文
從Agile PLM 移轉 Aras PLM大小事30

尚未有邦友留言

立即登入留言