본문 바로가기
C#

C# 할일 관리 프로그램 할일관리(5)(사용자관리 idx 연결)

by improve 2024. 3. 6.

●TodoForm

public void makeTodo(int panelx, int panely, Todo todo, int evenOdd)
{

 // 
 // panel4
 // 
 panel4.BackColor = SystemColors.Info;
 panel4.Controls.Add(checkBox1);
 panel4.Controls.Add(finish_lb_value);
 panel4.Controls.Add(content_lb_value);
 panel4.Controls.Add(title_lb_value);
 panel4.Controls.Add(finish_lb);
 panel4.Controls.Add(content_lb);
 panel4.Controls.Add(title_lb);
 panel4.Location = new Point(panelx, panely);
 panel4.Name = "panel4";
 panel4.Size = new Size(270, 220);
 panel4.TabIndex = 1;
 panel4.ResumeLayout(false);
 panel4.PerformLayout();

 this.panel1.Controls.Add(panel4);

 this.label1.AutoSize = true;
 this.label1.Font = new Font("휴먼엑스포", 20.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(129)));
 this.label1.Location = new Point(12, 18);
 this.label1.Name = "label1";
 this.label1.Size = new Size(67, 30);
 this.label1.TabIndex = 0;
 this.label1.Text = "예약";

 this.panel1.Controls.Add(this.label1);

 

panel4를 추가해준다.

 

 

      public void TodoSelect() 
      {
          DataTable dataTable = todoDBMan.select();
          int y = 90;
          int evenOdd = 1;
          foreach (DataRow row in dataTable.Rows)
          {

              int idx = int.Parse(row["idx"].ToString());
              string title = row["title"].ToString();
              string content = row["content"].ToString();
              DateTime finishdate = new DateTime(
                                     int.Parse(row["finishdate"].ToString().Split('-', ' ')[0]),
                                     int.Parse(row["finishdate"].ToString().Split('-', ' ')[1]),
                                     int.Parse(row["finishdate"].ToString().Split('-', ' ')[2])
                                     );


              Todo todo = new Todo();
              todo.idx = idx;
              todo.title = title;
              todo.content = content;
              todo.finishdate = finishdate;

              makeTodo(10, y, todo, evenOdd % 2);
              y += 230;
          }

 

함수로 지정해준다.

 

private void button1_Click(object sender, EventArgs e)
{
    bool result = todoDBMan.insert(new Todo()
    {
        users_idx = int.Parse(useridx_combobox.Text),
        title = title_textbox.Text,
        content = content_tb.Text,
        finishdate = finish_datepicker.Value
    });

    if (result)
    {
        MessageBox.Show("입력하였습니다.");

        title_textbox.Text = "";
        content_tb.Text = "";
        panel1.Controls.Clear();
        TodoSelect();  함수로 지정해준건 호출 한다.
    }
}

 

 public TodoForm()
 {
     InitializeComponent();
     TodoSelect();
     List<string> list = userDBMan.selectUserId();

     useridx_combobox.DataSource = list;
     useridx_combobox.SelectedText = "1";
 }

 

List로  userDBMan안에 있는 selectUserId 함수를 호출한다.

 

 

●UserDBMan

 public List<string> selectUserId() 
 {
     try 
     {
         OracleConnection con = DBINFO.openConnect();

         string sql = "select idx from users";

         OracleDataAdapter adapter = new OracleDataAdapter();
         DataSet ds = new DataSet();

         OracleCommand oracleCommand = new OracleCommand(sql, con);
         adapter.SelectCommand = oracleCommand;

         adapter.Fill(ds);

         DBINFO.closeConnect();
         List<string> list = new List<string>();
         foreach (DataRow dr in ds.Tables[0].Rows)
         {
             list.Add(dr["idx"].ToString());
         }
         return list;
     }
     catch (Exception e) 
     {
         MessageBox.Show(e.StackTrace);
         MessageBox.Show(e.Message);
         return null;
     }
 }

 

만들어 준다.