📄 fmain.cs
字号:
if (objTag == null)
continue;
//末级菜单增加处理事件
MenuTag menuTag = (MenuTag)objTag;
string temp = dr["CdId"].ToString();
menuItem.Click += delegate(Object sender, System.EventArgs e)
{ OpenFunc(menuTag.assembly, menuTag.typeName, menuTag.showModal, menuTag.param, temp); };
}
}
}
#region GetAppMenuData
private QDataStore GetAppMenuData(DbProxyClient proxy)
{
QDataStore dsAppMenu = new QDataStore();
dsAppMenu.LibraryList = PBL.GyPbl;
dsAppMenu.DataWindowObject = GyDataObjects.D_Gy_JsCd;
//取用户角色
string[] roles = this.GetUserRole(proxy);
//取应用菜单数据
proxy.Clear();
proxy.AddRetrieveParam("p_yyid", App.yyId);
proxy.AddRetrieveParam("p_jsids", roles);
proxy.Retrieve(dsAppMenu);
return dsAppMenu;
}
#endregion
#region GetAppMenuModuleData
private QDataStore GetAppMenuModuleData(DbProxyClient proxy)
{
QDataStore dsAppMenuModule = new QDataStore();
dsAppMenuModule.LibraryList = PBL.GyPbl;
dsAppMenuModule.DataWindowObject = GyDataObjects.D_Gy_YyCdMk;
proxy.Clear();
proxy.AddRetrieveParam("p_appid", App.yyId);
proxy.Retrieve(dsAppMenuModule);
return dsAppMenuModule;
}
#endregion
#region GetUserRole
/// <summary>
///
/// </summary>
/// <param name="proxy"></param>
/// <returns></returns>
private string[] GetUserRole(DbProxyClient proxy)
{
ArrayList roleList = new ArrayList();
QDataStore dsUserRole = App.cache.RetrieveObject("DataStore/YhJs") as QDataStore;
try
{
if (dsUserRole == null)
{
dsUserRole = new User().GetUserRole(proxy, App.gh);
}
if (dsUserRole != null)
{
//停用的过滤掉
dsUserRole.SetFilter("TyBz = 0 ");
dsUserRole.Filter();
for (int rowIndex = 1; rowIndex < dsUserRole.RowCount+1; rowIndex++)
{
if (!dsUserRole.IsItemNull(rowIndex, "JsId"))
roleList.Add(dsUserRole.GetItemString(rowIndex, "JsId"));
}
}
return (string[])roleList.ToArray(typeof(string));
}
finally
{
if (roleList != null)
roleList.Clear();
}
}
#endregion
//设置菜单位置
private void SetMenuBtnLocation()
{
if (m_MenuBtn == null)
return;
if (m_MenuBtn.Length <= m_ShowMenuBtnCount)
m_MenuBtnStartIndex = 0;
int showIndex = 0;
for (int i = 0; i < m_MenuBtn.Length; i++)
{
if (i < m_MenuBtnStartIndex || i > m_MenuBtnStartIndex + m_ShowMenuBtnCount -1)
{
m_MenuBtn[i].Visible = false;
continue;
}
m_MenuBtn[i].Visible = true;
m_MenuBtn[i].Location = new Point(btnLeft.Location.X + btnLeft.Width + 1 + showIndex * m_MenuBtnWidth, 2);
showIndex++;
}
}
//左移
private void btnLeft_Click(object sender, EventArgs e)
{
if (m_MenuBtn.Length > m_ShowMenuBtnCount && m_MenuBtnStartIndex > 0)
{
m_MenuBtnStartIndex--;
SetMenuBtnLocation();
}
}
//右移
private void btnRight_Click(object sender, EventArgs e)
{
if (m_MenuBtn.Length > m_ShowMenuBtnCount && m_MenuBtn.Length > m_MenuBtnStartIndex + 1)
{
m_MenuBtnStartIndex++;
SetMenuBtnLocation();
}
}
#endregion
#region 打开功能点
private string GetCacheObjectId(string menuId)
{
return "/MainForm/MenuId" + menuId;
}
/// <summary>
/// 打开功能点
/// </summary>
/// <param name="assemblyName"></param>
/// <param name="typeName"></param>
/// <param name="showModal"></param>
/// <param name="param"></param>
/// <param name="menuId"></param>
private void OpenFunc(string assemblyName, string typeName, string showModal, string param,string menuId)
{
try
{
string objectId = GetCacheObjectId(menuId);
FBase form = App.cache.RetrieveObject(objectId) as FBase;
if (form != null && form.IsDisposed)
{
UNRegChildForm(menuId);
form = null;
}
if (form != null)
{
//传入参数...
form.Activate();
}
else
{
Assembly a = Assembly.LoadFrom(Application.StartupPath+"\\"+assemblyName);
form = (FBase)a.CreateInstance(typeName,false);
if (form == null)
{
throw new Exception("创建实例失败,请联系信息中心!");
}
//传参...?
if (showModal == "1")
{
form.ShowDialog(this);
}
else
{
form.MdiParent = this;
form.FormBorderStyle = FormBorderStyle.None;
form.MaximizeBox = false;
form.ControlBox = false;
//form.Location = new Point(0, 0);
form.Width = this.DisplayRectangle.Right - this.DisplayRectangle.Left - 5;
form.Height = this.DisplayRectangle.Height - (this.PanelTop.Size.Height + this.ToolStripForm.Size.Height + this.StatusStrip1.Height)-5;
form.MenuId = menuId;
App.cache.AddObject(objectId, form);
RegChildForm(menuId);
form.Show();
form.Location = new Point(0, 0);
}
}
}
catch(Exception ex)
{
AppError err = new AppError("打开功能点出错", "assemblyName:" + assemblyName + "typeName:" + typeName + "param:" + param, typeof(FMain), ex);
AppLog.Add(err);
MessageBox.Show("打开功能点出错:"+ex.Message,MsgTitle.Error);
}
}
#endregion
#region 根据菜单ID取菜单文字
private string GetMenuText(string menuId)
{
//应用菜单
QDataStore dsAppMenu = App.cache.RetrieveObject("DataStore/YyCd") as QDataStore;
if (dsAppMenu == null)
{
//重新检索?..
return "";
}
dsAppMenu.SetFilter("");
dsAppMenu.Filter();
string menuText = "";
int rowNum = dsAppMenu.FindRow("CdId='" + menuId + "'",1,dsAppMenu.RowCount);
if (rowNum > 0)
{
if (dsAppMenu.IsItemNull(rowNum,"CdWz"))
menuText = "";
else
menuText = dsAppMenu.GetItemString(rowNum, "CdWz");
}
return menuText;
}
#endregion
#region ToolStripForm
private ArrayList m_FormBtnList = new ArrayList();
public void UNRegChildForm(string menuId)
{
App.cache.RemoveObject(GetCacheObjectId(menuId));
RemoveItemByMenuId(menuId);
}
public void RegChildForm(string menuId)
{
FBase form = App.cache.RetrieveObject(GetCacheObjectId(menuId)) as FBase;
if (form == null || form.IsDisposed )
{
return;
}
string itemText = this.GetMenuText(menuId);
if (itemText == "")
itemText = form.Text;
ToolStripItem item = ToolStripForm.Items.Add(itemText);
item.ToolTipText = "";
item.Tag = menuId;
item.Click += delegate(object sender, EventArgs e) { ShowFormByMenuId(menuId); };
this.ToolStripForm.ShowItemToolTips = false;
}
private void ShowFormByMenuId(string menuId)
{
FBase form = App.cache.RetrieveObject(GetCacheObjectId(menuId)) as FBase;
if (form.IsDisposed || form == null)
{
RemoveItemByMenuId(menuId);
}
else
{
form.Activate();
}
}
private void RemoveItemByMenuId(string menuId)
{
foreach(ToolStripItem item in ToolStripForm.Items)
{
if (item.Tag.ToString() == menuId)
{
this.ToolStripForm.Items.Remove(item);
break;
}
}
}
#endregion
private void FMain_FormClosing(object sender, FormClosingEventArgs e)
{
//提交LOG
}
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void panelMenu_Paint(object sender, PaintEventArgs e)
{
}
private void btnMin_Click(object sender, EventArgs e)
{
this.PanelTop.Tag = "";
this.WindowState = FormWindowState.Minimized;
}
private void FMain_Paint(object sender, PaintEventArgs e)
{
if (this.PanelTop.Tag != null)
{
this.PanelTop.Refresh();
this.PanelTop.Tag = null;
}
}
private void btnHelp_Click(object sender, EventArgs e)
{
}
private void btnMessage_Click(object sender, EventArgs e)
{
}
}
public struct MenuTag
{
public string assembly;
public string typeName;
public string param;
public string showModal;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -