示例#1
0
        private void btOK_Click(object sender, EventArgs e)
        {
            if (tbGroupName.TextLength == 0)
            {
                MessageBox.Show("Введите название группы!");
            }
            else
            {
                var db = new MonitoringDB();
                group.Name        = tbGroupName.Text;
                group.Information = tbInformation.Text;
                group.Level       = 0;
                if (parentNode != null)
                {
                    if (parentNode.Tag != null)
                    {
                        group.Parent = db.UserGroups.Where(x => x.UsersGroupId == ((UsersGroup)parentNode.Tag).UsersGroupId).First();
                    }
                    group.Level = parentNode.Level + 1;
                }

                if (isAdd)
                {
                    db.UserGroups.Add(group);
                }
                else
                {
                    db.UserGroups.Attach(group);
                    db.Entry(db.UserGroups.Find(group.UsersGroupId)).State = EntityState.Modified;
                }
                db.SaveChanges();
                DialogResult = DialogResult.OK;
                Close();
            }
        }
示例#2
0
        public void AddConnection(ClientObject clientObject)
        {
            LicenceKey key;
            JsonPack   jsOut;
            JsonPack   jsIn = clientObject.GetMessage();

            switch (jsIn.metod)
            {
            case "JSDRegister":
                JSDRegister reg = (JSDRegister)jsIn.data;
                key = db.LicenceKeys.Where(x => x.Key == reg.key).FirstOrDefault();
                if (key != null && (key.UnicId == null || key.UnicId == ""))
                {
                    key.UnicId = reg.Id_1 + reg.Id_2;
                }
                db.LicenceKeys.Attach(key);
                db.Entry(db.LicenceKeys.Find(key.LicenceKeyId)).State = EntityState.Modified;
                db.SaveChanges();
                clientObject.user = db.Users.Where(x => x.UserId == key.UserId).FirstOrDefault();
                jsOut             = new JsonPack();
                jsOut.data        = new JSDRegisterS()
                {
                    result = true
                };
                clients.Add(clientObject);
                clientObject.SendMessage(jsOut);
                break;

            case "JSDLogin":
                JSDLogin login = (JSDLogin)jsIn.data;
                key   = db.LicenceKeys.Where(x => x.Key == login.LicenseKey && x.UnicId == login.UniqPC).FirstOrDefault();
                jsOut = new JsonPack()
                {
                    data = new JSDLoginS()
                    {
                        result = false
                    }
                };
                if (key != null)
                {
                    clientObject.user = db.Users.Where(x => x.UserId == key.UserId).FirstOrDefault();
                    ((JSDLoginS)(jsOut.data)).result = true;
                }
                ;
                clients.Add(clientObject);
                clientObject.SendMessage(jsOut);
                break;

            default:
                break;
            }

            /*
             * if (clientObject.TryLogin() == ResultCode.Login)
             * {
             *  Thread clientThread = new Thread(new ThreadStart(clientObject.Process));
             *  clientThread.Start();
             * }*/
        }
示例#3
0
        private bool SaveChange()
        {
            if (tbDeviceName.TextLength == 0)
            {
                MessageBox.Show("Введите название устройства (для оботражения)");
                return(false);
            }
            if (cbTypeDevice.Text == "")
            {
                MessageBox.Show("Виберете тип устройства!");
                return(false);
            }
            if (mtbLicenceKey.Text.Contains(' ') && MessageBox.Show("Для пользователя не сгенерирован ключ активации, сохранить без ключа?", "", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return(false);
            }

            user.Name     = tbDeviceName.Text;
            user.UserName = tbUserName.Text;
            user.DateReg  = DateTime.Now;
            if (parentGroup != null)
            {
                if (parentGroup.Tag != null)
                {
                    user.Group = db.UserGroups.Where(x => x.UsersGroupId == ((UsersGroup)parentGroup.Tag).UsersGroupId).First();
                }
            }
            user.Information = tbInformation.Text;
            user.TypePC      = cbTypeDevice.SelectedIndex;
            user.Phone       = mtbPhone.Text;
            user.Company     = tbCompany.Text;

            if (isAdd)
            {
                db.Users.Add(user);
                db.SaveChanges();
                isAdd = false;
            }
            else
            {
                if (user != null)
                {
                    db.Users.Attach(user);
                    db.Entry(db.Users.Find(user.UserId)).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    MessageBox.Show("Ошибка редактирования пользователя!");
                    return(false);
                }
            }

            if (!mtbLicenceKey.Text.Contains(' '))
            {
                LicenceKey licenseKey = new LicenceKey()
                {
                    Active     = true,
                    DateExp    = dtpDateTo.Value,
                    Key        = mtbLicenceKey.Text,
                    User       = user,
                    DateCreate = DateTime.Now,
                    UnicId     = null
                };
                db.LicenceKeys.Add(licenseKey);
                db.SaveChanges();
                lbNoSave.Visible = false;
                btApply.Enabled  = false;
            }
            //else
            //    MessageBox.Show("Ошибка редактирования ключа!");
            return(true);
        }