public void ToolStripItemCollection_Find_InvokeKeyExists_ReturnsExpected(string key) { using ToolStripMenuItem toolStrip = new ToolStripMenuItem(); var child1 = new ToolStripMenuItem { Name = "name1" }; var child2 = new ToolStripMenuItem { Name = "name2" }; var child3 = new ToolStripMenuItem { Name = "name2" }; var grandchild1 = new ToolStripMenuItem { Name = "name1" }; var grandchild2 = new ToolStripMenuItem { Name = "name2" }; var grandchild3 = new ToolStripMenuItem { Name = "name2" }; child3.DropDownItems.Add(grandchild1); child3.DropDownItems.Add(grandchild2); child3.DropDownItems.Add(grandchild3); ToolStripItemCollection collection = toolStrip.DropDownItems; collection.Add(child1); collection.Add(child2); collection.Add(child3); // Search all children. Assert.Equal(new ToolStripMenuItem[] { child2, child3, grandchild2, grandchild3 }, collection.Find(key, searchAllChildren: true)); // Call again. Assert.Equal(new ToolStripMenuItem[] { child2, child3, grandchild2, grandchild3 }, collection.Find(key, searchAllChildren: true)); // Don't search all children. Assert.Equal(new ToolStripMenuItem[] { child2, child3 }, collection.Find(key, searchAllChildren: false)); // Call again. Assert.Equal(new ToolStripMenuItem[] { child2, child3 }, collection.Find(key, searchAllChildren: false)); }
private void SearchAndCreate(IList <string> path, ToolStripItemCollection items) { string first = path.ElementAt(0); ToolStripMenuItem item; ToolStripItem[] subItems; if ((subItems = items.Find(first, false)).Length == 0) { item = new ToolStripMenuItem(); item.Name = item.Text = first; //non bellissimo, ma semplificativo items.Add(item); } else { item = subItems[0] as ToolStripMenuItem; if (item == null) { Console.WriteLine("Problema di conversione menuItem"); } } path.RemoveAt(0); if (path.Count > 0) { SearchAndCreate(path, item.DropDownItems); } }
static ToolStripItem Find(ToolStripItemCollection items, String key, Boolean searchAllChildren) { var tis = items.Find(key, searchAllChildren); if (tis != null && tis.Length > 0) { return(tis[0]); } foreach (ToolStripItem item in items) { if (item.Text.EqualIgnoreCase(key)) { return(item); } } if (searchAllChildren) { foreach (ToolStripItem item in items) { var tdi = item as ToolStripDropDownItem; if (tdi != null) { var ti = Find(tdi.DropDownItems, key, searchAllChildren); if (ti != null) { return(ti); } } } } return(null); }
public static ToolStripItem[] FindToolStripMenuItems(ToolStripItemCollection tsic, string key, bool searchAllChildren) { if (tsic == null) { return new ToolStripItem[] { } } ; ToolStripItem[] tsi = tsic.Find(key, searchAllChildren); if (!MonoWorkaroundRequired || !searchAllChildren) { return(tsi); } //Mono does not support 'searchAllChildren' for ToolStripItemCollection //Iterate over all items and search for given item List <ToolStripItem> lItems = new List <ToolStripItem>(tsi); foreach (var item in tsic) { ToolStripMenuItem tsmi = item as ToolStripMenuItem; if (tsmi == null) { continue; } lItems.AddRange(FindToolStripMenuItems(tsmi.DropDownItems, key, searchAllChildren)); } return(lItems.ToArray()); }
/// <summary> /// If <paramref name="header"/> does not exist, it gets created. /// Returns the ToolStripMenuItem object with the name <paramref name="header"/> /// </summary> /// <param name="parent"></param> /// <param name="header"></param> /// <returns></returns> ToolStripMenuItem GetOrAddDropDownMenu(MenuStrip parent, string header) { ToolStripItemCollection items = parent.Items; if (!items.ContainsKey(header)) { ToolStripMenuItem ts_menu_item = new ToolStripMenuItem(header); ts_menu_item.Name = header; items.Add(ts_menu_item); } return((ToolStripMenuItem)items.Find(header, false)[0]); }
private void cms_Dicts_Opening(object sender, CancelEventArgs e) { ToolStripItemCollection ti = null; ti = btn_Dicts_Groups.DropDown.Items; if (ti.Find("tss", true).Count() > 0) { ti.Remove(ti.Find("tss", true)[0]); } if (ti.Find("Manage_Groups", true).Count() > 0) { ti.Remove(ti.Find("Manage_Groups", true)[0]); } foreach (string s in Properties.Settings.Default.s_Groups) { ToolStripItem t = new ToolStripMenuItem(); t.Text = s.Substring(0, s.IndexOf(";")); t.Name = t.Text; if (ti == null || ti.Find(t.Text, true).Count() == 0) { btn_Dicts_Groups.DropDown.Items.Add(t); t.Click += T_Click; } } if (ti != null && ti.Count > 0) { ToolStripSeparator tss = new ToolStripSeparator(); tss.Name = "tss"; ToolStripItem tbtn = new ToolStripMenuItem(); tbtn.Text = "Manage Groups"; tbtn.Name = "Manage_Groups"; btn_Dicts_Groups.DropDown.Items.AddRange(new ToolStripItem[] { tss, tbtn }); tbtn.Click += Tbtn_Click; } }
private void frmMain_Load(object sender, EventArgs e) { ToolStripItemCollection tmnu = menuStrip1.Items; SetToolStripItems(tmnu); mnuAdmin.Enabled = true; mnuMast.Enabled = true; mnuTranS.Enabled = true; mnuChangePass.Enabled = true; mnuLogOff.Enabled = true; DataSet ds = new DataSet(); string sql = "select menuname from Cont_MastFrm where formid in (select FormId from Cont_UserRights where UserId ='" + Utils.User.GUserID + "' and View1=1) order by seqid"; ds = Utils.Helper.GetData(sql, cnstr); mnuUser.Enabled = true; Boolean hasRows = ds.Tables.Cast <DataTable>() .Any(table => table.Rows.Count != 0); if (hasRows) { foreach (DataRow dr in ds.Tables[0].Rows) { string mnu = dr["menuname"].ToString(); ToolStripItem[] t = tmnu.Find(mnu, true); foreach (ToolStripItem ti in t) { ti.Enabled = true; } } } this.mnuHelp.Enabled = true; this.mnuAbout.Enabled = true; //get localmodification date string codeBase = Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string localfile = Uri.UnescapeDataString(uri.Path); if (IsNetworkPath(localfile)) { MessageBox.Show("Does not allow to run from remote location/shared folder..," + Environment.NewLine + "Please Copy to Local Drive and Run Again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } bool tchk = Globals.GetGlobalVars(); //check for update version. DateTime servermodified = new DateTime(); DateTime localmodified = new DateTime(); if (!string.IsNullOrEmpty(Globals.G_UpdateChkPath)) { this.Cursor = Cursors.WaitCursor; Application.DoEvents(); using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials()) { if (unc.NetUseWithCredentials(Globals.G_UpdateChkPath, Globals.G_NetworkUser, Globals.G_NetworkDomain, Globals.G_NetworkPass)) { string fullpath = Path.Combine(Globals.G_UpdateChkPath, "ContractPayroll.exe"); if (File.Exists(fullpath)) { servermodified = File.GetLastWriteTime(fullpath); } } } localmodified = File.GetLastWriteTime(localfile); if (servermodified > localmodified) { MessageBox.Show("New Upgrade is available, please update from" + Globals.G_UpdateChkPath + " ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } this.Cursor = Cursors.Default; } }
public void CreateCopy(ToolStripItemCollection tsicTarget, ToolStripItem tsiPosRef, bool bAfter, ToolStripMenuItem tsmiBase) { if (tsicTarget == null) { Debug.Assert(false); return; } if (tsmiBase == null) { Debug.Assert(false); return; } ToolStripMenuItem tsmi = new ToolStripMenuItem(); string strName = tsmiBase.Name, strNameNew = null; if (!string.IsNullOrEmpty(strName)) { if (strName.StartsWith("m_menu", StrUtil.CaseIgnoreCmp)) { strNameNew = "m_ctx" + strName.Substring(6); } } if (!string.IsNullOrEmpty(strNameNew)) { ToolStripItem[] v = tsicTarget.Find(strNameNew, true); if ((v == null) || (v.Length == 0)) { tsmi.Name = strNameNew; } else { Debug.Assert(false); } } else { Debug.Assert(false); } CreateLink(tsmi, tsmiBase, (tsmiBase.DropDownItems.Count == 0)); int i, n = tsicTarget.Count; if (tsiPosRef == null) { i = (bAfter ? n : 0); } else { i = tsicTarget.IndexOf(tsiPosRef); if (i < 0) { Debug.Assert(false); i = n; } else if (bAfter) { ++i; } } tsicTarget.Insert(i, tsmi); foreach (ToolStripItem tsiSub in tsmiBase.DropDownItems) { ToolStripMenuItem tsmiSub = (tsiSub as ToolStripMenuItem); if (tsmiSub != null) { CreateCopy(tsmi.DropDownItems, null, true, tsmiSub); } else if (tsiSub is ToolStripSeparator) { tsmi.DropDownItems.Add(new ToolStripSeparator()); } else { Debug.Assert(false); } } }
private void frmMain_Load(object sender, EventArgs e) { ToolStripItemCollection tmnu = menuStrip1.Items; SetToolStripItems(tmnu); mnuAdmin.Enabled = true; mnuConfig.Enabled = true; mnuMast.Enabled = true; mnuProfile.Enabled = true; mnuEmployee.Enabled = true; mnuMess.Enabled = true; mnuTranS.Enabled = true; mnuLeave.Enabled = true; mnuShift.Enabled = true; mnuSanction.Enabled = true; mnuData.Enabled = true; mnuCostCent.Enabled = true; mnuChangePass.Enabled = true; mnuLogOff.Enabled = true; DataSet ds = new DataSet(); string sql = "select menuname from MastFrm where formid in (select FormId from userRights where UserId ='" + Utils.User.GUserID + "' and View1=1) order by seqid"; ds = Utils.Helper.GetData(sql, cnstr); mnuUser.Enabled = true; Boolean hasRows = ds.Tables.Cast <DataTable>() .Any(table => table.Rows.Count != 0); if (hasRows) { foreach (DataRow dr in ds.Tables[0].Rows) { string mnu = dr["menuname"].ToString(); ToolStripItem[] t = tmnu.Find(mnu, true); foreach (ToolStripItem ti in t) { ti.Enabled = true; } } } this.mnuHelp.Enabled = true; this.mnuAbout.Enabled = true; this.mnuStatus.Enabled = true; this.mnuServerStat.Enabled = true; //Set GateInOutIP Globals.SetGateInOutIPList(); //set LunchInOutIP Globals.SetLunchInOutIPList(); //set waterip Globals.SetWaterIPList(); //set ShiftList Globals.SetShiftList(); //set global vars Globals.GetGlobalVars(); //get localmodification date string codeBase = Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string localfile = Uri.UnescapeDataString(uri.Path); if (IsNetworkPath(localfile)) { MessageBox.Show("Does not allow to run from remote location/shared folder..," + Environment.NewLine + "Please Copy to Local Drive and Run Again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } //here we can start Quartz if host is server if (Utils.User.GUserID == "SERVER") { Globals.G_myscheduler = new Scheduler(); mnuRFIDUser.Enabled = true; mnuDataDownload.Enabled = true; mnuDataProcess.Enabled = true; mnuAutoMailSender.Enabled = true; Form t = Application.OpenForms["frmServerStatus"]; if (t == null) { Attendance.Forms.frmServerStatus m = new Attendance.Forms.frmServerStatus(); m.MdiParent = this; m.WindowState = FormWindowState.Maximized; m.Show(); } Thread.Sleep(TimeSpan.FromSeconds(5)); Globals.G_myscheduler.Start(); //create triggers Globals.G_myscheduler.RegSchedule_AutoTimeSet(); Globals.G_myscheduler.RegSchedule_WorkerProcess(); Globals.G_myscheduler.RegSchedule_AutoArrival(); Globals.G_myscheduler.RegSchedule_AutoProcess(); Globals.G_myscheduler.RegSchedule_DownloadPunch(); Globals.G_myscheduler.RegSchedule_AutoMail(); } else { //check for update version. DateTime servermodified = new DateTime(); DateTime localmodified = new DateTime(); if (!string.IsNullOrEmpty(Globals.G_UpdateChkPath)) { this.Cursor = Cursors.WaitCursor; Application.DoEvents(); using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials()) { if (unc.NetUseWithCredentials(Globals.G_UpdateChkPath, Globals.G_NetworkUser, Globals.G_NetworkDomain, Globals.G_NetworkPass)) { string fullpath = Path.Combine(Globals.G_UpdateChkPath, "AttendanceOKH.exe"); if (File.Exists(fullpath)) { servermodified = File.GetLastWriteTime(fullpath); } } } localmodified = File.GetLastWriteTime(localfile); if (servermodified > localmodified) { MessageBox.Show("New Upgrade is available, please update", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } this.Cursor = Cursors.Default; } } }
public static ToolStripMenuItem BuildDropDownMenuEx(ToolStripItemCollection items, string parentName, string name, Type enumType, EventHandler clickEvent, object tag = null, int min = 0, int max = 0, bool noSubItems = false) { var subMenuName = $"{parentName}_{name}"; var subMenuItems = items.Find(subMenuName, false); if (subMenuItems.Length > 0) { return(subMenuItems[0] as ToolStripMenuItem); } ToolStripMenuItem subMenuItem; subMenuItem = (ToolStripMenuItem)items.Add(name); subMenuItem.Name = subMenuName; if (noSubItems) { subMenuItem.Tag = tag; subMenuItem.Click += clickEvent; return(subMenuItem); } if (enumType != null) { foreach (var enumValue in Enum.GetValues(enumType)) { var itemText = (enumValue as IConvertible).GetDescription() ?? enumValue.ToString(); var item = subMenuItem.DropDownItems.Add(itemText); item.Tag = tag; var strValue = enumValue.ToString(); if (strValue.EndsWith("_")) { strValue = strValue.Substring(0, strValue.Length - 1); } item.AccessibleName = strValue; item.Click += clickEvent; } } else if (max > min) { List <int> range; if (max - min <= 20) { range = Enumerable.Range(min, (max - min) + 1).ToList(); } else { range = new List <int>(); for (var i = 0; i <= 10; i++) { range.Add(i * (max / 10)); } } foreach (var value in range) { var subSubItemName = $"{subMenuName}_{value}"; var item = subMenuItem.DropDownItems.Add(value.ToString()); item.Name = subSubItemName; item.Tag = tag; item.Click += clickEvent; } } else { subMenuItem.Tag = tag; subMenuItem.Click += clickEvent; } return(subMenuItem); }
public void habilitar_func_x_rol() { if (DatosSesion.esGuest()) { menuStrip1.Visible = false; panelSession.Visible = false; inicioSesionLink.Visible = true; inicioSesionLink.Enabled = true; closeSessionLink.Visible = false; passLinkLabel.Visible = false; } else { closeSessionLink.Enabled = true; passLinkLabel.Enabled = true; inicioSesionLink.Visible = false; } panelReservas.Enabled = true; menuStrip1.Enabled = true; List <Funcionalidad> f = DatosSesion.funcionalidades; newReservaButton.Enabled = f.Any(func => func.descripcion_funcionalidad == "Generar Reserva"); updateReservaButton.Enabled = f.Any(func => func.descripcion_funcionalidad == "Generar Reserva"); cancelReservaButton.Enabled = f.Any(func => func.descripcion_funcionalidad == "Cancelar Reserva"); ToolStripItemCollection itemsMenu = menuStrip1.Items; ToolStripItem menu_usuario = itemsMenu.Find("usuariosToolStripMenuItem", true)[0]; menu_usuario.Enabled = f.Any(func => func.descripcion_funcionalidad == "ABM Usuario"); ToolStripItem menu_Hotel = itemsMenu.Find("aBMHotelToolStripMenuItem", true)[0]; menu_Hotel.Enabled = f.Any(func => func.descripcion_funcionalidad == "ABM Hotel"); ToolStripItem menu_Habitacion = itemsMenu.Find("aBMHabitacionToolStripMenuItem", true)[0]; menu_Habitacion.Enabled = f.Any(func => func.descripcion_funcionalidad == "ABM Habitacion"); ToolStripItem menu_cliente = itemsMenu.Find("clientesToolStripMenuItem", true)[0]; menu_cliente.Enabled = f.Any(func => func.descripcion_funcionalidad == "ABM Clientes"); ToolStripItem menu_rol = itemsMenu.Find("rolToolStripMenuItem", true)[0]; menu_rol.Enabled = f.Any(func => func.descripcion_funcionalidad == "ABM Rol"); ToolStripItem menu_estadias = itemsMenu.Find("estadíasToolStripMenuItem", true)[0]; menu_rol.Enabled = f.Any(func => func.descripcion_funcionalidad == "Registrar Estadia"); ToolStripItem menu_estadisticas = itemsMenu.Find("listaEstadisticasToolStripMenuItem", true)[0]; menu_estadisticas.Enabled = f.Any(func => func.descripcion_funcionalidad == "Listado Estadistico"); }