Int64 IMDArtGalleriaLocationDataAccess.Add(MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

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

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

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

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void PrepareEditView()
        {
            MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity = CurrentMDArtGalleriaLocationEntity;


            if (!mDArtGalleriaLocationEntity.IsNew)
            {
                if (ddlParentArtGalleriaLocationID.Items.Count > 0 && mDArtGalleriaLocationEntity.ParentArtGalleriaLocationID != null)
                {
                    ddlParentArtGalleriaLocationID.SelectedValue = mDArtGalleriaLocationEntity.ParentArtGalleriaLocationID.ToString();
                }

                if (ddlCountryID.Items.Count > 0 && mDArtGalleriaLocationEntity.CountryID != null)
                {
                    ddlCountryID.SelectedValue = mDArtGalleriaLocationEntity.CountryID.ToString();
                }

                BindCityByCountry();

                if (ddlCityID.Items.Count > 0 && mDArtGalleriaLocationEntity.CityID != null)
                {
                    ddlCityID.SelectedValue = mDArtGalleriaLocationEntity.CityID.ToString();
                }

                txtName.Text         = mDArtGalleriaLocationEntity.Name.ToString();
                txtDescription.Text  = mDArtGalleriaLocationEntity.Description.ToString();
                chkIsRemoved.Checked = mDArtGalleriaLocationEntity.IsRemoved;

                btnSubmit.Text    = "Update";
                btnAddNew.Visible = true;
            }
        }
        private Int64 UpdateTran(MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDArtGalleriaLocation_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, "@ArtGalleriaLocationID", DbType.Int64, mDArtGalleriaLocationEntity.ArtGalleriaLocationID);
                db.AddInParameter(cmd, "@ParentArtGalleriaLocationID", DbType.Int64, mDArtGalleriaLocationEntity.ParentArtGalleriaLocationID);
                db.AddInParameter(cmd, "@CountryID", DbType.Int64, mDArtGalleriaLocationEntity.CountryID);
                db.AddInParameter(cmd, "@CityID", DbType.Int64, mDArtGalleriaLocationEntity.CityID);
                db.AddInParameter(cmd, "@Name", DbType.String, mDArtGalleriaLocationEntity.Name);
                db.AddInParameter(cmd, "@Description", DbType.String, mDArtGalleriaLocationEntity.Description);
                db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDArtGalleriaLocationEntity.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 SaveMDArtGalleriaLocationEntity()
        {
            if (IsValid)
            {
                try
                {
                    MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity = BuildMDArtGalleriaLocationEntity();

                    Int64 result = -1;

                    if (mDArtGalleriaLocationEntity.IsNew)
                    {
                        result = FCCMDArtGalleriaLocation.GetFacadeCreate().Add(mDArtGalleriaLocationEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(MDArtGalleriaLocationEntity.FLD_NAME_ArtGalleriaLocationID, mDArtGalleriaLocationEntity.ArtGalleriaLocationID.ToString(), SQLMatchType.Equal);
                        result = FCCMDArtGalleriaLocation.GetFacadeCreate().Update(mDArtGalleriaLocationEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _ArtGalleriaLocationID       = 0;
                        _MDArtGalleriaLocationEntity = new MDArtGalleriaLocationEntity();
                        PrepareInitialView();
                        BindMDArtGalleriaLocationList();

                        if (mDArtGalleriaLocationEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Art Galleria Location Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Art Galleria Location Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (mDArtGalleriaLocationEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add Art Galleria Location Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update Art Galleria Location Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
        protected void lvMDArtGalleriaLocation_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            Int64 ArtGalleriaLocationID;

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

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

                    PrepareEditView();

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

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(MDArtGalleriaLocationEntity.FLD_NAME_ArtGalleriaLocationID, ArtGalleriaLocationID.ToString(), SQLMatchType.Equal);

                        MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity = new MDArtGalleriaLocationEntity();


                        result = FCCMDArtGalleriaLocation.GetFacadeCreate().Delete(mDArtGalleriaLocationEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _ArtGalleriaLocationID       = 0;
                            _MDArtGalleriaLocationEntity = new MDArtGalleriaLocationEntity();
                            PrepareInitialView();
                            BindMDArtGalleriaLocationList();

                            MiscUtil.ShowMessage(lblMessage, "Art Galleria Location has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete Art Galleria Location.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
        private Int64 Update(MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDArtGalleriaLocation_SET";

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

                Database.AddInParameter(cmd, "@ArtGalleriaLocationID", DbType.Int64, mDArtGalleriaLocationEntity.ArtGalleriaLocationID);
                Database.AddInParameter(cmd, "@ParentArtGalleriaLocationID", DbType.Int64, mDArtGalleriaLocationEntity.ParentArtGalleriaLocationID);
                Database.AddInParameter(cmd, "@CountryID", DbType.Int64, mDArtGalleriaLocationEntity.CountryID);
                Database.AddInParameter(cmd, "@CityID", DbType.Int64, mDArtGalleriaLocationEntity.CityID);
                Database.AddInParameter(cmd, "@Name", DbType.String, mDArtGalleriaLocationEntity.Name);
                Database.AddInParameter(cmd, "@Description", DbType.String, mDArtGalleriaLocationEntity.Description);
                Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDArtGalleriaLocationEntity.IsRemoved);

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

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

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

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

            return(returnCode);
        }
        private MDArtGalleriaLocationEntity BuildMDArtGalleriaLocationEntity()
        {
            MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity = CurrentMDArtGalleriaLocationEntity;

            if (ddlParentArtGalleriaLocationID.Items.Count > 0)
            {
                if (ddlParentArtGalleriaLocationID.SelectedValue == "0")
                {
                    mDArtGalleriaLocationEntity.ParentArtGalleriaLocationID = null;
                }
                else
                {
                    mDArtGalleriaLocationEntity.ParentArtGalleriaLocationID = Int64.Parse(ddlParentArtGalleriaLocationID.SelectedValue);
                }
            }

            if (ddlCountryID.Items.Count > 0)
            {
                if (ddlCountryID.SelectedValue == "0")
                {
                }
                else
                {
                    mDArtGalleriaLocationEntity.CountryID = Int64.Parse(ddlCountryID.SelectedValue);
                }
            }

            if (ddlCityID.Items.Count > 0)
            {
                if (ddlCityID.SelectedValue == "0")
                {
                }
                else
                {
                    mDArtGalleriaLocationEntity.CityID = Int64.Parse(ddlCityID.SelectedValue);
                }
            }

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


            return(mDArtGalleriaLocationEntity);
        }
 Int64 IMDArtGalleriaLocationFacade.Delete(MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateMDArtGalleriaLocationDataAccess().Delete(mDArtGalleriaLocationEntity, filterExpression, option, reqTran));
 }
 Int64 IMDArtGalleriaLocationFacade.Add(MDArtGalleriaLocationEntity mDArtGalleriaLocationEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateMDArtGalleriaLocationDataAccess().Add(mDArtGalleriaLocationEntity, option, reqTran));
 }
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _ArtGalleriaLocationID       = 0;
     _MDArtGalleriaLocationEntity = new MDArtGalleriaLocationEntity();
     PrepareInitialView();
 }