public void panelClick(object sender, EventArgs e) { FlowLayoutPanel panel = (FlowLayoutPanel)sender; Control[] c = Controls.Find("label" + panel.Name.Substring(15), true); string day = c[0].Text; string date = yearLabel.Text + "-" + monthLabel.Text + "-" + day; if (day != "") // 날 없는 칸 선택 못하게 { MemoForm memoForm = new MemoForm("", "", Color.White.ToString(), "N", date); if (memoForm.ShowDialog() == DialogResult.OK) // 메모 저장 { TitleValue = memoForm.TitleValue; ContentsValue = memoForm.ContentsValue; ColorValue = memoForm.ColorValue; OracleConnection conn = dbConnect(); OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; OracleTransaction STrans = null; //오라클 트랜젝션 STrans = conn.BeginTransaction(); cmd.Transaction = STrans; //커맨드에 트랜젝션 명시 cmd.CommandText = "INSERT INTO memo VALUES(MEMO_ID_SEQUENCE.NEXTVAL, '" + TitleValue + "', '" + ContentsValue + "', '" + date + "', '" + ColorValue + "')"; cmd.ExecuteNonQuery(); cmd.Transaction.Commit(); //커밋 dbClose(conn); Label l = Addlabel(TitleValue, ColorValue); panel.Controls.Add(l); l.DoubleClick += new System.EventHandler(this.labelDoubleClick); return; } } }
public void labelDoubleClick(object sender, EventArgs e) { Label titleLabel = (Label)sender; Control parent = titleLabel.Parent; Control[] c = Controls.Find("label" + parent.Name.Substring(15), true); string day = c[0].Text; string date = yearLabel.Text + "-" + monthLabel.Text + "-" + day; // 해당 날짜 + 제목의 정보 가져와서 memoForm에 뿌려줌 OracleConnection conn = dbConnect(); OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT * FROM memo WHERE memo_date = :memo_date AND title = :title"; cmd.Parameters.Add(new OracleParameter("memo_date", date)); cmd.Parameters.Add(new OracleParameter("title", titleLabel.Text)); OracleDataReader reader = cmd.ExecuteReader(); string title = ""; string contents = ""; Color color = titleLabel.BackColor; if (reader.HasRows) { while (reader.Read()) { title = reader.GetString(1); if (reader.GetOracleString(2).IsNull == false) { contents = reader.GetString(2); } } } else { Console.WriteLine("No rows found."); } reader.Close(); dbClose(conn); MemoForm memoForm = new MemoForm(title, contents, color.ToString(), "Y", date); DialogResult result = memoForm.ShowDialog(); if (result == DialogResult.OK) //메모 수정 { TitleValue = memoForm.TitleValue; ContentsValue = memoForm.ContentsValue; ColorValue = memoForm.ColorValue; conn = dbConnect(); cmd = new OracleCommand(); cmd.Connection = conn; OracleTransaction STrans = null; //오라클 트랜젝션 STrans = conn.BeginTransaction(); cmd.Transaction = STrans; //커맨드에 트랜젝션 명시 cmd.CommandText = "UPDATE memo SET title = '" + TitleValue + "', memo_contents = '" + ContentsValue + "', color = '" + ColorValue + "' WHERE title = '" + title + "' AND memo_date = '" + date + "'"; cmd.ExecuteNonQuery(); cmd.Transaction.Commit(); //커밋 dbClose(conn); titleLabel.Text = TitleValue; titleLabel.BackColor = Color.FromName(ColorValue); return; } else if (result == DialogResult.No) // 메모 삭제 { conn = dbConnect(); cmd = new OracleCommand(); cmd.Connection = conn; OracleTransaction STrans = null; //오라클 트랜젝션 STrans = conn.BeginTransaction(); cmd.Transaction = STrans; //커맨드에 트랜젝션 명시 cmd.CommandText = "DELETE FROM memo WHERE title = '" + title + "' AND memo_date = '" + date + "'"; cmd.ExecuteNonQuery(); cmd.Transaction.Commit(); //커밋 dbClose(conn); parent.Controls.Remove(titleLabel); titleLabel.Dispose(); return; } }