using DevExpress.XtraBars; using DevExpress.XtraBars.Ribbon; using DevExpress.XtraEditors; using DeviceRepair.Models; using DeviceRepair.Models.Common; using DeviceRepair.Models.Enum; using DeviceRepair.Utils; using System; using System.Linq; using System.Windows.Forms; using TsSFCDevice.Client.Biz; using TsSFCDevice.Client.Biz.Base.Utils; using TsSFCDevice.Client.Biz.Impl; using TsSFCDevice.Client.Launch.Plan; using TsSFCDevice.Client.Launch.sysConfig; namespace TsSFCDevice.Client.Launch { public partial class frm_Launch : RibbonForm { private BarButtonItem CurrentMenu; public frm_Launch() { InitializeComponent(); AuthLayOut(false); } private void frm_Launch_Load(object sender, EventArgs e) { Scheduler.Instance.CallBack += InvokeChangeFormText; Scheduler.Instance.Run(); this.FormClosing += (ss, ee) => { if (XtraMessageBoxHelper.AskYesNo("确认现在退出系统吗?") != DialogResult.Yes) { ee.Cancel = true; } //UserManager.Instance.LogOut(); }; //获取 tips 保养计划弹窗数据 try { // 检测是否首次登录及超过3个月未修改密码 //APIResponseData apiResponseData2 = UserManager.Instance.CheckChangePwdDate(GlobalInfo.CurrentUser.LoginCode); //if (apiResponseData2.IsSuccess && apiResponseData2.ToBool()) //{ //PassChange: // if (new frmPwdModify(false).ShowDialog(this) == DialogResult.OK) // { // XtraMessageBoxHelper.Info("操作成功!"); // } // else // { // goto PassChange; // } //} btn_VerNo.Caption = "V " + Application.ProductVersion; if (!Biz.Base.Utils.Utility.SystemRuntimeInfo.CurrentUser.UserName.IsNull()) { bSubLblUser.Caption = $"{Biz.Base.Utils.Utility.SystemRuntimeInfo.CurrentUser.UserName}"; } //if (string.IsNullOrWhiteSpace(GlobalInfo.CurrentUser.RealName) || string.IsNullOrWhiteSpace(GlobalInfo.CurrentUser.LoginCode)) // bSubLblUser.Visibility = BarItemVisibility.Never; //else // bSubLblUser.Caption = GlobalInfo.CurrentUser.LoginCode + "-" + GlobalInfo.CurrentUser.RealName; //using (page_PlanDialog pd = new page_PlanDialog()) //{ // if (GlobalInfo.HasRole(AuthCodeConstValue.BIZ_PRESERVE)) // { // if (pd.ShowDialog(this) == DialogResult.Cancel) // { // this.Close(); // return; // } // } // if (GlobalInfo.HasRole(AuthCodeConstValue.BIZ_PLAN)) // { // //进入主程序 // pnl_Content.ShowInPanel(); // CurrentMenu = btn_DrivePlan; // SetButtonDown(); // //SetPlansScheduleText(); // } //} } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message, "错误"); } } /// /// 委托更新显示值 /// /// /// protected void InvokeChangeFormText(string arg, object Value) { this.Invoke(new Action(() => { switch (arg) { case "SchedulerPlanTips": btn_PlanCount.Caption = Value + ""; break; default: break; } })); } #region 设备维修 /// /// 设备维修台账 - (新) /// /// /// private void bar_btn_EquipmentMaintenanceLst_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.Device_REPAIRRECORD)) { throw new Exception($"当前账号缺少此操作的权限"); } using (Maintain.pageMaintainView view = new Maintain.pageMaintainView()) { view.ShowDialog(this); } } catch (Exception ex) { splashScreenManager1.TryCloseWait(); XtraMessageBoxHelper.Error(ex.Message); } } #endregion /// /// 设备类型 /// /// /// private void btn_Maintenance_ItemClick(object sender, ItemClickEventArgs e) { } /// /// 报表 /// /// /// private void btn_Import_ItemClick(object sender, ItemClickEventArgs e) { } #region PM 的保养 /// /// 设备保养计划 /// /// /// private void btn_DrivePlan_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PM_PLAN)) { throw new Exception($"当前账号缺少此操作的权限"); } using (Plan.pageDevicePlanView view = new Plan.pageDevicePlanView()) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// PM的 点检表 /// /// /// private void btn_FormVersionMaintenence_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PM_CheckFORM)) { throw new Exception($"当前账号缺少此操作的权限"); } using (CheckForm.pageCheckFormView view = new CheckForm.pageCheckFormView()) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } #endregion /// /// 设备台账 /// /// /// private void btn_Report01_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PM_Device_KH) && !Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PM_Device_OEM) ) { throw new Exception($"当前账号缺少此操作的权限"); } using (Device.pageDeviceView view = new Device.pageDeviceView()) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e) { // pnl_Content.ShowInPanel(); } /// /// 设备保养记录 /// /// /// private void btn_MaintenanceLst_ItemClick(object sender, ItemClickEventArgs e) { } /// /// 密码修改 /// /// /// private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e) { } /// /// 用户管理 /// /// /// private void btn_UserManager_ItemClick(object sender, ItemClickEventArgs e) { } /// /// 角色管理 /// /// /// private void barButtonItem5_ItemClick(object sender, ItemClickEventArgs e) { } void SetButtonDown() { var DownControl = ribbonControl.Items.FirstOrDefault(x => x is BarBaseButtonItem && (x as BarBaseButtonItem).Down && x != CurrentMenu); if (DownControl != null) { (DownControl as BarBaseButtonItem).Down = false; } if (CurrentMenu != null) { CurrentMenu.ButtonStyle = BarButtonStyle.Check; CurrentMenu.Down = true; } } /// /// 显示计划提醒小窗 /// /// /// private void btn_PlanCount_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PM_CheckFORM_Add)) { throw new Exception($"当前账号缺少此操作的权限"); } splashScreenManager1.ShowWaitForm(); using (page_PlanDialog view = new page_PlanDialog()) { splashScreenManager1.TryCloseWait(); view.ShowDialog(this); } } catch (Exception ex) { splashScreenManager1.TryCloseWait(); XtraMessageBoxHelper.Error(ex.Message); } } private void barButtonItem6_ItemClick(object sender, ItemClickEventArgs e) { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PM_PRESERVE_Watch)) { throw new Exception($"当前账号缺少此操作的权限"); } using (pageRecordView view = new pageRecordView(EnumDeviceBelong.PM)) { view.ShowDialog(this); } } #region 自定义字段 /// /// 现象区分 /// /// /// private void bar_SymptomlDistinction_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.Custom_FIELD_SYMPTOMLDISTINCTION)) { throw new Exception($"当前账号缺少此操作的权限"); } using (CustomField.pageFieldCode view = new CustomField.pageFieldCode("SYMPTOMLDISTINCTION", "BIZ_EQUIP_FIELD_SYMPTOMLDISTINCTION", "现象区分")) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// 维修方式 /// /// /// private void bar_Maintenance_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.Custom_FIELD_MAINTENANCEN)) { throw new Exception($"当前账号缺少此操作的权限"); } using (CustomField.pageFieldCode view = new CustomField.pageFieldCode("MAINTENANCE", "BIZ_EQUIP_FIELD_MAINTENANCEN", "维修方式")) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// 配件维护 /// /// /// private void barButtonItem7_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.Custom_FIELD_ACCESSORIES)) { throw new Exception($"当前账号缺少此操作的权限"); } using (CustomField.pageFieldCode view = new CustomField.pageFieldCode("ACCESSORIES", "BIZ_EQUIP_FIELD_ACCESSORIES", "配件维护")) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// 故障发生地 /// /// /// private void barButtonItem8_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.Custom_FIELD_WHEREFAILUREOCCURRED)) { throw new Exception($"当前账号缺少此操作的权限"); } using (CustomField.pageFieldCode view = new CustomField.pageFieldCode("WHEREFAILUREOCCURRED", "BIZ_EQUIP_FIELD_WHEREFAILUREOCCURRED", "故障发生地")) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } #endregion /// /// 系统设置 /// /// /// private void btnSystemSetting_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.Sys_Config)) { throw new Exception($"当前账号缺少此操作的权限"); } using (pageSytemSetting view = new pageSytemSetting()) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// 用户登录登出日志 /// /// /// private void barButtonItem13_ItemClick(object sender, ItemClickEventArgs e) { } /// /// AM 的树形设备清单 /// /// /// private void Am_List_ItemClick(object sender, ItemClickEventArgs e) { } /// /// AM的保养计划 /// /// /// private void Am_Plans_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.AM_PLAN)) { throw new Exception($"当前账号缺少此操作的权限"); } using (Plan.AM.pageDeviceAMPlanView view = new Plan.AM.pageDeviceAMPlanView()) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// tag /// /// /// private void btnTagMgr_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.Device_TAG)) { throw new Exception($"当前账号缺少此操作的权限"); } using (Tag.TagFormView view = new Tag.TagFormView()) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// AM 的点检表维护 /// /// /// private void Am_Form_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.AM_CheckFORM)) { throw new Exception($"当前账号缺少此操作的权限"); } using (CheckForm.pageCheckFormView view = new CheckForm.pageCheckFormView(EnumDeviceBelong.AM)) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// AM的保养记录 /// /// /// private void Am_Record_ItemClick(object sender, ItemClickEventArgs e) { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.AM_PRESERVE_Watch)) { throw new Exception($"当前账号缺少此操作的权限"); } using (pageRecordView view = new pageRecordView(EnumDeviceBelong.AM)) { view.ShowDialog(this); } } #region 方法 void AuthLayOut(bool beRefreshAuths) { if (beRefreshAuths) { #region 重新加载用户权限角色集合 Myl20210531 //UserRepository vUserRepos = new UserRepository(false); //Utility.SystemRuntimeInfo.CurrentUser.Roles = vUserRepos.UserRolesGet(Utility.SystemRuntimeInfo.CurrentUser.GUID.Value.ToString()); //Utility.SystemRuntimeInfo.CurrentUser.Auths = vUserRepos.UserAuthsGet(Utility.SystemRuntimeInfo.CurrentUser.UserCode); //if (Utility.SystemRuntimeInfo.CurrentUser.Roles == null || Utility.SystemRuntimeInfo.CurrentUser.Auths == null) //{ // XtraMessageBoxHelper.Warn("用户重新分配了角色或权限,重现分配后,角色或者权限为空!"); // ribbon.Enabled = false; //} #endregion } ribbonControl.Pages.ForEach(x => { PageControlAuthLayOut(x); }); } void PageControlAuthLayOut(RibbonPage vRPage) { vRPage.Groups.ForEach(A => { PageGroupAuthLayOut(A); }); var vVisibleGroup = vRPage.Groups.FirstOrDefault(A => { return A.Visible == true; }); if (vVisibleGroup == null) { vRPage.Visible = false; } else { vRPage.Visible = true; } } void PageGroupAuthLayOut(RibbonPageGroup vRPageGroup) { bool bShow = false; if (vRPageGroup.ItemLinks.Count > 0) { foreach (var item in vRPageGroup.ItemLinks) { if (item is BarButtonItemLink) { #region BarButtonItemLink var vBar = (BarButtonItemLink)item; if (vBar.Item != null) { if (vBar.Item.Tag != null) { if (Utility.SystemRuntimeInfo.AuthValidate(vBar.Item.Tag.ToString())) { if (vBar.Item.ButtonStyle != BarButtonStyle.DropDown) { vBar.Item.Visibility = BarItemVisibility.Always; } else { PopMenuBarButtonItemAuthLayOut(vBar.Item); } } else { if (vBar.Item.ButtonStyle != BarButtonStyle.DropDown) { vBar.Item.Visibility = BarItemVisibility.Never; } else { PopMenuBarButtonItemAuthLayOut(vBar.Item); } } } else { vBar.Item.Visibility = BarItemVisibility.Always; } } else { vBar.Item.Visibility = BarItemVisibility.Always; } if (vBar.Item.Visibility == BarItemVisibility.Always) { bShow = true; } #endregion } else if (item is BarSubItemLink) { var vBar = (BarSubItemLink)item; BarItemVisibility vBarVisibility = BarItemVisibility.Never; foreach (BarButtonItemLink iBar in vBar.VisibleLinks) { if (Utility.SystemRuntimeInfo.AuthValidate(iBar.Item.Tag.ToString())) { vBar.Item.Visibility = BarItemVisibility.Always; vBarVisibility = BarItemVisibility.Always; } else { vBar.Item.Visibility = BarItemVisibility.Never; } } vBar.Visible = vBarVisibility == BarItemVisibility.Always; } var vVisibleGroup = vRPageGroup.ItemLinks.FirstOrDefault( A => { if (A is BarButtonItemLink) { return ((BarButtonItemLink)A).Item.Visibility == BarItemVisibility.Always; } else if (A is BarSubItemLink) { return ((BarSubItemLink)A).Item.Visibility == BarItemVisibility.Always; } else { return true; } } ); if (vVisibleGroup == null) { vRPageGroup.Visible = false; } else { vRPageGroup.Visible = true; } } } else { vRPageGroup.Visible = true; } } void PopMenuBarButtonSubItemAuthLayOut(BarSubItem barItem, ref bool bShow) { if ((barItem.ItemLinks?.Count() ?? 0) == 0) { barItem.Visibility = BarItemVisibility.Always; } else { foreach (var item in barItem.ItemLinks) { if (item is BarButtonItemLink) { #region BarButtonItemLink var vPopBarItem = item as BarButtonItemLink; if (vPopBarItem.Item != null) { if (vPopBarItem.Item.Tag != null) { if (Utility.SystemRuntimeInfo.AuthValidate(vPopBarItem.Item.Tag.ToString())) { bShow = true; vPopBarItem.Item.Visibility = BarItemVisibility.Always; } else { if (Utility.SystemRuntimeInfo.AuthStartWithValidate(vPopBarItem.Item.Tag.ToString())) { bShow = true; vPopBarItem.Item.Visibility = BarItemVisibility.Always; } else { vPopBarItem.Item.Visibility = BarItemVisibility.Never; } } } else { bShow = true; vPopBarItem.Item.Visibility = BarItemVisibility.Always; } } #endregion } else if (item is BarSubItemLink) { var vPopSubBarItem = item as BarSubItemLink; if (vPopSubBarItem != null) { var vSubBarItem = vPopSubBarItem.Item as BarSubItem; var vShowFlag = false; PopMenuBarButtonSubItemAuthLayOut(vSubBarItem, ref vShowFlag); if (vShowFlag) { bShow = true; } } } } if (bShow) { barItem.Visibility = BarItemVisibility.Always; } else { barItem.Visibility = BarItemVisibility.Never; } } } void PopMenuBarButtonItemAuthLayOut(BarButtonItem barItem) { bool bShow = false; var pm = barItem.DropDownControl as PopupMenu; if (pm == null) { barItem.Visibility = BarItemVisibility.Always; } else { foreach (var item in pm.ItemLinks) { if (item is BarButtonItemLink) { #region BarButtonItemLink var vPopBarItem = item as BarButtonItemLink; if (vPopBarItem.Item != null) { if (vPopBarItem.Item.Tag != null) { if (Utility.SystemRuntimeInfo.AuthValidate(vPopBarItem.Item.Tag.ToString())) { bShow = true; vPopBarItem.Item.Visibility = BarItemVisibility.Always; } else { if (Utility.SystemRuntimeInfo.AuthStartWithValidate(vPopBarItem.Item.Tag.ToString())) { bShow = true; vPopBarItem.Item.Visibility = BarItemVisibility.Always; } else { vPopBarItem.Item.Visibility = BarItemVisibility.Never; } } } else { bShow = true; vPopBarItem.Item.Visibility = BarItemVisibility.Always; } } #endregion } else if (item is BarSubItemLink) { var vPopSubBarItem = item as BarSubItemLink; if (vPopSubBarItem != null) { var vSubBarItem = vPopSubBarItem.Item as BarSubItem; var vShowFlag = false; PopMenuBarButtonSubItemAuthLayOut(vSubBarItem, ref vShowFlag); if (vShowFlag) { bShow = true; } } } } if (bShow) { barItem.Visibility = BarItemVisibility.Always; } else { barItem.Visibility = BarItemVisibility.Never; } } } #endregion /// /// 生产报修单 /// /// /// private void barButtonItem7_ItemClick_1(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.Device_REPAIRRECORD_Watch)) { throw new Exception($"当前账号缺少此操作的权限"); } using (Maintain.pageDeviceMaintenanceFormView view = new Maintain.pageDeviceMaintenanceFormView()) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// 清理缓存 /// /// /// private void batBtnRefresh_ItemClick(object sender, ItemClickEventArgs e) { Utility.SystemRuntimeInfo.CurrentUsersCaches = null; Utility.SystemRuntimeInfo.CurrentDeviceCaches = null; Utility.SystemRuntimeInfo.CurrentDevRootCaches = null; } /// /// 树形视图 /// /// /// private void btn_treeView_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PM_Device_KH) && !Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PM_Device_OEM) ) { throw new Exception($"当前账号缺少此操作的权限"); } using (Device.pageDeviceTreeView view = new Device.pageDeviceTreeView()) { view.ShowDialog(this); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } /// /// 跳过当前日期生成设备校验计划 /// /// /// private void btnPlanCheckJump_ItemClick(object sender, ItemClickEventArgs e) { try { if (!Utility.SystemRuntimeInfo.AuthValidate(OperationAuthConstValue.PLAN_JUMP_CHECK)) { throw new Exception($"当前账号缺少此操作的权限"); } } catch (Exception ex) { XtraMessageBoxHelper.Error(ex.Message); } } } }