⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ss_grpkccsh.pas

📁 省级集邮品管理ERP
💻 PAS
📖 第 1 页 / 共 3 页
字号:
      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 + -