Linq Distinct & Group by 하기

 

var result = myList.GroupBy(test => test.id)
                   .Select(grp => grp.First())
                   .ToList();
또는
        var q = from c in dt.AsEnumerable()
                group c by c.Field<string>("WSOperate") into g
                select new
                {
                    WSOperate = g.Key
                };

http://technet.microsoft.com/ko-kr/library/bb522522(v=sql.105).aspx

 

 

image

TEST1 테이블에는 데이터가 없다 . MERGE 를 통해서 데이터 삽입

 

    MERGE TEST1  AS T

      USING  TEST2 AS S
      ON S.PostID = T.PostID

        WHEN MATCHED THEN

        UPDATE SET [NO] = S.[NO]

        WHEN NOT MATCHED THEN

        INSERT VALUES(S.[NO] , S.NAME)

        WHEN NOT MATCHED BY SOURCE THEN 
        DELETE;

    SELECT  * FROM TEST1    
    SELECT  * FROM TEST2

image

 

또는

    MERGE TEST1  AS T

      USING  ( SELECT 100 AS [NO] , 'KOJAEDOO' AS NAME , 0 AS POSTID) AS S
      ON S.PostID = T.PostID

        WHEN MATCHED THEN

        UPDATE SET [NO] = S.[NO]

        WHEN NOT MATCHED THEN

        INSERT VALUES(S.[NO] , S.NAME)

        WHEN NOT MATCHED BY SOURCE THEN 
        DELETE;

    SELECT  * FROM TEST1    
    SELECT  * FROM TEST2

image

자바스크립트 호출로Ajax 판넬의 데이터 업데이트

 

 

image

 

“자바스크립트로 DataList 업데이트” (Button1)를 클릭하면 
“숨김버튼 자바스크립트로 이버튼 클릭”"(Button2) 를 이벤트를 비하인드로 실행시킨다.
 
WebFrom1.aspx
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <script>
            function UpdateGrid() {
                alert("업데이트 호출");

                <%=Page.GetPostBackEventReference(Button2)%>;
                return false;
            }

        </script>
    <div>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DataList ID="DataList1" runat="server">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                        <br />
                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("RegDate") %>'></asp:Label>
                    </ItemTemplate>
                </asp:DataList>
                <asp:Button ID="Button2" runat="server" Text="숨김버튼 자바스크립트로 이버튼 클릭" OnClick="Button2_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
    
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="자바스크립트로 DataList 업데이트"  OnClientClick="return UpdateGrid();" />
    
    </div>
    </form>
</body>
</html>
WebForm1.cs
    public partial class WebForm1 : System.Web.UI.Page
    {
        DataTable dt = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
            dt.Columns.Add("Name");
            dt.Columns.Add("RegDate");

            UpdateDatetime();
        }

        private void UpdateDatetime()
        {
            dt.Rows.Clear();
            for (int i = 0; i < 10; i++)
            {
                DataRow row = dt.NewRow();
                row["Name"] = i.ToString();
                row["RegDate"] = DateTime.Now.ToString();
                dt.Rows.Add(row);
            }

            this.DataList1.DataSource = dt;
            this.DataList1.DataBind();

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           //자바스크립트로 Button2클릭 이벤트를 호출해서 들어온 이벤트
            UpdateDatetime();
        }


    }
 
 
<%=Page.GetPostBackEventReference(Button2)%>; 이것만 알면 끝~

 

클라이언트

주의할점은

서버와 클라이언트 방식을 똑같이 맞추어 줘야한다

일단 기본적으로 20MB 이상 안올라감

아래값은 최대값이다(2GB) 이렇게 하면 성능 저하 및 디도스 공격에 취약해짐. 적절하게 값을 지정 해야하고

인증받은 계정만 쓸 수 있게 해야함

 

   transferMode="Streamed" messageEncoding="Mtom"

 

        private static IFileService CreateIFileService()
        {
            BasicHttpBindingService<IFileService> service
                                = new BasicHttpBindingService<IFileService>(Framework.Module.WCFCommon.FileServiceURL);
            service.BasicHttpBindingProperty.MessageEncoding = WSMessageEncoding.Mtom;
            service.BasicHttpBindingProperty.TransferMode = TransferMode.Streamed;
            service.BasicHttpBindingProperty.MaxBufferPoolSize = 2147483647;
            service.BasicHttpBindingProperty.MaxBufferSize = 2147483647;
            service.BasicHttpBindingProperty.MaxReceivedMessageSize = 2147483647;
      
            service.BasicHttpBindingProperty.ReaderQuotas.MaxDepth = 2147483647;
            service.BasicHttpBindingProperty.ReaderQuotas.MaxArrayLength = 2147483647;
            service.BasicHttpBindingProperty.ReaderQuotas.MaxBytesPerRead = 2147483647;
            service.BasicHttpBindingProperty.ReaderQuotas.MaxStringContentLength = 2147483647;
            service.BasicHttpBindingProperty.ReaderQuotas.MaxNameTableCharCount = 2147483647;

            return service.CreateProxy();
        }

서버 web.config

    <bindings>
      <basicHttpBinding>
        <binding name="baseBasicHttpBinding" closeTimeout="00:10:00"
          openTimeout="00:50:00" receiveTimeout="01:50:00" sendTimeout="00:50:00"
          maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
          transferMode="Streamed" messageEncoding="Mtom">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
 <services>
      <service name="KAI.CIM.WebService.FileService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="baseBasicHttpBinding"
          contract="KAI.CIM.Framework.Contract.IFileService" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
      </service>
    </services>

 

http://msdn.microsoft.com/ko-kr/library/aa395209(v=vs.110).aspx

* MTOM은 SOAP 메시지와 함께 큰 이진 첨부 파일을 원시 바이트로 전송함으로써 더 작은 크기의 메시지를 허용하는 메커니즘입니다.

오라클 클라이언트 드라이버등등 기타 여러가지의 이유로 32비트 DLL이 실행되어야하는 경우가 있다 이때 설정하는 방법

 

image

 

image

 

 

image

인터넷이 안되는곳에서 프로젝트를 배포할때 관련 파일을 같은 서버또는 다운받을수 있는곳에

올려놔야 하는데 이파일이 비주얼 스튜디오깔면 같이 깔린다.

 

파일위치

image

 

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages

image

너무간단해서 소스참고

    public partial class EnumFrm : Form
    {
        public enum UserLevel { Guest = -1, User = 0, Admin = 1 };

        public EnumFrm()
        {
            InitializeComponent();
            
            //enum 을 바인딩한다.
            this.c1Combo1.DataSource = Enum.GetNames(typeof(UserLevel));
        }

        private void c1Button1_Click(object sender, EventArgs e)
        {
            //콤보박스의 enum 값을 가져온다.
            var result = Enum.Parse(typeof(UserLevel), c1Combo1.SelectedText,false);
        }
    }

HTML 파싱을 보다 쉽게 할수있게 해주는 무료프레임워크

image

 

예제

BODY 태그의 내용만 가져오기

            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(q); //<html><body>kojaedoo</body></html>

            HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");

            if (bodyNode != null)
            {
                // Do something with bodyNode
                var bodyContent = bodyNode.InnerHtml;
            }

 

다른예제

 HtmlDocument doc = new HtmlDocument();
 doc.Load("file.htm");
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
 {
    HtmlAttribute att = link["href"];
    att.Value = FixLink(att);
 }
 doc.Save("file.htm");
 
 

다운로드

http://htmlagilitypack.codeplex.com/

GroupBox내에 있는 라디오 버튼의 체크된 값(Tag)을 가지고 온다.

매번 가져오기 귀찮아서 ㅡ_ㅡ;

image

namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
            this.groupBox1.SetRadioBoxValue("0001"); //값 세팅
        }

        private void button1_Click(object sender, EventArgs e)
        {
           var q= this.groupBox1.GetRadioBoxValue(); //체크된 박스의 tag값 읽어오기
           this.c1TextBox1.Text = q.ToString();
        }
    }
}

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public static class ControlExtention
    {
        /// <summary>
        /// Tag로 세팅된 값을 읽어온다.
        /// </summary>
        /// <param name="groupBox">The group box.</param>
        /// <returns></returns>
        public static object GetRadioBoxValue(this GroupBox groupBox)
        {
            try
            {
                foreach (Control item in groupBox.Controls)
                {
                    if (item.GetType() == typeof(RadioButton))
                    {
                        if (((RadioButton)item).Checked)
                        {
                            return item.Tag.ToString();
                        }
                    }
                }

                return string.Empty;
            }
            catch
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// Tag로 세팅된 저장한다.
        /// </summary>
        /// <param name="groupBox">The group box.</param>
        /// <returns></returns>
        public static void SetRadioBoxValue(this GroupBox groupBox , string tagValue)
        {

                foreach (Control item in groupBox.Controls)
                {
                    if (item.GetType() == typeof(RadioButton))
                    {
                        if (((RadioButton)item).Tag.ToString() == tagValue )
                        {
                            ((RadioButton)item).Checked = true;
                            return;
                        }
                    }
                }
            
        }//End For


    }
}

확장메서드

http://msdn.microsoft.com/ko-kr/library/bb383977.aspx

 

설정하기

첫번째 행의 DataType을 Boolean으로 설정한다.
 
 
 

선택된 행만 가져오기

 

private void btnDelete_Click(object sender, EventArgs e) { // delete selected rows _flex.Redraw = false; int rowsCnt = _flex.Rows.Count; RowCollection row = _flex.Rows; for (int i = rowsCnt - 1; 0 < i; i--) { Row r = _flex.Rows[i]; var q = r[0]; bool result = false; if (q != null && bool.TryParse(q.ToString(), out result)) { _flex.Rows.Remove(r.Index); } } this._flex.Redraw = true; }


위에처럼 하니 체크를 해제해도 해제가 안된다 ㅡㅡ

체크박스 선택 다른방법으로 가져오기

            for (int i = flexGrid.Rows.Count - 1; 0 < i; i--)

            {

                CheckEnum result = flexGrid.GetCellCheck(i, 0);

                if (result == CheckEnum.Checked)

                {

                    Row r = flexGrid.Rows[i];

                    TestObject dv = r.DataSource as TestObject;

                    Debug.WriteLine(dv.Name);

                }

            }

+ Recent posts