MainFrm.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. unit MainFrm;
  2. interface
  3. uses
  4. // Uses Units Please Try This Category
  5. // View
  6. ProjectManagerFme, ProjectFme, ProjectPropertiesFrm, OptionFrm, AboutFrm,
  7. AuthFrm,
  8. // Model & Data & Data Control ...
  9. ProjectData, SupportUnit, Globals, ZhAPI, ExcelImport, ConditionalDefines,
  10. // Controls & Delphi Default ... (Almost By Add Controls)
  11. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  12. Dialogs, cxGraphics, JimPages, ComCtrls, dxStatusBar, cxControls, JimTabs,
  13. dxBar, ImgList, UtilMethods, ZjDbaActns, ActnList, XPStyleActnCtrls, ActnMan,
  14. dxBarExtItems, sdDB, ExtCtrls, jpeg, StdCtrls, CslLabel, pngimage;
  15. type
  16. TMainForm = class(TForm)
  17. dxBarManager: TdxBarManager;
  18. Images: TImageList;
  19. dxsiFile: TdxBarSubItem;
  20. jtsProjects: TJimTabSet;
  21. dxStatusBar: TdxStatusBar;
  22. dxStatusBarContainer2: TdxStatusBarContainerControl;
  23. ProgressBar: TProgressBar;
  24. jpsMain: TJimPages;
  25. jpsMainProjectsManager: TJimPage;
  26. jpsMainProjects: TJimPage;
  27. jpsProjects: TJimPages;
  28. dxsiEdit: TdxBarSubItem;
  29. dxsiHelp: TdxBarSubItem;
  30. dxbtnCopy: TdxBarButton;
  31. dxbtnPaste: TdxBarButton;
  32. dxbtnCut: TdxBarButton;
  33. dxbtnInsert: TdxBarButton;
  34. dxbtnDelete: TdxBarButton;
  35. dxbtnUpMove: TdxBarButton;
  36. dxbtnDownMove: TdxBarButton;
  37. dxbtnUpLevel: TdxBarButton;
  38. dxbtnDownLevel: TdxBarButton;
  39. dxbtnAuthorizeDog: TdxBarButton;
  40. dxbtnAbout: TdxBarButton;
  41. dxbtnNewProject: TdxBarButton;
  42. dxbtnOpenProject: TdxBarButton;
  43. dxbtnDeleteProject: TdxBarButton;
  44. ActionManager1: TActionManager;
  45. ZjDbaInsert: TZjDbaInsert;
  46. ZjDbaDelete: TZjDbaDelete;
  47. ZjDbaUpMove: TZjDbaUpMove;
  48. ZjDbaDownMove: TZjDbaDownMove;
  49. ZjTreeDbaUpLevel: TZjTreeDbaUpLevel;
  50. ZjTreeDbaDownLevel: TZjTreeDbaDownLevel;
  51. ZjGridCopy: TZjGridCopy;
  52. ZjGridPaste: TZjGridPaste;
  53. ZjGridCut: TZjGridCut;
  54. ZjGridRemapedPaste: TZjGridRemapedPaste;
  55. dxpmTabSet: TdxBarPopupMenu;
  56. dxbtnCloseProject: TdxBarButton;
  57. actnCloseProject: TAction;
  58. dxbtnNewPhase: TdxBarButton;
  59. dxbtnCalculateLedger: TdxBarButton;
  60. actnNewPhase: TAction;
  61. dxbtnProjectProperties: TdxBarButton;
  62. actnProjectProperties: TAction;
  63. dxbtnSaveProject: TdxBarButton;
  64. actnSaveProject: TAction;
  65. dxbtnRemapedPaste: TdxBarButton;
  66. dxbtnImportExcel: TdxBarButton;
  67. actnImportExcel: TAction;
  68. dxbtnNewAudit: TdxBarButton;
  69. dxbtnCopyBillsBlock: TdxBarButton;
  70. actnNewAudit: TAction;
  71. dxbtnFinalAudit: TdxBarButton;
  72. dxbtnSubmitProject: TdxBarButton;
  73. dxbtnReceiveProject: TdxBarButton;
  74. dxbtnReplyProject: TdxBarButton;
  75. dxbtnAcceptProject: TdxBarButton;
  76. dxbtnCalculateAll: TdxBarButton;
  77. dxbtnNewSubProject: TdxBarButton;
  78. dxbtnNewTender: TdxBarButton;
  79. dxbtnOptions: TdxBarButton;
  80. actnOptions: TAction;
  81. dxbtnCalculatePhasePay: TdxBarButton;
  82. actnSubmit: TAction;
  83. actnReply: TAction;
  84. dxbtnSubmit: TdxBarButton;
  85. dxbtnReply: TdxBarButton;
  86. dxbtnFirstLevel: TdxBarButton;
  87. dxbtnSecondLevel: TdxBarButton;
  88. dxbtnThirdLevel: TdxBarButton;
  89. dxbtnFourthLevel: TdxBarButton;
  90. dxbtnFifthLevel: TdxBarButton;
  91. dxbtnAllLevel: TdxBarButton;
  92. dxbtnAllXmj: TdxBarButton;
  93. dxbtnExportGridToExcel: TdxBarButton;
  94. dxbtnRefresh: TdxBarButton;
  95. dxbtnUnlockInfo: TdxBarButton;
  96. actnUnlockInfo: TAction;
  97. dxUser: TdxBarSubItem;
  98. pnlUser: TPanel;
  99. lblAccount: TLabel;
  100. lblCompany: TLabel;
  101. lblRole: TLabel;
  102. dxLoginCloud: TdxBarButton;
  103. dxManageAccount: TdxBarButton;
  104. pnl1: TPanel;
  105. imgUserImage: TImage;
  106. lblMail: TLabel;
  107. dxUserContainer: TdxBarControlContainerItem;
  108. dxbtnBatchAddChild: TdxBarButton;
  109. dxbtnBatchAddNext: TdxBarButton;
  110. dxbtnReorderChildrenCode: TdxBarButton;
  111. dxbtnImportBillsPrice: TdxBarButton;
  112. dxsiImportExcel: TdxBarSubItem;
  113. dxbtnImportDealBills: TdxBarButton;
  114. actnImportBillsPrice: TAction;
  115. actnImportDealBills: TAction;
  116. dxbtnBatchReplaceBillsInfo: TdxBarButton;
  117. tAutoSave: TTimer;
  118. dxsiExportExcel: TdxBarSubItem;
  119. dxbtnExportExcel: TdxBarButton;
  120. actnExportExcel: TAction;
  121. dxbtnCurPhase: TdxBarButton;
  122. dxSync: TdxBarButton;
  123. dxbtnBatchWritePos_Reason: TdxBarButton;
  124. dxbtnExportCloudTenderFile: TdxBarButton;
  125. actnExportCloudTenderFile: TAction;
  126. dxtbnImportCloudTenderFile: TdxBarButton;
  127. actnImportCloudTenderFile: TAction;
  128. dxbtnCheckAndClear: TdxBarButton;
  129. dxbtnModifyDealBills: TdxBarButton;
  130. dxbtnLocateBills: TdxBarButton;
  131. dxbtnOpenBackupFolder: TdxBarButton;
  132. dxbtnSetBookmark: TdxBarButton;
  133. dxbtnExportFxBillsExcel: TdxBarButton;
  134. actnExportFxBillsExcel: TAction;
  135. dxseBatchInsert: TdxBarSpinEdit;
  136. actnBatchInsert: TAction;
  137. dxbtnRename: TdxBarButton;
  138. dxbtnImportGclBillsToXmj: TdxBarButton;
  139. dxbtnChangeDealBillsMode: TdxBarButton;
  140. dxsiExpandTo: TdxBarSubItem;
  141. dxbtnLocateBookmark: TdxBarButton;
  142. dxbtnImportPlaneFxBillsToXmj: TdxBarButton;
  143. dxbtnAllPeg: TdxBarButton;
  144. dxsiData: TdxBarSubItem;
  145. dxbtnTenderPartition: TdxBarButton;
  146. dxbtnSetDealPayPlan: TdxBarButton;
  147. dxbtnAddDetailGLs: TdxBarButton;
  148. dxbtnCopyDetailGls: TdxBarButton;
  149. dxbtnApplyToSameBills: TdxBarButton;
  150. dxbtnCalculatePriceMargin: TdxBarButton;
  151. dxbtnFxZJJL: TdxBarButton;
  152. dxbtnGclZJJL: TdxBarButton;
  153. dxbtnInsertCol: TdxBarButton;
  154. dxbtnHidden: TdxBarButton;
  155. dxbtnCancelHidden: TdxBarButton;
  156. dxbtnImportDmf: TdxBarButton;
  157. actnImportDmf: TAction;
  158. dxbtnCanCalc: TdxBarButton;
  159. dxbtnWithoutCalcCurPay: TdxBarButton;
  160. dxbtnSignOnline: TdxBarButton;
  161. dxbtnExportTpExcel: TdxBarButton;
  162. dxbtnHelpCenter: TdxBarButton;
  163. dxbtnLocateMeasureBills: TdxBarButton;
  164. dxbtnGuest: TdxBarButton;
  165. dxbtnLocateZJJL: TdxBarButton;
  166. dxbtnEpure: TdxBarButton;
  167. dxbtnLocateCompileBills: TdxBarButton;
  168. dxbtnGclGatherZJJL: TdxBarButton;
  169. dxbtnExportSumBaseFile: TdxBarButton;
  170. actnExportSumBaseFile: TAction;
  171. dxbtnGatherSubTender: TdxBarButton;
  172. dxbtnExportTenderError: TdxBarButton;
  173. dxbtnExportAllError: TdxBarButton;
  174. dxbtnExportStgResultExcel: TdxBarButton;
  175. dxbtnExportStgResult: TdxBarButton;
  176. dxbtnImportSubTenderGather: TdxBarButton;
  177. actnImportSubTenderGather: TAction;
  178. dxbtnExportBillsJson: TdxBarButton;
  179. actnExportBillsJson: TAction;
  180. dxbtnExportBillsPosExcelData: TdxBarButton;
  181. actnExportBillsPosExcelData: TAction;
  182. procedure FormCreate(Sender: TObject);
  183. procedure FormDestroy(Sender: TObject);
  184. procedure jtsProjectsChange(Sender: TObject; NewTab: Integer;
  185. var AllowChange: Boolean);
  186. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  187. procedure jtsProjectsMouseDown(Sender: TObject; Button: TMouseButton;
  188. Shift: TShiftState; X, Y: Integer);
  189. procedure actnCloseProjectExecute(Sender: TObject);
  190. procedure actnCloseProjectUpdate(Sender: TObject);
  191. procedure actnNewPhaseExecute(Sender: TObject);
  192. procedure actnProjectPropertiesUpdate(Sender: TObject);
  193. procedure actnProjectPropertiesExecute(Sender: TObject);
  194. procedure actnSaveProjectExecute(Sender: TObject);
  195. procedure actnNewAuditExecute(Sender: TObject);
  196. procedure actnNewPhaseUpdate(Sender: TObject);
  197. procedure actnOptionsExecute(Sender: TObject);
  198. procedure actnImportExcelExecute(Sender: TObject);
  199. procedure actnReplyExecute(Sender: TObject);
  200. procedure actnSubmitExecute(Sender: TObject);
  201. procedure dxBarManagerShowToolbarsPopup(Sender: TdxBarManager;
  202. PopupItemLinks: TdxBarItemLinks);
  203. procedure actnSubmitUpdate(Sender: TObject);
  204. procedure actnImportExcelUpdate(Sender: TObject);
  205. procedure actnUnlockInfoUpdate(Sender: TObject);
  206. procedure actnUnlockInfoExecute(Sender: TObject);
  207. procedure dxbtnAboutClick(Sender: TObject);
  208. procedure dxLoginCloudClick(Sender: TObject);
  209. procedure dxManageAccountClick(Sender: TObject);
  210. procedure dxbtnAuthorizeDogClick(Sender: TObject);
  211. procedure actnImportBillsPriceExecute(Sender: TObject);
  212. procedure actnImportDealBillsExecute(Sender: TObject);
  213. procedure tAutoSaveTimer(Sender: TObject);
  214. procedure actnExportExcelExecute(Sender: TObject);
  215. procedure dxSyncClick(Sender: TObject);
  216. procedure actnExportCloudTenderFileExecute(Sender: TObject);
  217. procedure actnExportCloudTenderFileUpdate(Sender: TObject);
  218. procedure actnImportCloudTenderFileExecute(Sender: TObject);
  219. procedure actnImportCloudTenderFileUpdate(Sender: TObject);
  220. procedure actnExportFxBillsExcelExecute(Sender: TObject);
  221. procedure dxseBatchInsertKeyDown(Sender: TObject; var Key: Word;
  222. Shift: TShiftState);
  223. procedure actnReplyUpdate(Sender: TObject);
  224. procedure dxbtnTenderPartitionClick(Sender: TObject);
  225. procedure actnImportDmfExecute(Sender: TObject);
  226. procedure dxbtnHelpCenterClick(Sender: TObject);
  227. procedure actnExportSumBaseFileExecute(Sender: TObject);
  228. procedure dxbtnGatherSubTenderClick(Sender: TObject);
  229. procedure actnImportSubTenderGatherExecute(Sender: TObject);
  230. procedure actnImportSubTenderGatherUpdate(Sender: TObject);
  231. procedure actnExportBillsJsonExecute(Sender: TObject);
  232. procedure actnExportBillsJsonUpdate(Sender: TObject);
  233. procedure actnExportBillsPosExcelDataExecute(Sender: TObject);
  234. private
  235. FProjectManagerFrame: TProjectManagerFrame;
  236. FProjectFrames: TList;
  237. procedure UpdateProgressBar(APosition: Integer);
  238. procedure UpdateProgressHint(const AHint: string);
  239. function CreateProjectView(ARec: TsdDataRecord): TProjectFrame;
  240. procedure LocateProjectView(AIndex: Integer);
  241. procedure DeleteProjectView(AIndex: Integer);
  242. procedure ResetProcessView(AIndex: Integer);
  243. procedure ChangeLeftSideGlobalView(AIndex: Integer);
  244. function GetCurProjectFrame: TProjectFrame;
  245. procedure OnError(ASender: TObject; AE: Exception);
  246. procedure ResetAutoSave;
  247. public
  248. procedure UpdateProgress(APos: Integer; const AHint: string);
  249. procedure LocateProject(AProjectID: Integer);
  250. function HasOpened(AProjectID: Integer): Boolean;
  251. function OpenProject(ARec: TsdDataRecord): TProjectFrame;
  252. property CurProjectFrame: TProjectFrame read GetCurProjectFrame;
  253. property ProjectManagerFrame: TProjectManagerFrame read FProjectManagerFrame;
  254. end;
  255. var
  256. MainForm: TMainForm;
  257. implementation
  258. uses
  259. ProjectProperty, ConstUnit, PHPWebDm, Math, ShellAPI,
  260. FindUserFrm, ImportExcelHintFrm, ConfigDoc, ExportExcel,
  261. ProjectCommands, BillsCompileDm, tpMainFrm,
  262. DealBillsExcelImport, ExcelImport_Bills, DetailExcelImport,
  263. stgGatherControl, stgSelectFileFrm;
  264. {$R *.dfm}
  265. {$R MeasureIcons.RES}
  266. procedure TMainForm.FormCreate(Sender: TObject);
  267. procedure CreateProjectManagerFrame;
  268. begin
  269. FProjectManagerFrame := TProjectManagerFrame.Create(nil);
  270. AlignControl(FProjectManagerFrame, jpsMainProjectsManager, alClient);
  271. end;
  272. procedure SetHintFont;
  273. begin
  274. if G_IsCloud then
  275. begin
  276. Screen.HintFont.Size := 11;
  277. Screen.HintFont.Name := 'Microsoft YaHei';
  278. end
  279. else
  280. begin
  281. Screen.HintFont.Name := 'SmartSimSun';
  282. Screen.HintFont.Size := 9;
  283. end;
  284. end;
  285. function GetSoftName: string;
  286. begin
  287. if _ModuleType = mtCompile then
  288. Result := '纵横公路工程0号台账软件'
  289. else if _ModuleType = mtAll then
  290. Result := '纵横公路工程结算决算计量一体化软件';
  291. end;
  292. function GetVersionName: string;
  293. begin
  294. Result := '';
  295. if _IsGuangDong then
  296. Result := Result + '广东';
  297. if _ModuleType = mtAll then
  298. begin
  299. if _IsDebugView then
  300. Result := 'Debug'
  301. else if G_IsTest then
  302. Result := '测试'
  303. else if G_IsCloud then
  304. Result := Result + '云'
  305. else if _IsEncrypt then
  306. Result := Result + '专业'
  307. else
  308. Result := Result + '学习';
  309. end;
  310. if Result <> '' then
  311. Result := Result + '版';
  312. end;
  313. procedure InitialForVersions;
  314. var
  315. sPic: string;
  316. begin
  317. if G_IsCloud then
  318. begin
  319. dxbtnNewProject.Visible := ivNever;
  320. dxbtnNewSubProject.Visible := ivNever;
  321. dxbtnReceiveProject.Visible := ivNever;
  322. dxbtnNewPhase.Visible := ivNever;
  323. dxUser.Visible := ivAlways;
  324. dxUser.Caption := PHPWeb.RealName;
  325. lblAccount.Caption := PHPWeb.RealName;
  326. lblMail.Caption := Format('(%s)', [PHPWeb.Account]);
  327. if Trim(PHPWeb.Company) <> '' then
  328. lblCompany.Caption := PHPWeb.Company
  329. else
  330. lblCompany.Caption := '我的单位';
  331. if Trim(PHPWeb.Role) <> '' then
  332. lblRole.Caption := PHPWeb.Role
  333. else
  334. lblRole.Caption := '我的职称';
  335. // 每次登录都下载到本地,再从本地读入显示。以保证图片实时更新。
  336. sPic := PHPWeb.UserPath + '0_' + IntToStr(PHPWeb.UserID) + '.jpg';
  337. if PHPWeb.DownFile(PHPWeb.UserImageURL, sPic) then
  338. if FileExists(sPic) then
  339. imgUserImage.Picture.LoadFromFile(sPic);
  340. end
  341. else
  342. begin
  343. dxUser.Visible := ivNever;
  344. dxbtnReceiveProject.Visible := ivAlways;
  345. end;
  346. MainForm.Caption := GetSoftName + GetVersionName;
  347. end;
  348. begin
  349. CreateProjectManagerFrame;
  350. FProjectFrames := TList.Create;
  351. InitialForVersions;
  352. SetHintFont;
  353. ResetAutoSave;
  354. end;
  355. procedure TMainForm.UpdateProgress(APos: Integer; const AHint: string);
  356. begin
  357. UpdateProgressBar(APos);
  358. UpdateProgressHint(AHint);
  359. Application.ProcessMessages;
  360. end;
  361. procedure TMainForm.UpdateProgressBar(APosition: Integer);
  362. begin
  363. if APosition < ProgressBar.Max then
  364. ProgressBar.Position := APosition
  365. else
  366. ProgressBar.Position := ProgressBar.Min;
  367. end;
  368. procedure TMainForm.UpdateProgressHint(const AHint: string);
  369. begin
  370. dxStatusBar.Panels[0].Text := AHint;
  371. end;
  372. procedure TMainForm.FormDestroy(Sender: TObject);
  373. begin
  374. ClearObjects(FProjectFrames);
  375. FProjectFrames.Free;
  376. FProjectManagerFrame.Free;
  377. if DirectoryExists(GetAppTempPath) then
  378. DeleteFileOrFolder(GetAppTempPath);
  379. end;
  380. function TMainForm.OpenProject(ARec: TsdDataRecord): TProjectFrame;
  381. begin
  382. if not HasOpened(ARec.ValueByName('ID').AsInteger) then
  383. Result := CreateProjectView(ARec)
  384. else
  385. begin
  386. LocateProject(ARec.ValueByName('ID').AsInteger);
  387. Result := CurProjectFrame;
  388. end;
  389. end;
  390. function TMainForm.HasOpened(AProjectID: Integer): Boolean;
  391. begin
  392. Result := OpenProjectManager.ProjectIndex(AProjectID) <> -1;
  393. end;
  394. procedure TMainForm.LocateProject(AProjectID: Integer);
  395. begin
  396. jtsProjects.TabIndex := OpenProjectManager.ProjectIndex(AProjectID) + 1;
  397. if jpsMain.ActivePage <> jpsMainProjects then
  398. jpsMain.ActivePage := jpsMainProjects;
  399. end;
  400. function TMainForm.CreateProjectView(ARec: TsdDataRecord): TProjectFrame;
  401. function CreateNewProjectPage: TJimPage;
  402. begin
  403. Result := TJimPage.Create(jpsProjects);
  404. Result.Pages := jpsProjects;
  405. jpsProjects.ActivePage := Result;
  406. end;
  407. function CreateNewProjectTab(const ATabName: string; APage: TJimPage): Integer;
  408. begin
  409. Result := jtsProjects.Tabs.AddObject(ATabName, APage);
  410. jtsProjects.TabIndex := Result;
  411. end;
  412. function CreateProjectFrame(AProjectData: TProjectData; APage: TJimPage): TProjectFrame;
  413. var
  414. ProjectFrame: TProjectFrame;
  415. begin
  416. AProjectData.IsGuest := FProjectManagerFrame.IsGuest;
  417. ProjectFrame := TProjectFrame.Create(AProjectData);
  418. FProjectFrames.Add(ProjectFrame);
  419. ProjectFrame.Parent := APage;
  420. ProjectFrame.Align := alClient;
  421. Result := ProjectFrame;
  422. end;
  423. var
  424. jimPage: TJimPage;
  425. begin
  426. jpsMain.ActivePage := jpsMainProjects;
  427. jimPage := CreateNewProjectPage;
  428. CreateNewProjectTab(ARec.ValueByName('Name').AsString, jimPage);
  429. Result := CreateProjectFrame(OpenProjectManager.Open(ARec), jimPage);
  430. ProjectManager.AddOpenTenderBackup(ARec.ValueByName('ID').AsInteger);
  431. end;
  432. procedure TMainForm.jtsProjectsChange(Sender: TObject; NewTab: Integer;
  433. var AllowChange: Boolean);
  434. begin
  435. LocateProjectView(NewTab - 1);
  436. ResetProcessView(NewTab);
  437. end;
  438. procedure TMainForm.LocateProjectView(AIndex: Integer);
  439. begin
  440. if AIndex >= 0 then
  441. begin
  442. jpsMain.ActivePage := jpsMainProjects;
  443. jpsProjects.ActivePage := TJimPage(jtsProjects.Tabs.Objects[AIndex + 1]);
  444. OpenProjectManager.CurProjectIndex := AIndex;
  445. ChangeLeftSideGlobalView(AIndex);
  446. end
  447. else
  448. jpsMain.ActivePage := jpsMainProjectsManager;
  449. end;
  450. procedure TMainForm.ChangeLeftSideGlobalView(AIndex: Integer);
  451. begin
  452. if (AIndex >= 0) and (AIndex < FProjectFrames.Count) then
  453. TProjectFrame(FProjectFrames[AIndex]).ResetAssistantView;
  454. end;
  455. procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  456. begin
  457. try
  458. OpenProjectManager.SaveAll;
  459. except
  460. end;
  461. end;
  462. procedure TMainForm.jtsProjectsMouseDown(Sender: TObject;
  463. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  464. begin
  465. if (Button = mbRight) and (jtsProjects.TabIndex > 0) then
  466. dxpmTabSet.PopupFromCursorPos;
  467. end;
  468. procedure TMainForm.actnCloseProjectExecute(Sender: TObject);
  469. begin
  470. OpenProjectManager.CurProjectData.SaveAndCheck;
  471. DeleteProjectView(jtsProjects.TabIndex - 1);
  472. LocateProjectView(jtsProjects.TabIndex - 1);
  473. ResetProcessView(jtsProjects.TabIndex);
  474. end;
  475. procedure TMainForm.actnCloseProjectUpdate(Sender: TObject);
  476. begin
  477. TAction(Sender).Enabled := jtsProjects.Tabs.Count > 1;
  478. end;
  479. procedure TMainForm.DeleteProjectView(AIndex: Integer);
  480. begin
  481. TProjectFrame(FProjectFrames[AIndex]).Free;
  482. FProjectFrames.Delete(AIndex);
  483. OpenProjectManager.Delete(AIndex);
  484. jpsProjects.Pages.Delete(AIndex);
  485. jtsProjects.Tabs.Delete(AIndex + 1);
  486. end;
  487. procedure TMainForm.actnNewPhaseExecute(Sender: TObject);
  488. begin
  489. TProjectFrame(FProjectFrames[jtsProjects.TabIndex - 1]).CreateNewPhase;
  490. end;
  491. procedure TMainForm.actnProjectPropertiesUpdate(Sender: TObject);
  492. begin
  493. TAction(Sender).Enabled := jtsProjects.TabIndex > 0;
  494. end;
  495. procedure TMainForm.actnProjectPropertiesExecute(Sender: TObject);
  496. begin
  497. ModifyProjectProperties(TProjectFrame(FProjectFrames[jtsProjects.TabIndex - 1]));
  498. end;
  499. procedure TMainForm.actnSaveProjectExecute(Sender: TObject);
  500. begin
  501. OpenProjectManager.CurProjectData.SaveAndCheck;
  502. end;
  503. procedure TMainForm.actnNewAuditExecute(Sender: TObject);
  504. begin
  505. TProjectFrame(FProjectFrames[jtsProjects.TabIndex - 1]).CreateNewAudit;
  506. end;
  507. procedure TMainForm.actnNewPhaseUpdate(Sender: TObject);
  508. begin
  509. TAction(Sender).Enabled := (jtsProjects.Tabs.Count > 1) and Assigned(CurProjectFrame);
  510. if TAction(Sender).Enabled then
  511. with CurProjectFrame.ProjectData do
  512. TAction(Sender).Enabled := TAction(Sender).Enabled and (ProjProperties.AuditStatus = -1);
  513. end;
  514. function TMainForm.GetCurProjectFrame: TProjectFrame;
  515. begin
  516. if jtsProjects.TabIndex > 0 then
  517. Result := TProjectFrame(FProjectFrames[jtsProjects.TabIndex - 1])
  518. else
  519. Result := nil;
  520. end;
  521. procedure TMainForm.actnOptionsExecute(Sender: TObject);
  522. begin
  523. ModifiedOptions;
  524. ResetAutoSave;
  525. end;
  526. procedure TMainForm.actnImportExcelExecute(Sender: TObject);
  527. var
  528. sFileName: string;
  529. Importor: Tdei_CustomBills;
  530. bWithLevelCode, bWithoutGclBills: Boolean;
  531. begin
  532. if HintAndImportTypeSelect(bWithLevelCode, bWithoutGclBills) then
  533. begin
  534. if SelectExcelFile(sFileName) then
  535. begin
  536. Importor := Tdei_CustomBills.Create(CurProjectFrame.ProjectData);
  537. try
  538. Importor.ImportFile(sFileName, bWithLevelCode, bWithoutGclBills);
  539. finally
  540. Importor.Free;
  541. end;
  542. end;
  543. end;
  544. end;
  545. procedure TMainForm.ResetProcessView(AIndex: Integer);
  546. begin
  547. dxBarManager.Bars[2].Visible := AIndex > 0;
  548. if G_IsCloud then
  549. dxBarManager.Bars[2].Visible := False;
  550. end;
  551. procedure TMainForm.actnReplyExecute(Sender: TObject); // 批复
  552. begin
  553. if not CurProjectFrame.CheckCanReport then Exit;
  554. Screen.Cursor := crHourGlass;
  555. try
  556. CurProjectFrame.ProjectData.SaveAndCheck;
  557. {$O-}
  558. // 失败后重复一次
  559. if not CurProjectFrame.ProjectData.ReplyProject then
  560. begin
  561. if not CurProjectFrame.ProjectData.ReplyProject then
  562. ErrorMessage('批复项目失败!');
  563. end;
  564. {$O+}
  565. finally
  566. Screen.Cursor := crDefault;
  567. end;
  568. end;
  569. procedure TMainForm.actnSubmitExecute(Sender: TObject); // 上报
  570. begin
  571. if not CurProjectFrame.CheckCanReport then Exit;
  572. Screen.Cursor := crHourGlass;
  573. try
  574. CurProjectFrame.ProjectData.SaveAndCheck;
  575. {$O-}
  576. // 失败后重复一次
  577. if not CurProjectFrame.ProjectData.SubmitProject then
  578. begin
  579. if not CurProjectFrame.ProjectData.SubmitProject then
  580. ErrorMessage('上报项目失败!');
  581. end;
  582. {$O+}
  583. finally
  584. Screen.Cursor := crDefault;
  585. end;
  586. end;
  587. procedure TMainForm.dxBarManagerShowToolbarsPopup(Sender: TdxBarManager;
  588. PopupItemLinks: TdxBarItemLinks);
  589. begin
  590. // 取消菜单栏右键菜单
  591. PopupItemLinks.Clear;
  592. end;
  593. procedure TMainForm.actnSubmitUpdate(Sender: TObject);
  594. begin
  595. with CurProjectFrame.ProjectData do
  596. TAction(Sender).Enabled := (ProjProperties.PhaseCount > 0) and
  597. ((ProjProperties.AuditStatus >= 0) and (ProjProperties.AuditStatus < iMaxStageCount-1));
  598. end;
  599. procedure TMainForm.actnImportExcelUpdate(Sender: TObject);
  600. begin
  601. TAction(Sender).Enabled := (jtsProjects.Tabs.Count > 1) and Assigned(CurProjectFrame);
  602. if TAction(Sender).Enabled then
  603. with CurProjectFrame.ProjectData do
  604. TAction(Sender).Enabled := TAction(Sender).Enabled and (PhaseIndex < 1);
  605. end;
  606. procedure TMainForm.actnUnlockInfoUpdate(Sender: TObject);
  607. begin
  608. TAction(Sender).Enabled := (jtsProjects.Tabs.Count > 1) and Assigned(CurProjectFrame);
  609. end;
  610. procedure TMainForm.actnUnlockInfoExecute(Sender: TObject);
  611. begin
  612. CurProjectFrame.UnLockData;
  613. end;
  614. procedure TMainForm.dxbtnAboutClick(Sender: TObject);
  615. begin
  616. ShowAboutForm;
  617. end;
  618. procedure TMainForm.dxLoginCloudClick(Sender: TObject);
  619. begin
  620. ShellExecute(Application.Handle, nil, PChar(PHPWeb.LoginCloudURL), nil, nil, SW_SHOWNORMAL);
  621. end;
  622. procedure TMainForm.dxManageAccountClick(Sender: TObject);
  623. begin
  624. ShellExecute(Application.Handle, nil, PChar(PHPWeb.PassportURL), nil, nil, SW_SHOWNORMAL);
  625. end;
  626. procedure TMainForm.dxbtnAuthorizeDogClick(Sender: TObject);
  627. begin
  628. Authorize;
  629. end;
  630. procedure TMainForm.actnImportBillsPriceExecute(Sender: TObject);
  631. var
  632. sFileName: string;
  633. Importor: TBillsPriceExcelImport;
  634. begin
  635. if SelectExcelFile(sFileName) then
  636. begin
  637. Importor := TBillsPriceExcelImport.Create(CurProjectFrame.ProjectData);
  638. try
  639. Importor.ImportFile(sFileName);
  640. finally
  641. Importor.Free;
  642. end;
  643. end;
  644. end;
  645. procedure TMainForm.actnImportDealBillsExecute(Sender: TObject);
  646. var
  647. sFileName: string;
  648. Importor: TDealBillsExcelImport;
  649. begin
  650. if SelectExcelFile(sFileName) then
  651. begin
  652. Importor := TDealBillsExcelImport.Create(CurProjectFrame.ProjectData);
  653. try
  654. Importor.ImportFile(sFileName);
  655. finally
  656. Importor.Free;
  657. end;
  658. end;
  659. end;
  660. procedure TMainForm.tAutoSaveTimer(Sender: TObject);
  661. begin
  662. Screen.Cursor := crHourGlass;
  663. try
  664. OpenProjectManager.SaveAll;
  665. finally
  666. screen.Cursor := crDefault;
  667. end;
  668. end;
  669. procedure TMainForm.ResetAutoSave;
  670. begin
  671. with SupportManager.ConfigInfo do
  672. begin
  673. tAutoSave.Interval := AutoSaveInterval * 60 * 1000;
  674. tAutoSave.Enabled := AutoSave;
  675. end;
  676. end;
  677. procedure TMainForm.actnExportExcelExecute(Sender: TObject);
  678. var
  679. sFileName: string;
  680. Exportor: TIDTreeExcelExportor;
  681. begin
  682. if SaveExcelFile(sFileName) then
  683. begin
  684. Exportor := TIDTreeExcelExportor.Create;
  685. try
  686. if SupportManager.ConfigInfo.ExcelWithMis then
  687. Exportor.DefineCol(@ciLedgerWithMis, Length(ciLedgerWithMis))
  688. else
  689. Exportor.DefineCol(@ciLedger, Length(ciLedger));
  690. Exportor.HasLevelCode := True;
  691. Exportor.ExportToFile(CurProjectFrame.ProjectData.BillsCompileData.BillsCompileTree, sFileName);
  692. finally
  693. Exportor.Free;
  694. end;
  695. end;
  696. end;
  697. procedure TMainForm.dxSyncClick(Sender: TObject);
  698. begin
  699. Screen.Cursor := crHourGlass;
  700. try
  701. FProjectManagerFrame.DoBatchReceiveAllOnline;
  702. finally
  703. Screen.Cursor := crDefault;
  704. end;
  705. end;
  706. procedure TMainForm.actnExportCloudTenderFileExecute(Sender: TObject);
  707. var
  708. sFileName: string;
  709. Exportor: TTenderExport;
  710. Rec: TsdDataRecord;
  711. begin
  712. // 导出前先保存
  713. CurProjectFrame.ProjectData.SaveAndCheck;
  714. // 导出云版专用
  715. sFileName := SupportManager.ConfigInfo.OutputPath + CurProjectFrame.ProjectData.ProjectName + '.ctf';
  716. if SaveFile(sFileName, '.ctf') then
  717. begin
  718. if FileExists(sFileName) and not QuestMessage(Format('存在同名文件“%s”,是否替换?', [ExtractFileName(sFileName)])) then
  719. Exit;
  720. Screen.Cursor := crHourGlass;
  721. try
  722. Rec := ProjectManagerFrame.Rec(CurProjectFrame.ProjectData.ProjectID);
  723. Exportor := TTenderExport.Create(Rec, sFileName);
  724. try
  725. Exportor.Execute;
  726. finally
  727. Exportor.Free;
  728. end;
  729. finally
  730. Screen.Cursor := crDefault;
  731. end;
  732. end;
  733. end;
  734. procedure TMainForm.actnExportCloudTenderFileUpdate(Sender: TObject);
  735. begin
  736. // 仅打开的项目可以导出云版专用格式,且该项目没有进行计量
  737. TAction(Sender).Enabled := (jtsProjects.Tabs.Count > 1) and Assigned(CurProjectFrame);
  738. if TAction(Sender).Enabled then
  739. TAction(Sender).Enabled := CurProjectFrame.ProjectData.ProjProperties.PhaseCount = 0;
  740. end;
  741. procedure TMainForm.actnImportCloudTenderFileExecute(Sender: TObject);
  742. var
  743. sFileName: string;
  744. begin
  745. if SelectFile(sFileName, '.ctf') then
  746. begin
  747. CurProjectFrame.ProjectData.ImportCloudTenderFile(sFileName);
  748. CurProjectFrame.RefreshColumnDisplay;
  749. end;
  750. end;
  751. procedure TMainForm.actnImportCloudTenderFileUpdate(Sender: TObject);
  752. begin
  753. TAction(Sender).Enabled := (jtsProjects.Tabs.Count > 1) and Assigned(CurProjectFrame);
  754. if TAction(Sender).Enabled then
  755. TAction(Sender).Enabled := CurProjectFrame.ProjectData.ProjProperties.PhaseCount = 0;
  756. end;
  757. procedure TMainForm.actnExportFxBillsExcelExecute(Sender: TObject);
  758. var
  759. sFileName: string;
  760. Exportor: TIDTreeExcelExportor;
  761. begin
  762. if SaveExcelFile(sFileName) then
  763. begin
  764. Exportor := TIDTreeExcelExportor.Create;
  765. try
  766. if SupportManager.ConfigInfo.ExcelWithMis then
  767. Exportor.DefineCol(@ciFxBillsWithMis, Length(ciFxBillsWithMis))
  768. else
  769. Exportor.DefineCol(@ciFxBills, Length(ciFxBills));
  770. Exportor.ExportToFile(CurProjectFrame.ProjectData.BillsCompileData.BillsCompileTree, sFileName);
  771. finally
  772. Exportor.Free;
  773. end;
  774. end;
  775. end;
  776. procedure TMainForm.dxseBatchInsertKeyDown(Sender: TObject; var Key: Word;
  777. Shift: TShiftState);
  778. var
  779. i: Integer;
  780. begin
  781. if Key = 13 then
  782. begin
  783. for i := 1 to dxseBatchInsert.IntValue do
  784. ZjDbaInsert.ExecuteTarget(CurProjectFrame.BillsCompileFrame.zgBillsCompile);
  785. end;
  786. end;
  787. procedure TMainForm.actnReplyUpdate(Sender: TObject);
  788. begin
  789. with CurProjectFrame.ProjectData do
  790. TAction(Sender).Enabled := (ProjProperties.PhaseCount > 0);
  791. end;
  792. procedure TMainForm.dxbtnTenderPartitionClick(Sender: TObject);
  793. begin
  794. PartTendersModel;
  795. end;
  796. procedure TMainForm.actnImportDmfExecute(Sender: TObject);
  797. var
  798. sFileName: string;
  799. begin
  800. if SelectFile(sFileName, '.dmf') then
  801. CurProjectFrame.ProjectData.ImportDmfFile(sFileName);
  802. end;
  803. procedure TMainForm.dxbtnHelpCenterClick(Sender: TObject);
  804. const
  805. sHelpUrl = 'http://help.smartcost.com.cn/hc/';
  806. begin
  807. ShellExecute(Application.Handle, nil, PChar(sHelpUrl), nil, nil, SW_SHOWNORMAL);
  808. end;
  809. procedure TMainForm.OnError(ASender: TObject; AE: Exception);
  810. begin
  811. MeasureLog.AppendLogTo(AE.Message);
  812. end;
  813. procedure TMainForm.actnExportSumBaseFileExecute(Sender: TObject);
  814. var
  815. sFileName: string;
  816. Exportor: TTenderExport;
  817. Rec: TsdDataRecord;
  818. begin
  819. // 导出前先保存
  820. CurProjectFrame.ProjectData.SaveAndCheck;
  821. // 导出云版专用
  822. sFileName := SupportManager.ConfigInfo.OutputPath + CurProjectFrame.ProjectData.ProjectName + '.sbf';
  823. if SaveFile(sFileName, '.sbf') then
  824. begin
  825. if FileExists(sFileName) and not QuestMessage(Format('存在同名文件“%s”,是否替换?', [ExtractFileName(sFileName)])) then
  826. Exit;
  827. Screen.Cursor := crHourGlass;
  828. try
  829. Rec := ProjectManagerFrame.Rec(CurProjectFrame.ProjectData.ProjectID);
  830. Exportor := TTenderExport.Create(Rec, sFileName);
  831. try
  832. Exportor.Execute;
  833. finally
  834. Exportor.Free;
  835. end;
  836. finally
  837. Screen.Cursor := crDefault;
  838. end;
  839. end;
  840. end;
  841. procedure TMainForm.dxbtnGatherSubTenderClick(Sender: TObject);
  842. var
  843. gc: TstgGatherControl;
  844. begin
  845. gc := TstgGatherControl.Create;
  846. Screen.Cursor := crHourGlass;
  847. try
  848. if SelectFileForSubTenderGather(gc) then
  849. gc.Gather;
  850. finally
  851. gc.Free;
  852. Screen.Cursor := crDefault;
  853. end;
  854. end;
  855. procedure TMainForm.actnImportSubTenderGatherExecute(Sender: TObject);
  856. var
  857. sFileName: string;
  858. begin
  859. if CurProjectFrame.ProjectData.ProjProperties.PhaseCount = 0 then
  860. WarningMessage('未开始计量,请在开始计量后再导入分包汇总数据。')
  861. else if CurProjectFrame.ProjectData.StageDataReadOnly then
  862. WarningMessage('当前正在查看数据非最新数据,请切换至最新一期再导入分包汇总数据。')
  863. else if QuestMessage('导入将清空标段本期所有计量数据(合同计量),确定继续?') and SelectFile(sFileName, '.sgf') then
  864. CurProjectFrame.ProjectData.ImportSubTenderGather(sFileName);
  865. end;
  866. procedure TMainForm.actnImportSubTenderGatherUpdate(Sender: TObject);
  867. begin
  868. TAction(Sender).Enabled := (jtsProjects.Tabs.Count > 1) and Assigned(CurProjectFrame)
  869. and (CurProjectFrame.ProjectData.PhaseData.StageCount <= 1);
  870. end;
  871. procedure TMainForm.actnExportBillsJsonExecute(Sender: TObject);
  872. var
  873. sFileName: string;
  874. begin
  875. if SaveFile(sFileName, '.json') then
  876. CurProjectFrame.ProjectData.BillsCompileData.RecursiveExportBillsJson(sFileName);
  877. end;
  878. procedure TMainForm.actnExportBillsJsonUpdate(Sender: TObject);
  879. begin
  880. TAction(Sender).Visible := _IsDebugView;
  881. TAction(Sender).Enabled := jtsProjects.Tabs.Count > 1;
  882. end;
  883. procedure TMainForm.actnExportBillsPosExcelDataExecute(Sender: TObject);
  884. var
  885. sFileName: string;
  886. Exportor: TBillsPosExcelExportor;
  887. begin
  888. if SaveExcelFile(sFileName) then
  889. begin
  890. Exportor := TBillsPosExcelExportor.Create;
  891. try
  892. Exportor.ExportToFile(CurProjectFrame.ProjectData.BillsCompileData.BillsCompileTree, sFileName);
  893. finally
  894. Exportor.Free;
  895. end;
  896. end;
  897. end;
  898. end.