问:
Linq query returns half the results
I am making an intranet Website using asp.NET MVC5 and Entity Framework for Data Access. I have two tables Web_Documents and Web_Profiles and a relation's table Web_Profile_joint_Document. Now to retrieve the Documents I want, I have to use IDProfile of Web_Profiles table. Then using this, I can find documents in the relation's table. One problem though, the query I make returns half the results I want. In the test I am making I have 2 IDProfile, values being 120 & 124. Here is my query:

```<code>IEnumerable<Web_Documents> retrieveDocuments;
List<int> idProfiles = new List<int>();
idProfiles.Add(120);
idProfiles.Add(124);
foreach (var item in idProfiles)
{
    var idDocument = context.WebProfils
                    .Where(c => c.IDProfil == item)
                    .SelectMany(c => c.Documents).ToList();

    if (idDocument != null)
    {
         if (retrieveDocuments == null)
         {
              retrieveDocuments = idDocument;
         }
         else
         {
              retrieveDocuments.Concat(idDocument);
         }
}
</code>```

Since Web_Profiles and Web_Documents have a relation, I can access ICollection <Web_Documents> Documents which is in Web_Profiles POCO (entity). I then store results in retrieveDocuments. But this returns only the values for IDProfile=120. Any ideas why?

Thanks!

Remark All answers are good!

答:
The query as it is loads one profile at a time. It's not returning half the results, it's returing the results it was asked to return.

In SQL, you'd use an IN clause to return records that match multiple IDs, eg WHERE ID IN (1,4,7).

In LINQ, you can do the same by creating a list/array of values and using Contains :

```<code>var profiles = new[]{120,124};
var retrievedDocuments = context.WebProfils
                .Where(c => profiles.Contains(c.IDProfil))
                .SelectMany(c => c.Documents)
                .ToList();
</code>```

Title: Linq query returns half the results

Body:
I am making an intranet Website using asp.NET MVC5 and Entity Framework for Data Access. I have two tables Web_Documents and Web_Profiles and a relation's table Web_Profile_joint_Document. Now to retrieve the Documents I want, I have to use IDProfile of Web_Profiles table. Then using this, I can find documents in the relation's table. One problem though, the query I make returns half the results I want. In the test I am making I have 2 IDProfile, values being 120 & 124. Here is my query:

IEnumerable<Web_Documents> retrieveDocuments;
List<int> idProfiles = new List<int>();
idProfiles.Add(120);
idProfiles.Add(124);
foreach (var item in idProfiles)
{
    var idDocument = context.WebProfils
                    .Where(c => c.IDProfil == item)
                    .SelectMany(c => c.Documents).ToList();

    if (idDocument != null)
    {
         if (retrieveDocuments == null)
         {
              retrieveDocuments = idDocument;
         }
         else
         {
              retrieveDocuments.Concat(idDocument);
         }
}

Since Web_Profiles and Web_Documents have a relation, I can access ICollection <Web_Documents> Documents which is in Web_Profiles POCO (entity). I then store results in retrieveDocuments. But this returns only the values for IDProfile=120. Any ideas why?

Thanks!

Remark All answers are good!

Body:
The query as it is loads one profile at a time. It's not returning half the results, it's returing the results it was asked to return.

In SQL, you'd use an IN clause to return records that match multiple IDs, eg WHERE ID IN (1,4,7).

In LINQ, you can do the same by creating a list/array of values and using Contains :

var profiles = new[]{120,124};
var retrievedDocuments = context.WebProfils
                .Where(c => profiles.Contains(c.IDProfil))
                .SelectMany(c => c.Documents)
                .ToList();


来源: stackexchange

问:
Yocto getcap: command not found
I'm updating our yocto from fido to morty, and have been migrating recipes and such to work with it, but now I dont have getcap on the target.

I checked that PATH is correctly set up:

```<code>echo $PATH
/usr/sbin:/usr/bin...
</code>```

and that there is no getcap in /usr/bin/ as there should be.

I understood that libcap should provide these, and I have libcap as dependency on multiple recipe, which build just fine, so I don't understand why they are not installed on the target.

I have no clue where to start looking for the problem, so any help is appreciated!

答:
If you have a look at build output from libcap, for instance ${WORKDIR}/packages-split, you'll see that the following packages have been created:

```<code>libcap
libcap-bin
libcap-dbg
libcap-dev
libcap-doc
libcap-locale
libcap-staticdev
</code>```

The actual library has been put into libcap, while the helper binaries has been put into libcap-bin.

ContentLicense: CC BY-SA 3.0

Title: Yocto getcap: command not found

Body:
I'm updating our yocto from fido to morty, and have been migrating recipes and such to work with it, but now I dont have getcap on the target.

I checked that PATH is correctly set up:

echo $PATH
/usr/sbin:/usr/bin...

and that there is no getcap in /usr/bin/ as there should be.

I understood that libcap should provide these, and I have libcap as dependency on multiple recipe, which build just fine, so I don't understand why they are not installed on the target.

I have no clue where to start looking for the problem, so any help is appreciated!

Body:
If you have a look at build output from libcap, for instance ${WORKDIR}/packages-split, you'll see that the following packages have been created:

libcap
libcap-bin
libcap-dbg
libcap-dev
libcap-doc
libcap-locale
libcap-staticdev

The actual library has been put into libcap, while the helper binaries has been put into libcap-bin.


问:
iOS Changing App icon at runtime
I want to change my app icon at runtime. I read other similar threads on SO, and they say that it is not possible using Apple sanctioned APIs. One of the responses mentioned that its possible using restricted APIs, but did not elaborate.

I understand that if I use restricted APIs, my application scope will be reduced to jail-broken devices only. I'm ok with that, but how do I implement this feature.

Sorry, I cannot indicate any research effort for this question because I have no idea how to go about it or even how to get started on this.

Thanks in advance :)

答:
Although this is an old question, I recently discovered this is now possible, as of iOS 10.3:

https://developer.apple.com/documentation/uikit/uiapplication/2806818-setalternateiconname

...using the UIApplication.setAlternateIconName(_:completionHandler:) API.

Note however you are limited to using icons which are already shipped as part of the app bundle.

Title: iOS Changing App icon at runtime


问:
How to generate dev APK file without asking for dev settings server ip in react native
I am able to generate APK(not signed APK) file using android studio. if i install that apk then we need to enter Dev server ip address in dev settings then only app working. Now how to generate apk without need of giving any server ip?

Thanks.

答:
For debug apk you need to manually create the bundle for a debug build and generate apk using gradlew.

```<code>react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
cd android
./gradlew assembleDebug
</code>```

Generated apk will be located at android/app/build/outputs/apk

This apk run in debug mode. If you shake device and try dev setting menu for reload, It required server IP. but you can dismiss message. Your app will work properly.

You can also generate apk for release mode. It not required any IP and not show any dev setting.

To generate apk in release mode

```<code>cd android
./gradlew assembleRelease
</code>```

Body:
For debug apk you need to manually create the bundle for a debug build and generate apk using gradlew.

react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
cd android
./gradlew assembleDebug

Generated apk will be located at android/app/build/outputs/apk

This apk run in debug mode. If you shake device and try dev setting menu for reload, It required server IP. but you can dismiss message. Your app will work properly.

You can also generate apk for release mode. It not required any IP and not show any dev setting.

To generate apk in release mode

cd android
./gradlew assembleRelease


问:
Make multi line design of tag control
I have applied the evernote tag control which is working but the design is not in multi line as I add tag it is added next to the previous tag and adding in the single line, but it has to move down when there is no more space on the page. Here is the screenshot of what I want:

I have followed this link : http://stackoverflow.com/questions/15167809/how-can-i-create-a-tagging-control-similar-to-evernote-in-wpf but still unable to get the tags in multi line. Please let me know where I am going wrong. Following is my xaml:

```<code><!-- EvernoteTagControl default style -->
<Style TargetType="{x:Type local:EvernoteTagControl}">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="White"/>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="White" />
        <LinearGradientBrush x:Key="IconBrush" EndPoint="0,1">
            <GradientStop Color="#5890f0" Offset="0" />
            <GradientStop Color="#0351d7" Offset="1" />
        </LinearGradientBrush>
    </Style.Resources>
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="Margin" Value="15 25 15 15" />
    <Setter Property="MinHeight" Value="25" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:EvernoteTagControl}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <!--<ColumnDefinition Width="Auto" />-->
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <!--<Path Grid.Column="0" Margin="2" Fill="{StaticResource IconBrush}" Height="19" Stretch="Uniform" Data="M 50.535714,0.44196425 0.00446427,34.754464 l 0,106.906246 100.71874573,0 0,-107.124996 L 50.535714,0.44196425 z m 0.1875,21.21874975 c 6.311826,0 11.40625,5.094424 11.40625,11.40625 0,6.311826 -5.094424,11.4375 -11.40625,11.4375 -6.311826,0 -11.4375,-5.125674 -11.4375,-11.4375 0,-6.311826 5.125674,-11.40625 11.4375,-11.40625 z" />-->
                    <ItemsPresenter Grid.Column="0" Margin="2"  />
                    <Button Margin="5,0,0,0" Grid.Column="1" Content="Click to add..." x:Name="PART_CreateTagButton">
                        <Button.Template>
                            <ControlTemplate TargetType="Button">
                                <ContentPresenter TextElement.Foreground="#FF555555" VerticalAlignment="Center" />
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Cursor" Value="Hand" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEditing" Value="True">
                        <Setter TargetName="PART_CreateTagButton" Property="Visibility" Value="Collapsed" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
            </Style>
        </Setter.Value>
    </Setter>
    <Setter Property="ItemsPanel" >
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>

<!-- EvernoteTagItem default style -->
<Style TargetType="{x:Type local:EvernoteTagItem}">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="MinWidth" Value="50" />
    <Setter Property="Margin" Value="0,0,2,0" />
    <Setter Property="Padding" Value="5,2,0,2" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:EvernoteTagItem}">
                <Button x:Name="PART_TagButton" Content="{TemplateBinding Text}" Foreground="#ffffff" Margin="{TemplateBinding Margin}" Padding="{TemplateBinding Padding}">
                    <Button.Template>
                        <ControlTemplate TargetType="Button">
                            <Border Margin="{TemplateBinding Margin}" Padding="{TemplateBinding Padding}" BorderBrush="#00698C" BorderThickness="1" CornerRadius="2" Background="#00698C" >
                                <Grid >
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,0,0,2" />
                                    <Button x:Name="PART_DeleteTagButton" Grid.Column="1"  Margin="3,0" VerticalAlignment="Center" HorizontalAlignment="Right"   >
                                        <Button.Template>
                                            <ControlTemplate>
                                                <Grid Height="10" Width="10" Background="#00698C" >
                                                    <Path Stretch="Uniform" ClipToBounds="True"  Stroke="{StaticResource HighlightBrush}" StrokeThickness="1" Data="M 85.364473,6.9977109 6.0640998,86.29808 6.5333398,85.76586 M 6.9926698,7.4977169 86.293043,86.79809 85.760823,86.32885"  />
                                                </Grid>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>
                                </Grid>
                            </Border>
                            <!--<ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Foreground" Value="#ffffff" />
                                    <Setter TargetName="PART_DeleteTagButton" Property="Visibility" Value="Visible" />
                                </Trigger>
                            </ControlTemplate.Triggers>-->
                        </ControlTemplate>
                    </Button.Template>
                </Button>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsEditing" Value="True">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:EvernoteTagItem}">
                        <tkInput:AutoCompleteBox x:Name="PART_InputBox"
                                                         Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                                                         ItemsSource="{Binding AllTags, RelativeSource={RelativeSource AncestorType={x:Type local:EvernoteTagControl}}}"
                                                         IsTextCompletionEnabled="True"
                                                         />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>
</code>```

I am getting these tags as:

答:
Currently, you use a StackPanel as ItemsPanel, but a stack panel will never wrap its items in multiple dimensions. So instead, you should  try panels like WrapPanel or UniformGrid

For the WrapPanel, you also need to set a Width in the ItemContainerStyle in order to assure same size for all tag items (according to your "what I want" picture).

Then you have to decide on the positioning of your PART_CreateTagButton button. With multi lines of tags, the grid layout of ItemsPresenter and PART_CreateTagButton might no longer be appropriate.

You can probably create a compound items source of the original tag items source and the button as last item. This way, the button will always be properly aligned with the tags. See Add extra items when using ItemsSource and How do you bind a CollectionContainer to a collection in a view model? for more details.

Title: Make multi line design of tag control

Body:
I have applied the evernote tag control which is working but the design is not in multi line as I add tag it is added next to the previous tag and adding in the single line, but it has to move down when there is no more space on the page. Here is the screenshot of what I want:

I have followed this link : http://stackoverflow.com/questions/15167809/how-can-i-create-a-tagging-control-similar-to-evernote-in-wpf but still unable to get the tags in multi line. Please let me know where I am going wrong. Following is my xaml:

    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="Margin" Value="15 25 15 15" />
    <Setter Property="MinHeight" Value="25" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:EvernoteTagControl}">
                <Grid>
                    <Grid.ColumnDefinitions>

                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <ItemsPresenter Grid.Column="0" Margin="2"  />
                    <Button Margin="5,0,0,0" Grid.Column="1" Content="Click to add..." x:Name="PART_CreateTagButton">
                        <Button.Template>
                            <ControlTemplate TargetType="Button">
                                <ContentPresenter TextElement.Foreground="#FF555555" VerticalAlignment="Center" />
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Cursor" Value="Hand" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEditing" Value="True">
                        <Setter TargetName="PART_CreateTagButton" Property="Visibility" Value="Collapsed" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="ItemContainerStyle">
        <Setter.Value>

        </Setter.Value>
    </Setter>
    <Setter Property="ItemsPanel" >
        <Setter.Value>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
</Style>

</Style>

I am getting these tags as:


问:
Source Control MySQL Stored Procedure to TFS 2015
I'm tasked to Source control the mysql stored procedures to TFS 2015. I'm trying to use Visual studio 2015 to source control it.
I have been seeing blog/questions/forums about MS SQl server SProc source controled to TFS 2015 through Visual studio 2015 (Create a SQl server database project and import the SProc).
I'm unable to connect or change to mysql provider in Connection properties( in Database project)

Is there another way to source control mysql Stored proc to TFS 2015?
Please help me know, what Am i Missing?
Please suggest free tools only

Thank you

答:
You need the MySQL for Visual Studio for the connection in VS.

Try to install the mysql .net connector

Install and Configur for MySQL for Visual Studio

Making a Connection

The check if you can connect the MySql in the project.


问:
How to fetch 4 characters from a string in oracle?
By using following query i am able to fetch a particular string.Now this output string contains alphanumeric characters.e.g.abcd123,pqrs542356.
Now i want to fetch only first 4 characters of this string which will be always alpha bates.

Query::

```<code>(SELECT SUBSTR(in_msg, INSTR( in_msg,'?', 1, 10 )+ 1, INSTR(in_msg,'?', 1, 11 ) - INSTR( in_msg,'?', 1, 10 )- 1)
 FROM emp_message
WHERE emp_no IN (SELECT emp_no
                   FROM main_table
                  WHERE name like '%abcd%')
</code>```

This query returns output as e.g.abcd1234,pqrs145423.
Again i want to fetch only first 4 characters from this query output.
Can somebody help me in this.

答:
You can use substr (like you already do):</p>

```<code>SUBSTR(value, 1, 4)
</code>```

ContentLicense: CC BY-SA 2.5

Body:
By using following query i am able to fetch a particular string.Now this output string contains alphanumeric characters.e.g.abcd123,pqrs542356.
Now i want to fetch only first 4 characters of this string which will be always alpha bates.

Query::

(SELECT SUBSTR(in_msg, INSTR( in_msg,'?', 1, 10 )+ 1, INSTR(in_msg,'?', 1, 11 ) - INSTR( in_msg,'?', 1, 10 )- 1)
 FROM emp_message
WHERE emp_no IN (SELECT emp_no
                   FROM main_table
                  WHERE name like '%abcd%')

This query returns output as e.g.abcd1234,pqrs145423.
Again i want to fetch only first 4 characters from this query output.
Can somebody help me in this.

Body:
You can use substr (like you already do):

SUBSTR(value, 1, 4)


问:
Initializing a C++11 string with {}
What is the difference between initializing a string with:

```<code>std::string testString = "Test";
</code>```

and

```<code>std::string testString{"Test"};
</code>```

Is this only syntactic sugar thing or there actually are some performance related differences?

答:
The {} initialization syntax is known as the uniform initialization syntax, it has a few key differences, but in your code as is they both do the same thing - construct a std::string object from the string literal "Test"

Initializing an object with an assignment is essentially the same as putting the right hand side in parentheses and constructing the object.  For example the below two are the same

```<code>T obj = a;
T obj(a);
</code>```

So you should be asking yourself, what is the difference between constructing a string object the following two ways

```<code>std::string{"Test"};
std::string("Test");
</code>```

And the answer is that both the constructions above are the same and call the same constructor for std::string

For more on uniform initialization see https://softwareengineering.stackexchange.com/questions/133688/is-c11-uniform-initialization-a-replacement-for-the-old-style-syntax

Title: Initializing a C++11 string with {}

Body:
What is the difference between initializing a string with:

std::string testString = "Test";

and

std::string testString{"Test"};

Is this only syntactic sugar thing or there actually are some performance related differences?

Body:
The {} initialization syntax is known as the uniform initialization syntax, it has a few key differences, but in your code as is they both do the same thing - construct a std::string object from the string literal "Test"

Initializing an object with an assignment is essentially the same as putting the right hand side in parentheses and constructing the object.  For example the below two are the same

T obj = a;
T obj(a);

So you should be asking yourself, what is the difference between constructing a string object the following two ways

std::string{"Test"};
std::string("Test");

And the answer is that both the constructions above are the same and call the same constructor for std::string

For more on uniform initialization see https://softwareengineering.stackexchange.com/questions/133688/is-c11-uniform-initialization-a-replacement-for-the-old-style-syntax


问:
Front end stack for a webapp featuring 'drag n drop'
I am returning to web development after many years. I did web development before jQuery came along.

Now I see a lot of frameworks to choose from. I see web frameworks (aurelia, ember etc) and then web design frameworks (bootstrap, foundation etc).

My task at hand is too narrow down the technology options for a web app which will provide a certain drag and drop user interface to build workflows.

For drag n drop I have seen, not used, dragulla and interact.js

But not having a hands on experience I am in a confused state. The only certain thing at the moment is the backend which is going to be Django.

Can you please provide some guidance here? My main concern is the ability of doing a smooth drag and drop experience. I would also like to save the state of the flow which is designed by dropping the objects on the canvas, to keep the visual representation of the workflow.

Cheers

答:
A simple and basic drag and drop functionality is provided by jquery ui draggable.

You can see how simple it is to implement:

```<code><!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Draggable + Sortable</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  ul { list-style-type: none; margin: 0; padding: 0; margin-bottom: 10px; }
  li { margin: 5px; padding: 5px; width: 150px; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#sortable" ).sortable({
      revert: true
    });
    $( "#draggable" ).draggable({
      connectToSortable: "#sortable",
      helper: "clone",
      revert: "invalid"
    });
    $( "ul, li" ).disableSelection();
  } );
  </script>
</head>
<body>

<ul>
  <li id="draggable" class="ui-state-highlight">Drag me down</li>
</ul>

<ul id="sortable">
  <li class="ui-state-default">Item 1</li>
  <li class="ui-state-default">Item 2</li>
  <li class="ui-state-default">Item 3</li>
  <li class="ui-state-default">Item 4</li>
  <li class="ui-state-default">Item 5</li>
</ul>

</body>
</html>
</code>```

Body:
A simple and basic drag and drop functionality is provided by jquery ui draggable.

You can see how simple it is to implement:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Draggable + Sortable</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  ul { list-style-type: none; margin: 0; padding: 0; margin-bottom: 10px; }
  li { margin: 5px; padding: 5px; width: 150px; }
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#sortable" ).sortable({
      revert: true
    });
    $( "#draggable" ).draggable({
      connectToSortable: "#sortable",
      helper: "clone",
      revert: "invalid"
    });
    $( "ul, li" ).disableSelection();
  } );
  </script>
</head>
<body>

<ul>
  <li id="draggable" class="ui-state-highlight">Drag me down</li>
</ul>

<ul id="sortable">
  <li class="ui-state-default">Item 1</li>
  <li class="ui-state-default">Item 2</li>
  <li class="ui-state-default">Item 3</li>
  <li class="ui-state-default">Item 4</li>
  <li class="ui-state-default">Item 5</li>
</ul>

</body>
</html>


问:
How can i fix bootstrap input-group overflow in col-xs-*?
I tried to use an input-group in this website i build. In col-md-* and col-lg-* it behave properly. But when in col-xs-* it's overflowing the container like this

Can anybody help me with this problem?

The code:

```<code><div class="row" style="border:1px solid #c1c1c1">
    <form>
        <div class="form-group col-xs-5 col-md-3" style="padding:8px;">
            <label for="dari">blah</label>
            <input type="date" class="form-control" id="dari"/>
        </div>
        <style>
            @media(min-width: 992px){
                .col-md-1.stripe{
                    width: 1%;
                }
            }
            .col-xs-1.stripe{
                width: 1%;
            }
        </style>
        <div class="form-group col-xs-1 col-md-1 stripe" style="margin-top:2em; padding:8px;">
            <p><strong>-</strong></p>
        </div>
        <div class="col-xs-5 col-md-3" style="padding:8px;">
            <label for="sampai">blah</label>
            <div class="input-group">
                <input type="date" class="form-control" id="sampai"/>
                <span class="input-group-btn">
                    <button class="btn btn-default">
                        <i class="glyphicon glyphicon-search"></i>
                        <span>&nbsp Search</span>
                    </button>
                </span>
            </div>
        </div>
    </form>
</div>
</code>```

答:
Here's an example, you can solve it using

```<code>display: inline-block;
max-width: 100%;
</code>```

using on input-group..

In example i added inline style on second input-group and you can see difference between yours and new one.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <form>

            blah
            <input type="date" class="form-control" id="dari"/>

-

            blah

                <input type="date" class="form-control" id="sampai"/>

                    <button class="btn btn-default">

                        &nbsp Search
                    </button>

                <input type="date" class="form-control" id="sampai"/>

                    <button class="btn btn-default">

                        &nbsp Search
                    </button>

    </form>

```

Also i would suggest you to use col-xs-12 for larger columns on mobile, and hidden-xs for hidding the dash between.

Body:
I tried to use an input-group in this website i build. In col-md-* and col-lg-* it behave properly. But when in col-xs-* it's overflowing the container like this

Can anybody help me with this problem?

The code:

    <form>

            blah
            <input type="date" class="form-control" id="dari"/>

-

            blah

                <input type="date" class="form-control" id="sampai"/>

                    <button class="btn btn-default">

                        &nbsp Search
                    </button>

    </form>

Body:
Here's an example, you can solve it using

display: inline-block;
max-width: 100%;

using on input-group..

In example i added inline style on second input-group and you can see difference between yours and new one.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="row" style="border:1px solid #c1c1c1">
  <div class="col-xs-7" style="border: 1px solid #ccc;"><div class="row">
    <form>
        <div class="form-group col-xs-5 col-md-3" style="padding:8px;">
            <label for="dari">blah</label>
            <input type="date" class="form-control" id="dari"/>
        </div>
        <style>
            @media(min-width: 992px){
                .col-md-1.stripe{
                    width: 1%;
                }
            }
            .col-xs-1.stripe{
                width: 1%;
            }
        </style>
        <div class="form-group col-xs-1 col-md-1 stripe" style="margin-top:2em; padding:8px;">
            <p><strong>-</strong></p>
        </div>
        <div class="col-xs-5 col-md-3" style="padding:8px;">
            <label for="sampai">blah</label>
            <div class="input-group">
                <input type="date" class="form-control" id="sampai"/>
                <span class="input-group-btn">
                    <button class="btn btn-default">
                        <i class="glyphicon glyphicon-search"></i>
                        <span>&nbsp Search</span>
                    </button>
                </span>
            </div>

            <div class="input-group" style="display: inline-block; max-width: 100%;">
                <input type="date" class="form-control" id="sampai"/>
                <span class="input-group-btn">
                    <button class="btn btn-default">
                        <i class="glyphicon glyphicon-search"></i>
                        <span>&nbsp Search</span>
                    </button>
                </span>
            </div>
        </div>
    </form>
    </div></div>
</div>

Also i would suggest you to use col-xs-12 for larger columns on mobile, and hidden-xs for hidding the dash between.


问:
How to access Python class in another folder when building Django management command?
I'm trying to turn a Python script into a Django management command. My script is in an application folder called sites. Folder structure:

```<code>project
|--sites
   |scanner.py
   |--management
      |__init__.py
      |--commands
         |__init__.py
         |getdeals.py
</code>```

I'm trying to have getdeals.py run as a management command. It finds objects in my Site model and then uses them to create an instance of the SiteDeals class, which is in the scanner.py file.

getdeals.py:

```<code>from django.core.management.base import BaseCommand
from sites.models import Site

class Command(BaseCommand):

    help = "Scans all sites for deals"

    def handle(self, *args, **options):
        site_set = Site.objects.all()

        for site in site_set:
            scraper = SiteDeals(site)
</code>```

When I run python manage.py getdeals it says NameError: name 'SiteDeals' is not defined.

I thought of taking the code from handle and writing it as a main() function in scanner.py, and then accessing it from getdeals.py, but can't work out how to access it that way.

How do I access SiteDeals from the scanner.py file, given that it is in another folder from my management/commands folder, so that I can pass my objects to it?

答:
You need to import SiteDeals, just as you import the Site model. Try:

```<code>from sites.scanner import SiteDeals
</code>```

Body:
I'm trying to turn a Python script into a Django management command. My script is in an application folder called sites. Folder structure:

project
|--sites
   |scanner.py
   |--management
      |__init__.py
      |--commands
         |__init__.py
         |getdeals.py

I'm trying to have getdeals.py run as a management command. It finds objects in my Site model and then uses them to create an instance of the SiteDeals class, which is in the scanner.py file.

getdeals.py:

from django.core.management.base import BaseCommand
from sites.models import Site

class Command(BaseCommand):

    help = "Scans all sites for deals"

    def handle(self, *args, **options):
        site_set = Site.objects.all()

        for site in site_set:
            scraper = SiteDeals(site)

When I run python manage.py getdeals it says NameError: name 'SiteDeals' is not defined.

I thought of taking the code from handle and writing it as a main() function in scanner.py, and then accessing it from getdeals.py, but can't work out how to access it that way.

How do I access SiteDeals from the scanner.py file, given that it is in another folder from my management/commands folder, so that I can pass my objects to it?

Body:
You need to import SiteDeals, just as you import the Site model. Try:

from sites.scanner import SiteDeals


问:
ClassCastException in oracle.sql.ArrayDescriptor.createDescriptor
I am getting a ClassCastException while creating a ArrayDescriptor in web application.
I am getting the connection from Tomcat DBCP Connection pool  using jndi lookup.
I am using ojdbc.jar  14 driver jar, Oracle 11g server, Tomcat 7 server and JDK 8.
I am not getting the oracle.jdbc.OracleConnection object from the connection that is returned from the pool.

Below is the error stack trace :

```<code>java.lang.ClassCastException: com.sun.proxy.$Proxy34 cannot be cast to oracle.jdbc.OracleConnection
        at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:149)
        at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:115)
</code>```

the connection sysout is:

```<code>ProxyConnection[PooledConnection[oracle.jdbc.driver.T4CConnection@770799c2]]
</code>```

JNDI config in server.xml in Tomcat below:-

```<code> Resource
         name="jdbc/my_db"
         auth="Container"``
         type="javax.sql.DataSource"
         factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
         initialSize="5"
         maxActive="5"
         maxIdle="2"
         minIdle="1"
         maxTotal="10"
         maxWaitMillis="10000"
         timeBetweenEvictionRunsMillis="34000"
         minEvictableIdleTimeMillis="55000"
         validationQuery="SELECT 1 FROM DUAL"
         validationInterval="34000"
         testOnBorrow="true"
         removeAbandoned="true"
         removeAbandonedTimeout="55"
         driverClassName="oracle.jdbc.OracleDriver"
         url="jdbc:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
         username="aaaaaaa"
         password="bbbbbbbbbb"
         connectionProperties="SetBigStringTryClob=true"
         accessToUnderlyingConnectionAllowed="true"/>
</code>```

using Hibernate to get connection:-

```<code>getSession().doWork(new Work() {
            @Override
            public void execute(Connection connection) throws SQLException {

                ArrayDescriptor descNum =
     ArrayDescriptor.createDescriptor("ARRAY_NUMC", connection );
}
</code>```

I also used connection unwrap method , but not works.

答: Always try to use the latest JDBC driver i.e., 12.2.0.1 JDBC driver is available on OTN. </p>

Body:
I am getting a ClassCastException while creating a ArrayDescriptor in web application.
I am getting the connection from Tomcat DBCP Connection pool  using jndi lookup.
I am using ojdbc.jar  14 driver jar, Oracle 11g server, Tomcat 7 server and JDK 8.
I am not getting the oracle.jdbc.OracleConnection object from the connection that is returned from the pool.

Below is the error stack trace :

java.lang.ClassCastException: com.sun.proxy.$Proxy34 cannot be cast to oracle.jdbc.OracleConnection
        at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:149)
        at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:115)

the connection sysout is:

ProxyConnection[PooledConnection[oracle.jdbc.driver.T4CConnection@770799c2]]

JNDI config in server.xml in Tomcat below:-

 Resource
         name="jdbc/my_db"
         auth="Container"``
         type="javax.sql.DataSource"
         factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
         initialSize="5"
         maxActive="5"
         maxIdle="2"
         minIdle="1"
         maxTotal="10"
         maxWaitMillis="10000"
         timeBetweenEvictionRunsMillis="34000"
         minEvictableIdleTimeMillis="55000"
         validationQuery="SELECT 1 FROM DUAL"
         validationInterval="34000"
         testOnBorrow="true"
         removeAbandoned="true"
         removeAbandonedTimeout="55"
         driverClassName="oracle.jdbc.OracleDriver"
         url="jdbc:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
         username="aaaaaaa"
         password="bbbbbbbbbb"
         connectionProperties="SetBigStringTryClob=true"
         accessToUnderlyingConnectionAllowed="true"/>

using Hibernate to get connection:-

getSession().doWork(new Work() {
            @Override
            public void execute(Connection connection) throws SQLException {

                ArrayDescriptor descNum =
     ArrayDescriptor.createDescriptor("ARRAY_NUMC", connection );
}

I also used connection unwrap method , but not works.


问:
Merge two table based on row name
I need to merge two table into one based on Row name, each table has 172 rows and 172 columns example of my data look

```<code>#table 1
A B C
1 2 3
2 3 4
5 6 7

#table 2
A B C
1 3 8
2 4 6
5 4 2
</code>```

I want my output like this

```<code>A B C
1 2 3
1 3 8
2 3 4
2 4 6
5 6 7
5 4 2
</code>```

答:
We can use rbind with order

```<code>rbind(table1, table2)[order(c(seq_len(nrow(table1)), seq_len(nrow(table2)))),]
#   A B C
#1 1 2 3
#4 1 3 8
#2 2 3 4
#5 2 4 6
#3 5 6 7
#6 5 4 2
</code>```

Title: Merge two table based on row name

Body:
I need to merge two table into one based on Row name, each table has 172 rows and 172 columns example of my data look

#table 1
A B C
1 2 3
2 3 4
5 6 7

#table 2
A B C
1 3 8
2 4 6
5 4 2

I want my output like this

A B C
1 2 3
1 3 8
2 3 4
2 4 6
5 6 7
5 4 2

Body:
We can use rbind with order

rbind(table1, table2)[order(c(seq_len(nrow(table1)), seq_len(nrow(table2)))),]
#   A B C
#1 1 2 3
#4 1 3 8
#2 2 3 4
#5 2 4 6
#3 5 6 7
#6 5 4 2


问:
what the name for the item in the green circle
what's the element name in the green circle? Whta's the event corresponding to click this element?

答:
In at least one example I found, clicking the gray triangle in the corner causes all rows to be selected.

But this is not a built-in feature of this control as far as I know. It is part of a custom template.

See this example:
http://www.dotnetspark.com/kb/2941-styling-wpf-datagrid.aspx

If you download the sample, and search the Resources/DataGridCustomization.xaml file for "SelectAll", you'll find the part of the template that contains this feature.


问:
Update values from multiple selected rows
I have 2 tables. Both have the same amount of rows.

Sample data:

```<code>Table1{
    Id, IdTable2Row
}

Table2 {
    Id, RedChicken -- LOL
}
</code>```

Each row of Table1 (column IdTable2Row) should get the id of 1 row of table 2 (irrelevant which one).
Table1.IdTable2Row is null in every row before the operation.

How can I do something like this?

```<code>UPDATE Table1 SET IdTable2Row = (SELECT Id FROM [Table2])
</code>```

答:
```<code>update T1
set idtablerow = t2.id
from Table1 T1
inner join Table2 T2
on T1.something = T2.something
</code>```

In your case, with no common column:

```<code>with T1 as
(
select Table1.*, row_number() over (order by anycolumn) rn
from Table1
)
update T1
set idtablerow = t2.id
from T1
inner join
(
select x1.*, row_number() over (order by id) rn
from Table2 x1
) T2
on t1.rn = t2.rn
</code>```

Should work

Body:
I have 2 tables. Both have the same amount of rows.

Sample data:

Table1{
    Id, IdTable2Row
}

Table2 {
    Id, RedChicken -- LOL
}

Each row of Table1 (column IdTable2Row) should get the id of 1 row of table 2 (irrelevant which one).
Table1.IdTable2Row is null in every row before the operation.

How can I do something like this?

UPDATE Table1 SET IdTable2Row = (SELECT Id FROM [Table2])

Body:
update T1
set idtablerow = t2.id
from Table1 T1
inner join Table2 T2
on T1.something = T2.something

In your case, with no common column:

with T1 as
(
select Table1.*, row_number() over (order by anycolumn) rn
from Table1
)
update T1
set idtablerow = t2.id
from T1
inner join
(
select x1.*, row_number() over (order by id) rn
from Table2 x1
) T2
on t1.rn = t2.rn

Should work


问:
How to use bundler behind a proxy?
I get the following output from the sudo bundle install command:

```<code>Fetching source index for `http://rubygems.org/`
Could not reach rubygems repository `http://rubygems.org/`
Could not find gem 'rspec-rails (>= 2.0.0.beta.22, runtime)' in any of the gem sources.
</code>```

I have $http_proxy set correctly and I've added gem: --http-proxy=my proxy to ~/.gemrc. These settings are what allow my gem commands to work, and I was hoping they would translate to bundler, but no such luck.

Thinking sudo might not inherit my all of my environment, I also added those settings to my root user, but nada.

At this point bundler is preventing me from deploying my application, and I can find very few others running into this. If no one has an answer I will be forced to rip bundler out of my Rails app (which I wouldn't mind doing...)

答:
OSX & Linux

```<code>export http_proxy=http://user:password@host:port
export HTTP_PROXY=$http_proxy
</code>```

If it's using HTTPS, set it as well

```<code>export https_proxy=http://user:password@host:port
export HTTPS_PROXY=$https_proxy
</code>```

If you use sudo, by default sudo does not preserves http proxy variable. Use -E flag to preserve it

```<code>$ sudo -E bundle install
</code>```

to make sudo preserves environment variables by default:

https://memset.wordpress.com/2010/10/14/bash-http_proxy-from-a-user-environment-to-sudo-one/

Windows

As pointed by answers below, you can use SET instead

```<code>SET HTTP_PROXY=http://user:password@host:port
SET HTTPS_PROXY=%HTTP_PROXY%
</code>```

Title: How to use bundler behind a proxy?

Body:
I get the following output from the sudo bundle install command:

Fetching source index for `http://rubygems.org/`
Could not reach rubygems repository `http://rubygems.org/`
Could not find gem 'rspec-rails (>= 2.0.0.beta.22, runtime)' in any of the gem sources.

I have $http_proxy set correctly and I've added gem: --http-proxy=my proxy to ~/.gemrc. These settings are what allow my gem commands to work, and I was hoping they would translate to bundler, but no such luck.

Thinking sudo might not inherit my all of my environment, I also added those settings to my root user, but nada.

At this point bundler is preventing me from deploying my application, and I can find very few others running into this. If no one has an answer I will be forced to rip bundler out of my Rails app (which I wouldn't mind doing...)

Body:
OSX & Linux

export http_proxy=http://user:password@host:port
export HTTP_PROXY=$http_proxy

If it's using HTTPS, set it as well

export https_proxy=http://user:password@host:port
export HTTPS_PROXY=$https_proxy

If you use sudo, by default sudo does not preserves http proxy variable. Use -E flag to preserve it

$ sudo -E bundle install

to make sudo preserves environment variables by default:

https://memset.wordpress.com/2010/10/14/bash-http_proxy-from-a-user-environment-to-sudo-one/

Windows

As pointed by answers below, you can use SET instead

SET HTTP_PROXY=http://user:password@host:port
SET HTTPS_PROXY=%HTTP_PROXY%

ContentLicense: CC BY-SA 4.0


问:
data retrieved error with firebase on Android
There are some problems on my Android app with Firebase.

The thing is I created a login function for my app on Android Studio using Firebase, but I have to click the "Login" button twice. It won't retrieve the data when you just click the button at the first time. Thank you.

Here is the java code.

```<code> package com.jax.android.jaxsqrcodeattendancesystemsecond;

    import android.content.Intent;
    import android.os.AsyncTask;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.google.firebase.database.ChildEventListener;
    import com.google.firebase.database.DataSnapshot;
    import com.google.firebase.database.DatabaseError;
    import com.google.firebase.database.DatabaseReference;
    import com.google.firebase.database.FirebaseDatabase;
    import com.google.firebase.database.Query;
    import com.google.gson.Gson;

    public class LoginActivity extends AppCompatActivity {
        private EditText username;
        private EditText password;
        private Button buttonLogin;
        private TextView registerHere;

        boolean validated = false;
        String TAG = "TAG: ";
        public User user = new User();
        DatabaseReference mDatabaseReference = FirebaseDatabase.getInstance().getReference("user");

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

            username = (EditText)findViewById(R.id.etUsername);
            password = (EditText)findViewById(R.id.etPassword);
            buttonLogin = (Button)findViewById(R.id.buttonLogin);
            registerHere = (TextView)findViewById(R.id.tvRegisterHere);

            //Login Button
            buttonLogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   AsyncLoginTask task  = new AsyncLoginTask();
                    task.execute();
                    System.out.println("There are " + "User name : " +" " +  user.getUserName() + " "+ "user password " + " :"
                            + user.getPassword() );

                }
            });

            registerHere.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
                    startActivity(intent);
                }
            });
        }

        private class AsyncLoginTask extends AsyncTask<String, Void, Void>{

            @Override
            protected Void doInBackground(String... params) {
                Log.i(TAG,"doInBackground");
                if(validated){
                    // open next activity
                    Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                    startActivity(intent);

                }
                return null;
            }

            @Override
            protected void onPreExecute() {
                String mUsername = username.getText().toString();
                String mPassword = password.getText().toString();
                Log.i(TAG, "onPreExecute");
                Query query =  mDatabaseReference.orderByChild("userName").equalTo(mUsername);
                query.addChildEventListener(new ChildEventListener() {
                    @Override
                    public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                        user  = dataSnapshot.getValue(User.class);
                    }

                    @Override
                    public void onChildChanged(DataSnapshot dataSnapshot, String s) {

                    }

                    @Override
                    public void onChildRemoved(DataSnapshot dataSnapshot) {

                    }

                    @Override
                    public void onChildMoved(DataSnapshot dataSnapshot, String s) {

                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });

                if (mUsername != "" && mUsername.equals(user.getUserName())){

                    if (password.getText().length()!= 0 && mPassword.equals(user.getPassword())){
                        validated = true;

                    }else{
                        Toast toast = Toast.makeText(getApplicationContext(), "User name and password don't match", Toast.LENGTH_LONG);
                        toast.show();
                        validated = false;
                    }

                }else{
                    Toast toast = Toast.makeText(getApplicationContext(), "please enter User name!", Toast.LENGTH_LONG);
                    toast.show();
                    validated = false;
                }

            }

            @Override
            protected void onPostExecute(Void aVoid) {
                if (validated){

                    Toast toast = Toast.makeText(getApplicationContext(), "Login Successful!", Toast.LENGTH_LONG);
                    toast.show();
                }
                else{
                    Toast toast = Toast.makeText(getApplicationContext(), "Error Occured!", Toast.LENGTH_LONG);
                    toast.show();
                }

               /* if (user.getName() != null && user != null) {
                    Gson gson = new Gson();
                    String myJson = gson.toJson(user);
                    Intent intent = new Intent( getApplicationContext() ,MainActivity.class);
                    intent.putExtra("USER_INFO", myJson);
                    startActivity(intent);

                }*/

            }
        }

    }
</code>```

And layout XML

```<code>  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.jax.android.jaxsqrcodeattendancesystemsecond.LoginActivity">

    <EditText
        android:id="@+id/etUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Username"
        />

    <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Password"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/buttonLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:text="Login" />

    <TextView
        android:id="@+id/tvRegisterHere"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Register Here"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
        android:layout_gravity="center"
        />
</LinearLayout>
</code>```

LogCat

```<code>07-07 11:43:11.722 2888-2888/? I/art: Not late-enabling -Xcheck:jni (already on)
07-07 11:43:11.723 2888-2888/? W/art: Unexpected CPU variant for X86 using defaults: x86
07-07 11:43:11.745 2888-2896/? E/art: Failed sending reply to debugger: Broken pipe
07-07 11:43:11.745 2888-2896/? I/art: Debugger is no longer active
07-07 11:43:11.745 2888-2896/? I/art: Starting a blocking GC Instrumentation
07-07 11:43:11.840 2888-2888/? W/System: ClassLoader referenced unknown path: /data/app/com.jax.android.jaxsqrcodeattendancesystemsecond-1/lib/x86
07-07 11:43:11.850 2888-2888/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
07-07 11:43:11.856 2888-2888/? D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
07-07 11:43:11.865 2888-2888/? I/FA: App measurement is starting up, version: 11011
07-07 11:43:11.865 2888-2888/? I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
07-07 11:43:11.877 2888-2888/? V/FA: Collection enabled
07-07 11:43:11.878 2888-2888/? V/FA: App package, google app id: com.jax.android.jaxsqrcodeattendancesystemsecond, 1:1070300143559:android:089e2e22ef09d40c
07-07 11:43:11.878 2888-2888/? I/FA: To enable faster debug mode event logging run:
                                       adb shell setprop debug.firebase.analytics.app com.jax.android.jaxsqrcodeattendancesystemsecond
07-07 11:43:11.878 2888-2888/? D/FA: Debug-level message logging enabled
07-07 11:43:11.881 2888-2888/? V/FA: Cancelling job. JobID: 803327265
07-07 11:43:11.883 2888-2888/? V/FA: Registered activity lifecycle callback
07-07 11:43:11.883 2888-2888/? I/FirebaseInitProvider: FirebaseApp initialization successful
07-07 11:43:11.900 2888-2918/? V/FA: Using measurement service
07-07 11:43:11.901 2888-2918/? V/FA: Connecting to remote service
07-07 11:43:11.903 2888-2888/? W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10298470
07-07 11:43:11.903 2888-2888/? I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:0
07-07 11:43:11.903 2888-2888/? I/DynamiteModule: Selected local version of com.google.android.gms.firebase_database
07-07 11:43:11.903 2888-2918/? W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10298470
07-07 11:43:11.909 2888-2918/? V/FA: Using measurement service
07-07 11:43:11.910 2888-2918/? V/FA: Connection attempt already in progress
07-07 11:43:11.912 2888-2888/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-07 11:43:11.914 2888-2888/? V/FA: onActivityCreated
07-07 11:43:11.940 2888-2921/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default
07-07 11:43:11.970 2888-2918/? V/FA: Using measurement service
07-07 11:43:11.970 2888-2918/? V/FA: Connection attempt already in progress
07-07 11:43:11.971 2888-2918/? V/FA: Activity resumed, time: 16635
07-07 11:43:11.976 2888-2918/? I/FA: Tag Manager is not found and thus will not be used
07-07 11:43:11.977 2888-2918/? D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=1414208018607190867}]
07-07 11:43:11.997 2888-2888/? W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
07-07 11:43:12.014 2888-2918/? V/FA: Using measurement service
07-07 11:43:12.014 2888-2918/? V/FA: Connecting to remote service
07-07 11:43:12.019 2888-2918/? W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10298470
07-07 11:43:12.020 2888-2918/? V/FA: Processing queued up service tasks: 4
07-07 11:43:12.020 2888-2918/? E/FA: Discarding data. Failed to send app launch
07-07 11:43:12.020 2888-2918/? E/FA: Failed to get app instance id
07-07 11:43:12.020 2888-2918/? E/FA: Failed to send current screen to service
07-07 11:43:12.020 2888-2918/? E/FA: Discarding data. Failed to send event to service
07-07 11:43:12.068 2888-2932/? I/OpenGLRenderer: Initialized EGL, version 1.4
07-07 11:43:12.068 2888-2932/? D/OpenGLRenderer: Swap behavior 1
07-07 11:43:12.068 2888-2932/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
07-07 11:43:12.068 2888-2932/? D/OpenGLRenderer: Swap behavior 0
07-07 11:43:12.406 2888-2888/? W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
07-07 11:43:12.407 2888-2918/? V/FA: Processing queued up service tasks: 0
07-07 11:43:33.469 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
07-07 11:43:39.465 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond I/TAG:: onPreExecute
07-07 11:43:39.471 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond I/System.out: There are User name :  null user password  :null
07-07 11:43:39.471 2888-2941/com.jax.android.jaxsqrcodeattendancesystemsecond I/TAG:: doInBackground
07-07 11:43:39.675 2888-2919/com.jax.android.jaxsqrcodeattendancesystemsecond W/PersistentConnection: pc_0 - Using an unspecified index. Consider adding '".indexOn": "userName"' at user to your security and Firebase Database rules for better performance
07-07 11:43:44.664 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond I/TAG:: onPreExecute
07-07 11:43:44.665 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond I/System.out: There are User name :  test01 user password  :123
07-07 11:43:44.667 2888-2942/com.jax.android.jaxsqrcodeattendancesystemsecond I/TAG:: doInBackground
07-07 11:43:44.679 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Recording user engagement, ms: 32709
07-07 11:43:44.680 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Using measurement service
07-07 11:43:44.680 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Connecting to remote service
07-07 11:43:44.682 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10298470
07-07 11:43:44.682 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Activity paused, time: 49340
07-07 11:43:44.683 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: onActivityCreated
07-07 11:43:44.688 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=32709, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=1414208018607190867}]
07-07 11:43:44.705 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Using measurement service
07-07 11:43:44.705 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Connection attempt already in progress
07-07 11:43:44.728 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Using measurement service
07-07 11:43:44.728 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Connection attempt already in progress
07-07 11:43:44.728 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Activity resumed, time: 49394
07-07 11:43:44.730 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=LoginActivity, firebase_previous_id(_pi)=1414208018607190867, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=1414208018607190868}]
07-07 11:43:44.739 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Using measurement service
07-07 11:43:44.739 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Connection attempt already in progress
07-07 11:43:45.059 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Processing queued up service tasks: 4
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond E/FA: Failed to send current screen to service
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond E/FA: Discarding data. Failed to send event to service
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond E/FA: Failed to send current screen to service
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond E/FA: Discarding data. Failed to send event to service
07-07 11:43:45.198 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
07-07 11:43:45.224 2888-2932/com.jax.android.jaxsqrcodeattendancesystemsecond D/OpenGLRenderer: endAllActiveAnimators on 0x9431e800 (RippleDrawable) with handle 0x943526d0
</code>```

Logcat Error.

See, When I first time click the login button, it doesn't have any data.

答:
I recomand you using Firebase authentication. You don't need to code your own algorithm and don't need to maintain it in the future. You can also use Google signin too.

Hope it helps.

Body:
There are some problems on my Android app with Firebase.

The thing is I created a login function for my app on Android Studio using Firebase, but I have to click the "Login" button twice. It won't retrieve the data when you just click the button at the first time. Thank you.

Here is the java code.

 package com.jax.android.jaxsqrcodeattendancesystemsecond;

    import android.content.Intent;
    import android.os.AsyncTask;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.google.firebase.database.ChildEventListener;
    import com.google.firebase.database.DataSnapshot;
    import com.google.firebase.database.DatabaseError;
    import com.google.firebase.database.DatabaseReference;
    import com.google.firebase.database.FirebaseDatabase;
    import com.google.firebase.database.Query;
    import com.google.gson.Gson;

    public class LoginActivity extends AppCompatActivity {
        private EditText username;
        private EditText password;
        private Button buttonLogin;
        private TextView registerHere;

        boolean validated = false;
        String TAG = "TAG: ";
        public User user = new User();
        DatabaseReference mDatabaseReference = FirebaseDatabase.getInstance().getReference("user");

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

            username = (EditText)findViewById(R.id.etUsername);
            password = (EditText)findViewById(R.id.etPassword);
            buttonLogin = (Button)findViewById(R.id.buttonLogin);
            registerHere = (TextView)findViewById(R.id.tvRegisterHere);

            //Login Button
            buttonLogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   AsyncLoginTask task  = new AsyncLoginTask();
                    task.execute();
                    System.out.println("There are " + "User name : " +" " +  user.getUserName() + " "+ "user password " + " :"
                            + user.getPassword() );

                }
            });

            registerHere.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
                    startActivity(intent);
                }
            });
        }

        private class AsyncLoginTask extends AsyncTask<String, Void, Void>{

            @Override
            protected Void doInBackground(String... params) {
                Log.i(TAG,"doInBackground");
                if(validated){
                    // open next activity
                    Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                    startActivity(intent);

                }
                return null;
            }

            @Override
            protected void onPreExecute() {
                String mUsername = username.getText().toString();
                String mPassword = password.getText().toString();
                Log.i(TAG, "onPreExecute");
                Query query =  mDatabaseReference.orderByChild("userName").equalTo(mUsername);
                query.addChildEventListener(new ChildEventListener() {
                    @Override
                    public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                        user  = dataSnapshot.getValue(User.class);
                    }

                    @Override
                    public void onChildChanged(DataSnapshot dataSnapshot, String s) {

                    }

                    @Override
                    public void onChildRemoved(DataSnapshot dataSnapshot) {

                    }

                    @Override
                    public void onChildMoved(DataSnapshot dataSnapshot, String s) {

                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });

                if (mUsername != "" && mUsername.equals(user.getUserName())){

                    if (password.getText().length()!= 0 && mPassword.equals(user.getPassword())){
                        validated = true;

                    }else{
                        Toast toast = Toast.makeText(getApplicationContext(), "User name and password don't match", Toast.LENGTH_LONG);
                        toast.show();
                        validated = false;
                    }

                }else{
                    Toast toast = Toast.makeText(getApplicationContext(), "please enter User name!", Toast.LENGTH_LONG);
                    toast.show();
                    validated = false;
                }

            }

            @Override
            protected void onPostExecute(Void aVoid) {
                if (validated){

                    Toast toast = Toast.makeText(getApplicationContext(), "Login Successful!", Toast.LENGTH_LONG);
                    toast.show();
                }
                else{
                    Toast toast = Toast.makeText(getApplicationContext(), "Error Occured!", Toast.LENGTH_LONG);
                    toast.show();
                }

               /* if (user.getName() != null && user != null) {
                    Gson gson = new Gson();
                    String myJson = gson.toJson(user);
                    Intent intent = new Intent( getApplicationContext() ,MainActivity.class);
                    intent.putExtra("USER_INFO", myJson);
                    startActivity(intent);

                }*/

            }
        }

    }

And layout XML

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.jax.android.jaxsqrcodeattendancesystemsecond.LoginActivity">

    <EditText
        android:id="@+id/etUsername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Username"
        />

    <EditText
        android:id="@+id/etPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Password"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/buttonLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:text="Login" />

    <TextView
        android:id="@+id/tvRegisterHere"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Register Here"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
        android:layout_gravity="center"
        />
</LinearLayout>

LogCat

07-07 11:43:11.722 2888-2888/? I/art: Not late-enabling -Xcheck:jni (already on)
07-07 11:43:11.723 2888-2888/? W/art: Unexpected CPU variant for X86 using defaults: x86
07-07 11:43:11.745 2888-2896/? E/art: Failed sending reply to debugger: Broken pipe
07-07 11:43:11.745 2888-2896/? I/art: Debugger is no longer active
07-07 11:43:11.745 2888-2896/? I/art: Starting a blocking GC Instrumentation
07-07 11:43:11.840 2888-2888/? W/System: ClassLoader referenced unknown path: /data/app/com.jax.android.jaxsqrcodeattendancesystemsecond-1/lib/x86
07-07 11:43:11.850 2888-2888/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
07-07 11:43:11.856 2888-2888/? D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
07-07 11:43:11.865 2888-2888/? I/FA: App measurement is starting up, version: 11011
07-07 11:43:11.865 2888-2888/? I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
07-07 11:43:11.877 2888-2888/? V/FA: Collection enabled
07-07 11:43:11.878 2888-2888/? V/FA: App package, google app id: com.jax.android.jaxsqrcodeattendancesystemsecond, 1:1070300143559:android:089e2e22ef09d40c
07-07 11:43:11.878 2888-2888/? I/FA: To enable faster debug mode event logging run:
                                       adb shell setprop debug.firebase.analytics.app com.jax.android.jaxsqrcodeattendancesystemsecond
07-07 11:43:11.878 2888-2888/? D/FA: Debug-level message logging enabled
07-07 11:43:11.881 2888-2888/? V/FA: Cancelling job. JobID: 803327265
07-07 11:43:11.883 2888-2888/? V/FA: Registered activity lifecycle callback
07-07 11:43:11.883 2888-2888/? I/FirebaseInitProvider: FirebaseApp initialization successful
07-07 11:43:11.900 2888-2918/? V/FA: Using measurement service
07-07 11:43:11.901 2888-2918/? V/FA: Connecting to remote service
07-07 11:43:11.903 2888-2888/? W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10298470
07-07 11:43:11.903 2888-2888/? I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:0
07-07 11:43:11.903 2888-2888/? I/DynamiteModule: Selected local version of com.google.android.gms.firebase_database
07-07 11:43:11.903 2888-2918/? W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10298470
07-07 11:43:11.909 2888-2918/? V/FA: Using measurement service
07-07 11:43:11.910 2888-2918/? V/FA: Connection attempt already in progress
07-07 11:43:11.912 2888-2888/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-07 11:43:11.914 2888-2888/? V/FA: onActivityCreated
07-07 11:43:11.940 2888-2921/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default
07-07 11:43:11.970 2888-2918/? V/FA: Using measurement service
07-07 11:43:11.970 2888-2918/? V/FA: Connection attempt already in progress
07-07 11:43:11.971 2888-2918/? V/FA: Activity resumed, time: 16635
07-07 11:43:11.976 2888-2918/? I/FA: Tag Manager is not found and thus will not be used
07-07 11:43:11.977 2888-2918/? D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=1414208018607190867}]
07-07 11:43:11.997 2888-2888/? W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
07-07 11:43:12.014 2888-2918/? V/FA: Using measurement service
07-07 11:43:12.014 2888-2918/? V/FA: Connecting to remote service
07-07 11:43:12.019 2888-2918/? W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10298470
07-07 11:43:12.020 2888-2918/? V/FA: Processing queued up service tasks: 4
07-07 11:43:12.020 2888-2918/? E/FA: Discarding data. Failed to send app launch
07-07 11:43:12.020 2888-2918/? E/FA: Failed to get app instance id
07-07 11:43:12.020 2888-2918/? E/FA: Failed to send current screen to service
07-07 11:43:12.020 2888-2918/? E/FA: Discarding data. Failed to send event to service
07-07 11:43:12.068 2888-2932/? I/OpenGLRenderer: Initialized EGL, version 1.4
07-07 11:43:12.068 2888-2932/? D/OpenGLRenderer: Swap behavior 1
07-07 11:43:12.068 2888-2932/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
07-07 11:43:12.068 2888-2932/? D/OpenGLRenderer: Swap behavior 0
07-07 11:43:12.406 2888-2888/? W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
07-07 11:43:12.407 2888-2918/? V/FA: Processing queued up service tasks: 0
07-07 11:43:33.469 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
07-07 11:43:39.465 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond I/TAG:: onPreExecute
07-07 11:43:39.471 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond I/System.out: There are User name :  null user password  :null
07-07 11:43:39.471 2888-2941/com.jax.android.jaxsqrcodeattendancesystemsecond I/TAG:: doInBackground
07-07 11:43:39.675 2888-2919/com.jax.android.jaxsqrcodeattendancesystemsecond W/PersistentConnection: pc_0 - Using an unspecified index. Consider adding '".indexOn": "userName"' at user to your security and Firebase Database rules for better performance
07-07 11:43:44.664 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond I/TAG:: onPreExecute
07-07 11:43:44.665 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond I/System.out: There are User name :  test01 user password  :123
07-07 11:43:44.667 2888-2942/com.jax.android.jaxsqrcodeattendancesystemsecond I/TAG:: doInBackground
07-07 11:43:44.679 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Recording user engagement, ms: 32709
07-07 11:43:44.680 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Using measurement service
07-07 11:43:44.680 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Connecting to remote service
07-07 11:43:44.682 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond W/GooglePlayServicesUtil: Google Play services out of date.  Requires 11011000 but found 10298470
07-07 11:43:44.682 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Activity paused, time: 49340
07-07 11:43:44.683 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: onActivityCreated
07-07 11:43:44.688 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=32709, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=1414208018607190867}]
07-07 11:43:44.705 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Using measurement service
07-07 11:43:44.705 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Connection attempt already in progress
07-07 11:43:44.728 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Using measurement service
07-07 11:43:44.728 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Connection attempt already in progress
07-07 11:43:44.728 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Activity resumed, time: 49394
07-07 11:43:44.730 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=LoginActivity, firebase_previous_id(_pi)=1414208018607190867, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=1414208018607190868}]
07-07 11:43:44.739 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Using measurement service
07-07 11:43:44.739 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Connection attempt already in progress
07-07 11:43:45.059 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond V/FA: Processing queued up service tasks: 4
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond E/FA: Failed to send current screen to service
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond E/FA: Discarding data. Failed to send event to service
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond E/FA: Failed to send current screen to service
07-07 11:43:45.061 2888-3455/com.jax.android.jaxsqrcodeattendancesystemsecond E/FA: Discarding data. Failed to send event to service
07-07 11:43:45.198 2888-2888/com.jax.android.jaxsqrcodeattendancesystemsecond W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
07-07 11:43:45.224 2888-2932/com.jax.android.jaxsqrcodeattendancesystemsecond D/OpenGLRenderer: endAllActiveAnimators on 0x9431e800 (RippleDrawable) with handle 0x943526d0

Logcat Error.

See, When I first time click the login button, it doesn't have any data.


问:
define a link (GET) on trigger
How can I send my mysql table parameters to a link through GET?

e.x. : http:/example.com/Send.ashx?id=[member.id]&name=[class.name]

答:
You cannot access MySQL via http directly. You will need to set up a rest API server that handles http requests, makes the corresponding SQL queries, formats the result (typically as json or XML) and sends it back to the client.

In case you already have an API / web server, we need more detailed information on your setup

Title: define a link (GET) on trigger


问:
Find Pattern in arrays
I have two sub-sequences of values and the values can be 0, -1 and 1.
The values reprensent the slope, 0 for null, -1 for negative one and 1 for positive one.
I want to join the two sub-sequences and build the sequence that represent the "union" of the two sub-sequences.

Example here : 1

a1 = [0 -1 0 1] and r1 = [0 -1 0] give me p1 = [0 -1 0 1]

a2 = [-1 0] and r2 = [0 1] give me p2 = [-1 0 1]

But i cannot find an algorithm working well. In fact the problem is that the values are not unique so the union doesn't do well.

Thanks in advance for your help.

Baptiste.

答: Here is an idea how you could solve your problem (assuming a2 is the smaller array, otherwise just swap)(actually, it should be irrelevant which array is larger)

Title: Find Pattern in arrays


问:
iPhone - Change icon of the app programmatically at runtime
I can read that changing the app icon programmatically at runtime is not possible, at least since iOS 3.0.

But... I regulary can see on "App" websites apps that can put icons on the springboard. The first I remember is that kind of app that you give a friend's picture from your album, and it creates an icon so you can call him just clicking on that icon:

http://itunes.apple.com/fr/app/speedtouch-the-best-home-screen/id378360978?mt=8

http://itunes.apple.com/fr/app/desktop-shortcut/id421701004?mt=8

http://itunes.apple.com/fr/app/appbutler-app-organizer/id327391626?mt=8

http://itunes.apple.com/fr/app/tap4music/id365578914?mt=8

So I guess, is it still impossible to change the app icon programmatically at runtime?

答:
This is now possible in iOS 10.3 using the UIApplication.setAlternateIconName(_:completionHandler:) API.

See my answer to this question: https://stackoverflow.com/a/44966454/233602


问:
Vscode extension track changes of html in previewHtml
I'm displaying a TextDocumentContentProvider using previewHtml. Is it possible to track the addition of text into the textbox that i'm displaying in this previewHtml ?

答: We don't do this automatically but your extension can certainly use the previous html preview contents to track changes or generate a diff</p>


问:
how to include different nav panels with ui-router
I have two sections to my AngularJS app which need separate nav bars:

Patents

patent nav bar: list patents, add patents

Transactions

transaction nav bar: current transactions, transaction history

I have read How to attach navbar only on certain pages using ui-router?, where you can use views, but that is including the templateUrl in the state, where I have my templateUrl declared in the component like so:

```<code>$stateProvider
.state('patents', {
   url: '/patents',
   component: 'patents',
})

angular.module('myApp').component('patents', {
    bindings: { patents: '<' },
    templateUrl: '../templates/patents/list/list-patents.htm'
});
</code>```

Question

What is the best approach to include different navigation in my templates/states when using components in ui-router? Apologies if the answer is straight forward.

答:
Method 1

Through ng-include in your template:

```<code><div ng-include="'link/to/template.html'"></div>
</code>```

Method 2

More dynamically, you can create a custom <navigation> component, which sets the correct template through a $stateParam.

Router:

```<code>.state('patents', {
    url         : '/patents',
    component   : 'patents',
    params      : {
        navigation  : 'custom'
    }
})
</code>```

And then, in your navigation component, you can use

```<code>template    : function($stateParams) {
    var navigation = $stateParam.navigation || 'default';
    return '<div ng-include="\''link/to/' + navigation + '.html'\'"></div>
},
</code>```

So you only have to set the param in your router when there is a custom navigation for that page.

Make sure though to include <navigation> on every page.

Method 3

In case you don't want to include <navigation> on every page, you can also create a single navigation menu (like you probably have now), and add a controller, with the following method

```<code>app.controller('NavigationCtrl', function($rootScope, $state) {
    $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
        this.navigation = toParams.navigation;
    });
})
</code>```

The you can capture the toParams on every route update, and use that to dynamically change the template:

Navigation template:

```<code><div class="nav" ng-controller="NavigationCtrl as $ctrl">

    <div ng-if="$ctrl.navigation === 'default'">
        // Include default
    </div>

    <div ng-if="$ctrl.navigation === 'custom'">
        // Include custom
    </div>

</div>
</code>```

Body:
I have two sections to my AngularJS app which need separate nav bars:

Patents

patent nav bar: list patents, add patents

Transactions

transaction nav bar: current transactions, transaction history

I have read How to attach navbar only on certain pages using ui-router?, where you can use views, but that is including the templateUrl in the state, where I have my templateUrl declared in the component like so:

$stateProvider
.state('patents', {
   url: '/patents',
   component: 'patents',
})

angular.module('myApp').component('patents', {
    bindings: { patents: '<' },
    templateUrl: '../templates/patents/list/list-patents.htm'
});

Question

What is the best approach to include different navigation in my templates/states when using components in ui-router? Apologies if the answer is straight forward.

Body:
Method 1

Through ng-include in your template:

<div ng-include="'link/to/template.html'"></div>

Method 2

More dynamically, you can create a custom <navigation> component, which sets the correct template through a $stateParam.

Router:

.state('patents', {
    url         : '/patents',
    component   : 'patents',
    params      : {
        navigation  : 'custom'
    }
})

And then, in your navigation component, you can use

template    : function($stateParams) {
    var navigation = $stateParam.navigation || 'default';
    return '<div ng-include="\''link/to/' + navigation + '.html'\'"></div>
},

So you only have to set the param in your router when there is a custom navigation for that page.

Make sure though to include <navigation> on every page.

Method 3

In case you don't want to include <navigation> on every page, you can also create a single navigation menu (like you probably have now), and add a controller, with the following method

app.controller('NavigationCtrl', function($rootScope, $state) {
    $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
        this.navigation = toParams.navigation;
    });
})

The you can capture the toParams on every route update, and use that to dynamically change the template:

Navigation template:

<div class="nav" ng-controller="NavigationCtrl as $ctrl">

    <div ng-if="$ctrl.navigation === 'default'">
        // Include default
    </div>

    <div ng-if="$ctrl.navigation === 'custom'">
        // Include custom
    </div>

</div>


问:
Import Excel to SQL Server 2005 using Sqlbulkupload
I want to upload excel file using SqlBulkCopy into a SQL Server 2005 table. My excel file size is 43MB. When I am uploading this file it will display error message that

The request filtering module is
  configured to deny a request that
  exceeds the request content length.

My web.config file setting is

```<code><httpRuntime executionTimeout="12000" maxRequestLength="2097151"
             useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
             minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>
</code>```

Thanks in advance.

答:
maxAllowedContentLength:

Optional uint attribute.

Specifies the maximum length of
  content in a request, in bytes.

The default value is 30000000.

Not that this has anything to do with SQL Server or bulk copy...

Body:
I want to upload excel file using SqlBulkCopy into a SQL Server 2005 table. My excel file size is 43MB. When I am uploading this file it will display error message that

The request filtering module is
  configured to deny a request that
  exceeds the request content length.

My web.config file setting is

<httpRuntime executionTimeout="12000" maxRequestLength="2097151"
             useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
             minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>

Thanks in advance.


问:
Gradle DSL method not found : testCompile()
I am using gradle version - 3.3-all and gradle plugin - gradle:2.3.3
I want to write test cases. So as per this page, I included the following in the the app's top build.gradle file.

```<code>        testCompile 'junit:junit:4.12'
        testCompile 'org.mockito:mockito-core:1.10.19'
</code>```

But I get the error saying

```<code>Error:(11, 0) Gradle DSL method not found: 'testCompile()'
Possible causes:<ul><li>The project 'TopLevelProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
</code>```

What could be the issue?

答:
Add the Java plugin</p>

```<code>apply plugin: 'java'
</code>```

Body:
I am using gradle version - 3.3-all and gradle plugin - gradle:2.3.3
I want to write test cases. So as per this page, I included the following in the the app's top build.gradle file.

        testCompile 'junit:junit:4.12'
        testCompile 'org.mockito:mockito-core:1.10.19'

But I get the error saying

Error:(11, 0) Gradle DSL method not found: 'testCompile()'
Possible causes:

The project 'TopLevelProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).

What could be the issue?

Body:
Add the Java plugin

apply plugin: 'java'


问:
How to Specify Python Version PyInstaller Uses?
I have Python 2.7 & 3.5 on my system.  I'm using OS X 10.12.  Python 2.7 is the default on the system.

When building PyInstaller using...

```<code>pyinstaller myscript.py
</code>```

...PyInstaller uses Python 2.7.

Perhaps I missed it, but I can't find anywhere in PyInstaller documentation that would allow me to specify the Python version.

Does anyone know how constrain PyInstaller to use the non-default Python version 3.5?

I've tried building using Macports.

After using command....

```<code>sudo port select python python35
</code>```

I get a confirmed...

```<code>Selecting 'python35' for 'python' succeeded. 'python35' is now active.
</code>```

Then when trying to build using...

```<code>pyinstaller main.py --onefile
</code>```

PyInstaller shows it's building with 2.7...

```<code>68 INFO: PyInstaller: 3.2.1
68 INFO: Python: 2.7.13
</code>```

Where am I going wrong?

答:
I solved a similar problem on Windows(10) using venv:
https://docs.python.org/3/library/venv.html

I first installed the version of python (3.5.2), that I thought would work with PyInstaller (3.2.1). Then I created a virtual environment. Next I activated that venv. Installed pyinstaller and ran pyinstaller.

It made my executable ok, whereas PyInstaller: 3.2.1 failed miserably with Python: 3.6.1.

Here is some pseudo cmd line commands, but you get the idea from reading the URL above.

```<code>Python35-32\python -m venv <venvpath>
cd <venvpath>
.\Scripts\activate
pip install PyInstaller
pyinstaller -F -c buildtest.py
</code>```

Body:
I have Python 2.7 & 3.5 on my system.  I'm using OS X 10.12.  Python 2.7 is the default on the system.

When building PyInstaller using...

pyinstaller myscript.py

...PyInstaller uses Python 2.7.

Perhaps I missed it, but I can't find anywhere in PyInstaller documentation that would allow me to specify the Python version.

Does anyone know how constrain PyInstaller to use the non-default Python version 3.5?

I've tried building using Macports.

After using command....

sudo port select python python35

I get a confirmed...

Selecting 'python35' for 'python' succeeded. 'python35' is now active.

Then when trying to build using...

pyinstaller main.py --onefile

PyInstaller shows it's building with 2.7...

68 INFO: PyInstaller: 3.2.1
68 INFO: Python: 2.7.13

Where am I going wrong?

Body:
I solved a similar problem on Windows(10) using venv:
https://docs.python.org/3/library/venv.html

I first installed the version of python (3.5.2), that I thought would work with PyInstaller (3.2.1). Then I created a virtual environment. Next I activated that venv. Installed pyinstaller and ran pyinstaller.

It made my executable ok, whereas PyInstaller: 3.2.1 failed miserably with Python: 3.6.1.

Here is some pseudo cmd line commands, but you get the idea from reading the URL above.

Python35-32\python -m venv <venvpath>
cd <venvpath>
.\Scripts\activate
pip install PyInstaller
pyinstaller -F -c buildtest.py


问:
Linq query returns half the results
I am making an intranet Website using asp.NET MVC5 and Entity Framework for Data Access. I have two tables Web_Documents and Web_Profiles and a relation's table Web_Profile_joint_Document. Now to retrieve the Documents I want, I have to use IDProfile of Web_Profiles table. Then using this, I can find documents in the relation's table. One problem though, the query I make returns half the results I want. In the test I am making I have 2 IDProfile, values being 120 & 124. Here is my query:

```<code>IEnumerable<Web_Documents> retrieveDocuments;
List<int> idProfiles = new List<int>();
idProfiles.Add(120);
idProfiles.Add(124);
foreach (var item in idProfiles)
{
    var idDocument = context.WebProfils
                    .Where(c => c.IDProfil == item)
                    .SelectMany(c => c.Documents).ToList();

    if (idDocument != null)
    {
         if (retrieveDocuments == null)
         {
              retrieveDocuments = idDocument;
         }
         else
         {
              retrieveDocuments.Concat(idDocument);
         }
}
</code>```

Since Web_Profiles and Web_Documents have a relation, I can access ICollection <Web_Documents> Documents which is in Web_Profiles POCO (entity). I then store results in retrieveDocuments. But this returns only the values for IDProfile=120. Any ideas why?

Thanks!

Remark All answers are good!

答:
Replace Your Code</p>

```<code>retrieveDocuments=retrieveDocuments.Concat(idDocument);
</code>```

Title: Linq query returns half the results

Body:
I am making an intranet Website using asp.NET MVC5 and Entity Framework for Data Access. I have two tables Web_Documents and Web_Profiles and a relation's table Web_Profile_joint_Document. Now to retrieve the Documents I want, I have to use IDProfile of Web_Profiles table. Then using this, I can find documents in the relation's table. One problem though, the query I make returns half the results I want. In the test I am making I have 2 IDProfile, values being 120 & 124. Here is my query:

IEnumerable<Web_Documents> retrieveDocuments;
List<int> idProfiles = new List<int>();
idProfiles.Add(120);
idProfiles.Add(124);
foreach (var item in idProfiles)
{
    var idDocument = context.WebProfils
                    .Where(c => c.IDProfil == item)
                    .SelectMany(c => c.Documents).ToList();

    if (idDocument != null)
    {
         if (retrieveDocuments == null)
         {
              retrieveDocuments = idDocument;
         }
         else
         {
              retrieveDocuments.Concat(idDocument);
         }
}

Since Web_Profiles and Web_Documents have a relation, I can access ICollection <Web_Documents> Documents which is in Web_Profiles POCO (entity). I then store results in retrieveDocuments. But this returns only the values for IDProfile=120. Any ideas why?

Thanks!

Remark All answers are good!

Body:
Replace Your Code

retrieveDocuments=retrieveDocuments.Concat(idDocument);