SpellCheck.aspx
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:19k
源码类别:

OA系统

开发平台:

C#

  1. <%@ Page Language="C#" ClassName="PopUpSpell" ValidateRequest="False" %>
  2. <%@ import Namespace="System.IO" %>
  3. <%@ import Namespace="NetSpell.SpellChecker" %>
  4. <%@ import Namespace="NetSpell.SpellChecker.Dictionary" %>
  5. <script runat="server">
  6.     NetSpell.SpellChecker.Spelling SpellChecker;
  7.     NetSpell.SpellChecker.Dictionary.WordDictionary WordDictionary;
  8.     
  9.     string culture = "en-US";
  10.    
  11.     void Page_Load(object sender, EventArgs e)
  12.     {
  13.          // if modal frame, quit
  14.          if (this.ModalFrame.Visible)
  15.              return;
  16.          // add client side events
  17.          this.Suggestions.Attributes.Add("onChange", "javascript: changeWord(this);");
  18.          this.SpellingBody.Attributes.Add("onLoad", "javascript: initialize();");
  19.          // load spell checker settings
  20.          this.LoadValues();
  21.          switch (this.SpellMode.Value)
  22.          {
  23.              case "start" :
  24.                  this.EnableButtons();
  25.                  this.SpellChecker.SpellCheck();
  26.                  break;
  27.              case "suggest" :
  28.                  this.EnableButtons();
  29.                  break;
  30.              case "load" :
  31.              case "end" :
  32.              default :
  33.                  this.DisableButtons();
  34.                  break;
  35.          }
  36.          
  37.     }
  38.     void Page_Init(object sender, EventArgs e)
  39.     {
  40.          // show iframe for modal support
  41.          if (Request.Params["Modal"] != null)
  42.          {
  43.              this.ModalFrame.Visible = true;
  44.              this.SuggestionForm.Visible = false;
  45.              return;
  46.          }         
  47.          
  48.          if (Request.Params["Culture"] != null)
  49.  {
  50. culture = Request.Params["Culture"];
  51.  }
  52.          // get dictionary from cache
  53.          this.WordDictionary = (WordDictionary)HttpContext.Current.Cache["WordDictionary-" + culture];
  54.          if (this.WordDictionary == null)
  55.          {
  56.              // if not in cache, create new
  57.              this.WordDictionary = new NetSpell.SpellChecker.Dictionary.WordDictionary();
  58.              this.WordDictionary.EnableUserFile = false;
  59.              //getting folder for dictionaries
  60.              string folderName="";
  61.              
  62.              if(ConfigurationSettings.AppSettings["DictionaryFolder"]== null)
  63. folderName = this.MapPath("~/bin");
  64.  else
  65.  {
  66. folderName = ConfigurationSettings.AppSettings["DictionaryFolder"];
  67. folderName = this.MapPath(Path.Combine(Request.ApplicationPath, folderName));
  68.  }
  69.              
  70.              this.WordDictionary.DictionaryFolder = folderName;
  71.              
  72.              // check if a dictionary exists for the culture, if so load it
  73.              string cultureDictionary = String.Concat (culture, ".dic");
  74.  if (File.Exists (folderName +"\"+ cultureDictionary))
  75.  {    
  76. this.WordDictionary.DictionaryFile = cultureDictionary;
  77.  }
  78.  else
  79.  {
  80.   this.WordDictionary.DictionaryFile = "en-US.dic";
  81.  }
  82.              //load and initialize the dictionary
  83.              this.WordDictionary.Initialize();
  84.              
  85.              // Store the Dictionary in cache
  86.              HttpContext.Current.Cache.Insert("WordDictionary-" + culture, this.WordDictionary, new CacheDependency(Path.Combine(folderName, this.WordDictionary.DictionaryFile)));
  87.          }
  88.          // create spell checker
  89.          this.SpellChecker = new NetSpell.SpellChecker.Spelling();
  90.          this.SpellChecker.ShowDialog = false;
  91.          this.SpellChecker.Dictionary = this.WordDictionary;
  92.          // adding events
  93.          this.SpellChecker.MisspelledWord += new NetSpell.SpellChecker.Spelling.MisspelledWordEventHandler(this.SpellChecker_MisspelledWord);
  94.          this.SpellChecker.EndOfText += new NetSpell.SpellChecker.Spelling.EndOfTextEventHandler(this.SpellChecker_EndOfText);
  95.          this.SpellChecker.DoubledWord += new NetSpell.SpellChecker.Spelling.DoubledWordEventHandler(this.SpellChecker_DoubledWord);
  96.     }
  97.     void SpellChecker_DoubledWord(object sender, NetSpell.SpellChecker.SpellingEventArgs e)
  98.     {
  99.          this.SaveValues();
  100.          this.CurrentWord.Text = this.SpellChecker.CurrentWord;
  101.          this.Suggestions.Items.Clear();
  102.          this.ReplacementWord.Text = string.Empty;
  103.          this.SpellMode.Value = "suggest";
  104.          this.StatusText.Text = string.Format("Word: {0} of {1}", this.SpellChecker.WordIndex + 1, this.SpellChecker.WordCount);
  105.     }
  106.     void SpellChecker_EndOfText(object sender, System.EventArgs e)
  107.     {
  108.          this.SaveValues();
  109.          this.SpellMode.Value = "end";
  110.          this.DisableButtons();
  111.          this.StatusText.Text = string.Format("Word: {0} of {1}", this.SpellChecker.WordIndex + 1, this.SpellChecker.WordCount);
  112.     }
  113.     void SpellChecker_MisspelledWord(object sender, NetSpell.SpellChecker.SpellingEventArgs e)
  114.     {
  115.          this.SaveValues();
  116.          this.CurrentWord.Text = this.SpellChecker.CurrentWord;
  117.          this.SpellChecker.Suggest();
  118.          this.Suggestions.DataSource = this.SpellChecker.Suggestions;
  119.          this.Suggestions.DataBind();
  120.          this.ReplacementWord.Text = string.Empty;
  121.          this.SpellMode.Value = "suggest";
  122.          this.StatusText.Text = string.Format("Word: {0} of {1}", this.SpellChecker.WordIndex + 1, this.SpellChecker.WordCount);
  123.     }
  124.     void EnableButtons()
  125.     {
  126.          this.IgnoreButton.Enabled = true;
  127.          this.IgnoreAllButton.Enabled = true;
  128.          this.AddButton.Enabled = true;
  129.          this.ReplaceButton.Enabled = true;
  130.          this.ReplaceAllButton.Enabled = true;
  131.          this.ReplacementWord.Enabled = true;
  132.          this.Suggestions.Enabled = true;
  133.     }
  134.     void DisableButtons()
  135.     {
  136.          this.IgnoreButton.Enabled = false;
  137.          this.IgnoreAllButton.Enabled = false;
  138.          this.AddButton.Enabled = false;
  139.          this.ReplaceButton.Enabled = false;
  140.          this.ReplaceAllButton.Enabled = false;
  141.          this.ReplacementWord.Enabled = false;
  142.          this.Suggestions.Enabled = false;
  143.     }
  144.     void SaveValues()
  145.     {
  146.          this.CurrentText.Value = this.SpellChecker.Text;
  147.          this.WordIndex.Value = this.SpellChecker.WordIndex.ToString();
  148.          // save ignore words
  149.          string[] ignore = (string[])this.SpellChecker.IgnoreList.ToArray(typeof(string));
  150.          this.IgnoreList.Value = String.Join("|", ignore);
  151.          // save replace words
  152.          ArrayList tempArray = new ArrayList(this.SpellChecker.ReplaceList.Keys);
  153.          string[] replaceKey = (string[])tempArray.ToArray(typeof(string));
  154.          this.ReplaceKeyList.Value = String.Join("|", replaceKey);
  155.          tempArray = new ArrayList(this.SpellChecker.ReplaceList.Values);
  156.          string[] replaceValue = (string[])tempArray.ToArray(typeof(string));
  157.          this.ReplaceValueList.Value = String.Join("|", replaceValue);
  158.          // saving user words
  159.          tempArray = new ArrayList(this.SpellChecker.Dictionary.UserWords.Keys);
  160.          string[] userWords = (string[])tempArray.ToArray(typeof(string));
  161.          Response.Cookies["UserWords"].Value = String.Join("|", userWords);;
  162.          Response.Cookies["UserWords"].Path = "/";
  163.          Response.Cookies["UserWords"].Expires = DateTime.Now.AddMonths(1);
  164.     }
  165.     void LoadValues()
  166.     {
  167.          if (this.CurrentText.Value.Length > 0)
  168.              this.SpellChecker.Text = this.CurrentText.Value;
  169.          if (this.WordIndex.Value.Length > 0)
  170.              this.SpellChecker.WordIndex = int.Parse(this.WordIndex.Value);
  171.          // restore ignore list
  172.          if (this.IgnoreList.Value.Length > 0)
  173.          {
  174.              this.SpellChecker.IgnoreList.Clear();
  175.              this.SpellChecker.IgnoreList.AddRange(this.IgnoreList.Value.Split('|'));
  176.          }
  177.          // restore replace list
  178.          if (this.ReplaceKeyList.Value.Length > 0 && this.ReplaceValueList.Value.Length > 0)
  179.          {
  180.              string[] replaceKeys = this.ReplaceKeyList.Value.Split('|');
  181.              string[] replaceValues = this.ReplaceValueList.Value.Split('|');
  182.              this.SpellChecker.ReplaceList.Clear();
  183.              if (replaceKeys.Length == replaceValues.Length)
  184.              {
  185.                  for (int i = 0; i < replaceKeys.Length; i++)
  186.                  {
  187.                      if (replaceKeys[i].Length > 0)
  188.                          this.SpellChecker.ReplaceList.Add(replaceKeys[i], replaceValues[i]);
  189.                  }
  190.              }
  191.          }
  192.          // restore user words
  193.          this.SpellChecker.Dictionary.UserWords.Clear();
  194.          if (Request.Cookies["UserWords"] != null)
  195.          {
  196.              string[] userWords = Request.Cookies["UserWords"].Value.Split('|');
  197.              for (int i = 0; i < userWords.Length; i++)
  198.              {
  199.                  if (userWords[i].Length > 0)
  200.                      this.SpellChecker.Dictionary.UserWords.Add(userWords[i], userWords[i]);
  201.              }
  202.          }
  203.     }
  204.     void IgnoreButton_Click(object sender, EventArgs e)
  205.     {
  206.          this.SpellChecker.IgnoreWord();
  207.          this.SpellChecker.SpellCheck();
  208.     }
  209.     void IgnoreAllButton_Click(object sender, EventArgs e)
  210.     {
  211.          this.SpellChecker.IgnoreAllWord();
  212.          this.SpellChecker.SpellCheck();
  213.     }
  214.     void AddButton_Click(object sender, EventArgs e)
  215.     {
  216.          this.SpellChecker.Dictionary.Add(this.SpellChecker.CurrentWord);
  217.          this.SpellChecker.SpellCheck();
  218.     }
  219.     void ReplaceButton_Click(object sender, EventArgs e)
  220.     {
  221.          this.SpellChecker.ReplaceWord(this.ReplacementWord.Text);
  222.          this.CurrentText.Value = this.SpellChecker.Text;
  223.          this.SpellChecker.SpellCheck();
  224.     }
  225.     void ReplaceAllButton_Click(object sender, EventArgs e)
  226.     {
  227.          this.SpellChecker.ReplaceAllWord(this.ReplacementWord.Text);
  228.          this.CurrentText.Value = this.SpellChecker.Text;
  229.          this.SpellChecker.SpellCheck();
  230.     }
  231. </script>
  232. <html xmlns="http://www.w3.org/1999/xhtml">
  233. <head runat="server" id="Head1">
  234.     <title>Spell Check &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  235. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  236. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  237. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  238. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  239. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  240. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  241. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  242. </title>
  243.     <link href="Load.ashx?type=style&file=spell.css" type="text/css" rel="stylesheet" />
  244.     <script type="text/javascript">
  245. var OxO825e=[]; window.focus() ;
  246.     </script>
  247.     <script language="JavaScript" src="Load.ashx?type=script&file=spell.js" type="text/javascript"></script>
  248. </head>
  249. <body id="SpellingBody" style="MARGIN: 0px" runat="server">
  250.     <form id="SpellingForm" name="SpellingForm" method="post" runat="server">
  251.         <input id="WordIndex" type="hidden" value="0" name="WordIndex" runat="server" />
  252.         <input id="CurrentText" type="hidden" name="CurrentText" runat="server" />
  253.         <input id="IgnoreList" type="hidden" name="IgnoreList" runat="server" />
  254.         <input id="ReplaceKeyList" type="hidden" name="ReplaceKeyList" runat="server" />
  255.         <input id="ReplaceValueList" type="hidden" name="ReplaceValueList" runat="server" />
  256.         <input id="ElementIndex" type="hidden" value="-1" name="ElementIndex" runat="server" />
  257.         <input id="SpellMode" type="hidden" value="load" name="SpellMode" runat="server" />
  258.         <asp:panel id="ModalFrame" runat="server" visible="False" enableviewstate="False">
  259.             <iframe id="SpellCheckFrame" hidefocus="hidefocus" name="SpellCheckFrame" src="SpellCheck.aspx?Culture=<%=Request.Params["Culture"]%>" frameborder="0" width="400" scrolling="no" height="300" style="width:400;height:300"></iframe>
  260.         </asp:panel>
  261.         <asp:panel id="SuggestionForm" runat="server" visible="true" enableviewstate="False">
  262.             <table cellspacing="0" cellpadding="5" width="100%">
  263.                 <tbody>
  264.                     <tr>
  265.                         <td valign="center" align="middle">
  266.                             <table cellspacing="0" cellpadding="2">
  267.                                 <tbody>
  268.                                     <tr>
  269.                                         <td style="WIDTH: 250px">
  270.                                             <em>Word Not in Dictionary:</em>
  271.                                         </td>
  272.                                         <td>
  273.                                             <asp:button id="IgnoreButton" onclick="IgnoreButton_Click" runat="server" enableviewstate="False" enabled="False" cssclass="button" text="Ignore"></asp:button>
  274.                                         </td>
  275.                                     </tr>
  276.                                     <tr>
  277.                                         <td>
  278.                                             <asp:Label id="CurrentWord" runat="server" font-bold="True" forecolor="Red"></asp:Label></td>
  279.                                         <td>
  280.                                             <asp:button id="IgnoreAllButton" onclick="IgnoreAllButton_Click" runat="server" enableviewstate="False" enabled="False" cssclass="button" text="Ignore All"></asp:button>
  281.                                         </td>
  282.                                     </tr>
  283.                                     <tr>
  284.                                         <td>
  285.                                             <em>Change To:</em>
  286.                                         </td>
  287.                                         <td>
  288.                                             <p>&nbsp;</p>
  289.                                         </td>
  290.                                     </tr>
  291.                                     <tr>
  292.                                         <td>
  293.                                             <asp:textbox id="ReplacementWord" runat="server" enableviewstate="False" enabled="False" cssclass="suggestion" columns="30" width="230px"></asp:textbox>
  294.                                         </td>
  295.                                         <td>
  296.                                             <asp:button id="AddButton" onclick="AddButton_Click" runat="server" enableviewstate="False" enabled="False" cssclass="button" text="Add"></asp:button>
  297.                                         </td>
  298.                                     </tr>
  299.                                     <tr>
  300.                                         <td>
  301.                                             <em>Suggestions:</em>
  302.                                         </td>
  303.                                         <td>
  304.                                             <p>&nbsp;</p>
  305.                                         </td>
  306.                                     </tr>
  307.                                     <tr>
  308.                                         <td rowspan="5">
  309.                                             <asp:listbox id="Suggestions" runat="server" enableviewstate="False" enabled="False" cssclass="suggestion" width="230px" rows="8"></asp:listbox>
  310.                                         </td>
  311.                                         <td>
  312.                                             <asp:button id="ReplaceButton" onclick="ReplaceButton_Click" runat="server" enableviewstate="False" enabled="False" cssclass="button" text="Replace"></asp:button>
  313.                                         </td>
  314.                                     </tr>
  315.                                     <tr>
  316.                                         <td>
  317.                                             <asp:button id="ReplaceAllButton" onclick="ReplaceAllButton_Click" runat="server" enableviewstate="False" enabled="False" cssclass="button" text="Replace All"></asp:button>
  318.                                         </td>
  319.                                     </tr>
  320.                                     <tr>
  321.                                         <td>
  322.                                             <p>&nbsp;</p>
  323.                                         </td>
  324.                                     </tr>
  325.                                     <tr>
  326.                                         <td>
  327.                                             <p>&nbsp;</p>
  328.                                         </td>
  329.                                     </tr>
  330.                                     <tr>
  331.                                         <td>
  332.                                             <input class="button" id="btnCancel" onclick="closeWindow()" type="button" value="Cancel" name="btnCancel" />
  333.                                         </td>
  334.                                     </tr>
  335.                                     <tr>
  336.                                         <td colspan="2">
  337.                                             <asp:Label id="StatusText" runat="Server" forecolor="DimGray" font-size="8pt">Loading
  338.                                             ...</asp:Label></td>
  339.                                     </tr>
  340.                                 </tbody>
  341.                             </table>
  342.                         </td>
  343.                     </tr>
  344.                 </tbody>
  345.             </table>
  346.         </asp:panel>
  347.     </form>
  348. </body>
  349. </html>
  350. <script type="text/javascript">
  351. var OxOda1c=["isWinIE","isGecko","isSafari","isOpera","userAgent","ua","opera","safari","gecko","msie","Mac","isMac","dialogWidth","availWidth","dialogHeight","availHeight","innerWidth","innerHeight"];var _Browser_TypeInfo=null; function Browser__InitType(){if(_Browser_TypeInfo!=null){return ;} ;var Ox4={}; Ox4[OxOda1c[0x5]]=navigator[OxOda1c[0x4]].toLowerCase(),Ox4[OxOda1c[0x3]]=(Ox4[OxOda1c[0x5]].indexOf(OxOda1c[0x6])>-0x1),Ox4[OxOda1c[0x2]]=(Ox4[OxOda1c[0x5]].indexOf(OxOda1c[0x7])>-0x1),Ox4[OxOda1c[0x1]]=(!Ox4[OxOda1c[0x3]]&&!Ox4[OxOda1c[0x2]]&&Ox4[OxOda1c[0x5]].indexOf(OxOda1c[0x8])>-0x1),Ox4[OxOda1c[0x0]]=(!Ox4[OxOda1c[0x3]]&&Ox4[OxOda1c[0x5]].indexOf(OxOda1c[0x9])>-0x1) ; Ox4[OxOda1c[0xb]]=navigator[OxOda1c[0x4]].indexOf(OxOda1c[0xa])!=-0x1 ; _Browser_TypeInfo=Ox4 ;}  ; Browser__InitType() ; function Browser_IsWinIE(){return _Browser_TypeInfo[OxOda1c[0x0]];}  ;try{if(Browser_IsWinIE()){ top.moveTo((screen[OxOda1c[0xd]]-self[OxOda1c[0xc]])/0x2,(screen[OxOda1c[0xf]]-self[OxOda1c[0xe]])/0x2) ;} else { top.moveTo((screen[OxOda1c[0xd]]-self[OxOda1c[0x10]])/0x2,(screen[OxOda1c[0xf]]-self[OxOda1c[0x11]])/0x2) ;} ;} catch(x){} ;
  352. </script>