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

📄 frm_customeredit.pas

📁 这是一个基于delphi平台的物流空运管理系统!
💻 PAS
📖 第 1 页 / 共 2 页
字号:

  for I := 0 to MemCount - 1 do
  begin
    MemCusBillName[i].Destroy;
  end;
  MemCount := 0;

  BtnAdd.Enabled := False;
  IsEdit := False;
  CusCode := '';
  EdtCusCode.SetFocus;
end;

procedure TFrmCustomerEdit.BtnSaveClick(Sender: TObject);
var
  SqlStr: string;
  ArrayCount: Integer;
  ValueArray: array[0..20] of string;
  I: Integer;
begin
  inherited;
  if FrmMain.IncludeValue('客户档案维护') then
  else
  begin
    ShowMessage('对不起,你不具有该操作的权限!');
    exit;
  end;

  if EdtCusCode.Text = '' then
  begin
    ShowMessage('对不起,客户代码不能够为空,请检查!');
    EdtCusCode.SetFocus;
    Exit;
  end;

  if EdtCusCName.Text = '' then
  begin
    ShowMessage('对不起,客户中文名称不能够为空,请检查!');
    EdtCusCName.SetFocus;
    Exit;
  end;

  if EdtCusName.Text = '' then
  begin
    ShowMessage('对不起,客户英文名称不能够为空,请检查!');
    EdtCusName.SetFocus;
    Exit;
  end;

  CusTypeDesc := '';
  if ChkShipper.Checked then
    if CusTypeDesc = '' then
      CusTypeDesc := '''发货人'''
    else
      CusTypeDesc := CusTypeDesc + ',' + '''发货人''';

  if ChkConsignee.Checked then
    if CusTypeDesc = '' then
      CusTypeDesc := '''收货人'''
    else
      CusTypeDesc := CusTypeDesc + ',' + '''收货人''';

  if ChkAgent.Checked then
    if CusTypeDesc = '' then
      CusTypeDesc := '''目的港代理'''
    else
      CusTypeDesc := CusTypeDesc + ',' + '''目的港代理''';

  if ChkCoLoad.Checked then
    if CusTypeDesc = '' then
      CusTypeDesc := '''CoLoad公司'''
    else
      CusTypeDesc := CusTypeDesc + ',' + '''CoLoad公司''';

  if IsEdit then
  begin
    if CusCode = EdtCusCode.text then
    else
    begin
      if (FrmMain.CheckExistCount('ShipperCode', CusCode, 'FileTable') > 0) or
        (FrmMain.CheckExistCount('ConsignCode', CusCode, 'FileTable') > 0)
        or (FrmMain.CheckExistCount('CusCode', CusCode, 'FareInfo') > 0)
        or (FrmMain.CheckExistCount('CusCode', CusCode, 'RealFareInfo') > 0)
          then
      begin
        ShowMessage('对不起,该客户代码已经使用,不能够在此进行修改,操作取消!');
        EdtCusCode.Text := CusCode;
        EdtCusCode.SetFocus;
        Exit;
      end;

      if FrmMain.CheckExistCount('CusCode', EdtCusCode.Text, 'CustomerInfo') >= 1
        then
      begin
        ShowMessage('对不起,客户代码重复,请检查重新录入!');
        EdtCusCode.SetFocus;
        Exit;
      end;
    end;
  end
  else
  begin
    if FrmMain.CheckExistCount('CusCode', EdtCusCode.Text, 'CustomerInfo') >= 1
      then
    begin
      ShowMessage('对不起,客户代码已经存在,请检查重新录入!');
      EdtCusCode.SetFocus;
      Exit;
    end;
  end;

  try
    FrmMain.UseDB.BeginTrans;
    SqlStr := '';
    if IsEdit then
    begin
      FrmMain.UpStr(SqlStr, 'CustomerInfo');
      FrmMain.UpStr(SqlStr, 'CusCode', EdtCusCode.text, ',');
      FrmMain.UpStr(SqlStr, 'CusName', EdtCusName.text, ',');
      FrmMain.UpStr(SqlStr, 'CusCName', EdtCusCName.text, ',');
      FrmMain.UpStr(SqlStr, 'CusAddress', MemCusYAddress.text, ',');
      FrmMain.UpStr(SqlStr, 'CusType', CmbCusType.text, ',');
      FrmMain.UpStr(SqlStr, 'CusPost', EdtCusPost.text, ',');
      FrmMain.UpStr(SqlStr, 'CusCAddress', EdtCusCAddress.text, ',');
      FrmMain.UpStr(SqlStr, 'CusTele', EdtCusTele.text, ',');
      FrmMain.UpStr(SqlStr, 'CusFax', EdtCusFax.text, ',');
      FrmMain.UpStr(SqlStr, 'CusRelation', EdtCusRelation.text, ',');
      FrmMain.UpStr(SqlStr, 'CusTradeType', CmbCusTradeType.text, ',');
      FrmMain.UpStr(SqlStr, 'CountryCode',
        FrmMain.GetFieldText(CmbCountryCode.text), ',');
      FrmMain.UpStr(SqlStr, 'ProviceCode',
        FrmMain.GetFieldText(CmbProviceCode.text), ',');
      FrmMain.UpStr(SqlStr, 'CusEmail', EdtCusEmail.text, ',');
      FrmMain.UpStr(SqlStr, 'CusRmbAccount', EdtCusRmbAccount.text, ',');
      FrmMain.UpStr(SqlStr, 'CusDollarAccount', EdtCusDollarAccount.text, ',');
      FrmMain.UpStr(SqlStr, 'AgentCity', CmbAgentCity.text, ',');
      FrmMain.UpStr(SqlStr, 'AgentComm', CmbAgentComm.text, ',');
      FrmMain.UpStr(SqlStr, 'AgentAc', CmbAgentAc.text, ',');
      FrmMain.UpStr(SqlStr, 'AgentTerms', MemAgentTerms.lines.Text, ',');
      FrmMain.UpStr(SqlStr, 'ForeignSource', CmbForeignSource.text, ',');
      FrmMain.UpStr(SqlStr, 'ForeignRequest', MemForeignRequest.lines.text,
        ',');
      FrmMain.UpStr(SqlStr, 'AgentType', CmbAgentType.text, ',');
      FrmMain.UpStr(SqlStr, 'CusTypeDesc', CusTypeDesc, ',');
      FrmMain.UpStr(SqlStr, 'Bank', EdtBank.text, '');
      FrmMain.UpStr(SqlStr, 'CusCode=', CusCode, 'w');
      if FrmMain.ExecSQL(SqlStr) then
      else
      begin
        ShowMessage('对不起,客户记录更新失败!');
        FrmMain.Usedb.RollbackTrans;
        Exit;
      end;

      ValueArray[0] := EdtCusCode.Text;
      ValueArray[1] := EdtCusName.Text;
      ValueArray[2] := EdtCusCName.Text;
      ValueArray[3] := CmbCusType.Text;
      ValueArray[4] := EdtCuscAddress.Text;
      ValueArray[5] := EdtCusTele.Text;
      ValueArray[6] := EdtCusFax.Text;
      ValueArray[7] := EdtCusRelation.Text;
      ValueArray[8] := EdtCusEMail.Text;
      ArrayCount := 8;

      CusCode := EdtCusCode.text;
      FrmMain.RefeshOne(ValueArray, ArrayCount, FrmCustomerInfo.lv);
      //添加CusttomerBillName

      for i := 0 to MemCount - 1 do
      begin
        //删除
        if Copy(CusBillID[I], 1, 1) = 'D' then
        begin
          Delete(CusBillID[I], 1, 1);
          SqlStr := 'Delete From CustomerBillName where ID=' + CusBillID[I];
          Frmmain.ExecSql(SqlStr);
        end
        else
        begin
          //增加
          if Copy(CusBillID[I], 1, 1) = 'A' then
          begin
            SqlStr := 'Insert into CustomerBillName(CusCode,CusBillName) ' +
              ' values(''' + CusCode + ''',''' + MemCusBillName[I].Lines.text +
                ''')';
            Frmmain.ExecSql(SqlStr);
            CusBillID[I] := Inttostr(Frmmain.GetLastIdentify);
          end
          else
          begin
            SqlStr := 'Update CustomerBillName Set CusCode=''' + EdtCusCode.Text
              + ''',CusBillName=''' + MemCusBillName[I].Lines.text + ''' where ID='
              + CusBillID[I];
            Frmmain.ExecSql(SqlStr);
          end;
        end;
      end;

      Frmmain.Usedb.CommitTrans;
    end
    else
    begin
      SqlStr := 'Insert into CustomerInfo(CusCode,CusName,CusCName,' +
        'CusAddress,CusTypeDesc,CusType,CusPost,CusCAddress,CusTele,CusFax,' +
        'CusRelation,CusTradeType,CountryCode,ProviceCode,CusEmail,' +
        'CusRmbAccount,CusDollarAccount,' +
        'AgentCity,AgentComm,AgentAc,AgentTerms,' +
        'ForeignSource,ForeignRequest,AgentType,Bank) values(';
      Frmmain.InsStr(SqlStr, EdtCusCode.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusName.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusCName.text, ',');
      Frmmain.InsStr(SqlStr, MemCusYAddress.Lines.text, ',');
      Frmmain.InsStr(SqlStr, CusTypeDesc, ',');
      Frmmain.InsStr(SqlStr, CmbCusType.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusPost.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusCAddress.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusTele.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusFax.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusRelation.text, ',');
      Frmmain.InsStr(SqlStr, CmbCusTradeType.text, ',');
      Frmmain.InsStr(SqlStr, Frmmain.GetfieldText(CmbCountryCode.text), ',');
      Frmmain.InsStr(SqlStr, Frmmain.GetfieldText(CmbProviceCode.text), ',');
      Frmmain.InsStr(SqlStr, EdtCusEmail.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusRmbAccount.text, ',');
      Frmmain.InsStr(SqlStr, EdtCusDollarAccount.text, ',');
      Frmmain.InsStr(SqlStr, CmbAgentCity.text, ',');
      Frmmain.InsStr(SqlStr, CmbAgentComm.text, ',');
      Frmmain.InsStr(SqlStr, CmbAgentAc.text, ',');
      Frmmain.InsStr(SqlStr, MemAgentTerms.Lines.text, ',');
      Frmmain.InsStr(SqlStr, CmbForeignSource.text, ',');
      Frmmain.InsStr(SqlStr, MemForeignRequest.lines.text, ',');
      Frmmain.InsStr(SqlStr, CmbAgentType.text, ',');
      Frmmain.InsStr(SqlStr, EdtBank.text, '');
      if Frmmain.ExecSQL(SqlStr) then
      else
      begin
        ShowMessage('对不起,客户档案插入记录失败,请检查!');
        exit;
      end;

      IsEdit := true;
      BtnAdd.Enabled := True;

      ValueArray[0] := EdtCusCode.Text;
      ValueArray[1] := EdtCusName.Text;
      ValueArray[2] := EdtCusCName.Text;
      ValueArray[3] := CmbCusType.Text;
      ValueArray[4] := EdtCuscAddress.Text;
      ValueArray[5] := EdtCusTele.Text;
      ValueArray[6] := EdtCusFax.Text;
      ValueArray[7] := EdtCusRelation.Text;
      ValueArray[8] := EdtCusEMail.Text;
      ArrayCount := 8;
      FrmMain.AddListView(ValueArray, ArrayCount, FrmCustomerInfo.lv);
      CusCode := EdtCusCode.Text;

      //添加CusttomerBillName

      for i := 0 to MemCount - 1 do
      begin
        if Copy(CusBillID[I], 1, 1) = 'A' then
        begin
          SqlStr := 'Insert into CustomerBillName(CusCode,CusBillName) values('''
            + CusCode + ''',''' + MemCusBillName[I].Lines.text + ''')';
          FrmMain.ExecSql(SqlStr);
          CusBillID[I] := Inttostr(FrmMain.GetLastIdentify);
        end;
      end;

      FrmMain.Usedb.CommitTrans;
    end;
  except
    ShowMessage('客户档案操作进行失败,请检查!');
    FrmMain.UseDb.RollbackTrans;
    exit;
  end;

end;

procedure TFrmCustomerEdit.BtnCloseClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TFrmCustomerEdit.FormDestroy(Sender: TObject);
begin
  inherited;
  FrmCustomerEdit:=nil;
end;

procedure TFrmCustomerEdit.NAddClick(Sender: TObject);
begin
  inherited;

  MemCount := MemCount + 1;
  SetLength(MemCusBillName, MemCount);
  SetLength(CusBillID, MemCount);
  MemCusBillName[MemCount - 1] := TMemo.Create(Self);
  MemCusBillName[MemCount - 1].Parent := CoolScrollCustomer;
  MemCusBillName[MemCount - 1].ScrollBars := ssVertical;
  MemCusBillName[MemCount - 1].Align := alTop;
  MemCusBillName[MemCount - 1].Height := 50;
  MemCusBillName[MemCount - 1].Lines.Text := '';
  MemCusBillName[MemCount - 1].Tag := MemCount - 1;
  MemCusBillName[MemCount - 1].OnDblClick := MemDblClick;
  MemCusBillName[MemCount - 1].SetFocus;
  CusBillID[MemCount - 1] := 'A';
end;

procedure TFrmCustomerEdit.NDelClick(Sender: TObject);
begin
  inherited;
if FrmCustomerEdit.ActiveControl = nil then
  begin
    ShowMessage('请先选中要删除的提单客户内容,然后再删除!');
    Exit;
  end;

  if FrmCustomerEdit.ActiveControl.Parent = CoolScrollCustomer then
  else
  begin
    ShowMessage('请先选中要删除的提单客户内容,然后再删除!');
    Exit;
  end;

  CusBillID[(Self.ActiveControl as TMemo).Tag] := 'D' + CusBillID[(Self.ActiveControl as TMemo).Tag];
  (Self.ActiveControl as TMemo).Visible := false;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -