//确认 private void okBtn_Click(object sender, EventArgs e) { bool newAuthority = false; var authority = db.Authority.FirstOrDefault(x => x.emplyeeId == m_Employee.id); if (authority == null) { newAuthority = true; authority = new Authority(); authority.emplyeeId = m_Employee.id; } foreach (Control p in cts) { foreach (Control ct in p.Controls) { if (ct.GetType() == typeof(CheckBox)) { var pro = authority.GetType().GetProperty(ct.Text); if (pro == null) continue; if (BathClass.getAuthority(db, LogIn.m_User, ct.Text)) pro.SetValue(authority, ((CheckBox)ct).Checked, null); } } } if (newAuthority) db.Authority.InsertOnSubmit(authority); db.SubmitChanges(); this.DialogResult = DialogResult.OK; this.Close(); }
// 获取员工权限,如果权限表中没有对应的employeeId,则按照jobId对应的权限 private void getAuthority() { m_Authority = db.Authority.FirstOrDefault(x => x.emplyeeId == m_Employee.id); if (m_Authority == null) m_Authority = db.Authority.FirstOrDefault(x => x.jobId == m_Employee.jobId); }
partial void DeleteAuthority(Authority instance);
partial void UpdateAuthority(Authority instance);
partial void InsertAuthority(Authority instance);
//对话框载入 private void JobForm_Load(object sender, EventArgs e) { cts = new Control[rp.Controls.Count + bg.Controls.Count]; rp.Controls.CopyTo(cts, 0); bg.Controls.CopyTo(cts, rp.Controls.Count); if (!newJob) { id.Text = m_job.id.ToString(); name.Text = m_job.name; note.Text = m_job.note; ip.Text = m_job.ip; this.Text = "编辑职位"; if (m_job.leaderId != null) ComboJobList.Text = db.Job.FirstOrDefault(x => x.id == m_job.leaderId).name; if (m_job.departId != null) ComboDeparts.Text = db.Department.FirstOrDefault(x => x.id == m_job.departId).name; m_Authority = db.Authority.FirstOrDefault(x => x.jobId == m_job.id); foreach (Control p in cts) { foreach (Control ct in p.Controls) { if (ct.GetType() == typeof(CheckBox)) { var pro = m_Authority.GetType().GetProperty(ct.Text); if (pro == null) continue; var proVal = pro.GetValue(m_Authority, null); ((CheckBox)ct).Checked = Convert.ToBoolean(proVal); } } } } else { int maxId = 1; if (db.Job.Count() != 0) { var res = db.Job.Max(x => x.id); maxId = res + 1; } id.Text = maxId.ToString(); name.Focus(); } }