コード例 #1
0
        private Preparation GetNextPreparation(AssignmentPreparationMethod apm, Guid labId, ref List <Guid> exIds, ref int nextPrepNum)
        {
            Preparation p = null;

            if (exIds == null)
            {
                p = new Preparation();
                p.AssignmentId        = SelectedOrderId;
                p.InstanceStatusId    = InstanceStatus.Active;
                p.LaboratoryId        = labId;
                p.Number              = nextPrepNum++;
                p.PreparationMethodId = apm.PreparationMethodId;
                p.SampleId            = mSample.Id;
                p.WorkflowStatusId    = WorkflowStatus.Construction;
                mSample.Preparations.Add(p);
            }
            else
            {
                if (exIds.Count < 1)
                {
                    throw new Exception("Missing external preparation ids in list");
                }
                Guid pid = exIds[0];
                exIds.RemoveAt(0);
                p = mSample.Preparations.Find(x => x.Id == pid);
                if (p == null)
                {
                    throw new Exception("External preparation with id " + pid + " was not found on sample " + mSample.Number);
                }
            }

            return(p);
        }
コード例 #2
0
        public FormOrderAddAnalMeth(Assignment ass, AssignmentPreparationMethod apm)
        {
            InitializeComponent();

            tbCount.KeyPress += CustomEvents.Integer_KeyPress;

            mAssignment = ass;
            mApm        = apm;
        }
コード例 #3
0
        public void LoadFromDB(SqlConnection conn, SqlTransaction trans, Guid astId)
        {
            if (!AssignmentSampleType.IdExists(conn, trans, astId))
            {
                throw new Exception("Assignment sample type with id " + astId.ToString() + " was not found");
            }

            PreparationMethods.Clear();

            using (SqlDataReader reader = DB.GetDataReader(conn, trans, "csp_select_assignment_sample_type", CommandType.StoredProcedure,
                                                           new SqlParameter("@id", astId)))
            {
                if (!reader.HasRows)
                {
                    throw new Exception("Assignment sample type with id " + astId.ToString() + " was not found");
                }

                reader.Read();

                Id                          = reader.GetGuid("id");
                AssignmentId                = reader.GetGuid("assignment_id");
                SampleTypeId                = reader.GetGuid("sample_type_id");
                SampleComponentId           = reader.GetGuid("sample_component_id");
                SampleCount                 = reader.GetInt32("sample_count");
                RequestedActivityUnitId     = reader.GetGuid("requested_activity_unit_id");
                RequestedActivityUnitTypeId = reader.GetGuid("requested_activity_unit_type_id");
                ReturnToSender              = reader.GetBoolean("return_to_sender");
                Comment                     = reader.GetString("comment");
                CreateDate                  = reader.GetDateTime("create_date");
                CreateId                    = reader.GetGuid("create_id");
                UpdateDate                  = reader.GetDateTime("update_date");
                UpdateId                    = reader.GetGuid("update_id");
                Dirty                       = false;
            }

            List <Guid> prepMethIds = new List <Guid>();

            using (SqlDataReader reader = DB.GetDataReader(conn, trans, "select id from assignment_preparation_method where assignment_sample_type_id = @astId", CommandType.Text,
                                                           new SqlParameter("@astId", astId)))
            {
                while (reader.Read())
                {
                    prepMethIds.Add(reader.GetGuid("id"));
                }
            }

            foreach (Guid apmId in prepMethIds)
            {
                AssignmentPreparationMethod apm = new AssignmentPreparationMethod();
                apm.LoadFromDB(conn, trans, apmId);
                PreparationMethods.Add(apm);
            }
        }
コード例 #4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!Utils.IsValidGuid(cboxPreparationMethod.SelectedValue))
            {
                MessageBox.Show("Preparation method is mandatory");
                return;
            }

            if (cbPrepsAlreadyExists.Checked && !Utils.IsValidGuid(cboxPrepMethLaboratory.SelectedValue))
            {
                MessageBox.Show("You must select a laboratory for external preparations");
                return;
            }

            if (String.IsNullOrEmpty(tbCount.Text.Trim()))
            {
                MessageBox.Show("Preparation method count is mandatory");
                return;
            }

            if (!Utils.IsValidInteger(tbCount.Text))
            {
                MessageBox.Show("Preparation method count must be a number");
                return;
            }

            int cnt = Convert.ToInt32(tbCount.Text);

            if (cnt < 1 || cnt > 10000)
            {
                MessageBox.Show("Preparation method count must be between 1 and 10000");
                return;
            }

            AssignmentPreparationMethod apm = new AssignmentPreparationMethod();

            apm.AssignmentSampleTypeId  = mAst.Id;
            apm.PreparationMethodId     = Utils.MakeGuid(cboxPreparationMethod.SelectedValue);
            apm.PreparationMethodCount  = cnt;
            apm.PreparationLaboratoryId = Utils.MakeGuid(cboxPrepMethLaboratory.SelectedValue);
            apm.Comment    = tbComment.Text.Trim();
            apm.CreateDate = DateTime.Now;
            apm.CreateId   = Common.UserId;
            apm.UpdateDate = DateTime.Now;
            apm.UpdateId   = Common.UserId;
            apm.Dirty      = true;
            mAst.PreparationMethods.Add(apm);

            DialogResult = DialogResult.OK;
            Close();
        }
コード例 #5
0
        private void btnExistingPreps_Click(object sender, EventArgs e)
        {
            // select existing preparations
            if (treeOrderLines.SelectedNode == null)
            {
                return;
            }

            TreeNode apmNode = treeOrderLines.SelectedNode;

            if (apmNode.Level != 1)
            {
                return;
            }

            Guid astId = Guid.Parse(apmNode.Parent.Name);
            Guid apmId = Guid.Parse(apmNode.Name);

            // FIXME: Sanity checks
            AssignmentSampleType        ast = mAssignment.SampleTypes.Find(x => x.Id == astId);
            AssignmentPreparationMethod apm = ast.PreparationMethods.Find(x => x.Id == apmId);

            if (apm.PreparationLaboratoryId == mAssignment.LaboratoryId)
            {
                MessageBox.Show("These preparation methods are not registered as external");
                return;
            }

            FormSelectExistingPreps form = new FormSelectExistingPreps(apm.PreparationLaboratoryId, mSample);

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (form.SelectedPreparationIds.Count == 0)
            {
                apmNode.Tag = null;
                if (apmNode.Text.EndsWith(" ..."))
                {
                    apmNode.Text = apmNode.Text.Substring(0, apmNode.Text.Length - 4);
                }
                return;
            }

            List <Guid> exIds = new List <Guid>(form.SelectedPreparationIds);

            if (apm.PreparationMethodCount != exIds.Count)
            {
                MessageBox.Show("Wrong number of external preparations");
                return;
            }

            apmNode.Tag = exIds;

            if (!apmNode.Text.EndsWith(" ..."))
            {
                apmNode.Text = apmNode.Text + " ...";
            }

            UpdateCurrentPreparations(apmNode);
        }
コード例 #6
0
        public void StoreToDB(SqlConnection conn, SqlTransaction trans)
        {
            SqlCommand cmd = new SqlCommand("", conn, trans);

            if (!AssignmentPreparationMethod.IdExists(conn, trans, Id))
            {
                // Insert new apm
                cmd.CommandText = "csp_insert_assignment_preparation_method";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", Id);
                cmd.Parameters.AddWithValue("@assignment_sample_type_id", AssignmentSampleTypeId, Guid.Empty);
                cmd.Parameters.AddWithValue("@preparation_method_id", PreparationMethodId, Guid.Empty);
                cmd.Parameters.AddWithValue("@preparation_method_count", PreparationMethodCount);
                cmd.Parameters.AddWithValue("@preparation_laboratory_id", PreparationLaboratoryId, Guid.Empty);
                cmd.Parameters.AddWithValue("@comment", Comment, String.Empty);
                cmd.Parameters.AddWithValue("@create_date", DateTime.Now);
                cmd.Parameters.AddWithValue("@create_id", Common.UserId, Guid.Empty);
                cmd.Parameters.AddWithValue("@update_date", DateTime.Now);
                cmd.Parameters.AddWithValue("@update_id", Common.UserId, Guid.Empty);

                cmd.ExecuteNonQuery();

                Dirty = false;
            }
            else
            {
                if (Dirty)
                {
                    // Update existing apm
                    cmd.CommandText = "csp_update_assignment_preparation_method";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@id", Id);
                    cmd.Parameters.AddWithValue("@assignment_sample_type_id", AssignmentSampleTypeId, Guid.Empty);
                    cmd.Parameters.AddWithValue("@preparation_method_id", PreparationMethodId, Guid.Empty);
                    cmd.Parameters.AddWithValue("@preparation_method_count", PreparationMethodCount);
                    cmd.Parameters.AddWithValue("@preparation_laboratory_id", PreparationLaboratoryId, Guid.Empty);
                    cmd.Parameters.AddWithValue("@comment", Comment, String.Empty);
                    cmd.Parameters.AddWithValue("@update_date", DateTime.Now);
                    cmd.Parameters.AddWithValue("@update_id", Common.UserId, Guid.Empty);

                    cmd.ExecuteNonQuery();

                    Dirty = false;
                }
            }

            foreach (AssignmentAnalysisMethod aam in AnalysisMethods)
            {
                aam.StoreToDB(conn, trans);
            }

            // Remove deleted prep methods from DB
            List <Guid> storedAnalMethIds = new List <Guid>();

            using (SqlDataReader reader = DB.GetDataReader(conn, trans, "select id from assignment_analysis_method where assignment_preparation_method_id = @id", CommandType.Text,
                                                           new SqlParameter("@id", Id)))
            {
                while (reader.Read())
                {
                    storedAnalMethIds.Add(reader.GetGuid("id"));
                }
            }

            cmd.CommandText = "delete from assignment_analysis_method where id = @id";
            cmd.CommandType = CommandType.Text;
            foreach (Guid aamId in storedAnalMethIds)
            {
                if (AnalysisMethods.FindIndex(x => x.Id == aamId) == -1)
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@id", aamId);
                    cmd.ExecuteNonQuery();
                }
            }
        }