Int64 IACAccountDataAccess.Delete(ACAccountEntity aCAccountEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Delete(aCAccountEntity, filterExpression, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = DeleteTran(aCAccountEntity, filterExpression, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        Int64 IACAccountDataAccess.Add(ACAccountEntity aCAccountEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Add(aCAccountEntity, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = AddTran(aCAccountEntity, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void PrepareEditView()
        {
            ACAccountEntity aCAccountEntity = CurrentACAccountEntity;


            if (!aCAccountEntity.IsNew)
            {
                if (ddlAccountGroupID.Items.Count > 0 && aCAccountEntity.AccountGroupID != null)
                {
                    ddlAccountGroupID.SelectedValue = aCAccountEntity.AccountGroupID.ToString();
                }

                txtAccountCode.Text  = aCAccountEntity.AccountCode.ToString();
                txtAccountCode2.Text = aCAccountEntity.AccountCode2.ToString();
                txtAccountName.Text  = aCAccountEntity.AccountName.ToString();
                txtDescription.Text  = aCAccountEntity.Description.ToString();
                if (ddlAccountStatusID.Items.Count > 0 && aCAccountEntity.AccountStatusID != null)
                {
                    ddlAccountStatusID.SelectedValue = aCAccountEntity.AccountStatusID.ToString();
                }

                if (ddlTaxTypeID.Items.Count > 0 && aCAccountEntity.TaxTypeID != null)
                {
                    ddlTaxTypeID.SelectedValue = aCAccountEntity.TaxTypeID.ToString();
                }

                chkIsRemoved.Checked = aCAccountEntity.IsRemoved;

                btnSubmit.Text    = "Update";
                btnAddNew.Visible = true;
            }
        }
        private Int64 UpdateTran(ACAccountEntity aCAccountEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ACAccount_SET";

            Database db = DatabaseFactory.CreateDatabase();

            using (DbCommand cmd = db.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option, db);
                AddOutputParameter(cmd, db);
                AddFilterExpressionParameter(cmd, filterExpression, db);

                db.AddInParameter(cmd, "@AccountID", DbType.Int64, aCAccountEntity.AccountID);
                db.AddInParameter(cmd, "@AccountGroupID", DbType.Int64, aCAccountEntity.AccountGroupID);
                db.AddInParameter(cmd, "@AccountCode", DbType.String, aCAccountEntity.AccountCode);
                db.AddInParameter(cmd, "@AccountCode2", DbType.String, aCAccountEntity.AccountCode2);
                db.AddInParameter(cmd, "@AccountName", DbType.String, aCAccountEntity.AccountName);
                db.AddInParameter(cmd, "@Description", DbType.String, aCAccountEntity.Description);
                db.AddInParameter(cmd, "@AccountStatusID", DbType.Int64, aCAccountEntity.AccountStatusID);
                db.AddInParameter(cmd, "@TaxTypeID", DbType.Int64, aCAccountEntity.TaxTypeID);
                db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, aCAccountEntity.IsRemoved);

                DbConnection connection = db.CreateConnection();
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();

                try
                {
                    using (IDataReader reader = db.ExecuteReader(cmd, transaction))
                    {
                        returnCode = GetReturnCodeFromParameter(cmd);
                    }

                    if (returnCode > 0)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        throw new ArgumentException("Error Code." + returnCode.ToString());
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    transaction.Dispose();
                    connection.Close();
                    connection = null;
                }
            }

            return(returnCode);
        }
        private void SaveACAccountEntity()
        {
            if (IsValid)
            {
                try
                {
                    ACAccountEntity aCAccountEntity = BuildACAccountEntity();

                    Int64 result = -1;

                    if (aCAccountEntity.IsNew)
                    {
                        result = FCCACAccount.GetFacadeCreate().Add(aCAccountEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(ACAccountEntity.FLD_NAME_AccountID, aCAccountEntity.AccountID.ToString(), SQLMatchType.Equal);
                        result = FCCACAccount.GetFacadeCreate().Update(aCAccountEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _AccountID       = 0;
                        _ACAccountEntity = new ACAccountEntity();
                        PrepareInitialView();
                        BindACAccountList();

                        if (aCAccountEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "A CAccount Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "A CAccount Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (aCAccountEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add A CAccount Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update A CAccount Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
        protected void lvACAccount_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            Int64 AccountID;

            Int64.TryParse(e.CommandArgument.ToString(), out AccountID);

            if (AccountID > 0)
            {
                if (string.Equals(e.CommandName, "EditItem"))
                {
                    _AccountID = AccountID;

                    PrepareEditView();

                    cpeEditor.Collapsed   = false;
                    cpeEditor.ClientState = "false";
                }
                else if (string.Equals(e.CommandName, "DeleteItem"))
                {
                    try
                    {
                        Int64 result = -1;

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(ACAccountEntity.FLD_NAME_AccountID, AccountID.ToString(), SQLMatchType.Equal);

                        ACAccountEntity aCAccountEntity = new ACAccountEntity();


                        result = FCCACAccount.GetFacadeCreate().Delete(aCAccountEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _AccountID       = 0;
                            _ACAccountEntity = new ACAccountEntity();
                            PrepareInitialView();
                            BindACAccountList();

                            MiscUtil.ShowMessage(lblMessage, "A CAccount has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete A CAccount.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
        private Int64 DeleteTran(ACAccountEntity aCAccountEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ACAccount_SET";

            Database db = DatabaseFactory.CreateDatabase();


            using (DbCommand cmd = db.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd, db);
                AddFilterExpressionParameter(cmd, filterExpression, db);


                DbConnection connection = db.CreateConnection();
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();

                try
                {
                    using (IDataReader reader = db.ExecuteReader(cmd, transaction))
                    {
                        returnCode = GetReturnCodeFromParameter(cmd);
                    }

                    if (returnCode >= 0)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        throw new ArgumentException("Error Code." + returnCode.ToString());
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    transaction.Dispose();
                    connection.Close();
                    connection = null;
                }
            }

            return(returnCode);
        }
        private Int64 Update(ACAccountEntity aCAccountEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ACAccount_SET";

            using (DbCommand cmd = Database.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd);
                AddFilterExpressionParameter(cmd, filterExpression);

                Database.AddInParameter(cmd, "@AccountID", DbType.Int64, aCAccountEntity.AccountID);
                Database.AddInParameter(cmd, "@AccountGroupID", DbType.Int64, aCAccountEntity.AccountGroupID);
                Database.AddInParameter(cmd, "@AccountCode", DbType.String, aCAccountEntity.AccountCode);
                Database.AddInParameter(cmd, "@AccountCode2", DbType.String, aCAccountEntity.AccountCode2);
                Database.AddInParameter(cmd, "@AccountName", DbType.String, aCAccountEntity.AccountName);
                Database.AddInParameter(cmd, "@Description", DbType.String, aCAccountEntity.Description);
                Database.AddInParameter(cmd, "@AccountStatusID", DbType.Int64, aCAccountEntity.AccountStatusID);
                Database.AddInParameter(cmd, "@TaxTypeID", DbType.Int64, aCAccountEntity.TaxTypeID);
                Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, aCAccountEntity.IsRemoved);

                using (IDataReader reader = Database.ExecuteReader(cmd))
                {
                    returnCode = GetReturnCodeFromParameter(cmd);

                    switch (returnCode)
                    {
                    case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST:
                    {
                        throw new ArgumentException("ACAccountEntity already exists. Please specify another ACAccountEntity.");
                    }

                    case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION:
                    {
                        throw new ArgumentException("ACAccountEntity data already updated from different session.");
                    }

                    case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION:
                    {
                        throw new ArgumentException("ACAccountEntity already exists. Please specify another ACAccountEntity.");
                    }
                    }
                }
            }

            return(returnCode);
        }
        private ACAccountEntity BuildACAccountEntity()
        {
            ACAccountEntity aCAccountEntity = CurrentACAccountEntity;

            if (ddlAccountGroupID.Items.Count > 0)
            {
                if (ddlAccountGroupID.SelectedValue == "0")
                {
                }
                else
                {
                    aCAccountEntity.AccountGroupID = Int64.Parse(ddlAccountGroupID.SelectedValue);
                }
            }

            aCAccountEntity.AccountCode  = txtAccountCode.Text.Trim();
            aCAccountEntity.AccountCode2 = txtAccountCode2.Text.Trim();
            aCAccountEntity.AccountName  = txtAccountName.Text.Trim();
            aCAccountEntity.Description  = txtDescription.Text.Trim();
            if (ddlAccountStatusID.Items.Count > 0)
            {
                if (ddlAccountStatusID.SelectedValue == "0")
                {
                }
                else
                {
                    aCAccountEntity.AccountStatusID = Int64.Parse(ddlAccountStatusID.SelectedValue);
                }
            }

            if (ddlTaxTypeID.Items.Count > 0)
            {
                if (ddlTaxTypeID.SelectedValue == "0")
                {
                }
                else
                {
                    aCAccountEntity.TaxTypeID = Int64.Parse(ddlTaxTypeID.SelectedValue);
                }
            }

            aCAccountEntity.IsRemoved = chkIsRemoved.Checked;


            return(aCAccountEntity);
        }
        private Int64 Delete(ACAccountEntity aCAccountEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ACAccount_SET";

            using (DbCommand cmd = Database.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd);
                AddFilterExpressionParameter(cmd, filterExpression);


                using (IDataReader reader = Database.ExecuteReader(cmd))
                {
                    returnCode = GetReturnCodeFromParameter(cmd);

                    switch (returnCode)
                    {
                    case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST:
                    {
                        throw new ArgumentException("ACAccountEntity already exists. Please specify another ACAccountEntity.");
                    }

                    case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION:
                    {
                        throw new ArgumentException("ACAccountEntity data already updated from different session.");
                    }

                    case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION:
                    {
                        throw new ArgumentException("ACAccountEntity already exists. Please specify another ACAccountEntity.");
                    }
                    }
                }
            }

            return(returnCode);
        }
Beispiel #11
0
 Int64 IACAccountFacade.Delete(ACAccountEntity aCAccountEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateACAccountDataAccess().Delete(aCAccountEntity, filterExpression, option, reqTran));
 }
Beispiel #12
0
 Int64 IACAccountFacade.Add(ACAccountEntity aCAccountEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateACAccountDataAccess().Add(aCAccountEntity, option, reqTran));
 }
Beispiel #13
0
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _AccountID       = 0;
     _ACAccountEntity = new ACAccountEntity();
     PrepareInitialView();
 }