protected void btnAddAccountingPlan_Click(object sender, EventArgs e) { accountManager = new AccountManager(this); accountingPlan = new AccountingPlan(); if (String.IsNullOrEmpty(cboTreeAccountingPlan.SelectedValue)) { ShowError("Selecione um plano de contas pai!"); return; } if (treAccountingPlan.SelectedNode != null) { AccountingPlan original_accountingPlan = accountManager.GetAccountingPlan(Company.CompanyId, Convert.ToInt32(treAccountingPlan.SelectedValue)); accountingPlan.CopyPropertiesFrom(original_accountingPlan); accountingPlan.Name = txtName.Text.ToUpper(); accountingPlan.ParentId = Convert.ToInt32(cboTreeAccountingPlan.SelectedValue); accountManager.UpdateAccountingPlan(original_accountingPlan, accountingPlan); } else { accountingPlan.CompanyId = Company.CompanyId; accountingPlan.Name = txtName.Text.ToUpper(); accountingPlan.ParentId = Convert.ToInt32(cboTreeAccountingPlan.SelectedValue); accountManager.InsertAccountingPlan(accountingPlan); } BindTree(); }
protected void btnAddAccountingPlan_Click(object sender, EventArgs e) { accountManager = new AccountManager(this); accountingPlan = new AccountingPlan(); if (String.IsNullOrEmpty(cboTreeAccountingPlan.SelectedValue)) { ShowError("Selecione um plano de contas pai!"); return; } if (treAccountingPlan.SelectedNode != null) { AccountingPlan original_accountingPlan = accountManager.GetAccountingPlan(Company.CompanyId,Convert.ToInt32(treAccountingPlan.SelectedValue)); accountingPlan.CopyPropertiesFrom(original_accountingPlan); accountingPlan.Name = txtName.Text.ToUpper(); accountingPlan.ParentId = Convert.ToInt32(cboTreeAccountingPlan.SelectedValue); accountManager.UpdateAccountingPlan(original_accountingPlan, accountingPlan); } else { accountingPlan.CompanyId = Company.CompanyId; accountingPlan.Name = txtName.Text.ToUpper(); accountingPlan.ParentId = Convert.ToInt32(cboTreeAccountingPlan.SelectedValue); accountManager.InsertAccountingPlan(accountingPlan); } BindTree(); }
protected void btnDeleteAccoutingPlan_Command(object sender, CommandEventArgs e) { if (treAccountingPlan.SelectedNode == null) { ShowError("Selecione um plano de contas!"); return; } if (e.CommandName == "Select") { var node = treAccountingPlan.FindNodeByValue(e.CommandArgument.ToString()); cboTreeAccountingPlan.SelectedValue = String.Empty; if (node.ParentNode != null) { cboTreeAccountingPlan.SelectedValue = node.ParentNode.Value; } txtName.Text = node.Text; } else if (e.CommandName == "Delete") { accountingPlan = new AccountManager(this).GetAccountingPlan(Company.CompanyId, Convert.ToInt32(treAccountingPlan.SelectedNode.Value)); accountManager = new AccountManager(this); switch (accountManager.DeleteAccountingPlan(accountingPlan)) { case AccountManager.AccountPlanDeleteStatus.DeletingRegisterWithForeignKey: ShowError(Resources.Exception.DeletingRegisterWithForeignKey); break; case AccountManager.AccountPlanDeleteStatus.ExistsAssociatedAccountPlan: ShowError(Resources.Exception.ExistsChildCategories); break; default: accountManager.DeleteAccountingPlan(accountingPlan); BindTree(); break; } } }
/// <summary> /// This method is a basic update method /// Change this method to change how the AccountingPlan is Updated /// </summary> /// <param name="original_entity"></param> /// <param name="entity"></param> public void UpdateAccountingPlan(AccountingPlan original_entity, AccountingPlan entity) { // DbContext.AccountingPlans.Attach(original_entity); original_entity.CopyPropertiesFrom(entity); DbContext.SubmitChanges(); }
public AccountPlanDeleteStatus DeleteAccountingPlan(AccountingPlan entity) { if (entity.AccountingPlans.Any()) return AccountPlanDeleteStatus.ExistsAssociatedAccountPlan; if (entity.Invoices.Any() || entity.Bills.Any()) return AccountPlanDeleteStatus.DeletingRegisterWithForeignKey; DbContext.AccountingPlans.DeleteOnSubmit(entity); DbContext.SubmitChanges(); return AccountPlanDeleteStatus.Valid; }
/// <summary> /// This method is a basic insert method /// Change this method to change how the AccountingPlan is Inserted /// </summary> /// <param name="entity"></param> public int InsertAccountingPlan(AccountingPlan entity) { DbContext.AccountingPlans.InsertOnSubmit(entity); DbContext.SubmitChanges(); //entity.Code = GetAccountingPlan(entity.CompanyId, entity.ParentId).Code; if (entity.AccountingPlan1 != null && String.IsNullOrEmpty(entity.Code) && entity.ParentId.HasValue) { AccountingPlan parent = GetAccountingPlan(entity.CompanyId, Convert.ToInt32(entity.ParentId)); parent.AccountingPlans.Load(); entity.Code = parent.Code + "." + parent.AccountingPlans.Count(); DbContext.SubmitChanges(); } return entity.AccountingPlanId; }
protected void btnDeleteAccoutingPlan_Command(object sender, CommandEventArgs e) { if (treAccountingPlan.SelectedNode == null) { ShowError("Selecione um plano de contas!"); return; } if (e.CommandName == "Select") { var node = treAccountingPlan.FindNodeByValue(e.CommandArgument.ToString()); cboTreeAccountingPlan.SelectedValue = String.Empty; if (node.ParentNode != null) cboTreeAccountingPlan.SelectedValue = node.ParentNode.Value; txtName.Text = node.Text; } else if (e.CommandName == "Delete") { accountingPlan = new AccountManager(this).GetAccountingPlan(Company.CompanyId, Convert.ToInt32(treAccountingPlan.SelectedNode.Value)); accountManager = new AccountManager(this); switch (accountManager.DeleteAccountingPlan(accountingPlan)) { case AccountManager.AccountPlanDeleteStatus.DeletingRegisterWithForeignKey: ShowError(Resources.Exception.DeletingRegisterWithForeignKey); break; case AccountManager.AccountPlanDeleteStatus.ExistsAssociatedAccountPlan: ShowError(Resources.Exception.ExistsChildCategories); break; default: accountManager.DeleteAccountingPlan(accountingPlan); BindTree(); break; } } }