//自动创建契约津贴发放记录
        public static List<MonthlyContractAllowanceItem> AutoGenerateMonthlyContractAllowanceItems(int year, int month)
        {
            List<MonthlyContractAllowanceItem> list = new List<MonthlyContractAllowanceItem>();
            //获取正在执行的借款标准
            List<ContractAllowance> ContractAllowanceList = GetContractAllowances(year, month);
            foreach (ContractAllowance wa in ContractAllowanceList)
            {
                SalaryResult sr = SalaryResult.GetFromCache(wa.员工编号, year, month);
                //如果已经发上表工资
                if (sr != null)
                {
                    if (sr.企业排班天数 == 0) continue;

                    MonthlyContractAllowanceItem item = MonthlyContractAllowanceItem.AddMonthlyContractAllowanceItem(wa.员工编号, year, month);
                    item.姓名 = sr.姓名;
                    item.月津贴标准 = wa.月津贴额度;
                    item.应出勤天数 = sr.企业排班天数;
                    item.实际出勤天数 = sr.实际出勤天数;
                    item.实际发放金额 = Math.Round(wa.月津贴额度 * (sr.实际出勤天数 / sr.企业排班天数), 2);
                    item.Save();

                    list.Add(item);
                }
            }
            return list;
        }
        public static MonthlyContractAllowanceItem AddMonthlyContractAllowanceItem(string emplid, int year, int month)
        {
            MonthlyContractAllowanceItem item = GetMonthlyContractAllowanceItem(emplid, year, month);

            if (item == null)
            {
                item      = new MonthlyContractAllowanceItem();
                item.标识   = Guid.NewGuid();
                item.员工编号 = emplid;
                item.年    = year;
                item.月    = month;
                item.创建人  = AccessController.CurrentUser.姓名;
                item.创建时间 = DateTime.Now;
                item.Save();
            }
            return(item);
        }
        protected override void OnSaving()
        {
            if (this.期间 == null)
            {
                this.期间 = GetPeriod(年, 月);
            }

            MonthlyContractAllowanceItem found = GetMonthlyContractAllowanceItem(this.员工编号, this.期间);

            if (found != null && found.标识 != this.标识)
            {
                throw new Exception("已存在该员工的契约津贴发放记录,不能重复创建。");
            }
            else
            {
                base.OnSaving();
            }

            MONTHLY_CONTRACT_ALLOWANCEITEM_CACHE.Set(CacheKey, this, TimeSpan.FromHours(10));
        }
        public static MonthlyContractAllowanceItem GetMonthlyContractAllowanceItem(Guid id)
        {
            MonthlyContractAllowanceItem obj = (MonthlyContractAllowanceItem)Session.DefaultSession.GetObjectByKey(typeof(MonthlyContractAllowanceItem), id);

            return(obj);
        }