private void BeforePropertyChangedEvent(CustomProperty sender, PropertyChangeEventArgs e) { if (sender is CustomProperty) { DBCustomProperty prop = (DBCustomProperty)sender; bool bRet = false; string sErrMsg = "未定义的错误"; try { if (m_lua != null) { DoScript(prop);//可能会有重名的字段,因不同表字段现在可以在同一TAB页中,需要加上parentfield. LuaFunction fun = m_lua.GetFunction(GetRealFunctionName(prop.Key, "onbeforevaluechang"));//"__fname__" + prop.Key + ".onbeforevaluechang"); if (fun != null) { object[] retobjs = fun.Call(prop, e); if (retobjs != null && retobjs.GetLength(0) > 0) { if (retobjs[0] is bool) { bRet = (bool)retobjs[0]; if (!bRet) sErrMsg = (string)retobjs[1]; } } } else bRet = true; //无函数表示没有脚本指定 } } catch (Exception ex) { //ScriptDebugForm frm = Program.MainForm.DebugForm; //frm.OutputBox.Text += ex.Message + "\r\n"; //frm.Show(); //frm.BringToFront(); Helper.AddLog(ex.Message); sErrMsg = "LUA运行时错误:\r\n" + ex.Message; } if (!bRet) { sErrMsg = sErrMsg.Replace("\\n", "\n"); sErrMsg = sErrMsg.Replace("\\t", "\t"); throw new Exception(sErrMsg); } else { //尝试先锁定再提交修改 object[] findkeys = FindKeys == null ? (object[])prop.Tag : FindKeys; // 加入限制:只能在<默认值>结点中修改挂接的子表的默认行的内容 bool bModifyingSubTableDefaults = true; foreach (object _key in findkeys) { if (_key.ToString() != "0") { bModifyingSubTableDefaults = false; break; } } if (bModifyingSubTableDefaults) { if (!Program.MainForm.m_CurBaseForm.BaseTree.SelectedNode.Text.Contains("默认值")) throw new Exception("不能在这里直接修改子表默认值,请先选择<默认值>结点,再进行修改。"); else { if (!CanModifyDefaultVal()) throw new Exception("不允许修改默认值。"); } } if (!OnLockRecord(true, prop, findkeys)) { throw new Exception(string.Format("这条记录已经被[{0}]在模块[{1}]中锁定,请等待解锁后,再进行修改操作。", m_reclock.GetServerLastLockUser(findkeys), m_reclock.GetServerLastLockModID(findkeys))); } } } }
private void BeforePropertyChanged(CustomProperty sender, PropertyChangeEventArgs e) { if (sender is CustomProperty) { CustomProperty prop = (CustomProperty)sender; bool bRet = false; string sErrMsg = "未定义的错误"; try { if (m_lua != null) { DoScript(prop.ID);//可能会有重名的字段,因不同表字段现在可以在同一TAB页中,需要加上parentfield. LuaFunction fun = m_lua.GetFunction("__fname__" + prop.ID + ".onbeforevaluechang"); if (fun != null) { object[] retobjs = fun.Call(prop, e); if (retobjs.GetLength(0) > 0) { if (retobjs[0] is bool) { bRet = (bool)retobjs[0]; if (!bRet) sErrMsg = (string)retobjs[1]; } } } else bRet = true; //无函数表示没有脚本指定 } } catch (Exception ex) { ScriptDebugForm frm = ((MainForm)ParentForm).DebugForm; frm.OutputBox.Text += ex.Message + "\r\n"; frm.Show(); frm.BringToFront(); } if (!bRet) { throw new Exception(sErrMsg); } } }