Пример #1
0
        protected override void Update()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                List <SearchCondition> conditions = new List <SearchCondition>();
                conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.PKLeaveInfoID, PKLeaveInfoID.ToString(), SearchComparator.Equal, SearchType.SearchString));
                CommonDAL <LeaveInfo> .Update(this, conditions);

                foreach (TimeDurationInfo item in timeDurationList)
                {
                    if (item.IsNew)
                    {
                        item.FKLeaveInfoID = this.PKLeaveInfoID;
                    }
                    item.Save();
                }

                //#region For transact unit test
                //throw new Exception();
                //#endregion

                if (this.PreStatus != LeaveStatus.Accepted && this.Status == LeaveStatus.Accepted ||
                    this.status == LeaveStatus.Rejected && this.PreStatus == LeaveStatus.Accepted)
                {
                    int    year;
                    double usedHours = GetDurationHours(timeDurationList, out year);

                    if (usedHours != 0 && year != 0)
                    {
                        conditions.Clear();
                        conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKEmployeeID, FKSubmitEmployeeID.ToString(), SearchComparator.Equal, SearchType.SearchString));
                        conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKLeaveTypeID, FKLeaveTypeID.ToString(), SearchComparator.Equal, SearchType.SearchString));
                        conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Year, year.ToString(), SearchComparator.Equal, SearchType.SearchNotString));
                        EmployeeLeaveSummary leaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions);

                        if (null == leaveSummary)
                        {
                            leaveSummary = EmployeeLeaveSummary.CreateEmployeeLeaveSummary(FKSubmitEmployeeID, FKLeaveTypeID, year);
                        }
                        if (this.status == LeaveStatus.Rejected)
                        {
                            usedHours = -usedHours;
                        }

                        leaveSummary.UsedHours += usedHours;

                        if (leaveSummary.UsedHours < 0)
                        {
                            leaveSummary.UsedHours = 0;                             // used hours cannot be a negative number
                        }
                        leaveSummary.Save();
                    }
                }

                ts.Complete();
            }
        }
Пример #2
0
        protected override void Insert()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                CommonDAL <LeaveInfo> .Insert(this);

                foreach (TimeDurationInfo item in timeDurationList)
                {
                    item.FKLeaveInfoID = this.PKLeaveInfoID;
                    item.Save();
                }

                //#region For transact unit test
                //throw new Exception();
                //#endregion

                // When the leave is accepted, update the employee leave summary.
                if (this.Status == LeaveStatus.Accepted)
                {
                    int    year;
                    double usedHours = GetDurationHours(timeDurationList, out year);

                    if (usedHours != 0 && year != 0)
                    {
                        List <SearchCondition> conditions = new List <SearchCondition>();
                        conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKEmployeeID, FKSubmitEmployeeID.ToString(), SearchComparator.Equal, SearchType.SearchString));
                        conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.FKLeaveTypeID, FKLeaveTypeID.ToString(), SearchComparator.Equal, SearchType.SearchString));
                        conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Year, year.ToString(), SearchComparator.Equal, SearchType.SearchNotString));
                        EmployeeLeaveSummary leaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions);

                        if (null == leaveSummary)
                        {
                            leaveSummary = EmployeeLeaveSummary.CreateEmployeeLeaveSummary(FKSubmitEmployeeID, FKLeaveTypeID, year);
                        }
                        leaveSummary.UsedHours += usedHours;
                        leaveSummary.Save();
                    }
                }

                ts.Complete();
            }
        }