Exemple #1
0
    public void QueryTroubleCodeSuccess()
    {
      try
      {
        string cls = "QingQi";
        TroubleCodeItem zhCNExpect = new TroubleCodeItem();
        zhCNExpect.Code = "0040";
        zhCNExpect.Content = "从进气歧管压力输入电压低于其最小可能值。";
        zhCNExpect.Description = "接插件接触不良/传感器损坏";

        TroubleCodeItem enUSExpect = new TroubleCodeItem();
        enUSExpect.Code = "0040";
        enUSExpect.Content = "Input voltage from the intake manifold pressure fell below its minimum possible value.";
        enUSExpect.Description = "Connector poor contact / sensor damage";

        Settings.Language = "zh-CN";
        var result = _db.QueryTroubleCode(zhCNExpect.Code, cls);
        Assert.IsTrue(zhCNExpect.Equals(result));

        Settings.Language = "en-US";
        result = _db.QueryTroubleCode(enUSExpect.Code, cls);
        Assert.IsTrue(enUSExpect.Equals(result));
      }
      catch (DatabaseException ex)
      {
        Assert.Fail(ex.Message);
      }
    }
Exemple #2
0
        public TroubleCodeItem QueryTroubleCode(string code, string cls)
        {
            Action ThrowException = () =>
            {
                throw new DatabaseException(String.Format("Query trouble code fail by code = {0}, class = {1}",
                    code, cls));
            };

            try
            {
                troubleCodeCommand.Prepare();

                troubleCodeCommand.Parameters[0].Value = Encrypt(code);
                troubleCodeCommand.Parameters[1].Value = EncryptLang;
                troubleCodeCommand.Parameters[2].Value = Encrypt(cls);

                using (var reader = troubleCodeCommand.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        TroubleCodeItem item = new TroubleCodeItem();
                        item.Code = code;
                        item.Content = DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(0));

                        if (!reader.IsDBNull(1))
                            item.Description = DBCrypto.DecryptToString(reader.GetFieldValue<byte[]>(1));
                        return item;
                    }
                }
            }
            catch
            {
                ThrowException();
            }

            ThrowException();
            return null;
        }