예제 #1
0
    private void mSave()
    {
        if (mValidateAddEdit())
        {
            try
            {
                Languages languages = new Languages();
                if (pIDLanguage.HasValue)
                {
                    languages.LoadByPrimaryKey(pIDLanguage.Value);
                }
                else
                {
                    languages.AddNew();
                    languages.pPriority = mSetPriority();
                }

                languages.pTitle     = txtTitle.Text;
                languages.pCode      = txtCode.Text;
                languages.pIsRTL     = cbxIsRTL.Checked;
                languages.pIsActive  = cbxIsActive.Checked;
                languages.pIsDefault = cbxIsDefault.Checked;
                if (cbxIsDefault.Checked)
                {
                    mFalseAllRecordsForDefault();
                }

                if (cbxIsActive.Checked)
                {
                    string LocaleFile = string.Format("{0}{1}.xml", Global.Constants.FOLDER_CLIENT_LOCALE, txtCode.Text);
                    if (!File.Exists(Server.MapPath(LocaleFile)))
                    {
                        string      translateTemplateFile = string.Format("{0}{1}", Global.Constants.FOLDER_CLIENT_LOCALE, Global.Constants.FILE_TRANSLATOR_TEMPLATE_XML);
                        XmlDocument doc = new XmlDocument();
                        doc.Load(Server.MapPath(translateTemplateFile));
                        XmlNode root = doc.DocumentElement;
                        root.Attributes["name"].Value      = txtCode.Text;
                        root.Attributes["full_name"].Value = txtTitle.Text;
                        doc.Save(Server.MapPath(LocaleFile));
                    }
                }

                languages.Save();

                if (cbxIsDefault.Checked)
                {
                    Farschidus.Translator.SetPublicDefaultLanguage(languages.pIDLanguage.ToString());
                }

                pMessage.Clear();
                pMessage.Add(Farschidus.Translator.AppTranslate["general.message.success"], Farschidus.Web.UI.Message.MessageTypes.Success);
                mShowMessage(pMessage);

                if (!pIDLanguage.HasValue)
                {
                    mClear();
                }
            }
            catch (Exception ex)
            {
                pMessage.Clear();
                pMessage.Add(ex.Message, Farschidus.Web.UI.Message.MessageTypes.Error);
                mShowMessage(pMessage);
            }
        }
        else
        {
            mShowMessage(pMessage);
        }
    }