/
dorofeev_denis
/
Monitoring_objects
Обзор
Документация
Войти
/
dorofeev_denis
/
Monitoring_objects
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Unit1.pas
441 строка
17 KB
dorofeev_denis
create: MONITORING_OBJECTS.dpr, MONITORING_OBJECTS.dproj, Unit1.dfm, Unit1.pas, Unit2.dfm, Unit2.pas, Unit3.dfm, Unit3.pas, Для исправления статусов Росреестра.xlsx, создание схем и таблиц.sql
07 май 2026, 14:24
Верифицирован
07 май 2026, 14:24
830bc00
Код
Авторство
О чём код?
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UniProvider, OracleUniProvider, Data.DB, MemDS, DBAccess, Uni, Vcl.StdCtrls, Unit2, Unit3, UniDacVcl, Vcl.Grids, Vcl.DBGrids, Vcl.Mask, Vcl.DBCtrls, Vcl.ExtCtrls, Vcl.Menus, Vcl.ComCtrls; // ������ ���������� ����������� ����� ��� ������ ����������� ���� ����������� � ��, � ��������� ������ ���� ��� LoginPrompt = true ���������� ���� ������������ �� ����� (��. ��. ������������) type TForm_main = class(TForm) UniConnectDialog1: TUniConnectDialog; UniDataSource1: TUniDataSource; Panel_DBGrid: TPanel; DBGrid1: TDBGrid; Panel_search: TPanel; Label_district: TLabel; ComboBox_district: TComboBox; Label_kn: TLabel; Edit_kn: TEdit; Label_name: TLabel; Edit_name: TEdit; Label_status: TLabel; ComboBox_status: TComboBox; Label_address: TLabel; Edit_address: TEdit; Label_area: TLabel; Edit_area: TEdit; Button_find: TButton; Panel_connect: TPanel; Button_connect: TButton; Button_disconnect: TButton; Label_object_type: TLabel; ComboBox_object_type: TComboBox; Label1: TLabel; ComboBox_object_class: TComboBox; UniConnection1: TUniConnection; UniQuery1: TUniQuery; OracleUniProvider1: TOracleUniProvider; MainMenu1: TMainMenu; N1: TMenuItem; N2: TMenuItem; N_upd_exp: TMenuItem; N4: TMenuItem; Label_remark: TLabel; Label_remark_ogv_omsu: TLabel; Edit_remark: TEdit; Edit_remark_ogv_omsu: TEdit; ComboBox_remark: TComboBox; ComboBox_remark_ogv_omsu: TComboBox; Panel1: TPanel; Edit1: TEdit; Button_change: TButton; Edit_double: TEdit; Label_double: TLabel; ComboBox_double: TComboBox; Button_upload_script_result: TButton; Main_ProgressBar: TProgressBar; Main_search_num_rows: TEdit; Label2: TLabel; Label_status_ogv_omsu: TLabel; ComboBox_status_ogv_omsu: TComboBox; procedure Button_connectClick(Sender: TObject); procedure Button_disconnectClick(Sender: TObject); procedure UniConnection1Error(Sender: TObject; E: EDAError; var Fail: Boolean); procedure FormCreate(Sender: TObject); procedure Button_findClick(Sender: TObject); procedure Button_changeClick(Sender: TObject); procedure DBGrid1CellClick(Column: TColumn); procedure Find_objects; procedure N4Click(Sender: TObject); procedure N_upd_expClick(Sender: TObject); procedure Button_upload_script_resultClick(Sender: TObject); procedure ComboBox_remarkChange(Sender: TObject); procedure ComboBox_remark_ogv_omsuChange(Sender: TObject); procedure ComboBox_doubleChange(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form_main: TForm_main; emp_id: integer; // ������� ������������ (�� �������� � ������ ������) id: integer; // id ������� m_obj dept_no: integer; // ����� ������, ��� ��������� ������������ (�� �������� � ������ ������) dept_name: string; //������������ ������, ��� ��������� ������������ (�� �������� � ������ ������) path_exe: string; //���� �� exe ����� logs: TextFile; //��� ������ implementation {$R *.dfm} procedure Load_script(path: widestring); //������ ���������� ����� � ���� ������ var ts: TStringList; i: integer; begin {ExtractFilePath(Application.ExeName) Application.ExeName - ���������� ������ ���� �� exe ����� � ���������� ������ exe �����, �.�. C:\...\...\Project1.exe � ���������� �������� � ���� ������ ExtractFilePath - �������� ���� ���� �� C:\...\...\} ts:=TStringList.Create(); ts.LoadFromFile(path); Form_main.UniQuery1.SQL.Clear; //������ ��� ������� ���� ����� ������� for i:= 0 to ts.Count-1 do Form_main.UniQuery1.SQL.Add(ts.Strings[i]); //�� ������� ts.Free; //������������ ������ end; //����� ������ procedure TForm_main.Find_objects; var kn, address, name, area, district, status, status_ogv_omsu, object_type, object_class, remark, remark_ogv_omsu, object_duplicate, s: string; begin try // ��� ����������� ������ ���������� ������������ Active, ��� ��������� - Execute Form_main.UniQuery1.Active:= false; Form_main.UniQuery1.SQL.Clear; Load_script(path_exe + 'FILES_LOAD\find_objects.sql'); district:= Form_main.ComboBox_district.Items[Form_main.ComboBox_district.ItemIndex]; kn:= trim(Form_main.Edit_kn.Text); // ������� ������� �� � ����� �� status:= Form_main.ComboBox_status.Items[Form_main.ComboBox_status.ItemIndex]; status_ogv_omsu:= Form_main.ComboBox_status_ogv_omsu.Items[Form_main.ComboBox_status_ogv_omsu.ItemIndex]; object_type:= Form_main.ComboBox_object_type.Items[Form_main.ComboBox_object_type.ItemIndex]; object_class:= Form_main.ComboBox_object_class.Items[Form_main.ComboBox_object_class.ItemIndex]; address:= ansilowercase(trim(Form_main.Edit_address.Text)); name:= ansilowercase(trim(Form_main.Edit_name.Text)); area:= ansilowercase(trim(Form_main.Edit_area.Text)); remark:= ansilowercase(trim(Edit_remark.Text)); remark_ogv_omsu:= ansilowercase(trim(Edit_remark_ogv_omsu.Text)); object_duplicate:= ansilowercase(trim(Edit_double.Text)); {����� ������������ ������ �� �������� ����������} s:= ''; if district = '��� ������' then district:= '%' else district:= district + '%'; if kn <> '' then s:= s + ' and o.cadastral_number like ''%' + kn + '%'''; if object_type = '������ ��������' then // ��� ������� s:= s + ' and o.object_type is null' else if object_type <> '��� ����' then s:= s + ' and o.object_type = ''' + object_type + ''''; if object_class = '������ ��������' then // ��� ������� s:= s + ' and o.object_class is null' else if object_class <> '��� �������' then s:= s + ' and o.object_class = ''' + object_class + ''''; if status <> '��� �������' then // ������ ���������� s:= s + ' and o.status = ''' + status + ''''; if status_ogv_omsu <> '��� �������' then // ������ ���, ���� s:= s + ' and o.status_ogv_omsu = ''' + status_ogv_omsu + ''''; if address <> '' then // ����� s:= s + ' and lower(o.address) like ''%' + address + '%'''; if name <> '' then // ������������ �� s:= s + ' and lower(o.name) like ''%' + name + '%'''; if area <> '' then // ������� s:= s + ' and lower(o.area) like ''%' + area + '%'''; case ComboBox_remark.ItemIndex of //����� ����������� ���������� 0: if remark <> '' then s:= s + ' and lower(o.remark) like ''%' + remark + '%'''; // ������ �������� �� ����������� ������������ like 1: s:= s + ' and o.remark is null'; 2: s:= s + ' and o.remark is not null'; end; case ComboBox_remark_ogv_omsu.ItemIndex of //����� ����������� ���, ���� 0: if remark_ogv_omsu <> '' then s:= s + ' and lower(o.remark_ogv_omsu) like ''%' + remark_ogv_omsu + '%'''; // ������ �������� �� ����������� ������������ like 1: s:= s + ' and o.remark_ogv_omsu is null'; 2: s:= s + ' and o.remark_ogv_omsu is not null'; end; case ComboBox_double.ItemIndex of //����� ����� �� 0: if object_duplicate <> '' then s:= s + ' and lower(o.object_duplicate) like ''%' + object_duplicate + '%'''; // ������ �������� �� ����������� ������������ like 1: s:= s + ' and o.object_duplicate is null'; 2: s:= s + ' and o.object_duplicate is not null'; end; Form_main.UniQuery1.MacroByName('mac').Value:= s; Form_main.UniQuery1.ParamByName('district').ParamType:= ptInput; Form_main.UniQuery1.ParamByName('district').AsString:= district; {Form_main.UniQuery1.ParamByName('cadastral_number').ParamType:= ptInput; Form_main.UniQuery1.ParamByName('obj_address').ParamType:= ptInput; Form_main.UniQuery1.ParamByName('obj_name').ParamType:= ptInput; Form_main.UniQuery1.ParamByName('obj_area').ParamType:= ptInput; } {Form_main.UniQuery1.ParamByName('cadastral_number').AsString:= kn; Form_main.UniQuery1.ParamByName('obj_address').AsString:= address; Form_main.UniQuery1.ParamByName('obj_name').AsString:= name; Form_main.UniQuery1.ParamByName('obj_area').AsString:= area; } Form_main.UniQuery1.Active:= true; Main_search_num_rows.Text:= IntToStr(Form_main.UniQuery1.RecordCount); except on E:Exception do MessageDlg('������ ��� �������� ������� ������ ��: ' + e.Message, mtInformation,[mbOK],0); end; end; {����������� �������������� �������� ������������, �� �������� � ������ ������} function Get_emp_id(out dept_no: integer; out dept_name: string): integer; begin Form_main.UniQuery1.SQL.Clear; Form_main.UniQuery1.SQL.Add('select e.id, e.dept_no, e.dept_name from monitoring_objects.m_emps e where e.username = :username'); Form_main.UniQuery1.ParamByName('username').AsString:= ansilowercase(Form_main.UniConnection1.Username); // ������������������� ���� ������ Form_main.UniQuery1.Active:= true; //��������� ������ Result:= Form_main.UniQuery1.Fields[0].AsInteger; // null = 0 dept_no:= Form_main.UniQuery1.Fields[1].AsInteger; dept_name:= Form_main.UniQuery1.Fields[2].AsString; Form_main.UniQuery1.Active:= false end; procedure TForm_main.Button_upload_script_resultClick(Sender: TObject); var num_of_rows, num_of_fields: integer; begin try num_of_rows:= UniQuery1.RecordCount; num_of_fields:= UniQuery1.FieldCount; Form_tools.Export_to_excel(UniQuery1, num_of_rows, num_of_fields, '������������� �������'); UniDataSource1.Enabled:= true; //�������� ����������� ������ ��� ��������� �������� except on E:Exception do begin MessageDlg('������ ��� �������� ������ � MS Excel! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); UniDataSource1.Enabled:= true; //�������� ����������� ������ (��� ����� ��-���������) end; end; end; //����� ���� ������ � ���� "����� ��" procedure TForm_main.ComboBox_doubleChange(Sender: TObject); begin if ComboBox_double.ItemIndex = 0 then // ����� � ���� "����� ��" �� "��������" Edit_double.Enabled:= true else Edit_double.Enabled:= false end; //����� ���� ������ � ���� "����������� ����������" procedure TForm_main.ComboBox_remarkChange(Sender: TObject); begin if ComboBox_remark.ItemIndex = 0 then // ����� � ���� "����������� ����������" �� "��������" Edit_remark.Enabled:= true else Edit_remark.Enabled:= false end; //����� ���� ������ � ���� "����������� ���, ����" procedure TForm_main.ComboBox_remark_ogv_omsuChange(Sender: TObject); begin if ComboBox_remark_ogv_omsu.ItemIndex = 0 then // ����� � ���� "����������� ���, ����" �� "��������" Edit_remark_ogv_omsu.Enabled:= true else Edit_remark_ogv_omsu.Enabled:= false end; procedure TForm_main.Button_changeClick(Sender: TObject); begin if id <> 0 then begin Form_change.Edit_object_duplicate.Text:= DBGrid1.DataSource.DataSet.FieldByName('����� ��').AsString; Form_change.Edit_remark.Text:= DBGrid1.DataSource.DataSet.FieldByName('���-� ����������').AsString; Form_change.Edit_remark_ogv_omsu.Text:= DBGrid1.DataSource.DataSet.FieldByName('����-� ���, ����').AsString; Form_change.ShowModal end else MessageDlg('�������� ������ ��� �����������!', mtInformation,[mbOK],0) end; procedure TForm_main.Button_connectClick(Sender: TObject); begin UniConnection1.ConnectDialog:= UniConnectDialog1; UniConnectDialog1.UseServerHistory:= false; // �� ������� ������ �������� //UniConnectDialog1.StoreLogInfo:= false; //�� ��������� ������ ������������� � ������� Windows ��� ����������� � ��. ���� �������� .../SOFTWARE/Devart/Unidac (����� ������� HKEY_CURRENT_USER, HKEY_USERS) Form_main.UniConnection1.Connect; // ����������� � ����� �� emp_id:= Get_emp_id(dept_no, dept_name); if emp_id <> 0 then begin Button_connect.Caption:= '����������'; Form_main.Caption:= Form_main.Caption + ', ������������: ' + ansiuppercase(Form_main.UniConnection1.Username) + ', ' + ansiuppercase(dept_name); Button_disconnect.Visible:= true; Button_connect.Enabled:= false; N_upd_exp.Enabled:= true; // ������ ���������� � �������� Panel_search.Enabled:= true; Panel_DBGrid.Enabled:= true; end else begin UniConnection1.Disconnect; MessageDlg('������������ ' + ansiuppercase(Form_main.UniConnection1.Username) + ' ����������� � ������� mfc_in_out_docs.mfc_rp_emps! ������ ��������, ���������� � ������������!', mtInformation,[mbOK],0); end; end; procedure TForm_main.Button_disconnectClick(Sender: TObject); begin UniConnection1.Disconnect; Button_connect.Caption:= '������������ � ��'; Form_main.Caption:= '���������� ��'; Button_disconnect.Visible:= false; Button_connect.Enabled:= true; Panel_search.Enabled:= false; Panel_DBGrid.Enabled:= false; N_upd_exp.Enabled:= false; // ������ ���������� � �������� end; //����� ������ procedure TForm_main.Button_findClick(Sender: TObject); begin id:= 0; Edit1.Clear; Form_main.Find_objects end; procedure TForm_main.DBGrid1CellClick(Column: TColumn); var status: Variant; begin Edit1.Text:= 'ID - ' + DBGrid1.DataSource.DataSet.FieldByName('id').AsString; id:= DBGrid1.DataSource.DataSet.FieldByName('id').AsInteger; status:= DBGrid1.DataSource.DataSet.FieldByName('������ ����-��').Value; if status = '�����' then Form_change.ComboBox_status.ItemIndex:= 0; if status = '��������' then Form_change.ComboBox_status.ItemIndex:= 1; if status = '����� ����������������' then Form_change.ComboBox_status.ItemIndex:= 2; if status = '���������������� ����� ��������� �������������' then Form_change.ComboBox_status.ItemIndex:= 3; if status = '��������' then Form_change.ComboBox_status.ItemIndex:= 4; if status = '�����' then Form_change.ComboBox_status.ItemIndex:= 5; if status = '�� ������� ������������� �����' then Form_change.ComboBox_status.ItemIndex:= 6; if status = '������� �������� � ���������������� �� 518-��' then Form_change.ComboBox_status.ItemIndex:= 7; if status = '��������������� �� �����������' then Form_change.ComboBox_status.ItemIndex:= 8; if status = '�������������� ���������� � ���������� ���������������' then Form_change.ComboBox_status.ItemIndex:= 9; if status = '� ������' then Form_change.ComboBox_status.ItemIndex:= 10; if status = '���� �� ���� �������' then Form_change.ComboBox_status.ItemIndex:= 11; if status = '����� ���������������� �� 518 ��' then Form_change.ComboBox_status.ItemIndex:= 12; if status = '������������ ��' then Form_change.ComboBox_status.ItemIndex:= 13; if status = '�������� �� �����������' then Form_change.ComboBox_status.ItemIndex:= 14; if status = '����������' then Form_change.ComboBox_status.ItemIndex:= 15; if status = '���������������� ��' then Form_change.ComboBox_status.ItemIndex:= 16; if status = '��������������� �������, �� �������� �� �������' then Form_change.ComboBox_status.ItemIndex:= 17; if status = '�����������' then Form_change.ComboBox_status.ItemIndex:= 18; if status = '����� ���������' then Form_change.ComboBox_status.ItemIndex:= 19; if status = '�� �� ��������� ��� 518-��, ���� ���' then Form_change.ComboBox_status.ItemIndex:= 20; Form_change.ComboBox_statusChange(nil); end; procedure TForm_main.FormCreate(Sender: TObject); begin Button_disconnect.Visible:= false; path_exe:= ExtractFilePath(Application.ExeName); Panel_search.Enabled:= false; Panel_DBGrid.Enabled:= false; N_upd_exp.Enabled:= false; // ������ ���������� � �������� end; procedure TForm_main.N_upd_expClick(Sender: TObject); begin Form_tools.ShowModal // ���������� � �������� end; procedure TForm_main.N4Click(Sender: TObject); begin Form_main.Close end; procedure TForm_main.UniConnection1Error(Sender: TObject; E: EDAError; var Fail: Boolean); begin if UniConnection1.InTransaction then Form_main.UniConnection1.Rollback; // ����� ����������, ���� ��� ������� Fail:= false; // ��� ����, ����� �� ������������ ����������� ��������� �� ������ Oracle case e.ErrorCode of 1017: MessageDlg('�������� �����/������! ������ ��������!', mtInformation,[mbOK],0); 28000: MessageDlg('������� ������������! ���������� � ������������!', mtInformation,[mbOK],0); 1031,942: // ������ � �������, ���� ����� �� �������, ��: 1) ����������� ������������ � ������� MFC_RP_EMPS 2) ������������ � ������� MFC_RP_EMPS ������, �� �� ������������� ���� MY_MFC_IN_OUT_DOCS_MAIN_ROLE begin UniConnection1.Disconnect; // ����������� �� ����� MessageDlg('������������ ����������! ��������� ������� ����������� ������������ "' + UniConnection1.Username + '" � ������� MONITORING_OBJECTS.M_EMPS � ��������������� ��� ���� ���� MY_MONITORING_OBJ_MAIN_ROLE! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end else begin Form_main.UniConnection1.Rollback; MessageDlg('������ ��� ��������� ������ � ��! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end; end; end; end.