Пример #1
0
        public static Document GetDocument(int id)
        {
            Document document      = null;
            string   sqlExpression = "SELECT * FROM Document WHERE Id = @id AND Deleted = 0";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);
                command.Parameters.Add("@id", SqlDbType.Int);
                command.Parameters["@id"].Value = id;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Company      receiver        = null;
                        Company      sender          = null;
                        int          documentTypeId  = (int)reader["DocumentTypeId"];
                        DocumentType type            = SqlDocumentType.GetDocumentType(documentTypeId);
                        int          documentCode    = (int)reader["DocumentCode"];
                        string       title           = (string)reader["Title"];
                        string       content         = reader["Content"].GetType() == typeof(DBNull) ? null : (string)reader["Content"];
                        DateTime     creationDate    = (DateTime)reader["CreationDate"];
                        bool         senderConfirm   = (bool)reader["SenderConfirm"];
                        bool         receiverConfirm = (bool)reader["ReceiverConfirm"];
                        if (reader["ReceiverId"] != DBNull.Value)
                        {
                            int receiverId = (int)reader["ReceiverId"];
                            receiver = new Company()
                            {
                                Id        = receiverId,
                                InitState = InitializationState.INITIALIZATION_NEEDED
                            };
                        }
                        if (reader["SenderId"] != DBNull.Value)
                        {
                            int senderId = (int)reader["SenderId"];
                            sender = new Company()
                            {
                                Id        = senderId,
                                InitState = InitializationState.INITIALIZATION_NEEDED
                            };
                        }
                        document = new Document(type, documentCode, title)
                        {
                            Id              = id,
                            Text            = content,
                            CreationDate    = creationDate,
                            ReceiverConfirm = receiverConfirm,
                            SenderConfirm   = senderConfirm,
                            Receiver        = receiver,
                            Sender          = sender
                        };
                    }
                }
            }
            return(document);
        }
Пример #2
0
 public static int GenerateDocumentTypeId()
 {
     if (_lastIdDictionary[PersistedClass.DocumentType] == 0)
     {
         _lastIdDictionary[PersistedClass.DocumentType] = SqlDocumentType.GetMaxId();
     }
     _lastIdDictionary[PersistedClass.DocumentType]++;
     return(_lastIdDictionary[PersistedClass.DocumentType]);
 }
Пример #3
0
 public void Initialize()
 {
     Persons   = SqlPerson.GetAllPersons();
     Companies = SqlCompany.GetAllCompanies();
     Companies.ForEach((c) => c.InitState = InitializationState.INITIALIZATION_NEEDED);
     Chanceries = SqlChancery.GetAllChanceries();
     Chanceries.ForEach((c) => c.InitState = InitializationState.INITIALIZATION_NEEDED);
     Directors = SqlDirector.GetAllDirectors();
     Directors.ForEach((d) => d.InitState = InitializationState.INITIALIZATION_NEEDED);
     Secretaries = SqlSecretary.GetAllSecretaries();
     Secretaries.ForEach((s) => s.InitState = InitializationState.INITIALIZATION_NEEDED);
     MainSecretaries = SqlMainSecretary.GetAllMainSecretaries();
     MainSecretaries.ForEach((ms) => ms.InitState = InitializationState.INITIALIZATION_NEEDED);
     Documents = SqlDocument.GetAllDocuments();
     Documents.ForEach((d) => d.InitState = InitializationState.INITIALIZATION_NEEDED);
     CompanyTypes  = SqlCompanyType.GetAllCompanyTypes();
     DocumentTypes = SqlDocumentType.GetAllDocumentTypes();
     Markers       = SqlMarker.GetAllMarkers();
 }