/// <summary> /// 设置字段的值 /// </summary> /// <param name="type"></param> /// <param name="obj"></param> public void SetItemValue(SystemType type, string obj) { if (type == SystemType.附件) { label2.SendToBack(); PermissionForm owner = null; Form f = this.FindForm(); if (f != null && f is PermissionForm) { owner = f as PermissionForm; } string[] ss = obj.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (ss.Length > 1) { int id; if (int.TryParse(ss[0], out id) && id > 0) { Attachment a = Commons.GetAttachmentForDownload(id); ac.SetAttachment(a); } } ac.BringToFront(); } else { ac.SendToBack(); label2.Text = obj; label2.BringToFront(); } }
private static bool Enable10(Control control, User user) { Form owner = control.FindForm(); if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { control.Enabled = true; int nofinded = 0; string formName = owner.Name; PermissionCollection ps = user.GetAllPermissions(false); foreach (Control c in control.Controls) { string controlName = c.Name; if (ps.ContainsControl(formName, control.Name, controlName)) { c.Enabled = true; } else { c.Enabled = false; nofinded++; ToolStrip ms = c as ToolStrip; if (ms != null) { if (ms.EnableChildrenForUser(user)) { nofinded--; } } else { if (c.EnableChildrenForUser(user)) { nofinded--; } } } } if (nofinded == control.Controls.Count) { control.Enabled = false; return(false); } else { return(true); } } } return(false); }
/// <summary> /// 设置字段的值 /// </summary> /// <param name="type"></param> /// <param name="obj"></param> public void SetItemValue(SystemType type, string obj) { comboBox1.SelectedIndex = GetIndexByType(type, comboBox1); switch (type) { case SystemType.附件: PermissionForm owner = null; Form f = this.FindForm(); if (f != null && f is PermissionForm) { owner = f as PermissionForm; } Attachment a = Commons.GetAttachment(obj, owner); List <Attachment> atta = new List <Attachment>(); if (a != null) { atta.Add(a); } uc.Attachments = atta; break; case SystemType.时间: dtp.Value = Convert.ToDateTime(obj); break; case SystemType.数字: nud.Value = Convert.ToDecimal(obj); break; case SystemType.字符: default: tb.Text = Convert.ToString(obj); break; } }
/// <summary> /// 获取刚选定的附件(尚未上传),或者已经上传的附件(格式:12|abc.txt) /// </summary> /// <param name="filepath"></param> /// <param name="owner"></param> /// <returns></returns> public static Attachment GetAttachment(string filepath, PermissionForm owner = null) { Attachment a = null; if (!string.IsNullOrEmpty(filepath)) { int id = 0; string truePath = filepath; int index = filepath.IndexOf("|"); if (index > -1)//12|abc.txt { id = Convert.ToInt32(filepath.Substring(0, index)); truePath = filepath.Substring(index + 1); } a = new Attachment(); a.ID = id; a.AttachmentFilename = truePath; if (File.Exists(filepath)) { FileInfo fi = new FileInfo(filepath); a.Size = fi.Length; } if (owner != null) { a.Uploader = owner.User; } } return(a); }
/// <summary> /// 用于子窗体的排除权限 /// </summary> /// <param name="menu"></param> /// <param name="user"></param> /// <returns></returns> internal static bool DisableForUser2(this ToolStripItem menu, User user = null) { Form owner = null; if (menu.Owner != null) { if (menu.Owner.Parent != null) { owner = menu.Owner.Parent.FindForm(); } } if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { menu.Enabled = true; string formName = owner.Name; string controlName = menu.Name; PermissionCollection ps = user.GetAllPermissions(false); if (ps.ExceptControl(formName, controlName)) { menu.Enabled = false; return(true); } else { ToolStripDropDownItem dropmenu = menu as ToolStripDropDownItem; if (dropmenu != null) { ToolStripItemCollection items = dropmenu.DropDownItems; if (items != null) { foreach (ToolStripItem c in items) { controlName = c.Name; if (ps.ExceptControl(formName, dropmenu.Name, controlName)) { c.Enabled = false; } else { c.DisableForUser2(user); } } } } } } } return(false); }
private void SelectFilesToUpload() { OpenFileDialog f = new OpenFileDialog(); f.Multiselect = multiselect; f.Filter = "所有文件(*.*)|*.*"; f.Title = "选择要上传的附件..."; if (f.ShowDialog() == DialogResult.OK) { User user = null; Form owner = this.FindForm(); if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } } string[] files = f.FileNames; List <Attachment> attachs = new List <Attachment>(); StringBuilder sb = new StringBuilder(); foreach (string file in files) { FileInfo fi = new FileInfo(file); Attachment attach = new Attachment(); attach.AttachmentFilename = file; attach.Size = fi.Length; attach.Uploader = user; attachs.Add(attach); if (sb.Length == 0) { sb.Append(fi.Name); } else { sb.Append("," + fi.Name); } } this.label1.Tag = attachs; this.label1.Text = sb.ToString(); if (MessageBox.Show("确定要上传这些附件吗?" + Environment.NewLine + sb.ToString(), "上传提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { UploadAttachments(attachs); } else { this.label1.Text = "上传附件..."; this.label1.Tag = null; } } f.Dispose(); }
private static bool Disable10(Control control, User user) { Form owner = control.FindForm(); if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { control.Enabled = true; string formName = owner.Name; string controlName = control.Name; PermissionCollection ps = user.GetAllPermissions(false); if (ps.ExceptControl(formName, controlName)) { control.Enabled = false; return(true); } else { foreach (Control c in control.Controls) { controlName = c.Name; if (ps.ExceptControl(formName, control.Name, controlName)) { c.Enabled = false; } else { ToolStrip ms = c as ToolStrip; if (ms != null) { ms.DisableForUser(user); } else { c.DisableForUser(user); } } } } } } return(false); }
private static bool Enable20(ToolStrip menuStrip, User user) { Form owner = menuStrip.FindForm(); if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { menuStrip.Enabled = true; int nofinded = 0; string formName = owner.Name; PermissionCollection ps = user.GetAllPermissions(false); foreach (ToolStripItem c in menuStrip.Items) { string controlName = c.Name; if (ps.ContainsControl(formName, menuStrip.Name, controlName)) { c.Enabled = true; } else { c.Enabled = false; nofinded++; if (c.EnableChildrenForUser2(user)) { nofinded--; } } } if (nofinded == menuStrip.Items.Count) { menuStrip.Enabled = false; return(false); } else { return(true); } } } return(false); }
/// <summary> /// 设置字段的值(注意:只能自己上传附件,无法修改别人上传的附件,其他字段类型的值就能修改) /// </summary> /// <param name="type"></param> /// <param name="obj"></param> public void SetItemValue(SystemType type, string obj) { panel1.Controls.Clear(); Control c = null; switch (type) { case SystemType.附件: PermissionForm owner = null; Form f = this.FindForm(); if (f != null && f is PermissionForm) { owner = f as PermissionForm; } Attachment a = Commons.GetAttachment(obj, owner); List <Attachment> atta = new List <Attachment>(); if (a != null) { atta.Add(a); } uc.Attachments = atta; c = uc; break; case SystemType.时间: dtp.Value = Convert.ToDateTime(obj); c = dtp; break; case SystemType.数字: nud.Value = Convert.ToDecimal(obj); c = nud; break; case SystemType.字符: default: tb.Text = Convert.ToString(obj); c = tb; break; } if (c != null) { panel1.Controls.Add(c); } }
private static bool Disable20(ToolStrip menuStrip, User user) { Form owner = menuStrip.FindForm(); if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { menuStrip.Enabled = true; string formName = owner.Name; string controlName = menuStrip.Name; PermissionCollection ps = user.GetAllPermissions(false); if (ps.ExceptControl(formName, controlName)) { menuStrip.Enabled = false; return(true); } else { foreach (ToolStripItem c in menuStrip.Items) { controlName = c.Name; if (ps.ExceptControl(formName, menuStrip.Name, controlName)) { c.Enabled = false; } else { c.DisableForUser2(user); } } } } } return(false); }
/// <summary> /// 用于主窗体的包含权限 /// </summary> /// <param name="menu"></param> /// <param name="user"></param> /// <returns></returns> internal static bool EnableChildrenForUser2(this ToolStripItem menu, User user = null) { Form owner = null; if (menu.Owner != null) { if (menu.Owner.Parent != null) { owner = menu.Owner.Parent.FindForm(); } } if (owner != null) { if (user == null) { PermissionForm pf = owner as PermissionForm; if (pf != null) { user = pf.User; } } if (user != null) { ToolStripDropDownItem dropmenu = menu as ToolStripDropDownItem; if (dropmenu != null) { ToolStripItemCollection items = dropmenu.DropDownItems; if (items != null) { dropmenu.Enabled = true; int nofinded = 0; string formName = owner.Name; PermissionCollection ps = user.GetAllPermissions(false); foreach (ToolStripItem c in items) { string controlName = c.Name; if (ps.ContainsControl(formName, dropmenu.Name, controlName)) { c.Enabled = true; } else { c.Enabled = false; nofinded++; if (c.EnableChildrenForUser2(user)) { nofinded--; } } } if (nofinded == items.Count) { dropmenu.Enabled = false; return(false); } else { return(true); } } } } } return(false); }