Example #1
0
        // *************************** IMPORT: SAMPLE    ******************************
        // *****************************************************************************
        public static int InsertOrUpdateWQX_IMPORT_TEMP_SAMPLE(global::System.Int32? tEMP_SAMPLE_IDX, string uSER_ID, global::System.String oRG_ID, global::System.Int32? pROJECT_IDX,
            string pROJECT_ID, global::System.Int32? mONLOC_IDX, string mONLOC_ID, global::System.Int32? aCTIVITY_IDX, global::System.String aCTIVITY_ID,
            global::System.String aCT_TYPE, global::System.String aCT_MEDIA, global::System.String aCT_SUBMEDIA, global::System.DateTime? aCT_START_DT, global::System.DateTime? aCT_END_DT,
            global::System.String aCT_TIME_ZONE, global::System.String rELATIVE_DEPTH_NAME, global::System.String aCT_DEPTHHEIGHT_MSR, global::System.String aCT_DEPTHHEIGHT_MSR_UNIT,
            global::System.String tOP_DEPTHHEIGHT_MSR, global::System.String tOP_DEPTHHEIGHT_MSR_UNIT, global::System.String bOT_DEPTHHEIGHT_MSR, global::System.String bOT_DEPTHHEIGHT_MSR_UNIT,
            global::System.String dEPTH_REF_POINT, global::System.String aCT_COMMENT, global::System.String bIO_ASSEMBLAGE_SAMPLED, global::System.String bIO_DURATION_MSR,
            global::System.String bIO_DURATION_MSR_UNIT, global::System.String bIO_SAMP_COMPONENT, int? bIO_SAMP_COMPONENT_SEQ, global::System.String bIO_REACH_LEN_MSR,
            global::System.String bIO_REACH_LEN_MSR_UNIT, global::System.String bIO_REACH_WID_MSR, global::System.String bIO_REACH_WID_MSR_UNIT, int? bIO_PASS_COUNT,
            global::System.String bIO_NET_TYPE, global::System.String bIO_NET_AREA_MSR, global::System.String bIO_NET_AREA_MSR_UNIT, global::System.String bIO_NET_MESHSIZE_MSR,
            global::System.String bIO_MESHSIZE_MSR_UNIT, global::System.String bIO_BOAT_SPEED_MSR, global::System.String bIO_BOAT_SPEED_MSR_UNIT, global::System.String bIO_CURR_SPEED_MSR,
            global::System.String bIO_CURR_SPEED_MSR_UNIT, global::System.String bIO_TOXICITY_TEST_TYPE, int? sAMP_COLL_METHOD_IDX, global::System.String sAMP_COLL_METHOD_ID,
            global::System.String sAMP_COLL_METHOD_CTX, global::System.String sAMP_COLL_METHOD_NAME, global::System.String sAMP_COLL_EQUIP, global::System.String sAMP_COLL_EQUIP_COMMENT,
            int? sAMP_PREP_IDX, global::System.String sAMP_PREP_ID, global::System.String sAMP_PREP_CTX, global::System.String sAMP_PREP_NAME,
            global::System.String sAMP_PREP_CONT_TYPE, global::System.String sAMP_PREP_CONT_COLOR, global::System.String sAMP_PREP_CHEM_PRESERV,
            global::System.String sAMP_PREP_THERM_PRESERV, global::System.String sAMP_PREP_STORAGE_DESC, string sTATUS_CD, string sTATUS_DESC, bool BioIndicator, Boolean autoImportRefDataInd)
        {
            try
            {
                using (OpenEnvironmentEntities ctx = new OpenEnvironmentEntities())
                {
                    Boolean insInd = false;

                    //******************* GET STARTING RECORD *************************************************
                    T_WQX_IMPORT_TEMP_SAMPLE a;
                    if (tEMP_SAMPLE_IDX != null)  //grab from IDX if given
                        a = (from c in ctx.T_WQX_IMPORT_TEMP_SAMPLE
                             where c.TEMP_SAMPLE_IDX == tEMP_SAMPLE_IDX
                             select c).FirstOrDefault();
                    else  //check if existing activity ID exists in the import
                    {
                        a = (from c in ctx.T_WQX_IMPORT_TEMP_SAMPLE
                             where c.ACTIVITY_ID == aCTIVITY_ID
                             && c.ORG_ID == oRG_ID
                             select c).FirstOrDefault();
                    }

                    //if can't find a match based on supplied IDX or ID, then create a new record
                    if (a == null)
                    {
                        insInd = true;
                        a = new T_WQX_IMPORT_TEMP_SAMPLE();
                    }
                    //********************** END GET STARTING RECORD ************************************************

                    if (!string.IsNullOrEmpty(uSER_ID)) a.USER_ID = uSER_ID;
                    if (!string.IsNullOrEmpty(oRG_ID)) a.ORG_ID = oRG_ID;

                    //PROJECT HANDLING
                    if (pROJECT_IDX == null && pROJECT_ID == null) { sTATUS_CD = "F"; sTATUS_DESC += "Project ID must be provided. "; }
                    if (pROJECT_IDX != null) a.PROJECT_IDX = pROJECT_IDX;

                    if (pROJECT_ID != null)
                    {
                        a.PROJECT_ID = pROJECT_ID.Trim().SubStringPlus(0, 35);

                        T_WQX_PROJECT ptemp = db_WQX.GetWQX_PROJECT_ByIDString(pROJECT_ID, oRG_ID);
                        if (ptemp == null) { sTATUS_CD = "F"; sTATUS_DESC += "Project ID does not exist. Create project first."; }
                        else { a.PROJECT_IDX = ptemp.PROJECT_IDX; }
                    }

                    //MONITORING LOCATION HANDLING
                    if (mONLOC_IDX == null && mONLOC_ID == null) { sTATUS_CD = "F"; sTATUS_DESC += "Monitoring Location ID must be provided. "; }
                    if (mONLOC_IDX != null) a.MONLOC_IDX = mONLOC_IDX;

                    if (mONLOC_ID != null)
                    {
                        a.MONLOC_ID = mONLOC_ID.Trim().SubStringPlus(0, 35);

                        T_WQX_MONLOC mm = db_WQX.GetWQX_MONLOC_ByIDString(oRG_ID, mONLOC_ID);
                        if (mm == null) { sTATUS_CD = "F"; sTATUS_DESC += "Monitoring Location ID does not exist. Import MonLocs first."; }
                        else { a.MONLOC_IDX = mm.MONLOC_IDX; }
                    }

                    //ACTIVITY ID HANDLING
                    if (aCTIVITY_IDX == null && aCTIVITY_ID == null) { sTATUS_CD = "F"; sTATUS_DESC += "Activity ID must be provided. "; }
                    if (aCTIVITY_IDX != null) a.ACTIVITY_IDX = aCTIVITY_IDX;
                    if (!string.IsNullOrEmpty(aCTIVITY_ID)) a.ACTIVITY_ID = aCTIVITY_ID.Trim().SubStringPlus(0, 35);

                    //ACTIVITY TYPE HANDLING
                    if (!string.IsNullOrEmpty(aCT_TYPE))
                    {
                        a.ACT_TYPE = aCT_TYPE.SubStringPlus(0, 70) ?? "";
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("ActivityType", aCT_TYPE.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Activity Type not valid. "; }
                    }
                    else
                    { a.ACT_TYPE = "";  sTATUS_CD = "F"; sTATUS_DESC += "Activity Type is required."; }

                    if (!string.IsNullOrEmpty(aCT_MEDIA))
                    {
                        a.ACT_MEDIA = aCT_MEDIA.SubStringPlus(0, 20) ?? "";
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("ActivityMedia", aCT_MEDIA.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Activity Media not valid. "; }
                    }
                    else
                    { a.ACT_MEDIA = ""; sTATUS_CD = "F"; sTATUS_DESC += "Activity Media is required."; }

                    if (!string.IsNullOrEmpty(aCT_SUBMEDIA))
                    {
                        a.ACT_SUBMEDIA = aCT_SUBMEDIA.SubStringPlus(0, 45);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("ActivityMediaSubdivision", aCT_SUBMEDIA.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Activity Media Subdivision not valid. "; }
                    }

                    if (aCT_START_DT == null)
                    {
                        sTATUS_CD = "F"; sTATUS_DESC += "Activity Start Date must be provided. ";
                    }
                    else
                    {
                        //fix improperly formatted datetime
                        if (aCT_START_DT.ConvertOrDefault<DateTime>().Year < 1900)
                            { sTATUS_CD = "F"; sTATUS_DESC += "Activity Start Date is formatted incorrectly. "; }
                        else
                            a.ACT_START_DT = aCT_START_DT;
                    }

                    if (aCT_END_DT != null)
                    {
                        //fix improperly formatted datetime
                        if (aCT_END_DT.ConvertOrDefault<DateTime>().Year < 1900)
                            aCT_END_DT = null;

                        a.ACT_END_DT = aCT_END_DT;
                    }

                    if (!string.IsNullOrEmpty(aCT_TIME_ZONE))
                    {
                        a.ACT_TIME_ZONE = aCT_TIME_ZONE.Trim().SubStringPlus(0, 4);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("TimeZone", aCT_TIME_ZONE.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "TimeZone not valid. "; }
                    }
                    else
                    {
                        //put in Timezone if missing
                        a.ACT_TIME_ZONE = Utils.GetWQXTimeZoneByDate(a.ACT_START_DT.ConvertOrDefault<DateTime>());
                    }

                    if (!string.IsNullOrEmpty(rELATIVE_DEPTH_NAME))
                    {
                        a.RELATIVE_DEPTH_NAME = rELATIVE_DEPTH_NAME.Trim().SubStringPlus(0, 15);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("ActivityRelativeDepth", rELATIVE_DEPTH_NAME.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Relative Depth Name not valid. "; }
                    }

                    if (!string.IsNullOrEmpty(aCT_DEPTHHEIGHT_MSR))
                    {
                        a.ACT_DEPTHHEIGHT_MSR = aCT_DEPTHHEIGHT_MSR.Trim().SubStringPlus(0, 12);
                    }

                    if (!string.IsNullOrEmpty(aCT_DEPTHHEIGHT_MSR_UNIT))
                    {
                        a.ACT_DEPTHHEIGHT_MSR_UNIT = aCT_DEPTHHEIGHT_MSR_UNIT.Trim().SubStringPlus(0, 12);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", aCT_DEPTHHEIGHT_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Depth Measure Unit not valid. "; }
                    }

                    if (!string.IsNullOrEmpty(tOP_DEPTHHEIGHT_MSR))
                    {
                        a.TOP_DEPTHHEIGHT_MSR = tOP_DEPTHHEIGHT_MSR.Trim().SubStringPlus(0, 12);
                    }

                    if (!string.IsNullOrEmpty(tOP_DEPTHHEIGHT_MSR_UNIT))
                    {
                        a.TOP_DEPTHHEIGHT_MSR_UNIT = tOP_DEPTHHEIGHT_MSR_UNIT.Trim().SubStringPlus(0, 12);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", tOP_DEPTHHEIGHT_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Top Depth Measure Unit not valid. "; }
                    }

                    if (!string.IsNullOrEmpty(bOT_DEPTHHEIGHT_MSR))
                    {
                        a.BOT_DEPTHHEIGHT_MSR = bOT_DEPTHHEIGHT_MSR.Trim().SubStringPlus(0, 12);
                    }

                    if (!string.IsNullOrEmpty(bOT_DEPTHHEIGHT_MSR_UNIT))
                    {
                        a.BOT_DEPTHHEIGHT_MSR_UNIT = bOT_DEPTHHEIGHT_MSR_UNIT.Trim().SubStringPlus(0, 12);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", bOT_DEPTHHEIGHT_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Bottom Depth Measure Unit not valid. "; }
                    }

                    if (!string.IsNullOrEmpty(dEPTH_REF_POINT))
                    {
                        a.DEPTH_REF_POINT = dEPTH_REF_POINT.Trim().SubStringPlus(0, 125);
                    }

                    if (!string.IsNullOrEmpty(aCT_COMMENT))
                    {
                        a.ACT_COMMENT = aCT_COMMENT.Trim().SubStringPlus(0, 4000);
                    }

                    //BIOLOGICAL MONITORING
                    if (BioIndicator == true)
                    {
                        if (!string.IsNullOrEmpty(bIO_ASSEMBLAGE_SAMPLED))
                        {
                            a.BIO_ASSEMBLAGE_SAMPLED = bIO_ASSEMBLAGE_SAMPLED.Trim().SubStringPlus(0, 50);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("Assemblage", bIO_ASSEMBLAGE_SAMPLED.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Bio Assemblage not valid. "; }
                        }

                        if (!string.IsNullOrEmpty(bIO_DURATION_MSR))
                        {
                            a.BIO_DURATION_MSR = bIO_DURATION_MSR.Trim().SubStringPlus(0, 12);
                        }

                        if (!string.IsNullOrEmpty(bIO_DURATION_MSR_UNIT))
                        {
                            a.BIO_DURATION_MSR_UNIT = bIO_DURATION_MSR_UNIT.Trim().SubStringPlus(0, 12);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", bIO_DURATION_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Bio Collection Duration Unit not valid. "; }
                        }

                        if (!string.IsNullOrEmpty(bIO_SAMP_COMPONENT))
                        {
                            a.BIO_SAMP_COMPONENT = bIO_SAMP_COMPONENT.Trim().SubStringPlus(0, 15);
                        }

                        if (bIO_SAMP_COMPONENT_SEQ != null) a.BIO_SAMP_COMPONENT_SEQ = bIO_SAMP_COMPONENT_SEQ;

                        if (!string.IsNullOrEmpty(bIO_REACH_LEN_MSR))
                        {
                            a.BIO_REACH_LEN_MSR = bIO_REACH_LEN_MSR.Trim().SubStringPlus(0, 12);
                        }

                        if (!string.IsNullOrEmpty(bIO_REACH_LEN_MSR_UNIT))
                        {
                            a.BIO_REACH_LEN_MSR_UNIT = bIO_REACH_LEN_MSR_UNIT.Trim().SubStringPlus(0, 12);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", bIO_REACH_LEN_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Bio Reach Length Unit not valid. "; }
                        }

                        if (!string.IsNullOrEmpty(bIO_REACH_WID_MSR))
                        {
                            a.BIO_REACH_WID_MSR = bIO_REACH_WID_MSR.Trim().SubStringPlus(0, 12);
                        }

                        if (!string.IsNullOrEmpty(bIO_REACH_WID_MSR_UNIT))
                        {
                            a.BIO_REACH_WID_MSR_UNIT = bIO_REACH_WID_MSR_UNIT.Trim().SubStringPlus(0, 12);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", bIO_REACH_WID_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Bio Reach Width Unit not valid. "; }
                        }

                        if (bIO_PASS_COUNT != null) a.BIO_PASS_COUNT = bIO_PASS_COUNT;

                        if (!string.IsNullOrEmpty(bIO_NET_TYPE))
                        {
                            a.BIO_NET_TYPE = bIO_NET_TYPE.Trim().SubStringPlus(0, 30);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("NetType", bIO_NET_TYPE.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Bio Net Type not valid. "; }
                        }

                        if (!string.IsNullOrEmpty(bIO_NET_AREA_MSR))
                        {
                            a.BIO_NET_AREA_MSR = bIO_NET_AREA_MSR.Trim().SubStringPlus(0, 12);
                        }

                        if (!string.IsNullOrEmpty(bIO_NET_AREA_MSR_UNIT))
                        {
                            a.BIO_NET_AREA_MSR_UNIT = bIO_NET_AREA_MSR_UNIT.Trim().SubStringPlus(0, 12);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", bIO_NET_AREA_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Bio Net Area Unit not valid. "; }
                        }

                        if (!string.IsNullOrEmpty(bIO_NET_MESHSIZE_MSR))
                        {
                            a.BIO_NET_MESHSIZE_MSR = bIO_NET_MESHSIZE_MSR.Trim().SubStringPlus(0, 12);
                        }

                        if (!string.IsNullOrEmpty(bIO_MESHSIZE_MSR_UNIT))
                        {
                            a.BIO_MESHSIZE_MSR_UNIT = bIO_MESHSIZE_MSR_UNIT.Trim().SubStringPlus(0, 12);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", bIO_MESHSIZE_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Bio Net Mesh Size Unit not valid. "; }
                        }

                        if (!string.IsNullOrEmpty(bIO_BOAT_SPEED_MSR))
                        {
                            a.BIO_BOAT_SPEED_MSR = bIO_BOAT_SPEED_MSR.Trim().SubStringPlus(0, 12);
                        }

                        if (!string.IsNullOrEmpty(bIO_BOAT_SPEED_MSR_UNIT))
                        {
                            a.BIO_BOAT_SPEED_MSR_UNIT = bIO_BOAT_SPEED_MSR_UNIT.Trim().SubStringPlus(0, 12);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", bIO_BOAT_SPEED_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Boat Speed Unit not valid. "; }
                        }

                        if (!string.IsNullOrEmpty(bIO_CURR_SPEED_MSR))
                        {
                            a.BIO_CURR_SPEED_MSR = bIO_CURR_SPEED_MSR.Trim().SubStringPlus(0, 12);
                        }

                        if (!string.IsNullOrEmpty(bIO_CURR_SPEED_MSR_UNIT))
                        {
                            a.BIO_CURR_SPEED_MSR_UNIT = bIO_CURR_SPEED_MSR_UNIT.Trim().SubStringPlus(0, 12);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("MeasureUnit", bIO_CURR_SPEED_MSR_UNIT.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Current Speed Unit not valid. "; }
                        }

                        if (!string.IsNullOrEmpty(bIO_TOXICITY_TEST_TYPE))
                        {
                            a.BIO_TOXICITY_TEST_TYPE = bIO_TOXICITY_TEST_TYPE.Trim().SubStringPlus(0, 7);
                            if (db_Ref.GetT_WQX_REF_DATA_ByKey("ToxicityTestType", bIO_TOXICITY_TEST_TYPE.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Toxicity Test Type not valid. "; }
                        }
                    }

                    if (sAMP_COLL_METHOD_IDX != null)
                    {
                        a.SAMP_COLL_METHOD_IDX = sAMP_COLL_METHOD_IDX;

                        //if IDX is populated but ID/Name/Ctx aren't then grab them
                        T_WQX_REF_SAMP_COL_METHOD scm = db_Ref.GetT_WQX_REF_SAMP_COL_METHOD_ByIDX(a.SAMP_COLL_METHOD_IDX);
                        if (scm != null)
                        {
                            a.SAMP_COLL_METHOD_ID = scm.SAMP_COLL_METHOD_ID;
                            a.SAMP_COLL_METHOD_NAME = scm.SAMP_COLL_METHOD_NAME;
                            a.SAMP_COLL_METHOD_CTX = scm.SAMP_COLL_METHOD_CTX;
                        }
                    }
                    else
                    {
                        //set context to org id if none is provided
                        if (!string.IsNullOrEmpty(sAMP_COLL_METHOD_ID) && string.IsNullOrEmpty(sAMP_COLL_METHOD_CTX))
                            sAMP_COLL_METHOD_CTX = oRG_ID;

                        if (!string.IsNullOrEmpty(sAMP_COLL_METHOD_ID) && !string.IsNullOrEmpty(sAMP_COLL_METHOD_CTX))
                        {
                            //lookup matching collection method IDX
                            T_WQX_REF_SAMP_COL_METHOD scm = db_Ref.GetT_WQX_REF_SAMP_COL_METHOD_ByIDandContext(sAMP_COLL_METHOD_ID.Trim(), sAMP_COLL_METHOD_CTX.Trim());
                            if (scm != null)
                                a.SAMP_COLL_METHOD_IDX = scm.SAMP_COLL_METHOD_IDX;
                            else  //no matching sample collection method lookup found
                            {
                                if (autoImportRefDataInd == true)
                                {
                                    db_Ref.InsertOrUpdateT_WQX_REF_SAMP_COL_METHOD(null, sAMP_COLL_METHOD_ID.Trim(), sAMP_COLL_METHOD_CTX.Trim(), sAMP_COLL_METHOD_NAME.Trim(), "", true);
                                }
                                else
                                {
                                    sTATUS_CD = "F"; sTATUS_DESC += "No matching Sample Collection Method found - please add it at the Reference Data screen first. ";
                                }
                            }
                            //****************************************

                            a.SAMP_COLL_METHOD_ID = sAMP_COLL_METHOD_ID.Trim().SubStringPlus(0, 20);
                            a.SAMP_COLL_METHOD_CTX = sAMP_COLL_METHOD_CTX.Trim().SubStringPlus(0, 120);

                            if (!string.IsNullOrEmpty(sAMP_COLL_METHOD_NAME))
                            {
                                a.SAMP_COLL_METHOD_NAME = sAMP_COLL_METHOD_NAME.Trim().SubStringPlus(0, 120);
                            }
                        }
                    }

                    if (a.SAMP_COLL_METHOD_IDX == null && a.ACT_TYPE.ToUpper().Contains("SAMPLE"))
                    { sTATUS_CD = "F"; sTATUS_DESC += "Sample Collection Method is required when Activity Type contains the term -Sample-. "; }

                    if (!string.IsNullOrEmpty(sAMP_COLL_EQUIP))
                    {
                        a.SAMP_COLL_EQUIP = sAMP_COLL_EQUIP.Trim().SubStringPlus(0, 40);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("SampleCollectionEquipment", sAMP_COLL_EQUIP.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Sample Collection Equipment not valid. "; }
                    }
                    else
                    {
                        //special validation requiring sampling collection equipment if activity type contains "Sample"
                        if (a.ACT_TYPE.ToUpper().Contains("SAMPLE"))
                        { sTATUS_CD = "F"; sTATUS_DESC += "Sample Collection Equipment is required when Activity Type contains the term -Sample-. "; }
                    }

                    if (!string.IsNullOrEmpty(sAMP_COLL_EQUIP_COMMENT))
                    {
                        a.SAMP_COLL_EQUIP_COMMENT = sAMP_COLL_EQUIP_COMMENT.Trim().SubStringPlus(0, 4000);
                    }

                    if (sAMP_PREP_IDX != null)
                        a.SAMP_PREP_IDX = sAMP_PREP_IDX;
                    else
                    {
                        //set context to org id if none is provided
                        if (!string.IsNullOrEmpty(sAMP_PREP_ID) && string.IsNullOrEmpty(sAMP_PREP_CTX))
                            sAMP_PREP_CTX = oRG_ID;

                        if (!string.IsNullOrEmpty(sAMP_PREP_ID) && !string.IsNullOrEmpty(sAMP_PREP_CTX))
                        {
                            //see if matching prep method exists
                            T_WQX_REF_SAMP_PREP sp = db_Ref.GetT_WQX_REF_SAMP_PREP_ByIDandContext(sAMP_PREP_ID.Trim(), sAMP_PREP_CTX.Trim());
                            if (sp != null)
                                a.SAMP_PREP_IDX = sp.SAMP_PREP_IDX;
                            //****************************************

                            a.SAMP_PREP_ID = sAMP_PREP_ID.Trim().SubStringPlus(0, 20);
                            a.SAMP_PREP_CTX = sAMP_PREP_CTX.Trim().SubStringPlus(0, 120);

                            if (!string.IsNullOrEmpty(sAMP_PREP_NAME))
                            {
                                a.SAMP_PREP_NAME = sAMP_PREP_NAME.Trim().SubStringPlus(0, 120);
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(sAMP_PREP_CONT_TYPE))
                    {
                        a.SAMP_PREP_CONT_TYPE = sAMP_PREP_CONT_TYPE.Trim().SubStringPlus(0, 35);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("SampleContainerType", sAMP_PREP_CONT_TYPE.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Sample Container Type not valid. "; }
                    }

                    if (!string.IsNullOrEmpty(sAMP_PREP_CONT_COLOR))
                    {
                        a.SAMP_PREP_CONT_COLOR = sAMP_PREP_CONT_COLOR.Trim().SubStringPlus(0, 15);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("SampleContainerColor", sAMP_PREP_CONT_COLOR.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Sample Container Color not valid. "; }
                    }

                    if (!string.IsNullOrEmpty(sAMP_PREP_CHEM_PRESERV))
                    {
                        a.SAMP_PREP_CHEM_PRESERV = sAMP_PREP_CHEM_PRESERV.Trim().SubStringPlus(0, 250);
                    }

                    if (!string.IsNullOrEmpty(sAMP_PREP_THERM_PRESERV))
                    {
                        a.SAMP_PREP_THERM_PRESERV = sAMP_PREP_THERM_PRESERV.Trim().SubStringPlus(0, 25);
                        if (db_Ref.GetT_WQX_REF_DATA_ByKey("ThermalPreservativeUsed", sAMP_PREP_THERM_PRESERV.Trim()) == false) { sTATUS_CD = "F"; sTATUS_DESC += "Thermal Preservative Used not valid. "; }
                    }

                    if (!string.IsNullOrEmpty(sAMP_PREP_STORAGE_DESC))
                    {
                        a.SAMP_PREP_STORAGE_DESC = sAMP_PREP_STORAGE_DESC.Trim().SubStringPlus(0, 250);
                    }

                    if (sTATUS_CD != null) a.IMPORT_STATUS_CD = sTATUS_CD;
                    if (sTATUS_DESC != null) a.IMPORT_STATUS_DESC = sTATUS_DESC.SubStringPlus(0,100);

                    if (insInd) //insert case
                        ctx.AddToT_WQX_IMPORT_TEMP_SAMPLE(a);

                    ctx.SaveChanges();

                    return a.TEMP_SAMPLE_IDX;
                }
            }
            catch (Exception ex)
            {
                sTATUS_CD = "F";
                sTATUS_DESC += "Unspecified error";
                return 0;
            }
        }
Example #2
0
        public static int InsertOrUpdateWQX_IMPORT_TEMPLATE_DTL(global::System.Int32? tEMPLATE_DTL_ID, global::System.Int32? tEMPLATE_ID, global::System.Int32? cOL_NUM, global::System.String fIELD_MAP,
            string cHAR_NAME, string cHAR_DEFAULT_UNIT, String cREATE_USER = "system", string cHAR_DEFAULT_SAMP_FRACTION = null)
        {
            using (OpenEnvironmentEntities ctx = new OpenEnvironmentEntities())
            {
                Boolean insInd = false;
                try
                {
                    T_WQX_IMPORT_TEMPLATE_DTL a = new T_WQX_IMPORT_TEMPLATE_DTL();

                    if (tEMPLATE_ID != null)
                        a = (from c in ctx.T_WQX_IMPORT_TEMPLATE_DTL
                             where c.TEMPLATE_DTL_ID == tEMPLATE_DTL_ID
                             select c).FirstOrDefault();

                    if (a == null) //insert case
                    {
                        insInd = true;
                        a = new T_WQX_IMPORT_TEMPLATE_DTL();
                    }

                    if (tEMPLATE_ID != null) a.TEMPLATE_ID = tEMPLATE_ID.ConvertOrDefault<int>();
                    if (cOL_NUM != null) a.COL_NUM = cOL_NUM.ConvertOrDefault<int>();
                    if (fIELD_MAP != null) a.FIELD_MAP = fIELD_MAP;
                    if (cHAR_NAME != null) a.CHAR_NAME = cHAR_NAME;
                    if (cHAR_DEFAULT_UNIT != null) a.CHAR_DEFAULT_UNIT = cHAR_DEFAULT_UNIT;
                    if (cHAR_DEFAULT_SAMP_FRACTION != null) a.CHAR_DEFAULT_SAMP_FRACTION = cHAR_DEFAULT_SAMP_FRACTION;

                    if (insInd) //insert case
                    {
                        a.CREATE_DT = System.DateTime.Now;
                        a.CREATE_USERID = cREATE_USER;
                        ctx.AddToT_WQX_IMPORT_TEMPLATE_DTL(a);
                    }

                    ctx.SaveChanges();

                    return a.TEMPLATE_DTL_ID;
                }
                catch (Exception ex)
                {
                    return 0;
                }
            }
        }