/// <summary> /// Open an Account record from the database. /// </summary> /// <param name="Id">The id (primary key) of the Account to open.</param> /// <remarks>Created: Theo Crous 14/11/2011</remarks> public override void OpenRecord(Int64 Id) { try { using (new CDS.Client.Desktop.Essential.UTL.WaitCursor()) { base.OpenRecord(Id); glxAccount = BL.GLX.GLX_Account.LoadByEntityId(Id, DataContext); sysEntity = BL.SYS.SYS_Entity.Load(glxAccount.EntityId, DataContext); //If you do this in one line the ddlSiteAccount_EditValueChanged fires and creates a new site account //this should not be done glxSiteAccount = BL.GLX.GLX_SiteAccount.LoadByAccount(glxAccount.EntityId, DataContext); if (glxSiteAccount != null) { //chkSystemAccount.Enabled = true; //if (glxSiteAccount.SystemDefaultAccount) //{ // ddlSiteAccountType.Enabled = false; //} fieldBudgetAmount.Visible = !glxAccount.AgingAccount; } chkControlAccount.Checked = sysEntity.CodeSub == "00000"; chkControlAccount.Enabled = false; //ddlType.Enabled = sysEntity.CodeSub == "00000"; //GET LOOKUP INFO tcgDetails_SelectedPageChanged(tcgDetails, null); } } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
/// <summary> /// The binding source is bound to a new instance of an Account. This is for the instances where a new record is to be created. /// </summary> /// <remarks>Created: Theo Crous 17/11/2011</remarks> protected override void OnNewRecord() { try { base.OnNewRecord(); glxAccount = BL.GLX.GLX_Account.New; sysEntity = BL.SYS.SYS_Entity.NewAccount; chkControlAccount.Checked = false; chkControlAccount.Enabled = true; chkAgingAccount.Enabled = true; btnRecon.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; AllowArchive = false; tcgDetails_SelectedPageChanged(tcgDetails, null); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
public static DB.SYS_Entity CreateORG_CompanySYS_Entity(byte typeId, string codeSub, string description, string name, DataContext dataContext) { DB.SYS_Entity sys_entity = null; switch (typeId) { case (byte)ORG.ORG_Type.Customer: sys_entity = SYS.SYS_Entity.NewCustomerAccountEntity; sys_entity.CodeMain = SYS.SYS_Entity.Load(ApplicationDataContext.Instance.SiteAccounts.Debtors.EntityId, dataContext).CodeMain; break; case (byte)ORG.ORG_Type.Supplier: sys_entity = SYS.SYS_Entity.NewSupplierAccountEntity; sys_entity.CodeMain = SYS.SYS_Entity.Load(ApplicationDataContext.Instance.SiteAccounts.Creditors.EntityId, dataContext).CodeMain; break; } sys_entity.CodeSub = codeSub; sys_entity.Description = description; sys_entity.Name = name; return(sys_entity); }
/// <summary> /// Archives the current bound item /// </summary> protected override void Archive() { base.Archive(); DB.GLX_Account glxAccount = (DB.GLX_Account)BindingSource.DataSource; DB.SYS_Entity sys_entity = BL.SYS.SYS_Entity.Load(((DB.GLX_Account)BindingSource.DataSource).EntityId, DataContext); if (!sys_entity.Archived) { try { //000 = Archived or Un-Archived //001 = Outstanding Balance //002 = Control Account //003 = Is Parent //004 = Parent is Archived int code = -1;/* Context.Database.SqlQuery<int>( * "DECLARE @return_value int" + Environment.NewLine + * "EXEC @return_value = [dbo].[spArchiveAccount]" + Environment.NewLine + * " @AccountId = " + glxAccount.Id + "," + Environment.NewLine + * " @Archive = 1" + Environment.NewLine + * "SELECT @return_value"); */ if (code.Equals(0)) { sys_entity.Archived = !sys_entity.Archived; btnArchive.Caption = sys_entity.Archived ? "Un-Archive" : "Archive"; } else if (code.Equals(1)) { Essential.BaseAlert.ShowAlert("Archive", "This account can not be archive." + Environment.NewLine + "\t• Account has outstanding balances.", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Information); } else if (code.Equals(2)) { Essential.BaseAlert.ShowAlert("Archive", "This account can not be archive." + Environment.NewLine + "\t• Account is a control account.", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Information); } else if (code.Equals(3)) { Essential.BaseAlert.ShowAlert("Archive", "This account can not be archive." + Environment.NewLine + "\t• Account is a parent for another account.", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Information); } else { } } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } } else { try { //TODO: Find a way to do this //returns 1 if sp was able to unarchive account int code = -1; /* Context.Database.SqlQuery<int>( * "DECLARE @return_value int" + Environment.NewLine + * "EXEC @return_value = [dbo].[spArchiveAccount]" + Environment.NewLine + * " @AccountId = " + glxAccount.Id + "," + Environment.NewLine + * " @Archive = 0" + Environment.NewLine + * "SELECT @return_value"); */ if (code.Equals(0)) { sys_entity.Archived = !sys_entity.Archived; btnArchive.Caption = sys_entity.Archived ? "Un-Archive" : "Archive"; } else if (code.Equals(4)) { Essential.BaseAlert.ShowAlert("Un-Archive", "This account can not be archive." + Environment.NewLine + "\t• Accounts parent account is archived.", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Information); } else { Essential.BaseAlert.ShowAlert("Archive", "Account could not be un-archived.", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Information); } } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } } }
public override void OpenRecord(long Id) { base.OpenRecord(Id); sysEntity = BL.SYS.SYS_Entity.Load(Id, DataContext); }
public static DB.SYS_Entity GetPreviousItem(DB.SYS_Entity entry, DataContext dataContext) { return(dataContext.EntitySystemContext.SYS_Entity.OrderByDescending(o => o.Name).FirstOrDefault(n => n.Name.CompareTo(entry.Name) < 0 && n.TypeId == entry.TypeId)); }
protected override bool SaveSuccessful() { try { using (new CDS.Client.Desktop.Essential.UTL.WaitCursor()) { this.OnSaveRecord(); if (!IsValid) { return(false); } //orgCompany.StatementPreference = ""; //for (int i = 0; i < clbStatementPreference.ItemCount; i++) //{ // string value = (clbStatementPreference.GetItem(i) as DB.ORG_StatementPreference).Id.ToString(); // orgCompany.StatementPreference = String.Format("{0}{1}", orgCompany.StatementPreference, clbStatementPreference.GetItemChecked(i) ? value + "," : ""); //} try { using (TransactionScope transaction = DataContext.GetTransactionScope()) { //Link the ORG_Company entities to the ORG_Entity's SYS_Entity if (orgSalesContact != null) { orgSalesContact.IsDefault = true; orgSalesContact.CompanyId = orgEntitysysEntity.Id; } if (orgAccountsContact != null) { orgAccountsContact.IsDefault = true; orgAccountsContact.CompanyId = orgEntitysysEntity.Id; } if (OldSalesContact != null && ddlSalesContact.EditValue != null && OldSalesContact != Convert.ToInt64(ddlSalesContact.EditValue)) { BL.ORG.ORG_Contact.RemoveContact(OldSalesContact.Value, DataContext); } if (OldAccountsContact != null && ddlAccountContact.EditValue != null && OldAccountsContact != Convert.ToInt64(ddlAccountContact.EditValue)) { BL.ORG.ORG_Contact.RemoveContact(OldAccountsContact.Value, DataContext); } if (IsNew) { //Maybe dont allow change of SYS_Entity BL.EntityController.SaveSYS_Entity(orgEntitysysEntity, DataContext); DataContext.SaveChangesEntitySystemContext(); BL.EntityController.SaveORG_Company(orgCompany, DataContext); DataContext.SaveChangesEntityOrganisationContext(); BL.EntityController.SaveSYS_Address(sysBillingAddress, DataContext); BL.EntityController.SaveSYS_Address(sysShippingAddress, DataContext); DataContext.SaveChangesEntitySystemContext(); //Links the SYS_Access entities to the ORG_CompanyAddress entities orgBillingAddress.AddressId = sysBillingAddress.Id; orgShippingAddress.AddressId = sysShippingAddress.Id; BL.EntityController.SaveORG_CompanyAddress(orgBillingAddress, DataContext); BL.EntityController.SaveORG_CompanyAddress(orgShippingAddress, DataContext); //Save changes to the ORG_Company Entity BL.EntityController.SaveORG_Company(orgCompany, DataContext); DataContext.SaveChangesEntityOrganisationContext(); BL.ORG.ORG_History.GenerateCompanyHistory(orgCompany, DataContext); //If the GLX Module is accessable add and link GLX_Account and SYS_Entity to ORG_Company if (BL.ApplicationDataContext.Instance.Modules.Any(n => n.Id == (byte)BL.SYS.SYS_Modules.GLX && n.Code == "YES")) { DB.GLX_Account glxAccount = BL.GLX.GLX_Account.New; DB.SYS_Entity sysEntityAccount = BL.SYS.SYS_Entity.NewAccount; glxAccount.AgingAccount = true; switch (Type) { case BL.ORG.ORG_Type.Customer: DB.GLX_Account glxDebtor = BL.GLX.GLX_Account.LoadByEntityId(BL.ApplicationDataContext.Instance.SiteAccounts.Debtors.EntityId, DataContext); DB.SYS_Entity sysDebtor = BL.SYS.SYS_Entity.Load(BL.ApplicationDataContext.Instance.SiteAccounts.Debtors.EntityId, DataContext); sysEntityAccount.CodeMain = sysDebtor.CodeMain; glxAccount.AccountTypeId = glxDebtor.AccountTypeId; glxAccount.MasterControlId = sysDebtor.Id; break; case BL.ORG.ORG_Type.Supplier: DB.GLX_Account glxCreditor = BL.GLX.GLX_Account.LoadByEntityId(BL.ApplicationDataContext.Instance.SiteAccounts.Creditors.EntityId, DataContext); DB.SYS_Entity sysCreditor = BL.SYS.SYS_Entity.Load(BL.ApplicationDataContext.Instance.SiteAccounts.Creditors.EntityId, DataContext); sysEntityAccount.CodeMain = sysCreditor.CodeMain; glxAccount.AccountTypeId = glxCreditor.AccountTypeId; glxAccount.MasterControlId = sysCreditor.Id; break; } sysEntityAccount.CodeSub = orgEntitysysEntity.CodeSub; sysEntityAccount.Description = orgEntitysysEntity.Description; sysEntityAccount.Name = orgEntitysysEntity.Name; sysEntityAccount.ShortName = orgEntitysysEntity.ShortName; BL.EntityController.SaveSYS_Entity(sysEntityAccount, DataContext); DataContext.SaveChangesEntitySystemContext(); glxAccount.EntityId = sysEntityAccount.Id; //ControlId Represents the Rollup Account //on New Accounts it is its own control glxAccount.ControlId = sysEntityAccount.Id; BL.EntityController.SaveGLX_Account(glxAccount, DataContext); DataContext.SaveChangesEntityAccountingContext(); //orgCompany.AccountId = sysEntityAccount.Id; DataContext.SaveChangesEntityOrganisationContext(); } DataContext.SaveChangesEntityOrganisationContext(); DataContext.SaveChangesEntityAccountingContext(); DataContext.SaveChangesEntitySystemContext(); } else { if (orgEntitysysEntity.ChangeList.Contains("Name") && BL.ApplicationDataContext.Instance.Modules.Any(n => n.Id == (byte)BL.SYS.SYS_Modules.GLX && n.Code == "YES")) { BL.SYS.SYS_Entity.AllignCompanyAccountNames(orgEntitysysEntity, DataContext); } DataContext.SaveChangesEntityOrganisationContext(); DataContext.SaveChangesEntityAccountingContext(); DataContext.SaveChangesEntitySystemContext(); orgCompany.HasChanges = false; } DataContext.CompleteTransaction(transaction); } DataContext.EntityOrganisationContext.AcceptAllChanges(); DataContext.EntityAccountingContext.AcceptAllChanges(); DataContext.EntitySystemContext.AcceptAllChanges(); return(true); } catch (Exception ex) { DataContext.EntityOrganisationContext.RejectChanges(); DataContext.EntityAccountingContext.RejectChanges(); DataContext.EntitySystemContext.RejectChanges(); HasErrors = true; if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } return(false); } } } catch (Exception ex) { HasErrors = true; CurrentException = ex; if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } return(false); } }