Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public int GetDigitalSignaturePKValue()
        {
            object u = processor.QueryScalar("select max(id) from DigitalSignature", null);

            if (u != null && u.ToString() != string.Empty)
            {
                return(Convert.ToInt32(u));
            }
            else
            {
                return(0);
            }
        }
Esempio n. 3
0
        public bool IsExist(string username, string right)
        {
            Dictionary <string, object> dic = new Dictionary <string, object> ();

            dic.Add("username", username);
            dic.Add("right", right);
            object o = processor.QueryScalar("select 1 from userright where username=@username COLLATE NOCASE and right=@right", dic);

            if (o == null || o.ToString() == "")
            {
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// 插入用户操作日志
        /// </summary>
        /// <param name="dic"></param>
        /// <returns></returns>
        public bool InsertLog(Dictionary <string, object> dic)
        {
            OperationLog log = new OperationLog();

            if (dic.Keys.Contains("ID"))
            {
                log.ID = (int)dic.First(p => { return(p.Key == "ID"); }).Value;
            }
            else
            {
                object o  = processor.QueryScalar("select max(id) from OperationLog", null);
                int    id = 0;
                if (o != null && !string.IsNullOrEmpty(o.ToString()))
                {
                    id = Convert.ToInt32(o);
                }
                log.ID = id + 1;
            }
            log.Operatetime = (DateTime)dic.First(p => { return(p.Key == "OperateTime"); }).Value;
            log.Action      = (string)dic.First(p => { return(p.Key == "Action"); }).Value;
            log.Username    = (string)dic.First(p => { return(p.Key == "UserName"); }).Value;
            log.Fullname    = (string)dic.First(p => { return(p.Key == "FullName"); }).Value;
            log.Detail      = (string)dic.First(p => { return(p.Key == "Detail"); }).Value;
            log.LogType     = (int)dic.First(p => { return(p.Key == "LogType"); }).Value;//0系统,1分析
            return(this.InsertLog(log));
        }
Esempio n. 5
0
        private int GetCurrentUserId()
        {
            object u = processor.QueryScalar("select max(userid) from userinfo", null);

            if (u != null && u.ToString() != string.Empty)
            {
                return(Convert.ToInt32(u));
            }
            else
            {
                return(0);
            }
        }
Esempio n. 6
0
        public int GetAlarmConfigPKValue()
        {
            object u = processor.QueryScalar("select max(id) from AlarmConfig", null);

            if (u != null && u.ToString() != string.Empty)
            {
                return(Convert.ToInt32(u));
            }
            else
            {
                return(0);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 插入relation
        /// </summary>
        /// <param name="username"></param>
        /// <param name="dic"></param>
        /// <returns></returns>
        public bool InsertMeanRel(string username, Dictionary <string, object> dic, DbTransaction tran)
        {
            /*先查询是否存在username->meaning的关系*/
            Dictionary <string, object> condition = new Dictionary <string, object>();

            condition.Add("username", username);
            condition.Add("desc", dic["Desc"]);
            object o = processor.QueryScalar("select 1 from UserMeanRelation where username=@username and MeaningDesc=@desc", condition);

            if (o == null || o.ToString() == "")
            {
                UserMeanRelation rel = new UserMeanRelation();
                //if (dic.Keys.Contains("mID"))
                //    rel.MeaningsID = (int)dic.First(p => p.Key == "mID").Value;
                //else
                //{
                //查询meaning id
                // Meanings m = this.GetMeaningByName(dic["Desc"].ToString());
                //if(m!=null&&m.Id!=0)
                //{
                if (dic.Keys.Contains("ID"))
                {
                    rel.ID = (int)dic.First(p => { return(p.Key == "ID"); }).Value;
                }
                else
                {
                    int id = this.GetRelationPKValue();
                    rel.ID = id + 1;
                }
                rel.MeaningDesc = dic["Desc"].ToString();
                rel.Username    = username;
                rel.Remark      = DateTime.Now.ToString();
                return(processor.Insert <UserMeanRelation>(rel, tran));
                //}
            }
            return(false);
        }
Esempio n. 8
0
 /// <summary>
 /// 查询是否存在用户列表
 /// </summary>
 /// <returns></returns>
 public bool QueryUser()
 {
     try
     {
         object o = processor.QueryScalar("SELECT count(1) FROM UserInfo ", null);
         if (o != null && o.ToString() != "0")
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception exc) { return(false); }
 }
Esempio n. 9
0
 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;
             }
         }
     }
 }
Esempio n. 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
 }