예제 #1
0
 partial void DeleteComputer(Computer instance);
예제 #2
0
 partial void InsertComputer(Computer instance);
예제 #3
0
 partial void UpdateComputer(Computer instance);
예제 #4
0
        public void SetPcLockStatus(ServerInfo serverInfo, Cert cert, int lockPc)
        {
            string connString = String.Format(settingsHelper.connectionString, serverInfo.address);
            SqlConnection connection = new SqlConnection(connString);
            DataClassesDataContext database = new DataClassesDataContext();

            try
            {
                connection.Open();

                var queryUser = from u in database.Users
                                where u.Username == cert.user
                                select u;

                if (queryUser.Count() == 0)
                {
                    User newUser = new User
                    {
                        Username = cert.user,
                        Type = "user"
                    };

                    database.Users.InsertOnSubmit(newUser);
                    database.SubmitChanges();
                }

                var queryPC = from u in database.Computers
                              where u.PC_name == Environment.MachineName
                              select u;

                if (queryPC.Count() == 0)
                {
                    Computer newPC = new Computer
                    {
                        PC_name = cert.pcName,
                        Lock_status = lockPc
                    };

                    database.Computers.InsertOnSubmit(newPC);
                    database.SubmitChanges();
                    MessageBox.Show("This PC is now LOCKED.\n\nUser authorized on this PC:\n" + cert.user);
                }
                else
                {
                    queryPC.First().Lock_status = lockPc;
                    database.SubmitChanges();
                    if (lockPc == 1)
                        MessageBox.Show("This PC is now LOCKED.\n\nUser authorized on this PC:\n" + cert.user);
                    else MessageBox.Show("This PC is now UNLOCKED.");
                }

                queryUser = from u in database.Users
                            where u.Username == cert.user
                            select u;

                queryPC = from u in database.Computers
                          where u.PC_name == Environment.MachineName
                          select u;

                var queryAuth = from a in database.Auths
                                where a.ID_user == queryUser.First().ID && a.ID_pc == queryPC.First().ID
                                select a;

                if (queryAuth.Count() == 0)
                {
                    Auth newAuth = new Auth
                    {
                        ID_pc = queryPC.First().ID,
                        ID_user = queryUser.First().ID,
                        Auth_key = cert.HashedAuthKey,
                        Device = cert.deviceId
                    };

                    database.Auths.InsertOnSubmit(newAuth);
                    database.SubmitChanges();
                }
                else if (lockPc == 0)
                {
                    database.Auths.DeleteOnSubmit(queryAuth.First());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                connection.Close();
            }
        }