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

📄 unit6.pas

📁 材料管理系统
💻 PAS
字号:
unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls,ADODB,DateUtils;

type

  Tfrmduixiaodengji = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit2: TEdit;
    Label4: TLabel;
    Edit3: TEdit;
    Label5: TLabel;
    Edit4: TEdit;
    Label6: TLabel;
    DateTimePicker1: TDateTimePicker;
    Label7: TLabel;
    Edit5: TEdit;
    Button1: TButton;
    Edit6: TEdit;
    Memo1: TMemo;
    Label8: TLabel;
    ComboBox1: TComboBox;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Edit3KeyPress(Sender: TObject; var Key: Char);
    procedure Edit4KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
    procedure Edit3Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function IsEmpty(const Scr:string): boolean;
    function IsNotNumric(const ScrString:string):boolean;
    procedure Clear();
//    procedure DataToCombobox1();
  end;

var
  frmduixiaodengji: Tfrmduixiaodengji;

implementation
Uses Unit2;

{$R *.dfm}
//procedure TFrmduixiaodengji.DataToCombobox1();
//begin
//  ComboBox1.Items.Add('只');
//  Combobox1.Items.Add('把');
//  Combobox1.Items.Add('根');
//  Combobox1.Items.Add('张');
//  Combobox1.Items.Add('包');
//  Combobox1.Items.Add('箱');
//  Combobox1.Items.Add('盒');
//  Combobox1.Items.Add('瓶');
//  Combobox1.Items.Add('本');
//  Combobox1.Items.Add('袋');
//  Combobox1.Items.Add('块');
//  Combobox1.Items.Add('双');
//  Combobox1.Items.Add('卷');
//  Combobox1.Items.Add('付');
//  Combobox1.Items.Add('套');
//  Combobox1.Items.Add('KG');
//  Combobox1.Items.Add('克');
//  Combobox1.Items.Add('in2');
//  Combobox1.Items.Add('节');
//end;

procedure TFrmduixiaodengji.Clear();
begin
  Edit6.clear;
  Edit5.clear;
  Combobox1.Clear;
  Edit2.clear;
  Edit3.clear;
  Edit4.clear;
  Memo1.Clear;
end;

function Tfrmduixiaodengji.IsNotNumric(const ScrString:string):boolean;
var
  c:string;
  i:integer;
  BoolResult:Boolean;
  cnt:integer;
begin
  cnt:=0;
  BoolResult := FALSE;
  if copy(ScrString,1,1)='.' then
    cnt:=1;
  for i := 2 to length(Scrstring) do
  begin
    //c:=PChar(copy(ScrString,i,1))^;
    c := Copy(ScrString,i,1);
    if c='-' then
    begin
      BoolResult:=true;
      break;
    end;
    if c = '.' then
    begin
      cnt:=cnt+1;
      if cnt>1 then
      begin
          boolResult:=true;
          break;
      end;
    end;

//    else
//      BoolResult:=false;
  end;
  Result := BoolResult;
end;

function TFrmduixiaodengji.IsEmpty(const Scr:string): boolean;
begin
  if trim(Scr)='' then
    Result := True
  else
    Result := False;
end;


procedure Tfrmduixiaodengji.FormCreate(Sender: TObject);
begin
  datetimepicker1.DateTime := date;
end;

procedure Tfrmduixiaodengji.Button1Click(Sender: TObject);
var
  Query1:TADOQuery;
  Query2:TADOQuery;
  cailiaoming:string;
  cailiaoclass:string;
  guigexinghao:string;
  danwei:string;
  danjia:string;
  shuliang:string;
  jine:string;
  nian:Integer;
  yue:Integer;
  beizhu:string;
  sl:string;
  je:string;
//  SQL:string;
  LeftArea:string;
  RightArea:string;
begin
  if IsEmpty(Edit6.Text)=True then
  begin
    application.MessageBox('材料名称不能为空!','提示',MB_OK OR MB_ICONERROR);
    exit;
  end;
  if IsEmpty(Edit6.Text)=True then
  begin
    application.MessageBox('材料名称不能为空!','提示',MB_OK OR MB_ICONERROR);
    exit;
  end;
  if IsEmpty(Combobox1.Text)=True then
  begin
    application.MessageBox('单位不能为空!','提示',MB_OK OR MB_ICONERROR);
    exit;
  end;
  if IsEmpty(Edit2.Text)=True then
  begin
    application.MessageBox('单价不能为空!','提示',MB_OK OR MB_ICONERROR);
    exit;
  end;
  if IsEmpty(Edit3.Text)=True then
  begin
    application.MessageBox('数量不能为空!','提示',MB_OK OR MB_ICONERROR);
    exit;
  end;
  if (length(trim(Edit2.Text))=1) and (trim(Edit2.Text) ='.') then
    Edit2.Text := '0';
  if IsNotNumric(Edit2.Text) = True then
  begin
    application.MessageBox('请输入合法的单价!','提示',MB_OK OR MB_ICONERROR);
    Edit2.clear;
    exit;
  end;
  if IsNotNumric(Edit3.Text) = True then
  begin
    application.MessageBox('请输入合法的数量!','提示',MB_OK OR MB_ICONERROR);
    Edit3.clear;
    exit;
  end;
  if IsNotNumric(Edit4.Text) = True then
  begin
    application.MessageBox('请输入合法的金额!','提示',MB_OK OR MB_ICONERROR);
    Edit4.clear;
    exit;
  end;

try
  if self.Caption ='低耗对销' then
      cailiaoclass := '低耗对销'
  else
      cailiaoclass := '机电对销';
  cailiaoming :=trim(Edit6.Text);
  guigexinghao := trim(Edit5.Text);
  danwei := trim(Combobox1.Text);
  danjia := trim(Edit2.Text);
  shuliang := trim(Edit3.Text);
  jine := trim(Edit4.Text);
  nian := YearOf(DateTimePicker1.date);
  yue := MonthOfTheYear(DateTimePicker1.Date);
  beizhu := trim(Memo1.Text);
  Query1 := TADOQuery.Create(nil);
  Query2 := TADOQuery.Create(NIL);
  Query1.ConnectionString := Frmmain.ADOConnection1.ConnectionString;
  Query2.ConnectionString := Frmmain.ADOConnection1.ConnectionString;
  LeftArea  := IntToStr(nian)+'-'+IntToStr(yue)+'-'+'25';
  if yue=12 then
    RightArea := IntToStr(nian+1)+'-'+'1'+'-'+'25';
  if (yue < 12) then
    RightArea := IntToStr(nian)+'-'+IntToStr(yue + 1)+'-'+'25';
//    showmessage(cailiaoclass);
//    showmessage(LeftArea+'   '+RightArea);
    {在[yyyy-mm-25,yyyy-mm2-25)只间}
  if (DateTimePicker1.Date >= StrToDate(LeftArea)) and (DateTimePicker1.Date < StrToDate(RightArea)) then
  begin
//  showmessage('1');
    Query1.Close;
    Query1.SQL.Clear;
    Query1.SQL.Add('Select * from duixiao where nian='+IntToStr(YearOf(StrToDate(RightArea)))+' and yue='+IntToStr(MonthOfTheYear(StrToDate(RightArea)))+' and class='''+
      cailiaoclass+''' and cailiaoming='''+Edit6.Text+'''');
    Query1.Prepared;
    Query1.Open;
    if Not Query1.Eof then       //存在此月的记录
    begin
//    showmessage('1.1');
      sl := Query1.FieldByName('shuliang').AsString;
      je := Query1.FieldByName('jine').AsString;
      sl := FloatToStr(StrToFloat(sl)+StrToFloat(Edit3.Text));
      je := FloatToStr(StrToFloat(je)+StrToFloat(Edit4.Text));
      Query2.Close;
      Query2.SQL.Clear;
      Query2.SQL.Add('Update duixiao set shuliang='''+Format('%.2f',[StrToFloat(sl)])+''',jine='''+Format('%.2f',[StrToFloat(je)])+''',beizhu='''+
        Memo1.Lines.Text+''' where nian='+IntToStr(YearOf(StrToDate(RightArea)))+' and yue='+IntToStr(MonthOfTheYear(StrToDate(RightArea)))+
        ' and class='''+cailiaoclass+''' and cailiaoming='''+Edit6.Text+'''');
      Query2.ExecSQL;
    end
    else               //不存在记录
    begin
//    showmessage('1.2');
      Query2.Close;
      Query2.SQL.Clear;
      Query2.SQL.Add('Insert into duixiao values('''+Edit6.Text+''','''+cailiaoclass+''','''+Edit5.Text+
        ''','''+ComboBox1.Text+''','''+Format('%.2f',[StrToFloat(Edit2.Text)])+''','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''','+IntToStr(YearOf(StrToDate(RightArea)))+ ','+
        IntToStr(MonthOfTheYear(StrToDate(RightArea)))+','''+Memo1.Lines.Text+''')');
      Query2.Prepared;
      Query2.ExecSQL;
    end;
  end;
  {左区间}
  if DateTimePicker1.Date < StrToDate(LeftArea) then
  begin
//  showmessage('2');
    Query1.Close;
    Query1.SQL.Clear;
    Query1.SQL.Add('Select * from duixiao where nian='+IntToStr(nian)+' and yue='+IntToStr(MonthOfTheYear(StrToDate(LeftArea)))+' and class='''+
      cailiaoclass+''' and cailiaoming='''+Edit6.Text+'''');
    Query1.Open;
    if Not Query1.Eof then       //存在此月的记录
    begin
//    showmessage('2.1');
      sl := Query1.FieldByName('shuliang').AsString;
      je := Query1.FieldByName('jine').AsString;
      sl := FloatToStr(StrToFloat(sl)+StrToFloat(Edit3.Text));
      je := FloatToStr(StrToFloat(je)+StrToFloat(Edit4.Text));
      Query2.Close;
      Query2.SQL.Clear;
      Query2.SQL.Add('Update duixiao set shuliang='''+Format('%.2f',[StrToFloat(sl)])+''',jine='''+Format('%.2f',[StrToFloat(je)])+''',beizhu='''+
        Memo1.Lines.Text+''' where nian='+IntToStr(nian)+' and yue='+IntToStr(MonthOfTheYear(StrToDate(LeftArea)))+
        ' and class='''+cailiaoclass+''' and cailiaoming='''+Edit6.Text+'''');
      Query2.ExecSQL;
    end
    else               //不存在记录
    begin
//    showmessage('2.2');
      Query2.Close;
      Query2.SQL.Clear;
      Query2.SQL.Add('Insert into duixiao values('''+Edit6.Text+''','''+cailiaoclass+''','''+Edit5.Text+
        ''','''+ComboBox1.Text+''','''+Format('%.2f',[StrToFloat(Edit2.Text)])+''','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''','+IntToStr(nian)+ ','+
        IntToStr(MonthOfTheYear(StrToDate(LeftArea)))+','''+Memo1.Lines.Text+''')');
      Query2.ExecSQL;
    end;
  end;
  {右区间}
  if DateTimePicker1.Date > StrToDate(RightArea) then
  begin
    Application.MessageBox('应该不会出现这个对话框!Unit6,Line:300','???',MB_OK OR MB_ICONSTOP);
    Application.Terminate;
  end;

//  with Query1 do
//  begin
//    Close;
//    SQL.Clear;
//    SQL.Add('select shuliang,jine from duixiao where class='''+cailiaoclass+''' and '+
//      'cailiaoming='''+cailiaoming+''' and nian='+IntToStr(nian)+' and yue='+IntToStr(yue));
//    Open;
//  end;
//  if not Query1.Eof then
//  begin
//    sl := Query1.FieldByName('shuliang').AsString;
//    je := Query1.FieldByName('jine').AsString;
//    sl := FloatToStr(StrToFloat(sl) + StrToFloat(shuliang));
//    je := FloatToStr(StrToFloat(je) + StrToFloat(jine));
//    SQL := 'Update duixiao set shuliang='+sl+',jine='+je+' where class='''+cailiaoclass+''' and '+
//      'cailiaoming='''+cailiaoming+''' and nian='+nian+' and yue='+yue+'';
//  end
//  else
//    SQL := 'insert  duixiao values('''+ cailiaoming +''','''+cailiaoclass +''','''+
//    guigexinghao+''','''+danwei+''','+danjia+','+shuliang+','+jine+','+nian+','+yue+
//    ','''+beizhu+''')';
//  Query1.Close;
//  Query1.SQL.Clear;
//  Query1.SQL.Add(SQL);
//  Query1.ExecSQL;
  FreeAndNil(Query1);
  FreeAndNil(Query2);
  {刷新操作}
  if self.Caption = '低耗对销' then
  begin
    Frmmain.Querydhdx.Close;
    Frmmain.Querydhdx.SQL.Clear;
    Frmmain.Querydhdx.SQL.Add('select * from duixiao where class='''+cailiaoclass+'''');
    Frmmain.Querydhdx.Open;
    Clear;
  end
  else
  begin

    Frmmain.Queryjddx.Close;
    Frmmain.Queryjddx.SQL.Clear;
    Frmmain.Queryjddx.SQL.Add('select * from duixiao where class='''+cailiaoclass+'''');
    Frmmain.Queryjddx.Open;
    Clear;
  end;
except
  showmessage('系统出错!');
end;
//  DataToCombobox1;
end;

procedure Tfrmduixiaodengji.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in ['0'..'9',#8,'.'] ) then
    key:=#0;
end;

procedure Tfrmduixiaodengji.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in ['0'..'9',#8,'.','-'] ) then
    key:=#0;
end;

procedure Tfrmduixiaodengji.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in ['0'..'9',#8,'.','-'] ) then
    key:=#0;
end;

procedure Tfrmduixiaodengji.Edit3Change(Sender: TObject);
begin
  if Trim(Edit2.Text) = '' then
    Exit;
  Edit4.Text := FloatToStr(StrToFloatDef(Edit2.Text,0) * StrToFloatDef(Edit3.Text,0));

end;

end.

⌨️ 快捷键说明

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