コード例 #1
0
        public FormOrderAddPrepMeth(Assignment ass, AssignmentSampleType ast)
        {
            InitializeComponent();

            tbCount.KeyPress += CustomEvents.Integer_KeyPress;

            mAssignment = ass;
            mAst        = ast;
            cbPrepsAlreadyExists.Checked   = false;
            cboxPrepMethLaboratory.Enabled = false;
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!CheckExistingSampleType())
            {
                return;
            }

            if (!Utils.IsValidGuid(cboxSampleType.SelectedValue))
            {
                MessageBox.Show("Sample type is mandatory");
                return;
            }

            if (String.IsNullOrEmpty(tbNumSamples.Text))
            {
                MessageBox.Show("Number of samples is mandatory");
                return;
            }

            if (!Utils.IsValidInteger(tbNumSamples.Text))
            {
                MessageBox.Show("Number of samples must be a number");
                return;
            }

            int nsamples = Convert.ToInt32(tbNumSamples.Text);

            if (nsamples < 1 || nsamples > 10000)
            {
                MessageBox.Show("Number of samples must be between 1 and 10000");
                return;
            }

            AssignmentSampleType ast = new AssignmentSampleType();

            ast.AssignmentId                = mAssignment.Id;
            ast.SampleTypeId                = Utils.MakeGuid(cboxSampleType.SelectedValue);
            ast.SampleComponentId           = Utils.MakeGuid(cboxSampleComponent.SelectedValue);
            ast.SampleCount                 = nsamples;
            ast.RequestedActivityUnitId     = Utils.MakeGuid(cboxRequestedUnit.SelectedValue);
            ast.RequestedActivityUnitTypeId = Utils.MakeGuid(cboxRequestedUnitType.SelectedValue);
            ast.ReturnToSender              = cbReturnToSender.Checked;
            ast.Comment    = tbComment.Text.Trim();
            ast.CreateDate = DateTime.Now;
            ast.CreateId   = Common.UserId;
            ast.UpdateDate = DateTime.Now;
            ast.UpdateId   = Common.UserId;
            ast.Dirty      = true;
            mAssignment.SampleTypes.Add(ast);

            DialogResult = DialogResult.OK;
            Close();
        }
コード例 #4
0
        public void LoadFromDB(SqlConnection conn, SqlTransaction trans, Guid assId)
        {
            using (SqlDataReader reader = DB.GetDataReader(conn, trans, "csp_select_assignment", CommandType.StoredProcedure,
                                                           new SqlParameter("@id", assId)))
            {
                if (!reader.HasRows)
                {
                    throw new Exception("Error: Assignment with id " + assId.ToString() + " was not found");
                }

                reader.Read();

                Id                     = reader.GetGuid("id");
                Name                   = reader.GetString("name");
                LaboratoryId           = reader.GetGuid("laboratory_id");
                AccountId              = reader.GetGuid("account_id");
                Deadline               = reader.GetDateTimeNullable("deadline");
                RequestedSigmaAct      = reader.GetDouble("requested_sigma_act");
                RequestedSigmaMDA      = reader.GetDouble("requested_sigma_mda");
                CustomerCompanyName    = reader.GetString("customer_company_name");
                CustomerCompanyEmail   = reader.GetString("customer_company_email");
                CustomerCompanyPhone   = reader.GetString("customer_company_phone");
                CustomerCompanyAddress = reader.GetString("customer_company_address");
                CustomerContactName    = reader.GetString("customer_contact_name");
                CustomerContactEmail   = reader.GetString("customer_contact_email");
                CustomerContactPhone   = reader.GetString("customer_contact_phone");
                CustomerContactAddress = reader.GetString("customer_contact_address");
                ApprovedCustomer       = reader.GetBoolean("approved_customer");
                ApprovedCustomerBy     = reader.GetString("approved_customer_by");
                ApprovedLaboratory     = reader.GetBoolean("approved_laboratory");
                ApprovedLaboratoryBy   = reader.GetString("approved_laboratory_by");
                ContentComment         = reader.GetString("content_comment");
                ReportComment          = reader.GetString("report_comment");
                AuditComment           = reader.GetString("audit_comment");
                WorkflowStatusId       = reader.GetInt32("workflow_status_id");
                LastWorkflowStatusDate = reader.GetDateTimeNullable("last_workflow_status_date");
                LastWorkflowStatusBy   = reader.GetString("last_workflow_status_by");
                AnalysisReportVersion  = reader.GetInt32("analysis_report_version");
                InstanceStatusId       = reader.GetInt32("instance_status_id");
                LockedId               = reader.GetGuid("locked_id");
                CreateDate             = reader.GetDateTime("create_date");
                CreateId               = reader.GetGuid("create_id");
                UpdateDate             = reader.GetDateTime("update_date");
                UpdateId               = reader.GetGuid("update_id");
                Description            = reader.GetString("description");
            }

            SampleTypes.Clear();

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

            using (SqlDataReader reader = DB.GetDataReader(conn, trans, "select id from assignment_sample_type where assignment_id = @id", CommandType.Text,
                                                           new SqlParameter("@id", assId)))
            {
                while (reader.Read())
                {
                    sampleTypeIds.Add(reader.GetGuid("id"));
                }
            }

            foreach (Guid astId in sampleTypeIds)
            {
                AssignmentSampleType ast = new AssignmentSampleType();
                ast.LoadFromDB(conn, trans, astId);
                SampleTypes.Add(ast);
            }

            Dirty = false;
        }
コード例 #5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!Utils.IsValidGuid(cboxLaboratory.SelectedValue))
            {
                MessageBox.Show("You must select a laboratory first");
                return;
            }

            if (gridOrders.SelectedRows.Count < 1)
            {
                MessageBox.Show("You must select an order first");
                return;
            }

            if (!mAssignment.ApprovedLaboratory)
            {
                MessageBox.Show("Can not add samples to orders that is not approved by laboratory");
                return;
            }

            if (!mAssignment.ApprovedCustomer)
            {
                MessageBox.Show("Can not add samples to orders that is not approved by customer");
                return;
            }

            if (mAssignment.WorkflowStatusId != WorkflowStatus.Construction)
            {
                MessageBox.Show("Can not add samples to orders that is not under construction");
                return;
            }

            if (treeOrderLines.SelectedNode == null)
            {
                MessageBox.Show("You must select a order line first");
                return;
            }

            TreeNode tnode = treeOrderLines.SelectedNode;

            if (tnode.Level != 0)
            {
                MessageBox.Show("You must select a top level order line for this sample");
                return;
            }

            SqlConnection  conn  = null;
            SqlTransaction trans = null;

            try
            {
                Guid astId = Guid.Parse(tnode.Name);
                AssignmentSampleType ast = mAssignment.SampleTypes.Find(x => x.Id == astId);
                if (ast == null)
                {
                    throw new Exception("No assignment sample type found with id " + ast.Id.ToString());
                }

                conn  = DB.OpenConnection();
                trans = conn.BeginTransaction();

                AstInfo astInfo      = tnode.Tag as AstInfo;
                int     nSamplesFree = DB.GetAvailableSamplesOnAssignmentSampleType(conn, trans, astId);
                if (nSamplesFree <= 0)
                {
                    MessageBox.Show("This order line is full");
                    return;
                }

                string[] items = tnode.Text.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
                if (items.Length < 2)
                {
                    throw new Exception("Invalid sample type found in assignment: " + tnode.Text);
                }

                string st1 = items[1];
                string st2 = mSample.GetSampleTypePath(conn, trans);
                if (!st2.StartsWith(st1))
                {
                    MessageBox.Show("Wrong sample type for sample " + mSample.Number);
                    return;
                }

                if (astInfo.SampleComponentId != Guid.Empty && astInfo.SampleComponentId != mSample.SampleComponentId)
                {
                    MessageBox.Show("Wrong sample component for sample " + mSample.Number);
                    return;
                }

                Guid labId = Utils.MakeGuid(cboxLaboratory.SelectedValue);

                SelectedOrderId   = mAssignment.Id;
                SelectedOrderName = mAssignment.Name;

                foreach (AssignmentPreparationMethod apm in ast.PreparationMethods)
                {
                    if (apm.PreparationLaboratoryId != mAssignment.LaboratoryId)
                    {
                        // Check that external preparations exists
                        TreeNode[] tn = treeOrderLines.Nodes.Find(apm.Id.ToString(), true);
                        if (tn.Length < 1)
                        {
                            throw new Exception("No assignment preparation methods found with id " + apm.Id.ToString());
                        }

                        if (tn[0].Tag == null)
                        {
                            MessageBox.Show("You must specify external preparations for this order line");
                            return;
                        }
                    }
                }

                if (mSample.HasOrder(conn, trans, SelectedOrderId))
                {
                    MessageBox.Show("Sample " + mSample.Number + " is already added to order " + mAssignment.Name);
                    return;
                }

                int nextPrepNum = DB.GetNextPreparationNumber(conn, trans, mSample.Id);

                foreach (AssignmentPreparationMethod apm in ast.PreparationMethods)
                {
                    List <Guid> exIds = null;
                    if (apm.PreparationLaboratoryId != mAssignment.LaboratoryId)
                    {
                        // External preparations
                        TreeNode[] tn = treeOrderLines.Nodes.Find(apm.Id.ToString(), true);
                        if (tn.Length < 1)
                        {
                            throw new Exception("No assignment preparation method node found in tree with id " + apm.Id.ToString());
                        }

                        exIds = tn[0].Tag as List <Guid>;
                    }

                    for (int i = 0; i < apm.PreparationMethodCount; i++)
                    {
                        Preparation p = GetNextPreparation(apm, labId, ref exIds, ref nextPrepNum);

                        int nextAnalNum = DB.GetNextAnalysisNumber(conn, trans, p.Id);
                        foreach (AssignmentAnalysisMethod aam in apm.AnalysisMethods)
                        {
                            for (int j = 0; j < aam.AnalysisMethodCount; j++)
                            {
                                Analysis a = new Analysis();
                                a.PreparationId    = p.Id;
                                a.AnalysisMethodId = aam.AnalysisMethodId;
                                a.InstanceStatusId = InstanceStatus.Active;
                                a.WorkflowStatusId = WorkflowStatus.Construction;
                                a.Number           = nextAnalNum++;
                                a.AssignmentId     = SelectedOrderId;
                                a.LaboratoryId     = labId;
                                p.Analyses.Add(a);
                            }
                        }
                    }
                }

                mSample.ConnectToOrderLine(conn, trans, ast.Id);

                mSample.StoreToDB(conn, trans);

                string json = JsonConvert.SerializeObject(mSample);
                DB.AddAuditMessage(conn, trans, "sample", mSample.Id, AuditOperationType.Update, json, "");

                trans.Commit();
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                trans?.Rollback();
                Common.Log.Error(ex);
                MessageBox.Show(ex.Message);
                DialogResult = DialogResult.Abort;
            }
            finally
            {
                conn?.Close();
            }

            Close();
        }
コード例 #6
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);
        }
コード例 #7
0
        public void StoreToDB(SqlConnection conn, SqlTransaction trans)
        {
            SqlCommand cmd = new SqlCommand("", conn, trans);

            if (!AssignmentSampleType.IdExists(conn, trans, Id))
            {
                // Insert new ast
                cmd.CommandText = "csp_insert_assignment_sample_type";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", Id);
                cmd.Parameters.AddWithValue("@assignment_id", AssignmentId, Guid.Empty);
                cmd.Parameters.AddWithValue("@sample_type_id", SampleTypeId, Guid.Empty);
                cmd.Parameters.AddWithValue("@sample_component_id", SampleComponentId, Guid.Empty);
                cmd.Parameters.AddWithValue("@sample_count", SampleCount);
                cmd.Parameters.AddWithValue("@requested_activity_unit_id", RequestedActivityUnitId, Guid.Empty);
                cmd.Parameters.AddWithValue("@requested_activity_unit_type_id", RequestedActivityUnitTypeId, Guid.Empty);
                cmd.Parameters.AddWithValue("@return_to_sender", ReturnToSender);
                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 ast
                    cmd.CommandText = "csp_update_assignment_sample_type";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@id", Id);
                    cmd.Parameters.AddWithValue("@assignment_id", AssignmentId, Guid.Empty);
                    cmd.Parameters.AddWithValue("@sample_type_id", SampleTypeId, Guid.Empty);
                    cmd.Parameters.AddWithValue("@sample_component_id", SampleComponentId, Guid.Empty);
                    cmd.Parameters.AddWithValue("@sample_count", SampleCount);
                    cmd.Parameters.AddWithValue("@requested_activity_unit_id", RequestedActivityUnitId, Guid.Empty);
                    cmd.Parameters.AddWithValue("@requested_activity_unit_type_id", RequestedActivityUnitTypeId, Guid.Empty);
                    cmd.Parameters.AddWithValue("@return_to_sender", ReturnToSender);
                    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 (AssignmentPreparationMethod apm in PreparationMethods)
            {
                apm.StoreToDB(conn, trans);
            }

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

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

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