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

📄 tascomm.pas.svn-base

📁 这是一个功能齐全的,代码完整的ERP企业信息管理系统,现在上传和大家分享
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
unit TasComm;

interface

uses
  Classes, SysUtils, Controls, Windows, Forms, ComCtrls,CommCtrl,DBGrids, DB, 
  Messages, Graphics, ADODB, ActiveX, SYSDATA, CommFun, Dialogs, StdCtrls;

//更新销售定单信息(定单状态)
//AType:  0=项目计划,1=任务计划
Procedure UpdateOrderInfo(AOrderID:string;AType:Integer);
//更新来电记录信息(来电状态)
Procedure UpdateCallInfo(ACallID:string;AType:Integer);
//更新项目计划信息(项目状态、实际工时、完工比率、任务总数、预计开始日期、预计完成日期、实际开始日期、实际完成日期)
Procedure UpdateProjectInfo(AProjID:string);
//更新任务计划信息(实际工时、工单总数、预计开始日期、预计完成日期、实际开始日期、实际完成日期)
procedure UpdateTasksInfo(ATaskID:string);
//更新任务工单信息(实际工时、实际开始日期、实际结束日期)
procedure UpdateWorksInfo(AWorkID:string);

//显示执行人员名称
function GetPersonName(APersonNo:string):string;

//取得所有任务类别
procedure GetAllTasksClass(AcbClass:TComboBox); overload;
//取得所有任务类别
procedure GetAllTasksClass(ADataSet:TADODataSet;AcbClass:TComboBox); overload;
//取得有子任务的电脑编号
function GetChildTask(ATasClass:string):string;

//取得汇报工时表中的员工人数
function GetPersons(APersonNo:String):Integer;

//将汇报工时中的工作时间转换为一天为单位的时间长度
function GetDays(ATimeValue:double):double ;

implementation

//更新销售定单信息(定单状态)
//AType:  0=项目计划,1=任务计划
//项目计划或任务计划新增,修改,删除时调用
Procedure UpdateOrderInfo(AOrderID:string;AType:Integer);
var
  AQty:Double;
  AStatus,ALine:Integer;
  AQuery:TADOQuery;
begin
  if AOrderID='' then Exit;
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  case AType of
    0:SYSDM.qryQuery.SQL.Add('select T500_003 from TAS500 where T500_007=0 and T500_008='+''''+AOrderID+'''');
    1:SYSDM.qryQuery.SQL.Add('select T510_003 from TAS510 where T510_008=0 and T510_009='+''''+AOrderID+'''');
  end;
  SYSDM.qryQuery.Open;
  //定单状态
  //当不存在项目计划或任务计划时,定单状态=新建,否则定单状态=执行,计划状态=完成,则定单状态=完成
  if SYSDM.qryQuery.IsEmpty then
    AStatus:=0   //新建
  else
  begin
    if SYSDM.qryQuery.Fields[0].AsInteger=3 then   //完成
      AStatus:=5   //完成
    else
      AStatus:=1;   //执行
  end;
  if (AStatus<>5) and (IsExists('select 1 from TAS533 where T533_002='+''''+AOrderID+'''')) then AStatus:=2;  //发货
  //更新销售定单状态
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('update ORD510A set O510A_004='+IntToStr(AStatus)+' where O510A_001='+''''+AOrderID+'''');
  SYSDM.qryQuery.ExecSQL;

  //更新销售定单-子表的发货数量
  AQuery:=TADOQuery.Create(nil);
  AQuery.Connection:=SYSDM.ADOC;
  AQuery.Close;
  AQuery.SQL.Clear;
  AQuery.SQL.Add('select T533_002,T533_003,sum(T533_004) as T533_004 from TAS533 where T533_002='+''''+AOrderID+''''+' group by T533_002,T533_003');
  AQuery.Open;
  while not AQuery.Eof do
  begin
    ALine:=AQuery.FieldByName('T533_003').AsInteger;
    AQty:=AQuery.FieldByName('T533_004').AsFloat;
    SYSDM.qryQuery.Close;
    SYSDM.qryQuery.SQL.Clear;
    SYSDM.qryQuery.SQL.Add('update ORD510B set O510B_016='+FloatToStr(AQty)+' where O510B_001='+''''+AOrderID+''''+' and O510B_002='+IntToStr(ALine));
    SYSDM.qryQuery.ExecSQL;
    AQuery.Next;
  end;
  if AQuery.IsEmpty then
  begin
    SYSDM.qryQuery.Close;
    SYSDM.qryQuery.SQL.Clear;
    SYSDM.qryQuery.SQL.Add('update ORD510B set O510B_016=0 where O510B_001='+''''+AOrderID+'''');
    SYSDM.qryQuery.ExecSQL;
  end;
  AQuery.Close;
  AQuery.Free;
end;

//更新来电记录信息(来电状态)
//AType:  0=项目计划,1=任务计划
//项目计划或任务计划新增,修改,删除时调用
Procedure UpdateCallInfo(ACallID:string;AType:Integer);
var
  ACount,AStatus:Integer;
begin
  if ACallID='' then Exit;
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  case AType of
    0:SYSDM.qryQuery.SQL.Add('select count(T500_001) from TAS500 where T500_007=2 and T500_008='+''''+ACallID+'''');
    1:SYSDM.qryQuery.SQL.Add('select count(T510_001) from TAS510 where T510_008=1 and T510_009='+''''+ACallID+'''');
  end;
  SYSDM.qryQuery.Open;
  ACount:=SYSDM.qryQuery.Fields[0].AsInteger;

  //来电状态
  //当不存在任务计划时,来电状态=受理,否则来电状态=待报价 或 待派工
  AStatus:=1;
  if ACount<>0 then
  begin
    //来电记录需要报价,则来电状态=待报价;
    //不需要报价且需要派工,则状态=待派工;
    //不需要派工且不为投诉,则状态=完成
    SYSDM.qryQuery.Close;
    SYSDM.qryQuery.SQL.Clear;
    SYSDM.qryQuery.SQL.Add('select S500_020,S500_027,S100_005 from SER500,SER100 where S500_004=S100_001 and S500_001='+''''+ACallID+'''');
    SYSDM.qryQuery.Open;
    if SYSDM.qryQuery.FieldByName('S500_027').AsBoolean then
      AStatus:=2  //待报价
    else
    begin
      if SYSDM.qryQuery.FieldByName('S500_020').AsBoolean then
        AStatus:=5  //待派工
      else
        if not SYSDM.qryQuery.FieldByName('S100_005').AsBoolean then AStatus:=12;  //完成
    end;
  end;
  //更新来电记录
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('update SER500 set S500_003='+IntToStr(AStatus)+' where S500_001='+''''+ACallID+'''');
  SYSDM.qryQuery.ExecSQL;
end;

//更新项目计划信息(项目状态、实际工时、完工比率、任务总数、预计开始日期、预计完成日期、实际开始日期、实际完成日期)
//任务计划新增、修改、删除时调用
Procedure UpdateProjectInfo(AProjID:string);
var
  ADays,APercent:Double;
  ACount,AStatus:Integer;
  AFromDate,AToDate,AFactFromDate,AFactToDate:TDateTime;
begin
  if AProjID='' then Exit;
  //实际工时
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select sum(T510_013) from TAS510 where T510_008=2 and T510_009='+''''+AProjID+'''');
  SYSDM.qryQuery.Open;
  if (SYSDM.qryQuery.Fields[0].IsNull) or (SYSDM.qryQuery.IsEmpty) then
    ADays:=0
  else
    ADays:=SYSDM.qryQuery.Fields[0].Value;

  //任务总数
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select count(T510_001) from TAS510 where T510_008=2 and T510_009='+''''+AProjID+'''');
  SYSDM.qryQuery.Open;
  if SYSDM.qryQuery.IsEmpty then ACount:=0 else ACount:=SYSDM.qryQuery.Fields[0].Value;

  //项目状态
  if ACount=0 then AStatus:=1 else AStatus:=2;  //当不存在任务计划时,项目状态=计划,否则项目状态=执行
  //如果原項目狀態=完成,則狀態不變
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select T500_003 from TAS500 where T500_001='+''''+AProjID+'''');
  SYSDM.qryQuery.Open;
  if SYSDM.qryQuery.Fields[0].AsInteger=3 then AStatus:=3;
  
  //完工比率
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select sum(T510_014) from TAS510 where T510_008=2 and T510_009='+''''+AProjID+'''');
  SYSDM.qryQuery.Open;
  if SYSDM.qryQuery.IsEmpty then APercent:=0 else APercent:=SYSDM.qryQuery.Fields[0].AsFloat;
  if ACount=0 then APercent:=0 else APercent:=APercent/ACount;
  if AStatus=3 then APercent:=100;

  //预计开始日期
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select top 1 T510_025 from TAS510 where T510_025 is not null and T510_008=2 and T510_009='+''''+AProjID+''''+' order by T510_025');
  SYSDM.qryQuery.Open;
  if (SYSDM.qryQuery.IsEmpty) or (SYSDM.qryQuery.Fields[0].IsNull) then
    AFromDate:=0
  else
    AFromDate:=SYSDM.qryQuery.Fields[0].Value;
  //预计完成日期
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select top 1 T510_026 from TAS510 where T510_026 is not null and T510_008=2 and T510_009='+''''+AProjID+''''+' order by T510_025 desc');
  SYSDM.qryQuery.Open;
  if (SYSDM.qryQuery.IsEmpty) or (SYSDM.qryQuery.Fields[0].IsNull) then
    AToDate:=0
  else
    AToDate:=SYSDM.qryQuery.Fields[0].Value;
  //实际开始日期
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select top 1 T510_027 from TAS510 where T510_027 is not null and T510_008=2 and T510_009='+''''+AProjID+''''+' order by T510_027');
  SYSDM.qryQuery.Open;
  if (SYSDM.qryQuery.IsEmpty) or (SYSDM.qryQuery.Fields[0].IsNull) then
    AFactFromDate:=0
  else
    AFactFromDate:=SYSDM.qryQuery.Fields[0].Value;
  //实际完成日期
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select top 1 T510_028 from TAS510 where T510_028 is not null and T510_008=2 and T510_009='+''''+AProjID+''''+' order by T510_027 desc');
  SYSDM.qryQuery.Open;
  if (SYSDM.qryQuery.IsEmpty) or (SYSDM.qryQuery.Fields[0].IsNull) then
    AFactToDate:=0
  else
    AFactToDate:=SYSDM.qryQuery.Fields[0].Value;

  //更新项目计划信息(项目状态、实际工时、完工比率、任务总数)
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select * from TAS500 where T500_001='+''''+AProjID+'''');
  SYSDM.qryQuery.Open;
  SYSDM.qryQuery.Edit;
  SYSDM.qryQuery.FieldByName('T500_003').Value:=AStatus;  //项目状态
  SYSDM.qryQuery.FieldByName('T500_012').Value:=ADays;  //实际工时
  SYSDM.qryQuery.FieldByName('T500_013').Value:=APercent;  //完工比率
  SYSDM.qryQuery.FieldByName('T500_014').Value:=ACount;  //任务总数
  if (SYSDM.qryQuery.FieldByName('T500_024').AsString='') and (AFromDate<>0) then
    SYSDM.qryQuery.FieldByName('T500_024').Value:=AFromDate;  //预计开始日期
  if (SYSDM.qryQuery.FieldByName('T500_025').AsString='') and (AToDate<>0) then
    SYSDM.qryQuery.FieldByName('T500_025').Value:=AToDate;  //预计完成日期
  if AFactFromDate=0 then SYSDM.qryQuery.FieldByName('T500_026').AsString:='' else SYSDM.qryQuery.FieldByName('T500_026').Value:=AFactFromDate;  //实际开始日期
  if AFactToDate=0 then SYSDM.qryQuery.FieldByName('T500_027').AsString:='' else if AStatus=3 then SYSDM.qryQuery.FieldByName('T500_027').Value:=AFactToDate;  //实际完成日期
  SYSDM.qryQuery.Post;
end;

//更新任务计划信息(实际工时、工单总数、预计开始日期、预计完成日期、实际开始日期、实际完成日期)
//任务工单新增、修改、删除时调用
//ATaskID:任务计划编号
procedure UpdateTasksInfo(ATaskID:string);
var
  ADays:Double;
  ACount,AStatus,AClass:Integer;
  AOrderID:string;
  AFromDate,AToDate,AFactFromDate,AFactToDate:TDateTime;
  ADate:TDateTime;
  ACust,AItem:Integer;
  AMacNo:String;
  AYear,AMonth,ADay:Word;
  AInsDate,AEndDate:string;
begin
  if ATaskID='' then Exit;
  //实际工时
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select sum(T520_008) from TAS520 where T520_002='+''''+ATaskID+'''');
  SYSDM.qryQuery.Open;
  if (SYSDM.qryQuery.Fields[0].IsNull) or (SYSDM.qryQuery.IsEmpty) then
    ADays:=0
  else
    ADays:=SYSDM.qryQuery.Fields[0].Value;

  //工单总数
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select count(T520_001) from TAS520 where T520_002='+''''+ATaskID+'''');
  SYSDM.qryQuery.Open;
  if SYSDM.qryQuery.IsEmpty then ACount:=0 else ACount:=SYSDM.qryQuery.Fields[0].Value;

  //设置任务状态
  //当删除了所有的工单后,任务状态=计划
  if ACount=0 then
  begin
    AStatus:=1;
  end else
  begin
    //当有新工单建立时,任务状态=执行,否则任务状态=最后一张汇报单的后续处理状态
    AStatus:=2;   //任务状态=执行
    SYSDM.qryQuery.Close;
    SYSDM.qryQuery.SQL.Clear;
    SYSDM.qryQuery.SQL.Add('select T520_001 from TAS520 where T520_002='+''''+ATaskID+''''+' and T520_001 not in');
    SYSDM.qryQuery.SQL.Add('(select distinct A.T520_001 from TAS520 A, TAS530 B where A.T520_001=B.T530_002 and A.T520_002='+''''+ATaskID+''''+')');
    SYSDM.qryQuery.Open;
    if SYSDM.qryQuery.IsEmpty then
    begin
      SYSDM.qryQuery.Close;
      SYSDM.qryQuery.SQL.Clear;
      SYSDM.qryQuery.SQL.Add('select top 1 B.T530_010 from TAS520 A, TAS530 B where A.T520_001=B.T530_002 and A.T520_002='+''''+ATaskID+''''+' order by B.T530_005 desc');
      SYSDM.qryQuery.Open;
      AStatus:=SYSDM.qryQuery.FieldByName('T530_010').Value;
    end;
  end;

  //预计开始日期
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select top 1 T520_006 from TAS520 where T520_006 is not null and T520_002='+''''+ATaskID+''''+' order by T520_006');
  SYSDM.qryQuery.Open;
  if (SYSDM.qryQuery.IsEmpty) or (SYSDM.qryQuery.Fields[0].IsNull) then
    AFromDate:=0
  else
    AFromDate:=SYSDM.qryQuery.Fields[0].Value;
  //预计完成日期
  SYSDM.qryQuery.Close;
  SYSDM.qryQuery.SQL.Clear;
  SYSDM.qryQuery.SQL.Add('select top 1 T520_007 from TAS520 where T520_007 is not null and T520_002='+''''+ATaskID+''''+' order by T520_006 desc');
  SYSDM.qryQuery.Open;
  if (SYSDM.qryQuery.IsEmpty) or (SYSDM.qryQuery.Fields[0].IsNull) then
    AToDate:=0
  else
    AToDate:=SYSDM.qryQuery.Fields[0].Value;
  //实际开始日期

⌨️ 快捷键说明

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