/// <summary> /// Insert a <see cref="Document"/> passed as an argument via Stored Procedure that returns the newly inserted Document Key /// </summary> /// <param name="aDocument">A <see cref="Document"/>.</param> /// <exception cref="ArgumentNullException">If <c>aDocument</c> argument is <c>null</c>.</exception> public static void Insert(Document aDocument) { if (aDocument == null) { throw new ArgumentNullException("aDocument"); } using (var vSqlCommand = new SqlCommand() { CommandType = CommandType.Text, Connection = new SqlConnection(Connection.Instance.SqlConnectionString) }) { var vStringBuilder = new StringBuilder(); vStringBuilder.AppendLine("insert into DOC_Document"); vStringBuilder.AppendLine(" (CLN_Key, DOC_Name)"); vStringBuilder.AppendLine("values"); vStringBuilder.AppendLine(" (@CLNKey, @DOCName)"); vStringBuilder.AppendLine(";"); vStringBuilder.AppendLine("select SCOPE_IDENTITY()"); ObjectToData(vSqlCommand, aDocument); vSqlCommand.CommandText = vStringBuilder.ToString(); vSqlCommand.Connection.Open(); aDocument.DocKey = Convert.ToInt32(vSqlCommand.ExecuteScalar()); vSqlCommand.Connection.Close(); } }
/// <summary> /// Load a <see cref="SqlDataReader"/> into a <see cref="Document"/> object. /// </summary> /// <param name="aDocument">A <see cref="Document"/> argument.</param> /// <param name="aSqlDataReader">A <see cref="SqlDataReader"/> argument.</param> public static void DataToObject(Document aDocument, SqlDataReader aSqlDataReader) { aDocument.ClnKey = Convert.ToInt32(aSqlDataReader["CLN_Key"]); aDocument.ClnName = Convert.ToString(aSqlDataReader["CLN_Name"]); aDocument.DocKey = Convert.ToInt32(aSqlDataReader["DOC_Key"]); aDocument.DocName = Convert.ToString(aSqlDataReader["DOC_Name"]); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="Document"/> object, with keys in <c>aDocument</c>. /// </summary> /// <param name="aUserKey">A <see cref="UserKey"/> object.</param> /// <param name="aDocument">A <see cref="Document"/>.</param> /// <exception cref="ArgumentNullException">If <c>aDocument</c> is <c>null</c>.</exception> public static void Load(UserKey aUserKey, Document aDocument) { if (aDocument == null) { throw new ArgumentNullException("Load Document Business"); } if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Document", AccessMode.Read)) { throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "Document"); } DocumentData.Load(aDocument); }
/// <summary> /// Assigns all <c>aSource</c> object's values to this instance of <see cref="ProviderCollection"/>. /// </summary> /// <param name="aSource">A source object.</param> public override void AssignFromSource(object aSource) { if (!(aSource is DocumentCollection)) { throw new ArgumentException("Invalid assignment source", "DocumentCollection"); } _documentFilter.AssignFromSource((aSource as DocumentCollection)._documentFilter); _documentList.Clear(); (aSource as DocumentCollection)._documentList.ForEach(vDocumentSource => { Document vDocumentTarget = new Document(); vDocumentTarget.AssignFromSource(vDocumentSource); _documentList.Add(vDocumentTarget); }); }
/// <summary> /// Delete a <see cref="Document"/> object passed as an argument. /// </summary> /// <param name="aDocument">The <see cref="Document"/> object to be deleted.</param> /// <exception cref="ArgumentNullException">If <c>aDocument</c> argument is <c>null</c>.</exception> public static void Delete(Document aDocument) { if (aDocument == null) { throw new ArgumentNullException("aDocument"); } using (var vSqlCommand = new SqlCommand() { CommandType = CommandType.Text, Connection = new SqlConnection(Connection.Instance.SqlConnectionString) }) { var vStringBuilder = new StringBuilder(); vStringBuilder.AppendLine("delete DOC_Document"); vStringBuilder.AppendLine("where CLN_Key = @CLNKey"); vSqlCommand.Parameters.AddWithValue("@CLNKey", aDocument.ClnKey); vStringBuilder.AppendLine("and DOC_Key = @DOCKey"); vSqlCommand.Parameters.AddWithValue("@DOCKey", aDocument.DocKey); vSqlCommand.CommandText = vStringBuilder.ToString(); vSqlCommand.Connection.Open(); vSqlCommand.ExecuteNonQuery(); vSqlCommand.Connection.Close(); } }
/// <summary> /// Add a <see cref="Document"/>. /// </summary> /// <param name="aUserToken">A <see cref="UserToken"/> object used for Access Control.</param> /// <param name="aDocument"><see cref="Document"/> object.</param> public static void AddDocument(UserToken aUserToken, Document aDocument) { UserCallHandler.ServiceCall<Document>(aUserToken, "AddDocument", aDocument); }
/// <summary> /// Loads the <see cref="SqlCommand"/> parameters with values from an <see cref="Document"/>. /// </summary> /// <param name="aSqlCommand">A <see cref="SqlDataReader"/> argument.</param> /// <param name="aDocument">A <see cref="Document"/> argument.</param> public static void ObjectToData(SqlCommand aSqlCommand, Document aDocument) { aSqlCommand.Parameters.AddWithValue("@CLNKey", aDocument.ClnKey); aSqlCommand.Parameters.AddWithValue("@DOCName", aDocument.DocName); }
/// <summary> /// The overloaded Load method that will return a specific <see cref="Document"/>, with keys in the <c>aDocument</c> argument. /// </summary> /// <param name="aDocument">A <see cref="Document"/>.</param> /// <exception cref="ArgumentNullException">If <c>aDocument</c> argument is <c>null</c>.</exception> /// <exception cref="Exception">If no record is found.</exception> public static void Load(Document aDocument) { if (aDocument == null) { throw new ArgumentNullException("aDocument"); } using (var vSqlCommand = new SqlCommand() { CommandType = CommandType.Text, Connection = new SqlConnection(Connection.Instance.SqlConnectionString) }) { var vStringBuilder = BuildSQL(); vStringBuilder.AppendLine("and t1.CLN_Key = @CLNKey"); vStringBuilder.AppendLine("and t2.DOC_Key = @DOCKey"); vSqlCommand.Parameters.AddWithValue("@CLNKey", aDocument.ClnKey); vSqlCommand.Parameters.AddWithValue("@DOCKey", aDocument.DocKey); vSqlCommand.CommandText = vStringBuilder.ToString(); vSqlCommand.Connection.Open(); using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader()) { if (!vSqlDataReader.HasRows) { throw new Exception(String.Format("Expected Document not found: CLN_Key = {0}, DOC_Key = {1}", aDocument.ClnKey, aDocument.DocKey)); } vSqlDataReader.Read(); DataToObject(aDocument, vSqlDataReader); vSqlDataReader.Close(); } vSqlCommand.Connection.Close(); } }
/// <summary> /// The overloaded Load method that will fill the <c>DocumentList</c> property a <see cref="DocumentCollection"/> object as an /// ordered <c>List</c> of <see cref="Document"/>, filtered by the filter properties of the passed <see cref="DocumentCollection"/>. /// </summary> /// <param name="aDocumentCollection">The <see cref="DocumentCollection"/> object that must be filled.</param> /// <remarks> /// The filter properties of the <see cref="DocumentCollection"/> must be correctly completed by the calling application. /// </remarks> /// <exception cref="ArgumentNullException">If <c>aDocumentCollection</c> argument is <c>null</c>.</exception> public static void Load(DocumentCollection aDocumentCollection) { if (aDocumentCollection == null) { throw new ArgumentNullException("aDocumentCollection"); } using (var vSqlCommand = new SqlCommand() { CommandType = CommandType.Text, Connection = new SqlConnection(Connection.Instance.SqlConnectionString) }) { var vStringBuilder = BuildSQL(); if (aDocumentCollection.DocumentFilter.IsFiltered) { if (aDocumentCollection.DocumentFilter.DocumentClientKeyFilter > 0) { vStringBuilder.AppendLine("and t1.CLN_Key = @CLNKey"); vSqlCommand.Parameters.AddWithValue("@CLNKey", aDocumentCollection.DocumentFilter.DocumentClientKeyFilter); } } vStringBuilder.AppendLine("order by t2.DOC_Name"); vSqlCommand.CommandText = vStringBuilder.ToString(); vSqlCommand.Connection.Open(); using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader()) { while (vSqlDataReader.Read()) { var vDocument = new Document(); DataToObject(vDocument, vSqlDataReader); aDocumentCollection.DocumentList.Add(vDocument); } vSqlDataReader.Close(); } vSqlCommand.Connection.Close(); } }
/// <summary> /// Gets the <see cref="Document"/> by Key. /// </summary> /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param> /// <returns>Document as XML <see cref="string"/>.</returns> /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception> public static string GetDocument(UserKey aUserKey, string aXmlArgument) { if (aXmlArgument == null) { throw new ArgumentNullException("aXmlArgument of GetDocument"); } Document vDocument = new Document(); vDocument = XmlUtils.Deserialize<Document>(aXmlArgument); DocumentBusiness.Load(aUserKey, vDocument); return XmlUtils.Serialize<Document>(vDocument, true); }