반응형

* VBNET 폴더 락 설정 및 해제  - 권한 설정 및 해제 예제...

 테스트 환경

 - 윈도우7 64 Bit

 - Visual Studio 2008 닷넷 프레임 워크 3.5


메인화면

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'Folder Open
        Dim fbd As FolderBrowserDialog = New FolderBrowserDialog

        If (fbd.ShowDialog() = Windows.Forms.DialogResult.OK) Then

            label1.Text = fbd.SelectedPath

        End If

    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
        'Folder Lock Set
        '선택된 폴더가 존재 하지 않으면...
        If (Not System.IO.Directory.Exists(label1.Text)) Then
            Return
        End If

        Try

            Dim strAdminUserName As String = Environment.UserName
            Dim ds As System.Security.AccessControl.DirectorySecurity = System.IO.Directory.GetAccessControl(label1.Text)
            Dim fsa As System.Security.AccessControl.FileSystemAccessRule = New System.Security.AccessControl.FileSystemAccessRule(strAdminUserName, _
                                                                                                                                   Security.AccessControl.FileSystemRights.FullControl, _
                                                                                                                                   Security.AccessControl.AccessControlType.Deny)
            ds.AddAccessRule(fsa)
            System.IO.Directory.SetAccessControl(label1.Text, ds)

        Catch ex As Exception
            label2.Text = ex.Message.ToString()
        End Try
        label2.Text = "Folder Lock Success..."

    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        'Folder Lock Cancel

        '선택된 폴더가 존재 하지 않으면...
        If (Not System.IO.Directory.Exists(label1.Text)) Then
            Return
        End If

        Try
            Dim strAdminUserName As String = Environment.UserName
            Dim ds As System.Security.AccessControl.DirectorySecurity = System.IO.Directory.GetAccessControl(label1.Text)
            Dim fsa As System.Security.AccessControl.FileSystemAccessRule = New System.Security.AccessControl.FileSystemAccessRule(strAdminUserName, _
                                                                                                                                   Security.AccessControl.FileSystemRights.FullControl, _
                                                                                                                                   Security.AccessControl.AccessControlType.Deny)


            ds.RemoveAccessRule(fsa)
            System.IO.Directory.SetAccessControl(label1.Text, ds)

        Catch ex As Exception
            label2.Text = ex.Message.ToString()
        End Try

        label2.Text = "Folder Lock Cancel..."

    End Sub

End Class

 

* 결과 화면

 

위 그림과 같이 해당 폴더 권한을 설정 하고 접근 하면 권한이 없다고 나오고 해제 하고 접근 하게 되면 해당 폴더에

접근 할 수 있게 됩니다. 



https://kdsoft-zeros.tistory.com/87

 

[C#] 폴더 락 설정 및 해제 (Folder Lock) - 권한 설정 및 해제

* C# 폴더 락 설정 및 해제 - 권한 설정 및 해제 예제... 테스트 환경 - 윈도우7 64 Bit - Visual Studio 2008 닷넷 프레임 워크 3.5 전체 소스 코드 Form1.cs using System; using System.Collections.Generic;..

kdsoft-zeros.tistory.com

 

반응형
반응형

* C# 폴더 락 설정 및 해제  - 권한 설정 및 해제 예제...

 테스트 환경

 - 윈도우7 64 Bit

 - Visual Studio 2008 닷넷 프레임 워크 3.5

 

메인화면

 

전체 소스 코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using System.Security.AccessControl;
using System.IO;

namespace CSharp_FolderLock
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //Folder Lock Set
            //선택된 폴더가 존재 하지 않는다면....
            if (!Directory.Exists(label1.Text))
            {
                return;
            }

            try
            {
                string adminUserName = Environment.UserName;
                DirectorySecurity ds = Directory.GetAccessControl(label1.Text);
                FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);
                ds.AddAccessRule(fsa);
                Directory.SetAccessControl(label1.Text, ds);
            }
            catch (Exception ex)
            {
                label2.Text = ex.Message.ToString();
            }

            label2.Text = "Folder Lock Success...";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //Folder Lock Cancel
            //선택된 폴더가 존재 하지 않는다면....
            if (!Directory.Exists(label1.Text))
            {
                return;
            }


            try
            {
                string adminUserName = Environment.UserName;
                DirectorySecurity ds = Directory.GetAccessControl(label1.Text);
                FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);
                ds.RemoveAccessRule(fsa);
                Directory.SetAccessControl(label1.Text, ds);
            }
            catch (Exception ex)
            {
                label2.Text = ex.Message.ToString();
            }
            label2.Text = "Folder Lock Cancel...";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Folder Select
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                label1.Text = fbd.SelectedPath ;
            }

        }
    }
}

 

* 결과 화면

 

위 그림과 같이 해당 폴더 권한을 설정 하고 접근 하면 권한이 없다고 나오고 해제 하고 접근 하게 되면 해당 폴더에

접근 할 수 있게 됩니다. 

반응형
반응형

* 안드로이드 리스트뷰 예제...

 

public class ListViewActivity extends AppCompatActivity {

//string 배열 선언... 
String[] strList = {"Button Ex", "TabView Ex", "Timer Ex", "내부 File Read & Write Ex", "Local DB Ex","리스트뷰 필터링"};

 

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

//액션바 셋팅
ActionBar ab = getSupportActionBar();
ab.setTitle("메인화면...");

 

//어뎁터 연결 리스트뷰랑...
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,strList);
ListView lv = (ListView)findViewById(R.id.lvMain);
lv.setAdapter(adapter1);

 

//리스트 뷰 이벤트
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplicationContext(),((TextView)view).getText() + "클릭함. " + i,Toast.LENGTH_SHORT).show();
// i 변수 인덱스 키

반응형
반응형

* VBNET 기상청 날씨 (Weather) 정보 가져오기 예제...

 

메인화면

전체 소스 코드

Form1.vb

========================================================================

Public Class Form1

    Dim strURL As String = "http://www.kma.go.kr/weather/forecast/mid-term-xml.jsp"
    Dim strCity As String = ""

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cboCity.SelectedIndex = 10
        lblToday.Text = DateTime.Now.ToString("yyyy-MM-dd")
    End Sub

    Private Sub cboCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCity.SelectedIndexChanged
        Try

            Using xr As Xml.XmlReader = Xml.XmlReader.Create(strURL)

                Dim strMsg As String = ""
                Dim ws As Xml.XmlWriterSettings = New Xml.XmlWriterSettings()
                ws.Indent = True
                Dim bCheck As Boolean = False
                Dim iCount As Integer = 0

                strCity = cboCity.Text

                While (xr.Read())

                    Select Case xr.NodeType
                        Case Xml.XmlNodeType.CDATA
                            '헤더 내용 표시
                            txtMsg.Text = xr.Value.ToString().Replace(", ")
                        Case Xml.XmlNodeType.Element
                        Case Xml.XmlNodeType.Text
                            '선택된 도시이면...
                            If (xr.Value.Equals(strCity)) Then
                                bCheck = True
                            End If

                            If (bCheck) Then
                                Dim dt As DateTime
                                Dim b As Boolean = DateTime.TryParse(xr.Value.ToString(), dt)

                                If b Then
                                    strMsg += "/"
                                End If

                                strMsg += xr.Value + ","
                                iCount += 1
                                If (iCount > 36) Then
                                    bCheck = False
                                End If

                            End If

                        Case Xml.XmlNodeType.XmlDeclaration
                        Case Xml.XmlNodeType.ProcessingInstruction
                        Case Xml.XmlNodeType.Comment
                        Case Xml.XmlNodeType.EndElement
                    End Select

                End While

                '요일별로 짜르기
                Dim strTmp() As String = strMsg.Split("/")

                '요일별 데이터로 나누기
                Dim strWh1() As String = strTmp(1).Split(",")
                label3.Text = strWh1(0)
                label5.Text = "최저: " + strWh1(2) + " ℃"
                label6.Text = "최고: " + strWh1(3) + " ℃"
                label7.Text = strWh1(1)

                Dim strWh2() As String = strTmp(2).Split(",")
                label11.Text = strWh2(0)
                label10.Text = "최저: " + strWh2(2) + " ℃"
                label9.Text = "최고: " + strWh2(3) + " ℃"
                label8.Text = strWh2(1)

                Dim strWh3() As String = strTmp(3).Split(",")
                label15.Text = strWh3(0)
                label14.Text = "최저: " + strWh3(2) + " ℃"
                label13.Text = "최고: " + strWh3(3) + " ℃"
                label12.Text = strWh3(1)

                Dim strWh4() As String = strTmp(4).Split(",")
                label27.Text = strWh4(0)
                label26.Text = "최저: " + strWh4(2) + " ℃"
                label25.Text = "최고: " + strWh4(3) + " ℃"
                label24.Text = strWh4(1)

                Dim strWh5() As String = strTmp(5).Split(",")
                label23.Text = strWh5(0)
                label22.Text = "최저: " + strWh5(2) + " ℃"
                label21.Text = "최고: " + strWh5(3) + " ℃"
                label20.Text = strWh5(1)

                Dim strWh6() As String = strTmp(6).Split(",")
                label19.Text = strWh6(0)
                label18.Text = "최저: " + strWh6(2) + " ℃"
                label17.Text = "최고: " + strWh6(3) + " ℃"
                label16.Text = strWh6(1)

            End Using

        Catch ex As Exception

        End Try
    End Sub

    
End Class

========================================================================

기상청 jsp 내용

 

콤보 박스 내용은 아래의 그림과 같이 속성에서 바로 등록 해 주었으며, ComboBox Index 가 아닌

Text 즉 도시 이름으로 체크 하기에 아이템 순서는 상관이 없습니다.

 

 

*결과 화면

 

 

반응형
반응형

* 기상청 날씨 (Weather) 정보 가져오기 예제...

 

메인화면

전체 소스 코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace CSharp_Weather
{
    public partial class Form1 : Form
    {
        string strURL = "http://www.kma.go.kr/weather/forecast/mid-term-xml.jsp";
        string strCity = "";
        public Form1()
        {
            InitializeComponent();

            cboCity.SelectedIndex = 10;
            lblToday.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }

        private void cboCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                using (XmlReader xr = XmlReader.Create(strURL))
                {
                    string strMsg = "";
                    XmlWriterSettings ws = new XmlWriterSettings();
                    ws.Indent = true;
                    bool bCheck = false;
                    int iCount = 0;
                    strCity = cboCity.Text;

                    while (xr.Read())
                    {
                        switch (xr.NodeType)
                        {
                            case XmlNodeType.CDATA:
                                {
                                    txtMsg.Text = xr.Value.ToString().Replace("<br />", " ");
                                    break;
                                }
                            case XmlNodeType.Element:
                                {
                                    break;
                                }
                            case XmlNodeType.Text:
                                {
                                    if (xr.Value.Equals(strCity))
                                    {
                                        bCheck = true;
                                    }

                                    if (bCheck)
                                    {
                                        DateTime dt;
                                        bool b = DateTime.TryParse(xr.Value.ToString(), out dt);
                                        if (b)
                                        {
                                            strMsg += "/";
                                        }

                                        strMsg += xr.Value + ",";
                                        iCount += 1;
                                        if (iCount > 36)
                                        {
                                            bCheck = false;
                                        }
                                    }
                                    break;
                                }
                            case XmlNodeType.XmlDeclaration:
                                {
                                    break;
                                }
                            case XmlNodeType.ProcessingInstruction:
                                {
                                    break;
                                }
                            case XmlNodeType.Comment:
                                {
                                    break;
                                }
                            case XmlNodeType.EndElement:
                                {
                                    break;
                                }
                        }
                    }//while

                    //요일별로 짜르기
                    string[] strTmp = strMsg.Split('/');

                    //요일별 데이터
                    string[] strWh1 = strTmp[1].Split(',');
                    label3.Text = strWh1[0];
                    label5.Text = "최저: " + strWh1[2] + " ℃";
                    label6.Text = "최고: " + strWh1[3] + " ℃";
                    label7.Text = strWh1[1];

                    string[] strWh2 = strTmp[2].Split(',');
                    label11.Text = strWh2[0];
                    label10.Text = "최저: " + strWh2[2] + " ℃";
                    label9.Text = "최고: " + strWh2[3] + " ℃";
                    label8.Text = strWh2[1];

                    string[] strWh3 = strTmp[3].Split(',');
                    label15.Text = strWh3[0];
                    label14.Text = "최저: " + strWh3[2] + " ℃";
                    label13.Text = "최고: " + strWh3[3] + " ℃";
                    label12.Text = strWh3[1];

                    string[] strWh4 = strTmp[4].Split(',');
                    label27.Text = strWh4[0];
                    label26.Text = "최저: " + strWh4[2] + " ℃";
                    label25.Text = "최고: " + strWh4[3] + " ℃";
                    label24.Text = strWh4[1];

                    string[] strWh5 = strTmp[5].Split(',');
                    label23.Text = strWh5[0];
                    label22.Text = "최저: " + strWh5[2] + " ℃";
                    label21.Text = "최고: " + strWh5[3] + " ℃";
                    label20.Text = strWh5[1];

                    string[] strWh6 = strTmp[6].Split(',');
                    label19.Text = strWh6[0];
                    label18.Text = "최저: " + strWh6[2] + " ℃";
                    label17.Text = "최고: " + strWh6[3] + " ℃";
                    label16.Text = strWh6[1];
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }
        }
    }
}

기상청 jsp 내용 

 

콤보 박스 내용은 아래의 그림과 같이 속성에서 바로 등록 해 주었으며, ComboBox Index 가 아닌

Text 즉 도시 이름으로 체크 하기에 아이템 순서는 상관이 없습니다.

 

 

*결과 화면

 

반응형
반응형

* 안드로이드 내부 저장소 파일 읽고 쓰고 지우기 예제...

 

메인화면

 

전체 소스 코드

 

package com.example.administrator.androidcontrolex;

import android.content.Context;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class InFileExActivity extends AppCompatActivity {

    EditText etInput;
    TextView tvList;

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

        //액션바 셋팅
        ActionBar ab = getSupportActionBar();
        ab.setTitle("내부 파일 예제...");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        etInput = (EditText)findViewById(R.id.txtInput);
        tvList = (TextView)findViewById(R.id.txtList);

        Button btnS = (Button)findViewById(R.id.btnSave);
        Button btnL = (Button)findViewById(R.id.btnLoad);
        Button btnD = (Button)findViewById(R.id.btnDelete);
        Button btnO = (Button)findViewById(R.id.btnOpen);

        btnS.setOnClickListener(lisner);
        btnL.setOnClickListener(lisner);
        btnD.setOnClickListener(lisner);
        btnO.setOnClickListener(lisner);

    }

    public  void FileSave(String strFileName, String strMsg)
    {
        try
        {
            //파일이름 날짜 표현 방법 : String strTime = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            //20180903_112233
            FileOutputStream fos = openFileOutput(strFileName, Context.MODE_APPEND);
            String strText = strMsg + "\n";
            fos.write(strText.getBytes());
            fos.close();
        }
        catch (Exception e)
        {
            Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
            return;
        }

        Toast.makeText(getApplicationContext(),"파일 저장이 완료 되었습니다.",Toast.LENGTH_SHORT).show();
    }

    public  String FileLoad(String strFileName)
    {
        String strTmp;
        try {
            FileInputStream fis = openFileInput(strFileName);
            StringBuffer sb = new StringBuffer();
            byte dataBuffer[] = new byte[1024];
            int n = 0 ;

            // -1 파일 끝을 의미
            while((n=fis.read(dataBuffer)) != -1 ){
                sb.append(new String(dataBuffer) );
            }

            strTmp = sb.toString();
            fis.close();

        }
        catch (Exception e)
        {
            Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
            return "";
        }

        Toast.makeText(getApplicationContext(),"파일 로드가 완료 되었습니다.",Toast.LENGTH_SHORT).show();
        return  strTmp;
    }

    public  void FileDelete(String strFileName)
    {
        if(deleteFile(strFileName))
        {
            Toast.makeText(getApplicationContext(),"파일 정상적으로 삭제 되었습니다.",Toast.LENGTH_SHORT).show();
        }
        else
        {
            Toast.makeText(getApplicationContext(),"파일 삭제하는데 실패 하였습니다.",Toast.LENGTH_SHORT).show();
        }
    }


    Button.OnClickListener lisner = new Button.OnClickListener(){
      public void onClick(View vi)
      {
            switch (vi.getId())
            {
                case R.id.btnSave :
                {
                    FileSave("test.txt", etInput.getText().toString());
                    etInput.setText("");
                    break;
                }
                case R.id.btnLoad :
                {
                    tvList.setText(FileLoad("test.txt"));
                    break;
                }
                case R.id.btnDelete :
                {
                    FileDelete("test.txt");
                    break;
                }
                case R.id.btnOpen :
                {

                    break;
                }
            }
      }
    };

  
}

 

파일 Write Source

 

파일 Read Source

파일 Delete Source

 

 

*예제 결과 화면

파일 저장
파일 읽기
파일 삭제
파일이 삭제 된 후 파일 읽기한 화면

 

반응형
반응형

* 휴대폰 설정 -> 일반 -> 휴대폰 정보 로 들어 갑니다.

  소프트웨어 정보 로 또 들어가서 빌드 번호가 나오게 되면

  두번 연속 클릭 하게 되면 개발자 모드로 진입 하게 됩니다.

 

  개발자 모드로 되었으면 개발자 옵션에서 USB 디버깅 연결시 항상 

  허용을 해 줍니다. 

  안드로이드 스튜디오를 열고 실행을 했을 때 아래의 그림과 같이 Connected

  Devices 에 USB 로 연결된 휴대폰이 뜨면 성공 안뜨면... 

  Ex) 삼성 폰이면 삼성 홈페이지로 이동 드라이브를 다운 받아 설치를 합니다.

       아래의 휴대폰은 LG 폰으로 연결 한 예

 

반응형
반응형

* DateTime Class 를 이용한 현재 선택된 달의 마지막 날짜 및 요일 구하기 예제...

 

메인화면

 

 

전체 소스코드

Form1.vb

 

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'C# 과 같은 DateTime Class 이용
        numYear.Value = DateTime.Now.Year
        numMonth.Value = DateTime.Now.Month

        'VB6 처럼 사용
        'numYear.Value = Date.Now.Year
        'numMonth.Value = Date.Now.Month

    End Sub

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        '날짜 타입으로 변환 하기...
        Dim dtTmp As DateTime = DateTime.Parse(numYear.Value.ToString() + "-" + numMonth.Value.ToString() + "-01")

        '현재 선택된 달 +1 하기...
        Dim dt As DateTime = dtTmp.AddMonths(1)
        '+1 된 달에서 하루 빼기...
        dt = dt.AddDays(-1)

        label4.Text = "선택된 년월: " + numYear.Value.ToString() + "-" + numMonth.Value.ToString()
        label5.Text = "마지막 일: " + dt.ToString("dd")
        label6.Text = "마지막 요일: " + GetDayOfWeek(dt)


    End Sub


    Private Function GetDayOfWeek(ByVal dt As DateTime) As String

        Dim strDay As String = ""

        Select Case dt.DayOfWeek
            Case DayOfWeek.Monday
                strDay = "월요일"
            Case DayOfWeek.Tuesday
                strDay = "화요일"
            Case DayOfWeek.Wednesday
                strDay = "수요일"
            Case DayOfWeek.Thursday
                strDay = "목요일"
            Case DayOfWeek.Friday
                strDay = "금요일"
            Case DayOfWeek.Saturday
                strDay = "토요일"
            Case DayOfWeek.Sunday
                strDay = "일요일"
        End Select

        Return strDay

    End Function

End Class

 

* 사용자 정의 함수 GetDayOfWeek => 요일 값을 문자열로 변환 하여 리턴 하는 함수

 

* 예제 결과

 

결과화면

 

반응형

+ Recent posts