Paul

Paul

  • NA
  • 13
  • 0

Asp.net / C#: How to get the right resource from a class lib

May 8 2013 8:48 AM
I have a web application written with C#/ASP.NET that use a Class Library to Get, Insert & Update information.
This is application runs with 2 different language: English & French.

Once the user logged in, I can detect his culture (already stored in db) and it displays correctly french/english labels correctly by retrieving the right resource file.

In the Class Library (.dll), I added 2 Resource Files for French & English version to return error message based on the user culture.

So my problem is when I try to update user profile and the culture is french, and in the "Address" field is empty the system keeps returning the english message no matter the user culture


Here's a snapshot from my Class Library (.dll)


    public string Address1
        {
            get { return _Address1; }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    // Error! The field « Address » is mandatory!");
                    throw new Exception(Resources.CTenant_Messages.Address1_Missing.ToString());
                }


                else if (value.ToString().Trim().Length > LibNamtek.Public.CConstant.LENGTH_300)
                {
                    // Error! The total length for « Address » exceeds " + LibNamtek.Public.CConstant.LENGTH_300.ToString() + " caracters.");
                    throw new Exception(Resources.CTenant_Messages.Address1_Length.ToString().Replace("[LENGTH]", LibNamtek.Public.CConstant.LENGTH_300.ToString()));
                }
                else
                {
                    _Address1 = value;
                }
            }
        }




        public DataSet UpdateUser()
        {
            string v_connection_string = CConnection.GetDBConnection();
            SqlConnection v_connection = new SqlConnection(v_connection_string);


            try
            {
                // Open Connection
                v_connection.Open();


                SqlCommand cmd = new SqlCommand("pr_update_user", v_connection);
                cmd.CommandType = CommandType.StoredProcedure;


                cmd.Parameters.Add("@p_user_id", SqlDbType.Int);
                cmd.Parameters["@p_user_id"].Value = this.UserId;


                cmd.Parameters.Add("@p_name", SqlDbType.NVarChar);
                cmd.Parameters["@p_name"].Size = LibNamtek.Public.CConstant.LENGTH_300;
                cmd.Parameters["@p_name"].Value = this.Name;


                cmd.Parameters.Add("@p_address1", SqlDbType.NVarChar);
                cmd.Parameters["@p_address1"].Size = LibNamtek.Public.CConstant.LENGTH_300;
                cmd.Parameters["@p_address1"].Value = this.Address1;;


                cmd.Parameters.Add("@p_address2", SqlDbType.NVarChar);
                cmd.Parameters["@p_address2"].Size = LibNamtek.Public.CConstant.LENGTH_300;
                cmd.Parameters["@p_address2"].Value = (this.Address2 == LibNamtek.Public.CConstant.DEFAULT_STRING ? DBNull.Value : (object)this.Address2);


                cmd.Parameters.Add("@p_city", SqlDbType.NVarChar);
                cmd.Parameters["@p_city"].Size = LibNamtek.Public.CConstant.LENGTH_300;
                cmd.Parameters["@p_city"].Value = this.City;


                cmd.Parameters.Add("@p_province", SqlDbType.NVarChar);
                cmd.Parameters["@p_province"].Size = LibNamtek.Public.CConstant.LENGTH_300;
                cmd.Parameters["@p_province"].Value = this.Province;


                cmd.Parameters.Add("@p_country_id", SqlDbType.Int);
                cmd.Parameters["@p_country_id"].Value = this.CountryId;


                cmd.Parameters.Add("@p_postal_code", SqlDbType.NVarChar);
                cmd.Parameters["@p_postal_code"].Size = LibNamtek.Public.CConstant.LENGTH_30;
                cmd.Parameters["@p_postal_code"].Value = this.PostalCode;


                cmd.Parameters.Add("@p_phone1", SqlDbType.NVarChar);
                cmd.Parameters["@p_phone1"].Size = LibNamtek.Public.CConstant.LENGTH_30;
                cmd.Parameters["@p_phone1"].Value = this.Phone1;


                cmd.Parameters.Add("@p_fax", SqlDbType.NVarChar);
                cmd.Parameters["@p_fax"].Size = LibNamtek.Public.CConstant.LENGTH_30;
                cmd.Parameters["@p_fax"].Value = (this.Fax == LibNamtek.Public.CConstant.DEFAULT_STRING ? DBNull.Value : (object)this.Fax);


                cmd.Parameters.Add("@p_email", SqlDbType.NVarChar);
                cmd.Parameters["@p_email"].Size = LibNamtek.Public.CConstant.LENGTH_300;
                cmd.Parameters["@p_email"].Value = this.Email;


                cmd.Parameters.Add("@p_memo", SqlDbType.NVarChar);
                cmd.Parameters["@p_memo"].Value = (this.Memo == LibNamtek.Public.CConstant.DEFAULT_STRING ? DBNull.Value : (object)this.Memo);


                cmd.Parameters.Add("@p_system_date", SqlDbType.DateTime);
                cmd.Parameters["@p_system_date"].Value = this.SystemDate;


                cmd.Parameters.Add("@p_system_user", SqlDbType.NVarChar);
                cmd.Parameters["@p_system_user"].Size = LibNamtek.Public.CConstant.LENGTH_30;
                cmd.Parameters["@p_system_user"].Value = this.SystemUser;


                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet("UpdateTenant");
                da.Fill(ds);


                return ds;


            }


            catch (Exception ex)
            {
                throw ex;
            }


            finally
            {
                if (v_connection != null)
                {
                    v_connection.Close();
                }
            }
        }