?? unit_setupfeast.pas
字號:
unit Unit_SetupFeast;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Unit_Config, DBTables, Db, StdCtrls, TFlatEditUnit, TFlatButtonUnit,
ExtCtrls, Grids, DBGrids, ComCtrls, crypt, Procedurep,
TFlatRadioButtonUnit, TFlatSpinEditUnit, TFlatComboBoxUnit;
type
TFrm_SetupFeast = class(TFrm_Config)
Label1: TLabel;
FlatRadioButton_Date: TFlatRadioButton;
FlatRadioButton_ODate: TFlatRadioButton;
Label2: TLabel;
Label4: TLabel;
FlatComboBox_Month: TFlatComboBox;
FlatComboBox_Day: TFlatComboBox;
Label5: TLabel;
Label6: TLabel;
UpdateSQL1: TUpdateSQL;
procedure BitBtnAddClick(Sender: TObject);
procedure BitBtnAlterClick(Sender: TObject);
procedure BitBtnSaveClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Query_PUBAfterScroll(DataSet: TDataSet);
procedure BitBtnDelClick(Sender: TObject);
procedure BitBtnCancelClick(Sender: TObject);
procedure FlatRadioButton_ODateClick(Sender: TObject);
procedure FlatRadioButton_DateClick(Sender: TObject);
private
{ Private declarations }
//當前的節日編碼
P_CurrentCode :string;
//判斷是否為插入狀態
P_Insert :boolean;
//設置編輯框的灰和不灰Lflag為true,可編輯
procedure ProcSetPanel(Lflag:boolean);
public
{ Public declarations }
end;
var
Frm_SetupFeast: TFrm_SetupFeast;
implementation
uses main,dmmain,unit_public;
//按鈕控制
function Fun_ButtonStatus(pFormName:TForm;pStatus:Boolean=False):Boolean;stdcall;export;external'winfun.dll';
//輸框狀態控制
//Function Fun_ComponentStatus(pFormName:TForm;pStatusStyle:Integer=0;pStatus:Boolean=False):Integer;stdCall;external'winfun.dll';
Function Fun_ComponentStatus(pFormName:TForm;pStatusStyle:Integer=0;pStatus:Boolean=False;pObject:TObject=Nil):Integer;stdCall;external'winfun.dll';
{$R *.DFM}
procedure TFrm_SetupFeast.BitBtnAddClick(Sender: TObject);
begin
inherited;
kk:=1;
Fun_ButtonStatus(Self,True);
FlatRadioButton_Date.Checked :=true;
FlatComboBox_Month.ItemIndex :=0;
FlatComboBox_Day.ItemIndex :=0;
FlatEdit1.Text :='';
ProcSetPanel(true);
Fun_ComponentStatus(self,0,True); //--可輸入-- 使輸入框有效,用戶可以輸入數值
DBGrid_PUB.Enabled:=False;
end;
procedure TFrm_SetupFeast.BitBtnAlterClick(Sender: TObject);
begin
inherited;
kk:=2;
Fun_ButtonStatus(Self,True);
ProcSetPanel(true);
Fun_ComponentStatus(self,0,True); //--可輸入-- 使輸入框有效,用戶可以輸入數值
DBGrid_PUB.Enabled:=False;
end;
procedure TFrm_SetupFeast.BitBtnSaveClick(Sender: TObject);
var
ODate,NDate:String;
DateStyle:String;
MyDate: TDateTime;
LYear,Lstr :string;
SQL:String;
begin
inherited;
//***********驗證時間是否正確*******************
//得到后臺數據庫系統時間
Query_Tmp.close;
Query_Tmp.sql.text :='select sysdate from dual';
Query_Tmp.open;
LYear :=copy(Query_Tmp.fields[0].asstring,1,4);
try
MyDate := EncodeDate(strtoint(LYear),strtoint(FlatComboBox_Month.text),
strtoint(FlatComboBox_Day.text));
except
MessageDlg('輸入時間有誤',mtConfirmation, [mbYes], 0);
exit;
end;
if trim(FlatEdit1.Text) ='' then
begin
MessageDlg('節日內容字段不能為空!',mtConfirmation, [mbYes], 0);
exit;
end;
if length(FlatEdit1.Text) >30 then
begin
MessageDlg('節日內容字段超過長度!',mtConfirmation, [mbYes], 0);
exit;
end;
//提示是否更新
if kk=2 then
if MessageDlg('是否要更新該記錄?',mtConfirmation, [mbYes,mbNo], 0)=mrNo then exit;
//if (Application.MessageBox('是否要更新該記錄?',
// '提示',MB_OKCANCEL)=IDCANCEL) then exit;
//**********************************************
If FlatRadioButton_Date.Checked Then
Begin
ODate:='';
NDate:=FlatComboBox_Month.Text+FlatComboBox_Day.Text;
DateStyle:='0';
End
Else
Begin
NDate:='';
ODate:=FlatComboBox_Month.Text+FlatComboBox_Day.Text;
DateStyle:='1';
End;
//
case kk of
1: // add
Begin
SQL :='Insert Into T_D_HoliDay Values(Seq_HoliDay_Code.Nextval,'''
+Trim(FlatEdit1.Text)+''','''+NDate+''','''+ODate+''','+DateStyle+')';
if AnalyzeSql(SQL)=1 then exit;
end;
2: // edit
begin
Sql :='Update T_D_HoliDay Set HOLIDAY_CONTENT='''
+Trim(FlatEdit1.Text)+''',HOLIDAY_DATE='''+NDate+''',HOLIDAY_ODATE='''
+ODate+''',HOLIDAY_FLAG='+DateStyle+' Where HOLIDAY_CODE='+Query_PUB.FieldByName('HOLIDAY_CODE').AsString;
if AnalyzeSql(SQL)=1 then exit;
end;
end;
//Query_Pub.Close;
//Query_Pub.Open;SERVER NAME=doone03
//*************數據同步********************
case kk of
1: // add
Begin
P_Insert :=true;
Query_Pub.insert;
Query_Tmp.close;
Query_Tmp.sql.text :='select nvl(max(HOLIDAY_CODE),0) from T_D_HoliDay';
Query_Tmp.open;
P_CurrentCode :=Query_Tmp.fields[0].asstring;
end;
2: // edit
begin
P_Insert :=true;
Query_Pub.Edit;
end;
end;
if FlatRadioButton_Date.Checked then
begin
Query_Pub.FieldByName('HOLIDAY').asstring :='新歷';
Query_PUB.fieldbyname('HOLIDAY_FLAG').AsString :='0';
end;
if FlatRadioButton_ODate.Checked then
begin
Query_Pub.FieldByName('HOLIDAY').asstring :='農歷';
Query_PUB.fieldbyname('HOLIDAY_FLAG').AsString :='1';
end;
Lstr :=FlatEdit1.text;
Query_Pub.FieldByName('HOLIDAY_CONTENT').asstring :=Lstr;
if NDate<>'' then
begin
Lstr :=copy(NDate,1,2)+'月'+copy(NDate,3,2)+'日';
Query_Pub.FieldByName('NDAY').asstring :=Lstr;
Query_Pub.FieldByName('HOLIDAY_DATE').asstring :=NDate;
end
else
Query_Pub.FieldByName('NDAY').asstring :='';
if ODate<>'' then
begin
Lstr :=copy(ODate,1,2)+'月'+copy(ODate,3,2)+'日';
Query_Pub.FieldByName('ODAY').asstring :=Lstr;
Query_Pub.FieldByName('HOLIDAY_ODATE').asstring :=ODate;
end
else
Query_Pub.FieldByName('ODAY').asstring :='';
Query_PUB.FieldByName('HOLIDAY_CODE').AsString :=P_CurrentCode;
P_Insert :=false;
Query_Pub.Post;
//*****************************************
Fun_ButtonStatus(Self,False);
Fun_ComponentStatus(self,0,False); //--可輸入-- 使輸入框有效,用戶可以輸入數值
Query_PUB.AfterScroll(nil);
DBGrid_PUB.Enabled:=True;
end;
procedure TFrm_SetupFeast.FormShow(Sender: TObject);
begin
inherited;
crypt.UserEnter_Log(Caption, '瀏覽', -1, Gh, '登入窗體');
P_Insert :=false;
Fun_ButtonStatus(Self,False);
Fun_ComponentStatus(self,0,False); //--可輸入-- 使輸入框有效,用戶可以輸入數值
//Query_PUB.AfterScroll(nil);
//修改部分 2001-07-10 ChenQingBo
BitBtnAdd.Enabled:=(JBDM<=2);
BitBtnAlter.Enabled:=(JBDM<=2);
BitBtnDel.Enabled:=(JBDM<=2);
Query_PUBAfterScroll(nil);
// FlatEdit1.Enabled:=(JBDM<=2);
//設置編輯框的狀態
ProcSetPanel(false);
end;
procedure TFrm_SetupFeast.Query_PUBAfterScroll(DataSet: TDataSet);
Var
Holiday :String;
begin
inherited;
if P_Insert then exit;
If not(Query_PuB.bof and Query_PuB.eof) Then
Begin
If Query_PUB.fieldbyname('HOLIDAY_FLAG').AsString='0' Then
Begin
FlatRadioButton_Date.Checked:=True;
Holiday:=Query_PUB.fieldbyname('HOLIDAY_DATE').AsString;
End
Else
Begin
FlatRadioButton_ODate.Checked:=True;
Holiday:=Query_PUB.fieldbyname('HOLIDAY_ODATE').AsString;
End;
FlatCombobox_Month.ItemIndex:=FlatCombobox_Month.Items.IndexOf(Copy(Holiday,1,2));
FlatCombobox_Day.ItemIndex:=FlatCombobox_Day.Items.IndexOf(Copy(Holiday,3,2));
FlatEdit1.Text := Query_PUB.fieldbyname('HOLIDAY_CONTENT').AsString;
P_CurrentCode := Query_PUB.fieldbyname('HOLIDAY_CODE').AsString;
End;
//***********當沒有記錄時要控制按鈕及權限************
If not(Query_PuB.bof and Query_PuB.eof) Then
begin
//
BitBtnAdd.Enabled:=true;
BitBtnAlter.Enabled:=true;
BitBtnDel.Enabled:=true;
//權限
BitBtnAdd.Enabled:=(JBDM<=2);
BitBtnAlter.Enabled:=(JBDM<=2);
BitBtnDel.Enabled:=(JBDM<=2);
end
else
begin
//BitBtnAdd.Enabled:=false;
BitBtnAlter.Enabled:=false;
BitBtnDel.Enabled:=false;
end;
//*******************************************
ProcSetPanel(false);
end;
procedure TFrm_SetupFeast.BitBtnDelClick(Sender: TObject);
var
sql :string;
begin
inherited;
if MessageDlg('是否要刪除該記錄?',mtConfirmation, [mbYes,mbNo], 0)=mrNo then exit;
//if (Application.MessageBox('是否要刪除該記錄?',
// '提示',MB_OKCANCEL)=IDCANCEL) then exit;
Sql:='Delete T_D_HOLIDAY where HOLIDAY_CODE='+#39+
Query_PUB.FieldByName('HOLIDAY_CODE').AsString+#39;
if AnalyzeSql(SQL)=1 then exit;
FlatEdit1.text :='';
Query_Pub.Delete;
//Query_Pub.Close;
//Query_Pub.Open;
Query_PUB.AfterScroll(nil);
end;
procedure TFrm_SetupFeast.BitBtnCancelClick(Sender: TObject);
begin
inherited;
Fun_ButtonStatus(Self,False);
Fun_ComponentStatus(self,0,False); //--可輸入-- 使輸入框有效,用戶可以輸入數值
DBGrid_PUB.Enabled:=True;
Query_PUB.AfterScroll(nil);
end;
procedure TFrm_SetupFeast.FlatRadioButton_ODateClick(Sender: TObject);
begin
Label1.Caption:='農歷日期';
end;
procedure TFrm_SetupFeast.FlatRadioButton_DateClick(Sender: TObject);
begin
Label1.Caption:='新歷日期';
end;
procedure TFrm_SetupFeast.ProcSetPanel(Lflag: boolean);
var
li:integer;
begin
for li:=1 to Frm_SetupFeast.ComponentCount -1 do
begin
if Frm_SetupFeast.Components[li] is TFlatComboBox then
TFlatComboBox(Frm_SetupFeast.Components[li]).enabled :=Lflag;
if Frm_SetupFeast.Components[li] is TFlatRadioButton then
TFlatRadioButton(Frm_SetupFeast.Components[li]).enabled :=Lflag;
if Frm_SetupFeast.Components[li] is TFlatEdit then
TFlatEdit(Frm_SetupFeast.Components[li]).enabled :=Lflag;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -