protected void btnAddCostCenter_Click(object sender, EventArgs e)
    {
        accountManager = new AccountManager(this);
        costCenter = new CostCenter();

        if (treCostCenter.SelectedNode != null)
        {
            CostCenter original_costCenter = accountManager.GetCostCenter(Convert.ToInt32(treCostCenter.SelectedNode.Value));
            costCenter.CopyPropertiesFrom(original_costCenter);

            if (!String.IsNullOrEmpty(cboTreeCostCenters.SelectedValue))
                costCenter.ParentId = Convert.ToInt32(cboTreeCostCenters.SelectedValue);
            else
                costCenter.ParentId = null;

            costCenter.Name = txtName.Text;
            accountManager.UpdateCostCenter(original_costCenter, costCenter);
        }
        else
        {
            costCenter.CompanyId = Company.CompanyId;
            costCenter.Name = txtName.Text;

            if (!String.IsNullOrEmpty(cboTreeCostCenters.SelectedValue))
                costCenter.ParentId = Convert.ToInt32(cboTreeCostCenters.SelectedValue);
            else
                costCenter.ParentId = null;

            accountManager.InsertCostCenter(costCenter);
        }

        BindTree();
    }
Esempio n. 2
0
    protected void btnAddCostCenter_Click(object sender, EventArgs e)
    {
        accountManager = new AccountManager(this);
        costCenter     = new CostCenter();

        if (treCostCenter.SelectedNode != null)
        {
            CostCenter original_costCenter = accountManager.GetCostCenter(Convert.ToInt32(treCostCenter.SelectedNode.Value));
            costCenter.CopyPropertiesFrom(original_costCenter);

            if (!String.IsNullOrEmpty(cboTreeCostCenters.SelectedValue))
            {
                costCenter.ParentId = Convert.ToInt32(cboTreeCostCenters.SelectedValue);
            }
            else
            {
                costCenter.ParentId = null;
            }

            costCenter.Name = txtName.Text;
            accountManager.UpdateCostCenter(original_costCenter, costCenter);
        }
        else
        {
            costCenter.CompanyId = Company.CompanyId;
            costCenter.Name      = txtName.Text;

            if (!String.IsNullOrEmpty(cboTreeCostCenters.SelectedValue))
            {
                costCenter.ParentId = Convert.ToInt32(cboTreeCostCenters.SelectedValue);
            }
            else
            {
                costCenter.ParentId = null;
            }

            accountManager.InsertCostCenter(costCenter);
        }

        BindTree();
    }
 /// <summary>
 /// this method updates costcenter
 /// </summary>
 /// <param name="original_entity"></param>
 /// <param name="entity"></param>
 public void UpdateCostCenter(CostCenter original_entity, CostCenter entity)
 {
     original_entity.CopyPropertiesFrom(entity);
     DbContext.SubmitChanges();
 }