From ebaaaaaffd4b6857802e0b413898c61eb4f6df42 Mon Sep 17 00:00:00 2001 From: Dag Robole Date: Tue, 11 Jun 2019 07:42:13 +0200 Subject: [PATCH] Improved sample merge --- FormMain.Designer.cs | 82 ++++++------ FormMain.cs | 23 ++-- FormMain.resx | 90 +------------ FormSampleMerge.Designer.cs | 244 ++++++++++++++++++++++++++++++++---- FormSampleMerge.cs | 198 ++++++++++++++++++++++++++--- 5 files changed, 456 insertions(+), 181 deletions(-) diff --git a/FormMain.Designer.cs b/FormMain.Designer.cs index 7c0e96a..9055698 100644 --- a/FormMain.Designer.cs +++ b/FormMain.Designer.cs @@ -4150,7 +4150,7 @@ private void InitializeComponent() this.label38.Dock = System.Windows.Forms.DockStyle.Fill; this.label38.Location = new System.Drawing.Point(3, 60); this.label38.Name = "label38"; - this.label38.Size = new System.Drawing.Size(112, 30); + this.label38.Size = new System.Drawing.Size(113, 30); this.label38.TabIndex = 0; this.label38.Text = "Laboratory"; this.label38.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4160,7 +4160,7 @@ private void InitializeComponent() this.label39.Dock = System.Windows.Forms.DockStyle.Fill; this.label39.Location = new System.Drawing.Point(3, 150); this.label39.Name = "label39"; - this.label39.Size = new System.Drawing.Size(112, 30); + this.label39.Size = new System.Drawing.Size(113, 30); this.label39.TabIndex = 1; this.label39.Text = "Deadline"; this.label39.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4170,7 +4170,7 @@ private void InitializeComponent() this.label40.Dock = System.Windows.Forms.DockStyle.Fill; this.label40.Location = new System.Drawing.Point(3, 180); this.label40.Name = "label40"; - this.label40.Size = new System.Drawing.Size(112, 30); + this.label40.Size = new System.Drawing.Size(113, 30); this.label40.TabIndex = 2; this.label40.Text = "Req. sigma"; this.label40.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4180,7 +4180,7 @@ private void InitializeComponent() this.label42.Dock = System.Windows.Forms.DockStyle.Fill; this.label42.Location = new System.Drawing.Point(3, 90); this.label42.Name = "label42"; - this.label42.Size = new System.Drawing.Size(112, 30); + this.label42.Size = new System.Drawing.Size(113, 30); this.label42.TabIndex = 5; this.label42.Text = "Responsible"; this.label42.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4191,9 +4191,9 @@ private void InitializeComponent() this.cboxOrderResponsible.Dock = System.Windows.Forms.DockStyle.Fill; this.cboxOrderResponsible.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboxOrderResponsible.FormattingEnabled = true; - this.cboxOrderResponsible.Location = new System.Drawing.Point(121, 93); + this.cboxOrderResponsible.Location = new System.Drawing.Point(122, 93); this.cboxOrderResponsible.Name = "cboxOrderResponsible"; - this.cboxOrderResponsible.Size = new System.Drawing.Size(233, 23); + this.cboxOrderResponsible.Size = new System.Drawing.Size(232, 23); this.cboxOrderResponsible.TabIndex = 2; this.cboxOrderResponsible.ValueMember = "Id"; this.cboxOrderResponsible.SelectedIndexChanged += new System.EventHandler(this.cboxOrderResponsible_SelectedIndexChanged); @@ -4205,9 +4205,9 @@ private void InitializeComponent() this.cboxOrderLaboratory.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboxOrderLaboratory.Enabled = false; this.cboxOrderLaboratory.FormattingEnabled = true; - this.cboxOrderLaboratory.Location = new System.Drawing.Point(121, 63); + this.cboxOrderLaboratory.Location = new System.Drawing.Point(122, 63); this.cboxOrderLaboratory.Name = "cboxOrderLaboratory"; - this.cboxOrderLaboratory.Size = new System.Drawing.Size(233, 23); + this.cboxOrderLaboratory.Size = new System.Drawing.Size(232, 23); this.cboxOrderLaboratory.TabIndex = 1; this.cboxOrderLaboratory.ValueMember = "Id"; this.cboxOrderLaboratory.SelectedIndexChanged += new System.EventHandler(this.cboxOrderLaboratory_SelectedIndexChanged); @@ -4223,9 +4223,9 @@ private void InitializeComponent() "1", "2", "3"}); - this.cboxOrderRequestedSigma.Location = new System.Drawing.Point(121, 183); + this.cboxOrderRequestedSigma.Location = new System.Drawing.Point(122, 183); this.cboxOrderRequestedSigma.Name = "cboxOrderRequestedSigma"; - this.cboxOrderRequestedSigma.Size = new System.Drawing.Size(233, 23); + this.cboxOrderRequestedSigma.Size = new System.Drawing.Size(232, 23); this.cboxOrderRequestedSigma.TabIndex = 4; this.cboxOrderRequestedSigma.ValueMember = "Id"; this.cboxOrderRequestedSigma.SelectedIndexChanged += new System.EventHandler(this.cboxOrderRequestedSigma_SelectedIndexChanged); @@ -4235,7 +4235,7 @@ private void InitializeComponent() this.label4.Dock = System.Windows.Forms.DockStyle.Fill; this.label4.Location = new System.Drawing.Point(3, 0); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(112, 30); + this.label4.Size = new System.Drawing.Size(113, 30); this.label4.TabIndex = 10; this.label4.Text = "Name"; this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4243,10 +4243,10 @@ private void InitializeComponent() // tbOrderName // this.tbOrderName.Dock = System.Windows.Forms.DockStyle.Fill; - this.tbOrderName.Location = new System.Drawing.Point(121, 3); + this.tbOrderName.Location = new System.Drawing.Point(122, 3); this.tbOrderName.Name = "tbOrderName"; this.tbOrderName.ReadOnly = true; - this.tbOrderName.Size = new System.Drawing.Size(233, 21); + this.tbOrderName.Size = new System.Drawing.Size(232, 21); this.tbOrderName.TabIndex = 0; // // panel30 @@ -4255,9 +4255,9 @@ private void InitializeComponent() this.panel30.Controls.Add(this.btnOrderClearDeadline); this.panel30.Controls.Add(this.btnOrderSelectDeadline); this.panel30.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel30.Location = new System.Drawing.Point(121, 153); + this.panel30.Location = new System.Drawing.Point(122, 153); this.panel30.Name = "panel30"; - this.panel30.Size = new System.Drawing.Size(233, 24); + this.panel30.Size = new System.Drawing.Size(232, 24); this.panel30.TabIndex = 14; // // tbOrderDeadline @@ -4267,7 +4267,7 @@ private void InitializeComponent() this.tbOrderDeadline.Location = new System.Drawing.Point(0, 0); this.tbOrderDeadline.Name = "tbOrderDeadline"; this.tbOrderDeadline.ReadOnly = true; - this.tbOrderDeadline.Size = new System.Drawing.Size(185, 21); + this.tbOrderDeadline.Size = new System.Drawing.Size(184, 21); this.tbOrderDeadline.TabIndex = 1; // // btnOrderClearDeadline @@ -4275,7 +4275,7 @@ private void InitializeComponent() this.btnOrderClearDeadline.BackgroundImage = global::DSA_lims.Properties.Resources.clear_16; this.btnOrderClearDeadline.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btnOrderClearDeadline.Dock = System.Windows.Forms.DockStyle.Right; - this.btnOrderClearDeadline.Location = new System.Drawing.Point(185, 0); + this.btnOrderClearDeadline.Location = new System.Drawing.Point(184, 0); this.btnOrderClearDeadline.Name = "btnOrderClearDeadline"; this.btnOrderClearDeadline.Size = new System.Drawing.Size(24, 24); this.btnOrderClearDeadline.TabIndex = 3; @@ -4288,7 +4288,7 @@ private void InitializeComponent() this.btnOrderSelectDeadline.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btnOrderSelectDeadline.Dock = System.Windows.Forms.DockStyle.Right; this.btnOrderSelectDeadline.InitialImage = null; - this.btnOrderSelectDeadline.Location = new System.Drawing.Point(209, 0); + this.btnOrderSelectDeadline.Location = new System.Drawing.Point(208, 0); this.btnOrderSelectDeadline.Name = "btnOrderSelectDeadline"; this.btnOrderSelectDeadline.Size = new System.Drawing.Size(24, 24); this.btnOrderSelectDeadline.TabIndex = 2; @@ -4301,7 +4301,7 @@ private void InitializeComponent() this.label41.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); this.label41.Location = new System.Drawing.Point(3, 240); this.label41.Name = "label41"; - this.label41.Size = new System.Drawing.Size(112, 120); + this.label41.Size = new System.Drawing.Size(113, 120); this.label41.TabIndex = 3; this.label41.Text = "Content comment"; this.label41.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4309,12 +4309,12 @@ private void InitializeComponent() // tbOrderContentComment // this.tbOrderContentComment.Dock = System.Windows.Forms.DockStyle.Fill; - this.tbOrderContentComment.Location = new System.Drawing.Point(121, 243); + this.tbOrderContentComment.Location = new System.Drawing.Point(122, 243); this.tbOrderContentComment.MaxLength = 1000; this.tbOrderContentComment.Multiline = true; this.tbOrderContentComment.Name = "tbOrderContentComment"; this.tbOrderContentComment.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.tbOrderContentComment.Size = new System.Drawing.Size(233, 114); + this.tbOrderContentComment.Size = new System.Drawing.Size(232, 114); this.tbOrderContentComment.TabIndex = 6; this.tbOrderContentComment.TextChanged += new System.EventHandler(this.tbOrderContentComment_TextChanged); // @@ -4323,7 +4323,7 @@ private void InitializeComponent() this.label34.Dock = System.Windows.Forms.DockStyle.Fill; this.label34.Location = new System.Drawing.Point(3, 120); this.label34.Name = "label34"; - this.label34.Size = new System.Drawing.Size(112, 30); + this.label34.Size = new System.Drawing.Size(113, 30); this.label34.TabIndex = 16; this.label34.Text = "Customer"; this.label34.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4333,9 +4333,9 @@ private void InitializeComponent() this.panel3.Controls.Add(this.tbOrderCustomer); this.panel3.Controls.Add(this.btnOrderSelectCustomer); this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel3.Location = new System.Drawing.Point(121, 123); + this.panel3.Location = new System.Drawing.Point(122, 123); this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(233, 24); + this.panel3.Size = new System.Drawing.Size(232, 24); this.panel3.TabIndex = 17; // // tbOrderCustomer @@ -4344,7 +4344,7 @@ private void InitializeComponent() this.tbOrderCustomer.Location = new System.Drawing.Point(0, 0); this.tbOrderCustomer.Name = "tbOrderCustomer"; this.tbOrderCustomer.ReadOnly = true; - this.tbOrderCustomer.Size = new System.Drawing.Size(209, 21); + this.tbOrderCustomer.Size = new System.Drawing.Size(208, 21); this.tbOrderCustomer.TabIndex = 3; // // btnOrderSelectCustomer @@ -4352,7 +4352,7 @@ private void InitializeComponent() this.btnOrderSelectCustomer.BackgroundImage = global::DSA_lims.Properties.Resources.user_16; this.btnOrderSelectCustomer.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.btnOrderSelectCustomer.Dock = System.Windows.Forms.DockStyle.Right; - this.btnOrderSelectCustomer.Location = new System.Drawing.Point(209, 0); + this.btnOrderSelectCustomer.Location = new System.Drawing.Point(208, 0); this.btnOrderSelectCustomer.Name = "btnOrderSelectCustomer"; this.btnOrderSelectCustomer.Size = new System.Drawing.Size(24, 24); this.btnOrderSelectCustomer.TabIndex = 0; @@ -4364,7 +4364,7 @@ private void InitializeComponent() this.label35.Dock = System.Windows.Forms.DockStyle.Fill; this.label35.Location = new System.Drawing.Point(3, 210); this.label35.Name = "label35"; - this.label35.Size = new System.Drawing.Size(112, 30); + this.label35.Size = new System.Drawing.Size(113, 30); this.label35.TabIndex = 18; this.label35.Text = "Req. sigma MDA"; this.label35.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4375,9 +4375,9 @@ private void InitializeComponent() this.cboxOrderRequestedSigmaMDA.Dock = System.Windows.Forms.DockStyle.Fill; this.cboxOrderRequestedSigmaMDA.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboxOrderRequestedSigmaMDA.FormattingEnabled = true; - this.cboxOrderRequestedSigmaMDA.Location = new System.Drawing.Point(121, 213); + this.cboxOrderRequestedSigmaMDA.Location = new System.Drawing.Point(122, 213); this.cboxOrderRequestedSigmaMDA.Name = "cboxOrderRequestedSigmaMDA"; - this.cboxOrderRequestedSigmaMDA.Size = new System.Drawing.Size(233, 23); + this.cboxOrderRequestedSigmaMDA.Size = new System.Drawing.Size(232, 23); this.cboxOrderRequestedSigmaMDA.TabIndex = 5; this.cboxOrderRequestedSigmaMDA.ValueMember = "Id"; this.cboxOrderRequestedSigmaMDA.SelectedIndexChanged += new System.EventHandler(this.cboxOrderRequestedSigmaMDA_SelectedIndexChanged); @@ -4387,7 +4387,7 @@ private void InitializeComponent() this.label62.Dock = System.Windows.Forms.DockStyle.Fill; this.label62.Location = new System.Drawing.Point(3, 30); this.label62.Name = "label62"; - this.label62.Size = new System.Drawing.Size(112, 30); + this.label62.Size = new System.Drawing.Size(113, 30); this.label62.TabIndex = 19; this.label62.Text = "Description"; this.label62.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4395,10 +4395,10 @@ private void InitializeComponent() // tbOrderDescription // this.tbOrderDescription.Dock = System.Windows.Forms.DockStyle.Fill; - this.tbOrderDescription.Location = new System.Drawing.Point(121, 33); + this.tbOrderDescription.Location = new System.Drawing.Point(122, 33); this.tbOrderDescription.MaxLength = 80; this.tbOrderDescription.Name = "tbOrderDescription"; - this.tbOrderDescription.Size = new System.Drawing.Size(233, 21); + this.tbOrderDescription.Size = new System.Drawing.Size(232, 21); this.tbOrderDescription.TabIndex = 20; this.tbOrderDescription.TextChanged += new System.EventHandler(this.tbOrderDescription_TextChanged); // @@ -10262,9 +10262,9 @@ private void InitializeComponent() this.tabPrepAnalPreps.BackColor = System.Drawing.SystemColors.ButtonFace; this.tabPrepAnalPreps.Controls.Add(this.panel10); this.tabPrepAnalPreps.Controls.Add(this.splitContainer3); - this.tabPrepAnalPreps.Location = new System.Drawing.Point(4, 24); + this.tabPrepAnalPreps.Location = new System.Drawing.Point(4, 22); this.tabPrepAnalPreps.Name = "tabPrepAnalPreps"; - this.tabPrepAnalPreps.Size = new System.Drawing.Size(674, 571); + this.tabPrepAnalPreps.Size = new System.Drawing.Size(674, 573); this.tabPrepAnalPreps.TabIndex = 3; this.tabPrepAnalPreps.Text = "Preparations"; // @@ -10275,7 +10275,7 @@ private void InitializeComponent() this.panel10.Controls.Add(this.btnPrepAnalPrepUpdate); this.panel10.Controls.Add(this.label23); this.panel10.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel10.Location = new System.Drawing.Point(0, 545); + this.panel10.Location = new System.Drawing.Point(0, 547); this.panel10.Name = "panel10"; this.panel10.Size = new System.Drawing.Size(674, 26); this.panel10.TabIndex = 1; @@ -10765,9 +10765,9 @@ private void InitializeComponent() this.tabPrepAnalAnalysis.BackColor = System.Drawing.SystemColors.ButtonFace; this.tabPrepAnalAnalysis.Controls.Add(this.panel76); this.tabPrepAnalAnalysis.Controls.Add(this.panel63); - this.tabPrepAnalAnalysis.Location = new System.Drawing.Point(4, 24); + this.tabPrepAnalAnalysis.Location = new System.Drawing.Point(4, 22); this.tabPrepAnalAnalysis.Name = "tabPrepAnalAnalysis"; - this.tabPrepAnalAnalysis.Size = new System.Drawing.Size(674, 571); + this.tabPrepAnalAnalysis.Size = new System.Drawing.Size(674, 573); this.tabPrepAnalAnalysis.TabIndex = 4; this.tabPrepAnalAnalysis.Text = "Analyses"; // @@ -10778,7 +10778,7 @@ private void InitializeComponent() this.panel76.Dock = System.Windows.Forms.DockStyle.Fill; this.panel76.Location = new System.Drawing.Point(0, 246); this.panel76.Name = "panel76"; - this.panel76.Size = new System.Drawing.Size(674, 325); + this.panel76.Size = new System.Drawing.Size(674, 327); this.panel76.TabIndex = 3; // // panel9 @@ -10788,7 +10788,7 @@ private void InitializeComponent() this.panel9.Dock = System.Windows.Forms.DockStyle.Fill; this.panel9.Location = new System.Drawing.Point(0, 0); this.panel9.Name = "panel9"; - this.panel9.Size = new System.Drawing.Size(674, 299); + this.panel9.Size = new System.Drawing.Size(674, 301); this.panel9.TabIndex = 4; // // gridPrepAnalResults @@ -10806,7 +10806,7 @@ private void InitializeComponent() this.gridPrepAnalResults.ReadOnly = true; this.gridPrepAnalResults.RowHeadersVisible = false; this.gridPrepAnalResults.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.gridPrepAnalResults.Size = new System.Drawing.Size(674, 274); + this.gridPrepAnalResults.Size = new System.Drawing.Size(674, 276); this.gridPrepAnalResults.TabIndex = 0; // // toolsSampleResRes @@ -10878,7 +10878,7 @@ private void InitializeComponent() this.panel14.Controls.Add(this.btnPrepAnalAnalDiscard); this.panel14.Controls.Add(this.btnPrepAnalAnalUpdate); this.panel14.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel14.Location = new System.Drawing.Point(0, 299); + this.panel14.Location = new System.Drawing.Point(0, 301); this.panel14.Name = "panel14"; this.panel14.Size = new System.Drawing.Size(674, 26); this.panel14.TabIndex = 5; diff --git a/FormMain.cs b/FormMain.cs index 913b009..b6d2fbf 100644 --- a/FormMain.cs +++ b/FormMain.cs @@ -2027,7 +2027,11 @@ private void cboxSampleSampleType_SelectedIndexChanged(object sender, EventArgs Guid sampleTypeId = Utils.MakeGuid(cboxSampleSampleType.SelectedValue); TreeNode[] tnodes = treeSampleTypes.Nodes.Find(sampleTypeId.ToString(), true); if (tnodes.Length < 1) + { + Common.Log.Error("Unable to find sample type with id: " + sampleTypeId); + MessageBox.Show("Error: Unable to find sample type with id: " + sampleTypeId); return; + } SqlConnection conn = null; try @@ -2501,19 +2505,9 @@ private void miSamplesMerge_Click(object sender, EventArgs e) return; } - List sampleIds = new List(); - HashSet uniqueTypes = new HashSet(); + List sampleIds = new List(); foreach(DataGridViewRow row in gridSamples.SelectedRows) - { sampleIds.Add(Utils.MakeGuid(row.Cells["id"].Value)); - uniqueTypes.Add(row.Cells["sample_type_name"].Value.ToString()); - } - - if(uniqueTypes.Count > 1) - { - MessageBox.Show("You can not merge different sample types"); - return; - } var sampleIdsArr = from item in sampleIds select "'" + item + "'"; string sampleIdsCsv = string.Join(",", sampleIdsArr); @@ -2521,7 +2515,8 @@ private void miSamplesMerge_Click(object sender, EventArgs e) SqlConnection conn = null; try { - conn = DB.OpenConnection(); + conn = DB.OpenConnection(); + int mergeTest = Convert.ToInt32(DB.GetScalar(conn, null, "select count(transform_to_id) from sample where id in (" + sampleIdsCsv + ")", CommandType.Text)); if(mergeTest > 0) { @@ -2530,8 +2525,6 @@ private void miSamplesMerge_Click(object sender, EventArgs e) } Func nCheck = field => Convert.ToInt32(DB.GetScalar(conn, null, "select count(distinct(" + field + ")) from sample where id in(" + sampleIdsCsv + ")", CommandType.Text)); - - // FIXME: Must select new sample type if ((nCheck("laboratory_id") & nCheck("project_sub_id")) != 1) { MessageBox.Show("All samples to be merged must have the same laboratory and project"); @@ -2549,7 +2542,7 @@ private void miSamplesMerge_Click(object sender, EventArgs e) conn?.Close(); } - FormSampleMerge form = new FormSampleMerge(sampleIdsCsv); + FormSampleMerge form = new FormSampleMerge(sampleIds, treeSampleTypes); if (form.ShowDialog() != DialogResult.OK) return; diff --git a/FormMain.resx b/FormMain.resx index 85ee0ae..392237c 100644 --- a/FormMain.resx +++ b/FormMain.resx @@ -123,36 +123,12 @@ 402, 17 - - 882, 56 - - - 565, 95 - - - 652, 17 - - - 17, 212 - - - 776, 17 - - - 227, 212 - 227, 212 1126, 17 - - 1126, 17 - - - 17, 56 - 17, 56 @@ -168,36 +144,18 @@ 269, 56 - - 553, 56 - - - 982, 17 - 982, 17 565, 251 - - 565, 251 - - - 789, 251 - 789, 251 732, 56 - - 732, 56 - - - 17, 95 - 17, 95 @@ -216,27 +174,15 @@ 784, 134 - - 784, 134 - 486, 17 - - 486, 17 - - - 17, 251 - 17, 251 463, 251 - - 463, 251 - @@ -322,15 +268,15 @@ 122, 212 - - 122, 212 - 565, 95 652, 17 + + 17, 212 + 754, 173 @@ -400,48 +346,24 @@ 188, 173 - - 188, 173 - - - 913, 212 - 913, 212 351, 173 - - 351, 173 - - - 1280, 212 - 1280, 212 901, 251 - - 901, 251 - 964, 173 808, 212 - - 808, 212 - - - 1257, 173 - - - 1069, 173 - 1257, 173 @@ -451,18 +373,12 @@ 651, 212 - - 651, 212 - 339, 212 444, 212 - - 444, 212 - 904, 17 diff --git a/FormSampleMerge.Designer.cs b/FormSampleMerge.Designer.cs index d9856b4..683ae44 100644 --- a/FormSampleMerge.Designer.cs +++ b/FormSampleMerge.Designer.cs @@ -33,11 +33,28 @@ private void InitializeComponent() this.btnCancel = new System.Windows.Forms.Button(); this.btnOk = new System.Windows.Forms.Button(); this.gridSamples = new System.Windows.Forms.DataGridView(); - this.panel2 = new System.Windows.Forms.Panel(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.label2 = new System.Windows.Forms.Label(); + this.cboxSampleType = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.cboxSampleComponent = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.tbComment = new System.Windows.Forms.TextBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.dtSamplingTime = new System.Windows.Forms.DateTimePicker(); + this.dtSamplingDate = new System.Windows.Forms.DateTimePicker(); + this.panel3 = new System.Windows.Forms.Panel(); + this.dtReferenceTime = new System.Windows.Forms.DateTimePicker(); + this.dtReferenceDate = new System.Windows.Forms.DateTimePicker(); + this.label6 = new System.Windows.Forms.Label(); + this.tbExternalId = new System.Windows.Forms.TextBox(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.gridSamples)).BeginInit(); + this.tableLayoutPanel1.SuspendLayout(); this.panel2.SuspendLayout(); + this.panel3.SuspendLayout(); this.SuspendLayout(); // // panel1 @@ -45,15 +62,15 @@ private void InitializeComponent() this.panel1.Controls.Add(this.btnCancel); this.panel1.Controls.Add(this.btnOk); this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel1.Location = new System.Drawing.Point(0, 389); + this.panel1.Location = new System.Drawing.Point(0, 405); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(536, 28); + this.panel1.Size = new System.Drawing.Size(557, 28); this.panel1.TabIndex = 9; // // btnCancel // this.btnCancel.Dock = System.Windows.Forms.DockStyle.Right; - this.btnCancel.Location = new System.Drawing.Point(336, 0); + this.btnCancel.Location = new System.Drawing.Point(357, 0); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(100, 28); this.btnCancel.TabIndex = 2; @@ -64,7 +81,7 @@ private void InitializeComponent() // btnOk // this.btnOk.Dock = System.Windows.Forms.DockStyle.Right; - this.btnOk.Location = new System.Drawing.Point(436, 0); + this.btnOk.Location = new System.Drawing.Point(457, 0); this.btnOk.Name = "btnOk"; this.btnOk.Size = new System.Drawing.Size(100, 28); this.btnOk.TabIndex = 1; @@ -88,36 +105,201 @@ private void InitializeComponent() this.gridSamples.ReadOnly = true; this.gridSamples.RowHeadersVisible = false; this.gridSamples.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.gridSamples.Size = new System.Drawing.Size(536, 362); + this.gridSamples.Size = new System.Drawing.Size(557, 231); this.gridSamples.TabIndex = 10; // - // panel2 + // tableLayoutPanel1 // - this.panel2.Controls.Add(this.label1); - this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom; - this.panel2.Location = new System.Drawing.Point(0, 362); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(536, 27); - this.panel2.TabIndex = 12; + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 70F)); + this.tableLayoutPanel1.Controls.Add(this.label2, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.cboxSampleType, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.label3, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.cboxSampleComponent, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 4); + this.tableLayoutPanel1.Controls.Add(this.label4, 0, 3); + this.tableLayoutPanel1.Controls.Add(this.label5, 0, 5); + this.tableLayoutPanel1.Controls.Add(this.tbComment, 1, 5); + this.tableLayoutPanel1.Controls.Add(this.panel2, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.panel3, 1, 4); + this.tableLayoutPanel1.Controls.Add(this.label6, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.tbExternalId, 1, 0); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 231); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 7; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.Size = new System.Drawing.Size(557, 174); + this.tableLayoutPanel1.TabIndex = 13; + // + // label2 + // + this.label2.Dock = System.Windows.Forms.DockStyle.Fill; + this.label2.Location = new System.Drawing.Point(3, 28); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(161, 28); + this.label2.TabIndex = 2; + this.label2.Text = "Sample type"; + this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // cboxSampleType + // + this.cboxSampleType.Dock = System.Windows.Forms.DockStyle.Fill; + this.cboxSampleType.FormattingEnabled = true; + this.cboxSampleType.Location = new System.Drawing.Point(170, 31); + this.cboxSampleType.Name = "cboxSampleType"; + this.cboxSampleType.Size = new System.Drawing.Size(384, 21); + this.cboxSampleType.TabIndex = 3; + this.cboxSampleType.SelectedIndexChanged += new System.EventHandler(this.cboxSampleType_SelectedIndexChanged); + // + // label3 + // + this.label3.Dock = System.Windows.Forms.DockStyle.Fill; + this.label3.Location = new System.Drawing.Point(3, 56); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(161, 28); + this.label3.TabIndex = 4; + this.label3.Text = "Sample component"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // cboxSampleComponent + // + this.cboxSampleComponent.Dock = System.Windows.Forms.DockStyle.Fill; + this.cboxSampleComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboxSampleComponent.FormattingEnabled = true; + this.cboxSampleComponent.Location = new System.Drawing.Point(170, 59); + this.cboxSampleComponent.Name = "cboxSampleComponent"; + this.cboxSampleComponent.Size = new System.Drawing.Size(384, 21); + this.cboxSampleComponent.TabIndex = 5; // // label1 // this.label1.Dock = System.Windows.Forms.DockStyle.Fill; - this.label1.ForeColor = System.Drawing.Color.Red; - this.label1.Location = new System.Drawing.Point(0, 0); + this.label1.Location = new System.Drawing.Point(3, 112); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(536, 27); - this.label1.TabIndex = 1; - this.label1.Text = "Note: Merged samples will not inherit any sample component. Remember to set this " + - "manually if necessary."; + this.label1.Size = new System.Drawing.Size(161, 28); + this.label1.TabIndex = 6; + this.label1.Text = "Reference date"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // label4 + // + this.label4.Dock = System.Windows.Forms.DockStyle.Fill; + this.label4.Location = new System.Drawing.Point(3, 84); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(161, 28); + this.label4.TabIndex = 7; + this.label4.Text = "Sampling date"; + this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // label5 + // + this.label5.Dock = System.Windows.Forms.DockStyle.Fill; + this.label5.Location = new System.Drawing.Point(3, 140); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(161, 28); + this.label5.TabIndex = 8; + this.label5.Text = "Sample comment"; + this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // tbComment + // + this.tbComment.Dock = System.Windows.Forms.DockStyle.Fill; + this.tbComment.Location = new System.Drawing.Point(170, 143); + this.tbComment.MaxLength = 1000; + this.tbComment.Name = "tbComment"; + this.tbComment.Size = new System.Drawing.Size(384, 20); + this.tbComment.TabIndex = 9; + // + // panel2 + // + this.panel2.Controls.Add(this.dtSamplingTime); + this.panel2.Controls.Add(this.dtSamplingDate); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(170, 87); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(384, 22); + this.panel2.TabIndex = 10; + // + // dtSamplingTime + // + this.dtSamplingTime.Dock = System.Windows.Forms.DockStyle.Fill; + this.dtSamplingTime.Format = System.Windows.Forms.DateTimePickerFormat.Time; + this.dtSamplingTime.Location = new System.Drawing.Point(183, 0); + this.dtSamplingTime.Name = "dtSamplingTime"; + this.dtSamplingTime.Size = new System.Drawing.Size(201, 20); + this.dtSamplingTime.TabIndex = 1; + // + // dtSamplingDate + // + this.dtSamplingDate.Dock = System.Windows.Forms.DockStyle.Left; + this.dtSamplingDate.Format = System.Windows.Forms.DateTimePickerFormat.Short; + this.dtSamplingDate.Location = new System.Drawing.Point(0, 0); + this.dtSamplingDate.Name = "dtSamplingDate"; + this.dtSamplingDate.Size = new System.Drawing.Size(183, 20); + this.dtSamplingDate.TabIndex = 0; + // + // panel3 + // + this.panel3.Controls.Add(this.dtReferenceTime); + this.panel3.Controls.Add(this.dtReferenceDate); + this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel3.Location = new System.Drawing.Point(170, 115); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(384, 22); + this.panel3.TabIndex = 11; + // + // dtReferenceTime + // + this.dtReferenceTime.Dock = System.Windows.Forms.DockStyle.Fill; + this.dtReferenceTime.Format = System.Windows.Forms.DateTimePickerFormat.Time; + this.dtReferenceTime.Location = new System.Drawing.Point(183, 0); + this.dtReferenceTime.Name = "dtReferenceTime"; + this.dtReferenceTime.Size = new System.Drawing.Size(201, 20); + this.dtReferenceTime.TabIndex = 1; + // + // dtReferenceDate + // + this.dtReferenceDate.Dock = System.Windows.Forms.DockStyle.Left; + this.dtReferenceDate.Format = System.Windows.Forms.DateTimePickerFormat.Short; + this.dtReferenceDate.Location = new System.Drawing.Point(0, 0); + this.dtReferenceDate.Name = "dtReferenceDate"; + this.dtReferenceDate.Size = new System.Drawing.Size(183, 20); + this.dtReferenceDate.TabIndex = 0; + // + // label6 + // + this.label6.Dock = System.Windows.Forms.DockStyle.Fill; + this.label6.Location = new System.Drawing.Point(3, 0); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(161, 28); + this.label6.TabIndex = 12; + this.label6.Text = "External Id"; + this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // tbExternalId + // + this.tbExternalId.Dock = System.Windows.Forms.DockStyle.Fill; + this.tbExternalId.Location = new System.Drawing.Point(170, 3); + this.tbExternalId.MaxLength = 128; + this.tbExternalId.Name = "tbExternalId"; + this.tbExternalId.Size = new System.Drawing.Size(384, 20); + this.tbExternalId.TabIndex = 13; // // FormSampleMerge // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(536, 417); + this.ClientSize = new System.Drawing.Size(557, 433); this.Controls.Add(this.gridSamples); - this.Controls.Add(this.panel2); + this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.panel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); @@ -129,7 +311,10 @@ private void InitializeComponent() this.Load += new System.EventHandler(this.FormSampleMerge_Load); this.panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.gridSamples)).EndInit(); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); this.panel2.ResumeLayout(false); + this.panel3.ResumeLayout(false); this.ResumeLayout(false); } @@ -140,7 +325,22 @@ private void InitializeComponent() private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.Button btnOk; private System.Windows.Forms.DataGridView gridSamples; - private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ComboBox cboxSampleType; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.ComboBox cboxSampleComponent; private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox tbComment; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.DateTimePicker dtSamplingTime; + private System.Windows.Forms.DateTimePicker dtSamplingDate; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.DateTimePicker dtReferenceTime; + private System.Windows.Forms.DateTimePicker dtReferenceDate; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox tbExternalId; } } \ No newline at end of file diff --git a/FormSampleMerge.cs b/FormSampleMerge.cs index 126fd1d..036aefa 100644 --- a/FormSampleMerge.cs +++ b/FormSampleMerge.cs @@ -25,26 +25,136 @@ You should have received a copy of the GNU General Public License using System.Text; using System.Windows.Forms; using Newtonsoft.Json; +using System.Linq; namespace DSA_lims { public partial class FormSampleMerge : Form - { - private string SampleIdsCsv = String.Empty; + { + private List mSampleIds = null; + private string mSampleIdsCsv = String.Empty; + private List mSamples = new List(); + private TreeView mSampleTypeTree = null; - public FormSampleMerge(string sampleIdsCsv) + public FormSampleMerge(List sampleIds, TreeView sampleTypeTree) { InitializeComponent(); - SampleIdsCsv = sampleIdsCsv; + mSampleIds = sampleIds; + mSampleTypeTree = sampleTypeTree; + var sampleIdsArr = from item in mSampleIds select "'" + item + "'"; + string sampleIdsCsv = string.Join(",", sampleIdsArr); + mSampleIdsCsv = sampleIdsCsv; } private void FormSampleMerge_Load(object sender, EventArgs e) - { + { + HashSet samplePathSet = new HashSet(); + SqlConnection conn = null; try { + UI.PopulateSampleTypes(mSampleTypeTree, cboxSampleType); + conn = DB.OpenConnection(); + + foreach(Guid sid in mSampleIds) + { + Sample s = new Sample(); + s.LoadFromDB(conn, null, sid); + s.Parameters.Clear(); + foreach (Preparation p in s.Preparations) + p.Analyses.Clear(); + s.Preparations.Clear(); + + mSamples.Add(s); + + samplePathSet.Add(s.GetSampleTypePath(conn, null)); + } + + if(samplePathSet.Count == 0) + { + cboxSampleType.SelectedValue = Guid.Empty; + cboxSampleType.Enabled = true; + } + else if(samplePathSet.Count == 1) + { + SqlCommand cmd = new SqlCommand("select id from sample_type where path = @path", conn); + cmd.Parameters.AddWithValue("@path", samplePathSet.ElementAt(0)); + Guid stId = (Guid)cmd.ExecuteScalar(); + cboxSampleType.SelectedValue = stId; + cboxSampleType.Enabled = false; + } + else + { + string[] firstItems = samplePathSet.ElementAt(0).Split(new char[] { '/' }); + int finalLevel = firstItems.Length; + + for (int i = 1; i < samplePathSet.Count; i++) + { + int level = 0; + string[] items = samplePathSet.ElementAt(i).Split(new char[] { '/' }); + int max = Math.Min(firstItems.Length, items.Length); + for(int j=0; j mSamplesSortedBySamplingDate = mSamples.OrderBy(x => x.SamplingDateFrom).ToList(); + mSamplesSortedBySamplingDate.RemoveAll(x => x.SamplingDateFrom == null); + if (mSamplesSortedBySamplingDate.Count == 0) + { + DateTime now = DateTime.Now; + dtSamplingDate.Value = now; + dtSamplingTime.Value = now; + } + else + { + int mid = mSamplesSortedBySamplingDate.Count / 2; + DateTime dtstime = mSamplesSortedBySamplingDate[mid].SamplingDateFrom.Value; + dtSamplingDate.Value = dtstime; + dtSamplingTime.Value = dtstime; + } + + List mSamplesSortedByRefDate = mSamples.OrderBy(x => x.ReferenceDate).ToList(); + mSamplesSortedByRefDate.RemoveAll(x => x.ReferenceDate == null); + if (mSamplesSortedByRefDate.Count == 0) + { + DateTime now = DateTime.Now; + dtReferenceDate.Value = now; + dtReferenceTime.Value = now; + } + else + { + int mid = mSamplesSortedByRefDate.Count / 2; + DateTime dtrtime = mSamplesSortedByRefDate[mid].ReferenceDate.Value; + dtReferenceDate.Value = dtrtime; + dtReferenceTime.Value = dtrtime; + } + string query = String.Format(@" select s.id, @@ -56,14 +166,16 @@ from sample s inner join sample_type st on st.id = s.sample_type_id left outer join sample_component sc on sc.id = s.sample_component_id where s.id in({0}) -order by s.number desc", -SampleIdsCsv); +order by s.number desc", mSampleIdsCsv); + gridSamples.DataSource = DB.GetDataTable(conn, null, query, CommandType.Text); gridSamples.Columns["id"].Visible = false; gridSamples.Columns["sample_number"].HeaderText = "Sample number"; gridSamples.Columns["external_id"].HeaderText = "External Id"; gridSamples.Columns["sample_type_name"].HeaderText = "Sample type"; gridSamples.Columns["sample_component_name"].HeaderText = "Sample component"; + + } catch (Exception ex) { @@ -76,7 +188,7 @@ where s.id in({0}) { conn?.Close(); } - } + } private void btnCancel_Click(object sender, EventArgs e) { @@ -86,6 +198,12 @@ private void btnCancel_Click(object sender, EventArgs e) private void btnOk_Click(object sender, EventArgs e) { + if(!Utils.IsValidGuid(cboxSampleType.SelectedValue)) + { + MessageBox.Show("You must select a sample type"); + return; + } + Dictionary map = new Dictionary(); SqlConnection conn = null; @@ -97,8 +215,7 @@ private void btnOk_Click(object sender, EventArgs e) trans = conn.BeginTransaction(); DateTime currDate = DateTime.Now; - - // FIXME: Using first sample in list as a template + Guid oldSampleId = Utils.MakeGuid(gridSamples.Rows[0].Cells["id"].Value); Sample newSample = new Sample(); newSample.LoadFromDB(conn, trans, oldSampleId); @@ -108,10 +225,23 @@ private void btnOk_Click(object sender, EventArgs e) newSample.Preparations.Clear(); newSample.Parameters.Clear(); newSample.Number = DB.GetNextSampleCount(conn, trans); - newSample.ExternalId = String.Empty; - newSample.SampleComponentId = Guid.Empty; + newSample.ExternalId = String.IsNullOrEmpty(tbExternalId.Text.Trim()) ? String.Empty : tbExternalId.Text.Trim(); + newSample.SampleTypeId = Utils.MakeGuid(cboxSampleType.SelectedValue); + if (Utils.IsValidGuid(cboxSampleComponent.SelectedValue)) + newSample.SampleComponentId = Utils.MakeGuid(cboxSampleComponent.SelectedValue); + else newSample.SampleComponentId = Guid.Empty; newSample.TransformFromId = Guid.Empty; + newSample.MunicipalityId = Guid.Empty; + newSample.LocationType = String.Empty; + newSample.Location = String.Empty; + newSample.StationId = Guid.Empty; + newSample.SampleStorageId = Guid.Empty; + newSample.SamplerId = Guid.Empty; + newSample.SamplingMethodId = Guid.Empty; + newSample.Latitude = newSample.Longitude = newSample.Altitude = null; newSample.InstanceStatusId = InstanceStatus.Active; + newSample.SamplingDateFrom = newSample.SamplingDateTo = new DateTime(dtSamplingDate.Value.Year, dtSamplingDate.Value.Month, dtSamplingDate.Value.Day, dtSamplingTime.Value.Hour, dtSamplingTime.Value.Minute, dtSamplingTime.Value.Second); + newSample.ReferenceDate = new DateTime(dtReferenceDate.Value.Year, dtReferenceDate.Value.Month, dtReferenceDate.Value.Day, dtReferenceTime.Value.Hour, dtReferenceTime.Value.Minute, dtReferenceTime.Value.Second); newSample.WetWeight_g = null; newSample.DryWeight_g = null; newSample.LodWeightStart = null; @@ -129,7 +259,8 @@ private void btnOk_Click(object sender, EventArgs e) newSample.LodTemperatureAsh2 = null; newSample.LodWaterPercentAsh2 = null; newSample.LodFactorAsh2 = null; - newSample.Comment = String.Empty; + newSample.Comment = tbComment.Text.Trim(); + newSample.LockedId = Guid.Empty; newSample.CreateDate = currDate; newSample.CreateId = Common.UserId; newSample.UpdateDate = currDate; @@ -138,9 +269,9 @@ private void btnOk_Click(object sender, EventArgs e) newSample.StoreToDB(conn, trans); string json = JsonConvert.SerializeObject(newSample); - DB.AddAuditMessage(conn, trans, "sample", newSample.Id, AuditOperationType.Insert, json, ""); + DB.AddAuditMessage(conn, trans, "sample", newSample.Id, AuditOperationType.Insert, json, ""); - SqlCommand cmd = new SqlCommand("update sample set transform_to_id = @transform_to_id where id in("+ SampleIdsCsv + ")", conn, trans); + SqlCommand cmd = new SqlCommand("update sample set transform_to_id = @transform_to_id where id in("+ mSampleIdsCsv + ")", conn, trans); cmd.CommandType = CommandType.Text; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@transform_to_id", newSample.Id); @@ -162,6 +293,41 @@ private void btnOk_Click(object sender, EventArgs e) DialogResult = DialogResult.OK; Close(); - } + } + + private void cboxSampleType_SelectedIndexChanged(object sender, EventArgs e) + { + if (!Utils.IsValidGuid(cboxSampleType.SelectedValue)) + { + cboxSampleComponent.DataSource = null; + return; + } + + Guid sampleTypeId = Utils.MakeGuid(cboxSampleType.SelectedValue); + TreeNode[] tnodes = mSampleTypeTree.Nodes.Find(sampleTypeId.ToString(), true); + if (tnodes.Length < 1) + { + Common.Log.Error("Unable to find sample type with id: " + sampleTypeId); + MessageBox.Show("Error: Unable to find sample type with id: " + sampleTypeId); + return; + } + + SqlConnection conn = null; + try + { + conn = DB.OpenConnection(); + UI.PopulateSampleComponentsAscending(conn, sampleTypeId, tnodes[0], cboxSampleComponent); + } + catch (Exception ex) + { + Common.Log.Error(ex); + MessageBox.Show(ex.Message); + return; + } + finally + { + conn?.Close(); + } + } } }