public static void UpdateParaMaping(TblParamMapping pitems)
 {
     try
     {
         if (TblParamMapping.FetchByID(pitems.Id) != null)
         {
             pitems.IsNew = false;
             pitems.Save();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        //Insert Paramapping vào db

        public static int InsertParaMapping(TblParamMapping objParaMapping)
        {
            int   record        = -1;
            Query _QueryMapping = TblParamMapping.CreateQuery();

            try
            {
                using (var scope = new TransactionScope())
                {
                    using (var sp = new SharedDbConnectionScope())
                    {
                        //TblParamMappingCollection objCollection =new TblParamMappingController().FetchByQuery(
                        //        TblParamMapping.CreateQuery().AddWhere(TblParamMapping.Columns.MedParamID,
                        //                                               Comparison.Equals, objParaMapping.MedParamID).AND
                        //            (TblParamMapping.Columns.LisParaName, Comparison.Equals, objParaMapping.LisParaName)
                        //            .AND(TblParamMapping.Columns.DeviceId, Comparison.Equals, objParaMapping.DeviceId));

                        SqlQuery q = new Select().From(TblParamMapping.Schema)
                                     .Where(TblParamMapping.Columns.MedParamID).IsEqualTo(objParaMapping.MedParamID)
                                     .And(TblParamMapping.Columns.LisParaName).IsEqualTo(objParaMapping.LisParaName)
                                     .And(TblParamMapping.Columns.DeviceId).IsEqualTo(objParaMapping.DeviceId);
                        if (q.GetRecordCount() <= 0)
                        {
                            objParaMapping.IsNew = true;
                            objParaMapping.Save();
                            record = Utility.Int32Dbnull(_QueryMapping.GetMax(TblParamMapping.Columns.Id), -1);
                        }
                        //else
                        //{
                        //    new Update(TblParamMapping.Schema)
                        //        .Set(TblParamMapping.Columns.LisParaName).EqualTo(objParaMapping.LisParaName)
                        //        .Set(TblParamMapping.Columns.DeviceId).EqualTo(objParaMapping.DeviceId)
                        //        .Set(TblParamMapping.Columns.MedParaName).EqualTo(objParaMapping.MedParaName)
                        //        .Set(TblParamMapping.Columns.IsTestName).EqualTo(objParaMapping.IsTestName)
                        //        .Where(TblParamMapping.Columns.MedParamID).IsEqualTo(objParaMapping.MedParamID).Execute();
                        //}
                    }

                    scope.Complete();
                    //record = 1;
                }
            }
            catch (Exception ex)
            {
                record = -1;
            }
            return(record);
        }