/// <summary> /// 打开指定的表单模板或者表单模板文件对应的脚本 /// </summary> /// <param name="docTypeInfo">表单模板信息</param> /// <param name="szHndfFile">表单模板文件</param> /// <returns>是否成功</returns> public bool Open(TempletType docTypeInfo, string szHndfFile) { this.IsModified = false; this.m_hndfFile = szHndfFile; this.m_docTypeInfo = docTypeInfo; this.RefreshFormText(); FormFileParser parser = new FormFileParser(); this.textEditor1.Text = parser.GetScriptData(szHndfFile); if (GlobalMethods.Misc.IsEmptyString(this.textEditor1.Text)) { string szDefaultHndfFile = string.Format("{0}\\Templet\\Default.hndt" , GlobalMethods.Misc.GetWorkingPath()); this.textEditor1.Text = parser.GetScriptData(szDefaultHndfFile); } this.IsModified = false; return(true); }
//internal short OpenTemplet(DocTypeInfo docTypeInfo) //{ // if (docTypeInfo == null) // return SystemData.ReturnValue.FAILED; // DesignEditForm designEditForm = this.GetDesignForm(docTypeInfo); // if (designEditForm != null) // { // designEditForm.Activate(); // return SystemData.ReturnValue.OK; // } // designEditForm = new DesignEditForm(this.MainForm); // designEditForm.FlagCode = Guid.NewGuid().ToString(); // this.MainForm.OpenDesignEditForm(designEditForm); // string szDocTypeID = docTypeInfo.DocTypeID; // string szHndfFile = string.Format("{0}\\Cache\\{1}.hndt" // , GlobalMethods.Misc.GetWorkingPath(), szDocTypeID); // byte[] byteTempletData = null; // //short shRet = TempletService.Instance.GetFormTemplet(szDocTypeID, ref byteTempletData); // //if (shRet != SystemData.ReturnValue.OK) // // return shRet; // GlobalMethods.IO.WriteFileBytes(szHndfFile, byteTempletData); // return designEditForm.Open(docTypeInfo, szHndfFile) ? // SystemData.ReturnValue.OK : SystemData.ReturnValue.FAILED; //} /// <summary> /// 保存当前正在编辑的模板文件 /// </summary> /// <returns>bool</returns> internal bool SaveTemplet() { DesignEditForm designForm = this.ActiveTemplet; ScriptEditForm scriptForm = this.ActiveScript; if (scriptForm == null && designForm == null) { return(false); } if (designForm != null) { scriptForm = this.GetScriptForm(designForm); } else if (scriptForm != null) { designForm = this.GetDesignForm(scriptForm); } FormFileParser parser = new FormFileParser(); string szScriptData = null; if (scriptForm != null) { szScriptData = scriptForm.Save(); } else { szScriptData = parser.GetScriptData(designForm.HndfFile); } string szDesignData = null; if (designForm != null) { designForm.Save(ref szDesignData); } else { szDesignData = parser.GetDesignData(scriptForm.HndfFile); } byte[] byteTempletData = null; parser.MakeFormData(szDesignData, szScriptData, out byteTempletData); DialogResult result = MessageBoxEx.ShowQuestion("是否提交到服务器?" + "\r\n提交到服务器,请点击“是”按钮!\r\n仅保存到本地,请点击“否”按钮!"); if (result == DialogResult.Cancel) { return(false); } bool success = true; if (result == DialogResult.No) { success = this.SaveTempletToLocal(byteTempletData); } else { success = this.SaveTempletToServer(byteTempletData); } if (success) { if (designForm != null) { designForm.IsModified = false; } if (scriptForm != null) { scriptForm.IsModified = false; } } return(success); }
internal void ShowScriptTestForm() { DesignEditForm designForm = this.ActiveTemplet; ScriptEditForm scriptForm = this.ActiveScript; if (scriptForm == null && designForm == null) { return; } if (designForm != null) { scriptForm = this.GetScriptForm(designForm); } else if (scriptForm != null) { designForm = this.GetDesignForm(scriptForm); } FormFileParser parser = new FormFileParser(); string szScriptData = null; if (scriptForm != null) { szScriptData = scriptForm.Save(); } else { szScriptData = parser.GetScriptData(designForm.HndfFile); } string szDesignData = null; if (designForm != null) { designForm.Save(ref szDesignData); } else { szDesignData = parser.GetDesignData(scriptForm.HndfFile); } //编译脚本 ScriptProperty scriptProperty = new ScriptProperty(); scriptProperty.ScriptText = szScriptData; CompileResults results = null; results = ScriptCompiler.Instance.CompileScript(scriptProperty); if (!results.HasErrors) { this.MainForm.ShowCompileErrorForm(null); } else { if (scriptForm == null) { this.OpenScriptEditForm(designForm); } this.MainForm.ShowCompileErrorForm(this.GetCompileErrors(results)); MessageBoxEx.Show("编译失败,无法启动测试程序!"); return; } ScriptTestForm scriptTestForm = new ScriptTestForm(); scriptTestForm.ScriptData = szScriptData; scriptTestForm.DesignData = szDesignData; scriptTestForm.ShowDialog(); }
/// <summary> /// 在所有模版中查找指定的文本 /// </summary> /// <param name="szFindText">文本</param> /// <param name="bMatchCase">是否匹配大小写</param> public void FindTextInAllTemplet(string szFindText, bool bMatchCase) { if (!bMatchCase) { szFindText = szFindText.ToLower(); } List <TempletType> lstDocTypeData = new List <TempletType>(); TempletTypeAccess.Instance.GetTempletTypes(null, ref lstDocTypeData); if (lstDocTypeData.Count <= 0) { return; } List <FindResult> Result = new List <FindResult>(); int indextext = 0; //索引号 int indexLine = 0; //行号 int i = 0; //正在比对的字符序号 int indexCol = 0; char chFindText = new char(); string sztextFormat = string.Empty; char[] arrFindText = szFindText.Trim().ToCharArray(); FormFileParser parser = new FormFileParser(); for (int index = 0; index < lstDocTypeData.Count; index++) { if (lstDocTypeData[index].IsFolder) { continue; } byte[] byteTempletData = null; short shRet = TempletTypeAccess.Instance.GetTempletData(lstDocTypeData[index].DocTypeID, ref byteTempletData); if (byteTempletData == null) { continue; } parser = new FormFileParser(); string szScripData = parser.GetScriptData(byteTempletData); string[] arrScripText = szScripData.Split(new Char[] { '\n' }, StringSplitOptions.None); indexLine = 0; //行号清零 indextext = 0; //索引号清零 foreach (string sztext in arrScripText) { if (string.IsNullOrEmpty(sztext)) { continue; } if (!bMatchCase) { sztextFormat = sztext.ToLower(); } else { sztextFormat = sztext; } char[] arrCtext = sztextFormat.ToCharArray(); i = 0;//正在比对的字符序号 for (indexCol = 0; indexCol < arrCtext.Length; indexCol++) { chFindText = arrCtext[indexCol]; indextext++; if (i != 0 && chFindText != arrFindText[i]) { indexCol -= i - 1; indextext -= i - 1; i = 0; continue; } if (chFindText != arrFindText[i]) { i = 0; continue; } if (i == arrFindText.Length - 1) { Result.Add(new FindResult(indextext - szFindText.Trim().Length , szFindText.Trim().Length , indexLine , sztext , lstDocTypeData[index].DocTypeID , lstDocTypeData[index].DocTypeName , SystemData.FileType.TEMPLET)); i = 0; continue; } i++; } indextext++;//修正分行去掉'\n'产生的偏移量 indexLine++; } } if (this.MainForm != null && !this.MainForm.IsDisposed) { this.MainForm.ShowFindResultForm(this, szFindText, Result, true); } }