FormOrder.pas
资源名称:__DCOM.rar [点击查看]
上传用户:etonglee
上传日期:2014-03-01
资源大小:698k
文件大小:9k
源码类别:
Internet/IE编程
开发平台:
Delphi
- unit FormOrder;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ComCtrls, Grids, DBGrids, ExtCtrls, DB, DBClient, ActnList,
- Menus, StdCtrls, Mask, DBCtrls, Provider, ADODB;
- type
- TFrmOrder = class(TForm)
- ScrollBox: TScrollBox;
- pnlControls: TPanel;
- Splitter: TSplitter;
- dbgrdDetail: TDBGrid;
- StatusBar: TStatusBar;
- btnFind: TButton;
- btnRefresh: TButton;
- btnSave: TButton;
- btnCancel: TButton;
- btnAdd: TButton;
- btnModify: TButton;
- ActionList: TActionList;
- PopupMenu: TPopupMenu;
- actAdd: TAction;
- actModify: TAction;
- actRefresh: TAction;
- actSave: TAction;
- actFind: TAction;
- actCancel: TAction;
- actAddRow: TAction;
- actDelRow: TAction;
- cltdsOrders: TClientDataSet;
- cltdsOrderDetails: TClientDataSet;
- dsOrders: TDataSource;
- dsOrderDetails: TDataSource;
- Button1: TButton;
- actDelete: TAction;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- N6: TMenuItem;
- N7: TMenuItem;
- N8: TMenuItem;
- N9: TMenuItem;
- cltdsOrdersCustomerID: TWideStringField;
- cltdsOrdersEmployeeID: TIntegerField;
- cltdsOrdersOrderDate: TDateTimeField;
- cltdsOrdersRequiredDate: TDateTimeField;
- cltdsOrdersShippedDate: TDateTimeField;
- cltdsOrdersShipVia: TIntegerField;
- cltdsOrdersFreight: TBCDField;
- cltdsOrdersShipName: TWideStringField;
- cltdsOrdersShipAddress: TWideStringField;
- cltdsOrdersShipCity: TWideStringField;
- cltdsOrdersShipRegion: TWideStringField;
- cltdsOrdersShipPostalCode: TWideStringField;
- cltdsOrdersShipCountry: TWideStringField;
- cltdsOrderDetailsOrderID: TIntegerField;
- cltdsOrderDetailsProductID: TIntegerField;
- cltdsOrderDetailsUnitPrice: TBCDField;
- cltdsOrderDetailsQuantity: TSmallintField;
- cltdsOrderDetailsDiscount: TFloatField;
- PopupMenu_grid: TPopupMenu;
- N10: TMenuItem;
- N11: TMenuItem;
- cltdsOrderDetailsProductName: TStringField;
- cltdsOrderDetailsTotal: TFloatField;
- Label1: TLabel;
- DBEdit1: TDBEdit;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- DBEdit4: TDBEdit;
- Label5: TLabel;
- DBEdit5: TDBEdit;
- Label6: TLabel;
- DBEdit6: TDBEdit;
- Label7: TLabel;
- Label8: TLabel;
- DBEdit8: TDBEdit;
- Label9: TLabel;
- DBEdit9: TDBEdit;
- Label10: TLabel;
- DBEdit10: TDBEdit;
- Label11: TLabel;
- DBEdit11: TDBEdit;
- Label12: TLabel;
- DBEdit12: TDBEdit;
- Label13: TLabel;
- DBEdit13: TDBEdit;
- Label14: TLabel;
- DBEdit14: TDBEdit;
- DBLookupComboBox1: TDBLookupComboBox;
- DBLookupComboBox2: TDBLookupComboBox;
- DBLookupComboBox3: TDBLookupComboBox;
- cltdsOrdersOrderID: TIntegerField;
- procedure cltdsOrderDetailsCalcFields(DataSet: TDataSet);
- procedure actAddExecute(Sender: TObject);
- procedure actModifyExecute(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure actCancelExecute(Sender: TObject);
- procedure actAddRowExecute(Sender: TObject);
- procedure actDelRowExecute(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure actFindExecute(Sender: TObject);
- procedure actRefreshExecute(Sender: TObject);
- procedure actSaveExecute(Sender: TObject);
- private
- { Private declarations }
- FOrderID:integer;
- Procedure RefreshButtons();
- Procedure OpenOrder(OrderID:integer);
- Procedure OpenOrderDetail(OrderID:integer);
- Procedure OpenOther();
- Procedure SaveData();
- Procedure RefreshData();
- public
- { Public declarations }
- Class Procedure ShowOrder();
- end;
- implementation
- uses DtmdMain, SvrObj_Orders_TLB, UnitShare, FormFind;
- {$R *.dfm}
- Class Procedure TFrmOrder.ShowOrder();
- var
- oFrm:TFrmOrder;
- begin
- oFrm:=TFrmOrder.Create(Application);
- try
- oFrm.Show();
- except
- oFrm.Free();
- end;
- end;
- Procedure TFrmOrder.SaveData();
- var
- DeltaOrder,DeltaOrderDetail:OleVariant;
- Orders:IOrders;
- OrderId:integer;
- IsOk:WordBool;
- ErrorMsg:WideString;
- begin
- if cltdsOrdersOrderID.IsNull then
- begin
- showmessage('请输入OrderID!');
- exit;
- end;
- IsOk:=false;
- ErrorMsg:='';
- OrderId:= cltdsOrdersOrderID.AsInteger;
- if cltdsOrders.State<>dsBrowse then
- cltdsOrders.Post();
- //把更新数据写入Delta中
- if cltdsOrders.ChangeCount>0 then //判断是否有更新
- DeltaOrder:=cltdsOrders.Delta;
- if cltdsOrderDetails.State<>dsBrowse then
- cltdsOrderDetails.Post();
- //把更新数据写入Delta中
- if cltdsOrderDetails.ChangeCount>0 then //判断是否有更新
- DeltaOrderDetail:=cltdsOrderDetails.Delta;
- Orders:=CoOrders.CreateRemote(APPSVR);
- Orders.UpdateOrder(OrderId,DeltaOrder,DeltaOrderDetail,IsOk,ErrorMsg);
- if not IsOk then
- begin
- showmessage('错误信息:'+#13+ErrorMsg);//接收服务器端传递过来的错误信息
- exit;
- end;
- FOrderID:=OrderId;
- RefreshData(); //刷新
- end;
- Procedure TFrmOrder.OpenOther();
- var
- RetData:OleVariant;
- Orders:IOrders;
- begin
- if (DmMain.cltdsCustomers.Active and DmMain.cltdsShipper.Active and
- DmMain.cltdsProducts.Active and DmMain.cltdsEmployees.Active) then
- exit;
- Orders:=CoOrders.CreateRemote(APPSVR);
- //APPSVR是应用服务器地址或机器名
- //创建远程对象实例
- Orders.GetOtherData(RetData);
- DmMain.cltdsEmployees.Data:=RetData[0];
- DmMain.cltdsCustomers.Data:=RetData[1];
- DmMain.cltdsShipper.Data:=RetData[2];
- DmMain.cltdsProducts.Data:=RetData[3];
- end;
- Procedure TFrmOrder.OpenOrder(OrderID:integer);
- var
- RetData:OleVariant;
- Orders:IOrders;
- begin
- Orders:=CoOrders.CreateRemote(APPSVR);
- Orders.GetOrder(OrderID,RetData);
- cltdsOrders.Data:=RetData;
- cltdsOrders.ReadOnly:=true;
- end;
- Procedure TFrmOrder.OpenOrderDetail(OrderID:integer);
- var
- RetData:OleVariant;
- Orders:IOrders;
- begin
- Orders:=CoOrders.CreateRemote(APPSVR);
- Orders.GetOrderDetail(OrderID,RetData);
- cltdsOrderDetails.Data:=RetData;
- cltdsOrderDetails.ReadOnly:=true;
- end;
- Procedure TFrmOrder.RefreshButtons();
- begin
- if not cltdsOrders.Active then
- begin
- actFind.Enabled:=true;
- actAdd.Enabled:=true;
- actAddRow.Enabled:=false;
- actModify.Enabled:=false;
- actRefresh.Enabled:=false;
- actSave.Enabled:=false;
- actCancel.Enabled:=false;
- actDelRow.Enabled:=false;
- actDelete.Enabled:=false;
- exit;
- end;
- if cltdsOrders.ReadOnly then
- begin
- actFind.Enabled:=true;
- actAdd.Enabled:=true;
- actAddRow.Enabled:=false;
- actModify.Enabled:=true;
- actRefresh.Enabled:=true;
- actSave.Enabled:=false;
- actCancel.Enabled:=false;
- actDelRow.Enabled:=false;
- if cltdsOrders.IsEmpty then
- actDelete.Enabled:=false
- else
- actDelete.Enabled:=true;
- dbgrdDetail.Options:=dbgrdDetail.Options+[dgRowSelect];
- end
- else
- begin
- actFind.Enabled:=false;
- actAdd.Enabled:=false;
- actAddRow.Enabled:=true;
- actModify.Enabled:=false;
- actRefresh.Enabled:=false;
- actSave.Enabled:=true;
- actCancel.Enabled:=true;
- actDelRow.Enabled:=true;
- actDelete.Enabled:=false;
- dbgrdDetail.Options:=dbgrdDetail.Options-[dgRowSelect]+[dgEditing];
- end;
- end;
- procedure TFrmOrder.cltdsOrderDetailsCalcFields(DataSet: TDataSet);
- begin
- cltdsOrderDetailsTotal.AsFloat:=cltdsOrderDetailsUnitPrice.AsFloat*
- cltdsOrderDetailsQuantity.AsFloat*(1-cltdsOrderDetailsDiscount.AsFloat);
- end;
- procedure TFrmOrder.actAddExecute(Sender: TObject);
- begin
- if not cltdsOrders.Active then
- exit;
- FOrderID:=-1;
- RefreshData();
- cltdsOrders.ReadOnly:=false;
- cltdsOrderDetails.ReadOnly:=false;
- cltdsOrders.Append();
- RefreshButtons();
- end;
- procedure TFrmOrder.actModifyExecute(Sender: TObject);
- begin
- if not cltdsOrders.Active then
- exit;
- cltdsOrders.ReadOnly:=false;
- cltdsOrderDetails.ReadOnly:=false;
- RefreshButtons();
- end;
- procedure TFrmOrder.FormCreate(Sender: TObject);
- begin
- FOrderID:=-1;
- OpenOther();
- end;
- Procedure TFrmOrder.RefreshData();
- begin
- OpenOrder(FOrderID);
- OpenOrderDetail(FOrderID);
- RefreshButtons();
- end;
- procedure TFrmOrder.actCancelExecute(Sender: TObject);
- begin
- if not cltdsOrders.Active then
- exit;
- cltdsOrders.CancelUpdates();
- cltdsOrderDetails.CancelUpdates();
- cltdsOrders.ReadOnly:=true;
- cltdsOrderDetails.ReadOnly:=true;
- RefreshButtons();
- end;
- procedure TFrmOrder.actAddRowExecute(Sender: TObject);
- begin
- if not cltdsOrderDetails.Active then
- exit;
- if cltdsOrderDetails.ReadOnly then
- exit;
- cltdsOrderDetails.Append();
- end;
- procedure TFrmOrder.actDelRowExecute(Sender: TObject);
- begin
- if not cltdsOrderDetails.Active then
- exit;
- if cltdsOrderDetails.ReadOnly then
- exit;
- if cltdsOrderDetails.RecordCount>0 then
- cltdsOrderDetails.Delete();
- end;
- procedure TFrmOrder.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- Action:=caFree;
- end;
- procedure TFrmOrder.actFindExecute(Sender: TObject);
- var
- ResultValue:integer;
- begin
- ResultValue:= TFrmFind.ShowFind();
- if ResultValue<>-1 then
- begin
- FOrderID:=ResultValue;
- RefreshData();
- end;
- end;
- procedure TFrmOrder.actRefreshExecute(Sender: TObject);
- begin
- RefreshData();
- end;
- procedure TFrmOrder.actSaveExecute(Sender: TObject);
- begin
- SaveData();
- end;
- end.