Int64 IACCompanyInfoDataAccess.Delete(ACCompanyInfoEntity aCCompanyInfoEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

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

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

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

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

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

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

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

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private ACCompanyInfoEntity BuildACCompanyInfoEntity()
        {
            ACCompanyInfoEntity aCCompanyInfoEntity = CurrentACCompanyInfoEntity;

            aCCompanyInfoEntity.CompanyName           = txtCompanyName.Text.Trim();
            aCCompanyInfoEntity.AddressLine1          = txtAddressLine1.Text.Trim();
            aCCompanyInfoEntity.AddressLine2          = txtAddressLine2.Text.Trim();
            aCCompanyInfoEntity.PhoneNumber           = txtPhoneNumber.Text.Trim();
            aCCompanyInfoEntity.Email                 = txtEmail.Text.Trim();
            aCCompanyInfoEntity.OfficialCompanyNumber = txtOfficialCompanyNumber.Text.Trim();
            if (ddlHomeCurrencyID.Items.Count > 0)
            {
                if (ddlHomeCurrencyID.SelectedValue == "0")
                {
                }
                else
                {
                    aCCompanyInfoEntity.HomeCurrencyID = Int64.Parse(ddlHomeCurrencyID.SelectedValue);
                }
            }

            if (ddlFiscalYearID.Items.Count > 0)
            {
                if (ddlFiscalYearID.SelectedValue == "0")
                {
                }
                else
                {
                    aCCompanyInfoEntity.FiscalYearID = Int64.Parse(ddlFiscalYearID.SelectedValue);
                }
            }


            return(aCCompanyInfoEntity);
        }
        private void PrepareEditView()
        {
            ACCompanyInfoEntity aCCompanyInfoEntity = CurrentACCompanyInfoEntity;


            if (!aCCompanyInfoEntity.IsNew)
            {
                txtCompanyName.Text           = aCCompanyInfoEntity.CompanyName.ToString();
                txtAddressLine1.Text          = aCCompanyInfoEntity.AddressLine1.ToString();
                txtAddressLine2.Text          = aCCompanyInfoEntity.AddressLine2.ToString();
                txtPhoneNumber.Text           = aCCompanyInfoEntity.PhoneNumber.ToString();
                txtEmail.Text                 = aCCompanyInfoEntity.Email.ToString();
                txtOfficialCompanyNumber.Text = aCCompanyInfoEntity.OfficialCompanyNumber.ToString();
                if (ddlHomeCurrencyID.Items.Count > 0 && aCCompanyInfoEntity.HomeCurrencyID != null)
                {
                    ddlHomeCurrencyID.SelectedValue = aCCompanyInfoEntity.HomeCurrencyID.ToString();
                }

                if (ddlFiscalYearID.Items.Count > 0 && aCCompanyInfoEntity.FiscalYearID != null)
                {
                    ddlFiscalYearID.SelectedValue = aCCompanyInfoEntity.FiscalYearID.ToString();
                }


                btnSubmit.Text    = "Update";
                btnAddNew.Visible = true;
            }
        }
        private Int64 UpdateTran(ACCompanyInfoEntity aCCompanyInfoEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ACCompanyInfo_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, "@CompanyInfoID", DbType.Int64, aCCompanyInfoEntity.CompanyInfoID);
                db.AddInParameter(cmd, "@CompanyName", DbType.String, aCCompanyInfoEntity.CompanyName);
                db.AddInParameter(cmd, "@AddressLine1", DbType.String, aCCompanyInfoEntity.AddressLine1);
                db.AddInParameter(cmd, "@AddressLine2", DbType.String, aCCompanyInfoEntity.AddressLine2);
                db.AddInParameter(cmd, "@PhoneNumber", DbType.String, aCCompanyInfoEntity.PhoneNumber);
                db.AddInParameter(cmd, "@Email", DbType.String, aCCompanyInfoEntity.Email);
                db.AddInParameter(cmd, "@OfficialCompanyNumber", DbType.String, aCCompanyInfoEntity.OfficialCompanyNumber);
                db.AddInParameter(cmd, "@HomeCurrencyID", DbType.Int64, aCCompanyInfoEntity.HomeCurrencyID);
                db.AddInParameter(cmd, "@FiscalYearID", DbType.Int64, aCCompanyInfoEntity.FiscalYearID);

                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 SaveACCompanyInfoEntity()
        {
            if (IsValid)
            {
                try
                {
                    ACCompanyInfoEntity aCCompanyInfoEntity = BuildACCompanyInfoEntity();

                    Int64 result = -1;

                    if (aCCompanyInfoEntity.IsNew)
                    {
                        result = FCCACCompanyInfo.GetFacadeCreate().Add(aCCompanyInfoEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(ACCompanyInfoEntity.FLD_NAME_CompanyInfoID, aCCompanyInfoEntity.CompanyInfoID.ToString(), SQLMatchType.Equal);
                        result = FCCACCompanyInfo.GetFacadeCreate().Update(aCCompanyInfoEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _CompanyInfoID       = 0;
                        _ACCompanyInfoEntity = new ACCompanyInfoEntity();
                        PrepareInitialView();
                        BindACCompanyInfoList();

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

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

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

                    PrepareEditView();

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

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(ACCompanyInfoEntity.FLD_NAME_CompanyInfoID, CompanyInfoID.ToString(), SQLMatchType.Equal);

                        ACCompanyInfoEntity aCCompanyInfoEntity = new ACCompanyInfoEntity();


                        result = FCCACCompanyInfo.GetFacadeCreate().Delete(aCCompanyInfoEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _CompanyInfoID       = 0;
                            _ACCompanyInfoEntity = new ACCompanyInfoEntity();
                            PrepareInitialView();
                            BindACCompanyInfoList();

                            MiscUtil.ShowMessage(lblMessage, "A CCompany Info has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete A CCompany Info.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
        private Int64 DeleteTran(ACCompanyInfoEntity aCCompanyInfoEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ACCompanyInfo_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(ACCompanyInfoEntity aCCompanyInfoEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ACCompanyInfo_SET";

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

                Database.AddInParameter(cmd, "@CompanyInfoID", DbType.Int64, aCCompanyInfoEntity.CompanyInfoID);
                Database.AddInParameter(cmd, "@CompanyName", DbType.String, aCCompanyInfoEntity.CompanyName);
                Database.AddInParameter(cmd, "@AddressLine1", DbType.String, aCCompanyInfoEntity.AddressLine1);
                Database.AddInParameter(cmd, "@AddressLine2", DbType.String, aCCompanyInfoEntity.AddressLine2);
                Database.AddInParameter(cmd, "@PhoneNumber", DbType.String, aCCompanyInfoEntity.PhoneNumber);
                Database.AddInParameter(cmd, "@Email", DbType.String, aCCompanyInfoEntity.Email);
                Database.AddInParameter(cmd, "@OfficialCompanyNumber", DbType.String, aCCompanyInfoEntity.OfficialCompanyNumber);
                Database.AddInParameter(cmd, "@HomeCurrencyID", DbType.Int64, aCCompanyInfoEntity.HomeCurrencyID);
                Database.AddInParameter(cmd, "@FiscalYearID", DbType.Int64, aCCompanyInfoEntity.FiscalYearID);

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

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

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

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

            return(returnCode);
        }
        private Int64 Delete(ACCompanyInfoEntity aCCompanyInfoEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.ACCompanyInfo_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("ACCompanyInfoEntity already exists. Please specify another ACCompanyInfoEntity.");
                    }

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

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

            return(returnCode);
        }
 Int64 IACCompanyInfoFacade.Delete(ACCompanyInfoEntity aCCompanyInfoEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateACCompanyInfoDataAccess().Delete(aCCompanyInfoEntity, filterExpression, option, reqTran));
 }
 Int64 IACCompanyInfoFacade.Add(ACCompanyInfoEntity aCCompanyInfoEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateACCompanyInfoDataAccess().Add(aCCompanyInfoEntity, option, reqTran));
 }
示例#13
0
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _CompanyInfoID       = 0;
     _ACCompanyInfoEntity = new ACCompanyInfoEntity();
     PrepareInitialView();
 }