public void Init() { List <RoleInfo> role = processor.Query <RoleInfo>("SELECT * FROM RoleInfo", null); if (role == null || role.Count == 0) { role.Add(new RoleInfo() { ID = 1, Rolename = "Admin", Remark = DateTime.Now.ToString() }); role.Add(new RoleInfo() { ID = 2, Rolename = "User", Remark = DateTime.Now.ToString() }); processor.Insert <RoleInfo>(role); } this.cbxRole.DataSource = role; this.cbxRole.DisplayMember = "Rolename"; this.cbxRole.ValueMember = "ID"; userid = this.GetCurrentUserId(); if (username != null && username != string.Empty) { user = processor.QueryOne <UserInfo>("SELECT * FROM USERINFO WHERE username=@username COLLATE NOCASE", delegate() { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("username", username.Trim().ToLower()); return(dic); }); this.tbUserName.Text = user.UserName; this.tbFullName.Text = user.FullName; this.tbPwd.Text = user.Pwd; this.tbDescription.Text = user.Description; this.tbConfirm.Text = user.Pwd; switch (user.RoleId) { case 1: this.cbxRole.SelectedValue = 1; break; case 2: this.cbxRole.SelectedValue = 2; break; default: break; } // 如果为普通用户,则隐藏锁定、Diable、Group修改选项 if (Common.User.RoleId != 1 || Common.User.Userid == user.Userid) { this.cbxRole.Enabled = false; } Common.SetControlEnable(this.tbUserName, false); } else { Common.SetControlEnable(this.tbUserName, true); } }
public bool InsertPoint(PointInfo point, DbTransaction tran) { object o = processor.QueryScalar("select 1 from pointinfo where id=" + point.ID.ToString(), null); if (o != null && o.ToString() != "") { point.ID = GetPointPKValue() + 1; } return(processor.Insert <PointInfo>(point, tran)); }
private void OK(object sender, EventArgs args) { if (processor == null) { processor = new DeviceProcessor(); } if (this.tbMean.Text == string.Empty) { MessageBox.Show("Please input the meaning"); } else { if (meaning == null) { Meanings mean = new Meanings(); object o = processor.QueryScalar("SELECT MAX(ID) FROM Meanings", null); mean.Id = o != null && o.ToString() != string.Empty ? Convert.ToInt32(o) + 1 : 1; mean.Desc = this.tbMean.Text.TrimEnd(); mean.Remark = DateTime.Now.ToString(); if (processor.Insert <Meanings>(mean, null)) { form.DialogResult = DialogResult.OK; } else { MessageBox.Show("Saved Failure"); form.DialogResult = DialogResult.No; } } else { Meanings mean = new Meanings(); mean.Id = meaning.First().Key; mean.Desc = this.tbMean.Text.TrimEnd(); mean.Remark = DateTime.Now.ToString(); if (processor.Update <Meanings>(mean, null)) { form.DialogResult = MessageBox.Show("Saved Successfully"); } else { MessageBox.Show("Saved Failure"); form.DialogResult = DialogResult.No; } } } }
public void Init() { List <RoleInfo> role = processor.Query <RoleInfo>("SELECT * FROM RoleInfo", null); if (role == null || role.Count == 0) { role.Add(new RoleInfo() { ID = 1, Rolename = "Administrators", Remark = DateTime.Now.ToString() }); role.Add(new RoleInfo() { ID = 2, Rolename = "Users", Remark = DateTime.Now.ToString() }); processor.Insert <RoleInfo>(role); } this.cbxRole.DataSource = role; this.cbxRole.DisplayMember = "Rolename"; this.cbxRole.ValueMember = "ID"; userid = this.GetCurrentUserId(); if (username != null && username != string.Empty) { user = processor.QueryOne <UserInfo>("SELECT * FROM USERINFO WHERE username=@username", delegate() { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("username", username); return(dic); }); this.tbUserName.Text = user.UserName; this.tbFullName.Text = user.FullName; this.tbPwd.Text = user.Pwd; this.tbDescription.Text = user.Description; this.tbConfirm.Text = user.Pwd; this.cbChangePwd.Checked = Convert.ToBoolean(user.ChangePwd); this.cbLocked.Checked = Convert.ToBoolean(user.Locked); Common.SetControlEnable(this.cbLocked, true); Common.SetControlEnable(this.tbUserName, false); } else { Common.SetControlEnable(this.cbLocked, false); Common.SetControlEnable(this.tbUserName, true); } }
public bool InsertProfile(UserProfile profile, DbTransaction tran) { return(processor.Insert <UserProfile>(profile, tran)); }
private void InitEvents() { /*删除用户*/ this.btnDelete.Click += new EventHandler(delegate(object sender, EventArgs args) { DataTable dt = dgvUser.DataSource as DataTable; if (null != dt) { Dictionary <string, object> dic; foreach (DataGridViewRow row in this.dgvUser.SelectedRows) { dic = new Dictionary <string, object>(); dic.Add("username", row.Cells["User Name"].Value.ToString()); processor.ExecuteNonQuery("DELETE FROM USERINFO WHERE username=@username", dic); dt.Rows.RemoveAt(row.Index); } //this.InitUsers(); this.dgvUser.DataSource = dt; } }); /*删除meanings*/ this.btnDelMean.Click += new EventHandler(delegate(object sender, EventArgs args) { object o = this.clbMeaning.SelectedValue; if (o == null && o.ToString() == string.Empty) { MessageBox.Show("Please select the item!"); } else { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("id", o.ToString()); processor.ExecuteNonQuery("DELETE FROM Meanings WHERE id=@id", dic); processor.ExecuteNonQuery("DELETE FROM UserMeanRelation WHERE MeaningsID=@id", dic); //this.InitMeaning(); /* 重新绑定数据源 取消从数据库中读取*/ List <Meanings> list = this.clbMeaning.DataSource as List <Meanings>; if (list != null) { list = new List <Meanings>(list);//it does not make sense? it is bugged? list.Remove(this.clbMeaning.SelectedItem as Meanings); this.clbMeaning.DataSource = list; this.clbMeaning.ValueMember = "ID"; this.clbMeaning.DisplayMember = "Desc"; } } }); #region comment itemcheck /*list check event*/ this.clbMeaning.ItemCheck += new ItemCheckEventHandler(delegate(object sender, ItemCheckEventArgs args) { if (!flag) { return; } if (this.dgvUser.SelectedRows.Count <= 0) { MessageBox.Show("Please select the user!"); args.NewValue = args.CurrentValue; } else { Dictionary <string, object> dic = new Dictionary <string, object>(); int meanid = ((Meanings)clbMeaning.SelectedItem).Id; string username = this.dgvUser.SelectedRows[0].Cells["User Name"].Value.ToString(); dic.Add("MeaningsID", meanid); dic.Add("username", username); object obj = processor.QueryScalar("SELECT 1 FROM UserMeanRelation where MeaningsID=@MeaningsID AND username=@username", dic); if (args.NewValue == CheckState.Checked && obj == null)//添加 { obj = processor.QueryScalar("SELECT MAX(ID) FROM UserMeanRelation", null); UserMeanRelation u = new UserMeanRelation(); u.ID = obj != null && obj.ToString() != string.Empty ? Convert.ToInt32(obj) + 1 : 1; //u.MeaningsID = meanid; u.Username = username; u.MeaningDesc = ((Meanings)clbMeaning.SelectedItem).Desc; u.Remark = DateTime.Now.ToString(); if (processor.Insert <UserMeanRelation>(u, null)) { return;//MessageBox.Show("Add the meaning to " + username + " successfully!"); } else { MessageBox.Show("Add the meaning to " + username + " error!"); } } else if (args.NewValue == CheckState.Unchecked && obj != null) { processor.ExecuteNonQuery("DELETE FROM UserMeanRelation WHERE MeaningsID=@MeaningsID AND username=@username ", dic); } } }); #endregion //selection changed this.dgvUser.SelectionChanged += new EventHandler(delegate(object sender, EventArgs args) { this.UserSelectedChange(); }); #region comment //this.clbMeaning.SelectedIndexChanged += new EventHandler(delegate(object sender, EventArgs args) //{ // if (!flag) return; // CheckState ck = this.clbMeaning.GetItemCheckState(clbMeaning.Items.IndexOf(clbMeaning.SelectedItem)); // if (this.dgvUser.SelectedRows.Count <= 0) // { // MessageBox.Show("Please select the user!"); // //args.NewValue = args.CurrentValue; // } // else // { // Dictionary<string, object> dic = new Dictionary<string, object>(); // int meanid = ((Meanings)clbMeaning.SelectedItem).Id; // string username = this.dgvUser.SelectedRows[0].Cells["User Name"].Value.ToString(); // dic.Add("MeaningsID", meanid); // dic.Add("username", username); // object obj = processor.QueryScalar("SELECT 1 FROM UserMeanRelation where MeaningsID=@MeaningsID AND username=@username", dic); // if (ck == CheckState.Unchecked && obj == null)//添加 // { // obj = processor.QueryScalar("SELECT MAX(ID) FROM UserMeanRelation", null); // UserMeanRelation u = new UserMeanRelation(); // u.ID = obj != null && obj.ToString() != string.Empty ? Convert.ToInt32(obj) + 1 : 1; // u.MeaningsID = meanid; // u.Username = username; // u.MeaningDesc = ((Meanings)clbMeaning.SelectedItem).Desc; // u.Remark = DateTime.Now.ToString(); // if (processor.Insert<UserMeanRelation>(u, null)) // { // //MessageBox.Show("Add the meaning to " + username + " successfully!"); // this.clbMeaning.SetItemCheckState(this.clbMeaning.SelectedIndex, ck == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked); // } // else // MessageBox.Show("Add the meaning to " + username + " error!"); // } // else if (ck == CheckState.Checked && obj != null) // { // processor.ExecuteNonQuery("DELETE FROM UserMeanRelation WHERE MeaningsID=@MeaningsID AND username=@username ", dic); // this.clbMeaning.SetItemCheckState(this.clbMeaning.SelectedIndex, ck == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked); // } // } //}); #endregion }
public bool InsertAlarmConfig(AlarmConfig alarm, DbTransaction tran) { return(processor.Insert <AlarmConfig>(alarm, tran)); }
public bool InsertUser(UserInfo user, System.Data.Common.DbTransaction tran) { return(processor.Insert <UserInfo>(user, tran)); }
public bool InsertLogConfig(LogConfig log, DbTransaction tran) { return(processor.Insert <LogConfig>(log, tran)); }
public bool InsertDigitalSignature(DigitalSignature ds, DbTransaction tran) { return(processor.Insert <DigitalSignature>(ds, tran)); }
public bool InsertMeaning(Meanings m, DbTransaction tran) { return(processor.Insert <Meanings>(m, tran)); }
public bool InsertPolicy(Policy entity) { return(processor.Insert <Policy>(entity, null)); }
public bool InsertLog(OperationLog entity) { return(processor.Insert <OperationLog>(entity, null)); }
public bool InsertUserRight(UserRight right, DbTransaction tran) { return(processor.Insert <UserRight>(right, tran)); }
public bool InsertDevice(Device device, DbTransaction tran) { return(processor.Insert <Device>(device, tran)); }
public bool InsertReportEditor(ReportEditor report, DbTransaction tran) { return(processor.Insert <ReportEditor>(report, tran)); }