public PRODUCT GetElementById(Guid PRODUCT_ID, TransactionManager transactionManager) { PRODUCT cPRODUCTS = null; SqlDataReader reader = null; string selectsql = "select * from PRODUCT WITH (NOLOCK) WHERE PRODUCT_ID=@PRODUCT_ID"; SqlCommand cmd = new SqlCommand(selectsql); cmd.Parameters.Add("@PRODUCT_ID", SqlDbType.UniqueIdentifier, 16); cmd.Parameters["@PRODUCT_ID"].Value = PRODUCT_ID; fAssignNull(cmd); if (transactionManager != null) { cmd.Connection = transactionManager.Connection; cmd.Transaction = transactionManager.TransactionObject; reader = cmd.ExecuteReader(); cPRODUCTS = fReadToClass(ref reader); } else { using (SqlConnection conn = new SqlConnection(this._connectionString)) { conn.Open(); cmd.Connection = conn; reader = cmd.ExecuteReader(); cPRODUCTS = fReadToClass(ref reader); } } return(cPRODUCTS); }
public PRODUCT GetElementByKod(string[] _KeyFields, object[] _Values, TransactionManager transactionManager) { if (_KeyFields == null || _KeyFields.Length == 0) { return(null); } if (_Values == null || _Values.Length == 0) { return(null); } if (_KeyFields.Length != _Values.Length) { return(null); } PRODUCT cPRODUCTS = null; SqlDataReader reader = null; string selectsql = "select top 1 * from PRODUCT WITH (NOLOCK) WHERE "; string wherestr = ""; for (int _i = 0; _i <= _KeyFields.Length - 1; _i++) { if (wherestr.Trim() != "") { wherestr += " AND "; } wherestr += _KeyFields[_i] + "=@" + _KeyFields[_i]; } selectsql += wherestr; SqlCommand cmd = new SqlCommand(selectsql); for (int _z = 0; _z <= _Values.Length - 1; _z++) { cmd.Parameters.Add(new SqlParameter("@" + _KeyFields[_z], _Values[_z])); } fAssignNull(cmd); if (transactionManager != null) { cmd.Connection = transactionManager.Connection; cmd.Transaction = transactionManager.TransactionObject; reader = cmd.ExecuteReader(); cPRODUCTS = fReadToClass(ref reader); } else { using (SqlConnection conn = new SqlConnection(this._connectionString)) { conn.Open(); cmd.Connection = conn; reader = cmd.ExecuteReader(); cPRODUCTS = fReadToClass(ref reader); } } return(cPRODUCTS); }
public void fKaydetPRODUCT(PRODUCT cPRODUCTS, TransactionManager transactionManager) { if (cPRODUCTS.State == 1) { updatePRODUCT(cPRODUCTS, transactionManager); } else { insertPRODUCT(cPRODUCTS, transactionManager); } }
public PRODUCT fReadToClass(ref SqlDataReader reader) { PRODUCT cPRODUCTS = null; if (reader.Read()) { if (reader != null && !reader.IsClosed) { cPRODUCTS = new PRODUCT(); if (!reader.IsDBNull(0)) { cPRODUCTS.PRODUCT_ID = reader.GetGuid(0); } if (!reader.IsDBNull(1)) { cPRODUCTS.PRODUCT_TITLE = reader.GetString(1); } if (!reader.IsDBNull(2)) { cPRODUCTS.PRODUCT_CONTENT = reader.GetString(2); } if (!reader.IsDBNull(3)) { cPRODUCTS.PRODUCT_MD = reader.GetDateTime(3); } if (!reader.IsDBNull(4)) { cPRODUCTS.PRODUCT_CD = reader.GetDateTime(4); } cPRODUCTS.State = 1; } } reader.Close(); return(cPRODUCTS); }
private void updatePRODUCT(PRODUCT cPRODUCTS, TransactionManager transactionManager) { try { SqlCommand cmd = new SqlCommand("usp_UpdatePRODUCT"); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@PRODUCT_ID", SqlDbType.UniqueIdentifier); cmd.Parameters["@PRODUCT_ID"].Value = cPRODUCTS.PRODUCT_ID; cmd.Parameters.Add("@PRODUCT_TITLE", SqlDbType.NVarChar); cmd.Parameters["@PRODUCT_TITLE"].Value = cPRODUCTS.PRODUCT_TITLE; cmd.Parameters.Add("@PRODUCT_CONTENT", SqlDbType.NVarChar); cmd.Parameters["@PRODUCT_CONTENT"].Value = cPRODUCTS.PRODUCT_CONTENT; fAssignNull(cmd); if (transactionManager != null) { cmd.Connection = transactionManager.Connection; cmd.Transaction = transactionManager.TransactionObject; cmd.ExecuteNonQuery(); } else { using (SqlConnection conn = new SqlConnection(this._connectionString)) { conn.Open(); cmd.Connection = conn; cmd.ExecuteNonQuery(); } } } catch { throw; } }