Beispiel #1
0
 private void but_ad_delectuser_Click(object sender, RoutedEventArgs e)
 {
     DbTools.sqlExecuteNonQuery("delete from dbo.UserSignIn where UsID='" + text_ad_cardid.Text + "'");
     DbTools.sqlExecuteNonQuery("delete from dbo.Users where UsID='" + text_ad_cardid.Text + "'");
     MessageBox.Show("删除成功!");
     but_ad_delectuser.IsEnabled = false;
 }
Beispiel #2
0
        public static string sqlSelectUserAndInsertMessage(string CardID, DateTime time)
        {
            string username = null;

            try
            {
                using (SqlConnection sqlcon = new SqlConnection("Server=.;user=sa;pwd=123456;database=myIotDb"))
                {
                    sqlcon.Open();
                    SqlCommand    sql    = new SqlCommand("select UsName from dbo.Users where UsID='" + CardID + "'", sqlcon);
                    SqlDataReader reader = sql.ExecuteReader();
                    if (reader.Read() == true)
                    {
                        username = reader.GetString(0);
                    }
                    else
                    {
                        username = "******";
                    }
                }
                DbTools.sqlExecuteNonQuery("insert into dbo.UserSignIn(UsID, UsSignInTime) values('" + CardID + "', '" + time.ToString() + "')");
            }
            catch
            {
                username = "******";
            }
            return(username);
        }
Beispiel #3
0
        private void but_selectuser_Click(object sender, RoutedEventArgs e)
        {
            string mes = DbTools.sqlSelectUserMessage(text_ad_cardid.Text);

            MessageBox.Show(mes);
            if (Users.UserLevel == "超级管理员" && mes != "查询失败")
            {
                but_ad_delectuser.IsEnabled = true;
            }
        }
Beispiel #4
0
 private void but_ad_insert_Click(object sender, RoutedEventArgs e)
 {
     if (text_ad_x_pad.Text.Trim() == "")
     {
         MessageBox.Show("请输入密码!");
     }
     else
     {
         DbTools.sqlExecuteNonQuery("insert dbo.Administrators(AdName,AdPassword,AdLevel) values('" + text_ad_adname.Text + "','" + text_ad_x_pad.Text + "','普通管理员')");
         MessageBox.Show("新增管理员成功!");
     }
 }
Beispiel #5
0
 private void but_ad_delete_Click(object sender, RoutedEventArgs e)
 {
     if (text_ad_adname.Text == "admin")
     {
         MessageBox.Show("不能删除超级管理员!");
     }
     else
     {
         DbTools.sqlExecuteNonQuery("delete from dbo.Administrators where AdName='" + text_ad_adname.Text + "'");
         MessageBox.Show("删除成功!");
     }
 }
Beispiel #6
0
 void updatePad()
 {
     if (DbTools.sqlSelectAdminPad(text_name.Text, text_y_pad.Text))
     {
         DbTools.sqlExecuteNonQuery("update dbo.Administrators set AdPassword='******' where AdName='" + text_name.Text + "'");
         MessageBox.Show("修改成功!");
     }
     else
     {
         MessageBox.Show("密码错误!");
     }
 }
Beispiel #7
0
        void selectUserMessage()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("姓名");
            dt.Columns.Add("卡号");
            dt.Columns.Add("打卡时间");
            data_message.ItemsSource = dt.DefaultView;
            if (text_cardid.Text.Trim() == "" && text_user.Text.Trim() == "")
            {
                try
                {
                    DbTools.sqlExecuteReader("select dbo.UserSignIn.UsID,UsName,UsSignInTime from dbo.Users,dbo.UserSignIn where UsSignInTime>'" + date_start.Text + "' and UsSignInTime<'" + date_close.Text + "' and dbo.Users.UsID=dbo.UserSignIn.UsID", dt);
                }
                catch
                {
                    MessageBox.Show("查询失败!");
                }
            }
            else if (text_cardid.Text.Trim() != "" && text_user.Text.Trim() == "")
            {
                try
                {
                    DbTools.sqlExecuteReader("select dbo.UserSignIn.UsID,UsName,UsSignInTime from dbo.Users,dbo.UserSignIn where UsSignInTime>'" + date_start.Text + "' and UsSignInTime<'" + date_close.Text + "' and dbo.Users.UsID=dbo.UserSignIn.UsID and dbo.Users.UsID='" + text_cardid.Text + "'", dt);
                }
                catch
                {
                    MessageBox.Show("查询失败!");
                }
            }
            else if (text_cardid.Text.Trim() == "" && text_user.Text.Trim() != "")
            {
                try
                {
                    DbTools.sqlExecuteReader("select dbo.UserSignIn.UsID,UsName,UsSignInTime from dbo.Users,dbo.UserSignIn where UsSignInTime>'" + date_start.Text + "' and UsSignInTime<'" + date_close.Text + "' and dbo.Users.UsID=dbo.UserSignIn.UsID and dbo.Users.UsName='" + text_user.Text + "'", dt);
                }
                catch
                {
                    MessageBox.Show("查询失败!");
                }
            }
            else if (text_cardid.Text.Trim() != "" && text_user.Text.Trim() != "")
            {
                try
                {
                    DbTools.sqlExecuteReader("select dbo.UserSignIn.UsID,UsName,UsSignInTime from dbo.Users,dbo.UserSignIn where UsSignInTime>'" + date_start.Text + "' and UsSignInTime<'" + date_close.Text + "' and dbo.Users.UsID=dbo.UserSignIn.UsID and dbo.Users.UsName='" + text_user.Text + "' and dbo.Users.UsID='" + text_cardid.Text + "'", dt);
                }
                catch
                {
                    MessageBox.Show("查询失败!");
                }
            }
        }
Beispiel #8
0
        private void but_load_Click(object sender, RoutedEventArgs e)
        {
            string level = DbTools.sqlUserSignIn(text_user.Text.Trim(), text_pad.Text.Trim());

            if (level == "用户不存在")
            {
                MessageBox.Show("登陆失败,用户不存在!");
            }
            else
            {
                MessageBox.Show(level + "用户:" + text_user.Text + "\n欢迎进入物联网智能门禁系统!");
                Users.UserName  = text_user.Text;
                Users.UserLevel = level;
                Main main = new Main();
                this.Visibility = Visibility.Collapsed;
                main.ShowDialog();
            }
        }
Beispiel #9
0
 void insertUser()
 {
     if (text_CardID.Text.Trim() != "" && text_user.Text.Trim() != "")
     {
         try
         {
             DbTools.sqlExecuteNonQuery("insert into dbo.Users(UsID,UsName,UsCreateTime) values('" + text_CardID.Text + "','" + text_user.Text + "','" + DateTime.Now.ToString() + "')");
             MessageBox.Show("信息录入成功!");
         }
         catch
         {
             MessageBox.Show("信息录入失败!");
         }
     }
     else
     {
         MessageBox.Show("请完整填写信息!");
     }
 }
Beispiel #10
0
        void selectAdmin()
        {
            string pad = DbTools.sqlSelectPad(text_ad_adname.Text);

            if (pad == "用户不存在")
            {
                but_ad_insert.IsEnabled = true;
                text_ad_x_pad.IsEnabled = true;
                label_ad_adzt.Content   = "状态:账号不存在,可新增!";
            }
            else
            {
                text_ad_x_pad.IsEnabled = true;
                but_ad_update.IsEnabled = true;
                but_ad_delete.IsEnabled = true;
                label_ad_adzt.Content   = "状态:账号存在,请进行下一步操作!";
                text_ad_y_pad.Text      = pad;
            }
        }
Beispiel #11
0
 private void but_ad_update_Click(object sender, RoutedEventArgs e)
 {
     DbTools.sqlExecuteNonQuery("update dbo.Administrators set AdPassword='******' where AdName='" + text_ad_adname.Text + "'");
     MessageBox.Show("密码更改成功!");
 }
Beispiel #12
0
 void timerInit()//时钟初始化
 {
     selectTimer          = new DispatcherTimer();
     selectTimer.Interval = TimeSpan.FromMilliseconds(100);
     selectTimer.Tick    += new EventHandler((obj, eve) =>
     {
         try
         {
             cardID = CardTools.scanCard().Trim();//读卡操作
         }
         catch
         {
             cardID = null;
         }
         if (cardID != null && cardID != "")
         {
             string name = DbTools.sqlSelectUserAndInsertMessage(cardID, DateTime.Now);
             CardTools.readCardMessage();
             if (name != "非法卡")
             {
                 mTimer.Start();
                 label_zt.Content = "欢迎打卡:" + name;
             }
             else
             {
                 label_zt.Content = "非法卡,不与进入!";
             }
             cardID = null;
         }
     });
     mTimer          = new DispatcherTimer();
     mTimer.Interval = TimeSpan.FromMilliseconds(10);
     mTimer.Tick    += new EventHandler((obj, eve) =>
     {
         //门禁动画
         if (i <= 500)
         {
             i++;
         }
         if (i == 1)
         {
             selectTimer.Stop();
             openZigbee();
         }
         if (i <= 100)
         {
             grid_lm.Margin = new Thickness(134 - i, 41, 0, 0);
             grid_rm.Margin = new Thickness(263 + i, 41, 0, 0);
         }
         else
         if (i == 500)
         {
             i = 0;
             mTimer.Stop();
             grid_lm.Margin = new Thickness(134, 41, 0, 0);
             grid_rm.Margin = new Thickness(263, 41, 0, 0);
             selectTimer.Start();
             closeZigBee();
         }
     });
     #endregion
 }