コード例 #1
0
        //Auto generate Pre-Contract/Contract number
        //ContractStatus = P (Pre), O (Live)
        public SysAutoGenerateReturn GetNewContractNumber(string strContractStatus, string strSubContractType, string strSubProductType, string strLEFSInterestCode)
        {
            SysAutoGenerateReturn data = new SysAutoGenerateReturn();

            using (var db = new MainDbContext())
            {
                string strGroup = "";
                string strCode  = "";

                if (strContractStatus.Trim().ToUpper() == "P")
                {
                    strGroup = "PreContract";
                }
                else
                {
                    strGroup = "Contract";
                }

                strCode = FnGetContractNumberCode(strContractStatus, strSubContractType, strSubProductType, strLEFSInterestCode);
                data    = GetSystemID(strGroup, strCode, DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString());
            }
            return(data);
        }
コード例 #2
0
        public static bool UpdateSystemIDLastNum(SysAutoGenerateReturn data, string userName, MainDbContext db)
        {
            try
            {
                var Child = db.Sys_AutoGenerateIdChild;
                //var YearFilter = db.Sys_AutoGenerateIdMaster.FirstOrDefault(f => f.ID == data.MasterID);// ? Year.Substring(Year.Length - 2) : "00";
                var    YearFilter = db.Sys_AutoGenerateIdMaster.FirstOrDefault(f => f.Code == data.MasterCode);             // ? Year.Substring(Year.Length - 2) : "00";
                string YearInd    = "N";
                string MonthInd   = "N";
                string YearCheck  = data.YearCheck;
                string MonthCheck = data.MonthCheck;
                string LastNumber = data.LastNumber;
                //data.MasterID = YearFilter.ID;
                data.MasterCode = YearFilter.Code;
                if (YearFilter != null)
                {
                    YearInd  = YearFilter.YearInd;
                    MonthInd = YearFilter.MonthInd;
                }
                var newChild = Child.FirstOrDefault(f => f.ID == data.ID);
                if (YearInd == "N" && MonthInd == "N")
                {
                    if (newChild != null)
                    {
                        newChild.LastNumber      = data.LastNumber;
                        newChild.UpdatedBy       = userName;
                        newChild.UpdatedDate     = DateTime.UtcNow;
                        db.Entry(newChild).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        db.Sys_AutoGenerateIdChild.Add(new Sys_AutoGenerateIdChild()
                        {
                            //MasterID = data.MasterID,
                            MasterCode  = data.MasterCode,
                            LastNumber  = data.LastNumber,
                            Status      = "O",
                            MM          = "00",
                            YY          = "00",
                            CreatedBy   = userName,
                            CreatedDate = DateTime.UtcNow
                        });
                    }
                }
                else if (YearInd == "Y" && MonthInd == "N")
                {
                    if (newChild != null)
                    {
                        newChild.LastNumber      = data.LastNumber;
                        newChild.UpdatedBy       = userName;
                        newChild.UpdatedDate     = DateTime.UtcNow;
                        db.Entry(newChild).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Sys_AutoGenerateIdChild.Add(new Sys_AutoGenerateIdChild()
                        {
                            //MasterID = data.MasterID,
                            MasterCode  = data.MasterCode,
                            LastNumber  = data.LastNumber,
                            Status      = "O",
                            MM          = "00",
                            YY          = data.YearCheck,
                            CreatedBy   = userName,
                            CreatedDate = DateTime.UtcNow
                        });
                    }
                }
                else if (YearInd == "Y" && MonthInd == "Y")
                {
                    if (newChild != null)
                    {
                        newChild.LastNumber      = data.LastNumber;
                        newChild.UpdatedBy       = userName;
                        newChild.UpdatedDate     = DateTime.UtcNow;
                        db.Entry(newChild).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        db.Sys_AutoGenerateIdChild.Add(new Sys_AutoGenerateIdChild()
                        {
                            //MasterID = data.MasterID,
                            MasterCode  = data.MasterCode,
                            LastNumber  = data.LastNumber,
                            Status      = "O",
                            MM          = data.MonthCheck,
                            YY          = data.YearCheck,
                            CreatedBy   = userName,
                            CreatedDate = DateTime.UtcNow
                        });
                    }
                }
                db.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                glog.Error(ex.Message);
                return(false);
            }
        }
コード例 #3
0
        public static SysAutoGenerateReturn GetSystemID(string Group, string Code, string Year, string Month)
        {
            SysAutoGenerateReturn data = new SysAutoGenerateReturn();

            if (Month != null)
            {
                if ((Convert.ToInt32(Month) <= 9) && Month.Length != 2)
                {
                    Month = "0" + Month;
                }
            }
            using (var db = new MainDbContext())
            {
                var Master = db.Sys_AutoGenerateIdMaster.Where(f => f.Group == Group && f.Code == Code && f.Status == "O");
                var Child  = db.Sys_AutoGenerateIdChild;
                IQueryable <Sys_AutoGenerateIdChild> qChild = null;
                var    YearFilter = Master.FirstOrDefault();             // ? Year.Substring(Year.Length - 2) : "00";
                string YearInd    = "N";
                string MonthInd   = "N";
                string YearCheck  = "00";
                string MonthCheck = "00";
                string LastNumber = "0";
                //data.MasterID = YearFilter.ID;
                data.MasterCode = YearFilter.Code;
                string Prefix = null; string PrefixPosition = null; string PrefixSeperator = null;
                if (YearFilter != null)
                {
                    //qChild = Child.Where(f => f.MasterID == YearFilter.ID);
                    qChild    = Child.Where(f => f.MasterCode == YearFilter.Code);
                    YearInd   = YearFilter.YearInd;
                    MonthInd  = YearFilter.MonthInd;
                    YearCheck = Year.Substring(Year.Length - 2);
                }

                #region CheckYY
                if (YearInd == "N" && MonthInd == "N")
                {
                    var newChild = qChild.FirstOrDefault();
                    if (newChild != null)
                    {
                        data.ID    = newChild.ID;
                        YearCheck  = newChild.YY;
                        MonthCheck = newChild.MM;
                        LastNumber = newChild.LastNumber;
                    }
                    else
                    {
                        LastNumber = "0";
                    }
                }
                else if (YearInd == "Y" && MonthInd == "N")
                {
                    var newChild = qChild.FirstOrDefault(f => f.YY == YearCheck);
                    if (newChild != null)
                    {
                        data.ID    = newChild.ID;
                        YearCheck  = newChild.YY;
                        LastNumber = newChild.LastNumber;
                    }
                    else
                    {
                        //YearCheck = Year;
                        LastNumber = "0";
                    }
                }
                else if (YearInd == "Y" && MonthInd == "Y")
                {
                    var newChild = qChild.FirstOrDefault(f => f.YY == YearCheck && f.MM == Month);
                    if (newChild != null)
                    {
                        data.ID    = newChild.ID;
                        YearCheck  = newChild.YY;
                        MonthCheck = newChild.MM;
                        LastNumber = newChild.LastNumber;
                    }
                    else
                    {
                        MonthCheck = Month;
                        LastNumber = "0";
                    }
                }

                #endregion

                #region CheckMM
                if (MonthInd == "Y")
                {
                    var newChild = qChild.FirstOrDefault(f => f.MM == Month);
                    if (newChild != null)
                    {
                        data.ID    = newChild.ID;
                        MonthCheck = newChild.MM;
                        LastNumber = newChild.LastNumber;
                    }
                    else
                    {
                        MonthCheck = Month;
                        LastNumber = "0";
                    }
                }
                else if (YearInd == "N" && MonthInd == "Y")
                {
                    var newChild = qChild.FirstOrDefault(f => f.MM == Month);
                    if (newChild != null)
                    {
                        data.ID    = newChild.ID;
                        MonthCheck = newChild.MM;
                        LastNumber = newChild.LastNumber;
                    }
                    else
                    {
                        MonthCheck = Month;
                        LastNumber = "0";
                    }
                }
                else
                {
                    var newChild = qChild.FirstOrDefault();
                    if (newChild != null)
                    {
                        data.ID    = newChild.ID;
                        MonthCheck = newChild.MM;
                        LastNumber = newChild.LastNumber;
                    }
                }
                #endregion

                #region CheckPrefix
                Prefix = YearFilter.Prefix;
                #endregion

                #region CheckPrefixPosition
                PrefixPosition = YearFilter.PrefixPosition;
                #endregion

                #region PrefixSeperator
                PrefixSeperator = YearFilter.PrefixSeparator != null ? (PrefixPosition == "L" ? (Prefix + YearFilter.PrefixSeparator) : YearFilter.PrefixSeparator + Prefix) : Prefix;
                #endregion

                string Number        = null;
                string YearIndNumber = null;

                #region YearIndCheck
                if (YearInd == "Y")
                {
                    string YearSeperator = YearFilter.YearSeparator != null ? YearFilter.YearSeparator : "";
                    YearIndNumber = YearCheck + YearSeperator;
                }
                #endregion
                string MonthSeperator = YearFilter.MonthSeparator != null ? YearFilter.MonthSeparator : "";
                #region CheckMonthInd
                string MonthNumber = MonthCheck == "00" ? "" : MonthCheck;
                if (YearInd == "N" && MonthInd == "Y")
                {
                    Number = MonthNumber + MonthSeperator;
                }
                else if (YearInd == "Y" && MonthInd == "Y")
                {
                    Number = YearIndNumber + MonthNumber + MonthSeperator;
                }
                else if (YearInd == "Y" && MonthInd == "N")
                {
                    Number = YearIndNumber + MonthNumber;
                }
                #endregion

                #region FinalNumber
                int Width = YearFilter.Width ?? 0;
                LastNumber = (Convert.ToInt32(LastNumber) + 1).ToString();
                int    TotalPadding = Width - ((Number == null ? 0 : Number.Length) + LastNumber.Length + PrefixSeperator.Length);
                string Final        = PrefixPosition == "L" ? (PrefixSeperator + Number + FormattedString(LastNumber, TotalPadding))
                                : (Number + FormattedString(LastNumber, TotalPadding) + PrefixSeperator);
                data.LastNumber = LastNumber;
                data.YearCheck  = YearCheck;
                data.MonthCheck = MonthCheck;
                data.NewId      = Final;
                return(data);

                #endregion
            }
        }