Exemplo n.º 1
0
        /// <summary>Add an address in company addresses</summary>
        /// <param name="address">Address to add</param>
        public void AddAddress(CompanyAddress address)
        {
            if (this.addresses == null)
            {
                this.addresses = new List <CompanyAddress>();
            }

            this.addresses.Add(address);
        }
Exemplo n.º 2
0
        /// <summary>Gets a descriptive text with the differences between tow company address</summary>
        /// <param name="address1">First address</param>
        /// <param name="address2">Second address</param>
        /// <returns>Descriptive text with the differences between tow company address</returns>
        public static string Differences(CompanyAddress address1, CompanyAddress address2)
        {
            if (address1 == null || address2 == null)
            {
                return(string.Empty);
            }

            var res = new StringBuilder();

            if (address1.Address != address2.Address)
            {
                res.Append("Address:").Append(address2.Address).Append(", ");
            }

            if (address1.PostalCode != address2.PostalCode)
            {
                res.Append("PostalCode:").Append(address2.PostalCode).Append(", ");
            }

            if (address1.City != address2.City)
            {
                res.Append("City:").Append(address2.City).Append(", ");
            }

            if (address1.Province != address2.Province)
            {
                res.Append("Province:").Append(address2.Province).Append(", ");
            }

            if (address1.Country != address2.Country)
            {
                res.Append("Country:").Append(address2.Country).Append(", ");
            }

            if (address1.Phone != address2.Phone)
            {
                res.Append("Phone:").Append(address2.Phone).Append(", ");
            }

            if (address1.Mobile != address2.Mobile)
            {
                res.Append("Mobile:").Append(address2.Mobile).Append(";");
            }

            if (address1.Fax != address2.Fax)
            {
                res.Append("Fax:").Append(address2.Fax).Append(", ");
            }

            if (address1.Email != address2.Email)
            {
                res.Append("Email:").Append(address2.Email).Append(", ");
            }

            return(res.ToString());
        }
Exemplo n.º 3
0
        public Company(int companyId)
        {
            this.id                = -1;
            this.mailContact       = string.Empty;
            this.web               = string.Empty;
            this.subscriptionEnd   = DateTime.Now;
            this.subscriptionStart = DateTime.Now;
            this.name              = string.Empty;
            this.language          = "es";

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

                try
                {
                    cmd.Connection.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    if (rdr.HasRows)
                    {
                        rdr.Read();
                        this.id                = rdr.GetInt32(0);
                        this.name              = rdr.GetString(1);
                        this.mailContact       = string.Empty;
                        this.web               = string.Empty;
                        this.subscriptionStart = rdr.GetDateTime(2);
                        this.subscriptionEnd   = rdr.GetDateTime(3);
                        this.language          = rdr.GetString(4);
                        this.nif               = rdr.GetString(5);
                    }

                    this.departments = Company.GetDepartments(this.id);
                    this.addresses   = CompanyAddress.GetAddressByCompanyId(this);
                    foreach (CompanyAddress address in this.addresses)
                    {
                        if (address.DefaultAddress)
                        {
                            this.defaultAddress = address;
                            break;
                        }
                    }

                    this.GetEmployees();
                }
                catch
                {
                    this.id                = -1;
                    this.mailContact       = string.Empty;
                    this.web               = string.Empty;
                    this.subscriptionEnd   = DateTime.Now;
                    this.subscriptionStart = DateTime.Now;
                    this.name              = string.Empty;
                }
                finally
                {
                    if (cmd.Connection.State != ConnectionState.Closed)
                    {
                        cmd.Connection.Close();
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>Initializes a new instance of the Company class.
        /// Company data is searched on database based in company identifier
        /// </summary>
        /// <param name="companyId">Company identifier</param>
        public Company(int companyId)
        {
            this.Id                = -1;
            this.MailContact       = string.Empty;
            this.Web               = string.Empty;
            this.SubscriptionEnd   = DateTime.Now;
            this.SubscriptionStart = DateTime.Now;
            this.Name              = string.Empty;
            this.Headquarters      = string.Empty;
            this.Language          = "es";
            this.DiskQuote         = 0;

            string source = string.Format(CultureInfo.InvariantCulture, "cto::Company({0})", companyId);

            using (var cmd = new SqlCommand("Company_GetById"))
            {
                using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString))
                {
                    cmd.Connection  = cnn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@CompanyId", SqlDbType.Int);
                    cmd.Parameters["@CompanyId"].Value = companyId;

                    try
                    {
                        cmd.Connection.Open();
                        using (var rdr = cmd.ExecuteReader())
                        {
                            if (rdr.HasRows)
                            {
                                rdr.Read();
                                this.Id                = rdr.GetInt32(0);
                                this.Name              = rdr[1].ToString();
                                this.MailContact       = string.Empty;
                                this.Web               = string.Empty;
                                this.SubscriptionStart = rdr.GetDateTime(2);
                                this.SubscriptionEnd   = rdr.GetDateTime(3);
                                this.Language          = Convert.ToString(rdr[4], CultureInfo.InvariantCulture);
                                this.FiscalNumber      = rdr[5].ToString();
                                this.Code              = rdr[6].ToString();
                                this.DiskQuote         = rdr.GetInt64(8);
                                this.Agreement         = rdr.GetBoolean(9);
                                this.Headquarters      = rdr.GetString(10);
                            }

                            this.departments = Company.ObtainDepartments(this.Id);
                            this.addresses   = CompanyAddress.GetAddressByCompanyId(this).ToList();
                            foreach (var address in this.addresses)
                            {
                                if (address.DefaultAddress)
                                {
                                    this.defaultAddress = address;
                                    break;
                                }
                            }

                            this.ObtainEmployees();
                        }
                    }
                    catch (SqlException ex)
                    {
                        ExceptionManager.Trace(ex, string.Format(CultureInfo.InstalledUICulture, "cto::Company({0})", companyId));
                        this.Id                = -1;
                        this.MailContact       = string.Empty;
                        this.Web               = string.Empty;
                        this.SubscriptionEnd   = DateTime.Now;
                        this.SubscriptionStart = DateTime.Now;
                        this.Name              = string.Empty;
                        this.Headquarters      = string.Empty;
                    }
                    catch (FormatException ex)
                    {
                        ExceptionManager.Trace(ex, string.Format(CultureInfo.InstalledUICulture, "cto::Company({0})", companyId));
                        this.Id                = -1;
                        this.MailContact       = string.Empty;
                        this.Web               = string.Empty;
                        this.SubscriptionEnd   = DateTime.Now;
                        this.SubscriptionStart = DateTime.Now;
                        this.Name              = string.Empty;
                        this.Headquarters      = string.Empty;
                    }
                    catch (NullReferenceException ex)
                    {
                        ExceptionManager.Trace(ex, string.Format(CultureInfo.InstalledUICulture, "cto::Company({0})", companyId));
                        this.Id                = -1;
                        this.MailContact       = string.Empty;
                        this.Web               = string.Empty;
                        this.SubscriptionEnd   = DateTime.Now;
                        this.SubscriptionStart = DateTime.Now;
                        this.Name              = string.Empty;
                        this.Headquarters      = string.Empty;
                    }
                    catch (ArgumentNullException ex)
                    {
                        ExceptionManager.Trace(ex, string.Format(CultureInfo.InvariantCulture, "cto::Company({0})", companyId));
                        this.Id                = -1;
                        this.MailContact       = string.Empty;
                        this.Web               = string.Empty;
                        this.SubscriptionEnd   = DateTime.Now;
                        this.SubscriptionStart = DateTime.Now;
                        this.Name              = string.Empty;
                    }
                    catch (ArgumentException ex)
                    {
                        ExceptionManager.Trace(ex, string.Format(CultureInfo.InvariantCulture, "cto::Company({0})", companyId));
                        this.Id                = -1;
                        this.MailContact       = string.Empty;
                        this.Web               = string.Empty;
                        this.SubscriptionEnd   = DateTime.Now;
                        this.SubscriptionStart = DateTime.Now;
                        this.Name              = string.Empty;
                        this.Headquarters      = string.Empty;
                    }
                    finally
                    {
                        if (cmd.Connection.State != ConnectionState.Closed)
                        {
                            cmd.Connection.Close();
                        }
                    }
                }
            }

            this.countries = new List <Country>();
            using (var cmdCountries = new SqlCommand("Company_GetCountries"))
            {
                using (var cnnCountry = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ToString()))
                {
                    cmdCountries.Connection  = cnnCountry;
                    cmdCountries.CommandType = CommandType.StoredProcedure;
                    try
                    {
                        cmdCountries.Parameters.Add(DataParameter.Input("@CompanyId", companyId));
                        cmdCountries.Connection.Open();
                        using (var rdrCountries = cmdCountries.ExecuteReader())
                        {
                            while (rdrCountries.Read())
                            {
                                this.countries.Add(new Country()
                                {
                                    Id = rdrCountries.GetInt32(0), Description = rdrCountries.GetString(1)
                                });
                            }
                        }
                    }
                    catch (SqlException ex)
                    {
                        ExceptionManager.Trace(ex, source);
                    }
                    catch (FormatException ex)
                    {
                        ExceptionManager.Trace(ex, source);
                    }
                    catch (NullReferenceException ex)
                    {
                        ExceptionManager.Trace(ex, source);
                    }
                    catch (ArgumentNullException ex)
                    {
                        ExceptionManager.Trace(ex, source);
                    }
                    catch (ArgumentException ex)
                    {
                        ExceptionManager.Trace(ex, source);
                    }
                    finally
                    {
                        if (cmdCountries.Connection.State != ConnectionState.Closed)
                        {
                            cmdCountries.Connection.Close();
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>Insert an address into data base</summary>
        /// <param name="address">Address to insert</param>
        /// <param name="userId">Identifier of user that perfomrs the action</param>
        /// <returns>Result of action</returns>
        public static ActionResult Insert(CompanyAddress address, int userId)
        {
            var res = ActionResult.NoAction;

            if (address == null)
            {
                return(res);
            }

            /* CREATE PROCEDURE CompanyAddress_Insert
             * @CompanyAddressId int out,
             * @CompanyId int,
             * @Address nvarchar(50),
             * @PostalCode nvarchar(10),
             * @City nvarchar(50),
             * @Province nvarchar(50),
             * @Country nvarchar(15),
             * @Phone nvarchar(15),
             * @Mobile nvarchar(15),
             * @Email nvarchar(10),
             * @Notes text,
             * @Fax nvarchar(15),
             * @UserId int*/

            using (var cmd = new SqlCommand("CompanyAddress_Insert"))
            {
                using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString))
                {
                    cmd.Connection  = cnn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    try
                    {
                        int companyId = 0;
                        if (address.Company != null)
                        {
                            companyId = address.Company.Id;
                        }

                        cmd.Parameters.Add(DataParameter.OutputInt("@CompanyAddressId"));
                        cmd.Parameters.Add(DataParameter.Input("@CompanyId", companyId));
                        cmd.Parameters.Add(DataParameter.Input("@Address", address.Address, 100));
                        cmd.Parameters.Add(DataParameter.Input("@PostalCode", address.PostalCode, 10));
                        cmd.Parameters.Add(DataParameter.Input("@City", address.City, 50));
                        cmd.Parameters.Add(DataParameter.Input("@Province", address.Province, 50));
                        cmd.Parameters.Add(DataParameter.Input("@Country", address.Country, 15));
                        cmd.Parameters.Add(DataParameter.Input("@Phone", address.Phone, 15));
                        cmd.Parameters.Add(DataParameter.Input("@Mobile", address.Mobile, 15));
                        cmd.Parameters.Add(DataParameter.Input("@Email", address.Email, 50));
                        cmd.Parameters.Add(DataParameter.Input("@Notes", address.Notes));
                        cmd.Parameters.Add(DataParameter.Input("@Fax", address.Fax, 15));
                        cmd.Parameters.Add(DataParameter.Input("@UserId", userId));
                        cmd.Connection.Open();
                        cmd.ExecuteNonQuery();
                        res.Success      = true;
                        res.MessageError = cmd.Parameters["@CompanyAddressId"].Value.ToString();
                    }
                    finally
                    {
                        if (cmd.Connection.State != ConnectionState.Closed)
                        {
                            cmd.Connection.Close();
                        }
                    }
                }
            }

            return(res);
        }