public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity) { base.BeforeApplyChanges(dbHelper, entity); //DebugHelper.Break(); if (entity.ChangeStatus == "Add") { var configs = dbHelper.GetCount("ps.Config", ""); if (configs > 0) { throw new AfwException("امکان ثبت بیش از یک رکورد نیست."); } } }
public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity) { base.BeforeApplyChanges(dbHelper, entity); if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify)) { var redundantExists = dbHelper.EntityExists("cmn.FinancialYear", string.Format("YearNo = '{0}' and ID <> '{1}'", entity.GetFieldValue <string>("YearNo"), entity.GetFieldValue <Guid>("ID"))); if (redundantExists) { throw new AfwException("این سال مالی قبلا ثبت شده است."); } } if (entity.ChangeStatus == EntityChangeTypes.Modify) { if (dbHelper.GetCount("acc.AccDoc", string.Format("FinancialYear = '{0}'", entity.GetFieldValue <Guid>("ID"))) != 0) { var oldFinancialYear = dbHelper.FetchSingleByID("cmn.FinancialYear", entity.GetFieldValue <Guid>("ID"), null); if (oldFinancialYear.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeGhatei") != entity.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeGhatei") || oldFinancialYear.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeGhateiePishnevis") != entity.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeGhateiePishnevis") || oldFinancialYear.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeMovaghateAsli") != entity.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeMovaghateAsli") || oldFinancialYear.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeGhateieAsli") != entity.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeGhateieAsli") || oldFinancialYear.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeMovaghatePishnevis") != entity.GetFieldValue <int?>("AccSetting_ShomareShorooeAsnadeMovaghatePishnevis") || oldFinancialYear.GetFieldValue <bool>("AccSetting_ShomareDehieMojazaBeAsnadeGhateieAsli") != entity.GetFieldValue <bool>("AccSetting_ShomareDehieMojazaBeAsnadeGhateieAsli")) { throw new AfwException("بدلیل وجود سند حسابداری امکان تغییر تنظیمات سال مالی وجود ندارد."); } } } }
public override void BeforeApplyChanges(EntityDbHelper dbHelper, Entity entity) { base.BeforeApplyChanges(dbHelper, entity); if (entity.ChangeStatus.IsIn(EntityChangeTypes.Add, EntityChangeTypes.Modify)) { string parentAccountCondition = ""; if (entity.GetFieldValue <Guid?>("ParentAccount") == null) { parentAccountCondition = " and ParentAccount is null"; } else { parentAccountCondition = " and ParentAccount = '" + entity.GetFieldValue <Guid?>("ParentAccount") + "'"; } var redundantExists = dbHelper.GetCount("acc.account", string.Format("Code = '{0}' and FinancialYear = '{1}' and AccountLevel = '{2}' {3}", entity.GetFieldValue <string>("Code"), entity.GetFieldValue <Guid>("FinancialYear"), entity.GetFieldValue <Guid>("AccountLevel"), parentAccountCondition)); if (entity.ChangeStatus == EntityChangeTypes.Add) { if (redundantExists > 0) { throw new AfwException("کد تکراری ، این کد حساب قبلا ثبت شده است."); } } else if (entity.ChangeStatus == EntityChangeTypes.Modify) { if (redundantExists > 1) { throw new AfwException("کد تکراری ، این کد حساب قبلا ثبت شده است."); } } } }