BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: manoi ที่ สิงหาคม 16, 2006, 01:33:26 AM

หัวข้อ: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: manoi ที่ สิงหาคม 16, 2006, 01:33:26 AM
ในการเขียน Script นอกจากจะเขียนเป็น Script ให้ทำงานตามที่สั่งได้แล้ว ยังสามารถออกแบบให้สามารถติดต่อกับผู้ใช้งานโดยใช้ Standard VCL Component ได้ด้วย แต่เนื่องจากระบบ Script ไม่มีระบบ IDE ที่จะออกแบบหน้าจอ ดังนั้นจึงต้องใช้วิธีนำ component มาใช้โดยการเขียน Code มาดูตัวอย่างครับ

โค๊ด: Pascal
  1. Unit Script;
  2.  
  3. var MyForm : TForm;
  4.     OKButton : TButton;
  5.  
  6.  
  7. Implementation
  8.  
  9.  
  10. Procedure OKButtonClick;
  11. begin
  12.   MyForm.close;
  13.  
  14. end;
  15.  
  16. Procedure InitilizeForm;
  17. begin
  18.  
  19.   MyFORM:=TForm.create(nil);
  20.   MyForm.top:=100;
  21.   MyForm.left:=100;
  22.  
  23.   OKButton:=TButton.Create(MyForm);
  24.   OKButton.parent:=MyForm;
  25.   OKButton.Caption:='OK';
  26.   OKButton.left:=10;
  27.   OKButton.top:=10;
  28.  
  29.   OKButton.OnClick:=OkButtonClick;
  30.  
  31. end;
  32.  
  33.  
  34. Procedure Main;
  35. var
  36.   i:integer;
  37. begin
  38.   InitilizeForm;
  39.   MyForm.showmodal;
  40.   MyForm.free;
  41. end;
  42.  
  43.  
  44.  
  45.  
  46.  
  47. end.
  48.  
  49.  
  50.  
หัวข้อ: Re: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: manoi ที่ สิงหาคม 16, 2006, 04:38:42 AM
คราวนี้มาดูเมื่อเขียนให้ทำการดึงข้อมูลมาใช้บ้าง


โปรแกรม (script) Pttype name changer จะทำการดึงข้อมูลในตาราง pttype มาให้ผู้ใช้แก้ไขชื่อ โดยการระบุรหัสิทธิการรักษาที่ต้องการ

โค๊ด: Pascal
  1. Unit Script;
  2.  
  3. var MyForm : TForm;
  4.     OKButton : TButton;
  5.     SaveButton : TButton;
  6.     DBEdit1:TDBEdit;
  7.     DataSource : TDataSource;
  8.     ClientDataset : TClientDataset;
  9.     PttypeEdit : TEdit;
  10.  
  11.     PttypeLabel : TLabel;
  12.     PttypeNameLabel : TLabel;
  13.  
  14.  
  15. Implementation
  16.  
  17.  
  18. Procedure OKButtonClick;
  19. begin
  20.   MyForm.close;
  21.  
  22. end;
  23.  
  24. Procedure SaveButtonClick;
  25. begin
  26.   if ClientDataset.state = dsedit then ClientDataset.post;
  27.  
  28.   if ClientDataset.changecount>0 then HOSxP_UpdateDelta(clientdataset.delta,'select * from pttype where pttype="'+PttypeEdit.text+'"');
  29.   MyForm.close;
  30. end;
  31.  
  32. Procedure PttypeEditChange;
  33. begin
  34.   ClientDataset.Data:=HOSxP_GetDataset('select * from pttype where pttype="'+PttypeEdit.text+'"');
  35.   SaveButton.enabled:=ClientDataset.recordcount>0;
  36.  
  37. end;
  38.  
  39. Procedure InitilizeForm;
  40. begin
  41.  
  42.   MyFORM:=TForm.create(nil);
  43.   MyForm.top:=100;
  44.   MyForm.left:=100;
  45.  
  46.   OKButton:=TButton.Create(MyForm);
  47.   OKButton.parent:=MyForm;
  48.   OKButton.Caption:='Close';
  49.   OKButton.left:=150;
  50.   OKButton.top:=150;
  51.  
  52.   OKButton.OnClick:=OkButtonClick;
  53.  
  54.   SaveButton:=TButton.Create(MyForm);
  55.   SaveButton.parent:=MyForm;
  56.   SaveButton.Caption:='Save';
  57.   SaveButton.left:=50;
  58.   SaveButton.top:=150;
  59.   SaveButton.enabled:=false;
  60.  
  61.   SaveButton.OnClick:=SaveButtonClick;
  62.  
  63.   DataSource:=TDataSource.create(MyForm);
  64.   ClientDataset:=TClientDataset.create(MyForm);
  65.   ClientDataset.data:=HOSxP_GetDataset('select * from pttype limit 0');
  66.   DataSource.Dataset := ClientDataset;
  67.  
  68.   PttypeEdit:=TEdit.create(MyForm);
  69.   PttypeEdit.parent:=MyForm;
  70.   PttypeEdit.left:=100;
  71.   PttypeEdit.top:=20;
  72.   PttypeEdit.width:=40;
  73.  
  74.   PttypeEdit.onchange:=PttypeEditChange;
  75.  
  76.   PttypeLabel:=TLabel.create(MyForm);
  77.   PttypeLabel.parent:=MyForm;
  78.   PttypeLabel.caption:='ÃËÑÊÊÔ·¸Ô';
  79.   PttypeLabel.left:=20;
  80.   PttypeLabel.top:=23;
  81.  
  82.  
  83.   PttypeNameLabel:=TLabel.create(MyForm);
  84.   PttypeNameLabel.parent:=MyForm;
  85.   PttypeNameLabel.caption:='ª×èÍÊÔ·¸Ô';
  86.   PttypeNameLabel.left:=20;
  87.   PttypeNameLabel.top:=53;
  88.  
  89.   DBEdit1:=TDBEdit.create(MyForm);
  90.   DBEdit1.parent:=MyForm;
  91.   DBEdit1.left:=100;
  92.   DBEdit1.top:=50;
  93.   DBEdit1.DataSource:=Datasource;
  94.   DBEdit1.DataField:='name';
  95.  
  96.  
  97.  
  98. end;
  99.  
  100.  
  101. Procedure Main;
  102. var
  103.   i:integer;
  104. begin
  105.  
  106.  
  107.   InitilizeForm;
  108.   MyForm.showmodal;
  109.   MyForm.free;
  110.  
  111. end;
  112.  
  113.  
  114.  
  115.  
  116.  
  117. end.
  118.  
  119.  
  120.  
  121.  
หัวข้อ: Re: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: admin ที่ สิงหาคม 16, 2006, 08:09:08 AM
ลองเพิ่ม DBGrid เข้าไป

โค๊ด: Pascal
  1. Unit Script;
  2.  
  3. var MyForm : TForm;
  4.     OKButton : TButton;
  5.     SaveButton : TButton;
  6.     DBEdit1:TDBEdit;
  7.     DataSource : TDataSource;
  8.     ClientDataset : TClientDataset;
  9.     PttypeEdit : TEdit;
  10.  
  11.     PttypeLabel : TLabel;
  12.     PttypeNameLabel : TLabel;
  13.  
  14.     DBGrid : TDBGrid;
  15.  
  16.  
  17. Implementation
  18.  
  19.  
  20. Procedure OKButtonClick;
  21. begin
  22.   MyForm.close;
  23.  
  24. end;
  25.  
  26. Procedure SaveButtonClick;
  27. begin
  28.   if ClientDataset.state = dsedit then ClientDataset.post;
  29.  
  30.   if ClientDataset.changecount>0 then HOSxP_UpdateDelta(clientdataset.delta,'select * from pttype where pttype="'+PttypeEdit.text+'"');
  31.   MyForm.close;
  32. end;
  33.  
  34. Procedure PttypeEditChange;
  35. begin
  36.   ClientDataset.Data:=HOSxP_GetDataset('select * from pttype where pttype="'+PttypeEdit.text+'"');
  37.   SaveButton.enabled:=ClientDataset.recordcount>0;
  38.  
  39. end;
  40.  
  41. Procedure InitilizeForm;
  42. begin
  43.  
  44.   MyFORM:=TForm.create(nil);
  45.   MyForm.top:=200;
  46.   MyForm.left:=200;
  47.   MyForm.Width := 400;
  48.   MyForm.Height := 550;
  49.  
  50.   MyForm.caption:='Pttype name changer version 1.0';
  51.  
  52.   OKButton:=TButton.Create(MyForm);
  53.   OKButton.parent:=MyForm;
  54.   OKButton.Caption:='Close';
  55.   OKButton.left:=150;
  56.   OKButton.top:=450;
  57.  
  58.   OKButton.OnClick:=OkButtonClick;
  59.  
  60.   SaveButton:=TButton.Create(MyForm);
  61.   SaveButton.parent:=MyForm;
  62.   SaveButton.Caption:='Save';
  63.   SaveButton.left:=50;
  64.   SaveButton.top:=450;
  65.   SaveButton.enabled:=false;
  66.  
  67.   SaveButton.OnClick:=SaveButtonClick;
  68.  
  69.   DataSource:=TDataSource.create(MyForm);
  70.   ClientDataset:=TClientDataset.create(MyForm);
  71.   ClientDataset.data:=HOSxP_GetDataset('select * from pttype limit 0');
  72.   DataSource.Dataset := ClientDataset;
  73.  
  74.   PttypeEdit:=TEdit.create(MyForm);
  75.   PttypeEdit.parent:=MyForm;
  76.   PttypeEdit.left:=100;
  77.   PttypeEdit.top:=20;
  78.   PttypeEdit.width:=40;
  79.  
  80.   PttypeEdit.onchange:=PttypeEditChange;
  81.  
  82.   PttypeLabel:=TLabel.create(MyForm);
  83.   PttypeLabel.parent:=MyForm;
  84.   PttypeLabel.caption:='ÃËÑÊÊÔ·¸Ô';
  85.   PttypeLabel.left:=20;
  86.   PttypeLabel.top:=23;
  87.  
  88.  
  89.   PttypeNameLabel:=TLabel.create(MyForm);
  90.   PttypeNameLabel.parent:=MyForm;
  91.   PttypeNameLabel.caption:='ª×èÍÊÔ·¸Ô';
  92.   PttypeNameLabel.left:=20;
  93.   PttypeNameLabel.top:=53;
  94.  
  95.   DBEdit1:=TDBEdit.create(MyForm);
  96.   DBEdit1.parent:=MyForm;
  97.   DBEdit1.left:=100;
  98.   DBEdit1.top:=50;
  99.   DBEdit1.DataSource:=Datasource;
  100.   DBEdit1.DataField:='name';
  101.  
  102.   DBGrid := TDBGrid.create(MyForm);
  103.   DBGrid.parent := MyForm;
  104.   DBGrid.top:=100;
  105.   DBGrid.left:=20;
  106.   DBGrid.datasource := Datasource;
  107.  
  108.   MyForm.activecontrol := PttypeEdit;
  109.  
  110.  
  111.  
  112.  
  113. end;
  114.  
  115.  
  116. Procedure Main;
  117. var
  118.   i:integer;
  119. begin
  120.  
  121.  
  122.   InitilizeForm;
  123.   MyForm.showmodal;
  124.   MyForm.free;
  125.  
  126. end;
  127.  
  128.  
  129.  
  130.  
  131.  
  132. end.
  133.  
  134.  
  135.  
หัวข้อ: What 's next
เริ่มหัวข้อโดย: manoi ที่ สิงหาคม 16, 2006, 18:48:03 PM
จากความสามารถของตัว Script นี้ทำให้เราสามารถเพิ่มความยืดหยุ่นในการใช้งานระบบ HOSxP ได้ โดยการ Integrate Script เข้าไปในบางส่วนของระบบงานเพื่อให้ผู้ดูแลสามารถเพิ่มเติมการทำงานหรือเก็บข้อมูลบางอย่างเพิ่มเติมได้โดยไม่ต้องแก้ไขระบบหลัก ยกตัวอย่างเช่น

ระบบที่ได้นำร่องการ integrate ไปแล้วคือระบบการเชื่อมต่อกับ LIS ทั้งการส่ง Request Lab และการอ่านผล Lab จาก LIS

ระบบที่จะทำการ Integrate Script เข้าต่อจากนี้คือ ระบบการสั่ง X-Ray ที่จะสามารถออกแบบหน้าจอสั่ง X-Ray ได้เอง (ด้วยการดัดแปลง Script)
หัวข้อ: Re: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: nahos ที่ สิงหาคม 17, 2006, 01:12:27 AM
ดีครับ โหวต ๆ
หัวข้อ: Re: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: doramon ที่ สิงหาคม 17, 2006, 08:44:14 AM
ดีมากเลยครับแต่บางครั้งยากมีปัญหาภาษาไทย
อ่านไม่ออกอยู่ครับไม่รู้ว่าผมทำอะไรผิดหรือเปล่า
หัวข้อ: Re: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: manoi ที่ สิงหาคม 24, 2006, 08:04:42 AM
เย้ Geshi ทำงานได้แล้ว
หัวข้อ: Re: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: nuttavut ที่ สิงหาคม 24, 2006, 20:52:13 PM
..ดีครับ แต่ขอเป็น file VDO ประกอบได้ไหมครับ จะได้มองเห็นภาพและวิธีการ ลำดับขั้นตอน.......พิจารณาด้วยนะครับผม...
หัวข้อ: Re: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: manoi ที่ สิงหาคม 24, 2006, 22:40:00 PM
ต้องรอ Part II ครับ :]
หัวข้อ: Re: Pascal Script for Fun Part I
เริ่มหัวข้อโดย: nuttavut ที่ สิงหาคม 24, 2006, 23:27:22 PM
 :) ;D...จะรอดูนะครับ...ติดตามความคืบหน้าเสมอครับ...และขอบคุณทุกคำถามที่ตอบครับ... ::) :o