개발 노트

수정 삭제 조회 활성화 본문

프로그래밍/C#

수정 삭제 조회 활성화

알 수 없는 사용자 2022. 2. 15. 09:26

수정쿼리

string QueryUpdate = "update dc_caredocument " +
"SET careSeq='" + seqstr +
"',careStart='" + datetimepickeStart.Text +
"',careFinish='" + dateTimePickerEnd.Text +
"',time='" + textBoxTime.Text +
"',sympton='" + textBoxSympton.Text +
"',count='" + textBoxCount.Text +
"',injection='" + textBoxInjection.Text +
"',oral='" + textBoxOral.Text +
"',age='" + remain +
"',memo='" + textBoxMemo.Text + "' where careSeq='" + seqstr + "';";

 

삭제쿼리

string QueryDelete = "update dc_caredocument set flagYN='N' WHERE careSeq=" + seqstr;

 

조회쿼리

public void buttonSearch_Click(object sender, EventArgs e)
		{
			try
			{
				string Connect = "datasource=127.0.0.1;port=3306;database=dawoon;username=root;password=ekdnsel;Charset=utf8";
				string searchtext = textBoxSearch.Text.Trim();
				string Query32 = "SELECT number,birth,careStart FROM dawoon.dc_caredocument WHERE NUMBER = '" + comboBoxNumber.Text + "';";
				string field = "";
				string keyText = comboBoxSearch.Text;
				string flagYN = "";
				string Query2 = "";
				string Query4 = "";

				if (keyText == "개체번호") field = "number ";
				else if (keyText == "증상") field = "sympton ";

				if (checkBoxDelShow.Checked == true)
				{
					flagYN = "flagYN = 'N'";
				}
				else
				{
					flagYN = "flagYN = 'Y'";
				}
				// SELECT  accSeq, usedDate, dc_items.acount, dc_items.itemSeq, dc_items.subject, money, content, memo, dc_items.flagYN, dc_items.regDate, dc_items.issueDate, dc_items.issueID FROM dc_account LEFT JOIN dc_items ON dc_account.subject = dc_items.subject;
				// Query32 = "SELECT number,birth FROM dawoon.dc_careenroll WHERE NUMBER = '" + comboBoxNumber.Text + "';";
				Query32 = "SELECT 등록.number, 등록.birth, 문서.careStart FROM dawoon.dc_caredocument 문서 RIGHT JOIN dawoon.dc_careenroll 등록 ON (등록.number = 문서.number) WHERE 등록.number  = '" + comboBoxNumber.Text + "';";
				Query2 = "SELECT * FROM dc_caredocument WHERE " + field + "like '" + "%" + searchtext + "%" + "' AND " + flagYN;
				Query4 = "select COUNT(careSeq) cnt from dawoon.dc_caredocument WHERE flagYN ='Y';";
				//  + field + "like '%" + searchtext + "'% AND " + flagYN;
				//  " RIGHT JOIN dc_items 항목 ON (가계부.subject = 항목.subject) WHERE " + flagYN;
				MySqlConnection con = new MySqlConnection(Connect);

				con.Open();
				MySqlCommand Comm = new MySqlCommand(Query2, con);

				MySqlCommand CommNumber = new MySqlCommand(Query32, con);
				MySqlDataReader rdr = CommNumber.ExecuteReader();

				while (rdr.Read())
				{
					try
					{

						// 1. 키값을 가져와서 저장시켜야됨. 저장시키고 변수 선언
						string birthString = rdr.GetString("birth");
						string careStartString = rdr.GetString("careStart");
						string numberString = rdr.GetString("number");

						dateTimePickerBirth.Text = birthString;

						DateTime cares = new DateTime();
						DateTime birthd = new DateTime();
						TimeSpan remain = new TimeSpan();
						cares = Convert.ToDateTime(careStartString);
						birthd = Convert.ToDateTime(birthString);
						remain = cares - birthd;
						labelAge.Text = remain.Days.ToString();
					}
					catch (Exception ex)
					{
						labelAge.Text = "";
						string birthString = rdr.GetString("birth");



						dateTimePickerBirth.Text = birthString;


					}


				}



				rdr.Close();
				MySqlCommand CommNumber2 = new MySqlCommand(Query4, con);
				MySqlDataReader rdr2 = CommNumber2.ExecuteReader();
				while (rdr2.Read())
				{


					string cnt = rdr2.GetString("cnt");
					// sub.Contains(subject2)
					labelCountNb.Text = cnt;
				}
				rdr2.Close();

				MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
				MyAdapter.SelectCommand = Comm;
				DataTable dTable = new DataTable();
				MyAdapter.Fill(dTable);
				dataGridView1.DataSource = dTable;
				dataGridView1.Columns[0].Visible = false;
				dataGridView1.Columns[dataGridView1.Columns.Count - 4].Visible = false;
				dataGridView1.Columns[dataGridView1.Columns.Count - 3].Visible = false;
				dataGridView1.Columns[dataGridView1.Columns.Count - 2].Visible = false;
				dataGridView1.Columns[dataGridView1.Columns.Count - 1].Visible = false;
				dataGridView1.Columns[0].HeaderText = "고유번호";
				dataGridView1.Columns[1].HeaderText = "개체번호";
				dataGridView1.Columns[2].HeaderText = "치료시작일";
				dataGridView1.Columns[3].HeaderText = "치료종료일";
				dataGridView1.Columns[4].HeaderText = "시간";
				dataGridView1.Columns[5].HeaderText = "증상";
				dataGridView1.Columns[6].HeaderText = "횟수";
				dataGridView1.Columns[7].HeaderText = "주사처방(M)";
				dataGridView1.Columns[8].HeaderText = "경구투여";
				dataGridView1.Columns[9].HeaderText = "일령";
				dataGridView1.Columns[10].HeaderText = "생년월일";
				dataGridView1.Columns[11].HeaderText = "메모";
			}
			catch (Exception ex) { }

		}

'프로그래밍 > C#' 카테고리의 다른 글

C# join 테이블 칼럼 쓰기  (0) 2022.02.16
csv저장기능  (0) 2022.02.15
sql join query  (0) 2022.02.15
특정셀값 색깔연습  (0) 2022.02.14
아이콘 무료사이트  (0) 2022.02.14