private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { selectedRow = e.RowIndex; DataGridViewRow row = dataGridView2.Rows[selectedRow]; /* textBox4.Text = row.Cells[0].Value.ToString(); * textBox2.Text = row.Cells[1].Value.ToString(); * textBox3.Text = row.Cells[2].Value.ToString();*/ int A = Convert.ToInt32(row.Cells[2].Value.ToString()); string name_medi = row.Cells[1].Value.ToString(); conn.Open(); string query = ("Update medicine_use set medi_use_status = 3 from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where treatment_record.treatr_id = '" + txttrea.Text + "' AND medical.medi_name = '" + name_medi + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); conn.Close(); clinic_pharmacist_service m3 = new clinic_pharmacist_service(); m3.Show(); clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); clnlog.Close(); Visible = false; } catch (Exception) { } }
private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { conn.Open(); selectedRow = e.RowIndex; DataGridViewRow row = dataGridView3.Rows[selectedRow]; int tre_id = Convert.ToInt32(row.Cells[0].Value.ToString()); Queue <int> collection = new Queue <int>(); string query = ("select count(*) from treatment_record inner join appointment on appointment.opd_id = treatment_record.opd_id where treatr_id = '" + tre_id + "' AND status_approve = 1"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int app_count = (int)cmd.ExecuteScalar(); if (app_count == 1) { MessageBox.Show("มีข้อมูลการนัดหมาย"); } else { query = ("select count(treatr_medi_queue) from treatment_record where treatr_status = 3"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int queue_ry = (int)cmd.ExecuteScalar(); int queue = queue_ry + 1; query = ("Update treatment_record set treatr_medi_queue = '" + queue + "',treatr_status = 3 where treatr_id = '" + tre_id + "'"); // cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); conn.Close(); clinic_pharmacist_service m3 = new clinic_pharmacist_service(); m3.Show(); clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); clnlog.Close(); Visible = false; MessageBox.Show("คิวการจ่ายยาที่ " + queue); } } catch (Exception) { } // textBox1.Text = row.Cells[0].Value.ToString(); // textBox2.Text = row.Cells[1].Value.ToString(); // textBox3.Text = row.Cells[2].Value.ToString(); // txttrea.Text = row.Cells[0].Value.ToString(); // textBox4.Text = row.Cells[0].Value.ToString(); }
private void button1_Click(object sender, EventArgs e) { try { conn.Open(); /* string query = ("select count(*) from treatment_record inner join appointment on appointment.opd_id = treatment_record.opd_id where treatr_id = '"+textBox4.Text+"' AND status_approve = 1"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * int app_count = (int)cmd.ExecuteScalar(); * if(app_count == 1) * { * MessageBox.Show("มีการนัดหมาย"); * * int q = Convert.ToInt32(lblqueue.Text); * int p = q + 1; * lblqueue.Text = ""+p; * * query = ("select treatment_record.treatr_id from opd inner join treatment_record on treatment_record.opd_id = opd.opd_id where treatr_status = 2 AND treatment_record.treatr_medi_queue = '"+p+"'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * sdr = cmd.ExecuteReader(); * if (sdr.Read()) * { * txttrea.Text = (sdr["treatr_id"].ToString()); * textBox4.Text = ""; * textBox2.Text = ""; * textBox3.Text = ""; * } * * * * } * else * {*/ /* query = ("select count(*) from opd inner join treatment_record on treatment_record.opd_id = opd.opd_id inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where medicine_use.medi_use_status = 2 AND treatment_record.treatr_id = '" + txttrea.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * int count_app = (int)cmd.ExecuteScalar(); * if (count_app < 1) * {*/ string query = ("Select count(*) from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where treatment_record.treatr_status = 3 AND treatment_record.treatr_id = '" + txttrea.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int count_select = (int)cmd.ExecuteScalar(); if (count_select < 1) { MessageBox.Show("ไม่มีข้อมูลการสั่งยา"); } else { string today = DateTime.Now.ToString("yyyy-MM-dd", new CultureInfo("th-TH")); query = ("select count(*) from medicine_use inner join medical on medical.medi_id = medicine_use.medi_id inner join treatment_record on treatment_record.treatr_id = medicine_use.treatr_id where medicine_use.medi_use_status = 3 AND treatment_record.treatr_id = '" + txttrea.Text + "' AND medicine_use.medi_use_date = '" + today + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int count_pay = (int)cmd.ExecuteScalar(); if (count_pay >= 1) { query = ("Update treatment_record set treatr_status = 0 where treatr_id = '" + txttrea.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("Update queue_visit_record set qvr_status = 6 where opd_id = '" + txtopdid.Text + "' AND qvr_date = '" + today + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("Update medicine_use set medi_use_status = 0 from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where medicine_use.medi_use_status = 2 AND treatment_record.treatr_id = '" + txttrea.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); clinic_pharmacist_service m3 = new clinic_pharmacist_service(); m3.Show(); clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); clnlog.Close(); Visible = false; MessageBox.Show("จัดเก็บใบสั่งยาเรียบร้อย"); } else { MessageBox.Show("คุณยังไม่ได้จ่ายยา"); } } /* } * else * { * // query = ("Select count(*) from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where medicine_use.medi_use_status = 2 AND treatment_record.treatr_id = '" + txttrea.Text + "' AND medical.medi_name = '" + textBox2.Text + "'"); * query = ("Select count(*) from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where medicine_use.medi_use_status = 2 AND treatment_record.treatr_id = '" + txttrea.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * int count_select = (int)cmd.ExecuteScalar(); * if (count_select == 1) * {*/ /* query = ("select medi_qty,medi_min from medical where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * sdr = cmd.ExecuteReader(); * * if (sdr.Read()) * { * int nummed = Convert.ToInt32(sdr["medi_qty"].ToString()); * int min = Convert.ToInt32(sdr["medi_min"].ToString());*/ // int cut_stock = nummed - Convert.ToInt32(textBox3.Text); // query = ("Update medicine_use set medi_use_status = 0 from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where medicine_use.medi_use_status = 2 AND treatment_record.treatr_id = '" + textBox4.Text + "' AND medical.medi_name = '" + textBox2.Text + "'"); /* query = ("Update medicine_use set medi_use_status = 0 from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where medicine_use.medi_use_status = 2 AND treatment_record.treatr_id = '" + txttrea.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * * * clinic_pharmacist_service m3 = new clinic_pharmacist_service(); * m3.Show(); * clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); * clnlog.Close(); * Visible = false; * * * MessageBox.Show("จ่ายยาเรียบร้อย");*/ /* * if (nummed < min) * { * MessageBox.Show("ยาใกล้หมดคลังแล้ว"); * query = ("Update medical set medi_qty = '" + nummed + "' where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * * * * query = ("Update medicine_use set medi_use_status = 0 from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where medicine_use.medi_use_status = 2 AND treatment_record.treatr_id = '" + textBox4.Text + "' AND medical.medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * * * clinic_pharmacist_service m3 = new clinic_pharmacist_service(); * m3.Show(); * clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); * clnlog.Close(); * Visible = false; * * * MessageBox.Show("จ่ายยาเรียบร้อย"); * * * * * * * * * * * * } * else if (nummed < 0) * { * MessageBox.Show("ยาหมดคลังแล้ว"); * * } * else if (nummed > min) * { * query = ("Update medical set medi_qty = '" + nummed + "' where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * * * query = ("Update medicine_use set medi_use_status = 0 from treatment_record inner join medicine_use on medicine_use.treatr_id = treatment_record.treatr_id inner join medical on medical.medi_id = medicine_use.medi_id where medicine_use.medi_use_status = 2 AND treatment_record.treatr_id = '" + textBox4.Text + "' AND medical.medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * clinic_pharmacist_service m3 = new clinic_pharmacist_service(); * m3.Show(); * clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); * clnlog.Close(); * Visible = false; * * * MessageBox.Show("จ่ายยาเรียบร้อย"); * * * * * * * * * * }else * { * MessageBox.Show("ttttttttttt"); * } * * * * * * * } */ /* } * else * { * * MessageBox.Show("กรุณาเลือกยาที่จ่าย"); * textBox4.Text = ""; * textBox2.Text = ""; * textBox3.Text = ""; * } */ /* }else * { * MessageBox.Show("กรุณาเลือกยาที่จ่าย555555555"); * textBox4.Text = ""; * textBox2.Text = ""; * textBox3.Text = ""; * }*/ // } /* * * string query = ("select medi_qty from medical where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * sdr = cmd.ExecuteReader(); * * if (sdr.Read()) * { * int nummed = Convert.ToInt32(sdr["medi_qty"].ToString()); * int cut_stock = nummed - Convert.ToInt32(textBox3.Text); * if (nummed < 5) * { * MessageBox.Show("ยาใกล้หมดคลังแล้ว"); * query = ("Update medical set medi_qty = '" + cut_stock + "' where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * query = ("UPDATE medicine_use SET medi_use_status = 0 where treatr_id = '" + textBox4.Text + "' AND medi_use_id = '" + textBox1.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * clinic_pharmacist_service m3 = new clinic_pharmacist_service(); * m3.Show(); * clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); * clnlog.Close(); * Visible = false; * * * MessageBox.Show("จ่ายยาเรียบร้อย"); * * } * else if (nummed < 0) * { * MessageBox.Show("ยาหมดคลังแล้ว"); * * } * else if (nummed > 5) * { * query = ("Update medical set medi_qty = '" + cut_stock + "' where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * query = ("UPDATE medicine_use SET medi_use_status = 0 where treatr_id = '" + textBox4.Text + "' AND medi_use_id = '" + textBox1.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * clinic_pharmacist_service m3 = new clinic_pharmacist_service(); * m3.Show(); * clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); * clnlog.Close(); * Visible = false; * * * MessageBox.Show("จ่ายยาเรียบร้อย"); * * * } * * * * * * } */ conn.Close(); } catch (Exception ex) { // MessageBox.Show("มีข้อผิดพลาด"); // MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OKCancel); } }
private void button1_Click(object sender, EventArgs e) { conn.Open(); string query = ("select count(*) from treatment_record inner join appointment on appointment.opd_id = treatment_record.opd_id where treatr_id = '" + textBox4.Text + "' AND status_approve = 1"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int app_count = (int)cmd.ExecuteScalar(); if (app_count == 1) { MessageBox.Show("มีการนัดหมาย"); } else { query = ("select medi_qty from medical where medi_name = '" + textBox2.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); sdr = cmd.ExecuteReader(); if (sdr.Read()) { int nummed = Convert.ToInt32(sdr["medi_qty"].ToString()); int cut_stock = nummed - Convert.ToInt32(textBox3.Text); if (nummed < 5) { MessageBox.Show("ยาใกล้หมดคลังแล้ว"); query = ("Update medical set medi_qty = '" + cut_stock + "' where medi_name = '" + textBox2.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("UPDATE medicine_use SET medi_use_status = 0 where treatr_id = '" + textBox4.Text + "' AND medi_use_id = '" + textBox1.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); clinic_pharmacist_service m3 = new clinic_pharmacist_service(); m3.Show(); clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); clnlog.Close(); Visible = false; MessageBox.Show("จ่ายยาเรียบร้อย"); } else if (nummed < 0) { MessageBox.Show("ยาหมดคลังแล้ว"); } else if (nummed > 5) { query = ("Update medical set medi_qty = '" + cut_stock + "' where medi_name = '" + textBox2.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("UPDATE medicine_use SET medi_use_status = 0 where treatr_id = '" + textBox4.Text + "' AND medi_use_id = '" + textBox1.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); clinic_pharmacist_service m3 = new clinic_pharmacist_service(); m3.Show(); clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); clnlog.Close(); Visible = false; MessageBox.Show("จ่ายยาเรียบร้อย"); } } } /* * * string query = ("select medi_qty from medical where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * sdr = cmd.ExecuteReader(); * * if (sdr.Read()) * { * int nummed = Convert.ToInt32(sdr["medi_qty"].ToString()); * int cut_stock = nummed - Convert.ToInt32(textBox3.Text); * if (nummed < 5) * { * MessageBox.Show("ยาใกล้หมดคลังแล้ว"); * query = ("Update medical set medi_qty = '" + cut_stock + "' where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * query = ("UPDATE medicine_use SET medi_use_status = 0 where treatr_id = '" + textBox4.Text + "' AND medi_use_id = '" + textBox1.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * clinic_pharmacist_service m3 = new clinic_pharmacist_service(); * m3.Show(); * clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); * clnlog.Close(); * Visible = false; * * * MessageBox.Show("จ่ายยาเรียบร้อย"); * * } * else if (nummed < 0) * { * MessageBox.Show("ยาหมดคลังแล้ว"); * * } * else if (nummed > 5) * { * query = ("Update medical set medi_qty = '" + cut_stock + "' where medi_name = '" + textBox2.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * query = ("UPDATE medicine_use SET medi_use_status = 0 where treatr_id = '" + textBox4.Text + "' AND medi_use_id = '" + textBox1.Text + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * sda.Fill(dt); * * clinic_pharmacist_service m3 = new clinic_pharmacist_service(); * m3.Show(); * clinic_pharmacist_service clnlog = new clinic_pharmacist_service(); * clnlog.Close(); * Visible = false; * * * MessageBox.Show("จ่ายยาเรียบร้อย"); * * * } * * * * * * * } */ conn.Close(); }