Пример #1
0
        public bool RemoceUserRight(UserRight right, DbTransaction tran)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("ID", right.ID);
            return(processor.ExecuteNonQuery("delete from userright where id=@ID", tran, dic) == 0 ? false : true);
        }
Пример #2
0
        public void DeleteMeaningAndRelation(Meanings meaning)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("@MeaningId", meaning.Id);
            processor.ExecuteNonQuery("DELETE FROM UserMeanRelation WHERE MeaningId=@MeaningId", dic);
            processor.ExecuteNonQuery("DELETE FROM Meanings WHERE ID=@MeaningId", dic);
        }
Пример #3
0
        public bool DisableUser(string Username, bool effective)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("disable", effective == true?0:1);
            dic.Add("username", Username);
            return(processor.ExecuteNonQuery("update userinfo set disabled=@disable where username=@username COLLATE NOCASE", dic) == 0 ? false : true);
        }
Пример #4
0
        public void DeleteAlarmConfig(AlarmConfig alarm, DbTransaction tran)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("ID", alarm.ID);
            processor.ExecuteNonQuery("delete from alarmconfig where id=@ID", tran, dic);
        }
Пример #5
0
        public void DeleteLogConfig(LogConfig log, DbTransaction tran)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("ID", log.ID);
            processor.ExecuteNonQuery("delete from logconfig where id=@ID", tran, dic);
        }
Пример #6
0
        public void DeleteDigitalSignature(DigitalSignature digital, DbTransaction tran)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("ID", digital.ID);
            processor.ExecuteNonQuery("delete from DigitalSignature where id=@ID", tran, dic);
        }
Пример #7
0
        public void DeletePointInfo(PointInfo point, DbTransaction tran)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("ID", point.ID);
            processor.ExecuteNonQuery("delete from pointinfo where id=@ID", tran, dic);
        }
Пример #8
0
        public void DeleteDevice(Device device, DbTransaction tran)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("ID", device.ID);
            processor.ExecuteNonQuery("delete from device where id=@ID", tran, dic);
        }
Пример #9
0
        public void DeleteReportEditorBySnTn(string sn, string tn, DbTransaction tran)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("sn", sn);
            dic.Add("tn", tn);
            processor.ExecuteNonQuery("delete from ReportEditor where SN=@sn and TN=@tn", tran, dic);
        }
Пример #10
0
 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
 }
Пример #11
0
 /// <summary>
 /// 判断是否登录成功,同时保存用户信息
 /// </summary>
 /// <returns></returns>
 public bool Login()
 {
     try
     {
         if (Common.TextBoxChecked(tbAccount) && Common.TextBoxChecked(tbPwd))
         {
             UserInfo user = processor.QueryOne <UserInfo>("SELECT * FROM UserInfo WHERE username=@username", delegate()
             {
                 Dictionary <string, object> dic = new Dictionary <string, object>();
                 dic.Add("username", tbAccount.Text.TrimEnd());
                 //dic.Add("pwd", tbPwd.Text.TrimEnd());
                 return(dic);
             });
             if (user.Locked == 0)
             {
                 if (LoginTimes <= Common.Policy.LockedTimes)
                 {
                     if (user.Userid != 0 && user.Pwd.Equals(this.tbPwd.Text))
                     {
                         Common.User = user;
                         LoginTimes  = 0;
                         this.SaveUserList();//保存列表
                         //记录成功的日志
                         logBll.InsertLog(() =>
                         {
                             Dictionary <string, object> dic = new Dictionary <string, object>();
                             dic.Add("OperateTime", DateTime.Now);
                             dic.Add("Action", "Log on");
                             dic.Add("UserName", user.UserName);
                             dic.Add("FullName", user.FullName);
                             dic.Add("Detail", "Success");
                             dic.Add("LogType", 0);
                             return(dic);
                         });
                         return(true);
                     }
                     else if (user.Userid == 0)
                     {
                         this.lbAccount.Text = "× user does not exist.";
                         //this.lbAccount.ForeColor = System.Drawing.Color.Red;
                         return(false);
                     }
                     else
                     {
                         this.lbPwd.Text = "× password invalid.";
                         //this.lbPwd.ForeColor = System.Drawing.Color.Red;
                         LoginTimes++;
                         //记录日志
                         logBll.InsertLog(() =>
                         {
                             Dictionary <string, object> dic = new Dictionary <string, object>();
                             dic.Add("OperateTime", DateTime.Now);
                             dic.Add("Action", "Log on");
                             dic.Add("UserName", user.UserName);
                             dic.Add("FullName", user.FullName);
                             dic.Add("Detail", "Failure");
                             dic.Add("LogType", 0);
                             return(dic);
                         });
                         return(false);
                     }
                 }
                 else
                 {
                     Dictionary <string, object> dic = new Dictionary <string, object>();
                     dic.Add("locked", 1);
                     dic.Add("username", this.tbAccount.Text.TrimEnd());
                     processor.ExecuteNonQuery("UPDATE userinfo set locked=@locked where username=@username", dic);
                     this.lbPwd.Text = "× over " + Common.Policy.LockedTimes.ToString() + " times";
                 }
             }
             else
             {
                 this.lbPwd.Text = "× account's locked.";
                 //记录账号锁定日志
                 logBll.InsertLog(() =>
                 {
                     Dictionary <string, object> dic = new Dictionary <string, object>();
                     dic.Add("OperateTime", DateTime.Now);
                     dic.Add("Action", "Log on");
                     dic.Add("UserName", user.UserName);
                     dic.Add("FullName", user.FullName);
                     dic.Add("Detail", "Failure");
                     dic.Add("LogType", 0);
                     return(dic);
                 });
             }
         }
         return(false);
     }
     catch (Exception exc) { return(false); }
 }
Пример #12
0
 /// <summary>
 /// 判断是否登录成功,同时保存用户信息
 /// </summary>
 /// <returns></returns>
 public bool Login()
 {
     try
     {
         if (Common.TextBoxChecked(tbAccount) && Common.TextBoxChecked(tbPwd))
         {
             UserInfo user = processor.QueryOne <UserInfo>("SELECT * FROM UserInfo WHERE username=@username COLLATE NOCASE", delegate()
             {
                 Dictionary <string, object> dic = new Dictionary <string, object>();
                 dic.Add("username", tbAccount.Text.Trim().ToLower());
                 //dic.Add("pwd", tbPwd.Text.TrimEnd());
                 return(dic);
             });
             if (user.Locked == 0)
             {
                 if (user.Userid != 0 && user.Pwd.Equals(this.tbPwd.Text) && user.Disabled == 0)
                 {
                     Common.User = user;
                     loginTimes[user.UserName] = 0;
                     this.SaveUserList();    //保存列表
                     //记录成功的日志
                     if (Common.User.UserName != Common.SUPERUSER)
                     {
                         logBll.InsertLog(() =>
                         {
                             Dictionary <string, object> dic = new Dictionary <string, object>();
                             dic.Add("OperateTime", DateTime.UtcNow);
                             dic.Add("Action", LogAction.Logon);
                             dic.Add("UserName", user.UserName);
                             dic.Add("FullName", user.FullName);
                             dic.Add("Detail", "Successful");
                             dic.Add("LogType", LogAction.SystemAuditTrail);
                             return(dic);
                         });
                     }
                     return(true);
                 }
                 else if (user.Userid == 0 || user.Disabled == 1)
                 {
                     //TODO:
                     if (tbAccount.Text == Common.SUPERUSER && tbPwd.Text == Common.SUPERUSERPWD)
                     {
                         UserInfo super = new UserInfo()
                         {
                             UserName           = Common.SUPERUSER,
                             Pwd                = Common.SUPERUSERPWD,
                             FullName           = "super admin",
                             LastPwdChangedTime = DateTime.UtcNow,
                             RoleId             = 1
                         };
                         Common.User = super;
                         return(true);
                     }
                     else
                     {
                         Utils.ShowMessageBox(Messages.WrongUserNameOrPassword, Messages.TitleError);
                         return(false);
                     }
                 }
                 else if (user.Pwd != this.tbPwd.Text)
                 {
                     if (!loginTimes.ContainsKey(user.UserName))
                     {
                         loginTimes[user.UserName] = 0;
                     }
                     loginTimes[user.UserName]++;
                     if (loginTimes[user.UserName] >= Common.Policy.LockedTimes && Common.Policy.LockedTimes > 0)
                     {
                         Dictionary <string, object> dic = new Dictionary <string, object>();
                         dic.Add("locked", 1);
                         dic.Add("username", this.tbAccount.Text.TrimEnd());
                         processor.ExecuteNonQuery("UPDATE userinfo set locked=@locked where username=@username COLLATE NOCASE", dic);
                         Utils.ShowMessageBox(Messages.WrongPasswordExcceedCertainTimes, Messages.TitleError);
                     }
                     else
                     {
                         Utils.ShowMessageBox(Messages.WrongUserNameOrPassword, Messages.TitleError);
                     }
                     //记录账号锁定日志
                     if (Common.User.UserName != Common.SUPERUSER)
                     {
                         logBll.InsertLog(() =>
                         {
                             Dictionary <string, object> dic = new Dictionary <string, object>();
                             dic.Add("OperateTime", DateTime.UtcNow);
                             dic.Add("Action", LogAction.Logon);
                             dic.Add("UserName", user.UserName);
                             dic.Add("FullName", user.FullName);
                             dic.Add("Detail", "Failed");
                             dic.Add("LogType", LogAction.SystemAuditTrail);
                             return(dic);
                         });
                     }
                     return(false);
                 }
                 else
                 {
                     return(false);
                 }
             }
             else
             {
                 Utils.ShowMessageBox(Messages.UserLocked, Messages.TitleError);
             }
         }
         else
         {
             Utils.ShowMessageBox(Messages.WrongUserNameOrPassword, Messages.TitleError);
         }
         return(false);
     }
     catch { return(false); }
 }