private void button1_Click(object sender, EventArgs e)
        {
            DataTable table = (DataTable) dataGridView1.DataSource;

            // 방법1. 구조 및 전체 데이터 복제 후, filter and sort  
            DataTable table2 = table.Copy();
            table2.DefaultView.RowFilter = "구분 = '사용중'";
            table2.DefaultView.Sort = "ID DESC";

            dataGridView2.DataSource = table2;
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable table = (DataTable) dataGridView1.DataSource;

            // 방법2. 원본에서 필요한 데이터만 복사.
            // DataTable table2 = table.Clone(); // Clone은 구조만 복사됨.
            DataRow[] rows = table.Select("구분 = '사용중'", "ID DESC");
            DataTable table2 = rows.CopyToDataTable<DataRow>();

            dataGridView2.DataSource = table2;
        }
        

 

728x90

'Programming Language > C#' 카테고리의 다른 글

spread 에서 sheet 복사  (0) 2020.06.18
DataTable의 DataRow값을 빠르게 변경하기.  (0) 2020.06.05
NLog 사용 샘플  (0) 2020.04.25
[펌] Correlation of two arrays in C#  (0) 2020.02.06
ChartFX Help  (0) 2020.01.19

NLog

1. 개요
1.1 용도
 - Net platforms 용 Log.

1.2 관련사이트
 - NLog:https://nlog-project.org/
 
2. 사용법
2.1 설치
 - Visual Studio에서 프로젝트내 참조에서, "NuGet 패키지관리"메뉴에서 검색 후 설치.

2.2 NLog.config 파일 작성
 - 프로젝트 내에 파일 생성하고, 파일 속성에서 "출력 디렉토리에 복사"값을 "항상 복사"로 수정한다.

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>
        <target name="logfile" xsi:type="File" fileName="file.txt" />
        <target name="logconsole" xsi:type="Console" />
    </targets>

    <rules>
        <logger name="*" minlevel="Info" writeTo="logconsole" />
        <logger name="*" minlevel="Debug" writeTo="logfile" />
    </rules>
</nlog>

2.3 코딩

namespace WindowsFormsAppTestNLog
{
    public partial class Form1 : Form
    {
        private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            logger.Info("Hello {0}", "Earth");
        }
    }
}

 

 

 

 

 

728x90

'Programming Language > C#' 카테고리의 다른 글

DataTable의 DataRow값을 빠르게 변경하기.  (0) 2020.06.05
DataTable 데이터 복제  (0) 2020.06.03
[펌] Correlation of two arrays in C#  (0) 2020.02.06
ChartFX Help  (0) 2020.01.19
remove comments with C#  (0) 2019.10.14

https://stackoverflow.com/questions/17447817/correlation-of-two-arrays-in-c-sharp

 

public double ComputeCoeff(double[] values1, double[] values2)
{
    if(values1.Length != values2.Length)
        throw new ArgumentException("values must be the same length");

    var avg1 = values1.Average();
    var avg2 = values2.Average();

    var sum1 = values1.Zip(values2, (x1, y1) => (x1 - avg1) * (y1 - avg2)).Sum();

    var sumSqr1 = values1.Sum(x => Math.Pow((x - avg1), 2.0));
    var sumSqr2 = values2.Sum(y => Math.Pow((y - avg2), 2.0));

    var result = sum1 / Math.Sqrt(sumSqr1 * sumSqr2);

    return result;
}

예)

var values1 = new List<double> { 3, 2, 4, 5 ,6 };
var values2 = new List<double> { 9, 7, 12 ,15, 17 };

var result = ComputeCoeff(values1.ToArray(), values2.ToArray());
// 0.997054485501581

Debug.Assert(result.ToString("F6") == "0.997054");

Excel 함수 사용 예)

var values1 = new List<double> { 3, 2, 4, 5 ,6 };
var values2 = new List<double> { 9, 7, 12 ,15, 17 };

// Make sure to add a reference to Microsoft.Office.Interop.Excel.dll
// and use the namespace

var application = new Application();

var worksheetFunction = application.WorksheetFunction;

var result = worksheetFunction.Correl(values1.ToArray(), values2.ToArray());

Console.Write(result); // 0.997054485501581

 

https://be2u.tistory.com/144

 

[c#] 상관계수 함수 - Correlation Coefficient Function

상관관계에 대한 공식 정리 c# 기반 소스 코드 private float Correlation(List xList, List yList) { float result = 0; float multiplyXYSigma = 0; float xSigma = 0; float ySigma = 0; float x..

be2u.tistory.com

 

728x90

'Programming Language > C#' 카테고리의 다른 글

DataTable 데이터 복제  (0) 2020.06.03
NLog 사용 샘플  (0) 2020.04.25
ChartFX Help  (0) 2020.01.19
remove comments with C#  (0) 2019.10.14
excel upload faster  (0) 2019.10.14

 

1. Chart FX 8

- main link: https://support.softwarefx.com/Chart_FX_8  

- API Reference: http://support.softwarefx.com/Chart_FX_8/api

- Programmer's Guide & Samples: http://support.softwarefx.com/Chart_FX_8/article/2501002

- Samples: http://support.softwarefx.com/Chart_FX_8/samples

- 한국어 퀵가이드: http://download.softwarefx.com/CfxNet80/Chart_FX_8_Quick_Guide_Korean.pdf

 

2. Chart FX 7

- main link: https://support.softwarefx.com/Chart_FX_7/

- API Reference: https://support.softwarefx.com/Chart_FX_7/api

- Programmer's Guide & Samples: https://support.softwarefx.com/Chart_FX_7/article/2501002

- Samples: https://support.softwarefx.com/Chart_FX_7/samples

 

end.

 

728x90

'Programming Language > C#' 카테고리의 다른 글

NLog 사용 샘플  (0) 2020.04.25
[펌] Correlation of two arrays in C#  (0) 2020.02.06
remove comments with C#  (0) 2019.10.14
excel upload faster  (0) 2019.10.14
c# 관련사이트  (0) 2019.10.14

+ Recent posts