Exemple #1
0
        protected override void Recuperar_Registro()
        {
            try
            {
                // --- recuperate head
                if (IDTemplate_Method > 0)
                {
                    // --- recuperate head

                    CTemplate_methodFactory faTemplate_Method = new CTemplate_methodFactory();
                    CTemplate_method        oTemplate_Method  = faTemplate_Method.GetByPrimaryKey(new CTemplate_methodKeys(IDTemplate_Method));
                    gluCod_method.EditValue  = oTemplate_Method.Cod_template_method;
                    Num_version              = Convert.ToInt16(oTemplate_Method.Num_version);
                    tbTitle.Text             = oTemplate_Method.Title;
                    laTitulo.Text            = string.Format("Metodo ({0}-{1})", oTemplate_Method.Num_version, oTemplate_Method.Useredit);
                    cbDigestion.EditValue    = oTemplate_Method.Cod_digestion_method;
                    tbCost_Method.Value      = Convert.ToDecimal(oTemplate_Method.Cost_method);
                    tbAbreviation.Text       = oTemplate_Method.Abbreviation;
                    ckRecognized.Checked     = Convert.ToBoolean(oTemplate_Method.Recognized);
                    cbTypeSample.EditValue   = oTemplate_Method.Cod_type_sample;
                    cbElement.EditValue      = Convert.ToInt16(oTemplate_Method.Idelement);
                    cbTypeAnalysis.EditValue = null;
                    cbTypeAnalysis.EditValue = oTemplate_Method.Type_analisys; //recupera el tipo de analisis
                    cbRepetition.EditValue   = oTemplate_Method.Cod_repetition;
                }
            }
            catch (Exception ex)
            {
                ComunForm.Send_message(this.Text, TypeMsg.error, ex.Message);
            }
        }
Exemple #2
0
        Comun.MethodSaveProperty GetResultTestHeader()
        {
            // --- registro anterior
            if (IDTemplate_Method <= 0)
            {
                return(Comun.MethodSaveProperty.NewMethod);
            }
            else
            {
                CTemplate_methodFactory faTemplate_method = new CTemplate_methodFactory();
                CTemplate_method        oTemplate_method  = new CTemplate_method();
                oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(IDTemplate_Method));

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

                // --- change inside head, require new method
                if (oTemplate_method.Idelement != Convert.ToInt16(cbElement.EditValue))
                {
                    return(Comun.MethodSaveProperty.InspectionNewMethod);
                }
                if (oTemplate_method.Cod_type_sample != cbTypeSample.EditValue.ToString())
                {
                    return(Comun.MethodSaveProperty.InspectionNewMethod);
                }
                if (oTemplate_method.Type_analisys != Convert.ToChar(cbTypeAnalysis.EditValue))
                {
                    return(Comun.MethodSaveProperty.InspectionNewMethod);
                }
                if (oTemplate_method.Cod_template_method != gluCod_method.Text)
                {
                    return(Comun.MethodSaveProperty.InspectionNewMethod);
                }
                //if (oTemplate_method.Abbreviation != tbAbreviation.Text)
                //    return Comun.MethodSaveProperty.InspectionNewMethod;
                //if (oTemplate_method.Title != tbTitle.Text)
                //    return Comun.MethodSaveProperty.InspectionNewMethod;
                //if (oTemplate_method.Recognized != ckRecognized.Checked)
                //    return Comun.MethodSaveProperty.InspectionNewMethod;
                if (oTemplate_method.Cod_digestion_method != cbDigestion.EditValue.ToString())
                {
                    return(Comun.MethodSaveProperty.InspectionNewMethod);
                }
                //if (Convert.ToDecimal(oTemplate_method.Cost_method) != tbCost_Method.Value)
                //    return Comun.MethodSaveProperty.InspectionNewMethod;
                if (Convert.ToInt16(oTemplate_method.Cod_repetition) != Convert.ToInt16(cbRepetition.EditValue))
                {
                    return(Comun.MethodSaveProperty.InspectionNewMethod);
                }

                return(Comun.MethodSaveProperty.Nothing);
            }
        }
Exemple #3
0
        void FilterByCodMethod()
        {
            CTemplate_methodFactory faTemplate_Method = new CTemplate_methodFactory();

            IDTemplate_Method = Convert.ToInt32(gluCod_method.EditValue);
            CTemplate_method oTemplate_Method = faTemplate_Method.GetByPrimaryKey(new CTemplate_methodKeys(IDTemplate_Method));

            if (oTemplate_Method != null)
            {
                cbElement.EditValue      = Convert.ToInt16(oTemplate_Method.Idelement);
                cbTypeSample.EditValue   = oTemplate_Method.Cod_type_sample;
                cbTypeAnalysis.EditValue = oTemplate_Method.Type_analisys;
            }
        }
Exemple #4
0
        Comun.MethodSaveProperty GetResultTestHeader()
        {
            // --- registro anterior
            if (IDTemplate_Method <= 0)
            {
                return Comun.MethodSaveProperty.NewMethod;
            }
            else
            {
                CTemplate_methodFactory faTemplate_method = new CTemplate_methodFactory();
                CTemplate_method oTemplate_method = new CTemplate_method();
                oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(IDTemplate_Method));

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

                // --- change inside head, require new method
                if (oTemplate_method.Idelement != Convert.ToInt16(cbElement.EditValue))
                    return Comun.MethodSaveProperty.InspectionNewMethod;
                if (oTemplate_method.Cod_type_sample != cbTypeSample.EditValue.ToString())
                    return Comun.MethodSaveProperty.InspectionNewMethod;
                if (oTemplate_method.Type_analisys != Convert.ToChar(cbTypeAnalysis.EditValue))
                    return Comun.MethodSaveProperty.InspectionNewMethod;
                if (oTemplate_method.Cod_template_method != gluCod_method.Text)
                    return Comun.MethodSaveProperty.InspectionNewMethod;
                //if (oTemplate_method.Abbreviation != tbAbreviation.Text)
                //    return Comun.MethodSaveProperty.InspectionNewMethod;
                //if (oTemplate_method.Title != tbTitle.Text)
                //    return Comun.MethodSaveProperty.InspectionNewMethod;
                //if (oTemplate_method.Recognized != ckRecognized.Checked)
                //    return Comun.MethodSaveProperty.InspectionNewMethod;
                if (oTemplate_method.Cod_digestion_method != cbDigestion.EditValue.ToString())
                    return Comun.MethodSaveProperty.InspectionNewMethod;
                //if (Convert.ToDecimal(oTemplate_method.Cost_method) != tbCost_Method.Value)
                //    return Comun.MethodSaveProperty.InspectionNewMethod;
                if (Convert.ToInt16(oTemplate_method.Cod_repetition) != Convert.ToInt16(cbRepetition.EditValue))
                    return Comun.MethodSaveProperty.InspectionNewMethod;

                return Comun.MethodSaveProperty.Nothing;
            }
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
0
        void LoadQaqcStatus()
        {
            if (TypeSample == Comun.TypeSample.Sample)
            {

                // --- get repetitions
                repRepetition.DataSource = Comun.ListTypeRepetition;
                repRepetition.DisplayMember = "Name_repetition";
                repRepetition.ValueMember = "Cod_repetition";

                // --- get methods
                CTemplate_methodFactory faTemplate_method = new CTemplate_methodFactory();
                CTemplate_method oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));
                Methods oMethods = new Methods();

                gcMethods.DataSource = oMethods.GetAllLastVersionMethods(Convert.ToInt32(oTemplate_method.Idelement), oTemplate_method.Cod_type_sample);

                // --- assign to popup controls
                // observation
                Idtemplate_method = Convert.ToInt32(gvMethods.GetFocusedRowCellValue(gcMet_Idtemplate_method));
                tbObservation.Text = Text_obs;

                // method
                if (Idretest > 0)
                {
                    faTemplate_method = new CTemplate_methodFactory();
                    oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idretest));

                    tbCod_method.Text = oTemplate_method.Cod_template_method;
                    tbAbbrevMethod.Text = oTemplate_method.Abbreviation;
                    ckEnableRetest.Checked = true;
                }
                else
                {
                    faTemplate_method = new CTemplate_methodFactory();
                    oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));

                    tbCod_method.Text = oTemplate_method.Cod_template_method;
                    tbAbbrevMethod.Text = oTemplate_method.Abbreviation;
                    ckEnableRetest.Checked = false;
                    ckChangeMethod.Checked = false;
                }

                // --- get retest
                #region codigo anterior

                /*
                 CREATE OR REPLACE FUNCTION public.sp_retest_getBySample(p_idrecep_sample_detail_elem bigint, p_idbatch bigint) 
                returns TABLE ("Idbatch" BIGINT, "Num_tray" VARCHAR, "Idrecep_sample_detail_elem" BIGINT, "Idrecep_sample_detail" BIGINT
                ,"Cod_module" VARCHAR, "Cod_process" VARCHAR, "Status_process" CHAR, "Result_analysis" DECIMAL
                , "Str_result_analysis" VARCHAR, "Status_result" int, "Cod_sample" VARCHAR
                , "Flag_current_batch" boolean 
                )AS $$
                BEGIN
	                -- 
	                CREATE TEMP TABLE tmp_batch ON COMMIT DROP AS
	                SELECT origin_batch as idbatch, idrecep_sample_detail_elem, idrecep_sample_detail
	                FROM retest
	                WHERE (origin_batch = p_idbatch OR destiny_batch = p_idbatch)
	                UNION ALL
	                SELECT destiny_batch as idbatch, idrecep_sample_detail_elem, idrecep_sample_detail
	                FROM retest
	                WHERE (destiny_batch = p_idbatch OR origin_batch = p_idbatch);	

	                RETURN QUERY
	                SELECT DISTINCT t1.idbatch, CAST(LPAD(CAST(t2.num_tray AS VARCHAR), 5, '0') AS VARCHAR), t1.idrecep_sample_detail_elem, t4.idrecep_sample_detail
		                , t2.cod_module, t2.cod_process, t2.status_process, t3.result_analysis
		                , t3.str_result_analysis, COALESCE(CAST(t3.Qaqc_status_result AS INT), 0) as ER, t3.cod_sample		                
		                , CAST(CASE
			                WHEN t1.idbatch = p_idbatch THEN 1
			                ELSE 0
		                  END AS BOOLEAN) AS flag_current_batch		
	                FROM tmp_batch t1
		                INNER JOIN batch t2
			                ON t1.idbatch = t2.idbatch
		                LEFT OUTER JOIN batch_detail_aa_twofold t3
			                ON t2.idbatch = t3.idbatch
			                AND t1.idrecep_sample_detail_elem = t3.idrecep_sample_detail_elem
		                LEFT OUTER JOIN recep_sample_detail t4
			                ON t1.idrecep_sample_detail = t4.idrecep_sample_detail
	                WHERE t1.idrecep_sample_detail_elem = p_idrecep_sample_detail_elem;

                END;
                $$ LANGUAGE plpgsql; 
                */

                #endregion 

                var tmp_batch =
                    (from m in new CRetestFactory().GetAll().Where(x => x.Origin_batch == Idbatch || x.Destiny_batch == Idbatch)
                     select new { idbatch = m.Origin_batch, m.Idrecep_sample_detail_elem, m.Idrecep_sample_detail })
                     .Union(from m in new CRetestFactory().GetAll().Where(x => x.Destiny_batch == Idbatch || x.Origin_batch == Idbatch)
                            select new { idbatch = m.Destiny_batch, m.Idrecep_sample_detail_elem, m.Idrecep_sample_detail });

                var query2 =
                    (from m in tmp_batch.Where(x => x.Idrecep_sample_detail_elem == Idrecep_sample_detail_elem)
                     from n in new CBatchFactory().GetAll().Where(x => x.Idbatch == m.idbatch)
                     join p in new CBatch_detail_aa_twofoldFactory().GetAll()
                        on new { field1 = m.idbatch, field2 = m.Idrecep_sample_detail_elem } 
                            equals new { field1 = p.Idbatch, field2 = p.Idrecep_sample_detail_elem } into np
                     from q in np.DefaultIfEmpty()
                     join r in new CRecep_sample_detailFactory().GetAll()
                        on q.Idrecep_sample_detail equals r.Idrecep_sample_detail into qr
                     from s in qr
                     select new
                     {
                         m.idbatch,
                         Num_tray = n.Num_tray.ToString().PadLeft(5, '0'),
                         m.Idrecep_sample_detail_elem,
                         m.Idrecep_sample_detail,
                         n.Cod_module,
                         n.Cod_process,
                         n.Status_process,
                         q.Result_analysis,
                         q.Str_result_analysis,
                         Status_result = q == null ? 0 : q.Qaqc_status_result,
                         q.Cod_sample,
                         Flag_current_batch = m.idbatch == Idbatch ? true : false
                     }).Distinct();

                gcListRetest.DataSource = query2;

                Show_controls(Windows_current);
            }
            else
            {
                // --- reensayo de muestras de control de encontrar algún error
                gcObservation.Visible = false;
                ckEnableRetest.Visible = false;
                xtraTabControl1.TabPages[0].Text = "Reensayo de Bandeja";
                xtraTabControl1.TabPages[1].PageVisible = false;

                // --- get repetitions
                repRepetition.DataSource = Comun.ListTypeRepetition;
                repRepetition.DisplayMember = "Name_repetition";
                repRepetition.ValueMember = "Cod_repetition";

                // --- get methods
                CTemplate_methodFactory faTemplate_method = new CTemplate_methodFactory();
                CTemplate_method oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));
                Methods oMethods = new Methods();

                gcMethods.DataSource = oMethods.GetAllLastVersionMethods(Convert.ToInt32(oTemplate_method.Idelement), oTemplate_method.Cod_type_sample);

                // --- assign to popup controls
                // observation
                Idtemplate_method = Convert.ToInt32(gvMethods.GetFocusedRowCellValue(gcMet_Idtemplate_method));
                tbObservation.Text = Text_obs;

                // method
                faTemplate_method = new CTemplate_methodFactory();
                oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));

                tbCod_method.Text = oTemplate_method.Cod_template_method;
                tbAbbrevMethod.Text = oTemplate_method.Abbreviation;
                ckEnableRetest.Checked = true;
                ckChangeMethod.Checked = false;
                ckEnableRetest.Visible = false;
            }
        }
Exemple #8
0
        void LoadQaqcStatus()
        {
            if (TypeSample == Comun.TypeSample.Sample)
            {

                // --- get repetitions
                repRepetition.DataSource = Comun.ListTypeRepetition;
                repRepetition.DisplayMember = "Name_repetition";
                repRepetition.ValueMember = "Cod_repetition";

                // --- get methods
                CTemplate_methodFactory faTemplate_method = new CTemplate_methodFactory();
                CTemplate_method oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));
                Methods oMethods = new Methods();

                gcMethods.DataSource = oMethods.GetAllLastVersionMethods(Convert.ToInt32(oTemplate_method.Idelement), oTemplate_method.Cod_type_sample);

                // --- assign to popup controls
                // observation
                Idtemplate_method = Convert.ToInt32(gvMethods.GetFocusedRowCellValue(gcMet_Idtemplate_method));
                tbObservation.Text = Text_obs;

                // method
                if (Idretest > 0)
                {
                    faTemplate_method = new CTemplate_methodFactory();
                    oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idretest));

                    tbCod_method.Text = oTemplate_method.Cod_template_method;
                    tbAbbrevMethod.Text = oTemplate_method.Abbreviation;
                    ckEnableRetest.Checked = true;
                }
                else
                {
                    faTemplate_method = new CTemplate_methodFactory();
                    oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));

                    tbCod_method.Text = oTemplate_method.Cod_template_method;
                    tbAbbrevMethod.Text = oTemplate_method.Abbreviation;
                    ckEnableRetest.Checked = false;
                    ckChangeMethod.Checked = false;
                }

                // --- get retest
                #region codigo anterior

                /*
                 CREATE OR REPLACE FUNCTION public.sp_retest_getBySample(p_idrecep_sample_detail_elem bigint, p_idbatch bigint)
                returns TABLE ("Idbatch" BIGINT, "Num_tray" VARCHAR, "Idrecep_sample_detail_elem" BIGINT, "Idrecep_sample_detail" BIGINT
                ,"Cod_module" VARCHAR, "Cod_process" VARCHAR, "Status_process" CHAR, "Result_analysis" DECIMAL
                , "Str_result_analysis" VARCHAR, "Status_result" int, "Cod_sample" VARCHAR
                , "Flag_current_batch" boolean
                )AS $$
                BEGIN
                    --
                    CREATE TEMP TABLE tmp_batch ON COMMIT DROP AS
                    SELECT origin_batch as idbatch, idrecep_sample_detail_elem, idrecep_sample_detail
                    FROM retest
                    WHERE (origin_batch = p_idbatch OR destiny_batch = p_idbatch)
                    UNION ALL
                    SELECT destiny_batch as idbatch, idrecep_sample_detail_elem, idrecep_sample_detail
                    FROM retest
                    WHERE (destiny_batch = p_idbatch OR origin_batch = p_idbatch);

                    RETURN QUERY
                    SELECT DISTINCT t1.idbatch, CAST(LPAD(CAST(t2.num_tray AS VARCHAR), 5, '0') AS VARCHAR), t1.idrecep_sample_detail_elem, t4.idrecep_sample_detail
                        , t2.cod_module, t2.cod_process, t2.status_process, t3.result_analysis
                        , t3.str_result_analysis, COALESCE(CAST(t3.Qaqc_status_result AS INT), 0) as ER, t3.cod_sample
                        , CAST(CASE
                            WHEN t1.idbatch = p_idbatch THEN 1
                            ELSE 0
                          END AS BOOLEAN) AS flag_current_batch
                    FROM tmp_batch t1
                        INNER JOIN batch t2
                            ON t1.idbatch = t2.idbatch
                        LEFT OUTER JOIN batch_detail_aa_twofold t3
                            ON t2.idbatch = t3.idbatch
                            AND t1.idrecep_sample_detail_elem = t3.idrecep_sample_detail_elem
                        LEFT OUTER JOIN recep_sample_detail t4
                            ON t1.idrecep_sample_detail = t4.idrecep_sample_detail
                    WHERE t1.idrecep_sample_detail_elem = p_idrecep_sample_detail_elem;

                END;
                $$ LANGUAGE plpgsql;
                */

                #endregion

                var tmp_batch =
                    (from m in new CRetestFactory().GetAll().Where(x => x.Origin_batch == Idbatch || x.Destiny_batch == Idbatch)
                     select new { idbatch = m.Origin_batch, m.Idrecep_sample_detail_elem, m.Idrecep_sample_detail })
                     .Union(from m in new CRetestFactory().GetAll().Where(x => x.Destiny_batch == Idbatch || x.Origin_batch == Idbatch)
                            select new { idbatch = m.Destiny_batch, m.Idrecep_sample_detail_elem, m.Idrecep_sample_detail });

                var query2 =
                    (from m in tmp_batch.Where(x => x.Idrecep_sample_detail_elem == Idrecep_sample_detail_elem)
                     from n in new CBatchFactory().GetAll().Where(x => x.Idbatch == m.idbatch)
                     join p in new CBatch_detail_aa_twofoldFactory().GetAll()
                        on new { field1 = m.idbatch, field2 = m.Idrecep_sample_detail_elem }
                            equals new { field1 = p.Idbatch, field2 = p.Idrecep_sample_detail_elem } into np
                     from q in np.DefaultIfEmpty()
                     join r in new CRecep_sample_detailFactory().GetAll()
                        on q.Idrecep_sample_detail equals r.Idrecep_sample_detail into qr
                     from s in qr
                     select new
                     {
                         m.idbatch,
                         Num_tray = n.Num_tray.ToString().PadLeft(5, '0'),
                         m.Idrecep_sample_detail_elem,
                         m.Idrecep_sample_detail,
                         n.Cod_module,
                         n.Cod_process,
                         n.Status_process,
                         q.Result_analysis,
                         q.Str_result_analysis,
                         Status_result = q == null ? 0 : q.Qaqc_status_result,
                         q.Cod_sample,
                         Flag_current_batch = m.idbatch == Idbatch ? true : false
                     }).Distinct();

                gcListRetest.DataSource = query2;

                Show_controls(Windows_current);
            }
            else
            {
                // --- reensayo de muestras de control de encontrar algún error
                gcObservation.Visible = false;
                ckEnableRetest.Visible = false;
                xtraTabControl1.TabPages[0].Text = "Reensayo de Bandeja";
                xtraTabControl1.TabPages[1].PageVisible = false;

                // --- get repetitions
                repRepetition.DataSource = Comun.ListTypeRepetition;
                repRepetition.DisplayMember = "Name_repetition";
                repRepetition.ValueMember = "Cod_repetition";

                // --- get methods
                CTemplate_methodFactory faTemplate_method = new CTemplate_methodFactory();
                CTemplate_method oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));
                Methods oMethods = new Methods();

                gcMethods.DataSource = oMethods.GetAllLastVersionMethods(Convert.ToInt32(oTemplate_method.Idelement), oTemplate_method.Cod_type_sample);

                // --- assign to popup controls
                // observation
                Idtemplate_method = Convert.ToInt32(gvMethods.GetFocusedRowCellValue(gcMet_Idtemplate_method));
                tbObservation.Text = Text_obs;

                // method
                faTemplate_method = new CTemplate_methodFactory();
                oTemplate_method = faTemplate_method.GetByPrimaryKey(new CTemplate_methodKeys(Idtemplate_method));

                tbCod_method.Text = oTemplate_method.Cod_template_method;
                tbAbbrevMethod.Text = oTemplate_method.Abbreviation;
                ckEnableRetest.Checked = true;
                ckChangeMethod.Checked = false;
                ckEnableRetest.Visible = false;
            }
        }