vendredi 11 septembre 2015

Prevent rdlc subreport from growing and moving within main report

I keep dealing with visual studio 2013 report designer.

My biggest problem at the moment is to spare exaclty one sheet of a4 paper (210 mm * 297 mm) per every data record. The length of the details section of the main report varies all the time depending on the lengths of subreports and (seems to me) something else.

Is there a way to keep unchanged both the size and location of a subreport within the main report ?

Thank you in advance !



via Chebli Mohamed

Yii2 Html::dropDownList and Html::activeDropDownList trade-off

In Yii2, using Html::activeDropDownList, I can submit data in a form like the following:

 <?= Html::activeDropDownList($model, 'category', ArrayHelper::map($categories, 'id', 'name'), [
       'multiple' => 'multiple',
       'class' => 'multiselect',
 ]) ?>

Is there a way to specify pre-selected categories in the above? I know it can be done using Html::dropDownLost like the following:

<?= Html::dropDownList('category', [1, 3, 5], ArrayHelper::map($categories, 'id', 'name'), [
     'multiple' => 'multiple',
     'class' => 'multiselect',
]) ?>

But there is a trade-off! There is no place to indicate that this is some data attached to a certain model to submit as there was using Html::activeDropDownList.

One of the solution I found was to use ActiveForm like the following:

<?= $form->field($model, 'category')
      ->dropDownList('category', [1, 3, 5], ArrayHelper::map($categories, 'id', 'name')
]) ?>

The problem I have with that last option is that I am not able to specify the html options such as 'multiple' and css such as 'class'.

Any help on being able to use drop down list with the ability to specify that the list be multiselect and have pre-selected values? Also if someone directed me to a resource where I can read about when and where to choose activeDropDownList or dropDownList, I would really appreciate that.

Thanks!



via Chebli Mohamed

Angularjs - bind dynamic data to predefined template

I'm trying to bind dynamic scope variable with predefined html template. The data is being built based on user selection via drop-down and has ng-click on a button that calls the method to build scope variable, see below for an example:

HTML:

<select id="category" class="form-control" ng-model="dataParam.category">
    <option value="">Choose Category</option>
    <option value="">overview</option>
    <option value="">mention</option>
    <option value="">sentiment</option>
</select>
<button ng-click="buildMetricData()" class="form-control">New</button>

I have template defined as overview-form-temp.html and using ng-include to load it on the view:

<section id="overview" class="well custom-margin" ng-include="'Views/overview-form-temp.html'"></section>

Template:

<form id="overview-form" name="overview-form" novalidate>
    <fieldset class="space-bottom">
        <legend>U.S. Brand Reputation</legend>
        <div class="form-horizontal form-widgets col-sm-12">
            <div class="form-group">
                <label for="awarness" class="col-sm-3">Awareness:</label>
                <div class="col-sm-2">
                    <input type="number" min="0" id="awareness" class="form-control" ng-model="metricData.subcategory['us total']['awareness']" />
                </div>
                <div style="clear:both;"></div>
                <label for="hight-trust" class="col-sm-3">High Trust:</label>
                <div class="col-sm-2">
                    <input type="number" min="0" id="high-trust" class="form-control" ng-model="metricData.subcategory['us total']['high trust']" />
                </div>
            </div>
        </div>
    </fieldset>
</form>

Controller:

var app = angular.module('AdminApp',[]);
app.controller('MainDataContrl', ['$scope','$compile', function($scope,$compile){
    $scope.buildMetricData = function(){

        $scope.metricData = {
            params:{},
            subcategory:{}
        }

        switch($scope.metricData .params.category){
            case 'Overview':
                $scope.metricData.subcategory['us total'] = {};
                break;
        }
    }
}]);

The data is building the way expected but I'm having issues binding it to the template above.



via Chebli Mohamed

How unreferred values from string pool get removed?

I'm curious how values from a string-pool get removed?

suppose:

String a = "ABC"; // has a reference of string-pool
String b = new String("ABC"); // has a heap reference

b = null;
a = null;

In case of GC, "ABC" from the heap gets collected but "ABC" is still in the pool (because its in permGen and GC would not affect it).

If we keep adding values like:

String c = "ABC"; // pointing to 'ABC' in the pool. 

for(int i=0; i< 10000; i++) {
  c = ""+i;
  // each iteration adds a new value in the pool. Previous values don't have a pointer.
}

What I want to know is:

  • Will the pool remove values that are not referred to? If not, it means that the pool is eating up unnecessary memory.
  • What is the point then because the JVM is using the pool?
  • When could this be a performance risk?


via Chebli Mohamed

Attempt to invoke virtual method 'void android.support.v4.widget.DrawerLayout.setDrawerShadow(int, int)' on a null object reference

Due to my lack of knowledge on this I'm jumping from one problem to another. I've been trying to figure it out for hours now and looked through various previous questions but not getting anywhere. Most recent is this error:

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.widget.DrawerLayout.setDrawerShadow(int, int)' on a null object reference
        at XXXX.NavigationDrawerFragment.setUp(NavigationDrawerFragment.java:136)
        at XXXX.EditFactFind.onCreate(EditFactFind.java:72)
        at android.app.Activity.performCreate(Activity.java:5990)

My Activity (the main point that it's failing) is:

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;


import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
//import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class EditFactFind extends Activity implements NavigationDrawerFragment.NavigationDrawerCallbacks {

    public static final int RESULT_DELETE = -500;
    private boolean isInEditMode = true;
    private boolean isAddingFactFind = true;
    private NavigationDrawerFragment mNavigationDrawerFragment;
    private CharSequence mTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_factfind);

        final Button saveButton = (Button)findViewById(R.id.saveButton);
        final Button cancelButton = (Button)findViewById(R.id.cancelButton);
        final EditText titleEditText = (EditText)findViewById(R.id.titleEditText);
        //final EditText factFindEditText = (EditText)findViewById(R.id.factFindEditText);
        final TextView dateTextView = (TextView)findViewById(R.id.dateTextView);
        final Button nextButton =(Button) findViewById(R.id.nextButton);

        //Create fragment and give it an argument for the selected article
        secA_pg1 iniSecFrag = new secA_pg1();
        Bundle args = new Bundle();
        args.putInt(secA_pg1.ARG_INDEX, 1);
        iniSecFrag.setArguments(args);

        FragmentTransaction initialTransaction = getFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack so the user can navigate back
        initialTransaction.replace(R.id.fragment_container, iniSecFrag);
        initialTransaction.addToBackStack(null);

        //Commit the transaction
        initialTransaction.commit();

        mNavigationDrawerFragment = (NavigationDrawerFragment)
                getFragmentManager().findFragmentById(R.id.navigation_drawer);
        mTitle = getTitle();

        // Set up the drawer.
        mNavigationDrawerFragment.setUp(
                R.id.navigation_drawer,
                (DrawerLayout) findViewById(R.id.drawer_layout));

        Serializable extra = getIntent().getSerializableExtra("FactFind");
        if(extra != null)
        {
            FactFind factFind = (FactFind) extra;
            titleEditText.setText(factFind.getTitle());
          //  factFindEditText.setText(factFind.getFactFindTitle());

            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            String date = dateFormat.format(factFind.getDate());

            dateTextView.setText(date);

            isInEditMode = false;
            titleEditText.setEnabled(false);
          //  factFindEditText.setEnabled(false);
            saveButton.setText("Edit");

            isAddingFactFind = false;

        }

        cancelButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setResult(RESULT_CANCELED, new Intent());
                finish();
            }
        });

        nextButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //secA_pg1 secFrag = (secA_pg1) getFragmentManager().findFragmentById(R.id.Sec_A_pg1_fragment);
                //Create fragment and give it an argument for the selected article
                secA_pg2 newSecFrag = new secA_pg2();
                Bundle args = new Bundle();
                args.putInt(secA_pg2.ARG_INDEX, 2);
                newSecFrag.setArguments(args);

                FragmentTransaction transaction = getFragmentManager().beginTransaction();

                // Replace whatever is in the fragment_container view with this fragment,
                // and add the transaction to the back stack so the user can navigate back
                transaction.replace(R.id.fragment_container, newSecFrag);
                transaction.addToBackStack(null);

                //Commit the transaction
                transaction.commit();
            }
        });

        saveButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                if(isInEditMode)
                {
                    Intent returnIntent = new Intent();
                    FactFind factFind = new FactFind(titleEditText.getText().toString(),Calendar.getInstance().getTime());
                    returnIntent.putExtra("FactFind", factFind);
                    setResult(RESULT_OK, returnIntent);
                    finish();

                }
                else
                {
                    isInEditMode = true;
                    saveButton.setText("Save");
                    titleEditText.setEnabled(true);
                   // factFindEditText.setEnabled(true);
                }

            }
        });
    }

and my Navigation drawer is failing at the setUp method:

package XXXX;

import android.support.v4.app.FragmentActivity;

import android.app.ActionBar;

//import android.support.v7.app.ActionBar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.app.Fragment;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.support.v7.widget.Toolbar;

    public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;

    // set a custom shadow that overlays the main content when the drawer opens
   // mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(
            getActivity(),                    /* host Activity */
            mDrawerLayout,                    /* DrawerLayout object */
            R.drawable.ic_drawer,             /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }

        //    getActivity().InvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }

            if (!mUserLearnedDrawer) {
                // The user manually opened the drawer; store this flag to prevent auto-showing
                // the navigation drawer automatically in the future.
                mUserLearnedDrawer = true;
                SharedPreferences sp = PreferenceManager
                        .getDefaultSharedPreferences(getActivity());
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }

          //  getActivity().InvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

    // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
    // per the navigation drawer design guidelines.
    if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
        mDrawerLayout.openDrawer(mFragmentContainerView);
    }

    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

XML of the drawer is

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.DrawerLayout
    xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="XXXX.MainActivity">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         If you're not building against API 17 or higher, use
         android:layout_gravity="left" instead. -->
    <!-- The drawer is given a fixed width in dp and extends the full height of
         the container. -->
    <fragment
        android:id="@+id/navigation_drawer"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:name="XXXX.NavigationDrawerFragment"
        tools:layout="@layout/fragment_navigation_drawer" />

</android.DrawerLayout>

I'm assuming that mDrawerLayout isn't being picked up correctly and is therefore returning null but I can't figure out why that is.

Thanks.



via Chebli Mohamed

Create new worksheet if does not exist, rename based on cell value, then reference that worksheet

I have 2 workbooks one has the vba (MainWb), the other is just a template (TempWb) that the code paste values and formulas from the mainworkbook. The TempWb only has one blank sheet named graphs. The code needs to open the xltx file (TempWb), add a sheet and rename based on value in a certain cell on the MainWb (if it does not already exist) and then to reference that new sheet in the copy values process from the MainWb. I tried recording a macro but it didn't really help. I have researched and put some stuff together but not sure if it fits and works. Any suggestions would be appreciated.

This is what I have so far.

Option Explicit
Sub ExportSave()

Dim Alpha           As Workbook 'Template
Dim Omega           As Worksheet 'Template
Dim wbMain          As Workbook 'Main Export file
Dim FileTL          As String   'Test location
Dim FilePath        As String   'File save path
Dim FileProject     As String   'Project information
Dim FileTimeDate    As String   'Export Date and Time
Dim FileD           As String   'Drawing Number
Dim FileCopyPath    As String   'FileCopy save path
Dim FPATH           As String   'File Search Path
Dim Extract         As Workbook 'File Extract Data
Dim locs, loc                   'Location Search
Dim intLast         As Long     'EmptyCell Search
Dim intNext         As Long     'EmptyCell Seach
Dim rngDest         As Range    'Paste Value Range
Dim Shtname1        As String   'Part Platform
Dim Shtname2        As String   'Part Drawing Number
Dim Shtname3        As String   'Part Info
Dim rep             As Long

With Range("H30000")
            .Value = Format(Now, "mmm-dd-yy   hh-mm-ss AM/PM")
        End With

FilePath = "C:\Users\aholiday\Desktop\FRF_Data_Macro_Insert_Test"
FileCopyPath = "C:\Users\aholiday\Desktop\Backup"
FileTL = Sheets("Sheet1").Range("A1").Text
FileProject = Sheets("Sheet1").Range("E2").Text
FileTimeDate = Sheets("Sheet1").Range("H30000").Text
FileD = Sheets("Sheet1").Range("E3").Text
FPATH = "C:\Users\aholiday\Desktop\FRF_Data_Macro_Insert_Test\"
Shtname1 = wbMain.Sheets("Sheet1").Range("E2")
Shtname2 = wbMain.Sheets("Sheet1").Range("E3")
Shtname3 = wbMain.Sheets("Sheet1").Range("E4")

Select Case Range("A1").Value

    Case "Single Test Location"



    Case "Location 1"

    Application.DisplayAlerts = False
    Set wbMain = Workbooks("FRF Data Export Graphs.xlsm")
    wbMain.Sheets("Sheet1").Copy
    ActiveWorkbook.SaveAs FileName:=FileCopyPath & "\" & FileProject & Space(1) & FileD & Space(1) & FileTL & Space(1) & FileTimeDate & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close False

    Set Alpha = Workbooks.Open("\\plymshare01\Public\Holiday\FRF Projects\Templates\FRF Data Graphs.xltx")




    For rep = 1 To (Worksheets.Count)
        If LCase(Sheets(rep)).Name = LCase(Shtname1 & Space(1) & Shtname2 & Space(1) & Shtname3) Then
            MsgBox "This Sheet already exists"
            Exit Sub
        End If
    Next

    Sheets.Add after:=Sheets(Sheets.Count)
    Sheets(ActiveSheet.Name).Name = Shtname1 & Space(1) & Shtname2 & Space(1) & Shtname3


            Set Omega = Workbooks(ActiveWorkbook.Name).Sheets("ActiveWorksheet.Name")

            locs = Array("FRF Data Export Graphs.xlsm")



                    'set the first data block destination
                        Set rngDest = Omega.Cells(3, 1).Resize(30000, 3)

                    For Each loc In locs

                    Set Extract = Workbooks.Open(FileName:=FPATH & loc, ReadOnly:=True)

                    rngDest.Value = Extract.Sheets("Sheet1").Range("A4:D25602").Value

                    Extract.Close False

                    Set rngDest = rngDest.Offset(0, 4) 'move over to the right 4 cols

                    Next loc

                          With ActiveWorksheet.Range("D3:D25603").Formula = "=SQRT((B3)^2+(C3)^2)"

                                ActiveWorkbook.Charts.Add
                                ActiveChart.ChartType = xlXYScatterLines
                                ActiveChart.SetSourceData Source:=Sheets("Graphs").Range("A3:D7"), PlotBy:=xlRows
                                ActiveChart.Location Where:=xlLocationAsNewSheet, Name:=Shtname2

                                With ActiveChart
                                    .HasTitle = True
                                    .ChartTitle.Characters.Text = Shtname2
                                    .Axes(xlCategory, xlPrimary).HasTitle = True
                                    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Hz"
                                    .Axes(xlValue, xlPrimary).HasTitle = True
                                    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Blank"
                                End With

        Application.ScreenUpdating = True

    Case "Location 2"
    Case "Location 3"
    Case "Location 4"
    Case Else

        MsgBox "Export Failed!"

    End Select


    Application.DisplayAlerts = True

 End Sub

Run-time error '91' Object variable or With block not set code lines

Shtname1 = wbMain.Sheets("Sheet1").Range("E2")
Shtname2 = wbMain.Sheets("Sheet1").Range("E3")
Shtname3 = wbMain.Sheets("Sheet1").Range("E4")

This is supposed to tell the code what to name the new created sheet

Fixed: Moved under

Set = wbMain = Workbooks("FRF Data Export Graphs.xlsm")

New Error: Object doesnt support this property or method code

   If LCase(Sheets(rep)).Name = LCase(Shtname1 & Space(1) & Shtname2 & Space(1) & Shtname3) Then  



via Chebli Mohamed

checking well formed xml and logging the error to file

I have 4,000 xml files in folders a, b, c, and d Each folder contains 1000 files each. All folders are in main folder called library I need to check if the xml files are well formed using

xmllint --noout 100.xml"

command or may be with something better. Now incase of error, log the file name plus folder name in a log file.

log "library/a/100.xml"

Below is the Pseudo code. I need to build the script to run in shell script or something faster

#program check xml format
#!/bin/bash
echo Please, get ready to process
 for i in $(cat "/home/thrinity/library/);
  do
    xmllint --noout "$i" ;
    if error
      #log filefolder & file name
      print error to errorlog.txt
    else
end do

I am looking for error where a tag is missing.. something like.. 038339 here the invoice closing tag is missing or any way I can capture this

For those who might be intrested. The code below worked for me in Ubuntu 14.04 machine

find /YourMainFolder -name '*.xml' -print | xargs -I "{}" sh -c 'File="{}";xmllint --noout "${File}" || readlink -f {} >> errorlog.txt



via Chebli Mohamed