public static int AddAccount(tChartOfAccount account)
 {
     try
     {
         return AccountingDataProvider.AddAccount(account);
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
        public static int AddAccount(tChartOfAccount account)
        {
            int rowsAdded;

            using (IDbConnection connection = DbConnectionHelper.GetConnection())
            {
                var query =
                    new StringBuilder(
                        "INSERT INTO tChartOfAccount(CompanyID,AccountCode, AccountName, AccountType, SumFrom, TaxCode)");
                query.Append("VALUES(@CompanyID,@AccountCode, @AccountName, @AccountType, @SumFrom, @TaxCode)");

                rowsAdded = connection.Execute(query.ToString(), account);

            }

            return rowsAdded;
        }
        public static int UpdateAccount(tChartOfAccount account)
        {
            int rowsAdded;

            using (IDbConnection connection = DbConnectionHelper.GetConnection())
            {
                var query =
                    new StringBuilder(
                        "UPDATE tChartOfAccount SET  AccountName = @AccountName, ");
                query.Append("AccountType = @AccountType, SumFrom = @SumFrom, TaxCode = @TaxCode WHERE CompanyID = @CompanyID and AccountCode=@AccountCode");

                rowsAdded = connection.Execute(query.ToString(), account);
            }

            return rowsAdded;
        }
        public static int DeleteAccount(tChartOfAccount account)
        {
            int rowsAdded;

            using (IDbConnection connection = DbConnectionHelper.GetConnection())
            {
                var query =
                    new StringBuilder("DELETE FROM tChartOfAccount WHERE CompanyID = @CompanyID and AccountCode=@AccountCode");

                rowsAdded = connection.Execute(query.ToString(), account);
            }

            return rowsAdded;
        }
        private tChartOfAccount ChartOfAccountBuilder()
        {
            var chartOfAccount = new tChartOfAccount
            {
                CompanyId = ShatedData.ApplicationState.SelectedCompanyId ,
                AccountCode = Convert.ToInt16(txtAccountCode.Text),
                AccountName = txtAccountText.Text,
                AccountType = cboAccountType.SelectedIndex,

            };
            if (cboSummaryFrom.SelectedValue != null)
                if (cboSummaryFrom.SelectedIndex != 0)
                {
                    var findIndex = cboSummaryFrom.SelectedValue.ToString().IndexOf("|", 0);
                    if (findIndex != -1)
                    {
                        int accountCode = Convert.ToInt16(cboSummaryFrom.SelectedValue.ToString().Substring(0, findIndex));
                        chartOfAccount.SumFrom = accountCode;
                    }
                }

            if (cboTax.SelectedValue != null)
                if (cboTax.SelectedIndex != 0)
                {
                    var findIndex = cboTax.SelectedValue.ToString().IndexOf("|", 0);
                    if (findIndex != -1)
                    {
                        string taxCode = Convert.ToString(cboTax.SelectedValue.ToString().Substring(0, findIndex));
                        chartOfAccount.TaxCode = taxCode;
                    }
                }

            return chartOfAccount;
        }