예제 #1
0
        void Show_batch()
        {
            // --- show trace groups
            gbApprove.Visible = false;
            gbReview.Visible = false;
            gv2col_Qaqc_approve.ImageIndex = 0;
            gv2col_Qaqc_review.ImageIndex = 0;

            // --- show template method
            ShowDilution();

            // --- show description method
            CBatchFactory faBatch = new CBatchFactory();
            CBatch oBatch = faBatch.GetByPrimaryKey(new CBatchKeys(Idbatch));
            laTitleModule.Text = String.Format("Bandeja {0} en Espera", Comun.FormatCorrelativeCode("B-", Convert.ToInt64(oBatch.Num_tray), 5));

            if (oBatch.Status_process == 'W')
            {
                ucSignCloseTray.Title = "Cerrar bandeja";
                ucSignCloseTray.Enabled = true;
                bgvBatchCalc2.OptionsBehavior.Editable = false;

            }
            if (oBatch.Status_process == 'P')
            {
                ucSignCloseTray.Title = "Cerrado("+oBatch.User_close_tray+")";
                ucSignCloseTray.Enabled = false;
                bgvBatchCalc2.OptionsBehavior.Editable = true;
            }

            CTemplate_methodFactory faTemplate_method = new CTemplate_methodFactory();
            oTemplate_method_current = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));
            tbCodMethod.Text = oTemplate_method_current.Cod_template_method;
            tbTitle.Text = oTemplate_method_current.Title;
            tbAbbreviation.Text = oTemplate_method_current.Abbreviation;

            #region <optimizar>

            CTemplate_method_aaFactory faTemplate_method_aa = new CTemplate_method_aaFactory();
            oTemplate_method_aa_current = faTemplate_method_aa.GetByPrimaryKey(new CTemplate_method_aaKeys(Idtemplate_method));

            deDate_allowed_error.DateTime = Convert.ToDateTime(oTemplate_method_aa_current.Date_allowed_error);

            CMr_detailFactory faMr_detail = new CMr_detailFactory();
            CMr_detail oMr_detail = faMr_detail.GetByPrimaryKey(new CMr_detailKeys(Convert.ToInt16(oTemplate_method_aa_current.Idmr_detail)));
            tbLawMri.Text = oMr_detail.Nominal_value.ToString();

            CMrFactory faMr = new CMrFactory();
            CMr oMr = faMr.GetByPrimaryKey(new CMrKeys(
                Convert.ToInt16(oMr_detail.Idmr)
                ));
            tbMri.Text = oMr.Cod_mr;

            CMeasurement_unitFactory faMeasure = new CMeasurement_unitFactory();
            CMeasurement_unit oMeasurement_unit = faMeasure.GetByPrimaryKey(new CMeasurement_unitKeys(Convert.ToInt16(oMr_detail.Idunit1)));
            tbUnitMeasure.Text = oMeasurement_unit.Name_unit;

            #endregion

            // --- clear columns
            gcBachCalc.DataSource = null;

            // --- format the datatable with the number of repetitions
            oDataBatch = new CDataBatch(Idbatch, Idtemplate_method, Comun.StatusWork.Waiting, Comun.CriteriaSort.BySample);
            gcBachCalc.DataSource = oDataBatch.ListSamples;

            // --- show sd
            tbAbs.Value = oDataBatch.Absorbance;
            tbStd.Value = oDataBatch.StdVerification;
            tbAbs.BackColor = oDataBatch.ColorAbsorbance;
            tbStd.BackColor = oDataBatch.ColorStd;
            tbSdBlk.Text = oDataBatch.LrbMeasured.ToString();
            tbSdBlk.BackColor = oDataBatch.ColorLrbMeasured;
            tbSdMr.Text = oDataBatch.MriMeasured.ToString();
            tbSdMr.BackColor = oDataBatch.ColorMriMeasured;

            // --- show empty sample
            ShowParityEmptySample(false);
        }
예제 #2
0
        private void btRegAbsStd_Click(object sender, EventArgs e)
        {
            // registrar absorvancia y habilitar columnas de lecturas de absorción atómica
            // -- registrar absorvancia.
            if (MessageBox.Show("Registrar Absorvancia y Estandar de Verificación", "Datos de Calibración", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                CBatch oBatch = new CBatchFactory().GetByPrimaryKey(new CBatchKeys(Idbatch));
                oBatch.Absorvance = Convert.ToDecimal(tbAbs.Text);
                oBatch.Std_verification = Convert.ToDecimal(tbStd.Text);
                oBatch.Flag_abs_std = true;

                // -- absorbance
                decimal absMin = Convert.ToDecimal(oTemplate_method_aa_current.Absorvance) - Convert.ToDecimal(oTemplate_method_aa_current.Abs_incertitude);
                decimal absMax = Convert.ToDecimal(oTemplate_method_aa_current.Absorvance) + Convert.ToDecimal(oTemplate_method_aa_current.Abs_incertitude);

                oBatch.Flag_correct_abs = false;
                if (oBatch.Absorvance >= absMin && oBatch.Absorvance <= absMax)
                    oBatch.Flag_correct_abs = true;

                // -- std verification
                decimal stdMin = Convert.ToDecimal(oTemplate_method_aa_current.Std_verif) - Convert.ToDecimal(oTemplate_method_aa_current.Std_verif_incertitude);
                decimal stdMax = Convert.ToDecimal(oTemplate_method_aa_current.Std_verif) + Convert.ToDecimal(oTemplate_method_aa_current.Std_verif_incertitude);

                oBatch.Flag_correct_std = false;
                if (oBatch.Std_verification >= stdMin && oBatch.Std_verification <= stdMax)
                    oBatch.Flag_correct_std = true;

                CBatchFactory faBatch = new CBatchFactory();

                // -- habilitar columnas si está dentro del valor permitido.
                if (faBatch.Update(oBatch))
                {
                    paQaqc2.Enabled = false;
                    tbAbs.Properties.ReadOnly = true;
                    tbStd.Properties.ReadOnly = true;
                    gv2col_Reading1.OptionsColumn.AllowEdit = true;
                    gv2col_Reading2.OptionsColumn.AllowEdit = true;
                    btRegAbsStd.Enabled = false;
                    bgvBatchCalc2.OptionsBehavior.Editable = true;
                }

                SetApareanceAbsorvance();
                SetApareanceStdVerif();
            }
        }
예제 #3
0
        void InitConfigurationAbsStd()
        {
            if (tabTreeQaqc.SelectedTabPageIndex == 0)
            {
                CBatch oBatch = new CBatchFactory().GetByPrimaryKey(new CBatchKeys(Idbatch));

                if (oBatch.Status_process == 'P')
                {
                    paQaqc2.Enabled = true;

                    if (oBatch.Flag_abs_std == null)
                    {
                        tbAbs.Properties.ReadOnly = false;
                        tbStd.Properties.ReadOnly = false;
                        gv2col_Reading1.OptionsColumn.AllowEdit = false;
                        gv2col_Reading2.OptionsColumn.AllowEdit = false;
                        btRegAbsStd.Enabled = true;
                        bgvBatchCalc2.OptionsBehavior.Editable = false;
                    }
                    else
                    {
                        if (Convert.ToBoolean(oBatch.Flag_abs_std))
                        {
                            SetApareanceAbsorvance();
                            SetApareanceStdVerif();
                            paQaqc2.Enabled = false;
                            tbAbs.Properties.ReadOnly = true;
                            tbStd.Properties.ReadOnly = true;
                            btRegAbsStd.Enabled = false;
                            gv2col_Reading1.OptionsColumn.AllowEdit = true;
                            gv2col_Reading2.OptionsColumn.AllowEdit = true;
                            bgvBatchCalc2.OptionsBehavior.Editable = true;
                        }
                        else
                        {
                            tbAbs.Properties.ReadOnly = false;
                            tbStd.Properties.ReadOnly = false;
                            paQaqc2.Enabled = true;
                            btRegAbsStd.Enabled = true;
                            gv2col_Reading1.OptionsColumn.AllowEdit = false;
                            gv2col_Reading2.OptionsColumn.AllowEdit = false;
                            bgvBatchCalc2.OptionsBehavior.Editable = false;
                        }
                    }
                }
                else if (oBatch.Status_process == 'W')
                {
                    paQaqc2.Enabled = false;
                    gv2col_Reading1.OptionsColumn.AllowEdit = false;
                    gv2col_Reading2.OptionsColumn.AllowEdit = false;
                    bgvBatchCalc2.OptionsBehavior.Editable = false;
                }
            }
            else
            {
                paQaqc2.Enabled = false;

                tbAbs.Properties.ReadOnly = false;
                tbStd.Properties.ReadOnly = false;
                gv2col_Reading1.OptionsColumn.AllowEdit = false;
                gv2col_Reading2.OptionsColumn.AllowEdit = false;
                bgvBatchCalc2.OptionsBehavior.Editable = true;

                btRegAbsStd.Enabled = false;
            }
        }
예제 #4
0
        private void treeTrayWaiting_DragOver(object sender, DragEventArgs e)
        {
            DevExpress.XtraTreeList.TreeList tl = sender as DevExpress.XtraTreeList.TreeList;

            hi_over = tl.CalcHitInfo(tl.PointToClient(new Point(e.X, e.Y)));
            if (hi_over.Node != null && hi_drag.Node != null)
            {
                if (hi_over.Node != null && hi_over.Node.Level == 0)
                    e.Effect = DragDropEffects.None;
                else
                {
                    DevExpress.XtraTreeList.Nodes.TreeListNode node_drag = hi_drag.Node as DevExpress.XtraTreeList.Nodes.TreeListNode;
                    DevExpress.XtraTreeList.Nodes.TreeListNode node_over = hi_over.Node as DevExpress.XtraTreeList.Nodes.TreeListNode;

                    long idbatch_over = Convert.ToInt64(node_over.ParentNode.GetValue("Id"));

                    // get father level 1
                    long idbatch_drag = Convert.ToInt64(node_drag.ParentNode.GetValue("Id"));

                    if (idbatch_drag != idbatch_over)
                    {
                        int idtemplate_method_drag = Convert.ToInt32(node_drag.GetValue("Idtemplate_method"));

                        CBatch oBatch_over = new CBatchFactory().GetByPrimaryKey(new CBatchKeys(idbatch_over));

                        if (oBatch_over.Status_process == 'W' &&
                            oBatch_over.Idtemplate_method == idtemplate_method_drag)
                            e.Effect = DragDropEffects.Move;
                        else// batch en proceso
                            e.Effect = DragDropEffects.None;
                    }
                    else
                        e.Effect = DragDropEffects.None;
                }
            }
        }
예제 #5
0
        private void ucSignCloseTray_OnSign(bool login)
        {
            if (login)
            {
                // --- close samples tray
                CBatch oBatch = new CBatchFactory().GetByPrimaryKey(new CBatchKeys(Idbatch));
                oBatch.User_close_tray = Comun.GetUser();
                oBatch.Date_close_tray = Comun.GetDate();

                if (oBatch != null)
                {
                    FormMessage fmMessage = new FormMessage();
                    fmMessage.Title = String.Format("Cerrar Bandeja {0}", Comun.FormatCorrelativeCode("B-", Convert.ToInt64(oBatch.Num_tray), 5));
                    fmMessage.Message = "Al efectuar esta acción, la bandeja cambia a estado en 'proceso', se bloqueará el ingreso de muestras entrantes. Presione Ok para confirmar.";
                    if (fmMessage.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        oBatch.Status_process = 'P';    // --- in process

                        // --- add control sample if not exist
                        if (Convert.ToBoolean(!oBatch.Has_sample_control))
                        {
                            CBatchManager oBatchManager = new CBatchManager();

                            oBatchManager.SaveControlSample(Idtemplate_method, Idbatch);

                            // --- retrieve batch detail
                            Show_batch();
                        }

                        if (new CBatchFactory().Update(oBatch))
                        {
                            ucSignCloseTray.Enabled = false;
                            ucSignCloseTray.Title = "Cerrado("+oBatch.User_close_tray+")";
                        }

                        paQaqc2.Enabled = true;
                        bgvBatchCalc2.OptionsBehavior.Editable = false;
                        InitConfigurationAbsStd();
                    }
                }
            }
        }
예제 #6
0
        public void ApplyQaqcMrBlk(CBatch_detail_aa_twofold current_row)
        {
            int flag_mri = Convert.ToInt32(current_row.Flag_mri);

            // only work with rows that are reference material
            if (flag_mri == 1)
            {
                long          idbatch = Convert.ToInt64(pivot[0].Idbatch);
                CBatchFactory faBatch = new CBatchFactory();
                CBatch        oBatch  = faBatch.GetByPrimaryKey(new CBatchKeys(idbatch));
                GetSd();

                // recuperate the blk
                decimal value_blk = Convert.ToDecimal(current_row.Reading1);

                // blk
                if (current_row.Reading1 != null)
                {
                    if (value_blk <= Max_value_blk)
                    {
                        current_row.Qaqc_blk = 1;   // --- correcto

                        oBatch.Flag_correct_lrb = true;
                        oBatch.Lrb_measured     = Convert.ToDecimal(Lrb_measured);
                    }
                    if (value_blk > Max_value_blk)
                    {
                        current_row.Qaqc_blk = 2;   // --- error en el blanco

                        oBatch.Flag_correct_lrb = false;
                        oBatch.Lrb_measured     = Convert.ToDecimal(Lrb_measured);
                    }
                }

                // mri
                if (current_row.Reading2 != null)
                {
                    // ley mri +- repetibilidad*2 <= ley conocida + reproducibilidad

                    decimal min = Law_fixed - Factor_reproducibility;
                    decimal max = Law_fixed + Factor_reproducibility;

                    decimal law_mr = Convert.ToDecimal(current_row.Law2);
                    decimal value  = law_mr;

                    if (value >= min && value <= max)
                    {
                        current_row.Qaqc_mr     = 1; // correcto
                        oBatch.Flag_correct_mri = true;
                        oBatch.Mri_measured     = Convert.ToDecimal(Mri_measured);
                    }
                    if (value < min || value > max)
                    {
                        current_row.Qaqc_mr     = 2; // error en el mri
                        oBatch.Flag_correct_mri = false;
                        oBatch.Mri_measured     = Convert.ToDecimal(Mri_measured);
                    }
                }

                faBatch.Update(oBatch);
            }
            else
            {
                // no es mri
                current_row.Qaqc_blk = 3;
                current_row.Qaqc_mr  = 3;
            }
        }
예제 #7
0
        void Show_batch_finished()
        {
            gbApprove.Visible = true;
            gbReview.Visible = true;
            gv2col_Qaqc_approve.ImageIndex = 0;
            gv2col_Qaqc_review.ImageIndex = 0;

            // --- show template method
            ShowDilution();

            // --- show description method
            CTemplate_methodFactory faTemplate_method = new CTemplate_methodFactory();
            CTemplate_method oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));
            tbCodMethod.Text = oTemplate_method.Cod_template_method;
            tbTitle.Text = oTemplate_method.Title;
            tbAbbreviation.Text = oTemplate_method.Abbreviation;

            // --- get batch trace_batch
            CTrace_batchFactory faTrace_batch = new CTrace_batchFactory();
            Dictionary<string, string> dtTrace_batch = new BusinessLayer.Modules.ModProcessBatch().GetCurrentAndBelow(Idbatch, LimsProcess.PROCESS_IN_READING);

            CBatchFactory faBatch = new CBatchFactory();
            CBatch oBatch = faBatch.GetByPrimaryKey(new CBatchKeys(Idbatch));
            laTitleModule.Text = String.Format("Bandeja {0} Aprobada\n ({1})"
                , "B-" + oBatch.Num_tray.ToString().PadLeft(5, '0')
                , dtTrace_batch["User_approved"].ToString());

            laUser_approved.Text = dtTrace_batch["User_approved"].ToString();
            laDate_approved.Text = dtTrace_batch["Date_approved"].ToString();
            laUser_revised.Text = dtTrace_batch["User_revised"].ToString();
            laDate_revised.Text = dtTrace_batch["Date_revised"].ToString();

            #region <optimizar>

            CTemplate_method_aaFactory faTemplate_method_aa = new CTemplate_method_aaFactory();
            CTemplate_method_aa oTemplate_method_aa = faTemplate_method_aa.GetByPrimaryKey(new CTemplate_method_aaKeys(Idtemplate_method));

            deDate_allowed_error.DateTime = Convert.ToDateTime(oTemplate_method_aa.Date_allowed_error);

            CMr_detailFactory faMr_detail = new CMr_detailFactory();
            CMr_detail oMr_detail = faMr_detail.GetByPrimaryKey(new CMr_detailKeys(Convert.ToInt16(oTemplate_method_aa.Idmr_detail)));
            tbLawMri.Text = oMr_detail.Nominal_value.ToString();

            CMrFactory faMr = new CMrFactory();
            CMr oMr = faMr.GetByPrimaryKey(new CMrKeys(
                Convert.ToInt16(oMr_detail.Idmr)
                ));
            tbMri.Text = oMr.Cod_mr;

            CMeasurement_unitFactory faMeasure = new CMeasurement_unitFactory();
            CMeasurement_unit oMeasurement_unit = faMeasure.GetByPrimaryKey(new CMeasurement_unitKeys(Convert.ToInt16(oMr_detail.Idunit1)));
            tbUnitMeasure.Text = oMeasurement_unit.Name_unit;

            #endregion

            // --- clear columns
            gcBachCalc.DataSource = null;

            // --- format the datatable with the number of repetitions
            if (cbAuthorizationApproved.EditValue.ToString() == "0000")
                oDataBatch = new CDataBatch(Idbatch, Idtemplate_method, Comun.StatusWork.Saved, Comun.CriteriaSort.BySample);
            else
                oDataBatch = new CDataBatch(Idbatch, Idtemplate_method, Comun.StatusWork.Management, Comun.CriteriaSort.BySample);

            gcBachCalc.DataSource = oDataBatch.ListSamples;

            // --- show sd
            tbAbs.Value = oDataBatch.Absorbance;
            tbStd.Value = oDataBatch.StdVerification;
            tbAbs.BackColor = oDataBatch.ColorAbsorbance;
            tbStd.BackColor = oDataBatch.ColorStd;
            tbSdBlk.Text = oDataBatch.LrbMeasured.ToString();
            tbSdBlk.BackColor = oDataBatch.ColorLrbMeasured;
            tbSdMr.Text = oDataBatch.MriMeasured.ToString();
            tbSdMr.BackColor = oDataBatch.ColorMriMeasured;

            // --- OPTIMIZAR A USER CONTROL
            paAuthorization.Visible = true;

            // --- show empty sample
            ShowParityEmptySample(true);
        }
예제 #8
0
        public void Review()
        {
            try
            {
                CBatchFactory faBatch = new CBatchFactory();
                CBatch        oBatch  = faBatch.GetByPrimaryKey(new CBatchKeys(Idbatch));

                // --- save trace
                CRecep_sample_detail_elemFactory faRecep_sample_detail_elem = new CRecep_sample_detail_elemFactory();

                for (int i = 0; i < ListSamples.Count; i++)
                {
                    CBatch_detail_aa_twofold current_row = ListSamples[i];

                    int status_result = Convert.ToInt32(current_row.Qaqc_status_result);

                    if (Convert.ToInt32(current_row.Flag_mri) == 0)
                    {
                        // --- set how accepted sample
                        // Espera = 0,
                        // Incorrecto = 1,
                        // Plausible = 2,
                        // Aceptado = 3,
                        // IncorrectoPlausible = 4,
                        // Espera reensayos = 5
                        // --- save only the accept samples
                        long Idrecep_sample_detail_elem = Convert.ToInt64(current_row.Idrecep_sample_detail_elem);

                        if (Convert.ToBoolean(oBatch.Flag_correct_mri) && Convert.ToBoolean(oBatch.Flag_correct_lrb))
                        {
                            if (status_result == Convert.ToInt32(Comun.Status_result.Plausible))
                            {
                                current_row.Qaqc_status_result = Convert.ToInt16(Comun.Status_result.Aceptado);
                            }

                            Qaqc oQaqc = new Qaqc();
                            if (!oQaqc.IsRetest(Idrecep_sample_detail_elem, Idbatch))
                            {
                                // --- save final element law
                                if (current_row.Qaqc_status_result == Convert.ToInt16(Comun.Status_result.Aceptado))
                                {
                                    CRecep_sample_detail_elem oRecep_sample_detail_elem = faRecep_sample_detail_elem.GetByPrimaryKey(new CRecep_sample_detail_elemKeys(Idrecep_sample_detail_elem));
                                    oRecep_sample_detail_elem.Result_analysis     = current_row.Result_analysis;
                                    oRecep_sample_detail_elem.Str_result_analysis = current_row.Str_result_analysis.ToString();
                                    oRecep_sample_detail_elem.With_result         = true;
                                    if (current_row.Str_result_analysis == null)
                                    {
                                        oRecep_sample_detail_elem.With_result = false;
                                    }
                                    faRecep_sample_detail_elem.Update(oRecep_sample_detail_elem);
                                }
                                CBatch_detail_aa_twofoldFactory faBatch_detail_aa_twofold = new CBatch_detail_aa_twofoldFactory();
                                faBatch_detail_aa_twofold.Update(current_row);
                            }
                            else// --- es un reensayo
                            {
                                if (!oQaqc.ExistsResultPendingSel(Idrecep_sample_detail_elem, Idbatch))
                                {
                                    // --- si no está pendiente de seleccionar entre varios análisis
                                    // --- save final element law
                                    if (current_row.Qaqc_status_result == Convert.ToInt16(Comun.Status_result.Aceptado))
                                    {
                                        CRecep_sample_detail_elem oRecep_sample_detail_elem = faRecep_sample_detail_elem.GetByPrimaryKey(new CRecep_sample_detail_elemKeys(Idrecep_sample_detail_elem));
                                        oRecep_sample_detail_elem.Result_analysis     = current_row.Result_analysis;
                                        oRecep_sample_detail_elem.Str_result_analysis = current_row.Str_result_analysis.ToString();
                                        oRecep_sample_detail_elem.With_result         = true;
                                        if (current_row.Str_result_analysis == null)
                                        {
                                            oRecep_sample_detail_elem.With_result = false;
                                        }
                                        faRecep_sample_detail_elem.Update(oRecep_sample_detail_elem);
                                    }
                                    CBatch_detail_aa_twofoldFactory faBatch_detail_aa_twofold = new CBatch_detail_aa_twofoldFactory();
                                    faBatch_detail_aa_twofold.Update(current_row);
                                }
                            }

                            // --- save retest
                            if (current_row.Qaqc_tmp_retest == 1)
                            {
                                string       cod_type_sample = new CTemplate_methodFactory().GetByPrimaryKey(new CTemplate_methodKeys(Convert.ToInt32(current_row.Idtemplate_method))).Cod_type_sample;
                                CCorrelative oCorrelative    = new CCorrelativeFactory().GetByPrimaryKey(new CCorrelativeKeys(cod_type_sample));

                                CBatchManager oBatchManager = new CBatchManager();

                                oBatchManager.CallSaveSampleBatchWithRetest(
                                    Convert.ToInt32(current_row.Idtemplate_method),
                                    Convert.ToInt64(current_row.Idrecep_sample),
                                    Convert.ToInt64(current_row.Idrecep_sample_detail),
                                    Convert.ToInt64(current_row.Idrecep_sample_detail_elem),
                                    Convert.ToInt64(current_row.Cod_interno),
                                    current_row.Cod_sample,
                                    Comun.GetUser(),
                                    oCorrelative, Convert.ToInt32(current_row.Qaqc_par), Idbatch);
                            }

                            // --- register as finished trace process
                            CProcess_Sample_Manage.Finalize_process(Idrecep_sample_detail_elem, LimsProcess.PROCESS_APPROVE_SAMPLES, LimsProcess.PROCESS_ACCEPT_RESULTS);
                        }
                        else
                        {
                            // --- the samples pertain to batch with full batch retest
                            CProcess_Sample_Manage.Finalize_process(Idrecep_sample_detail_elem, LimsProcess.PROCESS_APPROVE_SAMPLES, LimsProcess.PROCESS_ACCEPT_RESULTS);
                        }
                    }
                }

                // --- modify the batch status, put in other process
                CProcess oProcess = new CProcessFactory().GetByPrimaryKey(new CProcessKeys(LimsProcess.PROCESS_ACCEPT_RESULTS));
                oBatch.Status_process   = Convert.ToChar(LimsProcess.Status_Process.Waiting);
                oBatch.Cod_module       = oProcess.Cod_module;
                oBatch.Cod_area         = oProcess.Cod_area;
                oBatch.Cod_process      = LimsProcess.PROCESS_ACCEPT_RESULTS;
                oBatch.User_review_tray = Comun.GetUser();
                oBatch.Date_review_tray = Comun.GetDate();
                faBatch.Update(oBatch);

                // --- register as finished trace batch
                Cprocess_Batch_Manage.Finalize_process(Idbatch, LimsProcess.PROCESS_APPROVE_SAMPLES, LimsProcess.PROCESS_ACCEPT_RESULTS);
            }
            catch (Exception ex)
            {
                Comun.Save_log(ex.InnerException.ToString());
                throw new Exception("pivot data::approve::Error occured.", ex);
            }
        }
예제 #9
0
        public void ApplyQaqcMrBlk(CBatch_detail_aa_twofold current_row)
        {
            int flag_mri = Convert.ToInt32(current_row.Flag_mri);

            // only work with rows that are reference material
            if (flag_mri == 1)
            {
                long idbatch = Convert.ToInt64(pivot[0].Idbatch);
                CBatchFactory faBatch = new CBatchFactory();
                CBatch oBatch = faBatch.GetByPrimaryKey(new CBatchKeys(idbatch));
                GetSd();

                // recuperate the blk
                decimal value_blk = Convert.ToDecimal(current_row.Reading1);

                // blk
                if (current_row.Reading1 != null)
                {
                    if (value_blk <= Max_value_blk)
                    {
                        current_row.Qaqc_blk = 1;   // --- correcto

                        oBatch.Flag_correct_lrb = true;
                        oBatch.Lrb_measured = Convert.ToDecimal(Lrb_measured);
                    }
                    if (value_blk > Max_value_blk)
                    {
                        current_row.Qaqc_blk = 2;   // --- error en el blanco

                        oBatch.Flag_correct_lrb = false;
                        oBatch.Lrb_measured = Convert.ToDecimal(Lrb_measured);
                    }
                }

                // mri
                if (current_row.Reading2 != null)
                {
                    // ley mri +- repetibilidad*2 <= ley conocida + reproducibilidad

                    decimal min = Law_fixed - Factor_reproducibility;
                    decimal max = Law_fixed + Factor_reproducibility;

                    decimal law_mr = Convert.ToDecimal(current_row.Law2);
                    decimal value = law_mr;

                    if (value >= min && value <= max)
                    {
                        current_row.Qaqc_mr = 1;    // correcto
                        oBatch.Flag_correct_mri = true;
                        oBatch.Mri_measured = Convert.ToDecimal(Mri_measured);
                    }
                    if (value < min || value > max)
                    {
                        current_row.Qaqc_mr = 2;    // error en el mri
                        oBatch.Flag_correct_mri = false;
                        oBatch.Mri_measured = Convert.ToDecimal(Mri_measured);
                    }
                }

                faBatch.Update(oBatch);
            }
            else
            {
                // no es mri
                current_row.Qaqc_blk = 3;
                current_row.Qaqc_mr = 3;
            }
        }
예제 #10
0
        public void RefreshQaqcSummary()
        {
            CBatch oBatch = new CBatchFactory().GetByPrimaryKey(new CBatchKeys(Idbatch));

            Absorbance      = oBatch.Absorvance == null ? 0 : Convert.ToDecimal(oBatch.Absorvance);
            StdVerification = oBatch.Std_verification == null ? 0 : Convert.ToDecimal(oBatch.Std_verification);
            MriMeasured     = oBatch.Mri_measured == null ? 0 : Convert.ToDecimal(oBatch.Mri_measured);
            LrbMeasured     = oBatch.Lrb_measured == null ? 0 : Convert.ToDecimal(oBatch.Lrb_measured);

            // --- absorbance
            if (oBatch.Flag_correct_abs == null)
            {
                ColorAbsorbance = Color.White;
            }
            else if (oBatch.Flag_correct_abs == true)
            {
                ColorAbsorbance = Comun.ColorVerde;
            }
            else
            {
                ColorAbsorbance = Comun.ColorRojo;
            }

            // --- std
            if (oBatch.Flag_correct_std == null)
            {
                ColorStd = Color.White;
            }
            else if (oBatch.Flag_correct_std == true)
            {
                ColorStd = Comun.ColorVerde;
            }
            else
            {
                ColorStd = Comun.ColorRojo;
            }

            // --- mri
            if (oBatch.Flag_correct_mri == null)
            {
                ColorMriMeasured = Color.White;
            }
            else if (oBatch.Flag_correct_mri == true)
            {
                ColorMriMeasured = Comun.ColorVerde;
            }
            else
            {
                ColorMriMeasured = Comun.ColorRojo;
            }

            // --- lrb
            if (oBatch.Flag_correct_lrb == null)
            {
                ColorLrbMeasured = Color.White;
            }
            else if (oBatch.Flag_correct_lrb == true)
            {
                ColorLrbMeasured = Comun.ColorVerde;
            }
            else
            {
                ColorLrbMeasured = Comun.ColorRojo;
            }
        }
예제 #11
0
        public void Approve()
        {
            try
            {
                CBatchFactory faBatch = new CBatchFactory();
                CBatch        oBatch  = faBatch.GetByPrimaryKey(new CBatchKeys(Idbatch));

                // --- check parity
                for (int i = 0; i < ListSamples.Count; i++)
                {
                    CBatch_detail_aa_twofold        row = ListSamples[i];
                    CBatch_detail_aa_twofoldFactory faBatch_detail_aa_twofold = new CBatch_detail_aa_twofoldFactory();

                    if (Convert.ToInt32(row.Flag_mri) == 0)
                    {
                        // --- reset retest temp configuration
                        row.Qaqc_tmp_retest          = 0;
                        row.Qaqc_tmp_retest_idmethod = 0;

                        if (row.Qaqc_error >= 0 && row.Qaqc_error <= 2)
                        {
                            row.Qaqc_status_result = 2;
                        }
                        else
                        {
                            if (row.Qaqc_error == 4)
                            {
                                row.Qaqc_status_result = 4;
                            }
                        }

                        faBatch_detail_aa_twofold.Update(row);

                        // --- save retest
                        if (row.Qaqc_error == 2 || row.Qaqc_error == 5)
                        {
                            string       cod_type_sample = new CTemplate_methodFactory().GetByPrimaryKey(new CTemplate_methodKeys(Convert.ToInt32(row.Idtemplate_method))).Cod_type_sample;
                            CCorrelative oCorrelative    = new CCorrelativeFactory().GetByPrimaryKey(new CCorrelativeKeys(cod_type_sample));

                            CBatchManager oBatchManager = new CBatchManager();

                            oBatchManager.CallSaveSampleBatchWithRetest(
                                Convert.ToInt32(row.Idtemplate_method),
                                Convert.ToInt64(row.Idrecep_sample),
                                Convert.ToInt64(row.Idrecep_sample_detail),
                                Convert.ToInt64(row.Idrecep_sample_detail_elem),
                                Convert.ToInt64(row.Cod_interno),
                                row.Cod_sample,
                                Comun.GetUser(),
                                oCorrelative,
                                Convert.ToInt32(row.Qaqc_par),
                                Convert.ToInt64(row.Idbatch));
                        }

                        // --- register as finished trace process
                        CProcess_Sample_Manage.Finalize_process(Convert.ToInt64(row.Idrecep_sample_detail_elem), LimsProcess.PROCESS_IN_READING, LimsProcess.PROCESS_APPROVE_SAMPLES);
                    }
                }

                // --- modify the batch status, put in other process
                CProcess oProcess = new CProcessFactory().GetByPrimaryKey(new CProcessKeys(LimsProcess.PROCESS_APPROVE_SAMPLES));
                oBatch.Status_process    = Convert.ToChar(LimsProcess.Status_Process.Waiting);
                oBatch.Cod_module        = oProcess.Cod_module;
                oBatch.Cod_area          = oProcess.Cod_area;
                oBatch.Cod_process       = LimsProcess.PROCESS_APPROVE_SAMPLES;
                oBatch.User_approve_tray = Comun.GetUser();
                oBatch.Date_approve_tray = Comun.GetDate();
                faBatch.Update(oBatch);

                // --- register as finished trace batch
                Cprocess_Batch_Manage.Finalize_process(Idbatch, LimsProcess.PROCESS_IN_READING, LimsProcess.PROCESS_APPROVE_SAMPLES);
            }
            catch (Exception ex)
            {
                Comun.Save_log(ex.InnerException.ToString());
                throw new Exception("pivot data::approve::Error occured.", ex);
            }
        }
예제 #12
0
        public void Review()
        {
            try
            {
                CBatchFactory faBatch = new CBatchFactory();
                CBatch oBatch = faBatch.GetByPrimaryKey(new CBatchKeys(Idbatch));

                // --- save trace
                CRecep_sample_detail_elemFactory faRecep_sample_detail_elem = new CRecep_sample_detail_elemFactory();

                for (int i = 0; i < ListSamples.Count; i++)
                {
                    CBatch_detail_aa_twofold current_row = ListSamples[i];

                    int status_result = Convert.ToInt32(current_row.Qaqc_status_result);

                    if (Convert.ToInt32(current_row.Flag_mri) == 0)
                    {
                        // --- set how accepted sample
                        // Espera = 0,
                        // Incorrecto = 1,
                        // Plausible = 2,
                        // Aceptado = 3,
                        // IncorrectoPlausible = 4,
                        // Espera reensayos = 5
                        // --- save only the accept samples
                        long Idrecep_sample_detail_elem = Convert.ToInt64(current_row.Idrecep_sample_detail_elem);

                        if (Convert.ToBoolean(oBatch.Flag_correct_mri) && Convert.ToBoolean(oBatch.Flag_correct_lrb))
                        {

                            if (status_result == Convert.ToInt32(Comun.Status_result.Plausible))
                                current_row.Qaqc_status_result = Convert.ToInt16(Comun.Status_result.Aceptado);

                            Qaqc oQaqc = new Qaqc();
                            if (!oQaqc.IsRetest(Idrecep_sample_detail_elem, Idbatch))
                            {
                                // --- save final element law
                                if (current_row.Qaqc_status_result == Convert.ToInt16(Comun.Status_result.Aceptado))
                                {
                                    CRecep_sample_detail_elem oRecep_sample_detail_elem = faRecep_sample_detail_elem.GetByPrimaryKey(new CRecep_sample_detail_elemKeys(Idrecep_sample_detail_elem));
                                    oRecep_sample_detail_elem.Result_analysis = current_row.Result_analysis;
                                    oRecep_sample_detail_elem.Str_result_analysis = current_row.Str_result_analysis.ToString();
                                    oRecep_sample_detail_elem.With_result = true;
                                    if (current_row.Str_result_analysis == null)
                                        oRecep_sample_detail_elem.With_result = false;
                                    faRecep_sample_detail_elem.Update(oRecep_sample_detail_elem);
                                }
                                CBatch_detail_aa_twofoldFactory faBatch_detail_aa_twofold = new CBatch_detail_aa_twofoldFactory();
                                faBatch_detail_aa_twofold.Update(current_row);
                            }
                            else// --- es un reensayo
                            {
                                if (!oQaqc.ExistsResultPendingSel(Idrecep_sample_detail_elem, Idbatch))
                                {
                                    // --- si no está pendiente de seleccionar entre varios análisis
                                    // --- save final element law
                                    if (current_row.Qaqc_status_result == Convert.ToInt16(Comun.Status_result.Aceptado))
                                    {
                                        CRecep_sample_detail_elem oRecep_sample_detail_elem = faRecep_sample_detail_elem.GetByPrimaryKey(new CRecep_sample_detail_elemKeys(Idrecep_sample_detail_elem));
                                        oRecep_sample_detail_elem.Result_analysis = current_row.Result_analysis;
                                        oRecep_sample_detail_elem.Str_result_analysis = current_row.Str_result_analysis.ToString();
                                        oRecep_sample_detail_elem.With_result = true;
                                        if (current_row.Str_result_analysis == null)
                                            oRecep_sample_detail_elem.With_result = false;
                                        faRecep_sample_detail_elem.Update(oRecep_sample_detail_elem);
                                    }
                                    CBatch_detail_aa_twofoldFactory faBatch_detail_aa_twofold = new CBatch_detail_aa_twofoldFactory();
                                    faBatch_detail_aa_twofold.Update(current_row);
                                }
                            }

                            // --- save retest
                            if (current_row.Qaqc_tmp_retest == 1)
                            {
                                string cod_type_sample = new CTemplate_methodFactory().GetByPrimaryKey(new CTemplate_methodKeys(Convert.ToInt32(current_row.Idtemplate_method))).Cod_type_sample;
                                CCorrelative oCorrelative = new CCorrelativeFactory().GetByPrimaryKey(new CCorrelativeKeys(cod_type_sample));

                                CBatchManager oBatchManager = new CBatchManager();

                                oBatchManager.CallSaveSampleBatchWithRetest(
                                    Convert.ToInt32(current_row.Idtemplate_method),
                                    Convert.ToInt64(current_row.Idrecep_sample),
                                    Convert.ToInt64(current_row.Idrecep_sample_detail),
                                    Convert.ToInt64(current_row.Idrecep_sample_detail_elem),
                                    Convert.ToInt64(current_row.Cod_interno),
                                    current_row.Cod_sample,
                                    Comun.GetUser(),
                                    oCorrelative, Convert.ToInt32(current_row.Qaqc_par), Idbatch);
                            }

                            // --- register as finished trace process
                            CProcess_Sample_Manage.Finalize_process(Idrecep_sample_detail_elem, LimsProcess.PROCESS_APPROVE_SAMPLES, LimsProcess.PROCESS_ACCEPT_RESULTS);
                        }
                        else
                        {
                            // --- the samples pertain to batch with full batch retest
                            CProcess_Sample_Manage.Finalize_process(Idrecep_sample_detail_elem, LimsProcess.PROCESS_APPROVE_SAMPLES, LimsProcess.PROCESS_ACCEPT_RESULTS);
                        }

                    }
                }

                // --- modify the batch status, put in other process
                CProcess oProcess = new CProcessFactory().GetByPrimaryKey(new CProcessKeys(LimsProcess.PROCESS_ACCEPT_RESULTS));
                oBatch.Status_process = Convert.ToChar(LimsProcess.Status_Process.Waiting);
                oBatch.Cod_module = oProcess.Cod_module;
                oBatch.Cod_area = oProcess.Cod_area;
                oBatch.Cod_process = LimsProcess.PROCESS_ACCEPT_RESULTS;
                oBatch.User_review_tray = Comun.GetUser();
                oBatch.Date_review_tray = Comun.GetDate();
                faBatch.Update(oBatch);

                // --- register as finished trace batch
                Cprocess_Batch_Manage.Finalize_process(Idbatch, LimsProcess.PROCESS_APPROVE_SAMPLES, LimsProcess.PROCESS_ACCEPT_RESULTS);

            }
            catch (Exception ex)
            {
                Comun.Save_log(ex.InnerException.ToString());
                throw new Exception("pivot data::approve::Error occured.", ex);
            }
        }
예제 #13
0
        public void RetestBatch()
        {
            try
            {
                CBatchFactory faBatch = new CBatchFactory();
                CBatch oBatch = faBatch.GetByPrimaryKey(new CBatchKeys(Idbatch));

                // --- check parity
                for (int i = 0; i < ListSamples.Count; i++)
                {
                    CBatch_detail_aa_twofold row = ListSamples[i];
                    CBatch_detail_aa_twofoldFactory faBatch_detail_aa_twofold = new CBatch_detail_aa_twofoldFactory();

                    if (Convert.ToInt32(row.Flag_mri) == 0)
                    {
                        // --- approved samples with additional retest mark
                        row.Qaqc_has_retest = 1;
                        faBatch_detail_aa_twofold.Update(row);

                        // --- save retest
                        string cod_type_sample = new CTemplate_methodFactory().GetByPrimaryKey(new CTemplate_methodKeys(Convert.ToInt32(row.Idtemplate_method))).Cod_type_sample;
                        CCorrelative oCorrelative = new CCorrelativeFactory().GetByPrimaryKey(new CCorrelativeKeys(cod_type_sample));

                        CBatchManager oBatchManager = new CBatchManager();

                        oBatchManager.CallSaveFromRetestFullBatch(
                            Convert.ToInt32(row.Idtemplate_method),
                            Convert.ToInt64(row.Idrecep_sample),
                            Convert.ToInt64(row.Idrecep_sample_detail),
                            Convert.ToInt64(row.Idrecep_sample_detail_elem),
                            Convert.ToInt64(row.Cod_interno),
                            row.Cod_sample,
                            Comun.GetUser(),
                            oCorrelative,
                            row.Qaqc_par);

                        // --- register as finished trace process
                        CProcess_Sample_Manage.Finalize_process(Convert.ToInt64(row.Idrecep_sample_detail_elem), LimsProcess.PROCESS_IN_READING, LimsProcess.PROCESS_APPROVE_SAMPLES);
                    }
                }

                // --- modify the batch status, put in other process
                CProcess oProcess = new CProcessFactory().GetByPrimaryKey(new CProcessKeys(LimsProcess.PROCESS_APPROVE_SAMPLES));
                oBatch.Status_process = Convert.ToChar(LimsProcess.Status_Process.Waiting);
                oBatch.Cod_module = oProcess.Cod_module;
                oBatch.Cod_area = oProcess.Cod_area;
                oBatch.Cod_process = LimsProcess.PROCESS_APPROVE_SAMPLES;
                oBatch.User_approve_tray = Comun.GetUser();
                oBatch.Date_approve_tray = Comun.GetDate();
                faBatch.Update(oBatch);

                // --- register as finished trace batch
                Cprocess_Batch_Manage.Finalize_process(Idbatch, LimsProcess.PROCESS_IN_READING, LimsProcess.PROCESS_APPROVE_SAMPLES);

            }
            catch (Exception ex)
            {
                Comun.Save_log(ex.InnerException.ToString());
                throw new Exception("pivot data::approve::Error occured.", ex);
            }
        }
예제 #14
0
        public void RefreshQaqcSummary()
        {
            CBatch oBatch = new CBatchFactory().GetByPrimaryKey(new CBatchKeys(Idbatch));
            Absorbance = oBatch.Absorvance == null ? 0 : Convert.ToDecimal(oBatch.Absorvance);
            StdVerification = oBatch.Std_verification == null ? 0 : Convert.ToDecimal(oBatch.Std_verification);
            MriMeasured = oBatch.Mri_measured == null ? 0 : Convert.ToDecimal(oBatch.Mri_measured);
            LrbMeasured = oBatch.Lrb_measured == null ? 0 : Convert.ToDecimal(oBatch.Lrb_measured);

            // --- absorbance
            if (oBatch.Flag_correct_abs == null)
                ColorAbsorbance = Color.White;
            else if (oBatch.Flag_correct_abs == true)
                ColorAbsorbance = Comun.ColorVerde;
            else
                ColorAbsorbance = Comun.ColorRojo;

            // --- std
            if (oBatch.Flag_correct_std == null)
                ColorStd = Color.White;
            else if (oBatch.Flag_correct_std == true)
                ColorStd = Comun.ColorVerde;
            else
                ColorStd = Comun.ColorRojo;

            // --- mri
            if (oBatch.Flag_correct_mri == null)
                ColorMriMeasured = Color.White;
            else if (oBatch.Flag_correct_mri == true)
                ColorMriMeasured = Comun.ColorVerde;
            else
                ColorMriMeasured = Comun.ColorRojo;

            // --- lrb
            if (oBatch.Flag_correct_lrb == null)
                ColorLrbMeasured = Color.White;
            else if (oBatch.Flag_correct_lrb == true)
                ColorLrbMeasured = Comun.ColorVerde;
            else
                ColorLrbMeasured = Comun.ColorRojo;
        }
예제 #15
0
        public long?GetBatchAvailable(int p_idtemplate_method, bool p_flag_new, string p_user, long p_idbatch_origin)
        {
            #region codigo anterior
            ///TODO

            /*
             *          CREATE OR REPLACE FUNCTION public.sp_GetBatchAvailable(p_idtemplate_method int4, p_flag_new boolean, p_user varchar, p_idbatch_origin bigint)
             * returns int4
             * AS $$
             *      Declare v_NullIdBatch bigint;
             *      Declare v_idbatch bigint;
             *      declare v_name_batch varchar(30);
             *      declare v_num_tray bigint;
             *      declare v_status_batch bpchar;
             *      declare v_mri_value numeric(10,6);
             *      declare v_cod_module varchar;
             *      declare v_cod_process varchar;
             *      declare v_cod_area varchar;
             *      declare v_status_process char(1);
             *      declare v_NullIdTraceBatch bigint;
             *      declare v_date_out timestamp;
             *      declare v_trace_prev bigint;
             *      declare v_trace_next bigint;
             *      declare v_observation varchar;
             *      declare v_user varchar;
             *      declare v_date_in timestamp;
             * BEGIN
             *      -- get the current batch of template method
             *
             *      v_NullIdBatch = 0;
             *      v_num_tray = COALESCE((SELECT MAX(num_tray)
             *                              FROM batch
             *                              ), 0)+1;
             *
             *      v_idbatch = 0;
             *      v_cod_module = 'M002';
             *      v_cod_process = 'P013';
             *      v_cod_area = 'A004';
             *      v_status_process = 'W';
             *      v_date_out = null;
             *      v_trace_prev = null;
             *      v_trace_next = null;
             *      v_observation = null;
             *      v_user = null;
             *      v_date_in = current_timestamp;
             *
             *      --
             *      SELECT INTO v_idbatch COALESCE(A.idbatch, 0)
             *      FROM (SELECT DISTINCT t1.idbatch, t2.idrecep_sample_detail,
             *                      t2.idtemplate_method, t3.limit_samples
             *              FROM batch t1
             *                      INNER JOIN batch_detail_aa_twofold t2 on t1.idbatch = t2.idbatch
             *                      INNER JOIN template_method t3 on t1.idtemplate_method = t3.idtemplate_method
             *              WHERE t1.cod_process = v_cod_process
             *                      AND t1.idtemplate_method = p_idtemplate_method
             *                      AND t1.idbatch <> p_idbatch_origin
             *                      AND t1.status_process = v_status_process) A
             *      GROUP BY A.idbatch, A.limit_samples
             *      HAVING count(*) < A.limit_samples;
             *
             *      -- get one name for the batch
             *      SELECT INTO v_name_batch, v_mri_value t3.abbreviation, t2.nominal_value
             *      FROM template_method_aa t1
             *              INNER JOIN mr_detail t2
             *                      ON t1.idmr_detail = t2.idmr_detail
             *                              AND t1.idtemplate_method = p_idtemplate_method
             *              INNER JOIN template_method t3
             *                      ON t1.idtemplate_method = t3.idtemplate_method
             *      WHERE t1.idtemplate_method = p_idtemplate_method;
             *
             *      IF (p_flag_new = true) THEN
             *              -- create a new batch
             *              v_idbatch  = (SELECT public.sp_batch_Insert(v_NullIdBatch,v_name_batch,v_num_tray,p_idtemplate_method,v_cod_module,v_cod_process,v_cod_area,v_status_process,true,v_mri_value, '', v_date_out, p_user, false));
             *
             *              -- save trace
             *              -- antes de insertar, si es ultima muestra y contiene mri no insertar
             *
             *              PERFORM public.sp_trace_batch_insert(v_NullIdTraceBatch, v_cod_module, v_cod_process, v_cod_area, v_idbatch, v_date_in, v_date_out, v_status_process, v_trace_prev, v_trace_next, v_observation, p_user, v_date_in, v_user, v_date_in, true);
             *      ELSE
             *              -- create new batch, if not exists batch in wait
             *              IF (v_idbatch = 0 or v_idbatch is null)
             *              THEN
             *                      -- create a new batch
             *                      v_idbatch = (SELECT public.sp_batch_Insert(v_NullIdBatch, v_name_batch, v_num_tray, p_idtemplate_method, v_cod_module, v_cod_process, v_cod_area, v_status_process, true, v_mri_value, '', v_date_out, p_user, false));
             *
             *                      -- save trace
             *                      PERFORM public.sp_trace_batch_insert(v_NullIdTraceBatch, v_cod_module, v_cod_process, v_cod_area, v_idbatch, v_date_in, v_date_out, v_status_process, v_trace_prev, v_trace_next, v_observation, p_user, v_date_in, v_user, v_date_in, true);
             *              END IF;
             *      END IF;
             *      return v_idbatch;
             *
             * END;*/

            #endregion

            var query =
                (from m in new CBatchFactory()
                 .GetAll()
                 .Where(x => x.Idbatch != p_idbatch_origin &&
                        x.Idtemplate_method == p_idtemplate_method &&
                        x.Status_process == 'W')
                 from n in new CBatch_detail_aa_twofoldFactory().GetAll().Where(x => x.Idbatch == m.Idbatch)
                 from p in new CTemplate_methodFactory().GetAll().Where(x => x.Idtemplate_method == m.Idtemplate_method)
                 from q in new CTemplate_method_aaFactory().GetAll().Where(x => x.Idtemplate_method == m.Idtemplate_method)
                 select new
                 { m.Idbatch, n.Idrecep_sample_detail, n.Idtemplate_method, q.Limit_samples }).ToList();

            var query2 =
                (from m in query
                 group m by new { m.Idbatch, m.Limit_samples }
                 into grp
                 where grp.Count() < grp.Key.Limit_samples
                 select new
            {
                Idbatch = grp.Key == null ? 0 : grp.Key.Idbatch
            }).ToList();

            var query3 =
                (from m in new CTemplate_method_aaFactory().GetAll().Where(x => x.Idtemplate_method == p_idtemplate_method)
                 join n in new CMr_detailFactory().GetAll() on m.Idmr_detail equals n.Idmr_detail
                 join p in new CTemplate_methodFactory().GetAll() on m.Idtemplate_method equals p.Idtemplate_method
                 select new
            {
                name_batch = p.Abbreviation,
                mri_value = n.Nominal_value
            }).ToList();

            string  name_batch = query3.FirstOrDefault().name_batch;
            decimal?mri_value  = query3.FirstOrDefault().mri_value;
            long?   num_tray   = new CBatchFactory().GetAll().Max(x => x.Num_tray) == null ? 0 : 1;

            long?idbatch = null;
            if (p_flag_new)
            {
                //save batch
                CBatch batch = new CBatch()
                {
                    Num_tray           = num_tray,
                    Idtemplate_method  = p_idtemplate_method,
                    Cod_module         = "M002",
                    Cod_process        = "P013",
                    Cod_area           = "A004",
                    Status_process     = 'W',
                    Status             = true,
                    Mri_value          = mri_value,
                    Description        = "",
                    Date_creation_tray = null,
                    User_creation_tray = p_user,
                    Has_sample_control = true
                };

                new CBatchFactory().Insert(batch);
                idbatch = batch.Idbatch;

                //save trace
                CTrace_batch trace_batch = new CTrace_batch()
                {
                    Cod_module     = "M002",
                    Cod_process    = "P013",
                    Cod_area       = "A004",
                    Idbatch        = batch.Idbatch,
                    Date_in        = DateTime.Now,
                    Status_process = 'W',
                    Usernew        = p_user,
                    Useredit       = p_user,
                    Status         = true
                };
            }
            else
            {
                if (idbatch == null || idbatch == 0)
                {
                    CBatch batch = new CBatch()
                    {
                        Name_batch         = name_batch,
                        Num_tray           = num_tray,
                        Idtemplate_method  = p_idtemplate_method,
                        Cod_module         = "M002",
                        Cod_process        = "P013",
                        Cod_area           = "A004",
                        Status_process     = 'W',
                        Status             = true,
                        Mri_value          = mri_value,
                        Description        = "",
                        Date_creation_tray = null,
                        User_creation_tray = p_user,
                        Has_sample_control = false
                    };

                    new CBatchFactory().Insert(batch);
                    idbatch = batch.Idbatch;

                    //save trace
                    CTrace_batch trace_batch = new CTrace_batch()
                    {
                        Cod_module     = "M002",
                        Cod_process    = "P013",
                        Cod_area       = "A004",
                        Idbatch        = batch.Idbatch,
                        Date_in        = DateTime.Now,
                        Status_process = 'W',
                        Usernew        = p_user,
                        Useredit       = p_user,
                        Status         = true
                    };
                }
            }
            return(idbatch);
        }
예제 #16
0
        private void SaveInBatch(CBatch_detail_aa_twofold oBatch_detail_aa_twofold, string user)
        {
            // --- get batch
            int idtemplate_method = Convert.ToInt32(oBatch_detail_aa_twofold.Idtemplate_method);

            long origin_batch = -1;

            if (Enabled_retest)
            {
                origin_batch = Convert.ToInt64(oRetest.Origin_batch);
            }

            long idbatch = Convert.ToInt64(GetBatchAvailable(idtemplate_method, user, origin_batch));

            CBatch oBatch = new CBatchFactory().GetByPrimaryKey(new CBatchKeys(idbatch));

            int num_free_places = GetNumFreePlacesInBatch(idbatch, idtemplate_method);

            if (num_free_places >= 1)
            {
                if (!Convert.ToBoolean(oBatch.Has_sample_control)) // batch no tiene mri
                {
                    long index_mri = GetIndexMriPredecessor(idbatch, Convert.ToInt64(oBatch_detail_aa_twofold.Cod_interno));

                    if (index_mri > 0)// --- el batch no tiene mri y en sus predecesores debe existir uno
                    {
                        if (num_free_places >= 2)
                        {
                            // --- insert mri
                            control_sample.Cod_interno = index_mri;
                            control_sample.Idbatch     = idbatch;
                            control_sample.Cod_sample  = Comun.FormatCorrelativeCode(Correlative.Prefix + Correlative.Cod_serie, index_mri, Convert.ToInt32(Correlative.Num_digits));
                            if (faBatch_detail_aa_twofold.Insert(control_sample))
                            {
                                oBatch.Has_sample_control = true;
                                new CBatchFactory().Update(oBatch);
                            }

                            // --- insert sample
                            CBatch_detail_aa_twofoldFactory faBatch_detail_aa_towfold = new CBatch_detail_aa_twofoldFactory();
                            oBatch_detail_aa_twofold.Idbatch = idbatch;
                            faBatch_detail_aa_towfold.Insert(oBatch_detail_aa_twofold);
                            SaveRetest(idbatch);
                        }
                        if (num_free_places == 1)
                        {
                            // --- insert mri
                            control_sample.Cod_interno = index_mri;
                            control_sample.Idbatch     = idbatch;
                            control_sample.Cod_sample  = Comun.FormatCorrelativeCode(Correlative.Prefix + Correlative.Cod_serie, index_mri, Convert.ToInt32(Correlative.Num_digits));
                            if (faBatch_detail_aa_twofold.Insert(control_sample))
                            {
                                oBatch.Has_sample_control = true;
                                new CBatchFactory().Update(oBatch);
                            }

                            // --- search batch to sample
                            SaveInBatch(oBatch_detail_aa_twofold, user);
                        }
                    }
                    else // --- index_mri = 0; entonces la bandeja no lleva mri
                    {
                        oBatch_detail_aa_twofold.Idbatch = idbatch;
                        faBatch_detail_aa_twofold.Insert(oBatch_detail_aa_twofold);
                        SaveRetest(idbatch);
                    }
                }
                else
                {
                    oBatch_detail_aa_twofold.Idbatch = idbatch;
                    faBatch_detail_aa_twofold.Insert(oBatch_detail_aa_twofold);
                    SaveRetest(idbatch);
                }
            }
        }