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

📄 unit8.~pas

📁 材料管理系统
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
        Query3.SQL.Clear;       {新材料input WeekDataCache}
        Query3.SQL.Add('Insert into WeekDataCache (cailiaoming,class,kucunshu,kucunjine,rukushu,rukujine,chukushu,chukujine)'+
          'values('''+ComboBox1.Text+''','''+clclass+''','+'''0.00'''+','+'''0.00'''+','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''','''+'0.00'''+','+'''0.00'''+')');
        Query3.ExecSQL;
        Query3.Close;                                              //结存就是入库数
        Query3.SQL.Clear;        {新材料input WeekHaoCai}
        Query3.SQL.Add('Insert into WeekHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+Edit1.Text+''','''+Format('%.2f',[StrToFloat(Edit2.Text)])+''',''0.00'',''0.00'','''+
          Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'','''+'0.00'',''0.00'','''+'0.00'',''0.00'','+'''0.00'',''0.00'','+'''0.00'',''0.00'','+'''0.00'',''0.00'','+
          '''0.00'',''0.00'','+'''0.00'',''0.00'','+'''0.00'',''0.00'','+'''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''','+IntToStr(zhou)+','+IntToStr(nian)+')');
        Query3.ExecSQL;
      end;
    end
    else       {本年本周记录存在}
    begin
      Query2.Close;
      Query2.SQL.Clear;
      Query2.SQL.Add('select * from WeekDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
      Query2.Open;
      if Query2.Eof then     //不可能发生,因为WeekHaoCai中有,则WeekDataCache一定有
      begin
        Application.MessageBox('Something unexpected occurred.Unit8,Line:309','Crazy',MB_OK OR MB_ICONERROR);
        Exit;
      end;
      kucunshu   := Query2.FieldByName('kucunshu').AsString;
      kucunjine  := Query2.FieldByName('kucunjine').AsString;
      rukushu    := Query2.FieldByName('rukushu').AsString;
      rukujine   := Query2.FieldByName('rukujine').AsString;
      chukushu   := Query2.FieldByName('chukushu').AsString;
      chukujine  := Query2.FieldByName('chukujine').AsString;
      rukushu    := FloatToStr(StrToFloat(rukushu)+StrToFloat(Edit3.Text));  //Update   'rukushu'
      rukujine   := FloatToStr(StrToFloat(rukujine)+StrToFloat(Edit4.Text));
      jiecunshu  := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu));
      jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
      Query3.Close;
      Query3.SQL.Clear;
      Query3.SQL.Add('Update WeekDataCache set rukushu='''+Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+''' where class='''+clclass+''' and cailiaoming='''+ ComboBox1.Text+'''');
      Query3.ExecSQL;  // showmessage('1  '+IntToStr(zhou));
      Query3.Close;
      Query3.SQL.Clear;
      Query3.SQL.Add('Update WeekHaoCai set rukushuliang='''+Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+''',jiecunshuliang='''+Format('%.2f',[StrToFloat(jiecunshu)])+''',jiecunjine='''+
      Format('%.2f',[StrToFloat(jiecunjine)])+''' where class='''+clclass+''' and cailiaoming='''+ ComboBox1.Text+
        ''' and nian='+IntToStr(nian)+' and zhou='+IntToStr(zhou));
      Query3.ExecSQL;     //showmessage('2');
    end;
    {把最后一次的记录记录在LastWeekIn中,同周不做叠加}
    Query3.Close;
    Query3.SQL.Clear;
    Query3.SQL.Add('Select * from LastWeekIn where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
    Query3.Prepared;
    Query3.Open;
    if Not Query3.Eof then
    begin
      Query3.Close;
      Query3.SQL.Clear;
      Query3.SQL.Add('Update LastWeekIn set lastrukushu='''+Edit3.Text+''',lastrukujine='''+Edit4.Text+
        ''' where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
      Query3.ExecSQL;
    end
    else
    begin
      Query3.Close;
      Query3.SQL.Clear;
      Query3.SQL.Add('Insert into LastWeekIn values('''+clclass+''','''+ComboBox1.Text+''','''+Edit3.Text+
        ''','''+Edit4.Text+''')');
      Query3.ExecSQL;
    end;
  except
    Application.MessageBox('系统错误W','ERROR',MB_OK OR MB_ICONSTOP);
  end;
  {月检验防止输入以前的月,但我想周检查过不了,就不会执行到此}
  {以下判断本年本天该怎样存放在MonthHaoCai,及MonthDataCache动态怎样变化}
  if (MonthOfTheYear(DateTimePicker1.Date) <= 1) and (zhou >= 52) then
    nian := nian + 1;   //恢复上面因为防止周出错而改动的nian 变量
//showmessage(IntToStr(nian));
  Yue       := MonthOfTheYear(DateTimePicker1.Date);
  LeftArea  := IntToStr(nian)+'-'+IntToStr(yue)+'-'+'25';
//  if ((yue=12) and (DayOfTheMonth(DateTimePicker1.Date) < 25)) then
//    RightArea := IntToStr(nian)+'-'+IntToStr(yue)+'-'+'25';
//  if ((yue=12) and (DayOfTheMonth(DateTimePicker1.Date) >24)) then
  if yue=12 then
    RightArea := IntToStr(nian+1)+'-'+'1'+'-'+'25';
  if (yue < 12) then
    RightArea := IntToStr(nian)+'-'+IntToStr(yue + 1)+'-'+'25';

//showmessage('left'+leftarea+' - right'+rightarea+' yue:'+IntToStr(yue));
//exit;
  try                             {在[LeftArea,RightArea)区间中}
    if (DateTimePicker1.Date >= StrToDate(LeftArea)) and (DateTimePicker1.Date < StrToDate(RightArea)) then
    begin
//  showmessage(LeftArea+'<='+DateToStr(DateTimePicker1.Date)+'<='+RightArea);   //not 断言
      with Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from MonthHaoCai where riqi='''+DateToStr(StrToDate(RightArea)-1)+''' and class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
        Open;
      end;
      if not Query1.Eof then       {今天在所属的这个月在MonthHaoCai中存在记录,则在MonthDataCache中一定有一条最近的记录}
      begin
        with Query2 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from MonthDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
          Open;
        end;
        if not Query2.Eof then     //MonthDataCache有此材料的记录
        begin
          kucunshu   := Query2.FieldByName('kucunshu').AsString;
          kucunjine  := Query2.FieldByName('kucunjine').AsString;
          rukushu    := Query2.FieldByName('rukushu').AsString;
          rukujine   := Query2.FieldByName('rukujine').AsString;
          chukushu   := Query2.FieldByName('chukushu').AsString;
          chukujine  := Query2.FieldByName('chukujine').AsString;
          rukushu    := FloatToStr(StrToFloat(Edit3.Text)+StrToFloat(rukushu));   //Update
          rukujine   := FloatToStr(StrToFloat(Edit4.Text)+StrToFloat(rukujine));
          jiecunshu  := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu));
          jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
          Query3.Close;
          Query3.SQL.Clear;              {更新rukushu,rukujine字段}
          Query3.SQL.Add('Update MonthDataCache set rukushu='''+ Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+''' where class='''+
            clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
          Query3.ExecSQL;
          Query3.Close;
          Query3.SQL.Clear;               {同时更新MonthHaoCai的rukushu,rukujine字段}
          Query3.SQL.Add('Update MonthHaoCai set rukushu='''+Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+
          ''',jiecunshu='''+Format('%.2f',[StrToFloat(jiecunshu)])+''',jiecunjine='''+Format('%.2f',[StrToFloat(jiecunjine)])+''' where riqi='''+
          DateToStr(StrToDate(RightArea)-1)+''' and class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
          Query3.ExecSQL;
        end
        else
          Application.MessageBox('这个对话框出现了,我真的疯了,因为没可能。','Crazy',MB_OK OR MB_ICONERROR);
      end
      else        {今天所属的这个月在MonthHaoCai中不存在记录,则在MonthDataCache中(可能是新的一个月,则有最近的记录。也可能是新材料)}
      begin
        Query2.Close;
        Query2.SQL.Clear;   {搜索MonthDataCache,有就是新的一个月,要做统计。没有,就是新材料}
        Query2.SQL.Add('select * from MonthDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
        Query2.Open;
        if not Query2.Eof then   {存在}
        begin
          kucunshu   := Query2.FieldByName('kucunshu').AsString;
          kucunjine  := Query2.FieldByName('kucunjine').AsString;
          rukushu    := Query2.FieldByName('rukushu').AsString;
          rukujine   := Query2.FieldByName('rukujine').AsString;
          chukushu   := Query2.FieldByName('chukushu').AsString;
          chukujine  := Query2.FieldByName('chukujine').AsString;
          kucunshu   := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu));   //统计上月的库存
          kucunjine  := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
          jiecunshu  := FloatToStr(StrToFloat(kucunshu)+StrToFloat(Edit3.Text)-0);     //新记录没有出库
          jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(Edit4.Text)-0);
          Query3.Close;
          Query3.SQL.Clear;    {统计更新}
          Query3.SQL.Add('Update MonthDataCache set kucunshu='''+Format('%.2f',[StrToFloat(kucunshu)])+''',kucunjine='''+Format('%.2f',[StrToFloat(kucunjine)])+
            ''',rukushu='''+Format('%.2f',[StrToFloat(Edit3.Text)])+''',rukujine='''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',chukushu=''0.00'',chukujine=''0.00'''+
            ' where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
          Query3.ExecSQL;
          Query3.Close;
          Query3.SQL.Clear;
          Query3.SQL.Add('Insert into MonthHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+guigexinghao+''','''+Edit1.Text+
            ''','''+Format('%.2f',[StrToFloat(Edit2.Text)])+''','''+Format('%.2f',[StrToFloat(kucunshu)])+''','''+Format('%.2f',[StrToFloat(kucunjine)])+
            ''','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(jiecunshu)])
            +''','''+Format('%.2f',[StrToFloat(jiecunjine)])+''','''+''+''','''+DateToStr(StrToDate(RightArea)-1)+''')');
          Query3.ExecSQL;
        end
        else     {MonthHaoCai中不存在,MonthDataCache没有。是新材料}
        begin
          Query3.Close;
          Query3.SQL.Clear;
          Query3.SQL.Add('Insert into MonthDataCache values('''+ComboBox1.Text+''','''+clclass+''','+'''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+
          Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'')');
          Query3.ExecSQL;
          Query3.Close;
          Query3.SQL.Clear;         {input MonthHaoCai}
          Query3.SQL.Add('Insert into MonthHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+guigexinghao+''','''+Edit1.Text+''','''+
            Format('%.2f',[StrToFloat(Edit2.Text)])+''',''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'','''+
            Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''','''+''+''','''+DateToStr(StrToDate(RightArea)-1)+''')');
          Query3.ExecSQL;
        end;
      end;
    end;
    {在(yyyy-mm-dd,LeftArea]区间}
    if DateTimePicker1.Date < StrToDate(LeftArea) then
    begin
      with Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from MonthHaoCai where riqi='''+DateToStr(StrToDate(LeftArea)-1)+''' and class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
        Open;
      end;
      if not Query1.Eof then   {MonthHaoCai中存在记录}
      begin
        with Query2 do
        begin
          Close;
          SQL.Clear;          {查找MonthDataCache有无相应记录}
          SQL.Add('select * from MonthDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
          Open;
        end;
        if not Query2.Eof then      //有
        begin
          kucunshu   := Query2.FieldByName('kucunshu').AsString;
          kucunjine  := Query2.FieldByName('kucunjine').AsString;
          rukushu    := Query2.FieldByName('rukushu').AsString;
          rukujine   := Query2.FieldByName('rukujine').AsString;
          chukushu   := Query2.FieldByName('chukushu').AsString;
          chukujine  := Query2.FieldByName('chukujine').AsString;
          rukushu    := FloatToStr(StrToFloat(rukushu)+StrToFloat(Edit3.Text));   // Update 'rukushu'
          rukujine   := FloatToStr(StrToFloat(rukujine)+StrToFloat(Edit4.Text));
          jiecunshu  := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu));
          jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
          Query3.Close;
          Query3.SQL.Clear;              {更新rukushu,rukujine字段}
          Query3.SQL.Add('Update MonthDataCache set rukushu='''+ Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+''' where class='''+
            clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
          Query3.ExecSQL;
          Query3.Close;
          Query3.SQL.Clear;               {同时更新MonthHaoCai的rukushu,rukujine字段}
          Query3.SQL.Add('Update MonthHaoCai set rukushu='''+Format('%.2f',[StrToFloat(rukushu)])+''',rukujine='''+Format('%.2f',[StrToFloat(rukujine)])+''',jiecunshu='''+Format('%.2f',[StrToFloat(jiecunshu)])+
            ''',jiecunjine='''+Format('%.2f',[StrToFloat(jiecunjine)])+''' where riqi='''+DateToStr(StrToDate(LeftArea)-1)+''' and class='''+clclass+
            ''' and cailiaoming='''+ComboBox1.Text+'''');
          Query3.ExecSQL;
        end
        else            //无
          Application.MessageBox('这个对话框出现了,我真的疯了,因为没可能。Unit8,Line:485','Crazy',MB_OK OR MB_ICONERROR);
      end
      else         {MonthHaoCai中不存在记录}
      begin        //几乎没有可能执行这段代码,因为前面以前建立了记录.(不可能这个月建上个月的记录)
        Query2.Close;    //showmessage('here1');
        Query2.SQL.Clear;        //查MonthDataCache,一般是没有的
        Query2.SQL.Add('select * from MonthDataCache where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
        Query2.Open;
        if Query2.Eof then    //在MontDataCache建立一条记录
        begin
          Query3.Close;             //showmessage('here2');
          Query3.SQL.Clear;
          Query3.SQL.Add('Insert into MonthDataCache values('''+ComboBox1.Text+''','''+clclass+''','+'''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+
            Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'')');
          Query3.ExecSQL;
          Query3.Close;
          Query3.SQL.Clear;
          Query3.SQL.Add('Insert into MonthHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+guigexinghao+''','''+Edit1.Text+''','''+
            Format('%.2f',[StrToFloat(Edit2.Text)])+''','+'''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+
            ''',''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(Edit3.Text)])+''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''','''+''+''','''+DateToStr(StrToDate(LeftArea)-1)+''')');
          Query3.ExecSQL;
        end
        else       {如果执行到此,则MonthDataCache中是历史记录}
        begin
          kucunshu   := Query2.FieldByName('kucunshu').AsString;
          kucunjine  := Query2.FieldByName('kucunjine').AsString;
          rukushu    := Query2.FieldByName('rukushu').AsString;
          rukujine   := Query2.FieldByName('rukujine').AsString;
          chukushu   := Query2.FieldByName('chukushu').AsString;
          chukujine  := Query2.FieldByName('chukujine').AsString;
          kucunshu   := FloatToStr(StrToFloat(kucunshu)+StrToFloat(rukushu)-StrToFloat(chukushu));
          kucunjine  := FloatToStr(StrToFloat(kucunjine)+StrToFloat(rukujine)-StrToFloat(chukujine));
          jiecunshu  := FloatToStr(StrToFloat(kucunshu)+StrToFloat(Edit3.Text)-0);     //新记录无出库
          jiecunjine := FloatToStr(StrToFloat(kucunjine)+StrToFloat(Edit4.Text)-0);
          Query3.Close;
          Query3.SQL.Clear;    {统计更新}
          Query3.SQL.Add('Update MonthDataCache set kucunshu='''+Format('%.2f',[StrToFloat(kucunshu)])+''',kucunjine='''+Format('%.2f',[StrToFloat(kucunjine)])+
          ''',rukushu='''+Format('%.2f',[StrToFloat(Edit3.Text)])+''',rukujine='''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',chukushu=''0.00'',chukujine=''0.00'''+
           ' where class='''+clclass+''' and cailiaoming='''+ComboBox1.Text+'''');
          Query3.ExecSQL;
          Query3.Close;        //showmessage(kucunshu+' '+rukushu+' '+chukushu+ ' '+ Edit3.Text);
          Query3.SQL.Clear;     //New Record
          Query3.SQL.Add('Insert into MonthHaoCai values('''+ComboBox1.Text+''','''+clclass+''','''+guigexinghao+''','''+Edit1.Text+
            ''','''+Format('%.2f',[StrToFloat(Edit2.Text)])+''','''+Format('%.2f',[StrToFloat(kucunshu)])+''','''+Format('%.2f',[StrToFloat(kucunjine)])+''','''+Format('%.2f',[StrToFloat(Edit3.Text)])+
            ''','''+Format('%.2f',[StrToFloat(Edit4.Text)])+''',''0.00'',''0.00'','''+Format('%.2f',[StrToFloat(jiecunshu)])+''','''+Format('%.2f',[StrToFloat(jiecunjine)])+''','''+''+
            ''','''+DateToStr(StrToDate(LeftArea)-1)+''')');
          Query3.ExecSQL;    //showmessage(LeftArea+'  '+'here3'+Query3.sql.text);
        end;
      end;
    end;
    if DateTimePicker1.Date > StrToDate(RightArea) then
    begin        {执行这里几乎没有可能,除非~~~~~~(因为这里是今年做明年的帐,无根无据)}
//      showmessage(LeftArea +'---'+RightArea);
      Application.MessageBox('Long,Long ago history!Unit8,Line:535','Crazy',MB_OK OR MB_ICONQUESTION);
      Exit;
    end;
  except
    Application.MessageBox('系统错误M','ERROR',MB_OK OR MB_ICONSTOP);
  end;

  try
    {///////////以下为输入YearHaoCai年报表的操作////////////}
    LeftArea := IntToStr(nian-1)+'-'+'12'+'-'+'25';

⌨️ 快捷键说明

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