Esempio n. 1
0
        public bool SaveBudget(decimal ruleCategoryId, int year, LeaveBudgetProxy proxy)
        {
            using (NHibernateSessionManager.Instance.BeginTransactionOn())
            {
                try
                {
                    DateTime fromDate, toDate;
                    if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        fromDate = Utility.ToMildiDate(String.Format("{0}/01/01", year));
                        toDate   = Utility.ToMildiDate(String.Format("{0}/12/{1}", year, Utility.GetEndOfPersianMonth(year, 12)));
                    }
                    else
                    {
                        fromDate = new DateTime(year, 1, 1);
                        toDate   = new DateTime(year, 12, Utility.GetEndOfMiladiMonth(year, 12));
                    }

                    objectRep.DeleteExistingBudget(ruleCategoryId, fromDate, toDate);


                    if (proxy.BudgetType == BudgetType.Usual)
                    {
                        Budget budget = new Budget();
                        budget.Date         = fromDate;
                        budget.RuleCategory = new RuleCategory()
                        {
                            ID = ruleCategoryId
                        };
                        budget.Type        = BudgetType.Usual;
                        budget.Description = proxy.Description;
                        budget.Day         = Utility.ToInteger(proxy.TotoalDay);
                        budget.Minute      = Utility.RealTimeToIntTime(proxy.TotoalTime);
                        this.SaveChanges(budget, UIActionType.ADD);
                        //

                        /* int day = Utility.ToInteger(proxy.TotoalDay) / 12;
                         * int minutes = ((Utility.ToInteger(proxy.TotoalDay) - day) * 480) / 12;
                         * for (int i = 0; i < 12; i++)
                         * {
                         *   Budget budget = new Budget();
                         *   if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                         *   {
                         *       budget.Date = Utility.ToMildiDate(String.Format("{0}/{1}/01", year, i + 1));
                         *   }
                         *   else
                         *   {
                         *       budget.Date = fromDate.AddMonths(i);
                         *   }
                         *   //budget.Date = fromDate.AddMonths(i);
                         *   budget.RuleCategory = new RuleCategory() { ID = ruleCategoryId };
                         *   budget.Type = BudgetType.PerMonth;
                         *   budget.Description = Utility.IsEmpty(proxy.Description) ? String.Empty : proxy.Description;
                         *   budget.Day = day;
                         *   budget.Minute = minutes;
                         *   this.SaveChanges(budget, UIActionType.ADD);
                         * }*/
                    }
                    else if (proxy.BudgetType == BudgetType.PerMonth)
                    {
                        for (int i = 0; i < 12; i++)
                        {
                            Budget budget = new Budget();
                            if (BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                            {
                                budget.Date = Utility.ToMildiDate(String.Format("{0}/{1}/01", year, i + 1));
                            }
                            else
                            {
                                budget.Date = fromDate.AddMonths(i);
                            }
                            //budget.Date = fromDate.AddMonths(i);
                            budget.RuleCategory = new RuleCategory()
                            {
                                ID = ruleCategoryId
                            };
                            budget.Type        = BudgetType.PerMonth;
                            budget.Description = Utility.IsEmpty(proxy.Description) ? String.Empty : proxy.Description;
                            budget.Day         = proxy[i].Day;
                            budget.Minute      = proxy[i].Minute;
                            this.SaveChanges(budget, UIActionType.ADD);
                        }
                    }

                    NHibernateSessionManager.Instance.CommitTransactionOn();
                    return(true);
                }
                catch (Exception ex)
                {
                    NHibernateSessionManager.Instance.RollbackTransactionOn();
                    LogException(ex, "BLeave", "SaveBudget");
                    throw ex;
                }
            }
        }