Showing
2 changed files
with
73 additions
and
26 deletions
| @@ -594,6 +594,7 @@ | @@ -594,6 +594,7 @@ | ||
| 594 | this.Controls.Add(this.textBox1); | 594 | this.Controls.Add(this.textBox1); |
| 595 | this.Name = "Form3"; | 595 | this.Name = "Form3"; |
| 596 | this.Text = "Form3"; | 596 | this.Text = "Form3"; |
| 597 | + this.Load += new System.EventHandler(this.Form3_Load); | ||
| 597 | ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); | 598 | ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); |
| 598 | this.ResumeLayout(false); | 599 | this.ResumeLayout(false); |
| 599 | this.PerformLayout(); | 600 | this.PerformLayout(); |
| @@ -10,6 +10,7 @@ using System.Windows.Forms; | @@ -10,6 +10,7 @@ using System.Windows.Forms; | ||
| 10 | using MySql.Data.MySqlClient; | 10 | using MySql.Data.MySqlClient; |
| 11 | using System.Data.SqlClient; | 11 | using System.Data.SqlClient; |
| 12 | using System.IO; | 12 | using System.IO; |
| 13 | +using System.Reflection; | ||
| 13 | 14 | ||
| 14 | namespace MedicalCheckInputTool | 15 | namespace MedicalCheckInputTool |
| 15 | { | 16 | { |
| @@ -455,11 +456,11 @@ namespace MedicalCheckInputTool | @@ -455,11 +456,11 @@ namespace MedicalCheckInputTool | ||
| 455 | //行政区集計 | 456 | //行政区集計 |
| 456 | private void makeSummaryAdmin(MySqlConnection readerCon) | 457 | private void makeSummaryAdmin(MySqlConnection readerCon) |
| 457 | { | 458 | { |
| 458 | - string readQuery = "select `行政区コード`,`行政区名称`,count(行政区コード) from `1回目` where `ロット番号` = @lotNo group by `行政区コード` order by `行政区コード`"; | 459 | + string readQuery = "select `行政区コード`,`行政区名称`,count(行政区コード) from `1回目` group by `行政区コード` order by `行政区コード`"; |
| 459 | MySqlCommand readCmd = new MySqlCommand(readQuery, readerCon); | 460 | MySqlCommand readCmd = new MySqlCommand(readQuery, readerCon); |
| 460 | readCmd.Parameters.AddWithValue("lotNo", EditParam.lotNo); | 461 | readCmd.Parameters.AddWithValue("lotNo", EditParam.lotNo); |
| 461 | 462 | ||
| 462 | - string countQuery = "select count(distinct `世帯番号`) from `1回目` where `行政区コード`= @adminCode and `ロット番号` = @lotNo"; | 463 | + string countQuery = "select count(distinct `世帯番号`) from `1回目` where `行政区コード`= @adminCode"; |
| 463 | MySqlCommand countCmd = new MySqlCommand(countQuery, readerCon); | 464 | MySqlCommand countCmd = new MySqlCommand(countQuery, readerCon); |
| 464 | 465 | ||
| 465 | try | 466 | try |
| @@ -514,17 +515,26 @@ namespace MedicalCheckInputTool | @@ -514,17 +515,26 @@ namespace MedicalCheckInputTool | ||
| 514 | 515 | ||
| 515 | } | 516 | } |
| 516 | 517 | ||
| 518 | + //行政区サマリ | ||
| 519 | + public class SummaryHealthArea | ||
| 520 | + { | ||
| 521 | + public int lotNo; | ||
| 522 | + public int countAll; | ||
| 523 | + public int count; | ||
| 524 | + } | ||
| 525 | + | ||
| 517 | //保健区集計 | 526 | //保健区集計 |
| 518 | private void makeSummaryHealthArea(MySqlConnection readerCon) | 527 | private void makeSummaryHealthArea(MySqlConnection readerCon) |
| 519 | { | 528 | { |
| 520 | - string getQuery = "select `保健区` from `1回目` where `ロット番号` = @lotNo group by `保健区`"; | 529 | +// string getQuery = "select `保健区` from `1回目` where `ロット番号` = @lotNo group by `保健区`"; |
| 530 | + string getQuery = "select `保健区` from `1回目` group by `保健区`"; | ||
| 521 | MySqlCommand getCmd = new MySqlCommand(getQuery, readerCon); | 531 | MySqlCommand getCmd = new MySqlCommand(getQuery, readerCon); |
| 522 | getCmd.Parameters.AddWithValue("lotNo", EditParam.lotNo); | 532 | getCmd.Parameters.AddWithValue("lotNo", EditParam.lotNo); |
| 523 | 533 | ||
| 524 | - string readQuery = "select `行政区コード`,`行政区名称`,count(行政区コード) from `1回目` where (`ロット番号` = @lotNo) and (`保健区` = @healthArea) group by `行政区コード` order by `行政区コード`"; | 534 | + string readQuery = "select `行政区コード`,`行政区名称` from `1回目` where (`保健区` = @healthArea) group by `行政区コード` order by `行政区コード`"; |
| 525 | MySqlCommand readCmd = new MySqlCommand(readQuery, readerCon); | 535 | MySqlCommand readCmd = new MySqlCommand(readQuery, readerCon); |
| 526 | 536 | ||
| 527 | - string countQuery = "select count(distinct `世帯番号`) from `1回目` where (`行政区コード`= @adminCode) and (`ロット番号` = @lotNo) and (`保健区` = @healthArea) "; | 537 | + string countQuery = "select `ロット番号`,count(`行政区コード`),count(distinct `世帯番号`) from `1回目` where (`行政区コード`= @adminCode) and (`保健区` = @healthArea) group by `ロット番号` order by `ロット番号`"; |
| 528 | MySqlCommand countCmd = new MySqlCommand(countQuery, readerCon); | 538 | MySqlCommand countCmd = new MySqlCommand(countQuery, readerCon); |
| 529 | 539 | ||
| 530 | try | 540 | try |
| @@ -548,50 +558,78 @@ namespace MedicalCheckInputTool | @@ -548,50 +558,78 @@ namespace MedicalCheckInputTool | ||
| 548 | foreach (string ha in healthAreaList) | 558 | foreach (string ha in healthAreaList) |
| 549 | { | 559 | { |
| 550 | readCmd.Parameters.Clear(); | 560 | readCmd.Parameters.Clear(); |
| 551 | - readCmd.Parameters.AddWithValue("lotNo", EditParam.lotNo); | ||
| 552 | readCmd.Parameters.AddWithValue("healthArea", ha); | 561 | readCmd.Parameters.AddWithValue("healthArea", ha); |
| 553 | // 実行 | 562 | // 実行 |
| 554 | MySqlDataReader reader = readCmd.ExecuteReader(); | 563 | MySqlDataReader reader = readCmd.ExecuteReader(); |
| 564 | + List<string> adminCodeList = new List<string>(); | ||
| 565 | + List<string> adminNameList = new List<string>(); | ||
| 566 | + | ||
| 555 | if (!reader.HasRows) | 567 | if (!reader.HasRows) |
| 556 | { //無かった | 568 | { //無かった |
| 557 | reader.Close(); | 569 | reader.Close(); |
| 570 | + continue; | ||
| 558 | } | 571 | } |
| 559 | else | 572 | else |
| 560 | { | 573 | { |
| 561 | - List<SummaryAdmin> adminList = new List<SummaryAdmin>(); | ||
| 562 | while (reader.Read()) | 574 | while (reader.Read()) |
| 563 | { | 575 | { |
| 564 | - SummaryAdmin tmp = new SummaryAdmin(); | ||
| 565 | - tmp.adminCode = this.isDBNull(reader, "行政区コード"); | ||
| 566 | - tmp.adminName = this.isDBNull(reader, "行政区名称"); | ||
| 567 | - tmp.count = reader.GetInt16(2); | ||
| 568 | - adminList.Add(tmp); | 576 | + adminCodeList.Add(isDBNull(reader, "行政区コード")); |
| 577 | + adminNameList.Add(isDBNull(reader, "行政区名称")); | ||
| 569 | } | 578 | } |
| 570 | reader.Close(); | 579 | reader.Close(); |
| 580 | + } | ||
| 571 | 581 | ||
| 572 | - StreamWriter writer = new StreamWriter("SummaryHealthArea_" + ha + ".csv", false, System.Text.Encoding.GetEncoding("shift_jis")); //ファイルストリーム | ||
| 573 | - writer.WriteLine("行政区コード,行政区名称,件数,世帯数"); | 582 | + StreamWriter writer = new StreamWriter("SummaryHealthArea_" + ha + ".csv", false, System.Text.Encoding.GetEncoding("shift_jis")); //ファイルストリーム |
| 583 | + writer.WriteLine(",,1,,2,,3,,4,,5,"); | ||
| 584 | + writer.WriteLine("行政区コード,行政区名称,件数,世帯数,件数,世帯数,件数,世帯数,件数,世帯数,件数,世帯数"); | ||
| 574 | 585 | ||
| 575 | - foreach (SummaryAdmin sa in adminList) | 586 | + for (int i = 0; i < adminCodeList.Count; i++ ) |
| 587 | + { | ||
| 588 | + countCmd.Parameters.Clear(); | ||
| 589 | + countCmd.Parameters.AddWithValue("adminCode", adminCodeList[i]); | ||
| 590 | + countCmd.Parameters.AddWithValue("healthArea", ha); | ||
| 591 | + // 実行 | ||
| 592 | + MySqlDataReader reader2 = countCmd.ExecuteReader(); | ||
| 593 | + if (!reader2.HasRows) | ||
| 594 | + { //無かった | ||
| 595 | + reader2.Close(); | ||
| 596 | + } | ||
| 597 | + else | ||
| 576 | { | 598 | { |
| 577 | - countCmd.Parameters.Clear(); | ||
| 578 | - countCmd.Parameters.AddWithValue("adminCode", sa.adminCode); | ||
| 579 | - countCmd.Parameters.AddWithValue("lotNo", EditParam.lotNo); | ||
| 580 | - countCmd.Parameters.AddWithValue("healthArea", ha); | ||
| 581 | - MySqlDataReader reader2 = countCmd.ExecuteReader(); | 599 | + List<SummaryHealthArea> haList = new List<SummaryHealthArea>(); |
| 582 | while (reader2.Read()) | 600 | while (reader2.Read()) |
| 583 | { | 601 | { |
| 584 | - int count2 = reader2.GetInt16(0); | ||
| 585 | - | ||
| 586 | - string line = sa.adminCode + "," + sa.adminName + "," + sa.count + "," + count2; | ||
| 587 | - writer.WriteLine(line); | 602 | + SummaryHealthArea tmp = new SummaryHealthArea(); |
| 603 | + tmp.lotNo = reader2.GetInt16(0); | ||
| 604 | + tmp.countAll = reader2.GetInt16(1); | ||
| 605 | + tmp.count = reader2.GetInt16(2); | ||
| 606 | + haList.Add(tmp); | ||
| 588 | } | 607 | } |
| 589 | reader2.Close(); | 608 | reader2.Close(); |
| 609 | + | ||
| 610 | + string line = adminCodeList[i] + "," + adminNameList[i] ; | ||
| 611 | + for (int j = 0; j < 5; j++) | ||
| 612 | + { | ||
| 613 | + SummaryHealthArea hit = null; | ||
| 614 | + | ||
| 615 | + hit = haList.Find(delegate(SummaryHealthArea sha) { return sha.lotNo == j+1; }); | ||
| 616 | + if (hit != null) | ||
| 617 | + { | ||
| 618 | + line += ","; | ||
| 619 | + line += hit.countAll + "," + hit.count; | ||
| 620 | + } | ||
| 621 | + else | ||
| 622 | + { | ||
| 623 | + line += ","; | ||
| 624 | + line += ","; | ||
| 625 | + } | ||
| 626 | + } | ||
| 627 | + writer.WriteLine(line); | ||
| 590 | } | 628 | } |
| 629 | + } | ||
| 591 | 630 | ||
| 592 | - writer.Close(); | 631 | + writer.Close(); |
| 593 | 632 | ||
| 594 | - } | ||
| 595 | } | 633 | } |
| 596 | } | 634 | } |
| 597 | catch (SqlException ex) | 635 | catch (SqlException ex) |
| @@ -621,5 +659,13 @@ namespace MedicalCheckInputTool | @@ -621,5 +659,13 @@ namespace MedicalCheckInputTool | ||
| 621 | 659 | ||
| 622 | } | 660 | } |
| 623 | 661 | ||
| 662 | + private void Form3_Load(object sender, EventArgs e) | ||
| 663 | + { | ||
| 664 | + typeof(DataGridView). | ||
| 665 | + GetProperty("DoubleBuffered", | ||
| 666 | + BindingFlags.Instance | BindingFlags.NonPublic). | ||
| 667 | + SetValue(dataGridView1, true, null); | ||
| 668 | + } | ||
| 669 | + | ||
| 624 | } | 670 | } |
| 625 | } | 671 | } |
Please
register
or
login
to post a comment