?? ss_grpkccsh.pas
字號:
while not Bof do
begin
if FieldByName('TS').AsInteger <> 0 then
begin
l_PPDM := FieldByName('TDM').AsString;
l_JJ := FieldByName('JJ').AsFloat;
Have_Find := True;
Break;
end;
Prior;
end;
end;
lbl_Search.Visible := False;
pgb_State.Visible := True;
lbl_State.Visible := True;
lbl_State.Caption := '正在保存...';
lbl_State.Refresh;
pgb_State.Max := RecordCount;
i := 0;
cur_pos := GetBookmark;
try
Database.StartTransaction;
First;
while not Eof do
begin
if FieldByName('Temp').AsInteger = 1 then
begin
{如果寫入數據庫,則判斷進價和銷價是否符合}
Can_Continue := True;
l_failPPDM := FieldByName('TDM').AsString; //by jillshao 2002-04-05
l_failJJ := FieldByName('JJ').AsFloat; //by jillshao 2002-04-05
{當輸入套數為0時刪除原來的記錄,石玉琢增加,避免出現沒有輸入一個票品的進價而僅僅輸入數量時出現的提示2002.04.04}
{ if FieldByName('TS').AsInteger = 0 then
begin
if Delete_Cur_Record = False then
begin
Can_Continue := False;
if Database.InTransaction then
Database.Rollback;
ds_init.DataSet := qry_init;
DoFailLocate;
CHQMsgBox('更新庫存出錯!');
end
else
Continue;
end; }
if FieldByName('TS').AsFloat <> 0 then
begin
if Test_JJ = False then
begin
Can_Continue := False;
if Database.InTransaction then
Database.Rollback;
ds_init.DataSet := qry_init;
DoFailLocate;
CHQMsgBox('同一票品進價不能相同!');
end;
if Test_XJ = False then
begin
Can_Continue := False;
if Database.InTransaction then
Database.Rollback;
ds_init.DataSet := qry_init;
DoFailLocate;
CHQMsgBox('其他庫房已經存在該票品的不同銷價!其價格為:' + FloatToStr(qry_Tmp.FieldByName('XJ').AsFloat / 100) + '元');
end;
if Can_Continue = False then
begin
if not (dgAlwaysShowEditor in rxdb_Init.Options) then
begin
rxdb_Init.Options := rxdb_Init.Options + [dgAlwaysShowEditor];
rxdb_Init.Options := rxdb_Init.Options - [dgAlwaysShowEditor];
end;
rxdb_Init.SetFocus;
FreeBookmark(cur_pos);
EnableControls;
pgb_State.Visible := False;
lbl_State.Visible := False;
lbl_Search.Visible := True;
Result := False;
Exit;
end;
end;
{符合條件,輸入數據庫}
Update_Record; {更新庫存記錄} {}
end;
pgb_State.Position := i;
i := i + 1;
Next;
end;
Delete_Record; {刪除庫存為0的記錄} {}
Database.Commit;
except
if Database.InTransaction then
Database.Rollback;
ds_init.DataSet := qry_init;
FreeBookmark(cur_pos);
pgb_State.Visible := False;
lbl_State.Visible := False;
lbl_Search.Visible := True;
ds_init.DataSet := qry_init;
EnableControls;
CHQMsgBox('數據初始化錯誤!可能是因為相同票品不同進價設置引起的,請重新設置相同票品不同進價,詳細內容請查看幫助。');
Result := False;
Exit;
end;
Call_StoreProc; {調用存儲過程,更新其他表,本步驟不加在事務內,同時出錯不顯式提示} {}
GotoBookmark(cur_pos);
FreeBookmark(cur_pos);
pgb_State.Visible := False;
lbl_State.Visible := False;
lbl_Search.Visible := True;
ds_init.DataSet := qry_init;
EnableControls;
Set_State(0);
end;
Show_Data;
if Have_Find = True then
begin
qry_Init.Locate('TDM', l_PPDM, [loCaseInsensitive]);
qry_Init.Locate('TDM;JJ', VarArrayOf([l_PPDM, l_JJ]), [loCaseInsensitive]);
end;
Result := True;
end;
{-------------------------------------------------------------------------------}
{判斷進價是否存在相同的}
function Tfrm_GRPKCCSH.Test_JJ: Boolean;
var
test_pos: Pointer;
l_PPDM: string;
l_JJ: Double;
begin
with qry_init do
begin
test_pos := GetBookmark;
try
l_PPDM := FieldByName('TDM').AsString;
l_JJ := FieldByName('JJ').AsFloat;
while not Eof do
begin
Next;
if Eof then Break;
if l_PPDM <> FieldByName('TDM').AsString then break;
if l_JJ = FieldByName('JJ').AsFloat then
begin
{查找新增項目}
if FieldByName('JJ').OldValue <> NULL then
GotoBookmark(test_pos);
{設置處于編輯狀態}
rxdb_Init.SelectedIndex := 4;
Result := False;
Exit;
end;
end;
GotoBookmark(test_pos);
while not Bof do
begin
Prior;
if Bof then Break;
if l_PPDM <> FieldByName('TDM').AsString then break;
if l_JJ = FieldByName('JJ').AsFloat then
begin
{查找新增項目}
if FieldByName('JJ').OldValue <> NULL then
GotoBookmark(test_pos);
{設置處于編輯狀態}
rxdb_Init.SelectedIndex := 4;
Result := False;
Exit;
end;
end;
GotoBookmark(test_pos);
finally
FreeBookmark(test_pos);
end;
end;
Result := True;
end;
{-------------------------------------------------------------------------------}
{測試銷價,是否在其他庫房中存在不同進價}
function Tfrm_GRPKCCSH.Test_XJ: Boolean;
var
l_KFDM: string;
begin
l_KFDM := fcb_KF.FieldString;
with qry_Tmp do
begin
Close;
SQL.Text := 'Select XJ from TYS_GRPPKC where PPDM=''' + qry_init.FieldByName('TDM').AsString + '''and KFDM<>''' + l_KFDM + ''' and XJ<>' + FloatToStr(qry_init.FieldByName('XJ').AsFloat);
Open;
end;
if qry_Tmp.IsEmpty = False then
begin
{設置處于編輯狀態}
rxdb_Init.SelectedIndex := 5;
if not (dgAlwaysShowEditor in rxdb_Init.Options) then
begin
rxdb_Init.Options := rxdb_Init.Options + [dgAlwaysShowEditor];
rxdb_Init.Options := rxdb_Init.Options - [dgAlwaysShowEditor];
end;
rxdb_Init.SetFocus;
Result := False;
exit;
end;
Result := True;
end;
{-------------------------------------------------------------------------------}
{向數據庫中插入不為0的數據}
function Tfrm_GRPKCCSH.Update_Record: Boolean;
const
Find_SQL = 'Select Count(*) as Data_Count from TYS_GRPPKC where KFDM=''%s'' and PPDM=''%s'' and JJ=%f';
Insert_SQL = 'Insert into TYS_GRPPKC (KFDM,PPDM,JJ,KWH,YJ,XJ,JSJ,ZK,TS) values(''%s'',''%s'',%f,''%s'',0,%f,%f,%f,%d)';
Update_SQL = 'update TYS_GRPPKC set KWH=''%s'',JJ=%f,XJ=%f,JSJ=%f,ZK=%f,TS=%d where KFDM=''%s'' and PPDM=''%s'' and JJ=%f';
var
l_oldJJ, l_JJ, l_XJ, l_JSJ, l_ZK: Double;
l_TS: Integer;
l_PPDM, l_KFDM, l_KWH: string;
SQLString: string;
begin
l_PPDM := qry_init.FieldByName('TDM').AsString;
l_KFDM := fcb_KF.FieldString;
l_JJ := qry_init.FieldByName('JJ').AsFloat;
l_XJ := qry_init.FieldByName('XJ').AsFloat;
l_JSJ := qry_init.FieldByName('JSJ').AsFloat;
l_ZK := qry_init.FieldByName('ZK').AsFloat;
l_TS := qry_init.FieldByName('TS').AsInteger;
l_KWH := qry_init.FieldByName('KWH').AsString;
{決定是插入還是修改}
if qry_init.FieldByName('PPDM').AsString = '' then {插入}
SQLString := Format(Insert_SQL, [l_KFDM, l_PPDM, l_JJ, l_KWH, l_XJ, l_JSJ, l_ZK, l_TS])
else
begin
try
l_oldJJ := qry_init.FieldByName('JJ').OldValue;
except
l_oldJJ := 0;
end;
SQLString := Format(Update_SQL, [l_KWH, l_JJ, l_XJ, l_JSJ, l_ZK, l_TS,
l_KFDM, l_PPDM, l_oldJJ]);
end;
with qry_Tmp do
begin
Close;
SQL.Text := SQLString;
ExecSQL;
end;
Result := True;
end;
{-------------------------------------------------------------------------------}
{石玉琢增加,為的是避免沒有維護進價單獨維護數量而導致提示銷價必須相同}
{刪除當前套數為0的記錄}
function Tfrm_GRPKCCSH.Delete_Cur_Record: Boolean;
var
l_PPDM, l_KFDM: string;
l_oldJJ: Double;
begin
Result := False;
l_PPDM := qry_init.FieldByName('TDM').AsString;
l_KFDM := fcb_KF.FieldString;
try
l_oldJJ := qry_init.FieldByName('JJ').OldValue;
except
l_oldJJ := 0;
end;
try
with qry_Tmp do
begin
Close;
SQL.Text := 'Delete TYS_JYPPKC Where KFDM= ''' + l_KFDM + ''' and PPDM=''' + l_PPDM + ''' and JJ=' + FloatToStr(l_oldJJ);
ExecSQL;
end;
Result := True;
except
Exit;
end;
end;
{-------------------------------------------------------------------------------}
{從數據庫中刪除為0的記錄}
function Tfrm_GRPKCCSH.Delete_Record: Boolean;
begin
with qry_Tmp do
begin
Close;
SQL.Text := 'Delete TYS_GRPPKC where Ts=0';
ExecSQL;
end;
Result := True;
end;
{調用存儲過程,更新其他表,本步驟不加在事務內,同時出錯不顯式提示}
function Tfrm_GRPKCCSH.Call_StoreProc: Boolean;
begin
try
with sp_Init do
begin
Close;
ParamByName('PC_DWDM').AsString := VG_UNITID;
ParamByName('PC_USERID').AsString := VG_UserID;
ParamByName('PN_FLG').AsFloat := 0;
ExecProc;
end;
except
CHQMsgBox('數據庫內部處理出錯!請與程序供應商聯系。錯誤為:存儲過程JYP_CSH_WC');
Result := False;
Exit;
end;
Result := True;
end;
{-------------------------------------------------------------------------------}
{啟動時顯示默認的所有數據}
procedure Tfrm_GRPKCCSH.FormShow(Sender: TObject);
begin
{初始化所有參數}
Init_Search_CSH;
DWMC.Caption := '使用單位:' + VG_UnitName;
Find_SQL := '';
lbl_Search.Caption := '顯示條件——所有數據';
qry_initTS.DisplayFormat := '#,##';
Show_Data;
{設置界面狀態,如果已經初始化或者初始化完成,則不能修改}
if Judge_Modify = False then
Set_State(2)
else
Set_State(0);
end;
{如果處于修改狀態,則退出時給出提示,詢問是否退出}
procedure Tfrm_GRPKCCSH.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if Edit_State = 1 then
if CHQMsgBox('正處于修改狀態,真的要退出嗎?', 2) = mrNo then
CanClose := False;
end;
{-------------------------------------------------------------------------------}
procedure Tfrm_GRPKCCSH.edt_LocateKeyPress(Sender: TObject; var Key: Char);
begin
if qry_init.Active = True then
begin
if Key in ['a'..'z'] then Key := Chr(Ord(key) + Ord('A') - Ord('a'));
qry_init.Locate('ZH', edt_Locate.Text + Key, [loCaseInsensitive, loPartialKey]);
end
else
Key := Chr(0);
end;
{---------------------------------功能按鈕--------------------------------------}
{保存初始化數據}
procedure Tfrm_GRPKCCSH.bbtn_SaveClick(Sender: TObject);
begin
Save_Init_Data;
end;
{取消保存初始化數據}
procedure Tfrm_GRPKCCSH.bbtn_CancelClick(Sender: TObject);
begin
Cancel_Init_Data;
end;
{修改}
procedure Tfrm_GRPKCCSH.bbtn_EditClick(Sender: TObject);
begin
qry_init.Edit;
Set_State(1);
rxdb_Init.SetFocus;
if rxdb_Init.SelectedIndex < 4 then
rxdb_Init.SelectedIndex := 4;
{
if not (dgAlwaysShowEditor in rxdb_Init.Options) then
begin
rxdb_Init.Options := rxdb_Init.Options + [dgAlwaysShowEditor];
rxdb_Init.Options := rxdb_Init.Options - [dgAlwaysShowEditor];
end;
}
end;
{增加同一票品不同進價}
procedure Tfrm_GRPKCCSH.bbtn_AddClick(Sender: TObject);
begin
Add_Init_Data;
end;
{批處理修改數據}
procedure Tfrm_GRPKCCSH.bbtn_ReplaceClick(Sender: TObject);
begin
Set_Data;
end;
{打印初始化數據}
procedure Tfrm_GRPKCCSH.bbtn_PrintClick(Sender: TObject);
begin
try
qry_init.Filter := 'TS<>0 and TS<>NULL';
qry_init.Filtered := True;
PrintDBGridEh(rxdb_Init, RxLbl_Title.Caption);
finally
qry_init.Filtered := False;
end;
end;
procedure Tfrm_GRPKCCSH.rxdb_InitDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
if qry_initTS.AsInteger > 0 then
if (gdSelected in State) and (rxdb_Init.Focused = True) then
rxdb_Init.Canvas.Font.Color := clWhite
else
rxdb_Init.Canvas.Font.Color := $00A56E3A;
rxdb_Init.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
procedure Tfrm_GRPKCCSH.rxdb_InitGetFooterParams(Sender: TObject; DataCol,
Row: Integer; Column: TColumnEh; AFont: TFont; var Background: TColor;
var Alignment: TAlignment; State: TGridDrawState; var Text: string);
begin
try
if (UpperCase(Column.Field.FieldName) = 'JJJE') or
(UpperCase(Column.Field.FieldName) = 'XJJE') or
(UpperCase(Column.Field.FieldName) = 'MZJE') then
if Text = '' then
Text := '0'
else
Text := FormatFloat('#,##0.00##', StrToFloat(Text) / 100)
except
end;
if (Column.FieldName = 'TMC') then
Text := '記錄數: ' + Text;
if (Column.FieldName = 'ZH') then
Text := '合 計';
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -