본문 바로가기
PROGRAMMING CODE/C#

[Oracle & C#] 메모장 만들기

by daye_ 2021. 10. 20.

Form1.cs

using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void Form1_Load(object sender, EventArgs e)
        {
            oracleConnection1.Open();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //개체참조가 객체의 인스턴스로 설정되지 않았습니다.
            DateTime current_time;

            current_time = Convert.ToDateTime(oracleCommand2.ExecuteScalar());

            oracleCommand1.Parameters.Add(new OracleParameter("aa",textBox1.Text));
            oracleCommand1.Parameters.Add(new OracleParameter("bb", current_time));
            oracleCommand1.Parameters.Add(new OracleParameter("cc", richTextBox1.Text));

            /*oracleCommand1.Parameters["aa"].Value = textBox1.Text;
            oracleCommand1.Parameters["bb"].Value = current_time;
            oracleCommand1.Parameters["cc"].Value = richTextBox1.Text;*/


            oracleCommand1.ExecuteNonQuery();
            MessageBox.Show("Memo Successfully Added");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = null;
            richTextBox1.Text = null;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OracleDataReader rdr = oracleCommand3.ExecuteReader();
            while (rdr.Read())
            {
                listBox2.Items.Add(rdr["M_id"]);
            }
            rdr.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string sql = "SELECT M_date,M_contents FROM Memo_table Where M_id=";
            string num = listBox2.SelectedItem.ToString();
            oracleCommand4.CommandText = sql + num;
            OracleDataReader rdr = oracleCommand4.ExecuteReader();

            listBox3.Items.Clear();
            int count = rdr.FieldCount;

            while (rdr.Read())
            {
                listBox3.Items.Add(rdr["M_date"]);
                listBox3.Items.Add(rdr["M_contents"]);
            }
        }
    }
}




Form1.Designer.cs

namespace MEMO_PROJECT
{
    partial class Form1
    {
        /// <summary>
        /// 필수 디자이너 변수입니다.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 사용 중인 모든 리소스를 정리합니다.
        /// </summary>
        /// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form 디자이너에서 생성한 코드

        /// <summary>
        /// 디자이너 지원에 필요한 메서드입니다. 
        /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
        /// </summary>
        private void InitializeComponent()
        {
            this.tappage = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.button2 = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.listBox3 = new System.Windows.Forms.ListBox();
            this.button4 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.listBox2 = new System.Windows.Forms.ListBox();
            this.oracleCommand1 = new Oracle.ManagedDataAccess.Client.OracleCommand();
            this.oracleConnection1 = new Oracle.ManagedDataAccess.Client.OracleConnection();
            this.oracleCommand2 = new Oracle.ManagedDataAccess.Client.OracleCommand();
            this.oracleCommand3 = new Oracle.ManagedDataAccess.Client.OracleCommand();
            this.oracleCommand4 = new Oracle.ManagedDataAccess.Client.OracleCommand();
            this.tappage.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.tabPage2.SuspendLayout();
            this.SuspendLayout();
            // 
            // tappage
            // 
            this.tappage.AccessibleRole = System.Windows.Forms.AccessibleRole.ScrollBar;
            this.tappage.CausesValidation = false;
            this.tappage.Controls.Add(this.tabPage1);
            this.tappage.Controls.Add(this.tabPage2);
            this.tappage.Location = new System.Drawing.Point(48, 31);
            this.tappage.Name = "tappage";
            this.tappage.SelectedIndex = 0;
            this.tappage.Size = new System.Drawing.Size(700, 394);
            this.tappage.TabIndex = 0;
            // 
            // tabPage1
            // 
            this.tabPage1.Controls.Add(this.richTextBox1);
            this.tabPage1.Controls.Add(this.button2);
            this.tabPage1.Controls.Add(this.button1);
            this.tabPage1.Controls.Add(this.textBox1);
            this.tabPage1.Controls.Add(this.label1);
            this.tabPage1.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
            this.tabPage1.Location = new System.Drawing.Point(4, 25);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(692, 365);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "메모입력";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // richTextBox1
            // 
            this.richTextBox1.Location = new System.Drawing.Point(48, 86);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(584, 246);
            this.richTextBox1.TabIndex = 3;
            this.richTextBox1.Text = "";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(430, 33);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 1;
            this.button2.Text = "다음메모";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(335, 34);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(78, 22);
            this.button1.TabIndex = 1;
            this.button1.Text = "메모저장";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(99, 34);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(208, 25);
            this.textBox1.TabIndex = 2;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(36, 37);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(57, 15);
            this.label1.TabIndex = 1;
            this.label1.Text = "키워드 ";
            // 
            // tabPage2
            // 
             this.tabPage2.Controls.Add(this.listBox3);
            this.tabPage2.Controls.Add(this.button4);
            this.tabPage2.Controls.Add(this.button3);
            this.tabPage2.Controls.Add(this.listBox2);
            this.tabPage2.Location = new System.Drawing.Point(4, 25);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage2.Size = new System.Drawing.Size(692, 365);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "메모리스트";
            this.tabPage2.UseVisualStyleBackColor = true;
            // 
            // listBox3
            // 
            this.listBox3.FormattingEnabled = true;
            this.listBox3.ItemHeight = 15;
            this.listBox3.Location = new System.Drawing.Point(34, 151);
            this.listBox3.Name = "listBox3";
            this.listBox3.Size = new System.Drawing.Size(281, 184);
            this.listBox3.TabIndex = 3;
            // 
            // button4
            // 
            this.button4.Location = new System.Drawing.Point(468, 85);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(75, 23);
            this.button4.TabIndex = 2;
            this.button4.Text = "내용보기";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(468, 29);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(147, 49);
            this.button3.TabIndex = 1;
            this.button3.Text = "리스트보기";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // listBox2
            // 
            this.listBox2.FormattingEnabled = true;
            this.listBox2.ItemHeight = 15;
            this.listBox2.Location = new System.Drawing.Point(34, 29);
            this.listBox2.Name = "listBox2";
            this.listBox2.Size = new System.Drawing.Size(410, 79);
            this.listBox2.TabIndex = 0;
            // 
            // oracleCommand1
            // 
            this.oracleCommand1.CommandText = "INSERT INTO Memo_table(M_ID,M_KEYWORD,M_DATE,M_CONTENTS) VALUES(memo_seq.nextval, :aa, :bb, :cc)";
            this.oracleCommand1.Connection = this.oracleConnection1;
            this.oracleCommand1.Transaction = null;
            // 
            // oracleConnection1
            // 
            this.oracleConnection1.ConnectionString = "DATA SOURCE = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = IP)(" +
    "PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XEPDB1)));USER " +
    "ID = S5546938; PASSWORD = S5546938";
            this.oracleConnection1.Credential = null;
            this.oracleConnection1.PDBName = "xepdb1";
            this.oracleConnection1.ServiceName = "xepdb1";
            // 
            // oracleCommand2
            // 
            this.oracleCommand2.CommandText = "SELECT SYSDATE FROM DUAL";
            this.oracleCommand2.Connection = this.oracleConnection1;
            this.oracleCommand2.Transaction = null;
            // 
            // oracleCommand3
            // 
            this.oracleCommand3.CommandText = "SELECT M_id FROM Memo_table";
            this.oracleCommand3.Connection = this.oracleConnection1;
            this.oracleCommand3.Transaction = null;
            // 
            // oracleCommand4
            // 
            this.oracleCommand4.CommandText = "SELECT M_date, M_contents FROM Memo_table";
            this.oracleCommand4.Connection = this.oracleConnection1;
            this.oracleCommand4.Transaction = null;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(800, 450);
            this.Controls.Add(this.tappage);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.tappage.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabPage1.PerformLayout();
            this.tabPage2.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.TabControl tappage;
        private System.Windows.Forms.TabPage tabPage1;
        private System.Windows.Forms.TabPage tabPage2;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.ListBox listBox2;
        private System.Windows.Forms.ListBox listBox3;
        private System.Windows.Forms.Button button4;
        private System.Windows.Forms.Button button3;
        private Oracle.ManagedDataAccess.Client.OracleCommand oracleCommand1;
        private Oracle.ManagedDataAccess.Client.OracleConnection oracleConnection1;
        private Oracle.ManagedDataAccess.Client.OracleCommand oracleCommand2;
        private System.Windows.Forms.RichTextBox richTextBox1;
        private Oracle.ManagedDataAccess.Client.OracleCommand oracleCommand3;
        private Oracle.ManagedDataAccess.Client.OracleCommand oracleCommand4;
    }
}

'PROGRAMMING CODE > C#' 카테고리의 다른 글

윈도우 계산기 프로그램 _ C# (망한코드)  (0) 2021.10.14
윈도우 계산기 프로그램 _ C#  (0) 2021.10.14