2

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();
            }
        }
    }
4

1 回答 1

0

您需要根据用户的文化设置线程的文化:

Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureString);

cultureString从数据库中读取的“en-GB”或“fr-FR”在哪里。

您应该只在创建类或改变文化时才需要这样做。然后代码应该选择正确的资源文件

于 2013-05-08T14:31:03.590 回答