private void myRadDataForm_EditEnding(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndingEventArgs e)
        {
            if (e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Cancel || e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Commit)
            {
                if ((sender as RadDataForm).CurrentItem != null)
                {
                    if (((sender as RadDataForm).CurrentItem as TDocs.Accounts).accountID_pk == null || ((sender as RadDataForm).CurrentItem as TDocs.Accounts).name == null)
                        e.Cancel = true;
                }
            }
            if (!e.Cancel)
            {
                if ((sender as RadDataForm).CurrentItem != null)
                {
                    if (((sender as RadDataForm).CurrentItem as TDocs.Accounts).createddate == null)
                    {
                        ((sender as RadDataForm).CurrentItem as TDocs.Accounts).createddate = DateTime.Now;
                        ((sender as RadDataForm).CurrentItem as TDocs.Accounts).createdby = @current_username;
                    }
                    ((sender as RadDataForm).CurrentItem as TDocs.Accounts).modifieddate = DateTime.Now;
                    ((sender as RadDataForm).CurrentItem as TDocs.Accounts).modifiedby = @current_username;
                    TDocs.Accounts view = (TDocs.Accounts)(sender as RadDataForm).CurrentItem;
                    
                    if (view.closed_date != null)
                        view.active = false;
                    else
                    {
                        if (!view.active)
                        {
                            RadWindow.Alert("You must enter a closed date when the account is set to closed");
                            return;
                        }

                    }

                    TDocs.TreasuryDocsEntities4 entities = new MyTreasuryDocsEntities();
                    entities.AttachTo("Accounts", (sender as RadDataForm).CurrentItem);
                    entities.UpdateObject((sender as RadDataForm).CurrentItem);
                    entities.BeginSaveChanges(AccountsUpdated, entities);
                }
                else
                {
                    //NEC - 7/19/2013
                    foreach (TDocs.AccountsView t in AccountsdataServiceDataSource.DataView)
                    {
                        if (accountNumber == t.accountNumber)
                        {
                            RadWindow.Alert("Account Number " + t.accountNumber + " is a duplicate.");
                            return;
                        }
                    }

                    TDocs.Accounts view = (TDocs.Accounts)dataServiceDataSource.DataView.AddNew();

                    view.name = accountName;
                    view.accountNumber = accountNumber;
                    view.divisionsID_fk = divisionID;
                    view.currencyID_fk = currencyID;
                    view.entityID_fk = entityID;
                    view.typeID_fk = typeID;
                    view.bankID_fk = bankID;
                    view.active = activeID;
                    view.acstatement = acStatement;
                    view.zba = zba;
                    if (open_date != defaultdate)
                        view.opened_date = open_date;
                    if (closed_date != defaultdate)
                        view.closed_date = closed_date;
                    view.createdby = @current_username;
                    view.createddate = DateTime.Now;
                    view.modifieddate = DateTime.Now;
                    view.modifiedby = @current_username;
                    (sender as RadDataForm).CurrentItem = view;
                    TDocs.TreasuryDocsEntities4 entities = new MyTreasuryDocsEntities();
                    entities.AddToAccounts(view);
                    entities.BeginSaveChanges(AccountsUpdated, entities);
                }
            }
        }
        private void signersDataForm_EditEnding(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndingEventArgs e)
        {
            if (e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Cancel || 
                e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Commit)
            {
                if ((sender as RadDataForm).CurrentItem != null)
                {
                    if (((sender as RadDataForm).CurrentItem as TDocs.Signers).signerID_pk == null || ((sender as RadDataForm).CurrentItem as TDocs.Signers).firstname == null)
                        e.Cancel = true;
                }
            }
            if (!e.Cancel)
            {
                if ((sender as RadDataForm).CurrentItem != null)
                {
                    if (((sender as RadDataForm).CurrentItem as TDocs.Signers).createddate == null)
                    {
                        ((sender as RadDataForm).CurrentItem as TDocs.Signers).createddate = DateTime.Now;
                        ((sender as RadDataForm).CurrentItem as TDocs.Signers).createdby = @current_username;
                    }
                    ((sender as RadDataForm).CurrentItem as TDocs.Signers).modifieddate = DateTime.Now;
                    ((sender as RadDataForm).CurrentItem as TDocs.Signers).modifiedby = @current_username;
                    if (activeID == false)
                        ((sender as RadDataForm).CurrentItem as TDocs.Signers).deactivation_date = DateTime.Now;

                    TDocs.TreasuryDocsEntities4 entities = new MyTreasuryDocsEntities();
                    entities.AttachTo("Signers", (sender as RadDataForm).CurrentItem);
                    entities.UpdateObject((sender as RadDataForm).CurrentItem);
                    entities.BeginSaveChanges(savedChanges, entities);
                }
                else
                {
                    TDocs.Signers view = new TDocs.Signers();
                    try
                    {
                        view.firstname = firstName;
                        view.lastname = lastName;
                        view.middlename = middleName;
                        view.title = title;
                        view.citizenshipID_fk = citizenshipID;
                        view.active = activeID;
                        view.createdby = @current_username;
                        view.createddate = DateTime.Now;
                        view.modifieddate = DateTime.Now;
                        view.modifiedby = @current_username;
                        (sender as RadDataForm).CurrentItem = view;

                        TDocs.TreasuryDocsEntities4 entities = new MyTreasuryDocsEntities();
                        entities.AddToSigners(view);
                        entities.BeginSaveChanges(savedChanges, entities);
                    }
                    catch (Exception ex)
                    {
                        RadWindow.Alert("Error " + ex.Message);
                    }
                }
            }
        }
        private void accountSignersDataForm_EditEnding(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndingEventArgs e)
        {
            if (e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Cancel
                    || e.EditAction == Telerik.Windows.Controls.Data.DataForm.EditAction.Commit)
            {
                if ((sender as RadDataForm).CurrentItem != null)
                {
                    if (((sender as RadDataForm).CurrentItem as TDocs.Accounts_Signers_Entitlements).accountID_fk == null || ((sender as RadDataForm).CurrentItem as TDocs.Accounts_Signers_Entitlements).signerID_fk == null)
                        e.Cancel = true;
                }
            }
            if (!e.Cancel)
            {
                TDocs.Accounts_Signers_Entitlements currentItem = (TDocs.Accounts_Signers_Entitlements)(sender as RadDataForm).CurrentItem;

                if (currentItem != null && currentItem.account_signer_entitlementID_pk != 0)
                {
                    if (((sender as RadDataForm).CurrentItem as TDocs.Accounts_Signers_Entitlements).createddate == null)
                    {
                        ((sender as RadDataForm).CurrentItem as TDocs.Accounts_Signers_Entitlements).createddate = DateTime.Now;
                        ((sender as RadDataForm).CurrentItem as TDocs.Accounts_Signers_Entitlements).createdby = @current_username;
                    }
                    ((sender as RadDataForm).CurrentItem as TDocs.Accounts_Signers_Entitlements).modifieddate = DateTime.Now;
                    ((sender as RadDataForm).CurrentItem as TDocs.Accounts_Signers_Entitlements).modifiedby = @current_username;
                    TDocs.TreasuryDocsEntities4 entities = new MyTreasuryDocsEntities();
                    entities.AttachTo("Accounts_Signers_Entitlements", (sender as RadDataForm).CurrentItem);
                    entities.UpdateObject((sender as RadDataForm).CurrentItem);
                    entities.BeginSaveChanges(UpdatedEntitlement, entities);
                }
                else
                {
                    //add new
                    TDocs.Accounts_Signers_Entitlements view = (TDocs.Accounts_Signers_Entitlements) Accounts_Signers_EntitlementsDataSource.DataView.AddNew();
                    (view as TDocs.Accounts_Signers_Entitlements).accountID_fk = accountID;
                    (view as TDocs.Accounts_Signers_Entitlements).signerID_fk = signerID;
                    (view as TDocs.Accounts_Signers_Entitlements).entitlementID_fk = entitlementID;
                    (view as TDocs.Accounts_Signers_Entitlements).added = DateTime.Now;
                    (view as TDocs.Accounts_Signers_Entitlements).user_add = @current_username;
                    (view as TDocs.Accounts_Signers_Entitlements).createdby = @current_username;
                    (view as TDocs.Accounts_Signers_Entitlements).createddate = DateTime.Now;
                    (view as TDocs.Accounts_Signers_Entitlements).modifieddate = DateTime.Now;
                    (view as TDocs.Accounts_Signers_Entitlements).modifiedby = @current_username;
                    (sender as RadDataForm).CurrentItem = view;
                    TreasuryDocsEntities4 entities = new MyTreasuryDocsEntities();
                    try
                    {
                        entities.AddToAccounts_Signers_Entitlements(view);
                        entities.BeginSaveChanges(UpdatedEntitlement, entities);
                    }
                    catch { }
                }
            }
        }