private ProfileForSqlSelect InsertProfile(ProfileItem profile, SqlTransaction trans)
        {
            int oldProfileId = -1;
            int newVersion   = 0;

            try
            {
                oldProfileId = GetProfileId(profile.ProfileKey, trans);
                _profileVersionSelect.Parameters["@PROF_ID"].Value = oldProfileId;
                _profileVersionSelect.Transaction = trans;
                newVersion = (int)_profileVersionSelect.ExecuteScalar() + 1;
            }
            catch (ArgumentException)
            {
                //В случаи отсутствия профиля(в том числе и при синхронизации)
                newVersion = profile.Version;
            }

            ProfileForSqlSelect profileSql = new ProfileForSqlSelect(0, profile.ProfileName, profile.NextGenerationKey, newVersion, DateTime.Now);

            _profileInsertCommand.Parameters["@PROF_GUID"].Value = profileSql.Key;
            _profileInsertCommand.Parameters["@VERSION"].Value   = profileSql.Version;
            _profileInsertCommand.Parameters["@PROF_TS"].Value   = profileSql.TS;
            _profileInsertCommand.Parameters["@PROF_NAME"].Value = profileSql.Name;
            _profileInsertCommand.Transaction = trans;
            profileSql.Id = (int)_profileInsertCommand.ExecuteScalar();

            if (oldProfileId != -1)
            {
                UpdateConnections(oldProfileId, profileSql.Id, trans);
            }

            return(profileSql);

            //catch (ArgumentException)
            //{
            //    throw new NotImplementedException();
            //    //_profileInsertCommand.Parameters["@PROF_NAME"].Value = profile.ProfileName;
            //    //_profileInsertCommand.Parameters["@PROF_GUID"].Value = profile.ProfileKey;
            //    //_profileInsertCommand.Parameters["@PROF_TS"].Value = DateTime.Now;
            //    //_profileInsertCommand.Parameters["@VERSION"].Value = 1;
            //    //_profileInsertCommand.Transaction = trans;

            //    //return (int)_profileInsertCommand.ExecuteScalar();
            //}
        }
Beispiel #2
0
        private Profile Profile(ProfileForSqlSelect prof)
        {
            var profile = new Profile(prof);

            var testTypes = new Dictionary <long, long>(5);

            _condCmd.Parameters["@PROF_ID"].Value = prof.Id;

            a++;
            using (var reader = _condCmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    testTypes.Add((int)reader[0], (int)reader[1]);
                }
            }

            foreach (var testType in testTypes)
            {
                FillParameters(profile, testType.Key, testType.Value);
            }

            return(profile);
        }
Beispiel #3
0
        private ProfileForSqlSelect InsertProfile(ProfileItem profile)
        {
            long oldProfileId = -1;
            long newVersion   = 0;

            try
            {
                oldProfileId = GetProfileId(profile.ProfileKey);
                var profileVersionSelect = new SQLiteCommand("SELECT P.PROF_VERS FROM PROFILES P WHERE P.PROF_ID = @PROF_ID", _connection);
                profileVersionSelect.Parameters.Add("@PROF_ID", DbType.Int64);
                profileVersionSelect.Prepare();
                profileVersionSelect.Parameters["@PROF_ID"].Value = oldProfileId;
                newVersion = Convert.ToInt64(profileVersionSelect.ExecuteScalar()) + 1;
            }
            catch (ArgumentException)
            {
                //В случаи отсутствия профиля(в том числе и при синхронизации)
                newVersion = profile.Version;
            }

            var profileInsertCommand = new SQLiteCommand("INSERT INTO PROFILES(PROF_ID, PROF_NAME, PROF_GUID, PROF_TS,PROF_VERS) VALUES (NULL, @PROF_NAME, @PROF_GUID, @PROF_TS,@VERSION)", _connection);


            profileInsertCommand.Parameters.Add("@VERSION", DbType.Int64);
            profileInsertCommand.Parameters.Add("@PROF_TS", DbType.String);
            profileInsertCommand.Parameters.Add("@PROF_NAME", DbType.String);
            profileInsertCommand.Prepare();

            ProfileForSqlSelect profileSql = new ProfileForSqlSelect(0, profile.ProfileName, profile.NextGenerationKey, Convert.ToInt32(newVersion), DateTime.Now);

            //profileInsertCommand.Parameters["@PROF_GUID"].Value = profile.ProfileKey; //Guid.NewGuid(); нельзя генерировать новое значение
            profileInsertCommand.Parameters.AddWithValue("@PROF_GUID", profileSql.Key.ToString());
            profileInsertCommand.Parameters["@VERSION"].Value   = profileSql.Version;
            profileInsertCommand.Parameters["@PROF_TS"].Value   = profileSql.TS.ToString(@"yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
            profileInsertCommand.Parameters["@PROF_NAME"].Value = profileSql.Name;
            profileInsertCommand.ExecuteNonQuery();

            profileSql.Id = Convert.ToInt32(_connection.LastInsertRowId);

            if (oldProfileId != -1)
            {
                UpdateConnections(oldProfileId, profileSql.Id);
            }

            return(profileSql);

            //catch (ArgumentException)
            //{
            //    var profileInsertCommand = new SQLiteCommand("INSERT INTO PROFILES(PROF_ID, PROF_NAME, PROF_GUID, PROF_TS, PROF_VERS) VALUES(NULL, @PROF_NAME, @PROF_GUID, @PROF_TS, 1)", _connection);
            //    profileInsertCommand.Parameters.Add("@PROF_NAME", DbType.String);
            //    profileInsertCommand.Parameters.Add("@PROF_GUID", DbType.Guid);
            //    profileInsertCommand.Parameters.Add("@PROF_TS", DbType.String);
            //    profileInsertCommand.Prepare();

            //    profileInsertCommand.Parameters["@PROF_NAME"].Value = profile.ProfileName;
            //    profileInsertCommand.Parameters["@PROF_GUID"].Value = profile.ProfileKey;
            //    profileInsertCommand.Parameters["@PROF_TS"].Value = DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
            //    profileInsertCommand.ExecuteNonQuery();

            //    return _connection.LastInsertRowId;
            //}
        }
Beispiel #4
0
 public Profile(ProfileForSqlSelect prof)
     : base(prof.Name, prof.Key, Convert.ToInt32(prof.Version), prof.TS)
 {
     ConstructorInit();
 }
Beispiel #5
0
        public ProfileItem GetProfileByProfName(string profName, string mmmeCode, ref bool Found)
        {
            //читаем один единственный профиль с принятым profName и MmmeCode
            try
            {
                ProfileItem Result = null;

                ProfileForSqlSelect profileDict = null;

                _profileSingleSelect.Parameters["@ProfName"].Value = profName;
                _profileSingleSelect.Parameters["@MmmeCode"].Value = mmmeCode;

                using (var reader = _profileSingleSelect.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        profileDict = new ProfileForSqlSelect((int)reader[0], (string)reader[1], (Guid)reader[2], (int)reader[3], (DateTime)reader[4]);
                    }
                }

                if (profileDict == null)
                {
                    Found = false;
                    return(Result);
                }
                else
                {
                    Found = true;

                    var testTypes = new Dictionary <long, long>(5);

                    _condCmd.Parameters["@PROF_ID"].Value = profileDict.Id;

                    using (var reader = _condCmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            testTypes.Add((int)reader[0], (int)reader[1]);
                        }
                    }

                    Profile profile = new Profile(profileDict.Name, profileDict.Key, profileDict.Version, profileDict.TS);


                    foreach (var testType in testTypes)
                    {
                        FillParameters(profile, testType.Key, testType.Value);
                    }

                    Result = new ProfileItem
                    {
                        ProfileId              = profileDict.Id,
                        ProfileName            = profileDict.Name,
                        ProfileKey             = profileDict.Key,
                        ProfileTS              = profileDict.TS,
                        GateTestParameters     = new List <TestParameters>(),
                        VTMTestParameters      = new List <Types.VTM.TestParameters>(),
                        BVTTestParameters      = new List <Types.BVT.TestParameters>(),
                        DvDTestParameterses    = new List <Types.dVdt.TestParameters>(),
                        ATUTestParameters      = new List <Types.ATU.TestParameters>(),
                        QrrTqTestParameters    = new List <Types.QrrTq.TestParameters>(),
                        TOUTestParameters      = new List <Types.TOU.TestParameters>(),
                        CommTestParameters     = profile.ParametersComm,
                        IsHeightMeasureEnabled = profile.IsHeightMeasureEnabled,
                        ParametersClamp        = profile.ParametersClamp,
                        Height      = profile.Height,
                        Temperature = profile.Temperature
                    };

                    foreach (var baseTestParametersAndNormativese in profile.TestParametersAndNormatives)
                    {
                        var gate = baseTestParametersAndNormativese as TestParameters;
                        if (gate != null)
                        {
                            Result.GateTestParameters.Add(gate);
                        }

                        var sl = baseTestParametersAndNormativese as Types.VTM.TestParameters;
                        if (sl != null)
                        {
                            Result.VTMTestParameters.Add(sl);
                        }

                        var bvt = baseTestParametersAndNormativese as Types.BVT.TestParameters;
                        if (bvt != null)
                        {
                            Result.BVTTestParameters.Add(bvt);
                        }

                        var dvdt = baseTestParametersAndNormativese as Types.dVdt.TestParameters;
                        if (dvdt != null)
                        {
                            Result.DvDTestParameterses.Add(dvdt);
                        }

                        var atu = baseTestParametersAndNormativese as Types.ATU.TestParameters;
                        if (atu != null)
                        {
                            Result.ATUTestParameters.Add(atu);
                        }

                        var qrrTq = baseTestParametersAndNormativese as Types.QrrTq.TestParameters;
                        if (qrrTq != null)
                        {
                            Result.QrrTqTestParameters.Add(qrrTq);
                        }

                        var tou = baseTestParametersAndNormativese as Types.TOU.TestParameters;
                        if (tou != null)
                        {
                            Result.TOUTestParameters.Add(tou);
                        }
                    }
                }

                return(Result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }