Int64 IAPPanelDataAccess.Delete(APPanelEntity aPPanelEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

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

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

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

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

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

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

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

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void SaveAPPanelEntity()
        {
            if (IsValid)
            {
                try
                {
                    APPanelEntity aPPanelEntity = BuildAPPanelEntity();

                    Int64 result = -1;

                    if (aPPanelEntity.IsNew)
                    {
                        result = FCCAPPanel.GetFacadeCreate().Add(aPPanelEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(APPanelEntity.FLD_NAME_APPanelID, aPPanelEntity.APPanelID.ToString(), SQLMatchType.Equal);
                        result = FCCAPPanel.GetFacadeCreate().Update(aPPanelEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _APPanelID     = 0;
                        _APPanelEntity = new APPanelEntity();
                        PrepareInitialView();
                        BindAPPanelList();

                        if (aPPanelEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "A PPanel Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "A PPanel Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (aPPanelEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add A PPanel Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update A PPanel Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
        private APPanelEntity BuildAPPanelEntity()
        {
            APPanelEntity aPPanelEntity = CurrentAPPanelEntity;

            aPPanelEntity.Name        = txtName.Text.Trim();
            aPPanelEntity.Description = txtDescription.Text.Trim();
            aPPanelEntity.IsRemoved   = chkIsRemoved.Checked;


            return(aPPanelEntity);
        }
        private Int64 UpdateTran(APPanelEntity aPPanelEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.APPanel_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, "@APPanelID", DbType.Int64, aPPanelEntity.APPanelID);
                db.AddInParameter(cmd, "@Name", DbType.String, aPPanelEntity.Name);
                db.AddInParameter(cmd, "@Description", DbType.String, aPPanelEntity.Description);
                db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, aPPanelEntity.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);
        }
        protected void lvAPPanel_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            Int64 APPanelID;

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

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

                    PrepareEditView();

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

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(APPanelEntity.FLD_NAME_APPanelID, APPanelID.ToString(), SQLMatchType.Equal);

                        APPanelEntity aPPanelEntity = new APPanelEntity();


                        result = FCCAPPanel.GetFacadeCreate().Delete(aPPanelEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _APPanelID     = 0;
                            _APPanelEntity = new APPanelEntity();
                            PrepareInitialView();
                            BindAPPanelList();

                            MiscUtil.ShowMessage(lblMessage, "A PPanel has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete A PPanel.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
        private void PrepareEditView()
        {
            APPanelEntity aPPanelEntity = CurrentAPPanelEntity;


            if (!aPPanelEntity.IsNew)
            {
                txtName.Text         = aPPanelEntity.Name.ToString();
                txtDescription.Text  = aPPanelEntity.Description.ToString();
                chkIsRemoved.Checked = aPPanelEntity.IsRemoved;

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

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

                Database.AddInParameter(cmd, "@APPanelID", DbType.Int64, aPPanelEntity.APPanelID);
                Database.AddInParameter(cmd, "@Name", DbType.String, aPPanelEntity.Name);
                Database.AddInParameter(cmd, "@Description", DbType.String, aPPanelEntity.Description);
                Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, aPPanelEntity.IsRemoved);

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

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

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

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

            return(returnCode);
        }
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _APPanelID     = 0;
     _APPanelEntity = new APPanelEntity();
     PrepareInitialView();
 }
 Int64 IAPPanelFacade.Delete(APPanelEntity aPPanelEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateAPPanelDataAccess().Delete(aPPanelEntity, filterExpression, option, reqTran));
 }
 Int64 IAPPanelFacade.Add(APPanelEntity aPPanelEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateAPPanelDataAccess().Add(aPPanelEntity, option, reqTran));
 }