Esempio n. 1
0
        public void ExchangePerson(decimal personId1, decimal personId2, string date1, string date2)
        {
            UIValidationExceptions exception = new UIValidationExceptions();

            if (personId1 == 0 || personId2 == 0)
            {
                exception.Add(ExceptionResourceKeys.ExceptionShiftPersonIdRequierd, "شناسه پرسنل مشخص نشده است", ExceptionSrc);
            }

            if (exception.Count > 0)
            {
                throw exception;
            }
            using (NHibernateSessionManager.Instance.BeginTransactionOn())
            {
                try
                {
                    DateTime dayDate1, dayDate2;
                    if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        dayDate1 = Utility.ToMildiDate(date1);
                        dayDate2 = Utility.ToMildiDate(date2);
                    }
                    else
                    {
                        dayDate1 = Utility.ToMildiDateTime(date1);
                        dayDate2 = Utility.ToMildiDateTime(date2);
                    }

                    objectRep.DeleteExceptionShift(personId1, dayDate1, dayDate1);
                    objectRep.DeleteExceptionShift(personId1, dayDate2, dayDate2);
                    objectRep.DeleteExceptionShift(personId2, dayDate2, dayDate2);
                    objectRep.DeleteExceptionShift(personId2, dayDate1, dayDate1);

                    ShiftRepository shiftRep = new ShiftRepository();
                    decimal?        shift1   = shiftRep.GetShiftIdByPersonId(personId1, dayDate1);
                    decimal?        shift2   = shiftRep.GetShiftIdByPersonId(personId2, dayDate2);

                    ShiftException exShift = new ShiftException();
                    exShift.RegistrationDate = DateTime.Now.Date;
                    exShift.Date             = dayDate1;
                    exShift.Person           = new Person()
                    {
                        ID = personId2
                    };
                    exShift.UserID = BUser.CurrentUser.ID;
                    if (shift1 != null && shift1 > 0)
                    {
                        exShift.Shift = new Shift()
                        {
                            ID = (decimal)shift1
                        };
                    }
                    else
                    {
                        exShift.Shift = null;
                    }
                    base.SaveChanges(exShift, UIActionType.ADD);

                    exShift = new ShiftException();
                    exShift.RegistrationDate = DateTime.Now.Date;
                    exShift.Date             = dayDate2;
                    exShift.Person           = new Person()
                    {
                        ID = personId1
                    };
                    exShift.UserID = BUser.CurrentUser.ID;
                    if (shift2 != null && shift2 > 0)
                    {
                        exShift.Shift = new Shift()
                        {
                            ID = (decimal)shift2
                        };
                    }
                    else
                    {
                        exShift.Shift = null;
                    }
                    base.SaveChanges(exShift, UIActionType.ADD);

                    NHibernateSessionManager.Instance.CommitTransactionOn();
                }
                catch (Exception ex)
                {
                    NHibernateSessionManager.Instance.RollbackTransactionOn();
                    LogException(ex, "BExceptionShift", "ExchangePerson");
                    throw ex;
                }
            }
        }
Esempio n. 2
0
        public void ExchangeDayByWorkGroup(decimal workGroupId, string firstDay, string secondDay)
        {
            UIValidationExceptions exception = new UIValidationExceptions();

            if (workGroupId == 0)
            {
                exception.Add(ExceptionResourceKeys.ExceptionShiftWorkGroupIdRequierd, "شناسه گروه کاری مشخص نشده است", ExceptionSrc);
            }

            if (exception.Count > 0)
            {
                throw exception;
            }
            using (NHibernateSessionManager.Instance.BeginTransactionOn())
            {
                try
                {
                    DateTime firstDate, secondDate;
                    if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        firstDate  = Utility.ToMildiDate(firstDay);
                        secondDate = Utility.ToMildiDate(secondDay);
                    }
                    else
                    {
                        firstDate  = Utility.ToMildiDateTime(firstDay);
                        secondDate = Utility.ToMildiDateTime(secondDay);
                    }

                    ISearchPerson            searchTool = new BPerson();
                    PersonAdvanceSearchProxy proxy      = new PersonAdvanceSearchProxy();
                    proxy.WorkGroupId       = workGroupId;
                    proxy.WorkGroupFromDate = Utility.ToString(firstDate);
                    int            count   = searchTool.GetPersonInAdvanceSearchCount(proxy);
                    IList <Person> persons = searchTool.GetPersonInAdvanceSearch(proxy, 0, count);
                    foreach (Person prs in persons)
                    {
                        decimal personId = prs.ID;
                        objectRep.DeleteExceptionShift(personId, firstDate, firstDate);
                        objectRep.DeleteExceptionShift(personId, secondDate, secondDate);

                        ShiftRepository shiftRep = new ShiftRepository();
                        decimal?        shift1   = shiftRep.GetShiftIdByPersonId(personId, firstDate);
                        decimal?        shift2   = shiftRep.GetShiftIdByPersonId(personId, secondDate);

                        ShiftException exShift = new ShiftException();
                        exShift.RegistrationDate = DateTime.Now.Date;
                        exShift.Date             = secondDate;
                        exShift.Person           = new Person()
                        {
                            ID = personId
                        };
                        exShift.UserID = BUser.CurrentUser.ID;
                        if (shift1 != null && shift1 > 0)
                        {
                            exShift.Shift = new Shift()
                            {
                                ID = (decimal)shift1
                            };
                        }
                        else
                        {
                            exShift.Shift = null;
                        }
                        base.SaveChanges(exShift, UIActionType.ADD);

                        exShift = new ShiftException();
                        exShift.RegistrationDate = DateTime.Now.Date;
                        exShift.Date             = firstDate;
                        exShift.Person           = new Person()
                        {
                            ID = personId
                        };
                        exShift.UserID = BUser.CurrentUser.ID;
                        if (shift2 != null && shift2 > 0)
                        {
                            exShift.Shift = new Shift()
                            {
                                ID = (decimal)shift2
                            };
                        }
                        else
                        {
                            exShift.Shift = null;
                        }
                        base.SaveChanges(exShift, UIActionType.ADD);
                    }

                    NHibernateSessionManager.Instance.CommitTransactionOn();
                }
                catch (Exception ex)
                {
                    NHibernateSessionManager.Instance.RollbackTransactionOn();
                    LogException(ex, "BExceptionShift", "ExchangeDayByWorkGroup");
                    throw ex;
                }
            }
        }