Example #1
0
        public string GetNewCode(Guid codeTitleId, Data.AccountingMoeinDetail parentAmd)
        {
            try
            {
                IQueryable <Guid?> coParentAmdIds = null;
                if (parentAmd != null)
                {
                    // پیدا کردن رکوردهای هم کد با والد
                    coParentAmdIds = this.GetByIdIn(parentAmd.IdIn, parentAmd.IdCodeTitle.ToGUID()).Select(r => r.IdAccountingMoein);
                }


                var codeTitle = Business.GetCodeTitleBusiness().GetById(codeTitleId);

                var amds = this.GetAll().Where(r => r.IdCodeTitle == codeTitle.Id);

                if (coParentAmdIds != null && coParentAmdIds.Any())
                {
                    amds = coParentAmdIds.Join(amds, o => o, i => i.IdAccountingMoein, (o, i) => new { i = i }).Select(r => r.i);
                }

                amds = amds.OrderByDescending(r => r.LastEdit);

                var amd = amds.FirstOrDefault();
                if (amd == null)
                {
                    return(codeTitle.CodeStart.ToInt().ToString().Calibrate('0', codeTitle.CodeLen.ToInt()));
                }

                var idin = amd.IdIn.ToInt() + 1;
                var code = idin.ToString().Calibrate('0', codeTitle.CodeLen.ToInt());
                while (this.GetByIdIn(code, codeTitle.Id).Any())
                {
                    code = (++idin).ToString().Calibrate('0', codeTitle.CodeLen.ToInt());
                }

                return(code);
            }
            catch
            {
                throw;
            }
        }
Example #2
0
        private Data.AccountingMoeinDetail SaveKol()
        {
            try
            {
                var    accountingMoeinDetailBusiness = Business.GetAccountingMoeinDetailBusiness();
                var    kols       = new List <Data.AccountingMoeinDetail>();
                string oldKolCode = null;

                //edit mode
                var kol = accountingMoeinDetailBusiness.GetByAccountingMoeinDetailId(AccountingMoeinId, Common.Constants.CodeTitle.Kol).FirstOrDefault();
                if (kol == null)
                {
                    kol = new Data.AccountingMoeinDetail()
                    {
                        IdAccountingMoein = AccountingMoeinId, IdCodeTitle = Common.Constants.CodeTitle.Kol
                    }
                }
                ;
                else
                {
                    oldKolCode = kol.IdIn;
                }

                PrepareKol(kol);
                kols.Add(kol);

                if (oldKolCode != null)
                {
                    var otherKols = accountingMoeinDetailBusiness.GetByIdIn(oldKolCode, Common.Constants.CodeTitle.Kol).Where(r => r.IdAccountingMoein != AccountingMoeinId).ToList();
                    otherKols.ForEach(r => PrepareGroup(r));
                    kols.AddRange(otherKols);
                }

                accountingMoeinDetailBusiness.Save(kols);
                return(kol);
            }
            catch
            {
                throw;
            }
        }
Example #3
0
        private Data.AccountingMoeinDetail SaveMoein()
        {
            try
            {
                var    accountingMoeinDetailBusiness = Business.GetAccountingMoeinDetailBusiness();
                var    moeins       = new List <Data.AccountingMoeinDetail>();
                string oldMoeinCode = null;

                //edit mode
                var moein = accountingMoeinDetailBusiness.GetByAccountingMoeinDetailId(AccountingMoeinId, Common.Constants.CodeTitle.Moein).FirstOrDefault();
                if (moein == null)
                {
                    moein = new Data.AccountingMoeinDetail()
                    {
                        IdAccountingMoein = AccountingMoeinId, IdCodeTitle = Common.Constants.CodeTitle.Moein
                    }
                }
                ;
                else
                {
                    oldMoeinCode = moein.IdIn;
                }
                PrepareMoein(moein);
                moeins.Add(moein);

                if (oldMoeinCode != null)
                {
                    var otherMoeins = accountingMoeinDetailBusiness.GetByIdIn(oldMoeinCode, Common.Constants.CodeTitle.Moein).Where(r => r.IdAccountingMoein != AccountingMoeinId).ToList();
                    otherMoeins.ForEach(r => PrepareMoein(r));
                    moeins.AddRange(otherMoeins);
                }

                accountingMoeinDetailBusiness.Save(moein);
                return(moein);
            }
            catch
            {
                throw;
            }
        }
Example #4
0
        private Data.AccountingMoeinDetail SaveGroup()
        {
            try
            {
                var    accountingMoeinDetailBusiness = Business.GetAccountingMoeinDetailBusiness();
                var    groups       = new List <Data.AccountingMoeinDetail>();
                var    group        = new Data.AccountingMoeinDetail();
                string oldGroupIdIn = null;
                //edit mode
                group = accountingMoeinDetailBusiness.GetByAccountingMoeinDetailId(AccountingMoeinId, Common.Constants.CodeTitle.Goruh).FirstOrDefault();
                if (group == null)
                {
                    group = new AccountingMoeinDetail()
                    {
                        IdAccountingMoein = AccountingMoeinId, IdCodeTitle = Common.Constants.CodeTitle.Goruh
                    }
                }
                ;
                else
                {
                    oldGroupIdIn = group.IdIn;
                }
                PrepareGroup(group);
                groups.Add(group);

                if (oldGroupIdIn != null)
                {
                    var otherGroups = accountingMoeinDetailBusiness.GetByIdIn(oldGroupIdIn, Common.Constants.CodeTitle.Goruh).Where(r => r.IdAccountingMoein != AccountingMoeinId).ToList();
                    otherGroups.ForEach(r => PrepareGroup(r));
                    groups.AddRange(otherGroups);
                }

                accountingMoeinDetailBusiness.Save(groups);
                return(group);
            }
            catch
            {
                throw;
            }
        }