Ejemplo n.º 1
0
        public void AddVersion(DocumentVersion version)
        {
            if (this.versions == null)
            {
                this.versions = new List <DocumentVersion>();
            }

            this.versions.Add(version);
        }
Ejemplo n.º 2
0
        public static ReadOnlyCollection <Document> GetByCompany(Company company)
        {
            List <Document> res = new List <Document>();

            if (company != null)
            {
                using (SqlCommand cmd = new SqlCommand("Company_GetDocuments"))
                {
                    cmd.Connection  = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@CompanyId", SqlDbType.Int);
                    try
                    {
                        cmd.Parameters["@CompanyId"].Value = company.Id;
                        Document newDocument = new Document();
                        cmd.Connection.Open();
                        SqlDataReader rdr = cmd.ExecuteReader();
                        while (rdr.Read())
                        {
                            if (newDocument.Id != rdr.GetInt64(0))
                            {
                                newDocument = new Document()
                                {
                                    Id          = rdr.GetInt64(0),
                                    Company     = company,
                                    Description = rdr.GetString(2),
                                    Code        = rdr.GetString(7),
                                    Category    = new KeyValuePair <string, int>(rdr.GetString(12), rdr.GetInt32(11)),
                                    Origin      = new KeyValuePair <string, int>(rdr.GetString(14), rdr.GetInt32(13))
                                };

                                res.Add(newDocument);
                            }

                            newDocument.AddVersion(new DocumentVersion()
                            {
                                DocumentId     = rdr.GetInt64(0),
                                Date           = rdr.GetDateTime(6),
                                Company        = company,
                                Id             = rdr.GetInt64(1),
                                State          = DocumentVersion.IntegerToStatus(rdr.GetInt32(5)),
                                User           = new ApplicationUser(rdr.GetInt32(4)),
                                Version        = rdr.GetInt32(3),
                                Reason         = rdr.GetString(8),
                                UserCreateName = rdr.GetString(10)
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        if (cmd.Connection.State != ConnectionState.Closed)
                        {
                            cmd.Connection.Close();
                        }
                    }
                }
            }

            return(new ReadOnlyCollection <Document>(res));
        }
Ejemplo n.º 3
0
        public static Document GetById(long documentId, int companyId)
        {
            Document res = new Document();

            using (SqlCommand cmd = new SqlCommand("Document_GetById"))
            {
                cmd.Connection  = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@DocumentId", SqlDbType.BigInt);
                cmd.Parameters.Add("@CompanyId", SqlDbType.Int);

                Company company = new Company(companyId);

                try
                {
                    cmd.Parameters["@DocumentId"].Value = documentId;
                    cmd.Parameters["@CompanyId"].Value  = companyId;
                    cmd.Connection.Open();
                    SqlDataReader rdr   = cmd.ExecuteReader();
                    bool          first = true;
                    while (rdr.Read())
                    {
                        if (first)
                        {
                            first           = false;
                            res.Id          = documentId;
                            res.Company     = company;
                            res.Description = rdr.GetString(2);
                            res.Category    = new KeyValuePair <string, int>(rdr.GetString(11), rdr.GetInt32(10));
                            res.Origin      = new KeyValuePair <string, int>(rdr.GetString(13), rdr.GetInt32(12));
                            res.Code        = rdr.GetString(14);
                            res.FechaAlta   = rdr.GetDateTime(15);
                            if (!rdr.IsDBNull(16))
                            {
                                res.FechaBaja = rdr.GetDateTime(16);
                            }

                            res.Conservation     = rdr.GetInt32(17);
                            res.ConservationType = rdr.GetInt32(18);
                            res.Source           = rdr.GetInt32(19) == 1;
                            res.Location         = rdr.GetString(20);
                            res.ModifiedOn       = rdr.GetDateTime(22);
                            res.ModifiedBy       = new ApplicationUser(rdr.GetInt32(21));
                        }

                        res.AddVersion(new DocumentVersion()
                        {
                            Id             = rdr.GetInt64(1),
                            Company        = company,
                            DocumentId     = documentId,
                            User           = new ApplicationUser(rdr.GetInt32(4)),
                            Version        = rdr.GetInt32(3),
                            Date           = rdr.GetDateTime(6),
                            State          = DocumentVersion.IntegerToStatus(rdr.GetInt32(5)),
                            Reason         = rdr.GetString(7),
                            UserCreateName = rdr.GetString(9)
                        });
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    if (cmd.Connection.State != ConnectionState.Closed)
                    {
                        cmd.Connection.Close();
                    }
                }
            }

            return(res);
        }