이 정도는 그냥 할 수 있을거라 생각했는데...ㅎㅎ
잊어먹지 않게끔 그리고 필요할 때 혹시 기억 안 나면 바로 찾아보게끔 정리..
- 폼 닫으면서 다른 폼 열기
// show the main form
Main_Form mform = new Main_Form();
mform.Show();
- 메세지박스 표시
MessageBox.Show("client information insert success", "Add ok",
MessageBoxButtons.OK, MessageBoxIcon.Error);
- 메뉴에서 폼 열기
private void manageClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
ManageClientsForm manageCF = new ManageClientsForm();
manageCF.ShowDialog();
}
- 애플리케이션 종료
private void Main_Form_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
- DB Connection Class (만들어놓고 다른 클래스나 폼에서 불러다가 사용)
// Requried Library for connect database
using System.Data;
using System.Data.SqlClient;
using Npgsql;
class CONNECT
{
private NpgsqlConnection connection = new NpgsqlConnection(
"Server='';Port='';Database='';User Id='';Password='';");
// create a function to return our connection
public NpgsqlConnection getConnection()
{
return connection;
}
// create a function to open the connection
public void openConnection()
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
}
// create a function to close the connection
public void closeConnection()
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
}
- DB실행 후 true/false 반환하기
if (command.ExecuteNonQuery() == 1)
{
return true;
}
else
{
return false;
}
- 데이터그리드에 데이터 표시하기
// client.cs 파일에서
public DataTable getClients()
{
NpgsqlCommand command = new NpgsqlCommand
("SELECT * FROM clients", conn.getConnection());
NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
DataTable table = new DataTable();
adapter.SelectCommand = command;
adapter.Fill(table);
return table;
}
// client_form.cs파일에서
dataGridView1.DataSource = client.getClients();
데이터베이스 파라메터 설정
// add parameters
command.Parameters.Add("@cid", NpgsqlTypes.NpgsqlDbType.Integer).Value = id;
콤보박스의 값을 정수로 변환해서 변수에 저장
int type = Convert.ToInt32(comboBoxRoomtype.SelectedValue.ToString());
데이터그리드에 있는 값을 가져와서 텍스트박스와 콤보박스에 뿌리기
// textbox
textBoxRoomNo.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
// combobox
comboBoxRoomtype.SelectedValue = dataGridView1.CurrentRow.Cells[1].Value;
콤보박스에 값을 가져와서 뿌려주기 (표시문자열, 실제 값)
// display room type
comboBoxRoomtype.DataSource = room.roomTypeList();
comboBoxRoomtype.DisplayMember = "label";
comboBoxRoomtype.ValueMember = "category_id";
[결과화면] - 만들고나면 별 거 없는데 왜 이걸 못하니 ㅠㅠ
댓글
댓글 쓰기