예제 #1
0
        public AttrDefine QueryOne(long tmpId, string attrId, string attrNm, string attrTp)
        {
            SqlConnection sqlConnection = DBConnection.OpenConnection();

            string sql = "SELECT * FROM AttrDefine WHERE 0 = 0"
                         + $" AND TmpId = {tmpId}"
                         + $" AND AttrId = '{attrId}'"
                         + $" AND AttrNm = '{attrNm}'"
                         + $" AND AttrTp = '{attrTp}'";
            AttrDefine attrDefine = null;

            using (SqlCommand command = new SqlCommand(sql, sqlConnection))
            {
                SqlDataReader dataReader = command.ExecuteReader();


                if (dataReader.HasRows)
                {
                    dataReader.Read();
                    attrDefine = new AttrDefine
                    {
                        TmpId       = (long)dataReader["TmpId"],
                        AttrId      = dataReader["AttrId"].ToString(),
                        AttrNm      = dataReader["AttrNm"].ToString(),
                        AttrTp      = dataReader["AttrTp"].ToString(),
                        LockFlag    = (int)dataReader["LockFlag"],
                        CrtDate     = dataReader["CrtDate"].ToString(),
                        Crter       = dataReader["Crter"].ToString(),
                        LstUpdtDate = dataReader["LstUpdtDate"].ToString(),
                        LstUpdter   = dataReader["LstUpdter"].ToString(),
                    };
                    dataReader.Close();
                }
                else
                {
                    dataReader.Close();
                    DBConnection.CloseConnection(sqlConnection);
                    string logMessage = string.Format("未找到记录!TmpId[{0}]AttrId[{1}]AttrNm[{2}]AttrTp[{3}]", tmpId, attrId, attrNm, attrTp);
                    log.Error(logMessage);
                    var responseMessge = new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content      = new StringContent(logMessage),
                        ReasonPhrase = "AttrDefine record not found"
                    };
                    throw new HttpResponseException(responseMessge);
                }
            }
            DBConnection.CloseConnection(sqlConnection);
            return(attrDefine);
        }
예제 #2
0
        public void Insert(AttrDefine attrDefine)
        {
            SqlConnection sqlConnection = DBConnection.OpenConnection();

            string crtDate = DateTime.Now.ToString("yyyyMMdd HH:mm:ss");
            string sql     = "INSERT INTO AttrDefine " + $"(TmpId, AttrId, AttrNm, AttrTp,CrtDate, Crter) Values ({attrDefine.TmpId},'{attrDefine.AttrId}', '{attrDefine.AttrNm}', '{attrDefine.AttrTp}', '{crtDate}','{attrDefine.Crter}')";

            using (SqlCommand command = new SqlCommand(sql, sqlConnection))
            {
                try
                {
                    command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    log.Error("INSERT INTO AttrDefine ERROR!", e);
                    DBConnection.CloseConnection(sqlConnection);
                    throw;
                }
            }
            DBConnection.CloseConnection(sqlConnection);
        }