private void SendComputerToDb() { currentComputer._AuditNumber = audnum; DataManager.log.Log("Клиент: начало отправки данных на сервер."); try { SetProgress(72); Notify("Отправка данных о компьютере"); DataManager.log.Log("Клиент: отправка данных о компьютере на сервер."); Pgs.AddComputerAndOs(currentComputer); SetProgress(75); Notify("Отправка ПО компьютера"); DataManager.log.Log("Клиент: отправка данных о ПО компьютера на сервер."); Pgs.AddSoftwareToComputer(currentComputer); SetProgress(85); Notify("Отправка комплектующих компьютера"); DataManager.log.Log("Клиент: отправка данных о комплектующих компьютера на сервер."); Pgs.AddHardwareToComputer(currentComputer); SetProgress(95); } catch (Exception ex) { CanselScan("Ошибка при попытке отправить данные на сервер:\n" + ex.Message); return; } FinishScan(); }
private void RefreshEquipements() { selectedItem = ""; switch (cbEquipType.SelectedIndex) { case 0: items = Pgs.GetCabels(); break; case 1: items = Pgs.GetNetEquip(); break; case 2: items = Pgs.GetProectors(); break; case 3: items = Pgs.GetBitovayaTehnika(); break; case 4: items = Pgs.GetPrinterScanner(); break; case 5: items = Pgs.GetKeyboardMouses(); break; } FillPanel(items); }
private void FillGridView() { string table_name = tables[cbDbTable.SelectedIndex]; if (User.Role != UserRole.Admin) { if (cbDbTable.SelectedIndex == 16) { da = Pgs.GetDataAdapter("SELECT id, name, type FROM " + table_name); } else if (cbDbTable.SelectedIndex == 17) { da = Pgs.GetDataAdapter("SELECT computer_name, program_id, os_id, path_exe, locked FROM " + table_name); } else { da = Pgs.GetDataAdapter("SELECT * FROM " + table_name); } } else { da = Pgs.GetDataAdapter("SELECT * FROM " + table_name); } dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; }
private void BtnSend_Click(object sender, EventArgs e) { try { ComputerInformation ci = new ComputerInformation(); Pgs.SendReport(ci.GetOs(), chosenComputerName, reporttype, selectedItem, selectedEquipementType, tbFio.Text, rtbComment.Text); var result = MessageBox.Show("Заявка успешно отправлена! Желаете сохранить ее в виде текстового файла?", "Успех", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.Yes) { SaveFileDialog sv = new SaveFileDialog(); sv.FileName = "result"; sv.Filter = "Тексовый файл|*.txt"; result = sv.ShowDialog(); if (result == DialogResult.OK) { System.IO.StreamWriter sw = new System.IO.StreamWriter(sv.FileName, false); sw.WriteLine("ФИО: " + tbFio.Text); sw.WriteLine("Компьютер: " + chosenComputerName); sw.WriteLine("Тип заявки: " + reporttype.ToString()); sw.WriteLine("Комментарий:" + rtbComment.Text); sw.Close(); MessageBox.Show("Успешно сохранено.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (onReportFinished != null) { onReportFinished(); } } catch (Exception ex) { MessageBox.Show("Ошибка отправки заявки: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ReportItemChooseForm(ReportType rt) { InitializeComponent(); DialogResult = DialogResult.Cancel; items = new List <string>(); cbEquipType.SelectedIndex = 0; switch (rt) { case ReportType.None: throw new Exception("Тип заявки не указан!"); case ReportType.SoftInstall: items = Pgs.GetAllSoftwareList(); lblTitle.Text += "программу"; break; case ReportType.ComponentRepair: items = Pgs.GetAllPcComponents(); lblTitle.Text += "компонент"; break; case ReportType.EquipRepair: cbEquipType.Visible = true; cbEquipType.SelectedIndexChanged += (o, ea) => { RefreshEquipements(); }; RefreshEquipements(); break; } FillPanel(items); }
private void BtnStartScan_Click(object sender, EventArgs e) { SetProgress(0); DataManager.log.Log("Клиент: начало сканирования."); computerExplorer.Clear(); try { Notify("Извлечение ПО"); SetProgress(15); DataManager.log.Log("Клиент: начало извлечения ПО."); FillSoftware(); computerExplorer.SetComputer(currentComputer); SetProgress(40); Notify("Извлечение комплектующих"); SetProgress(45); DataManager.log.Log("Клиент: начало извлечения железа."); FillHardware(); SetProgress(65); } catch (Exception ex) { CanselScan("Ошибка при сканировании:\n" + ex.Message + "\nСканирование прервано."); return; } if (User.Autonom) { CanselScan(User.AutonomWarning + "\nДанные не были отправлены на сервер."); return; } if (Pgs.CheckComputerExist(currentComputer._MAC, out audnum)) { SendComputerToDb(); return; } if (User.Role != UserRole.Admin) { CanselScan("Данный компьютер не привязан к какой-либо аудитории. Назначить компьютеру аудиторию может только администратор. Пожалуйста, сообщите ему о проблеме."); return; } audnum = DataManager.st.GetValue("auditory_number"); if (audnum == "null" || !Pgs.CheckAuditoryNumber(audnum)) { Notify("Назначение аудитории"); MessageBox.Show("Данному компьютеру необходимо назначить аудиторию, в которой он находится. Укажите это в следующем окне.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); if (!AskAudiotyNumber(out audnum)) { CanselScan("Данные не могут быть отправлены на сервер без указания номера аудитории."); return; } } SetProgress(70); SendComputerToDb(); }
internal List <Computer> RefreshComputers() { if (User.Autonom) { MessageBox.Show(User.AutonomWarning, "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } return(Pgs.GetNetworkComputerList()); }
internal bool SetIpPort(out string ip, out string port) { ip = DataManager.st.GetValue("server"); port = DataManager.st.GetValue("port"); if (String.IsNullOrEmpty(ip) || String.IsNullOrEmpty(port) || !Pgs.SetUserCheckConnection(ip, port)) { return(false); } return(true); }
private void LoginForm_Load(object sender, EventArgs e) { trgLoginConnect.onTriggered += ChangePanel; String ip, port; ip = DataManager.st.GetValue("server"); port = DataManager.st.GetValue("port"); tbServerIp.Text = ip; tbServerPort.Text = port; if (String.IsNullOrEmpty(ip) || String.IsNullOrEmpty(port) || !Pgs.SetUserCheckConnection(ip, port)) { trgLoginConnect._CurrentState = false; trgLoginConnect._Color2 = Color.Red; } }
private void RefreshDb() { try { NpgsqlDataAdapter da = Pgs.GetDataAdapter(cbSelect.SelectedIndex); ds.Reset(); da.Fill(ds); dt = ds.Tables[0]; dataGridView1.DataSource = dt; SetFont(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void BtnSignIn_Click(object sender, EventArgs e) { if (!Pgs.CheckConnection()) { MessageBox.Show("Невозможно соединиться с сервером. Проверка авторизации невозможна.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tbLogin.Text == string.Empty || tbPassword.Text == string.Empty) { MessageBox.Show("Пожалуйста, заполните все поля!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } String account_role = Pgs.GetUserRole(tbLogin.Text, tbPassword.Text); if (account_role == "") { MessageBox.Show("Неверный логин или пароль! Пожалуйста, проверьте введенные данные.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } User.Name = tbLogin.Text; if (account_role.ToLower() == "admin") { User.Role = UserRole.Admin; } else if (account_role.ToLower() == "lecturer") { User.Role = UserRole.Lecturer; } else { MessageBox.Show("Неизвестная роль пользователя! Обратитесь к системному администратору!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } String ip = DataManager.st.GetValue("server"); String port = DataManager.st.GetValue("port"); if (!Pgs.SetDatabaseConnectionWithRole(ip, port, account_role)) { MessageBox.Show("Неизвестная ошибка подключения к серверу. Обратитесь к администратору.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } User.Autonom = false; this.Hide(); MainForm mf = new MainForm(this); mf.Show(); }
internal bool SignIn(string Login, string Pass) { if (!Pgs.CheckConnection()) { MessageBox.Show("Невозможно соединиться с сервером. Проверка авторизации невозможна.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (Login == string.Empty || Pass == string.Empty) { MessageBox.Show("Пожалуйста, заполните все поля!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } String account_role = Pgs.GetUserRole(Login, Pass); if (account_role == "") { MessageBox.Show("Неверный логин или пароль! Пожалуйста, проверьте введенные данные.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } User.Name = Login; if (account_role.ToLower() == "admin") { User.Role = UserRole.Admin; } else if (account_role.ToLower() == "lecturer") { User.Role = UserRole.Lecturer; } else { MessageBox.Show("Неизвестная роль пользователя! Обратитесь к системному администратору!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } String ip = DataManager.st.GetValue("server"); String port = DataManager.st.GetValue("port"); if (!Pgs.SetDatabaseConnectionWithRole(ip, port, account_role)) { MessageBox.Show("Неизвестная ошибка подключения к серверу. Обратитесь к администратору.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } User.Autonom = false; return(true); }
private void RefreshItems() { List <String[]> equips = Pgs.GetEquipementsGroupedByAuditories(); String lastAud = ""; int broken = 0; foreach (String[] eq in equips) { if (lastAud != eq[1]) { lastAud = eq[1]; Label l = new Label() { Text = eq[1], AutoSize = true, Font = new Font("Arial", 13, FontStyle.Bold), Margin = new Padding(2, 4, 2, 4) }; flpEquips.Controls.Add(l); } broken = FillEquips(eq); } if (broken == 0) { return; } Label l3 = new Label() { Text = "Вышедшее из строя оборудование", AutoSize = true, Font = new Font("Arial", 13, FontStyle.Bold), Margin = new Padding(2, 4, 2, 4) }; flpEquips.Controls.Add(l3); foreach (var eq in equips) { if (!bool.Parse(eq[5])) { FillEquips(eq); } } }
private void FillComboBox(string header, string datapropertyname, string table_name, string value_member, string display_member) { DataGridViewComboBoxColumn c = new DataGridViewComboBoxColumn(); c.HeaderText = header; c.DataPropertyName = datapropertyname; //string table_name = tables[cbDbTable.SelectedIndex]; da = Pgs.GetDataAdapter($"SELECT {value_member}, {display_member} FROM " + table_name); //da = Pgs.GetDataAdapter($"SELECT * FROM " + table_name); dt = new DataTable(); da.Fill(dt); c.ValueMember = value_member; c.DisplayMember = display_member; c.DataSource = dt; c.FlatStyle = FlatStyle.Popup; dataGridView1.Columns.Add(c); }
internal bool GuestSignIn(string Ip, string Port) { Pgs.SetDatabaseConnectionWithRole(Ip, Port, "guest"); User.Autonom = false; if (!Pgs.CheckConnection()) { var result = MessageBox.Show("Внимание! Отсутствует соединение с базой данных. Вы все еще можете пользоваться некоторыми функциями программы, однако для ее эффективного использования необходимо восстановить соединение. Продолжить работу в автономном режиме?", "Ошибка подключения", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return(false); } else { User.Autonom = true; } } User.Role = UserRole.Guest; return(true); }
internal bool CheckConnection(string Ip, string Port) { if (Ip == string.Empty || Port == string.Empty) { MessageBox.Show("Заполните все поля!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } if (!Pgs.SetUserCheckConnection(Ip, Port)) { MessageBox.Show("Ошибка соединения с сервером БД!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else { MessageBox.Show("Соединение с сервером БД настроено!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); DataManager.st.SetValue("server", Ip); DataManager.st.SetValue("port", Port); Properties.Settings.Default.Save(); return(true); } }
private void BtnCheckConnection_Click(object sender, EventArgs e) { if (tbServerIp.Text == string.Empty || tbServerPort.Text == string.Empty) { MessageBox.Show("Заполните все поля!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!Pgs.SetUserCheckConnection(tbServerIp.Text, tbServerPort.Text)) { MessageBox.Show("Ошибка соединения с сервером БД!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); trgLoginConnect._Color2 = Color.Red; } else { MessageBox.Show("Соединение с сервером БД настроено!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); DataManager.st.SetValue("server", tbServerIp.Text); DataManager.st.SetValue("port", tbServerPort.Text); Properties.Settings.Default.Save(); trgLoginConnect._Color2 = Color.FromArgb(15, 240, 30); } }
public void FillComputers() { List <String> computers = Pgs.GetComputerNames(); int i = 0; foreach (String a in computers) { RadioButton rb = new RadioButton(); rb.Font = rbInstall.Font; rb.Text = a; rb.Margin = new Padding(5, 3, 3, 0); rb.AutoSize = true; pnlAuditory.Controls.Add(rb); rb.CheckedChanged += (o, ea) => { if (!rbInstall.Checked) { selectedItem = ""; } pnlReportType.Enabled = true; chosenComputerName = rb.Text; CheckSendButton(); }; if (i == 0) { rb.Checked = true; } i++; } if (i == 0) { MessageBox.Show("Нет компьютеров в базе. Невозможно отослать заявку.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error); if (onReportFinished != null) { onReportFinished(); } } }
private bool AskAudiotyNumber(out String number) { using (NumberAssign na = new NumberAssign()) { number = ""; var result = na.ShowDialog(); while (result == DialogResult.OK && !Pgs.CheckAuditoryNumber(na.Number)) { MessageBox.Show("Аудитории с таким номером нет в базе данных. Пожалуйста, проверьте правильность введенных данных или обратитесь к администратору.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); result = na.ShowDialog(); } if (result == DialogResult.OK) { number = na.Number; DataManager.st.SetValue("auditory_number", number); return(true); } else { return(false); } } }
static void Main(string[] args) { var handle = GetConsoleWindow(); ShowWindow(handle, SW_HIDE); LogMaker lm = new LogMaker(); Settings st = new Settings(); st.SeparationSymbol = ':'; st.EndOfLineType = Settings.EOLType.CRLF; String ip = st.GetValue("server"); String port = st.GetValue("port"); lm.Log("Запуск программы."); if (!Pgs.SetDatabaseConnectionWithRole(ip, port, "guest")) { lm.Log($"Ошибка подключения к базе с параметрами [{ip}] [{port}]."); return; } Computer currentComputer = new Computer(); try { ComputerInformation nw = new ComputerInformation(); currentComputer._MAC = nw.GetMACAddress(); currentComputer._Name = nw.GetName(); currentComputer._Ip = nw.GetIp(); currentComputer._Os = nw.GetOs(); List <Software> soft = nw.GetSoftwareCollection(); foreach (Software s in soft) { currentComputer.AddSoftware(s); } List <string> view = new List <string>(); ComputerInformation ci = new ComputerInformation(); ci.ScanFromCpuZ(); currentComputer.AddHardware(ci.GetCpu()); currentComputer.AddHardware(ci.GetMotherboard()); foreach (Hardware h in ci.GetGpus()) { currentComputer.AddHardware(h); } foreach (Hardware h in ci.GetRams()) { currentComputer.AddHardware(h); } foreach (Hardware h in ci.GetHdds()) { currentComputer.AddHardware(h); } String audnum = st.GetValue("auditory_number"); currentComputer._AuditNumber = audnum; Pgs.AddComputerAndOs(currentComputer); Pgs.AddSoftwareToComputer(currentComputer); Pgs.AddHardwareToComputer(currentComputer); lm.Log("Данные успешно отправлены."); } catch (Exception ex) { lm.Log("Ошибка при работе с данными: " + ex.Message); } }
public void ResetForm() { tbLogin.Clear(); tbPassword.Clear(); Pgs.SetUserCheckConnection(tbServerIp.Text, tbServerPort.Text); }