问:
Programmatically uncheck checkboxcolumn in datagridview
How can I programmatically uncheck all rows in a DataGridViewCheckboxColumn in a datagridview?

I can get the correct value of the checkbox using

```<code>(bool)row.Cells[CheckBoxColumn.Index].FormattedValue
</code>```

but that's only a getter.

I have tried setting the value of the cell using

```<code>(bool)row.Cells[CheckBoxColumn.Index].value = false
</code>```

but that doesn't affect the FormattedValue.

How can I solve this?

答:
You do sth. like:

```<code>(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;
</code>```

You just forgot to cast to the correct type, a generic DataGridViewCell doesn't know its value-type.

Body:
How can I programmatically uncheck all rows in a DataGridViewCheckboxColumn in a datagridview?

I can get the correct value of the checkbox using

(bool)row.Cells[CheckBoxColumn.Index].FormattedValue

but that's only a getter.

I have tried setting the value of the cell using

(bool)row.Cells[CheckBoxColumn.Index].value = false

but that doesn't affect the FormattedValue.

How can I solve this?

Body:
You do sth. like:

(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;

You just forgot to cast to the correct type, a generic DataGridViewCell doesn't know its value-type.

ContentLicense: CC BY-SA 4.0


来源: stackexchange

问:
Karma / jasmine-marbles: test failure message not properly formatted
I have added jasmine-marbles to my project and I am getting error messages like this:

```<code>Expected $[0].frame = 20 to equal 70.
Expected $[0].notification.kind = 'E' to equal 'N'.
Expected $[0].notification.value = undefined to equal LoadSuccess().
</code>```

instead of something like this:

```<code>Expected
    {"frame":50,"notification":{"kind":"N","value":{"payload":"[
...
to deep equal
    {"frame":40,"notification":{"kind":"N","value":{"payload":"[
...
</code>```

Test:

```<code>it('should loadData$', () => {
    const action = new LoadRequest('123');
    const completion = new LoadSuccess({});

    actions$.stream = hot('-a', { a: action });
    const response = cold('-a|', { a: {} });
    const expected = cold('---c', { c: completion });

    client.loadData = () => response;

    expect(effects.loadData$).toBeObservable(expected);
});
</code>```

package.json:

```<code>"devDependencies": {
    "jasmine-core": "^2.3.4",
    "jasmine-marbles": "^0.2.0",
    "jasmine-spec-reporter": "^3.2.0",
    "karma": "1.4.1",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "^1.0.0",
    "karma-jasmine": "^1.1.0",
    "karma-mocha-reporter": "^2.2.5",
    "karma-remap-istanbul": "0.2.1",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "2.0.2",
   ...
</code>```

How to fix the test failure message? Is it related to some karma reporter / plugin / missing library?

答:
See package.json,

```<code>"jasmine": "^2.5.3",
"jasmine-core": "~2.5.2",
</code>```

I don't know if it makes a difference.

ContentLicense: CC BY-SA 3.0

Body:
I have added jasmine-marbles to my project and I am getting error messages like this:

Expected $[0].frame = 20 to equal 70.
Expected $[0].notification.kind = 'E' to equal 'N'.
Expected $[0].notification.value = undefined to equal LoadSuccess().

instead of something like this:

Expected
    {"frame":50,"notification":{"kind":"N","value":{"payload":"[
...
to deep equal
    {"frame":40,"notification":{"kind":"N","value":{"payload":"[
...

Test:

it('should loadData$', () => {
    const action = new LoadRequest('123');
    const completion = new LoadSuccess({});

    actions$.stream = hot('-a', { a: action });
    const response = cold('-a|', { a: {} });
    const expected = cold('---c', { c: completion });

    client.loadData = () => response;

    expect(effects.loadData$).toBeObservable(expected);
});

package.json:

"devDependencies": {
    "jasmine-core": "^2.3.4",
    "jasmine-marbles": "^0.2.0",
    "jasmine-spec-reporter": "^3.2.0",
    "karma": "1.4.1",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "^1.0.0",
    "karma-jasmine": "^1.1.0",
    "karma-mocha-reporter": "^2.2.5",
    "karma-remap-istanbul": "0.2.1",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "2.0.2",
   ...

How to fix the test failure message? Is it related to some karma reporter / plugin / missing library?

Body:
See package.json,

"jasmine": "^2.5.3",
"jasmine-core": "~2.5.2",

I don't know if it makes a difference.


问:
PHP get array from string
I have an array in string given below.

```<code>$string="
"Status":true,
"ReVerifiedCount":1,
"ProfilePrefix":"INVTRK"
";
</code>```

How I can get array from this string same as it exists in string.

答:
```<code><?php

$string='{
"Status":true,
"ReVerifiedCount":1,
"ProfilePrefix":"INVTRK"
}';

$data=json_decode($string,true);
print_r($data);
</code>```

I formated your string-json the right way. Your double quotes and the missing brackets were creating the main problem as your input was not a valid json.

Output is this:

```<code>Array ( [Status] => 1 [ReVerifiedCount] => 1 [ProfilePrefix] => INVTRK )
</code>```

Title: PHP get array from string

Body:
I have an array in string given below.

$string="
"Status":true,
"ReVerifiedCount":1,
"ProfilePrefix":"INVTRK"
";

How I can get array from this string same as it exists in string.

Body:
<?php

$string='{
"Status":true,
"ReVerifiedCount":1,
"ProfilePrefix":"INVTRK"
}';

$data=json_decode($string,true);
print_r($data);

I formated your string-json the right way. Your double quotes and the missing brackets were creating the main problem as your input was not a valid json.

Output is this:

Array ( [Status] => 1 [ReVerifiedCount] => 1 [ProfilePrefix] => INVTRK )


问:
Sharing a complex object between processes?
I have a fairly complex Python object that I need to share between multiple processes. I launch these processes using multiprocessing.Process. When I share an object with multiprocessing.Queue and multiprocessing.Pipe in it, they are shared just fine. But when I try to share an object with other non-multiprocessing-module objects, it seems like Python forks these objects. Is that true?

I tried using multiprocessing.Value. But I'm not sure what the type should be? My object class is called MyClass. But when I try multiprocess.Value(MyClass, instance), it fails with:

TypeError: this type has no size

Any idea what's going on?

答:
here's a python package I made just for that (sharing complex objects between processes).

git: https://github.com/dRoje/pipe-proxy

The idea is you create a proxy for your object and pass it to a process. Then you use the proxy like you have a reference to the original object. Although you can only use method calls, so accessing object variables is done threw setters and getters.

Say we have an object called ‘example’, creating proxy and proxy listener is easy:

```<code>from pipeproxy import proxy
example = Example()
exampleProxy, exampleProxyListener = proxy.createProxy(example)
</code>```

Now you send the proxy to another process.

```<code>p = Process(target=someMethod, args=(exampleProxy,)) p.start()
</code>```

Use it in the other process as you would use the original object (example):

```<code>def someMethod(exampleProxy):
    ...
    exampleProxy.originalExampleMethod()
    ...
</code>```

But you do have to listen to it in the main process:

```<code>exampleProxyListener.listen()
</code>```

Read more and find examples here:

http://matkodjipalo.com/index.php/2017/11/12/proxy-solution-python-multiprocessing/

Body:
here's a python package I made just for that (sharing complex objects between processes).

git: https://github.com/dRoje/pipe-proxy

The idea is you create a proxy for your object and pass it to a process. Then you use the proxy like you have a reference to the original object. Although you can only use method calls, so accessing object variables is done threw setters and getters.

Say we have an object called ‘example’, creating proxy and proxy listener is easy:

from pipeproxy import proxy
example = Example()
exampleProxy, exampleProxyListener = proxy.createProxy(example)

Now you send the proxy to another process.

p = Process(target=someMethod, args=(exampleProxy,)) p.start()

Use it in the other process as you would use the original object (example):

def someMethod(exampleProxy):
    ...
    exampleProxy.originalExampleMethod()
    ...

But you do have to listen to it in the main process:

exampleProxyListener.listen()

Read more and find examples here:

http://matkodjipalo.com/index.php/2017/11/12/proxy-solution-python-multiprocessing/


问:
bash "wc -l" command output differs if call or through tee
When I issued two equivalent commands in Bash I got different output (from "wc -l" command), see below:

```<code>root@devel:~# ls /usr/bin -lha | tee >(wc -l) >(head) > /dev/null
total 76M
drwxr-xr-x  2 root root      20K Nov 11 18:58 .
drwxr-xr-x 10 root root     4.0K Oct  8 15:31 ..
-rwxr-xr-x  1 root root      51K Feb 22  2017 [
-rwxr-xr-x  1 root root       96 Jan 19  2017 2to3-3.5
-rwxr-xr-x  1 root root      23K Mar 22  2017 addpart
lrwxrwxrwx  1 root root       26 May 10  2017 addr2line -> x86_64-linux-gnu-    addr2line
lrwxrwxrwx  1 root root        6 Dec 13  2016 apropos -> whatis
-rwxr-xr-x  1 root root      15K Sep 13 19:47 apt
-rwxr-xr-x  1 root root      79K Sep 13 19:47 apt-cache
137
root@devel:~# ls /usr/bin -lha | wc -l
648
</code>```

what am I missing?

it's strange, but when I call it this way it gets even stranger output:

```<code>root@devel:~# ls /usr/bin -lha | tee >(wc) >(wc) > /dev/null
648    6121   39179
648    6121   39179
root@devel:~# ls /usr/bin -lha | tee >(wc) >(wc) > /dev/null
648    6121   39179
648    6121   39179
root@devel:~# ls /usr/bin -lha | tee >(wc) >(wc -l) > /dev/null
648
root@devel:~#     648    6121   39179
</code>```

seems like commands running asynchronously and ends in different time... or what it can be?

答:
Simple answer:

how to fix:

```<code>ls /usr/bin -lha | tee <b>--output-error=exit-nopipe</b> >(wc -l) >(head) > /dev/null
</code>```

Details:

The command head only prints the head of input, so it can finish its job as long as it gets enough input, then exits without waiting for all input.

So let's replace command head with the simple "head".

```<code>ls /usr/bin -lha | tee >(wc -l) <b>>(read l; echo $l)</b> > /dev/null</code>```

The simple "head" will read only one line, then exit, which causes that the pipe file gets closed immediately before tee finishes transferring all data to it.

So no doubt, you'll get same result with the simple "head". wc still prints wrong number.

The root reason of your issue, I think you can conclude yourself, is that one of the output pipes of tee is closed earlier, tee hits a write error, and then stops writing to other output files.

After understanding the root reason, I think it would be very easy for you to understand the following section in man page.

MODE determines behavior with write errors on the outputs:
   'warn' diagnose errors writing to any output

   'warn-nopipe'
          diagnose errors writing to any output not a pipe

   'exit' exit on error writing to any output

   'exit-nopipe'
          exit on error writing to any output not a pipe

   The  default MODE for the -p option is 'warn-nopipe'.  The default operation
   when --output-error is not specified, is to exit immediately on error writing to
   a pipe, and diagnose errors writing to non pipe outputs.
```

Some extra words

Actually if you replace >(wc -l) with a regular file in your problematic command line, you will find the file size will always be 16384 or 20480 or 32768 or 36864 or 28672 or ..., all of which are the multiple of 4096. (The writing to the regular file is incomplete because tee aborts earlier. If the writing was complete, the file size would be any value.)

4096 is the value of PIPE_BUF for most UNIX-like system. If you know what PIPE_BUF is, you will easily understand why the file size is always the multiple of 4096.

Body:
When I issued two equivalent commands in Bash I got different output (from "wc -l" command), see below:

root@devel:~# ls /usr/bin -lha | tee >(wc -l) >(head) > /dev/null
total 76M
drwxr-xr-x  2 root root      20K Nov 11 18:58 .
drwxr-xr-x 10 root root     4.0K Oct  8 15:31 ..
-rwxr-xr-x  1 root root      51K Feb 22  2017 [
-rwxr-xr-x  1 root root       96 Jan 19  2017 2to3-3.5
-rwxr-xr-x  1 root root      23K Mar 22  2017 addpart
lrwxrwxrwx  1 root root       26 May 10  2017 addr2line -> x86_64-linux-gnu-    addr2line
lrwxrwxrwx  1 root root        6 Dec 13  2016 apropos -> whatis
-rwxr-xr-x  1 root root      15K Sep 13 19:47 apt
-rwxr-xr-x  1 root root      79K Sep 13 19:47 apt-cache
137
root@devel:~# ls /usr/bin -lha | wc -l
648

what am I missing?

it's strange, but when I call it this way it gets even stranger output:

root@devel:~# ls /usr/bin -lha | tee >(wc) >(wc) > /dev/null
648    6121   39179
648    6121   39179
root@devel:~# ls /usr/bin -lha | tee >(wc) >(wc) > /dev/null
648    6121   39179
648    6121   39179
root@devel:~# ls /usr/bin -lha | tee >(wc) >(wc -l) > /dev/null
648
root@devel:~#     648    6121   39179

seems like commands running asynchronously and ends in different time... or what it can be?

Body:
Simple answer:

how to fix:

ls /usr/bin -lha | tee --output-error=exit-nopipe >(wc -l) >(head) > /dev/null

Details:

The command head only prints the head of input, so it can finish its job as long as it gets enough input, then exits without waiting for all input.

So let's replace command head with the simple "head".

ls /usr/bin -lha | tee >(wc -l) >(read l; echo $l) > /dev/null

The simple "head" will read only one line, then exit, which causes that the pipe file gets closed immediately before tee finishes transferring all data to it.

So no doubt, you'll get same result with the simple "head". wc still prints wrong number.

The root reason of your issue, I think you can conclude yourself, is that one of the output pipes of tee is closed earlier, tee hits a write error, and then stops writing to other output files.

After understanding the root reason, I think it would be very easy for you to understand the following section in man page.

MODE determines behavior with write errors on the outputs:
   'warn' diagnose errors writing to any output

   'warn-nopipe'
          diagnose errors writing to any output not a pipe

   'exit' exit on error writing to any output

   'exit-nopipe'
          exit on error writing to any output not a pipe

   The  default MODE for the -p option is 'warn-nopipe'.  The default operation
   when --output-error is not specified, is to exit immediately on error writing to
   a pipe, and diagnose errors writing to non pipe outputs.

Some extra words

Actually if you replace >(wc -l) with a regular file in your problematic command line, you will find the file size will always be 16384 or 20480 or 32768 or 36864 or 28672 or ..., all of which are the multiple of 4096. (The writing to the regular file is incomplete because tee aborts earlier. If the writing was complete, the file size would be any value.)

4096 is the value of PIPE_BUF for most UNIX-like system. If you know what PIPE_BUF is, you will easily understand why the file size is always the multiple of 4096.


问:
Returning value after several Runnable finish
Currently I have a code as follow :

```<code>public String getValue()
{
   StringBuilder builder = new StringBuilder();
   // 1st step
   //some logic to retreive code from database returning value
   //doing something with the returned value add it to collection
   builder.append(someString1);
   // 2nd step
   //some logic to retreive code from database returning value
   //doing something with the returned value add it to collection
   builder.append(someString2);
   // 3rd step
   //some logic to retreive code from database returning value
   //doing something with the returned value add it to collection
   builder.append(someString3);

   return builder.toString();
}
</code>```

I've read about Runnable object that can be used to split process into several thread, which going change my code into something like this :

```<code>public String getValue()
{
     Thread firstTread = new Thread(new Process1());
     firstTread.start();
     Thread secondTread = new Thread(new Process1());
     secondTread.start();
     Thread thirdTread = new Thread(new Process1());
     thirdTread.start();

     // here i got confuse how to determine whether all thread allready finished
     // before returning builder.toString();
}
//this is internal class
class Process1 implements Runnable
{
    public void run()
    {
      //do something and add to StringBuilder
    }
}

class Process2 implements Runnable
{
    public void run()
    {
      //do something and add to StringBuilder
    }
}

class Process3 implements Runnable
{
    public void run()
    {
      //do something and add to StringBuilder
    }
}
</code>```

How can I achieve that my goal to split the process into several thread?

答:
There are other alternatives for parallelising your work, but to answer your direct question on how to wait for a thread to finish, you can use</p>

```<code>firstTread.join();
secondTread.join();
thirdTread.join();
</code>```

Body:
Currently I have a code as follow :

public String getValue()
{
   StringBuilder builder = new StringBuilder();
   // 1st step
   //some logic to retreive code from database returning value
   //doing something with the returned value add it to collection
   builder.append(someString1);
   // 2nd step
   //some logic to retreive code from database returning value
   //doing something with the returned value add it to collection
   builder.append(someString2);
   // 3rd step
   //some logic to retreive code from database returning value
   //doing something with the returned value add it to collection
   builder.append(someString3);

   return builder.toString();
}

I've read about Runnable object that can be used to split process into several thread, which going change my code into something like this :

public String getValue()
{
     Thread firstTread = new Thread(new Process1());
     firstTread.start();
     Thread secondTread = new Thread(new Process1());
     secondTread.start();
     Thread thirdTread = new Thread(new Process1());
     thirdTread.start();

     // here i got confuse how to determine whether all thread allready finished
     // before returning builder.toString();
}
//this is internal class
class Process1 implements Runnable
{
    public void run()
    {
      //do something and add to StringBuilder
    }
}

class Process2 implements Runnable
{
    public void run()
    {
      //do something and add to StringBuilder
    }
}

class Process3 implements Runnable
{
    public void run()
    {
      //do something and add to StringBuilder
    }
}

How can I achieve that my goal to split the process into several thread?

Body:
There are other alternatives for parallelising your work, but to answer your direct question on how to wait for a thread to finish, you can use

firstTread.join();
secondTread.join();
thirdTread.join();


答:
Callable suits better for such task cause it returns result.

ExecutorService helps to incapsulate threads management.

```<code>  public static void main(String[] args) throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(3);
    List<Future<String>> futures = new ArrayList<>();
    futures.add(executorService.submit(new Process1()));
    futures.add(executorService.submit(new Process2()));
    futures.add(executorService.submit(new Process3()));

    StringBuilder sb = new StringBuilder();
    for (Future<String> future : futures) {
      // handle exceptions
      sb.append(future.get());
    }
  }
</code>```

Title: Returning value after several Runnable finish

Body:
Callable suits better for such task cause it returns result.

ExecutorService helps to incapsulate threads management.

  public static void main(String[] args) throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(3);
    List<Future<String>> futures = new ArrayList<>();
    futures.add(executorService.submit(new Process1()));
    futures.add(executorService.submit(new Process2()));
    futures.add(executorService.submit(new Process3()));

    StringBuilder sb = new StringBuilder();
    for (Future<String> future : futures) {
      // handle exceptions
      sb.append(future.get());
    }
  }


问:
.Swf skips to 3rd frame
I have a 6 frame .swf that is for some reason jumping to the 3rd frame upon loading.
This problem occurs in every browser except IE. I'm using AS2.
This is the actionscript for the first frame:

```<code>stop();

var SKUName = _root.SKUName;
var ProductImage = _root.ProductImage;
var ProductPrice = _root.ProductPrice;

var tbValue:String = String(iSize.text);

if(SKUName != undefined) {
    gotoAndPlay(6);
} else {
}
</code>```

The 6th frame just contains a stop(); action.

Any idea of why this is happening?

Thanks for any help.
Philip

答:
Try use </p>

```<code>gotoAndStop(6);
</code>```

<p>if u play a frame which include stop(); twice, flash will just compile stop(); or any other script for once </p>

ContentLicense: CC BY-SA 2.5

Title: .Swf skips to 3rd frame

Body:
I have a 6 frame .swf that is for some reason jumping to the 3rd frame upon loading.
This problem occurs in every browser except IE. I'm using AS2.
This is the actionscript for the first frame:

stop();

var SKUName = _root.SKUName;
var ProductImage = _root.ProductImage;
var ProductPrice = _root.ProductPrice;

var tbValue:String = String(iSize.text);

if(SKUName != undefined) {
    gotoAndPlay(6);
} else {
}

The 6th frame just contains a stop(); action.

Any idea of why this is happening?

Thanks for any help.
Philip

Body:
Try use

gotoAndStop(6);

if u play a frame which include stop(); twice, flash will just compile stop(); or any other script for once


问:
Could not find a part of the path while trying to retrieve a path in ASP.NET
I have the following code:

```<code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class view4 : System.Web.UI.Page
{
     protected void Page_Load(object sender, EventArgs e)
     {

        string strheadlinesid = string.Empty;

        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Convert.ToString(
                 Request.QueryString["folder"].ToString())))
            {
                strheadlinesid = Request.QueryString["folder"].ToString();
            }
       }

       Response.Write("<table style='width: 10px; height: 10px; margin-left:
           100px; margin-top: 10px'>");

        DirectoryInfo Dir = new DirectoryInfo(strheadlinesid);

        FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories);

        foreach (FileInfo FI in FileList)
        {

            Response.Write("<tr>");

            Response.Write("<td><a href= view3.aspx?file=" + FI.Name + "> " +
                FI.Name + "</a></td>");
            Response.Write("</tr>");
        }

        Response.Write("</table>");

    }

    private object DirectoryInfo(string p)
    {
        throw new NotImplementedException();
    }

}
</code>```

I'm getting the path of a directory by storing it in folder. However, when I use it to print the files from that directory, I'm getting the following error:

Could not find a part of the path
  'C:\Users\naresh\Documents\Visual\'.

The actual path C:\Users\naresh\Documents\Visual Studio 2010\WebSites\C_Manager\Account. But, the account part is changing dynamically.

答:
Add Your user to your application pool identity and it'll work
it is all about permissions </p>

Body:
I have the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class view4 : System.Web.UI.Page
{
     protected void Page_Load(object sender, EventArgs e)
     {

        string strheadlinesid = string.Empty;

        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Convert.ToString(
                 Request.QueryString["folder"].ToString())))
            {
                strheadlinesid = Request.QueryString["folder"].ToString();
            }
       }

       Response.Write("
");

        DirectoryInfo Dir = new DirectoryInfo(strheadlinesid);

        FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.AllDirectories);

        foreach (FileInfo FI in FileList)
        {

            Response.Write("
");

            Response.Write(" " +
                FI.Name + "	");
            Response.Write("
");
        }

        Response.Write("
");

    }

    private object DirectoryInfo(string p)
    {
        throw new NotImplementedException();
    }

}

I'm getting the path of a directory by storing it in folder. However, when I use it to print the files from that directory, I'm getting the following error:

Could not find a part of the path
  'C:\Users\naresh\Documents\Visual\'.

The actual path C:\Users\naresh\Documents\Visual Studio 2010\WebSites\C_Manager\Account. But, the account part is changing dynamically.


问:
Mock Projection Result Spring Data JPA
I am using spring data jpa in my spring boot project.

I am firing an JPQL query and using an projection to store the result of query.

My Projection :

public interface VeryBasicProjection {
    String getTitle();
    String getUrl();
}
```
<p>My service calling this projection :</p>
<pre class="lang-java prettyprint-override"><code>public List<VeryBasicDTO> getLatestData(int limit){

    // Pageable for Limit
    Pageable pageable = new PageRequest(0, limit);

    // Get Data from DB
    List<VeryBasicProjection> latestData = tableRepository.getLatestData("live", 2,pageable);
    List<VeryBasicDTO> responseDTO = new ArrayList<>();

    // Map Projection to DTO
    for(VeryBasicProjection veryBasicProjection : latestData){
        VeryBasicDTO veryBasicDTO = new VeryBasicDTO();
        veryBasicDTO.buildDTO(veryBasicProjection);
        responseDTO.add(veryBasicDTO);
    }

    return responseDTO;
}
</code>```

Now I want to test this service using Mockito(Unit Test Case)
I am mocking the call to repository
using when and thenReturn.

My question is how do I mock the result of repository? What should be in thenReturn? I mean how do I create instance of projection and setData to it?

答:
We have implemented the same stuff in below way

First mocked the two type of objects:

@Mock
private EntityManager em;

@Mock
private DemoProjectRepo demoProjectRepo;
```
<p>My <code>demoProjectRepo.findByAll</code> returns <code>List<DemoProjectDevices></code></p>
<pre class="lang-java prettyprint-override"><code>DemoProjectDevices device1 = new DemoProjectDevices();
device1.setAcctNbr("2365897412236589");
device1.setdeviceSeq(new BigDecimal(1));
device1.setCrteTms("2017-07-29 01:21:44.910807");

List<DemoProjectDevices> demoProjectDevices = new ArrayList<DemoProjectDevices>();
demoProjectDevices.add(device1);
</code>```

For the mock when and thenReturn:

Mockito.when(demoProjectRepo.findByAll("2365897412236589", em))
        .thenReturn(demoProjectDevices);
```

Title: Mock Projection Result Spring Data JPA

Body:
I am using spring data jpa in my spring boot project.

I am firing an JPQL query and using an projection to store the result of query.

My Projection :

public interface VeryBasicProjection {
    String getTitle();
    String getUrl();
}

My service calling this projection :

public List<VeryBasicDTO> getLatestData(int limit){

    // Pageable for Limit
    Pageable pageable = new PageRequest(0, limit);

    // Get Data from DB
    List<VeryBasicProjection> latestData = tableRepository.getLatestData("live", 2,pageable);
    List<VeryBasicDTO> responseDTO = new ArrayList<>();

    // Map Projection to DTO
    for(VeryBasicProjection veryBasicProjection : latestData){
        VeryBasicDTO veryBasicDTO = new VeryBasicDTO();
        veryBasicDTO.buildDTO(veryBasicProjection);
        responseDTO.add(veryBasicDTO);
    }

    return responseDTO;
}

Now I want to test this service using Mockito(Unit Test Case)
I am mocking the call to repository
using when and thenReturn.

My question is how do I mock the result of repository? What should be in thenReturn? I mean how do I create instance of projection and setData to it?

Body:
We have implemented the same stuff in below way

First mocked the two type of objects:

@Mock
private EntityManager em;

@Mock
private DemoProjectRepo demoProjectRepo;

My demoProjectRepo.findByAll returns List<DemoProjectDevices>

DemoProjectDevices device1 = new DemoProjectDevices();
device1.setAcctNbr("2365897412236589");
device1.setdeviceSeq(new BigDecimal(1));
device1.setCrteTms("2017-07-29 01:21:44.910807");

List<DemoProjectDevices> demoProjectDevices = new ArrayList<DemoProjectDevices>();
demoProjectDevices.add(device1);

For the mock when and thenReturn:

Mockito.when(demoProjectRepo.findByAll("2365897412236589", em))
        .thenReturn(demoProjectDevices);


问:
JSON deserialization for property starting with underscore ("_id") not working
Posting the question as I can't find solution specific to below problem.

One of the 3rd part REST service we are consuming return response similar to

{ "_id": "d55eb7c0",
   "applicationType": "TEST",
   "applicationId": "uxhJ1hcT1F8bpL3xAWvTjsymNcd1RArv",
   "description": "Some Description"}

tried to map "_id" attribute as, to follow proper java bean naming

```<code>@JsonProperty("_id")
private String id;
</code>```

which results in following error.

```<code>org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class ] and content type [application/json;charset=utf-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:109)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:917)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:901)
</code>```

if the field name is private String _id; json response is de-serialised without any issue. but I don't want to name field starting with '_' in our app.
We are using Jackson-2.7.3 & Spring RestTemplate to make REST calls.

Implementation for consuming the endpoint. Its a simple GET call using Spring RestTemplate.

HttpEntity<String> requestEntity = new HttpEntity<>(httpHeaders);
return restTemplate.exchange(authorizationProperties.getEndpoint() + "/roles", HttpMethod.GET, requestEntity,new ParameterizedTypeReference<Auth0Roles>() {});

Thanks in advance.

答:
I guess you need to apply the annotation on the accessor methods, not the field itself:</p>

```<code>   private String id;

   @JsonProperty("_id")
   public String getId() {
      return this.id;
   }
   public void setId(String i) {
      this.id = i;
   }
</code>```

Body:
Posting the question as I can't find solution specific to below problem.

One of the 3rd part REST service we are consuming return response similar to

{ "_id": "d55eb7c0",
   "applicationType": "TEST",
   "applicationId": "uxhJ1hcT1F8bpL3xAWvTjsymNcd1RArv",
   "description": "Some Description"}

tried to map "_id" attribute as, to follow proper java bean naming

@JsonProperty("_id")
private String id;

which results in following error.

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class ] and content type [application/json;charset=utf-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:109)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:917)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:901)

if the field name is private String _id; json response is de-serialised without any issue. but I don't want to name field starting with '_' in our app.
We are using Jackson-2.7.3 & Spring RestTemplate to make REST calls.

Implementation for consuming the endpoint. Its a simple GET call using Spring RestTemplate.

HttpEntity<String> requestEntity = new HttpEntity<>(httpHeaders);
return restTemplate.exchange(authorizationProperties.getEndpoint() + "/roles", HttpMethod.GET, requestEntity,new ParameterizedTypeReference<Auth0Roles>() {});

Thanks in advance.

Body:
I guess you need to apply the annotation on the accessor methods, not the field itself:

   private String id;

   @JsonProperty("_id")
   public String getId() {
      return this.id;
   }
   public void setId(String i) {
      this.id = i;
   }


问:
jQuery server side DOM manipulation
Does anyone know if it is possible to leverage the power of JQuery on the .Net serverside?

For example I have some HTML as a String in some code behind. Is there a way to execute JQuery on it?

I'm currently doing this...

Assume this is the String...

```<code><input id='AddressSettings_txtFirstName' name='txtFirstName'
value='#firstNameValue#' size='25' type='text'  class='val_required'/>
</code>```

My C#  does this

```<code> strHTML = strHTML.Replace("#firstNameValue#", customerInfo.FirstName);
</code>```

And this is how I bind my data to my HTML.

Now what I would like to do is instead of having to add the #firstNameValue# as a place holder and replacing it I would like to somehow execute a line of JQuery on the HTML string in my C# code.

```<code>strHTML = strHTML.ExecuteJQuery("$('#AddressSettings_txtFirstName').text('"
         + customerInfo.FirstName + "')");
</code>```

What are my options here?

答: This technology, ItsNat, is very similar to your desires, the bad news... is Java based.</p>

Title: jQuery server side DOM manipulation

Body:
Does anyone know if it is possible to leverage the power of JQuery on the .Net serverside?

For example I have some HTML as a String in some code behind. Is there a way to execute JQuery on it?

I'm currently doing this...

Assume this is the String...

<input id='AddressSettings_txtFirstName' name='txtFirstName'
value='#firstNameValue#' size='25' type='text'  class='val_required'/>

My C#  does this

 strHTML = strHTML.Replace("#firstNameValue#", customerInfo.FirstName);

And this is how I bind my data to my HTML.

Now what I would like to do is instead of having to add the #firstNameValue# as a place holder and replacing it I would like to somehow execute a line of JQuery on the HTML string in my C# code.

strHTML = strHTML.ExecuteJQuery("$('#AddressSettings_txtFirstName').text('"
         + customerInfo.FirstName + "')");

What are my options here?


问:
where_properties function and like keyword together in ahoy
Is it possible to use LIKE keyword and where_properties function together or something similar. Because i need to create query like this.</p>

```<code>Ahoy::Event.where(name: "$click").where_properties("'href' LIKE '%#{brochure.id}%'").count.size
</code>```

答:
please try this:

```<code> Ahoy::Event.where(name: "$click").where("properties ->> :key LIKE :value", key: "href", value: "%#{brochure.id}%").size
</code>```

fix the query now works as expected.

Body:
Is it possible to use LIKE keyword and where_properties function together or something similar. Because i need to create query like this.

Ahoy::Event.where(name: "$click").where_properties("'href' LIKE '%#{brochure.id}%'").count.size

Body:
please try this:

 Ahoy::Event.where(name: "$click").where("properties ->> :key LIKE :value", key: "href", value: "%#{brochure.id}%").size

fix the query now works as expected.


问:
Time Complexity of searching
there is a sorted array which is of very large size. every element is repeated more than once except one element. how much time will it take to find that element?

Options are:

1.O(1)

2.O(n)

3.O(logn)

4.O(nlogn)

答:
Must be O(n).

The fact that it's sorted doesn't help. Suppose you tried a binary method, jumping into the middle somewhere. You see that the value there has a neighbour that is the same. Now which half do you go to?

How would you write a program to find the value? You'd start at one end an check for an element whose neighbour is not the same. You'd have to walk the whole array until you found the value. So O(n)

Title: Time Complexity of searching


问:
Detaching Rows in Pivot Table - Laravel
I have a pivot table country_team with data in this form

country_team

```<code> country_id    team_id
     1            1
     1            2
</code>```

Country

```<code>   id    name
    1    Spain
</code>```

Team

```<code> id     name
  1     Barcelona
  2     Real Madrid
</code>```

In my table, i have it displayed in this form

Table

```<code> Country_id    Team
     1         Barcelona
     1         Real Madrid
</code>```

Now, i want to detach real Madrid from the row but how can get the id of real madrid or get the name Real Madrid to detach it. I cannot delete using country_id since it will delete all teams belonging to that particular country .

Controller

```<code>public function index()
{
    $countries = Country::where('id',Auth::user()->id)->get();

    return view('admin.order.index',compact('orders'));
}

public function deleteTeam()
{
    $get_country_id = Country::findOrFail($id);
    $get_country_id->teams()->detach();
}
</code>```

HTML

```<code><tbody>
    @foreach($countries as $country)
        @foreach($country->teams as $team)
        <tr>
            <td>{{$country->id }}</td>
            <td>{{ $team->name}}</td>
        </tr>
        @endforeach
    @endforeach
</tbody>
</code>```

答:
I personally use somethink like this to detach ids.

Controller

```<code>public function deleteTeam($country_id, $team_id)
{
    $country = Country::findOrFail($country_id);
    $country->teams()->detach($team_id);
}
</code>```

HTML

```<code><tbody>
    @foreach($countries as $country)
        @foreach($country->teams as $team)
            <tr>
                <td>{{ $country->id }}</td>
                <td>{{ $team->name }}</td>
                <td>
                    <form action="{{ route('admin.team.delete', ['country_id' => $country->id, 'team_id' => $tem->id]) }}" method="post">
                        <button type="submit" role="button">Delete</button>
                        {{ csrf_field() }}
                    </form>
                </td>
            </tr>
        @endforeach
    @endforeach
</tbody>
</code>```

And in your web.php you have to add the route in the correct group or something.

```<code>Route::post('delete/{country_id}/{team_id}', [
    'uses' => 'ControllerName@deleteTeam',
    'as' => 'admin.team.delete'
]);
</code>```

Title: Detaching Rows in Pivot Table - Laravel

Body:
I have a pivot table country_team with data in this form

country_team

 country_id    team_id
     1            1
     1            2

Country

   id    name
    1    Spain

Team

 id     name
  1     Barcelona
  2     Real Madrid

In my table, i have it displayed in this form

Table

 Country_id    Team
     1         Barcelona
     1         Real Madrid

Now, i want to detach real Madrid from the row but how can get the id of real madrid or get the name Real Madrid to detach it. I cannot delete using country_id since it will delete all teams belonging to that particular country .

Controller

public function index()
{
    $countries = Country::where('id',Auth::user()->id)->get();

    return view('admin.order.index',compact('orders'));
}

public function deleteTeam()
{
    $get_country_id = Country::findOrFail($id);
    $get_country_id->teams()->detach();
}

HTML

    @foreach($countries as $country)
        @foreach($country->teams as $team)

            {{$country->id }}
            {{ $team->name}}

        @endforeach
    @endforeach

Body:
I personally use somethink like this to detach ids.

Controller

public function deleteTeam($country_id, $team_id)
{
    $country = Country::findOrFail($country_id);
    $country->teams()->detach($team_id);
}

HTML

<tbody>
    @foreach($countries as $country)
        @foreach($country->teams as $team)
            <tr>
                <td>{{ $country->id }}</td>
                <td>{{ $team->name }}</td>
                <td>
                    <form action="{{ route('admin.team.delete', ['country_id' => $country->id, 'team_id' => $tem->id]) }}" method="post">
                        <button type="submit" role="button">Delete</button>
                        {{ csrf_field() }}
                    </form>
                </td>
            </tr>
        @endforeach
    @endforeach
</tbody>

And in your web.php you have to add the route in the correct group or something.

Route::post('delete/{country_id}/{team_id}', [
    'uses' => 'ControllerName@deleteTeam',
    'as' => 'admin.team.delete'
]);


问:
what did is difference between java and kotlin about visibility modifiers?

This is what the official document says. But when I do something like this:

```<code>var human : Human? = null
</code>```

and decompile it into java code, I find it actually was

```<code>@Nullable
private Human human;
</code>```

and it's no use to write this

```<code>public var human : Human? = null
</code>```

but when I write this:

```<code>lateinit var human : Human
</code>```

it become public this time

```<code>@NotNull
public Human human;
</code>```

it was a big problem when I use Dagger2

in Dagger2  the property be injected must be public, but if i write var human : Human? = null
it will fail to build.

答:
"The default visibility is public" just means that if you don't specify visibility, it's the same as specifying public.

Property corresponds to getter and setter methods (getHuman() and setHuman()) in decompiled code, not really to the field human.

The documentation talking about visibility from Kotlin, which isn't the same as visibility according to JVM (and can't be, because JVM doesn't have internal visibility). JVM visibility is just implementation details (so far as this documentation is concerned).

From 2 and 3 together, the cited documentation says absolutely nothing about even existence of the backing field, never mind its visibility, which is what Dagger cares about. Instead, it's documented in https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html:

In the first section, "Properties":

A private field, with the same name as the property name (only for properties with backing fields).

In "Instance fields":

If you need to expose a Kotlin property as a field in Java, you need to annotate it with the @JvmField annotation. The field will have the same visibility as the underlying property.

and

Late-Initialized properties are also exposed as fields. The visibility of the field will be the same as the visibility of lateinit property setter.

Body:
This is what the official document says. But when I do something like this:

var human : Human? = null

and decompile it into java code, I find it actually was

@Nullable
private Human human;

and it's no use to write this

public var human : Human? = null

but when I write this:

lateinit var human : Human

it become public this time

@NotNull
public Human human;

it was a big problem when I use Dagger2

in Dagger2  the property be injected must be public, but if i write var human : Human? = null
it will fail to build.


问:
Finding Hudson Log Files
Does anyone know how to search a Hudson server for the incremental log files that are generated from running reoccurring JUnit tests?  The Hudson dash board will show the last twenty tests, but we are looking for a log file that holds a complete history of Hudson builds and the status of each build.</p>

答:
The file structure on the Hudson master will look like this:

```<code>$HUDSON_HOME
     |
     ---- jobs
           |
           ---- [job name]
                     |
                     ---- builds
</code>```

Your files should be in the  directory underneath that.  However, if you're only keeping the last 20 builds, you're unlikely to find any files from previous builds.

If you're building on a slave, you may also find the files you're looking for under workspace/[job name] in the slave home directory.

Title: Finding Hudson Log Files

Body:
The file structure on the Hudson master will look like this:

$HUDSON_HOME
     |
     ---- jobs
           |
           ---- [job name]
                     |
                     ---- builds

Your files should be in the  directory underneath that.  However, if you're only keeping the last 20 builds, you're unlikely to find any files from previous builds.

If you're building on a slave, you may also find the files you're looking for under workspace/[job name] in the slave home directory.


问:
How to change color of space in vim
How can i change the space color in vim.
Right now, the space is gray and the color of . is somewhat grayish, so it is hard to identify what is . and space.

答:
Vim usually does not highlight common text with a background color.

If you have problems distinguishing punctuation, change / adapt your colorscheme and/or font.

There is :set list, which emphasizes whitespace, tabs, etc. Temporarily enabling this helps with whitespace issues, but I would not recommend to keep this on all the time. It's not a proper fix of your problem.

To solve your highlighting problem:
You need to find out which syntax group causes the highlighting. :syn list shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin. (I maintain an extended fork.) When you have the name of the offending syntax group, you can investigate where it comes from; (the last lines of) :scriptnames may help.

Title: How to change color of space in vim


问:
SQL Query to get data from 4 tables - to CAST and SUM
I  got stuck with a old query

This query returns Closing Stock value of all items in my Inventory

Original Scenario TABLES:

T1: DETAIL_PURCHASE

T2: PURCHASE_REPORT

T3: DETAIL_SALE

T4: SALE_REPORT

DETAIL_PURCHASE HAS COLUMNS ITEMID,QTYSOLD,BILLNO

PURCHASE_REPORT HAS COLUMNS BILLNO,BILLDATE

DETAIL_SALE HAS COLUMNS ITEMID,QTYSOLD,BILLNO

SALE_REPORT HAS COLUMNS BILLNO,BILLDATE

The Query I am looking for is to sum all QTY in DETAIL_PURCHASE of each Individual Items DIFFERENCE with sum all QTY in DETAIL_SALE of each Individual Items With a Date filter query using dates in SALE_REPORT & PURCHASE_REPORT.

```<code>SELECT
  dp.ITEMNAME,
  SUM(CAST(dp.QUANTITY AS numeric(18, 2))) - SUM(CAST(ds.QTY AS numeric(18, 2))) AS [ClosingStock]
FROM detailpurchases AS dp
JOIN purchasereport AS pr
  ON dp.BARCODE = pr.voucherno
JOIN detailsale AS ds
  ON ds.ITEMN = dp.ITEMN
JOIN salesreport AS sr
  ON ds.BARCODE = sr.voucherno
WHERE ds.T = 'R'
AND pr.voucherdate BETWEEN '" & DATE1.Text & "' AND '" & DATE2.Text & "'
AND sr.voucherdate BETWEEN '" & DATE1.Text & "' AND '" & DATE2.Text & "'
GROUP BY dp.ITEMNAME;
</code>```

The above query I worked out but it still returns wrong value. More likely Far greater value than needed.

Example Table:

DETAILPURCHASE:

```
ID  SN  ITEMN   BARCODE ITEMNAME    HSN T   CP  BID BATCHN  QUANTITY
282 1   106 0009    5STAR 10.1G 5/- 18063100    0   230.11011           90.0
330 2   106 0014    5STAR 10.1G 5/- 18063100    0   3.979876543         4860.0
332 2   106 0015    5STAR 10.1G 5/- 18063100    0   3.8397736           4860.0
385 3   106 0021    5STAR 10.1G 5/- 18063100    0   210.73944           144.0
446 1   106 0025    5STAR 10.1G 5/- 18063100    0   230.1099            108.0
545 6   106 0034    5STAR 10.1G 5/- 18063100    0   225.34766   1       90.0
598 1   106 0039    5STAR 10.1G 5/- 18063100    0   230.109944          180.0
671 1   106 0044    5STAR 10.1G 5/- 18063100    1   222.80137   54  832 270.0
814 1   106 0070    5STAR 10.1G 5/- 18063100    1   222.80  369 906 108.0
```

DETAILSALE:

```
ID  SN  ITEMN   BARCODE ITEMNAME    HSN T   CP  BIID    BATCHN  QTY
59  12  106 0214    5STAR 10.1G 5/- 18063100    R   222.8   54  832 2.0
94  7   106 0218    5STAR 10.1G 5/- 18063100    R   222.8   54  832 18.0
111 8   106 0220    5STAR 10.1G 5/- 18063100    R   222.8   54  832 5.0
163 1   106 0225    5STAR 10.1G 5/- 18063100    R   222.8   54  832 1.0
189 17  106 0227    5STAR 10.1G 5/- 18063100    R   222.8   54  832 1.0
257 13  106 0231    5STAR 10.1G 5/- 18063100    R   222.8   54  832 5.0
303 12  106 0232    5STAR 10.1G 5/- 18063100    R   222.8   54  832 4.0
359 22  106 0235    5STAR 10.1G 5/- 18063100    R   222.8   54  832 5.0
379 14  106 0236    5STAR 10.1G 5/- 18063100    R   222.8   54  832 2.0
497 1   106 0293    5STAR 10.1G 5/- 18063100    R   222.8   369 906 2.0
516 1   106 0291    5STAR 10.1G 5/- 18063100    R   222.8   369 906 18.0
```

PURCHASEREPORT:

```
ID  VOUCHERTYPE VOUCHERDATE        VOUCHERNO     PARTY
15  Purchase    2017-07-21 00:00:00.000 0006    VINAYAKA CORPORATION
16  Purchase    2017-07-14 00:00:00.000 0002    SAI MAHESWARA AGENCIES
17  Purchase    2017-07-11 00:00:00.000 0001    SATHYA TRADING CO
18  Purchase    2017-07-15 00:00:00.000 0003    CHELLU ENTERPRISES
19  Purchase    2017-07-15 00:00:00.000 0004    RITHESH TRADERS
20  Purchase    2017-07-16 00:00:00.000 0005    CHELLU ENTERPRISES
21  Purchase    2017-07-21 00:00:00.000 0006    SRI PRAMEELA MARKETINGS
22  Purchase    2017-07-22 00:00:00.000 0007    RITHESH TRADERS
24  Purchase    2017-07-24 00:00:00.000 0008    SATHYA TRADING CO
25  Purchase    2017-07-29 00:00:00.000 0009    CHELLU ENTERPRISES
26  Purchase    2017-07-31 00:00:00.000 0010    CHELLU ENTERPRISES
27  Purchase    2017-07-31 00:00:00.000 0011    RITHESH TRADERS
30  Purchase    2017-07-31 00:00:00.000 0012    SAI MAHESWARA AGENCIES
31  Purchase    2017-08-09 00:00:00.000 0013    CHELLU ENTERPRISES
32  Purchase    2017-08-09 00:00:00.000 0014    CHELLU ENTERPRISES
33  Purchase    2017-08-09 00:00:00.000 0015    CHELLU ENTERPRISES
34  Purchase    2017-08-09 00:00:00.000 0016    CHELLU ENTERPRISES
35  Purchase    2017-08-08 00:00:00.000 0017    SATHYA TRADING CO
36  Purchase    2017-08-12 00:00:00.000 0018    SRI PRAMEELA MARKETINGS
37  Purchase    2017-08-14 00:00:00.000 0019    RITHESH TRADERS
38  Purchase    2017-08-15 00:00:00.000 0020    CHELLU ENTERPRISES
39  Purchase    2017-08-17 00:00:00.000 0021    CHELLU ENTERPRISES
40  Purchase    2017-08-17 00:00:00.000 0022    SATHYA TRADING CO
41  Purchase    2017-08-21 00:00:00.000 0023    CHELLU ENTERPRISES
42  Purchase    2017-08-28 00:00:00.000 0024    SATHYA TRADING CO
43  Purchase    2017-08-29 00:00:00.000 0025    CHELLU ENTERPRISES
45  Purchase    2017-08-31 00:00:00.000 0027    SAI MAHESWARA AGENCIES
46  Purchase    2017-08-31 00:00:00.000 0028    SRI VINAYAKA AGENCIES
47  Purchase    2017-08-31 00:00:00.000 0026    RITHESH TRADERS
48  Purchase    2017-09-11 00:00:00.000 0027    SATHYA TRADING CO
49  Purchase    2017-09-14 00:00:00.000 0028    RITHESH TRADERS
50  Purchase    2017-09-15 00:00:00.000 0029    RITHESH TRADERS
51  Purchase    2017-09-06 00:00:00.000 0030    SRI PRAMEELA MARKETINGS
52  Purchase    2017-09-08 00:00:00.000 0031    MOKSHITHA ENTERPRISES
53  Purchase    2017-09-09 00:00:00.000 0032    SAI MAHESWARA AGENCIES
54  Purchase    2017-09-09 00:00:00.000 0033    SRI VINAYAKA AGENCIES
55  Purchase    2017-09-15 00:00:00.000 0034    CHELLU ENTERPRISES
56  Purchase    2017-09-15 00:00:00.000 0035    CHELLU ENTERPRISES
58  Purchase    2017-09-29 00:00:00.000 0036    SATHYA TRADING CO
59  Purchase    2017-09-22 00:00:00.000 0037    CHELLU ENTERPRISES
60  Purchase    2017-09-22 00:00:00.000 0038    RITHESH TRADERS
61  Purchase    2017-09-28 00:00:00.000 0039    CHELLU ENTERPRISES
62  Purchase    2017-09-28 00:00:00.000 0040    RITHESH TRADERS
63  Purchase    2017-09-28 00:00:00.000 0041    RITHESH TRADERS
64  Purchase    2017-09-29 00:00:00.000 0042    SATHYA TRADING CO
65  Purchase    2017-10-09 00:00:00.000 0043    SRI VINAYAKA AGENCIES
66  Purchase    2017-10-10 00:00:00.000 0044    CHELLU ENTERPRISES
67  Purchase    2017-10-11 00:00:00.000 0045    MOKSHITHA ENTERPRISES
68  Purchase    2017-10-14 00:00:00.000 0046    SATHYA TRADING CO
69  Purchase    2017-10-14 00:00:00.000 0047    RITHESH TRADERS
72  Purchase    2017-10-23 00:00:00.000 0048    CHELLU ENTERPRISES
73  Purchase    2017-10-23 00:00:00.000 0049    CHELLU ENTERPRISES
74  Purchase    2017-10-23 00:00:00.000 0050    CHELLU ENTERPRISES
```

SALEREPORT

```
ID  VOUCHERTYPE VOUCHERDATE     VOUCHERNO   PARTY
4   Sale    2017-10-02 00:00:00.000 0212    SAI MEDICALS
6   HOLD    2017-10-03 00:00:00.000 0214    VAMSI KRISHNA SUPER BAZAAR
7   Sale    2017-10-03 00:00:00.000 0215    ADS SUPER BAZAAR
9   Sale    2017-10-04 00:00:00.000 0217    SRI BALAJI GENARAL STORES
10  Sale    2017-10-04 00:00:00.000 0218    NEW SS BEKERY
11  Sale    2017-10-04 00:00:00.000 0219    KANYAKA PARAMESWARI STORES
12  Sale    2017-10-05 00:00:00.000 0220    VASAVI STORES
13  Sale    2017-10-05 00:00:00.000 0221    NAVEEN
14  Sale    2017-10-05 00:00:00.000 0222    SRI HARI MEDICALS
15  Sale    2017-10-05 00:00:00.000 0223    JAKKAM SHOPPING CORNER
16  Sale    2017-10-05 00:00:00.000 0224    C NARESH
19  Sale    2017-10-05 00:00:00.000 0225    K R C SONS STORES
20  Sale    2017-10-05 00:00:00.000 0226    SREEDHAR TRADERS
21  Sale    2017-10-06 00:00:00.000 0227    B V SHANMUGAM
22  Sale    2017-10-06 00:00:00.000 0228    NEW VENKATESWARA SWEETS
23  Sale    2017-10-07 00:00:00.000 0229    VIJAYA MEDICAL&GENARAL STORES
24  Sale    2017-10-07 00:00:00.000 0230    LANCHIPALLI MALLAINAIDU
25  Sale    2017-10-07 00:00:00.000 0231    NEW VENKATADRI SWEETS&COOL DRINKS
27  Sale    2017-10-08 00:00:00.000 0232    LANCHIPALLI MALLAINAIDU
28  Sale    2017-10-08 00:00:00.000 0233    J.BALASUBRAMANYAM
29  Sale    2017-10-08 00:00:00.000 0234    RAJESWARI GENARAL STORES
30  Sale    2017-10-08 00:00:00.000 0235    M/S SRI SAI PROVISINAL&DIGNITY STORES
31  Sale    2017-10-08 00:00:00.000 0236    B V SUBRAMANYAM
32  Sale    2017-10-09 00:00:00.000 0237    K. MADHUSUDAHANA,KUPPAM
33  Sale    2017-10-09 00:00:00.000 0238    JK SUPER BAZAAR
34  Sale    2017-10-09 00:00:00.000 0239    NEW LAKSHMI PROVISION STORES
35  Sale    2017-10-03 00:00:00.000 0213    RAJU
36  Sale    2017-10-04 00:00:00.000 0216    BALAJI
42  Sale    2017-11-03 00:00:00.000 0293    LAKSHMI SUPER BAZAAR
43  Sale    2017-11-03 00:00:00.000 0292    SREEDHAR TRADERS
44  Sale    2017-11-02 00:00:00.000 0291    M/S R S PANDURANGA GENARAL MARCHANT
45  Sale    2017-11-02 00:00:00.000 0290    SREEDHAR TRADERS
47  Sale    2017-11-04 00:00:00.000 0294    SRI MURUGAN AGENCY&GENARAL STORES
49  Sale    2017-11-04 00:00:00.000 0295    SRI HARI MEDICALS
50  Sale    2017-11-05 00:00:00.000 0296    M/S SRI SAI PROVISINAL&DIGNITY STORES
52  Sale    2017-11-05 00:00:00.000 0297    LAKSHMI SUPER BAZAAR
53  Sale    2017-11-05 00:00:00.000 0298    VAMSI KRISHNA SUPER BAZAAR
54  Sale    2017-10-02 00:00:00.000 0210    KA SUPER BAZAAR
55  Sale    2017-10-02 00:00:00.000 0211    SRI MURUGAN AGENCY&GENARAL STORES
```

I tried running the query:

```<code>    select
        dp.ITEMNAME,dp.BARCODE,
        (CAST(dp.QUANTITY AS numeric(18,2))) ,
        ds.BARCODE,
        (CAST(ds.QTY AS numeric(18,2))) as [ClosingStock]
    from [iBillDB].[dbo].detailpurchases as dp
    join [iBillDB].[dbo].purchasereport as pr on dp.BARCODE=pr.voucherno
    join [iBillDB].[dbo].detailsale as ds on ds.ITEMN=dp.ITEMN
    join [iBillDB].[dbo].salesreport as sr on ds.BARCODE=sr.voucherno
    where ds.T='R'
    and dp.ITEMN='106'
    group by dp.ITEMNAME,dp.QUANTITY,ds.QTY,dp.BARCODE,ds.BARCODE;
</code>```

I get result as follows:

```
ITEMNAME        BARCODE cs      BARCODE ClosingStock
5STAR 10.1G 5/- 0025    108.00  0225    1.00
5STAR 10.1G 5/- 0025    108.00  0227    1.00
5STAR 10.1G 5/- 0070    108.00  0225    1.00
5STAR 10.1G 5/- 0070    108.00  0227    1.00
5STAR 10.1G 5/- 0025    108.00  0218    18.00
5STAR 10.1G 5/- 0025    108.00  0291    18.00
5STAR 10.1G 5/- 0070    108.00  0218    18.00
5STAR 10.1G 5/- 0070    108.00  0291    18.00
5STAR 10.1G 5/- 0025    108.00  0214    2.00
5STAR 10.1G 5/- 0025    108.00  0236    2.00
5STAR 10.1G 5/- 0025    108.00  0293    2.00
5STAR 10.1G 5/- 0070    108.00  0214    2.00
5STAR 10.1G 5/- 0070    108.00  0236    2.00
5STAR 10.1G 5/- 0070    108.00  0293    2.00
5STAR 10.1G 5/- 0025    108.00  0232    4.00
5STAR 10.1G 5/- 0070    108.00  0232    4.00
5STAR 10.1G 5/- 0025    108.00  0220    5.00
5STAR 10.1G 5/- 0025    108.00  0231    5.00
5STAR 10.1G 5/- 0025    108.00  0235    5.00
5STAR 10.1G 5/- 0070    108.00  0220    5.00
5STAR 10.1G 5/- 0070    108.00  0231    5.00
5STAR 10.1G 5/- 0070    108.00  0235    5.00
5STAR 10.1G 5/- 0021    144.00  0225    1.00
5STAR 10.1G 5/- 0021    144.00  0227    1.00
5STAR 10.1G 5/- 0021    144.00  0218    18.00
5STAR 10.1G 5/- 0021    144.00  0291    18.00
5STAR 10.1G 5/- 0021    144.00  0214    2.00
5STAR 10.1G 5/- 0021    144.00  0236    2.00
5STAR 10.1G 5/- 0021    144.00  0293    2.00
5STAR 10.1G 5/- 0021    144.00  0232    4.00
5STAR 10.1G 5/- 0021    144.00  0220    5.00
5STAR 10.1G 5/- 0021    144.00  0231    5.00
5STAR 10.1G 5/- 0021    144.00  0235    5.00
5STAR 10.1G 5/- 0039    180.00  0225    1.00
5STAR 10.1G 5/- 0039    180.00  0227    1.00
5STAR 10.1G 5/- 0039    180.00  0218    18.00
5STAR 10.1G 5/- 0039    180.00  0291    18.00
5STAR 10.1G 5/- 0039    180.00  0214    2.00
5STAR 10.1G 5/- 0039    180.00  0236    2.00
5STAR 10.1G 5/- 0039    180.00  0293    2.00
5STAR 10.1G 5/- 0039    180.00  0232    4.00
5STAR 10.1G 5/- 0039    180.00  0220    5.00
5STAR 10.1G 5/- 0039    180.00  0231    5.00
5STAR 10.1G 5/- 0039    180.00  0235    5.00
5STAR 10.1G 5/- 0044    270.00  0225    1.00
5STAR 10.1G 5/- 0044    270.00  0227    1.00
5STAR 10.1G 5/- 0044    270.00  0218    18.00
5STAR 10.1G 5/- 0044    270.00  0291    18.00
5STAR 10.1G 5/- 0044    270.00  0214    2.00
5STAR 10.1G 5/- 0044    270.00  0236    2.00
5STAR 10.1G 5/- 0044    270.00  0293    2.00
5STAR 10.1G 5/- 0044    270.00  0232    4.00
5STAR 10.1G 5/- 0044    270.00  0220    5.00
5STAR 10.1G 5/- 0044    270.00  0231    5.00
5STAR 10.1G 5/- 0044    270.00  0235    5.00
5STAR 10.1G 5/- 0014    4860.00 0225    1.00
5STAR 10.1G 5/- 0014    4860.00 0227    1.00
5STAR 10.1G 5/- 0015    4860.00 0225    1.00
5STAR 10.1G 5/- 0015    4860.00 0227    1.00
5STAR 10.1G 5/- 0014    4860.00 0218    18.00
5STAR 10.1G 5/- 0014    4860.00 0291    18.00
5STAR 10.1G 5/- 0015    4860.00 0218    18.00
5STAR 10.1G 5/- 0015    4860.00 0291    18.00
5STAR 10.1G 5/- 0014    4860.00 0214    2.00
5STAR 10.1G 5/- 0014    4860.00 0236    2.00
5STAR 10.1G 5/- 0014    4860.00 0293    2.00
5STAR 10.1G 5/- 0015    4860.00 0214    2.00
5STAR 10.1G 5/- 0015    4860.00 0236    2.00
5STAR 10.1G 5/- 0015    4860.00 0293    2.00
5STAR 10.1G 5/- 0014    4860.00 0232    4.00
5STAR 10.1G 5/- 0015    4860.00 0232    4.00
5STAR 10.1G 5/- 0014    4860.00 0220    5.00
5STAR 10.1G 5/- 0014    4860.00 0231    5.00
5STAR 10.1G 5/- 0014    4860.00 0235    5.00
5STAR 10.1G 5/- 0015    4860.00 0220    5.00
5STAR 10.1G 5/- 0015    4860.00 0231    5.00
5STAR 10.1G 5/- 0015    4860.00 0235    5.00
5STAR 10.1G 5/- 0009    90.00   0225    1.00
5STAR 10.1G 5/- 0009    90.00   0227    1.00
5STAR 10.1G 5/- 0034    90.00   0225    1.00
5STAR 10.1G 5/- 0034    90.00   0227    1.00
5STAR 10.1G 5/- 0009    90.00   0218    18.00
5STAR 10.1G 5/- 0009    90.00   0291    18.00
5STAR 10.1G 5/- 0034    90.00   0218    18.00
5STAR 10.1G 5/- 0034    90.00   0291    18.00
5STAR 10.1G 5/- 0009    90.00   0214    2.00
5STAR 10.1G 5/- 0009    90.00   0236    2.00
5STAR 10.1G 5/- 0009    90.00   0293    2.00
5STAR 10.1G 5/- 0034    90.00   0214    2.00
5STAR 10.1G 5/- 0034    90.00   0236    2.00
5STAR 10.1G 5/- 0034    90.00   0293    2.00
5STAR 10.1G 5/- 0009    90.00   0232    4.00
5STAR 10.1G 5/- 0034    90.00   0232    4.00
5STAR 10.1G 5/- 0009    90.00   0220    5.00
5STAR 10.1G 5/- 0009    90.00   0231    5.00
5STAR 10.1G 5/- 0009    90.00   0235    5.00
5STAR 10.1G 5/- 0034    90.00   0220    5.00
5STAR 10.1G 5/- 0034    90.00   0231    5.00
5STAR 10.1G 5/- 0034    90.00   0235    5.00
```

in the above result The 2ndcolumn is BillNo of Purchases and 3rd column is QTY purchased
4th column is BillNo of Sales and 5th Column is QTY sold

My assessment is here while Summing up the values are repeated twice.

EXPECTED RESULT is:
10647

Actual Result is:
117243

答:
You are multplying values by joining unrelated records. (You are combining every purchase detail records with every sales detail record in an item.) You want to join the purchase sum with the sales sum, so aggregate first, join then:</p>

```<code>select
  coaleasce(p.itemname, s.itemname) as itemname,
  coaleasce(p.sum_qty, 0) - coaleasce(s.sum_qty, 0) as closing_stock
from
(
  select
    itemname,
    sum(cast(quantity as numeric(18, 2))) as sum_qty
  from detailpurchases
  where barcode in (select voucherno from purchasereport where voucherdate between ? and ?)
  group by itemname
) p
full outer join
(
  select
    itemname,
    sum(cast(qty as numeric(18, 2))) as sum_qty
  from detailsale
  where barcode in (select voucherno from salesreport where voucherdate between ? and ?)
  and T = 'R'
  group by itemname
) s on s.itemname = p.itemname;
</code>```

Body:
I  got stuck with a old query

This query returns Closing Stock value of all items in my Inventory

Original Scenario TABLES:

T1: DETAIL_PURCHASE

T2: PURCHASE_REPORT

T3: DETAIL_SALE

T4: SALE_REPORT

DETAIL_PURCHASE HAS COLUMNS ITEMID,QTYSOLD,BILLNO

PURCHASE_REPORT HAS COLUMNS BILLNO,BILLDATE

DETAIL_SALE HAS COLUMNS ITEMID,QTYSOLD,BILLNO

SALE_REPORT HAS COLUMNS BILLNO,BILLDATE

The Query I am looking for is to sum all QTY in DETAIL_PURCHASE of each Individual Items DIFFERENCE with sum all QTY in DETAIL_SALE of each Individual Items With a Date filter query using dates in SALE_REPORT & PURCHASE_REPORT.

SELECT
  dp.ITEMNAME,
  SUM(CAST(dp.QUANTITY AS numeric(18, 2))) - SUM(CAST(ds.QTY AS numeric(18, 2))) AS [ClosingStock]
FROM detailpurchases AS dp
JOIN purchasereport AS pr
  ON dp.BARCODE = pr.voucherno
JOIN detailsale AS ds
  ON ds.ITEMN = dp.ITEMN
JOIN salesreport AS sr
  ON ds.BARCODE = sr.voucherno
WHERE ds.T = 'R'
AND pr.voucherdate BETWEEN '" & DATE1.Text & "' AND '" & DATE2.Text & "'
AND sr.voucherdate BETWEEN '" & DATE1.Text & "' AND '" & DATE2.Text & "'
GROUP BY dp.ITEMNAME;

The above query I worked out but it still returns wrong value. More likely Far greater value than needed.

Example Table:

DETAILPURCHASE:

ID  SN  ITEMN   BARCODE ITEMNAME    HSN T   CP  BID BATCHN  QUANTITY
282 1   106 0009    5STAR 10.1G 5/- 18063100    0   230.11011           90.0
330 2   106 0014    5STAR 10.1G 5/- 18063100    0   3.979876543         4860.0
332 2   106 0015    5STAR 10.1G 5/- 18063100    0   3.8397736           4860.0
385 3   106 0021    5STAR 10.1G 5/- 18063100    0   210.73944           144.0
446 1   106 0025    5STAR 10.1G 5/- 18063100    0   230.1099            108.0
545 6   106 0034    5STAR 10.1G 5/- 18063100    0   225.34766   1       90.0
598 1   106 0039    5STAR 10.1G 5/- 18063100    0   230.109944          180.0
671 1   106 0044    5STAR 10.1G 5/- 18063100    1   222.80137   54  832 270.0
814 1   106 0070    5STAR 10.1G 5/- 18063100    1   222.80  369 906 108.0

DETAILSALE:

ID  SN  ITEMN   BARCODE ITEMNAME    HSN T   CP  BIID    BATCHN  QTY
59  12  106 0214    5STAR 10.1G 5/- 18063100    R   222.8   54  832 2.0
94  7   106 0218    5STAR 10.1G 5/- 18063100    R   222.8   54  832 18.0
111 8   106 0220    5STAR 10.1G 5/- 18063100    R   222.8   54  832 5.0
163 1   106 0225    5STAR 10.1G 5/- 18063100    R   222.8   54  832 1.0
189 17  106 0227    5STAR 10.1G 5/- 18063100    R   222.8   54  832 1.0
257 13  106 0231    5STAR 10.1G 5/- 18063100    R   222.8   54  832 5.0
303 12  106 0232    5STAR 10.1G 5/- 18063100    R   222.8   54  832 4.0
359 22  106 0235    5STAR 10.1G 5/- 18063100    R   222.8   54  832 5.0
379 14  106 0236    5STAR 10.1G 5/- 18063100    R   222.8   54  832 2.0
497 1   106 0293    5STAR 10.1G 5/- 18063100    R   222.8   369 906 2.0
516 1   106 0291    5STAR 10.1G 5/- 18063100    R   222.8   369 906 18.0

PURCHASEREPORT:

ID  VOUCHERTYPE VOUCHERDATE        VOUCHERNO     PARTY
15  Purchase    2017-07-21 00:00:00.000 0006    VINAYAKA CORPORATION
16  Purchase    2017-07-14 00:00:00.000 0002    SAI MAHESWARA AGENCIES
17  Purchase    2017-07-11 00:00:00.000 0001    SATHYA TRADING CO
18  Purchase    2017-07-15 00:00:00.000 0003    CHELLU ENTERPRISES
19  Purchase    2017-07-15 00:00:00.000 0004    RITHESH TRADERS
20  Purchase    2017-07-16 00:00:00.000 0005    CHELLU ENTERPRISES
21  Purchase    2017-07-21 00:00:00.000 0006    SRI PRAMEELA MARKETINGS
22  Purchase    2017-07-22 00:00:00.000 0007    RITHESH TRADERS
24  Purchase    2017-07-24 00:00:00.000 0008    SATHYA TRADING CO
25  Purchase    2017-07-29 00:00:00.000 0009    CHELLU ENTERPRISES
26  Purchase    2017-07-31 00:00:00.000 0010    CHELLU ENTERPRISES
27  Purchase    2017-07-31 00:00:00.000 0011    RITHESH TRADERS
30  Purchase    2017-07-31 00:00:00.000 0012    SAI MAHESWARA AGENCIES
31  Purchase    2017-08-09 00:00:00.000 0013    CHELLU ENTERPRISES
32  Purchase    2017-08-09 00:00:00.000 0014    CHELLU ENTERPRISES
33  Purchase    2017-08-09 00:00:00.000 0015    CHELLU ENTERPRISES
34  Purchase    2017-08-09 00:00:00.000 0016    CHELLU ENTERPRISES
35  Purchase    2017-08-08 00:00:00.000 0017    SATHYA TRADING CO
36  Purchase    2017-08-12 00:00:00.000 0018    SRI PRAMEELA MARKETINGS
37  Purchase    2017-08-14 00:00:00.000 0019    RITHESH TRADERS
38  Purchase    2017-08-15 00:00:00.000 0020    CHELLU ENTERPRISES
39  Purchase    2017-08-17 00:00:00.000 0021    CHELLU ENTERPRISES
40  Purchase    2017-08-17 00:00:00.000 0022    SATHYA TRADING CO
41  Purchase    2017-08-21 00:00:00.000 0023    CHELLU ENTERPRISES
42  Purchase    2017-08-28 00:00:00.000 0024    SATHYA TRADING CO
43  Purchase    2017-08-29 00:00:00.000 0025    CHELLU ENTERPRISES
45  Purchase    2017-08-31 00:00:00.000 0027    SAI MAHESWARA AGENCIES
46  Purchase    2017-08-31 00:00:00.000 0028    SRI VINAYAKA AGENCIES
47  Purchase    2017-08-31 00:00:00.000 0026    RITHESH TRADERS
48  Purchase    2017-09-11 00:00:00.000 0027    SATHYA TRADING CO
49  Purchase    2017-09-14 00:00:00.000 0028    RITHESH TRADERS
50  Purchase    2017-09-15 00:00:00.000 0029    RITHESH TRADERS
51  Purchase    2017-09-06 00:00:00.000 0030    SRI PRAMEELA MARKETINGS
52  Purchase    2017-09-08 00:00:00.000 0031    MOKSHITHA ENTERPRISES
53  Purchase    2017-09-09 00:00:00.000 0032    SAI MAHESWARA AGENCIES
54  Purchase    2017-09-09 00:00:00.000 0033    SRI VINAYAKA AGENCIES
55  Purchase    2017-09-15 00:00:00.000 0034    CHELLU ENTERPRISES
56  Purchase    2017-09-15 00:00:00.000 0035    CHELLU ENTERPRISES
58  Purchase    2017-09-29 00:00:00.000 0036    SATHYA TRADING CO
59  Purchase    2017-09-22 00:00:00.000 0037    CHELLU ENTERPRISES
60  Purchase    2017-09-22 00:00:00.000 0038    RITHESH TRADERS
61  Purchase    2017-09-28 00:00:00.000 0039    CHELLU ENTERPRISES
62  Purchase    2017-09-28 00:00:00.000 0040    RITHESH TRADERS
63  Purchase    2017-09-28 00:00:00.000 0041    RITHESH TRADERS
64  Purchase    2017-09-29 00:00:00.000 0042    SATHYA TRADING CO
65  Purchase    2017-10-09 00:00:00.000 0043    SRI VINAYAKA AGENCIES
66  Purchase    2017-10-10 00:00:00.000 0044    CHELLU ENTERPRISES
67  Purchase    2017-10-11 00:00:00.000 0045    MOKSHITHA ENTERPRISES
68  Purchase    2017-10-14 00:00:00.000 0046    SATHYA TRADING CO
69  Purchase    2017-10-14 00:00:00.000 0047    RITHESH TRADERS
72  Purchase    2017-10-23 00:00:00.000 0048    CHELLU ENTERPRISES
73  Purchase    2017-10-23 00:00:00.000 0049    CHELLU ENTERPRISES
74  Purchase    2017-10-23 00:00:00.000 0050    CHELLU ENTERPRISES

SALEREPORT

ID  VOUCHERTYPE VOUCHERDATE     VOUCHERNO   PARTY
4   Sale    2017-10-02 00:00:00.000 0212    SAI MEDICALS
6   HOLD    2017-10-03 00:00:00.000 0214    VAMSI KRISHNA SUPER BAZAAR
7   Sale    2017-10-03 00:00:00.000 0215    ADS SUPER BAZAAR
9   Sale    2017-10-04 00:00:00.000 0217    SRI BALAJI GENARAL STORES
10  Sale    2017-10-04 00:00:00.000 0218    NEW SS BEKERY
11  Sale    2017-10-04 00:00:00.000 0219    KANYAKA PARAMESWARI STORES
12  Sale    2017-10-05 00:00:00.000 0220    VASAVI STORES
13  Sale    2017-10-05 00:00:00.000 0221    NAVEEN
14  Sale    2017-10-05 00:00:00.000 0222    SRI HARI MEDICALS
15  Sale    2017-10-05 00:00:00.000 0223    JAKKAM SHOPPING CORNER
16  Sale    2017-10-05 00:00:00.000 0224    C NARESH
19  Sale    2017-10-05 00:00:00.000 0225    K R C SONS STORES
20  Sale    2017-10-05 00:00:00.000 0226    SREEDHAR TRADERS
21  Sale    2017-10-06 00:00:00.000 0227    B V SHANMUGAM
22  Sale    2017-10-06 00:00:00.000 0228    NEW VENKATESWARA SWEETS
23  Sale    2017-10-07 00:00:00.000 0229    VIJAYA MEDICAL&GENARAL STORES
24  Sale    2017-10-07 00:00:00.000 0230    LANCHIPALLI MALLAINAIDU
25  Sale    2017-10-07 00:00:00.000 0231    NEW VENKATADRI SWEETS&COOL DRINKS
27  Sale    2017-10-08 00:00:00.000 0232    LANCHIPALLI MALLAINAIDU
28  Sale    2017-10-08 00:00:00.000 0233    J.BALASUBRAMANYAM
29  Sale    2017-10-08 00:00:00.000 0234    RAJESWARI GENARAL STORES
30  Sale    2017-10-08 00:00:00.000 0235    M/S SRI SAI PROVISINAL&DIGNITY STORES
31  Sale    2017-10-08 00:00:00.000 0236    B V SUBRAMANYAM
32  Sale    2017-10-09 00:00:00.000 0237    K. MADHUSUDAHANA,KUPPAM
33  Sale    2017-10-09 00:00:00.000 0238    JK SUPER BAZAAR
34  Sale    2017-10-09 00:00:00.000 0239    NEW LAKSHMI PROVISION STORES
35  Sale    2017-10-03 00:00:00.000 0213    RAJU
36  Sale    2017-10-04 00:00:00.000 0216    BALAJI
42  Sale    2017-11-03 00:00:00.000 0293    LAKSHMI SUPER BAZAAR
43  Sale    2017-11-03 00:00:00.000 0292    SREEDHAR TRADERS
44  Sale    2017-11-02 00:00:00.000 0291    M/S R S PANDURANGA GENARAL MARCHANT
45  Sale    2017-11-02 00:00:00.000 0290    SREEDHAR TRADERS
47  Sale    2017-11-04 00:00:00.000 0294    SRI MURUGAN AGENCY&GENARAL STORES
49  Sale    2017-11-04 00:00:00.000 0295    SRI HARI MEDICALS
50  Sale    2017-11-05 00:00:00.000 0296    M/S SRI SAI PROVISINAL&DIGNITY STORES
52  Sale    2017-11-05 00:00:00.000 0297    LAKSHMI SUPER BAZAAR
53  Sale    2017-11-05 00:00:00.000 0298    VAMSI KRISHNA SUPER BAZAAR
54  Sale    2017-10-02 00:00:00.000 0210    KA SUPER BAZAAR
55  Sale    2017-10-02 00:00:00.000 0211    SRI MURUGAN AGENCY&GENARAL STORES

I tried running the query:

    select
        dp.ITEMNAME,dp.BARCODE,
        (CAST(dp.QUANTITY AS numeric(18,2))) ,
        ds.BARCODE,
        (CAST(ds.QTY AS numeric(18,2))) as [ClosingStock]
    from [iBillDB].[dbo].detailpurchases as dp
    join [iBillDB].[dbo].purchasereport as pr on dp.BARCODE=pr.voucherno
    join [iBillDB].[dbo].detailsale as ds on ds.ITEMN=dp.ITEMN
    join [iBillDB].[dbo].salesreport as sr on ds.BARCODE=sr.voucherno
    where ds.T='R'
    and dp.ITEMN='106'
    group by dp.ITEMNAME,dp.QUANTITY,ds.QTY,dp.BARCODE,ds.BARCODE;

I get result as follows:

ITEMNAME        BARCODE cs      BARCODE ClosingStock
5STAR 10.1G 5/- 0025    108.00  0225    1.00
5STAR 10.1G 5/- 0025    108.00  0227    1.00
5STAR 10.1G 5/- 0070    108.00  0225    1.00
5STAR 10.1G 5/- 0070    108.00  0227    1.00
5STAR 10.1G 5/- 0025    108.00  0218    18.00
5STAR 10.1G 5/- 0025    108.00  0291    18.00
5STAR 10.1G 5/- 0070    108.00  0218    18.00
5STAR 10.1G 5/- 0070    108.00  0291    18.00
5STAR 10.1G 5/- 0025    108.00  0214    2.00
5STAR 10.1G 5/- 0025    108.00  0236    2.00
5STAR 10.1G 5/- 0025    108.00  0293    2.00
5STAR 10.1G 5/- 0070    108.00  0214    2.00
5STAR 10.1G 5/- 0070    108.00  0236    2.00
5STAR 10.1G 5/- 0070    108.00  0293    2.00
5STAR 10.1G 5/- 0025    108.00  0232    4.00
5STAR 10.1G 5/- 0070    108.00  0232    4.00
5STAR 10.1G 5/- 0025    108.00  0220    5.00
5STAR 10.1G 5/- 0025    108.00  0231    5.00
5STAR 10.1G 5/- 0025    108.00  0235    5.00
5STAR 10.1G 5/- 0070    108.00  0220    5.00
5STAR 10.1G 5/- 0070    108.00  0231    5.00
5STAR 10.1G 5/- 0070    108.00  0235    5.00
5STAR 10.1G 5/- 0021    144.00  0225    1.00
5STAR 10.1G 5/- 0021    144.00  0227    1.00
5STAR 10.1G 5/- 0021    144.00  0218    18.00
5STAR 10.1G 5/- 0021    144.00  0291    18.00
5STAR 10.1G 5/- 0021    144.00  0214    2.00
5STAR 10.1G 5/- 0021    144.00  0236    2.00
5STAR 10.1G 5/- 0021    144.00  0293    2.00
5STAR 10.1G 5/- 0021    144.00  0232    4.00
5STAR 10.1G 5/- 0021    144.00  0220    5.00
5STAR 10.1G 5/- 0021    144.00  0231    5.00
5STAR 10.1G 5/- 0021    144.00  0235    5.00
5STAR 10.1G 5/- 0039    180.00  0225    1.00
5STAR 10.1G 5/- 0039    180.00  0227    1.00
5STAR 10.1G 5/- 0039    180.00  0218    18.00
5STAR 10.1G 5/- 0039    180.00  0291    18.00
5STAR 10.1G 5/- 0039    180.00  0214    2.00
5STAR 10.1G 5/- 0039    180.00  0236    2.00
5STAR 10.1G 5/- 0039    180.00  0293    2.00
5STAR 10.1G 5/- 0039    180.00  0232    4.00
5STAR 10.1G 5/- 0039    180.00  0220    5.00
5STAR 10.1G 5/- 0039    180.00  0231    5.00
5STAR 10.1G 5/- 0039    180.00  0235    5.00
5STAR 10.1G 5/- 0044    270.00  0225    1.00
5STAR 10.1G 5/- 0044    270.00  0227    1.00
5STAR 10.1G 5/- 0044    270.00  0218    18.00
5STAR 10.1G 5/- 0044    270.00  0291    18.00
5STAR 10.1G 5/- 0044    270.00  0214    2.00
5STAR 10.1G 5/- 0044    270.00  0236    2.00
5STAR 10.1G 5/- 0044    270.00  0293    2.00
5STAR 10.1G 5/- 0044    270.00  0232    4.00
5STAR 10.1G 5/- 0044    270.00  0220    5.00
5STAR 10.1G 5/- 0044    270.00  0231    5.00
5STAR 10.1G 5/- 0044    270.00  0235    5.00
5STAR 10.1G 5/- 0014    4860.00 0225    1.00
5STAR 10.1G 5/- 0014    4860.00 0227    1.00
5STAR 10.1G 5/- 0015    4860.00 0225    1.00
5STAR 10.1G 5/- 0015    4860.00 0227    1.00
5STAR 10.1G 5/- 0014    4860.00 0218    18.00
5STAR 10.1G 5/- 0014    4860.00 0291    18.00
5STAR 10.1G 5/- 0015    4860.00 0218    18.00
5STAR 10.1G 5/- 0015    4860.00 0291    18.00
5STAR 10.1G 5/- 0014    4860.00 0214    2.00
5STAR 10.1G 5/- 0014    4860.00 0236    2.00
5STAR 10.1G 5/- 0014    4860.00 0293    2.00
5STAR 10.1G 5/- 0015    4860.00 0214    2.00
5STAR 10.1G 5/- 0015    4860.00 0236    2.00
5STAR 10.1G 5/- 0015    4860.00 0293    2.00
5STAR 10.1G 5/- 0014    4860.00 0232    4.00
5STAR 10.1G 5/- 0015    4860.00 0232    4.00
5STAR 10.1G 5/- 0014    4860.00 0220    5.00
5STAR 10.1G 5/- 0014    4860.00 0231    5.00
5STAR 10.1G 5/- 0014    4860.00 0235    5.00
5STAR 10.1G 5/- 0015    4860.00 0220    5.00
5STAR 10.1G 5/- 0015    4860.00 0231    5.00
5STAR 10.1G 5/- 0015    4860.00 0235    5.00
5STAR 10.1G 5/- 0009    90.00   0225    1.00
5STAR 10.1G 5/- 0009    90.00   0227    1.00
5STAR 10.1G 5/- 0034    90.00   0225    1.00
5STAR 10.1G 5/- 0034    90.00   0227    1.00
5STAR 10.1G 5/- 0009    90.00   0218    18.00
5STAR 10.1G 5/- 0009    90.00   0291    18.00
5STAR 10.1G 5/- 0034    90.00   0218    18.00
5STAR 10.1G 5/- 0034    90.00   0291    18.00
5STAR 10.1G 5/- 0009    90.00   0214    2.00
5STAR 10.1G 5/- 0009    90.00   0236    2.00
5STAR 10.1G 5/- 0009    90.00   0293    2.00
5STAR 10.1G 5/- 0034    90.00   0214    2.00
5STAR 10.1G 5/- 0034    90.00   0236    2.00
5STAR 10.1G 5/- 0034    90.00   0293    2.00
5STAR 10.1G 5/- 0009    90.00   0232    4.00
5STAR 10.1G 5/- 0034    90.00   0232    4.00
5STAR 10.1G 5/- 0009    90.00   0220    5.00
5STAR 10.1G 5/- 0009    90.00   0231    5.00
5STAR 10.1G 5/- 0009    90.00   0235    5.00
5STAR 10.1G 5/- 0034    90.00   0220    5.00
5STAR 10.1G 5/- 0034    90.00   0231    5.00
5STAR 10.1G 5/- 0034    90.00   0235    5.00

in the above result The 2ndcolumn is BillNo of Purchases and 3rd column is QTY purchased
4th column is BillNo of Sales and 5th Column is QTY sold

My assessment is here while Summing up the values are repeated twice.

EXPECTED RESULT is:
10647

Actual Result is:
117243

Body:
You are multplying values by joining unrelated records. (You are combining every purchase detail records with every sales detail record in an item.) You want to join the purchase sum with the sales sum, so aggregate first, join then:

select
  coaleasce(p.itemname, s.itemname) as itemname,
  coaleasce(p.sum_qty, 0) - coaleasce(s.sum_qty, 0) as closing_stock
from
(
  select
    itemname,
    sum(cast(quantity as numeric(18, 2))) as sum_qty
  from detailpurchases
  where barcode in (select voucherno from purchasereport where voucherdate between ? and ?)
  group by itemname
) p
full outer join
(
  select
    itemname,
    sum(cast(qty as numeric(18, 2))) as sum_qty
  from detailsale
  where barcode in (select voucherno from salesreport where voucherdate between ? and ?)
  and T = 'R'
  group by itemname
) s on s.itemname = p.itemname;


问:
How to inherit schema properties from another schema?
I'm using ReDoc to visualize API documentation using an OpenAPI 2 (Swagger) JSON file. I'm trying to declare two request input parameters by including the first schema into the second one as follows:

...
"definitions": {
    "list-request": {
        "type": "object",
        "properties": {
            "token":{
                "type": "string",
                "format": "access-token",
                "required": true
            },
            "userId":{
                "type": "integer",
                "required": true,
                "format": "int32"
            },
            "mode": {
                "type": "string",
                "required": false,
                "default": "lite",
                "enum": [
                    "lite",
                    "detailed"
                ]
            },
            ... // other peroperties
        },
        "xml": {
            "name": "list-request"
        }
    },
    "list-request-lite":{
        "$ref": "#/definitions/list-request",
        "properties":{
            "mode": {
                "type": "string",
                "required": false,
                "enum": ["lite"]
            }
        }
    },
    ...
}
```

But it does not work - the list-request-lite schema just shows the mode property and none of the list-request schema properties are included. What am I doing wrong?

答:
You need allOf to combine a $ref with other properties.

Also, the required properties need to be listed in the required array on the schema level. Individual properties don't have the required attribute.

"definitions": {
  "list-request": {
    "type": "object",
    "properties": {
      "token": {
        "type": "string",
        "format": "access-token"
      },
      "userId": {
        "type": "integer",
        "format": "int32"
      },
      "mode": {
        "type": "string",
        "default": "lite",
        "enum": [
          "lite",
          "detailed"
        ]
      }
    },
    "xml": {
      "name": "list-request"
    },
    "required": [     // <---- required properties for this schema
      "token",
      "userId"
    ]
  },

  "list-request-lite": {
    "allOf": [        // <---------
      {
        "$ref": "#/definitions/list-request"
      },
      {
        "type": "object",
        "properties": {
          "mode": {
            "type": "string",
            "enum": ["lite"]
          }
        }
      }
    ]
  }
}
```

Body:
I'm using ReDoc to visualize API documentation using an OpenAPI 2 (Swagger) JSON file. I'm trying to declare two request input parameters by including the first schema into the second one as follows:

...
"definitions": {
    "list-request": {
        "type": "object",
        "properties": {
            "token":{
                "type": "string",
                "format": "access-token",
                "required": true
            },
            "userId":{
                "type": "integer",
                "required": true,
                "format": "int32"
            },
            "mode": {
                "type": "string",
                "required": false,
                "default": "lite",
                "enum": [
                    "lite",
                    "detailed"
                ]
            },
            ... // other peroperties
        },
        "xml": {
            "name": "list-request"
        }
    },
    "list-request-lite":{
        "$ref": "#/definitions/list-request",
        "properties":{
            "mode": {
                "type": "string",
                "required": false,
                "enum": ["lite"]
            }
        }
    },
    ...
}

But it does not work - the list-request-lite schema just shows the mode property and none of the list-request schema properties are included. What am I doing wrong?


问:
How to combine text with spaces in to a single column in R?
My last column ("details") has information that has spaces or tabs. How can I read all details as a single column in R?

input

```<code>date    month   year    type    expenditure details
10/31/2017  Oct 2017    food    10.89   Point Of Sale Withdrawal 17203473997 TRESIDDER U2           STANFORD     CAUS
10/31/2017  Oct 2017    uber    4.80    Point Of Sale Withdrawal 44519795098 UBER   TRIP F73MU      HELP.UBER.COMCAUS
10/31/2017  Oct 2017    instacart   99.00   Point Of Sale Withdrawal 44534891998 INSTACART SUBSCRIPTION HTTPSINSTACARCAUS
10/31/2017  Oct 2017    food    8.45    Point Of Sale Withdrawal 22607113998 CLARK CENTER-BIO-X CAF STANFORD     CAUS
10/31/2017  Oct 2017    food    4.00    Point Of Sale Withdrawal 33426639883 COUPA CAFE Y2E2        STANFORD     CAUS
10/31/2017  Oct 2017    uber    4.52    Point Of Sale Withdrawal 42029000200217 UBER TRIP QZ7W5 HELP.UB800-5928996  CAUS
10/30/2017  Oct 2017    food    5.85    Point Of Sale Withdrawal 44519950998 UBER   TRIP HOOMP      HELP.UBER.COMCAUS
10/30/2017  Oct 2017    uber    23.20   Point Of Sale Withdrawal 33428390882 COUPA CAFE LYTTON      PALO ALTO    CAUS
10/30/2017  Oct 2017    food    7.52    Point Of Sale Withdrawal 34530890882 PANDA EXPRESS #2035    STANFORD     CAUS
</code>```

答:
I'm not an expert on this, but I found a way that works. It uses readLines to read in every line from your file as a single string, and then split the first five words (columns date, month, year, type and expenditure) and uses the remainder of the line as a final column details:

```<code>raw_txt <- readLines("123.txt")

splitted <- lapply(strsplit(raw_txt[-1], " +"), function(x){
   one_to_five <- x[1:5]
   six         <- paste0(x[5:length(x)], collapse=" ")
   c(one_to_five, six)
})

# Bind together the elements in "splitted":
df <- do.call(rbind, splitted)

# Give the columns the right names:
colnames(df) <- strsplit(raw_txt[1], " +")[[1]]
</code>```

Result:

```<code>      date         month year   type        expenditure details
 [1,] "10/31/2017" "Oct" "2017" "food"      "10.89"     "10.89 Point Of Sale Withdrawal 17203473997 TRESIDDER U2 STANFORD CAUS"
 [2,] "10/31/2017" "Oct" "2017" "uber"      "4.80"      "4.80 Point Of Sale Withdrawal 44519795098 UBER TRIP F73MU HELP.UBER.COMCAUS"
 [3,] "10/31/2017" "Oct" "2017" "instacart" "99.00"     "99.00 Point Of Sale Withdrawal 44534891998 INSTACART SUBSCRIPTION HTTPSINSTACARCAUS"
 [4,] "10/31/2017" "Oct" "2017" "food"      "8.45"      "8.45 Point Of Sale Withdrawal 22607113998 CLARK CENTER-BIO-X CAF STANFORD CAUS"
 [5,] "10/31/2017" "Oct" "2017" "food"      "4.00"      "4.00 Point Of Sale Withdrawal 33426639883 COUPA CAFE Y2E2 STANFORD CAUS"
 [6,] "10/31/2017" "Oct" "2017" "uber"      "4.52"      "4.52 Point Of Sale Withdrawal 42029000200217 UBER TRIP QZ7W5 HELP.UB800-5928996 CAUS"
 [7,] "10/30/2017" "Oct" "2017" "food"      "5.85"      "5.85 Point Of Sale Withdrawal 44519950998 UBER TRIP HOOMP HELP.UBER.COMCAUS"
 [8,] "10/30/2017" "Oct" "2017" "uber"      "23.20"     "23.20 Point Of Sale Withdrawal 33428390882 COUPA CAFE LYTTON PALO ALTO CAUS"
 [9,] "10/30/2017" "Oct" "2017" "food"      "7.52"      "7.52 Point Of Sale Withdrawal 34530890882 PANDA EXPRESS #2035 STANFORD CAUS"
</code>```

Body:
My last column ("details") has information that has spaces or tabs. How can I read all details as a single column in R?

input

date    month   year    type    expenditure details
10/31/2017  Oct 2017    food    10.89   Point Of Sale Withdrawal 17203473997 TRESIDDER U2           STANFORD     CAUS
10/31/2017  Oct 2017    uber    4.80    Point Of Sale Withdrawal 44519795098 UBER   TRIP F73MU      HELP.UBER.COMCAUS
10/31/2017  Oct 2017    instacart   99.00   Point Of Sale Withdrawal 44534891998 INSTACART SUBSCRIPTION HTTPSINSTACARCAUS
10/31/2017  Oct 2017    food    8.45    Point Of Sale Withdrawal 22607113998 CLARK CENTER-BIO-X CAF STANFORD     CAUS
10/31/2017  Oct 2017    food    4.00    Point Of Sale Withdrawal 33426639883 COUPA CAFE Y2E2        STANFORD     CAUS
10/31/2017  Oct 2017    uber    4.52    Point Of Sale Withdrawal 42029000200217 UBER TRIP QZ7W5 HELP.UB800-5928996  CAUS
10/30/2017  Oct 2017    food    5.85    Point Of Sale Withdrawal 44519950998 UBER   TRIP HOOMP      HELP.UBER.COMCAUS
10/30/2017  Oct 2017    uber    23.20   Point Of Sale Withdrawal 33428390882 COUPA CAFE LYTTON      PALO ALTO    CAUS
10/30/2017  Oct 2017    food    7.52    Point Of Sale Withdrawal 34530890882 PANDA EXPRESS #2035    STANFORD     CAUS

Body:
I'm not an expert on this, but I found a way that works. It uses readLines to read in every line from your file as a single string, and then split the first five words (columns date, month, year, type and expenditure) and uses the remainder of the line as a final column details:

raw_txt <- readLines("123.txt")

splitted <- lapply(strsplit(raw_txt[-1], " +"), function(x){
   one_to_five <- x[1:5]
   six         <- paste0(x[5:length(x)], collapse=" ")
   c(one_to_five, six)
})

# Bind together the elements in "splitted":
df <- do.call(rbind, splitted)

# Give the columns the right names:
colnames(df) <- strsplit(raw_txt[1], " +")[[1]]

Result:

      date         month year   type        expenditure details
 [1,] "10/31/2017" "Oct" "2017" "food"      "10.89"     "10.89 Point Of Sale Withdrawal 17203473997 TRESIDDER U2 STANFORD CAUS"
 [2,] "10/31/2017" "Oct" "2017" "uber"      "4.80"      "4.80 Point Of Sale Withdrawal 44519795098 UBER TRIP F73MU HELP.UBER.COMCAUS"
 [3,] "10/31/2017" "Oct" "2017" "instacart" "99.00"     "99.00 Point Of Sale Withdrawal 44534891998 INSTACART SUBSCRIPTION HTTPSINSTACARCAUS"
 [4,] "10/31/2017" "Oct" "2017" "food"      "8.45"      "8.45 Point Of Sale Withdrawal 22607113998 CLARK CENTER-BIO-X CAF STANFORD CAUS"
 [5,] "10/31/2017" "Oct" "2017" "food"      "4.00"      "4.00 Point Of Sale Withdrawal 33426639883 COUPA CAFE Y2E2 STANFORD CAUS"
 [6,] "10/31/2017" "Oct" "2017" "uber"      "4.52"      "4.52 Point Of Sale Withdrawal 42029000200217 UBER TRIP QZ7W5 HELP.UB800-5928996 CAUS"
 [7,] "10/30/2017" "Oct" "2017" "food"      "5.85"      "5.85 Point Of Sale Withdrawal 44519950998 UBER TRIP HOOMP HELP.UBER.COMCAUS"
 [8,] "10/30/2017" "Oct" "2017" "uber"      "23.20"     "23.20 Point Of Sale Withdrawal 33428390882 COUPA CAFE LYTTON PALO ALTO CAUS"
 [9,] "10/30/2017" "Oct" "2017" "food"      "7.52"      "7.52 Point Of Sale Withdrawal 34530890882 PANDA EXPRESS #2035 STANFORD CAUS"


问:
How does SSL work on two connected domains?
I've read through related questions but couldn't quite find what I am looking for.
I have set up a domain just as "domain.com" and created two subdomains "client.domain.com" and "client-intern.domain.com". Further, there is a redirect active for "client.domain.com/intern" pointing to "client-intern.domain.com".

If I buy a single SSL certificate for "client.domain.com", will the data transfer also be secured when the client is going to "client.domain.com/intern"?
Or do I have to purchase a second certificate for "client-intern.domain.com"?

Thanks in advance for clarification,
Paul

UPDATE: If entering "client.domain.com/intern" into the web browsers address bar, this address remains there and the browser shows the content of "client-intern.domain.com" nonetheless.

答: You need a wildcard certificate to cover multiple subdomains (in your case domain.com, client.domain.com and client-intern.domain.com). Some CAs might offer you an option to include one or two subdomains into the certificate (as alternative name field) for free or for a small additional fee, but this is CA-dependent and in general the right way is a wildcard certificate. You can read about wildcard certs here (GlobalSign site).</p>


问:
ng-repeat using one-time binding - does track by then have an impact on performance?
As I read here (performance of $interpolate vs ng-repeat and one time binding) having the directive ng-repeat and use one-time binding is nearly equal in case of performance. Please correct me if this isn't right!

This means, that when using one-time binding on ng-repeat, the attribute track by doesn't add any value, right? Or does it actually help me in terms of performance, because ng-repeat otherwise still would generate an index at $$hashKey?

答:
This means, that when using one-time binding on ng-repeat, the attribute track by doesn't add any value, right?

There is no correlation between track by and one-time binding.

one-time binding reduces watchers count

track by doesn't re-render DOM once your list is updated from server and their is no change (lets say based on id of item)

one-time binding in ng-repeat a.e. ng-repeat="friend in ::friends" will stop recalculating friends once they are stable, which happens after the first digest cycle (if the expression result is a non-undefined value).

For example:

```<code><li ng-repeat="friend in ::friends ">{{friend.name}}</li>
</code>```

and:

```<code>$scope.friends = [{
    id: 0,
    name: 'Ben'
  }];

  $timeout(function(){
     $scope.friends.push({
    id: 3,
    name: 'Chen'
  });
  },1000);
</code>```

Result:

You will see  Ben but after 1 second delay there is no change because one-time binding stopped ng-repeat watcher. We commonly use it for fixed lists.

Demo 1

BTW, it works for list items count and not on item itself.

one-time binding will not get rid of $$hashKey

But you can write:

```<code><li ng-repeat="friend in ::friends track by friend.id">
</code>```

Demo 2

Body:
This means, that when using one-time binding on ng-repeat, the attribute track by doesn't add any value, right?

There is no correlation between track by and one-time binding.

one-time binding reduces watchers count

track by doesn't re-render DOM once your list is updated from server and their is no change (lets say based on id of item)

one-time binding in ng-repeat a.e. ng-repeat="friend in ::friends" will stop recalculating friends once they are stable, which happens after the first digest cycle (if the expression result is a non-undefined value).

For example:

<li ng-repeat="friend in ::friends ">{{friend.name}}</li>

and:

$scope.friends = [{
    id: 0,
    name: 'Ben'
  }];

  $timeout(function(){
     $scope.friends.push({
    id: 3,
    name: 'Chen'
  });
  },1000);

Result:

You will see  Ben but after 1 second delay there is no change because one-time binding stopped ng-repeat watcher. We commonly use it for fixed lists.

Demo 1

BTW, it works for list items count and not on item itself.

one-time binding will not get rid of $$hashKey

But you can write:

<li ng-repeat="friend in ::friends track by friend.id">

Demo 2


问:
Android, how can I remove controls of VideoView?
In my project I have a Video View that I put it in splash screen. Everything is OK and I can see it in splash screen but the problem is when it shows, control bar (back, next, time length) will show as well that I want see it. How can I disable it?

In the sample code (that I got my idea), it had

mVideoView.requestFocus();

that I removed it but still I think it has focus and because of this it shows control bar. Am I right? How can I prevent and don't let to show?

update:
This is my code:

```<code>mVideoView = (VideoView) findViewById(R.id.splash_video);
mVideoView.setVideoURI(Uri.parse("android.resource://com.infindo.motogp/raw/sp"));
mVideoView.setMediaController(new MediaController(this));
</code>```

答: You just have to remove videoView.setMediaController();

Body:
In my project I have a Video View that I put it in splash screen. Everything is OK and I can see it in splash screen but the problem is when it shows, control bar (back, next, time length) will show as well that I want see it. How can I disable it?

In the sample code (that I got my idea), it had

mVideoView.requestFocus();

that I removed it but still I think it has focus and because of this it shows control bar. Am I right? How can I prevent and don't let to show?

update:
This is my code:

mVideoView = (VideoView) findViewById(R.id.splash_video);
mVideoView.setVideoURI(Uri.parse("android.resource://com.infindo.motogp/raw/sp"));
mVideoView.setMediaController(new MediaController(this));


问:
After adding feature module in Android getting error "Error:Non-base feature modules require AAPTv2 to build."
In Android for Instant app after adding feature module getting below error "Error:Non-base feature modules require AAPTv2 to build."</p>

答: Make sure that in gradle.properties "android.enableAapt2" is set true</p>


问:
Varchar and int columns join in sql
I tried this query

```<code>insert into Dimension_DDTU (BI_Id, BI_Name, DBI_Id, dBI_Name)
    select
        ds.BI_ID,
        dvo.name,
        ds.BI_Id + '' + dm.DBI_Id as DBI_Id,
        dso.dname
    from
        Census.dbo.SMaster sm
    full outer join
        C.dbo.dis dso on dso.did = sm.did
    full outer join
        C.dbo.Div dvo on dvo.dsid = dso.diid
    full outer join
        b.dbo.DMap ds on ds.DOp_Id = dso.did
    full outer join
        b.dbo.DsMap dm on dm.DOp_Id = sm.did
</code>```

here BI_Id,DBI_Id data type is nvarchar(50) because I am storing values like this (001,002 ...)

and other columns which is in join are all int data type except

```<code>BI_Id and DBI_Id
</code>```

this shows an error

String or binary data would be truncated.

答:
Error says you are having troubles with insertion.

Here: Dimension_DDTU (BI_Id, BI_Name, DBI_Id, dBI_Name) one of column sized is not enough for storing inserted values.

My chrystal ball says it is Dimension_DDTU.DBI_Id which is of same varchar(50) size whilst must be varchar(100) at least to accept ds.BI_Id + '' + dm.DBI_Id (varchar(50) + varchar(50)).

If there will be a separator between those IDs then you should increaze size by size of that separator as well.

Title: Varchar and int columns join in sql

Body:
I tried this query

insert into Dimension_DDTU (BI_Id, BI_Name, DBI_Id, dBI_Name)
    select
        ds.BI_ID,
        dvo.name,
        ds.BI_Id + '' + dm.DBI_Id as DBI_Id,
        dso.dname
    from
        Census.dbo.SMaster sm
    full outer join
        C.dbo.dis dso on dso.did = sm.did
    full outer join
        C.dbo.Div dvo on dvo.dsid = dso.diid
    full outer join
        b.dbo.DMap ds on ds.DOp_Id = dso.did
    full outer join
        b.dbo.DsMap dm on dm.DOp_Id = sm.did

here BI_Id,DBI_Id data type is nvarchar(50) because I am storing values like this (001,002 ...)

and other columns which is in join are all int data type except

BI_Id and DBI_Id

this shows an error

String or binary data would be truncated.


问:
What Angular Providers do and how to use it?
I'm new with Angular. I follow a tutorial from this link, and i tried to do/add something that doesn't part of that tutorial. I added a providers :[EmployeeService] line to employee-list.component.ts and empployee.component.ts inside @component, and it returns error that said TypeError: Cannot read property 'push' of undefined. So realize that adding providers :[EmployeeService] to some components are unnecessary. I read about Dependency Injection from this link but i do not really get what i wanted to know. So can anyone give me a simple explanation how/when/where to use/put providers and how that error happens?

Thank you very much in advance.

答:
providers array tells Angular what services it should instantiate. You can define it on two places:

component

module

When you use providers in component the service will be available to that and all it's children.

When you use it in module the service will be available for all pipes, directives, components and services in given module.

But you can define it in both if you want - in that case Angular will create two instances of the same service.

For beginning provide your services on the module level.