示例#1
0
        public string GetNewCodeForHesab(Guid codeTitleId, Data.AccountingTafsillevelsDetail group)
        {
            try
            {
                var codeTitle = Business.GetCodeTitleBusiness().GetById(codeTitleId);
                if (group == null)
                {
                    return(codeTitle.CodeStart.ToInt().ToString().Calibrate('0', codeTitle.CodeLen.ToInt()));
                }

                var coIdAccountingTafsilLevels = this.GetByIdIn(group.IdIn, Common.Constants.CodeTitle.GoruheTafsili).Select(r => r.IdAccountingTafsilLevels).ToList();

                var atld = this.GetAll().Where(r => r.IdCodeTitle == codeTitleId && coIdAccountingTafsilLevels.Contains(r.IdAccountingTafsilLevels)).
                           OrderByDescending(r => r.LastEdit).FirstOrDefault();

                if (atld == null)
                {
                    return(codeTitle.CodeStart.ToInt().ToString().Calibrate('0', codeTitle.CodeLen.ToInt()));
                }

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

                return(code);
            }
            catch
            {
                throw;
            }
        }
示例#2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txt_grouh_tafsili.Text == "" || txt_onvane_hesab1.Text == "")
                {
                    throw new Exception(Localize.ex_all_item_mandatory);
                }

                var atldBusiness = Business.GetAccountingTafsilLevelDetailBusiness();
                var atlBusiness  = Business.GetAccountingTafsilLevelBusiness();
                var goldIdin     = string.Empty;
                var holdIdin     = string.Empty;

                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted,
                    Timeout = new TimeSpan(2, 0, 0)
                }))
                {
                    var atl = new Data.AccountingTafsilLevel();

                    if (!this.atlId.HasValue || this.atlId == Guid.Empty)
                    {
                        atlBusiness.Save(atl);
                        atlId = atl.Id;
                    }
                    else
                    {
                        atl = atlBusiness.GetById(this.atlId.Value);
                    }
                    var atlds = atldBusiness.GetByIdAccountingTafsilLevels(this.atlId.ToGUID()).ToList();

                    #region Goruh

                    var goruh = atlds.FirstOrDefault(r => r.IdCodeTitle == Common.Constants.CodeTitle.GoruheTafsili);

                    if (goruh == null)
                    {
                        goruh = new Data.AccountingTafsillevelsDetail()
                        {
                            IdAccountingTafsilLevels = atlId,
                            IdCodeTitle = Common.Constants.CodeTitle.GoruheTafsili
                        }
                    }
                    ;
                    else
                    {
                        goldIdin = goruh.IdIn;
                    }

                    PrepareGroup(goruh);

                    atldBusiness.Save(goruh);

                    #endregion

                    #region Hesab

                    var hesab = atlds.FirstOrDefault(r => r.IdCodeTitle == Common.Constants.CodeTitle.HesabTafsil);

                    if (hesab == null)
                    {
                        hesab = new Data.AccountingTafsillevelsDetail()
                        {
                            IdAccountingTafsilLevels = atlId,
                            IdCodeTitle = Common.Constants.CodeTitle.HesabTafsil
                        }
                    }
                    ;
                    else
                    {
                        holdIdin = hesab.IdIn;
                    }

                    PrepareHesab(hesab);

                    atldBusiness.Save(hesab);

                    #endregion

                    #region Update Other Groups

                    var otherGroups = atldBusiness.GetByIdIn(goruh.IdIn, Common.Constants.CodeTitle.GoruheTafsili).Where(r => r.Id != goruh.Id).ToList();
                    foreach (var item in otherGroups)
                    {
                        PrepareGroup(item);
                        atldBusiness.Save(item);
                    }

                    var otherHesabs = atldBusiness.GetByIdIn(hesab.IdIn, Common.Constants.CodeTitle.HesabTafsil).Where(r => r.Id != hesab.Id).ToList();
                    foreach (var item in otherHesabs)
                    {
                        PrepareHesab(item);
                        atldBusiness.Save(item);
                    }

                    #endregion

                    #region Accounting Tafsil Level

                    atl.IdIn = goruh.IdIn + hesab.IdIn;
                    atlBusiness.Save(atl);

                    var atls = atlBusiness.GetIdInStartWith(goruh.IdIn).ToList();
                    foreach (var item in atls)
                    {
                        item.IdIn = goruh.IdIn + item.IdIn.Remove(0, goruh.IdIn.Length);
                        atlBusiness.Save(item);
                    }

                    #endregion

                    scope.Complete();
                }

                this.Close();
            }
            catch (Exception ex)
            {
                AccountingKernel.Forms.Base.BaseWindow.ShowError(ex);
            }
        }