private void print_op() { int index = comboBox1.SelectedIndex + 1; print_rec print = new print_rec(); CrystalReport2 cr = new CrystalReport2(); TextObject visit_id = (TextObject)cr.ReportDefinition.Sections["Section1"].ReportObjects["Text1"]; BoxObject box = (BoxObject)cr.ReportDefinition.Sections["Section1"].ReportObjects["Box1"]; if (index == 1) { box.FillColor = Color.WhiteSmoke; } else if (index == 2) { box.FillColor = Color.Blue; } else if (index == 3) { box.FillColor = Color.Green; } else if (index == 4) { box.FillColor = Color.Yellow; } else if (index == 5) { box.FillColor = Color.Orange; } else if (index == 6) { box.FillColor = Color.Red; } string query = "SELECT MAX(id) FROM visits"; try { MySqlConnection conn = connection_config.GetDBConnection(); conn.Open(); MySqlCommand command = new MySqlCommand(query, conn); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { visit_id.Text = (reader.GetString(0)); } conn.Close(); reader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } print.crystalReportViewer1.ReportSource = cr; print.Show(); }
public void button2_Click(object sender, EventArgs e) { string[] rec = new string[5] { "", "", "", "", "" }; string[] dos = new string[5] { "", "", "", "", "" }; foreach (DataGridViewRow row in dataGridView1.Rows) { rec[row.Index] = row.Cells[0].Value.ToString().Trim(); } foreach (DataGridViewRow row in dataGridView1.Rows) { dos[row.Index] = row.Cells[1].Value.ToString().Trim(); } string result = string.Join(",", rec.Where(s => !string.IsNullOrEmpty(s))); print_rec print = new print_rec(); if (textBox3.Text == "" || textBox6.Text == "" || textBox7.Text == "" || textBox5.Text == "") { MessageBox.Show("Uzupełnij wszystkie pola"); } else { if (dataGridView1.Rows.Count == 0) { //archiwizacja !!! query = "INSERT INTO archive SELECT NULL, dr_pesel, visit_day, pesel, hour, NULL, ward_id FROM visits WHERE pesel = '" + textBox11.Text + "' AND visit_day='" + textBox4.Text + "' AND hour='" + textBox5.Text + "'; " + "SET @id = LAST_INSERT_ID(); " + "INSERT INTO file(id, interview, examination, diagnosis, drugs, kat_id) VALUES(NULL, '" + textBox3.Text + "', '" + textBox6.Text + "', '" + textBox7.Text + "', '" + result + "', @id);" + " DELETE FROM visits WHERE pesel = '" + textBox11.Text + "' AND visit_day='" + textBox4.Text + "' AND hour='" + textBox5.Text + "';"; conn.Open(); command = new MySqlCommand(query, conn); command.ExecuteNonQuery(); MessageBox.Show("Pomyślnie zakończono wizytę"); conn.Close(); this.Close(); } else { randomizer(); CrystalReport1 cr = new CrystalReport1(); TextObject patient = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text10"]; TextObject doctor = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text11"]; TextObject drph = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text12"]; TextObject datatime = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text13"]; TextObject r1 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text14"]; TextObject r2 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text28"]; TextObject r3 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text30"]; TextObject r4 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text32"]; TextObject r5 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text34"]; TextObject d1 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text15"]; TextObject d2 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text27"]; TextObject d3 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text29"]; TextObject d4 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text31"]; TextObject d5 = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text33"]; TextObject rec_code = (TextObject)cr.ReportDefinition.Sections["Section3"].ReportObjects["Text3"]; r1.Text = rec[0]; r2.Text = rec[1]; r3.Text = rec[2]; r4.Text = rec[3]; r5.Text = rec[4]; d1.Text = dos[0]; d2.Text = dos[1]; d3.Text = dos[2]; d4.Text = dos[3]; d5.Text = dos[4]; rec_code.Text = code; patient.Text = textBox1.Text; doctor.Text = textBox2.Text; drph.Text = "+48 " + drphone; DateTime dt = DateTime.Parse(textBox5.Text); textBox5.Text = dt.ToString("HH:mm"); datatime.Text = control_date + " godz. " + control_hour; print.crystalReportViewer1.ReportSource = cr; query = "INSERT INTO archive SELECT NULL, dr_pesel, visit_day, pesel, hour, NULL, ward_id FROM visits WHERE pesel = '" + textBox11.Text + "' AND visit_day='" + textBox4.Text + "' AND hour='" + textBox5.Text + "'; " + "SET @id = LAST_INSERT_ID(); " + "UPDATE archive SET rec_code='" + code + "' WHERE id=@id;" + "INSERT INTO file(id, interview, examination, diagnosis, drugs, kat_id) VALUES(NULL, '" + textBox3.Text + "', '" + textBox6.Text + "', '" + textBox7.Text + "', '" + result + "', @id);" + " DELETE FROM visits WHERE pesel = '" + textBox11.Text + "' AND visit_day='" + textBox4.Text + "' AND hour='" + textBox5.Text + "';"; conn.Open(); command = new MySqlCommand(query, conn); command.ExecuteNonQuery(); MessageBox.Show("Pomyślnie zakończono wizytę"); conn.Close(); this.Close(); print.Show(); code = ""; } } }