コード例 #1
0
ファイル: AccountForm.cs プロジェクト: tslekwadi/CDS
        /// <summary>
        /// Checks if you are running Lite or Orders version and if so limits you to 10 sub account
        /// </summary>
        /// <remarks>Created: Werner Scheffer 13/08/2013</remarks>
        private void txtCodeMain_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
        {
            //TODO: Remove CHIMERA Tags and make Pegasus LITE
#if (CHIMERA || CHIMERA_LITE || CHIMERA_ORDERS)
#if (CHIMERA_LITE || CHIMERA_ORDERS)
            Int64 total = BL.ApplicationContext.Instance.Context.GLX_Account.Where(n => n.SYS_Entity.CodeMain == txtCodeMain.Text).Count();

            if (total > 10)
            {
                Essential.BaseAlert.ShowAlert("Main Account limit", "Accounts are limited to ten sub accounts in Lite version", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Information);
                DB.GLX_Account glxAccount = (DB.GLX_Account)BindingSource.DataSource;
                glxAccount.SYS_Entity.CodeMain = "00000";
            }
#endif
#endif

            string codeMain        = e.NewValue.ToString();
            var    sysEntityParent = BL.SYS.SYS_Entity.LoadControlEntityByCode(codeMain, DataContext);

            if (sysEntityParent == null)
            {
                chkControlAccount.Enabled = true;
                chkAgingAccount.Enabled   = true;
                glxAccount.AccountTypeId  = 0;
                return;
            }

            var glxAccountParent = BL.GLX.GLX_Account.LoadByEntityId(sysEntityParent.Id, DataContext);

            //var glx_parent = from account in DataContext.EntityAccountingContext.GLX_Account
            //                 join entity in DataContext.EntitySystemContext.SYS_Entity
            //                 on account.EntityId equals entity.Id
            //                 where entity.CodeMain == e.NewValue && entity.CodeSub == "00000"
            //                 select new { account, entity };

            //if (glx_parent.Count() > 1)
            //    throw new Exception("Duplicate Accounts");

            // DataContext.EntityAccountingContext.GLX_Account.FirstOrDefault(n => n.SYS_Entity.CodeMain == e.NewValue && n.SYS_Entity.CodeSub == "00000");
            if (glxAccountParent != null)
            {
                glxAccount.AccountTypeId  = glxAccountParent.AccountTypeId; //DataContext.EntityAccountingContext.GLX_Account.FirstOrDefault(n => n.SYS_Entity.CodeMain == e.NewValue && n.SYS_Entity.CodeSub == "00000").AccountTypeId;
                chkControlAccount.Checked = false;
                chkControlAccount.Enabled = false;
                chkAgingAccount.Checked   = glxAccountParent.AgingAccount;
                chkAgingAccount.Enabled   = false;
                sysEntity.CodeMain        = sysEntityParent.CodeMain;
                glxAccount.AgingAccount   = glxAccountParent.AgingAccount;
                txtCodeMain.Refresh();
                txtCodeSub.Focus();
            }


            ddlType.Refresh();
        }
コード例 #2
0
        protected override void BindData()
        {
            base.BindData();
            EntityServerModeSourceTracking.QueryableSource = DataContext.EntitySystemContext.SYS_Tracking.Select(n => new { n.Id, TrackingNumber = n.Id, n.Initiator }).Distinct();


            //List<PaymentAccount> accounts = Essential.SystemSettingForm.DeSerializePaymentAccounts(DataAccessLayer.ApplicationContext.Instance.CompanySite.PaymentAccounts, typeof(List<GLX.PaymentAccount>));
            if (this.Tag is Accounting.Payment.MakePaymentsForm)
            {
                DB.SYS_Entity  entityAccount   = BL.SYS.SYS_Entity.Load(BL.ApplicationDataContext.Instance.SiteAccounts.Creditors.EntityId, DataContext);
                DB.GLX_Account creditorAccount = BL.GLX.GLX_Account.Load(entityAccount.Id, DataContext);

                ServerModeSourceCompanyAccount.QueryableSource = DataContext.ReadonlyContext.VW_Account.Where(n => n.Archived == false && n.ControlId == creditorAccount.Id);
                TabIcon = global::CDS.Shared.Resources.Properties.Resources.money_minus_32;
            }
            else if (this.Tag is Accounting.Payment.ReceivePaymentsForm)
            {
                DB.SYS_Entity  entityAccount  = BL.SYS.SYS_Entity.Load(BL.ApplicationDataContext.Instance.SiteAccounts.Debtors.EntityId, DataContext);
                DB.GLX_Account debtorsAccount = BL.GLX.GLX_Account.Load(entityAccount.Id, DataContext);
                ServerModeSourceCompanyAccount.QueryableSource = DataContext.ReadonlyContext.VW_Account.Where(n => n.Archived == false && n.ControlId == debtorsAccount.Id);
                TabIcon = global::CDS.Shared.Resources.Properties.Resources.money2_add_32;
            }
            else
            {
                ServerModeSourceCompanyAccount.QueryableSource = DataContext.ReadonlyContext.VW_Account.Where(n => n.Archived == false);
            }

            // ServerModeSourcePaymentAccount.QueryableSource = CDS.Client.DataAccessLayer.ApplicationContext.Instance.Context.GLX_Account.Where(n=> accounts.Select(l=>l.AccountId).Contains(n.Id));
            //Filter for master Accountants
            if (BL.ApplicationDataContext.Instance.AccessGranted(BL.SEC.AccessCodes.FIAARE))
            {
                ServerModeSourcePaymentAccount.QueryableSource = DataContext.ReadonlyContext.VW_Account.Where(n => PaymentAccounts.Contains(n.Id));
            }
            else
            {
                long?defaultSiteId = BL.ApplicationDataContext.Instance.LoggedInUser.DefaultSiteId;
                ServerModeSourcePaymentAccount.QueryableSource = DataContext.ReadonlyContext.VW_Account.Where(n => PaymentAccounts.Contains(n.Id) && n.SiteId == defaultSiteId);
            }
            ServerModeSourceAging.QueryableSource = DataContext.EntityAccountingContext.GLX_Aging;
        }
コード例 #3
0
ファイル: AccountForm.cs プロジェクト: tslekwadi/CDS
        /// <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;
                }
            }
        }
コード例 #4
0
ファイル: AccountForm.cs プロジェクト: tslekwadi/CDS
        /// <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;
                }
            }
        }
コード例 #5
0
 public static int GenerateAccountBalances(DB.GLX_Account Account, DataContext dataContext)
 {
     return(dataContext.EntityAccountingContext.ExecuteSqlCommand(string.Format("EXEC CDS_SYS.spGenerateAccountBalances {0},{1}", Account.EntityId, Account.AgingAccount ? 1 : 0)));
 }
コード例 #6
0
ファイル: AccountForm.cs プロジェクト: tslekwadi/CDS
        /// <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;
                    }
                }
            }
        }
コード例 #7
0
ファイル: AccountForm.cs プロジェクト: tslekwadi/CDS
        protected override bool SaveSuccessful()
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();

                    if (!IsValid)
                    {
                        return(false);
                    }

                    if (glxAccount.CenterId == -1)
                    {
                        glxAccount.CenterId = null;
                    }

                    //TODO: Improve this
                    DB.VW_Validation validationItem =
                        BL.ApplicationDataContext.Instance.ValidationRestrictions.Where(n =>
                                                                                        ((System.Windows.Forms.BindingSource)(txtName.DataBindings[0].DataSource)).DataSource.ToString().Split('.').Last().StartsWith(n.TableName) &&
                                                                                        n.ColumnName.Equals(txtName.DataBindings[0].BindingMemberInfo.BindingField)).FirstOrDefault();

                    ((DB.SYS_Entity)BindingSourceEntity.DataSource).ShortName = ((DB.SYS_Entity)BindingSourceEntity.DataSource).Name.Substring(0, validationItem.LengthMax.Value > txtName.Text.Length ? txtName.Text.Length : (int)validationItem.LengthMax.Value);


                    if (sysEntity.CodeSub != "00000")
                    {
                        DB.GLX_Account glxControlAccount = BL.GLX.GLX_Account.LoadControlAccountByCode(sysEntity.CodeMain, DataContext);
                        glxAccount.AgingAccount    = glxControlAccount.AgingAccount;
                        glxAccount.AccountTypeId   = glxControlAccount.AccountTypeId;
                        glxAccount.MasterControlId = glxControlAccount.EntityId;
                    }
                    else
                    {
                        if (ceSiteAccount.Checked)
                        {
                            glxAccount.SiteId = (long?)ddlSiteSelection.EditValue;
                        }
                    }

                    glxAccount.IsNewAccount = DataContext.EntityAccountingContext.GetEntityState(glxAccount) == System.Data.Entity.EntityState.Detached;
                    glxAccount.SiteAccount  = BindingSourceSiteAccount.DataSource as DB.GLX_SiteAccount;
                    if (glxAccount.SiteAccount != null)
                    {
                        glxAccount.SiteAccount.MakeSiteDefault = makeSiteDefault;
                    }

                    try
                    {
                        using (TransactionScope transaction = DataContext.GetTransactionScope())
                        {
                            BL.EntityController.SaveSYS_Entity(sysEntity, DataContext);
                            //Needs another check, Should only happen for ORG entities and not other accounts ie. Bank account, COS account etc
                            if (sysEntity.ChangeList.Contains("Name") && BL.ApplicationDataContext.Instance.Modules.Any(n => n.Id == (byte)BL.SYS.SYS_Modules.ORG && n.Code == "YES") && BL.ApplicationDataContext.Instance.SystemEntityContext.SYS_Entity.Any(n => n.CodeSub == sysEntity.CodeSub && n.TypeId == 3))
                            {
                                BL.SYS.SYS_Entity.AllignCompanyAccountNames(sysEntity, DataContext);
                            }
                            DataContext.SaveChangesEntitySystemContext();
                            glxAccount.EntityId = sysEntity.Id;
                            //ControlId Represents the Rollup Account
                            //on New Accounts it is its own control
                            glxAccount.ControlId = sysEntity.Id;
                            BL.EntityController.SaveGLX_Account(glxAccount, DataContext);
                            DataContext.SaveChangesEntityAccountingContext();
                            DataContext.SaveChangesEntitySystemContext();
                            DataContext.CompleteTransaction(transaction);
                        }
                        DataContext.EntityAccountingContext.AcceptAllChanges();
                        DataContext.EntitySystemContext.AcceptAllChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        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);
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
ファイル: BasePaymentsForm.cs プロジェクト: tslekwadi/CDS
        /// <summary>
        /// Add or remove an account to the payment reciept area.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>Created: Theo Crous 23/08/2012</remarks>
        private void chkAccount_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
        {
            try
            {
                BL.GLX.PaymentAccount account = ((List <BL.GLX.PaymentAccount>)BindingSourceAccounts.DataSource)[e.Index];

                string colname = "colReceived" + account.AccountId;

                if (account.AccountDefault || String.IsNullOrEmpty(defaultPaymentAccountColumn))
                {
                    defaultPaymentAccountColumn = colname;
                }

                //If default payment account is unchecked
                if (account.AccountDefault && e.State == CheckState.Unchecked)
                {
                    DB.GLX_Account defaultPaymentAccount = DataContext.EntityAccountingContext.GLX_Account.Where(n => ((List <BL.GLX.PaymentAccount>)BindingSourceAccounts.DataSource).Select(s => s.AccountId).Contains(n.Id) && !n.Id.Equals(account.AccountId)).FirstOrDefault();
                    if (defaultPaymentAccount == null)
                    {
                        chkAccount.SetItemChecked(e.Index, true);
                    }
                    else
                    {
                        bool found = false;

                        foreach (BL.GLX.PaymentAccount item in chkAccount.CheckedItems)
                        {
                            if (item.AccountId.Equals(defaultPaymentAccount.Id))
                            {
                                (((List <BL.GLX.PaymentAccount>)BindingSourceAccounts.DataSource)[e.Index]).AccountDefault = false;
                                ((List <BL.GLX.PaymentAccount>)BindingSourceAccounts.DataSource).Where(n => n.AccountId.Equals(defaultPaymentAccount.Id)).FirstOrDefault().AccountDefault = true;

                                defaultPaymentAccountColumn = "colReceived" + defaultPaymentAccount.Id;
                                found = true;

                                //Remove the old default payment colu
                                accountsColumns.Remove(account.AccountId);
                                grvOpenItem.Columns.Remove(grvOpenItem.Columns[colname]);
                                grvOpenItem.Bands["gbAccounts"].Columns.Remove(grvOpenItem.Columns[colname]);
                                entriesDataSource.Columns.Remove(entriesDataSource.Columns[colname]);

                                break;
                            }
                        }

                        if (!found)
                        {
                            chkAccount.SetItemChecked(e.Index, true);
                        }
                    }
                }
                else if (e.State == CheckState.Checked)
                {
                    //Iff account already in Accounts Column then ignore
                    if (accountsColumns.Select(n => n.Key).Contains(account.AccountId))
                    {
                        return;
                    }

                    accountsColumns.Add(account.AccountId, colname);

                    if (entriesDataSource != null)
                    {
                        entriesDataSource.Columns.Add(colname, typeof(decimal));
                    }

                    DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn added = null;
                    added = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn()
                    {
                        Name = colname, FieldName = colname, Caption = account.AccountShortName, RowIndex = 1, Tag = account, MaxWidth = 80, MinWidth = 80, Width = 80, Visible = true
                    };
                    //added.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                    //added.DisplayFormat.FormatString = "# ### ### ##0.00
                    added.DisplayFormat.FormatType   = DevExpress.Utils.FormatType.Numeric;
                    added.DisplayFormat.FormatString = "# ### ### ##0.00 DR; # ### ### ##0.00 CR; 0.00";
                    added.ColumnEdit = repCalcEdit;
                    added.OptionsColumn.AllowGroup             = DevExpress.Utils.DefaultBoolean.False;
                    added.OptionsColumn.AllowIncrementalSearch = false;
                    added.OptionsColumn.AllowMove     = false;
                    added.OptionsColumn.AllowShowHide = false;
                    added.OptionsFilter.AllowFilter   = false;

                    grvOpenItem.Columns.Add(added);
                    grvOpenItem.Bands["gbAccounts"].Columns.Add(added);
                    //added.Summary.Add(new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, colname, "{0:# ### ### ##0.00}"));
                    added.Summary.Add(new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, colname, "{0:# ### ### ##0.00 DR; # ### ### ##0.00 CR; 0.00}"));
                }
                else
                {
                    accountsColumns.Remove(account.AccountId);
                    grvOpenItem.Columns.Remove(grvOpenItem.Columns[colname]);
                    grvOpenItem.Bands["gbAccounts"].Columns.Remove(grvOpenItem.Columns[colname]);
                    entriesDataSource.Columns.Remove(entriesDataSource.Columns[colname]);
                }

                if (grvOpenItem.Columns["colTotal"] != null)
                {
                    grvOpenItem.Columns.Remove(grvOpenItem.Columns["colTotal"]);
                    grvOpenItem.Bands["gbAccounts"].Columns.Remove(grvOpenItem.Columns["colTotal"]);
                    entriesDataSource.Columns.Remove(entriesDataSource.Columns["colTotal"]);
                }

                if (entriesDataSource != null)
                {
                    entriesDataSource.Columns.Add("colTotal", typeof(decimal));
                }

                DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn total = null;
                total = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn()
                {
                    Name = "colTotal", FieldName = "colTotal", Caption = "Total", RowIndex = 1, Tag = "colTotal", MaxWidth = 120, MinWidth = 120, Width = 120, Visible = true
                };
                total.DisplayFormat.FormatType   = DevExpress.Utils.FormatType.Numeric;
                total.DisplayFormat.FormatString = "# ### ### ##0.00 DR; # ### ### ##0.00 CR; 0.00";
                total.ColumnEdit = repCalcEdit;
                total.OptionsColumn.AllowGroup             = DevExpress.Utils.DefaultBoolean.False;
                total.OptionsColumn.AllowIncrementalSearch = false;
                total.OptionsColumn.AllowMove     = false;
                total.OptionsColumn.AllowShowHide = false;
                total.OptionsFilter.AllowFilter   = false;
                total.OptionsColumn.AllowEdit     = false;

                grvOpenItem.Columns.Add(total);
                grvOpenItem.Bands["gbAccounts"].Columns.Add(total);
                total.Summary.Add(new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum, "colTotal", "{0:# ### ### ##0.00 DR; # ### ### ##0.00 CR; 0.00}"));

                foreach (var pair in accountsColumns)
                {
                    this.grvOpenItem.Columns[pair.Value].MinWidth = 240 / accountsColumns.Count;
                }
                grvOpenItem.Bands["gbAccounts"].Width = 240;

                PopulateTotals();
            }
            catch (Exception ex)
            {
            }
        }