/// <summary>
 /// Save the translation of the term
 /// </summary>
 private void BtnSave()
 {
     using (TMExpressionTranslation tt = TMExpressionTranslation.GetByKey(expressionId, languageCode))
     {
         if (tt != null)
         {
             #region Update translation
             tt.UserId = SessionState.User.Id;
             tt.Value  = txtTMExpressionValue.Text.Trim();
             #endregion
             int r = tt.Save();
             #region Save result
             if (r > 0)
             {
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "reloadParent", "<script>ReloadParent();top.close();</script>");
             }
             else
             {
                 lbMessage.Text     = TMExpressionTranslation.LastError;
                 lbMessage.CssClass = "hc_error";
                 lbMessage.Visible  = true;
             }
             #endregion
         }
         else
         {
             lbMessage.Text     = TMExpressionTranslation.LastError;
             lbMessage.CssClass = "hc_error";
             lbMessage.Visible  = true;
         }
     }
 }
Exemplo n.º 2
0
    /// <summary>
    /// Save translations
    /// </summary>
    private void Save()
    {
        bool canUpdate;

        for (int i = 0; i < dg.Rows.Count; i++)
        {
            string                  languageCode         = dg.Rows[i].Cells.FromKey("LanguageCode").Text;
            TemplatedColumn         col                  = (TemplatedColumn)dg.Rows[i].Cells.FromKey("Value").Column;
            TextBox                 tb                   = (TextBox)((CellItem)col.CellItems[i]).FindControl("TXTChangedValue");
            string                  newTMExpressionValue = tb.Text;
            TMExpressionTranslation tt;
            using (tt = TMExpressionTranslation.GetByKey(expressionId, languageCode))
            {
                if (tt == null)
                {
                    canUpdate = newTMExpressionValue != null;
                    if (canUpdate)
                    {
                        canUpdate = newTMExpressionValue.Trim() != string.Empty;
                    }
                    #region New Translation
                    if (canUpdate)
                    {
                        tt = new TMExpressionTranslation(expressionId, newTMExpressionValue, languageCode, dg.Rows[i].Cells.FromKey("Rtl").Text.ToLower() == "true",
                                                         SessionState.User.Id, DateTime.UtcNow);
                        int r = tt.Save();
                        if (r < 0)
                        {
                            lbMessage.Text     = "Error: Translation [" + languageCode + "] can't be created";
                            lbMessage.CssClass = "hc_error";
                            lbMessage.Visible  = true;
                            break;
                        }
                    }
                    #endregion
                }
                #region Translation already exist
                else
                {
                    if (tt.Value != newTMExpressionValue)
                    {
                        tt.LanguageCode = languageCode;
                        tt.Value        = newTMExpressionValue;
                        tt.Rtl          = dg.Rows[i].Cells.FromKey("Rtl").Text.ToLower() == "true";
                        canUpdate       = newTMExpressionValue != null;
                        if (canUpdate)
                        {
                            canUpdate = newTMExpressionValue.Trim() != string.Empty;
                        }
                        #region Value modified
                        if (canUpdate)
                        {
                            int r = tt.Save();
                            if (r < 0)
                            {
                                lbMessage.Text     = "Error: Translation [" + languageCode + "] can't be updated";
                                lbMessage.CssClass = "hc_error";
                                lbMessage.Visible  = true;
                                break;
                            }
                        }
                        #endregion
                        #region Value deleted
                        else
                        {
                            if (!tt.Delete(HyperCatalog.Shared.SessionState.User.Id))
                            {
                                lbMessage.Text     = "Error: localization [" + languageCode + "] can't be deleted";
                                lbMessage.CssClass = "hc_error";
                                lbMessage.Visible  = true;
                                break;
                            }
                        }
                        #endregion
                    }
                }
                #endregion
            }
        }
        ShowTMTranslations();
        lbMessage.Text     = "Data saved";
        lbMessage.CssClass = "hc_success";
        lbMessage.Visible  = true;
        using (Database dbObj = Utils.GetMainDB())
        {
            UITools.RefreshTab(Page, "Translations", Utils.GetCount(dbObj, String.Format("SELECT COUNT(*) FROM TMTranslations WHERE TMExpressionId = {0}", expressionId)));
        }
    }