/
dorofeev_denis
/
Monitoring_objects
Обзор
Документация
Войти
/
dorofeev_denis
/
Monitoring_objects
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Unit3.pas
774 строки
39 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 Unit3; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, MemDS, DBAccess, Uni, ComObj, ActiveX, Vcl.StdCtrls, UniDacVcl, Vcl.ComCtrls, UNIT_TEXT_FILES_AND_FOLDERS, Vcl.Grids, Vcl.Samples.Calendar, Vcl.Samples.Spin; type TForm_tools = class(TForm) Button_update_from_tir: TButton; UniQuery_upd_from_TIR: TUniQuery; Button_upload_to_ogv_omsu: TButton; ProgressBar1: TProgressBar; Label5: TLabel; DateTimePicker_from: TDateTimePicker; Label6: TLabel; DateTimePicker_to: TDateTimePicker; Button_statistika: TButton; Button_upload_from_ogv_omsu: TButton; OpenDialog1: TOpenDialog; GroupBox1: TGroupBox; Button_according_to_plan: TButton; ComboBox_according_to_plan: TComboBox; DateTimePicker_to_plan: TDateTimePicker; Label1: TLabel; Button_difference_status: TButton; GroupBox_with_54044: TGroupBox; Label2: TLabel; ComboBox_according_to_plan_with_54044: TComboBox; DateTimePicker_to_plan_with_54044: TDateTimePicker; Button_according_to_plan_with_54044: TButton; Edit_all: TEdit; Edit_start: TEdit; Label3: TLabel; Label4: TLabel; Button_load_status_rights_registered: TButton; Button_load_status_rosreestr_from_file: TButton; Button_load_status_archival: TButton; procedure Button_update_from_tirClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button_upload_to_ogv_omsuClick(Sender: TObject); procedure Export_to_excel(DataSet: TUniQuery; num_of_rows, num_of_fields: integer; sheet_name: string); procedure Button_statistikaClick(Sender: TObject); procedure Button_upload_from_ogv_omsuClick(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button_according_to_planClick(Sender: TObject); procedure Button_difference_statusClick(Sender: TObject); procedure Button_according_to_plan_with_54044Click(Sender: TObject); //procedure Button_update_from_FGIS_EGRNClick(Sender: TObject); procedure Button_load_status_rights_registeredClick(Sender: TObject); procedure Button_load_status_rosreestr_from_fileClick(Sender: TObject); procedure Button_load_status_archivalClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form_tools: TForm_tools; implementation uses Unit1; {$R *.dfm} procedure TForm_tools.Export_to_excel(DataSet: TUniQuery; num_of_rows, num_of_fields: integer; sheet_name: string); var i, j: integer; FData: Variant; FormatSettings : TFormatSettings; out_value: TDateTime; // ��� �������� ���������� �������������� �������� � ���� ��� �������� ������������� �������� � Excel i_progress_bar: integer; // ���������� ����� �������������� ������ num_cycle, k, ostatok, next_line: integer; exl, Column, Sheet, Range: OLEVariant; // � ������, ���� ���������� ��������� ��������, �� ��� ������������� �� ����������� //ls: DWORD; //date_format: string; begin try if num_of_rows <> 0 then if num_of_rows <= 1048576 then // ����������� ����� ������� � ����� ��� ���������� *.xlsx begin exl:= CreateOleObject('Excel.Application'); exl.DisplayAlerts:= true; //��������� ������� �� �������� ���������� MS Excel. �� ��������� ������� ���� � �������� �� ���������� ��������� exl.EnableEvents:= false; //���������� ������� Excel ��� ��������� ������ ���������� exl.WorkBooks.Add(-4167); //�������� ����� � ����� ����������� exl.WorkBooks[1] �� ��������� //exl.SheetsInNewWorkbook:= 1; // N - ���������� ������ (integer) //exl.Workbooks.Add('C:\������.xls'); //�������� ����� Sheet:= exl.WorkBooks[1].WorkSheets[1]; Sheet.Name:= sheet_name; //��������� ��� ���� ����� Column:= Sheet.Rows; Sheet.Columns.ColumnWidth:= 30; Column.Rows.Font.Size:= 10; Column.Rows.Font.Name:= 'Arial'; //��������� ��� ����� ����� Column.Rows[1].Font.Bold:= True; //������ ����� ������������ �������� //��������� ������ � ������������� ��������, ������ ������ � MS Excel ���������� � 1 if Form_tools.Button_according_to_plan.Enabled = false then // ���� ������ ������ �������� ���������� begin Sheet.Cells[1, 1]:= '�����'; Sheet.Cells[1, 2]:= '1. ����� �������� ���������� ���������'; Sheet.Cells[1, 3]:= '2. ������������ �������� ���������� ���������'; Sheet.Cells[1, 4]:= '3. ���������� ����� �������� �������� ������������, � ��������� ������� ��������� ��������� ����������� �� ��������� �� ����������������'; Sheet.Cells[1, 5]:= '4. �������� �������� �������� ������������ �� �������'; Sheet.Cells[1, 6]:= '5. ����������� �������� ����������� ����� � ������ ���������� ����� �� �����-�������'; Sheet.Cells[1, 7]:= '6. ���������� (��/���)'; Sheet.Cells[1, 8]:= '7. ���������� ��������, ��������������� ������� �������� � ������� � ����, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 9]:= '8. ���������� ��������, ������ � ������������ ����� �� ��������� ���� �������, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 10]:= '9. ���������� ��������, �� ������� ���������������� ����� ��������� �����, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 11]:= '10. ���������� ��������, ��������������� ������� �� �������� (����������� ��������������������, ������������������� ���������, ������ �� ��������������� �� ��������� � �.�.), �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 12]:= '11. ���������� ��������, ��������������� ������� ��������, �� �������� ������� �� ����������������, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 13]:= '12. ���������� ��������, � ��������� ������� ��������� ����������, ��������������� ������� 69.1 ������ � 218-��, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 14]:= '13. ���������� ��������, ������ �� ���������������� ������� � ��������� ������� �������� �������������� ����������, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 15]:= '14. ���������� ��������, �� ����������� ��� �������� ������ � 518-��, �������� � ������ �� ������� �����������, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 16]:= '15. ���������� ��������, �� ����������� ��� �������� ������ � 518-��, �� ����� �� ������� ���������������� � ����� ������� (�� ����� ��������� �����), �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 17]:= '16. ���������� ��������, ������ � ������������ ����� � ������ ����� �� ����������� �������� ���� (��������, ������������� ������� � �.�.), �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 18]:= '17. ���������� �������� � ������������� ������ � "������������ ��������" � ��� ������� ������������������ ����, ������������� �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 19]:= '17.1. ���������� ��������, ������������ �� ���� � �������� ����������� ���������� ����� � ������������ � ������ 20 ������ 69.1 ������ � 218-�� (�� ����� 5)'; Sheet.Cells[1, 20]:= '17.2. ���������� �������� (���������), � ��������� ������� � ���� ������� �������� �� ��������� �� � ������ ��������� � ������, ���������� � ������������ � ������ 23 ������ 69.1 ������ � 218-�� (�� ����� 5)'; Sheet.Cells[1, 21]:= '18. ���������� ��������� ��������, ��������������� ������������� �� ������� �� ������������, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 22]:= '19. ���������� ��������, ����������� � ������ ��������� (���������� ���������������� �������, ��� ���� ����� �� �������� ���� �� ��������,' + ' ���������� ������� ������� � ��������� ��������������� � �.�.), �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 23]:= '20. ���������� ��������, � ��������� ������� ������ ���������, �� �������� � ���������� ���������������� �� ������� � ���� �� ���� ��������, �� ��������� � ������ 10-14, 17-19, �� �������� ���� � ������ ���������� ����� �� �����-������� (�� ����� 5)'; Sheet.Cells[1, 24]:= '21. �������, �� ������� �������� � ���������������� �� ������� � ����, �� ��������� � ������ 10-14, 17-19 (�� ����� 21)'; end else for j:= 1 to num_of_fields do Sheet.Cells[1, j]:= DataSet.Fields[j-1].FieldName; // ������� � Fields ���������� � ���� num_cycle:= num_of_rows div 10000; // ���������� ������ ������� �� �������� 1000 ������� � Excel ostatok:= num_of_rows - 10000*num_cycle; //������� �� ������� �� �������� � 1000. ������� ����������� ��������. //������� ���������� ������ FData:= VarArrayCreate([1,10000,1,num_of_fields],varVariant); // ����������� ������������ ������ ��������� ���������� ������� FormatSettings:= TFormatSettings.Create('ru-RU'); // ���������� ������ ���������� � ����������������� ����������� // ������������� ������ ����������� ���� � ���������� �������� {ls:= exl.LanguageSettings.LanguageID[2]; // ��� ������ 2 ����� ������� msoLanguageIDUI if ls = 1049 then date_format:= '��.��.����' else date_format:= 'dd/mm/yyyy'; exl.WorkBooks[1].WorkSheets[1].Columns[9].NumberFormat:= AnsiString(date_format); exl.WorkBooks[1].WorkSheets[1].Columns[10].NumberFormat:= AnsiString(date_format); exl.WorkBooks[1].WorkSheets[1].Columns[11].NumberFormat:= AnsiString(date_format); } //��������� ������ ������� �� UniQuery1 �� 1000 ����� next_line:= 2; //�������������� ������ Excel, ���� ��������� ������ i_progress_bar:= 0; DataSet.First; for k:= 1 to num_cycle do // � ��� ������, ���� ����� �������� num_cycle = 0, �� � ���� �� �����, ����� ��������� ������ ������� begin for i:= 1 to 10000 do begin for j:=1 to VarArrayHighBound(FData,2) do if TryStrToDate(DataSet.Fields[j-1].AsString, out_value, FormatSettings) = true then // TryStrToDateTime � ������ ���������� ���� � ������ ���������� ��� ����, � �� ������!!! if out_value >= StrToDateTime('01.01.1900') then // Excel �� �������� ���� ������ XX ���� FData[i,j]:= DataSet.Fields[j-1].AsDateTime else FData[i,j]:= DataSet.Fields[j-1].AsWideString else FData[i,j]:= DataSet.Fields[j-1].AsWideString; ProgressBar1.Position:= round(i_progress_bar/num_of_rows*100); Form_main.Main_ProgressBar.Position:= ProgressBar1.Position; DataSet.Next; i_progress_bar:= i_progress_bar + 1; end; //�������� �������� ��� ������� ������ Range:= Sheet.Range[Sheet.Cells[next_line,1],Sheet.Cells[next_line+9999,VarArrayHighBound(FData,2)]]; // +1 - ��-�� ������ ������������ �������� �������� ��������� �� 1 ������ ���� Range.Value:= FData; next_line:= 10000*k + 2; //����� ������� ������, � ������� ��������� ��������� ������ ����� //last_line:= next_line+999 end; for i:= 1 to ostatok do begin for j:=1 to VarArrayHighBound(FData,2) do if TryStrToDate(DataSet.Fields[j-1].AsString, out_value, FormatSettings) = true then if out_value >= StrToDateTime('01.01.1900') then // Excel �� �������� ���� ������ XX ���� FData[i,j]:= DataSet.Fields[j-1].AsDateTime else FData[i,j]:= DataSet.Fields[j-1].AsWideString else FData[i,j]:= DataSet.Fields[j-1].AsWideString; ProgressBar1.Position:= round(i_progress_bar/num_of_rows*100); Form_main.Main_ProgressBar.Position:= ProgressBar1.Position; DataSet.Next; i_progress_bar:= i_progress_bar + 1; end; Range:= Sheet.Range[Sheet.Cells[next_line,1],Sheet.Cells[next_line+ostatok-1,VarArrayHighBound(FData,2)]]; // +1 - ��-�� ������ ������������ �������� �������� ��������� �� 1 ������ ���� Range.Value:= FData; //Raise Exception.Create('������'); ��� ������� ���� � ������ ��������� ������ exl.EnableEvents:= true; //��������� ������� Excel exl.Visible:= true; //���������� Excel ProgressBar1.Position:= 0; Form_main.Main_ProgressBar.Position:= 0; end else MessageDlg('���������� ������������ ������� �� ������� ��������� 1 048 576! ���������� ����������� �������� �� ������� ������!', mtInformation, [mbOk], 0) else MessageDlg('��������� � ���� �� �������!', mtInformation, [mbOk], 0); except on E:Exception do // � ������ ������������� ����� ������ � �������� ��������� ������� � �������� � Excel begin exl.Visible:= false; // �������� Excel ��� ��� �������� exl.EnableEvents:= false; exl.DisplayAlerts:= false; exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel Column:= Unassigned; Sheet:= Unassigned; Range:= Unassigned; end; end; end; // �������� �������� ���������� �������� procedure TForm_tools.Button_load_status_archivalClick(Sender: TObject); var cadastral_number, status, full_file_name, file_name: string; exl, FData: OLEVariant; i, num_of_rows_excel, sql_num_of_rows: integer; update_status_log: TextFile; //��� ������ begin //�������� �������� ���� ������ Create_Directory(path_exe, '\LOG'); full_file_name:= path_exe + '\LOG\' + '����������_��������_��_��������_' + GetLogFileName(now) + '.log'; Create_Text_File(update_status_log, full_file_name); //�������� ����� ���� ������ if OpenDialog1.Execute = true then //���������������� ��� ������� ������� begin file_name:= ExtractFileName(OpenDialog1.FileName); // ��� ����� � ����������� if not Form_main.UniConnection1.InTransaction then Form_main.UniConnection1.StartTransaction; try exl:= CreateOleObject('Excel.Application'); exl.Visible:= false; exl.DisplayAlerts:= false; exl.EnableEvents:= false; exl.WorkBooks.Open(OpenDialog1.FileName); FData:= exl.WorkBooks[1].WorkSheets[1].UsedRange.Value; //��������� ������ ����� ��������� � ���������� ������ ProgressBar1.Position:= 0; num_of_rows_excel:= exl.WorkBooks[1].WorkSheets[1].UsedRange.Rows.Count; //����� ������������ ����� �� ����� Edit_all.Text:= IntToStr(num_of_rows_excel); // ����� ����� �������������� ����� ����� ��������� for i:= 1 to num_of_rows_excel do // ��� ����� ��������� (��������� � ����������� ��������) begin Edit_start.Text:= IntToStr(i); cadastral_number:= FData[i,1]; cadastral_number:= trim(cadastral_number); status:= FData[i,2]; status:= trim(status); UniQuery_upd_from_TIR.SQL.Clear; //��������� ������� �� � �� � ��� ������ UniQuery_upd_from_TIR.SQL.Add('select o.status from monitoring_objects.m_obj o where o.cadastral_number = :cadastral_number'); UniQuery_upd_from_TIR.ParamByName('cadastral_number').AsString:= cadastral_number; UniQuery_upd_from_TIR.Execute; sql_num_of_rows:= UniQuery_upd_from_TIR.RecordCount; if (sql_num_of_rows <> 0) and (UniQuery_upd_from_TIR.Fields[0].AsString <> '��������') and (UniQuery_upd_from_TIR.Fields[0].AsString <> '���� �� ���� �������') and (status = '��������') then // �� ������ � ��, �� ����������, ����� ������ ��� ��������� begin UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + '\FILES_LOAD\' + '���������� ������� ��������.sql'); UniQuery_upd_from_TIR.ParamByName('cadastral_number').AsString:= cadastral_number; UniQuery_upd_from_TIR.ParamByName('updated_by').AsInteger:= emp_id; UniQuery_upd_from_TIR.ParamByName('updated_file').AsString:= file_name; UniQuery_upd_from_TIR.Execute; Write_Text_File(update_status_log, full_file_name, '������ �������: ' + chr(9) + '"' + cadastral_number + '"' + chr(9) + '"' + '��������' + '"'); // chr(9) ���� ��������� � ������ end; ProgressBar1.Position:= round(i/(num_of_rows_excel)*100); Application.ProcessMessages; end; Form_main.UniConnection1.Commit; // ���������� �������� ��������� ������ ����� ��������� ���� ������� MessageDlg('���������� �������� ���������� ���������! ������� "��" � �������� ������� ������...', mtInformation,[mbOK],0); exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel FData:= Unassigned; MessageDlg('������� ������ ���������!', mtInformation,[mbOK],0); except on E:Exception do begin exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel FData:= Unassigned; Form_main.UniConnection1.Rollback; ProgressBar1.Position:= 0; Write_Text_File(update_status_log, full_file_name, '������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message); MessageDlg('������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end end; end; end; // �������� �������� ���������� ����� ����������������/���������������� ����� ��������� ������������� procedure TForm_tools.Button_load_status_rights_registeredClick(Sender: TObject); var cadastral_number, full_file_name, status, file_name, subject_type: string; exl, FData: OLEVariant; i, num_of_rows_excel, sql_num_of_rows: integer; update_status_log: TextFile; //��� ������ begin //�������� �������� ���� ������ Create_Directory(path_exe, '\LOG'); full_file_name:= path_exe + '\LOG\' + '����������_��������_��_�����_����������������_' + GetLogFileName(now) + '.log'; Create_Text_File(update_status_log, full_file_name); //�������� ����� ���� ������ if OpenDialog1.Execute = true then //���������������� ��� ������� ������� begin file_name:= ExtractFileName(OpenDialog1.FileName); // ��� ����� � ����������� if not Form_main.UniConnection1.InTransaction then Form_main.UniConnection1.StartTransaction; try exl:= CreateOleObject('Excel.Application'); exl.Visible:= false; exl.DisplayAlerts:= false; exl.EnableEvents:= false; exl.WorkBooks.Open(OpenDialog1.FileName); FData:= exl.WorkBooks[1].WorkSheets[1].UsedRange.Value; //��������� ������ ����� ��������� � ���������� ������ ProgressBar1.Position:= 0; num_of_rows_excel:= exl.WorkBooks[1].WorkSheets[1].UsedRange.Rows.Count; //����� ������������ ����� �� ����� Edit_all.Text:= IntToStr(num_of_rows_excel); // ����� ����� �������������� ����� ����� ��������� for i:= 1 to num_of_rows_excel do // ��� ����� ��������� (��������� � ����������� ��������) begin Edit_start.Text:= IntToStr(i); cadastral_number:= FData[i,1]; cadastral_number:= trim(cadastral_number); subject_type:= FData[i,2]; subject_type:= trim(subject_type); UniQuery_upd_from_TIR.SQL.Clear; //��������� ������� �� � �� � ��� ������ UniQuery_upd_from_TIR.SQL.Add('select o.status from monitoring_objects.m_obj o where o.cadastral_number = :cadastral_number'); UniQuery_upd_from_TIR.ParamByName('cadastral_number').AsString:= cadastral_number; UniQuery_upd_from_TIR.Execute; sql_num_of_rows:= UniQuery_upd_from_TIR.RecordCount; if (sql_num_of_rows <> 0) and (UniQuery_upd_from_TIR.Fields[0].AsString <> '����� ����������������') and (UniQuery_upd_from_TIR.Fields[0].AsString <> '���������������� ����� ��������� �������������') and (UniQuery_upd_from_TIR.Fields[0].AsString <> '����� ���������������� �� 518 ��') and (UniQuery_upd_from_TIR.Fields[0].AsString <> '�����������') then // �� ������ � ��, �� ����������, ����� ������ ��� ��������� begin UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + '\FILES_LOAD\' + '���������� ������� ����� �����-��_�����. ����� ������-� �����-��.sql'); if (pos('������������� �����������', subject_type) <> 0) or (pos('��������-�������� �����������', subject_type) <> 0) or (pos('���������� ���������', subject_type) <> 0) or (pos('������� ���������� ���������', subject_type) <> 0) or (pos('����, ����, ����', subject_type) <> 0) then begin status:= '���������������� ����� ��������� �������������'; UniQuery_upd_from_TIR.ParamByName('status').AsString:= status; end else begin status:= '����� ����������������'; UniQuery_upd_from_TIR.ParamByName('status').AsString:= status; end; UniQuery_upd_from_TIR.ParamByName('cadastral_number').AsString:= cadastral_number; UniQuery_upd_from_TIR.ParamByName('updated_by').AsInteger:= emp_id; UniQuery_upd_from_TIR.ParamByName('updated_file').AsString:= file_name; UniQuery_upd_from_TIR.Execute; Write_Text_File(update_status_log, full_file_name, '������ �������: ' + chr(9) + '"' + cadastral_number + '"' + chr(9) + '"' + status + '"'); // chr(9) ���� ��������� � ������ end; ProgressBar1.Position:= round(i/(num_of_rows_excel)*100); Application.ProcessMessages; end; Form_main.UniConnection1.Commit; // ���������� �������� ��������� ������ ����� ��������� ���� ������� MessageDlg('���������� �������� ���������� ���������! ������� "��" � �������� ������� ������...', mtInformation,[mbOK],0); exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel FData:= Unassigned; MessageDlg('������� ������ ���������!', mtInformation,[mbOK],0); except on E:Exception do begin exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel FData:= Unassigned; Form_main.UniConnection1.Rollback; ProgressBar1.Position:= 0; Write_Text_File(update_status_log, full_file_name, '������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message); MessageDlg('������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end end; end; end; procedure TForm_tools.Button_update_from_tirClick(Sender: TObject); begin //UniConnection_upd_from_TIR.Connect; // ����������� � ����� �� if not Form_main.UniConnection1.InTransaction then Form_main.UniConnection1.StartTransaction; try Button_update_from_tir.Caption:= '���������� ����������, ��������...'; UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\' + '���������� ������� � ������������ � ������� ��� (����������).sql'); UniQuery_upd_from_TIR.Execute; Form_main.UniConnection1.Commit; // ���������� �������� ��������� ������ ����� �������� ���� ����������� ��� 1 ������ Button_update_from_tir.Caption:= '������ ���������'; Button_update_from_tir.Enabled:= false; Form_main.UniConnection1.Disconnect; except on E:Exception do begin Form_main.UniConnection1.Rollback; Form_main.UniConnection1.Disconnect; Button_update_from_tir.Caption:= '�������� ������ �� ���'; MessageDlg('������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end; end; end; procedure TForm_tools.Button_upload_to_ogv_omsuClick(Sender: TObject); var num_of_rows, num_of_fields: integer; s: string; begin try //Form_main.UniConnection1.Connect; // ����������� � ����� �� UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\' + '�������� � ������������.sql'); UniQuery_upd_from_TIR.ParamByName('date_start').AsDate:= DateTimePicker_from.Date; UniQuery_upd_from_TIR.ParamByName('date_finish').AsDate:= DateTimePicker_to.Date; UniQuery_upd_from_TIR.Execute; num_of_rows:= UniQuery_upd_from_TIR.RecordCount; num_of_fields:= UniQuery_upd_from_TIR.FieldCount; s:= DateToStr(DateTimePicker_from.Date) + ' - ' + DateToStr(DateTimePicker_to.Date); Export_to_excel(UniQuery_upd_from_TIR, num_of_rows, num_of_fields, s); //Form_main.UniConnection1.Disconnect; // ����������� �� ����� �� except on E:Exception do MessageDlg('������ ��� �������� ������ � MS Excel! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end; end; // (������ <> ��������) � ����-� ��� ���� �������� "����" procedure TForm_tools.Button1Click(Sender: TObject); var num_of_rows, num_of_fields: integer; begin try UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\' + '������ �� �������� � ����-� ������� �������� ����.sql'); UniQuery_upd_from_TIR.Execute; num_of_rows:= UniQuery_upd_from_TIR.RecordCount; num_of_fields:= UniQuery_upd_from_TIR.FieldCount; Export_to_excel(UniQuery_upd_from_TIR, num_of_rows, num_of_fields, '�� �������� + ���_���� ����'); except on E:Exception do MessageDlg('������ ��� �������� ������ � MS Excel! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end; end; //����� ���������� (� 54044 ��) procedure TForm_tools.Button_according_to_plan_with_54044Click(Sender: TObject); var num_of_rows, num_of_fields: integer; s: string; begin try Button_according_to_plan.Enabled:= false; UniQuery_upd_from_TIR.SQL.Clear; if ComboBox_according_to_plan_with_54044.ItemIndex = 0 then // ������ UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\����������\' + '����� ���������� ���������������� (������) � 54044 ��.sql') else // �� UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\����������\' + '����� ���������� ���������������� (��) � 54044 ��.sql'); UniQuery_upd_from_TIR.ParamByName('date_start').AsDate:= DateTimePicker_to_plan.Date; UniQuery_upd_from_TIR.Execute; num_of_rows:= UniQuery_upd_from_TIR.RecordCount; num_of_fields:= UniQuery_upd_from_TIR.FieldCount; s:= '����� ���������� �� ' + DateToStr(DateTimePicker_to_plan.Date); Export_to_excel(UniQuery_upd_from_TIR, num_of_rows, num_of_fields, s); Button_according_to_plan.Enabled:= true; except on E:Exception do begin MessageDlg('������ ��� �������� ������ � MS Excel! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); Button_according_to_plan.Enabled:= true; end; end; end; //�������� �������� ���������� �� ����� procedure TForm_tools.Button_load_status_rosreestr_from_fileClick(Sender: TObject); var cadastral_number, status, full_file_name, file_name: string; exl, FData: OLEVariant; i, num_of_rows_excel, sql_num_of_rows: integer; update_status_log: TextFile; //��� ������ begin //�������� �������� ���� ������ Create_Directory(path_exe, '\LOG'); full_file_name:= path_exe + '\LOG\' + '����������_��������_����������_��_�����_' + GetLogFileName(now) + '.log'; Create_Text_File(update_status_log, full_file_name); //�������� ����� ���� ������ if OpenDialog1.Execute = true then //���������������� ��� ������� ������� begin file_name:= ExtractFileName(OpenDialog1.FileName); // ��� ����� � ����������� if not Form_main.UniConnection1.InTransaction then Form_main.UniConnection1.StartTransaction; try exl:= CreateOleObject('Excel.Application'); exl.Visible:= false; exl.DisplayAlerts:= false; exl.EnableEvents:= false; exl.WorkBooks.Open(OpenDialog1.FileName); FData:= exl.WorkBooks[1].WorkSheets[1].UsedRange.Value; //��������� ������ ����� ��������� � ���������� ������ ProgressBar1.Position:= 0; num_of_rows_excel:= exl.WorkBooks[1].WorkSheets[1].UsedRange.Rows.Count; //����� ������������ ����� �� ����� Edit_all.Text:= IntToStr(num_of_rows_excel); // ����� ����� �������������� ����� ����� ��������� for i:= 1 to num_of_rows_excel do // ��� ����� ��������� (��������� � ����������� ��������) begin Edit_start.Text:= IntToStr(i); cadastral_number:= FData[i,1]; cadastral_number:= trim(cadastral_number); status:= FData[i,2]; status:= trim(status); UniQuery_upd_from_TIR.SQL.Clear; //��������� ������� �� � �� � ��� ������ UniQuery_upd_from_TIR.SQL.Add('select o.status from monitoring_objects.m_obj o where o.cadastral_number = :cadastral_number'); UniQuery_upd_from_TIR.ParamByName('cadastral_number').AsString:= cadastral_number; UniQuery_upd_from_TIR.Execute; sql_num_of_rows:= UniQuery_upd_from_TIR.RecordCount; if (sql_num_of_rows <> 0) and (UniQuery_upd_from_TIR.Fields[0].AsString <> status) then // ������� �� ���� � �� � ��� ������ ���������� �� ����, ��� � �����, ����� ��������� ������ begin UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + '\FILES_LOAD\' + '���������� �������� ���������� �� �����.sql'); UniQuery_upd_from_TIR.ParamByName('cadastral_number').AsString:= cadastral_number; UniQuery_upd_from_TIR.ParamByName('status').AsString:= status; UniQuery_upd_from_TIR.ParamByName('updated_by').AsInteger:= emp_id; UniQuery_upd_from_TIR.ParamByName('updated_file').AsString:= file_name; UniQuery_upd_from_TIR.Execute; Write_Text_File(update_status_log, full_file_name, '������ �������: ' + chr(9) + '"' + cadastral_number + '"' + chr(9) + '"' + status + '"'); // chr(9) ���� ��������� � ������ end; ProgressBar1.Position:= round(i/(num_of_rows_excel)*100); Application.ProcessMessages; end; Form_main.UniConnection1.Commit; // ���������� �������� ��������� ������ ����� ��������� ���� ������� MessageDlg('���������� �������� ���������� ���������! ������� "��" � �������� ������� ������...', mtInformation,[mbOK],0); exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel FData:= Unassigned; MessageDlg('������� ������ ���������!', mtInformation,[mbOK],0); except on E:Exception do begin exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel FData:= Unassigned; Form_main.UniConnection1.Rollback; ProgressBar1.Position:= 0; Write_Text_File(update_status_log, full_file_name, '������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message); MessageDlg('������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end end; end; end; //����� ���������� (��� 54044 ��) procedure TForm_tools.Button_according_to_planClick(Sender: TObject); var num_of_rows, num_of_fields: integer; s: string; begin try Button_according_to_plan.Enabled:= false; UniQuery_upd_from_TIR.SQL.Clear; if ComboBox_according_to_plan.ItemIndex = 0 then // ������ UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\����������\��� 54044 ��\' + '����� ���������� ���������������� (������) ��� 54044 ��.sql') else // �� UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\����������\��� 54044 ��\' + '����� ���������� ���������������� (��) ��� 54044 ��.sql'); UniQuery_upd_from_TIR.ParamByName('date_start').AsDate:= DateTimePicker_to_plan.Date; UniQuery_upd_from_TIR.Execute; num_of_rows:= UniQuery_upd_from_TIR.RecordCount; num_of_fields:= UniQuery_upd_from_TIR.FieldCount; s:= '����� ���������� �� ' + DateToStr(DateTimePicker_to_plan.Date); Export_to_excel(UniQuery_upd_from_TIR, num_of_rows, num_of_fields, s); Button_according_to_plan.Enabled:= true; except on E:Exception do begin MessageDlg('������ ��� �������� ������ � MS Excel! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); Button_according_to_plan.Enabled:= true; end; end; end; procedure TForm_tools.Button_difference_statusClick(Sender: TObject); var num_of_rows, num_of_fields: integer; begin try //Form_main.UniConnection1.Connect; // ����������� � ����� �� UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\' + '������������� ������� ���������� � ��.sql'); UniQuery_upd_from_TIR.Execute; num_of_rows:= UniQuery_upd_from_TIR.RecordCount; num_of_fields:= UniQuery_upd_from_TIR.FieldCount; Export_to_excel(UniQuery_upd_from_TIR, num_of_rows, num_of_fields, '������������� �������'); //Form_main.UniConnection1.Disconnect; except on E:Exception do MessageDlg('������ ��� �������� ������ � MS Excel! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end; end; procedure TForm_tools.Button_statistikaClick(Sender: TObject); var num_of_rows, num_of_fields: integer; begin try //Form_main.UniConnection1.Connect; // ����������� � ����� �� UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\' + '���������� �� �������� ��.sql'); UniQuery_upd_from_TIR.Execute; num_of_rows:= UniQuery_upd_from_TIR.RecordCount; num_of_fields:= UniQuery_upd_from_TIR.FieldCount; Export_to_excel(UniQuery_upd_from_TIR, num_of_rows, num_of_fields, '����������'); //Form_main.UniConnection1.Disconnect; except on E:Exception do MessageDlg('������ ��� �������� ������ � MS Excel! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end; end; //�������� ������ �� ������������ procedure TForm_tools.Button_upload_from_ogv_omsuClick(Sender: TObject); var cadastral_number, status_ogv_omsu, remark_ogv_omsu, file_name: string; exl, FData: OLEVariant; i, num_of_rows_excel, sql_num_of_rows: integer; update_status_ogv_omsu_log: TextFile; //��� ������ begin //�������� �������� ���� ������ Create_Directory(path_exe, '\LOG'); file_name:= path_exe + '\LOG\' + '����������_��������_���_����_' + GetLogFileName(now) + '.log'; Create_Text_File(update_status_ogv_omsu_log, file_name); //�������� ����� ���� ������ if OpenDialog1.Execute = true then //���������������� ��� ������� ������� begin if not Form_main.UniConnection1.InTransaction then Form_main.UniConnection1.StartTransaction; try exl:= CreateOleObject('Excel.Application'); exl.EnableEvents:= false; exl.WorkBooks.Open(OpenDialog1.FileName); if exl.WorkBooks[1].WorkSheets[1].Cells[1,1].Value <> 'ID �� � ��' then MessageDlg('�������� ��������� �����! ���������� � ������������!', mtInformation,[mbOK],0) else begin num_of_rows_excel:= exl.WorkBooks[1].WorkSheets[1].UsedRange.Rows.Count; //����� ������������ ����� � ����� FData:= exl.WorkBooks[1].WorkSheets[1].UsedRange.Value; //��������� ������ ����� ��������� Edit_all.Text:= IntToStr(num_of_rows_excel); ProgressBar1.Position:= 0; for i:= 1 to num_of_rows_excel do // ��� ����� ��������� (��������� � ����������� ��������) begin Edit_start.Text:= IntToStr(i); cadastral_number:= FData[i,3]; cadastral_number:= trim(cadastral_number); status_ogv_omsu:= FData[i,4]; status_ogv_omsu:= trim(status_ogv_omsu); remark_ogv_omsu:= FData[i,6]; remark_ogv_omsu:= trim(remark_ogv_omsu); UniQuery_upd_from_TIR.SQL.Clear; // ���������� ������ ��� ���� � �� UniQuery_upd_from_TIR.SQL.Add('select o.status_ogv_omsu from monitoring_objects.m_obj o where o.cadastral_number = :cadastral_number'); UniQuery_upd_from_TIR.ParamByName('cadastral_number').AsString:= cadastral_number; UniQuery_upd_from_TIR.Execute; sql_num_of_rows:= UniQuery_upd_from_TIR.RecordCount; if sql_num_of_rows = 0 then // ������ ���������� ������ ���������, ���������� �� �� ������������ Write_Text_File(update_status_ogv_omsu_log, file_name, '���������� �� (��������� ������� ������� �������� � ������):' + chr(9) + cadastral_number) else if (UniQuery_upd_from_TIR.Fields[0].AsString <> status_ogv_omsu) or (UniQuery_upd_from_TIR.Fields[0].AsVariant = null) then // ������ ���, ���� �� ����� ���� �� ��������� �� �������� ���,���� �� ����� ���� � ����� �� �������� ��� �� ���������, ����� ������ ��������� begin UniQuery_upd_from_TIR.SQL.Clear; UniQuery_upd_from_TIR.SQL.LoadFromFile(path_exe + 'FILES_LOAD\' + '���������� ������� ���, ����.sql'); UniQuery_upd_from_TIR.ParamByName('cadastral_number').AsString:= cadastral_number; UniQuery_upd_from_TIR.ParamByName('status_ogv_omsu').AsString:= status_ogv_omsu; UniQuery_upd_from_TIR.ParamByName('updated_file_ogv_omsu').AsString:= ExtractFileName(OpenDialog1.FileName); UniQuery_upd_from_TIR.ParamByName('updated_by_ogv_omsu').AsInteger:= emp_id; UniQuery_upd_from_TIR.ParamByName('remark_ogv_omsu').AsString:= remark_ogv_omsu; UniQuery_upd_from_TIR.Execute; Write_Text_File(update_status_ogv_omsu_log, file_name, '������ �������:' + chr(9) + '"' + cadastral_number + '"' + chr(9) + '"' + status_ogv_omsu + '"'); // chr(9) ���� ��������� � ������ end; ProgressBar1.Position:= round(i/(num_of_rows_excel)*100); Application.ProcessMessages; end; Form_main.UniConnection1.Commit; // ���������� �������� ��������� ������ ����� �������� ���� ������� MessageDlg('�������� ���������!', mtInformation,[mbOK],0); end; exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel FData:= Unassigned; except on E:Exception do begin exl.Quit; //��������� Excel � ��������� ��� �� ������ Windows exl:= Unassigned; // ����������� ���������� Excel Form_main.UniConnection1.Rollback; ProgressBar1.Position:= 0; Write_Text_File(update_status_ogv_omsu_log, file_name, '������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message); MessageDlg('������ ��� ���������� ������ � ��! ��������� �� ������: ' + e.Message, mtInformation,[mbOK],0); end end end; end; procedure TForm_tools.FormCreate(Sender: TObject); begin Button_update_from_tir.Enabled:= true; DateTimePicker_from.DateTime:= now; // ������� ���� DateTimePicker_to.Date:= now; DateTimePicker_to_plan.Date:= now; DateTimePicker_to_plan_with_54044.Date:= now; end; end.