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

📄 updataztunit.pas

📁 很好用的一个票据管理系统
💻 PAS
字号:
unit updataztUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Spin, Grids, ComCtrls, StdCtrls, Buttons, ExtCtrls;

type
  TupdataForm = class(TForm)
    Panel3: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Panel1: TPanel;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Edit2: TEdit;
    Edit4: TEdit;
    TabSheet2: TTabSheet;
    Panel2: TPanel;
    StringGrid1: TStringGrid;
    DateTimePicker2: TDateTimePicker;
    TabSheet3: TTabSheet;
    Label5: TLabel;
    Label7: TLabel;
    Edit5: TEdit;
    Edit6: TEdit;
    ComboBox1: TComboBox;
    Label3: TLabel;
    Edit3: TEdit;
    SpinButton1: TSpinButton;
    Edit1: TEdit;
    SpinButton2: TSpinButton;
    Label6: TLabel;
    procedure comboboxnewll;
    procedure StringGrid1New;
    procedure StringGrid1Newll;
    procedure FileCopy(Const sourcefilename,targetfilename:String);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure strubggrud1sekectcell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure stringgridchange(Sender: TObject);
    procedure spinbutton1downclick(Sender: TObject);
    procedure spinbutton1upclick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure edit3change(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure spinbutton2DownClick(Sender: TObject);
    procedure spinbutton2UpClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  updataForm: TupdataForm;

implementation
uses dm;
{$R *.dfm}
procedure Tupdataform.FileCopy(Const sourcefilename,targetfilename:string);
var
 S,T:TFileStream;
begin
  s:=TFileStream.Create(sourcefilename,fmOpenRead);
  try
    t:=TFileStream.Create(Targetfilename,fmopenWrite or fmCreate);
    try
      t.CopyFrom(s,s.Size);
    finally
      t.Free;
    end;
  finally
    s.Free;
  end;
end;
procedure Tupdataform.StringGrid1New;
var
 i:integer;
begin
  //stringgrid1.RowCount:=10;
  stringgrid1.ColWidths[0]:=90;
  Stringgrid1.Cells[0,0]:=' 月份';
  stringgrid1.Cells[1,0]:='    开始日期';
  stringgrid1.Cells[2,0]:='    结束日期';
  stringgrid1.FixedCols:=1;
  stringgrid1.FixedRows:=1;
  for i:=1 to Stringgrid1.RowCount-1 do
  begin
    stringgrid1.Cells[0,i]:=inttostr(i)+'月份';
  end;
end;
procedure Tupdataform.StringGrid1Newll;
var
 i:integer;
begin
  for i:=1 to stringgrid1.RowCount-1 do
  begin
    stringgrid1.Cells[1,i]:=edit3.Text+'-'+inttostr(i)+'-1';
    stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-31';
    if i=2 then
    begin
      stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-28';
    end;
    if i=4 then
    begin
      stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-30';
    end;
    if i=6 then
    begin
      stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-30';
    end;
    if i=9 then
    begin
      stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-30';
    end;
    if i=11 then
    begin
      stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-30';
    end
  end;
  if  datetimepicker2.Visible=true then
  begin
    datetimepicker2.Visible:=false;
  end;
end;
procedure tupdataform.comboboxnewll;
begin
   dmdata.ADOTable_dh.Active:=true;
   dmdata.ADOTable_dh.First;
   while not dmdata.ADOTable_dh.eof do
   begin
     combobox1.Items.Add(dmdata.ADOTable_dh['cacc']);
     dmdata.ADOTable_dh.Next;
   end;
   //combobox1.ItemIndex:=0;
end;

procedure TupdataForm.ComboBox1Change(Sender: TObject);
var
 j,unm:integer;
begin
  if combobox1.Text = '' then
    exit;
  with dmdata.CreateHDADOQuery do
  begin
     close;
     sql.Clear;
     sql.Add('Select * from g_account where cacc = :a');
     parameters.ParamByName('a').Value:=trim(combobox1.Text);
     open;
     if RecordCount > 0 then
     begin
        edit2.Text:=fieldByName('cacc_name').AsString;
        edit1.Text:=inttostr(fieldByName('pjlen').AsInteger);
        //datetimepicker1.Date:=fieldbyname('dbegin').AsDateTime;
     end
     else
     begin
       showmessage('没有该账套!');
       exit;
     end;
   end;
   //i:=pos('-',trim(datetostr(datetimepicker1.Date)));
   //str:= copy(trim(datetostr(datetimepicker1.Date)),1,i-1);
   with dmdata.CreateYearADOQuery do
   begin
     close;
     sql.Clear;
     sql.Add('Select * from g_account1 where (AccountNum = :a) and (iYear = :b)' );
    // showmessage(str+trim(combobox1.Text));
     parameters.ParamByName('a').Value:=trim(combobox1.Text);
     parameters.ParamByName('b').Value:=strtoint(trim(edit3.Text));
     open;
     if Recordcount > 0 then
     begin
       edit4.Text:=fieldbyname('FullpathName').AsString;
       //edit3.Text:=trim(str);
       unm:=fieldbyname('ID').AsInteger;
     end
     else
     begin
       showmessage('找不能到年度账');
       exit;
     end;
   end;
     with dmdata.CreateYearADOQuery do
     begin
       close;
       sql.Clear;
       sql.Add('Select * from g_period where (iacc_id = :a) and (iYear = :b)');
       parameters.ParamByName('a').Value:= unm;
       parameters.ParamByName('b').Value:=strtoint(edit3.Text);
       open;
       if Recordcount > 0 then
       begin
         First;
         j:=1;
         while not eof do
         begin
          stringgrid1.Cells[1,j]:=datetostr(fieldbyname('dbegin').AsDateTime);
          stringgrid1.Cells[2,j]:=datetostr(fieldbyname('dend').AsDateTime);
          Next;
          j:= j+1;
         end;
       end
       else
       begin
       exit;
       end;
     end;

end;

procedure TupdataForm.FormCreate(Sender: TObject);
var
 i:integer;
 datestr:string;
begin
 datestr:=datetostr(now);
 i:=pos('-',trim(datestr));
 edit3.Text:=copy(trim(datestr),1,i-1);
 Comboboxnewll;
 Stringgrid1New;
 StringGrid1Newll;
end;

procedure TupdataForm.strubggrud1sekectcell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  a:TRect;
begin
   if acol=2 then
   begin
     a:=stringGrid1.CellRect(Acol,Arow);
     a.Left:=a.Left+stringgrid1.Left;
     a.right:=a.Right+stringgrid1.Left;
     a.Top:=a.Top+stringgrid1.Top;
     a.Bottom:=a.Bottom+stringgrid1.Top;
     dateTimepicker2.Left:=a.Left+2;
     datetimepicker2.Top:=a.Top+2;
     datetimepicker2.Width:=stringgrid1.ColWidths[acol];
     datetimepicker2.Height:=stringgrid1.RowHeights[arow];
     datetimepicker2.Visible:=true;
     datetimepicker2.SetFocus;
     datetimepicker2.Date:=strtodate(StringGrid1.Cells[ACol,ARow]);
   end;
   Canselect:=true;
end;

procedure TupdataForm.stringgridchange(Sender: TObject);
var
 i,j,s,a,b:integer;
 str,str1:string;

begin
   StringGrid1.Cells[stringgrid1.Col,stringgrid1.Row]:=
   datetostr(datetimepicker2.date);
   datetimepicker2.Visible:=false;
   stringgrid1.SetFocus;
   //if StringGrid1.Cells[stringgrid1.Col,stringgrid1.Row]=stringgrid1.Cells[2,1]then
   //begin
        j:=length(trim(StringGrid1.Cells[stringgrid1.Col,stringgrid1.Row]));
        a:=pos('-',trim(StringGrid1.Cells[stringgrid1.Col,stringgrid1.Row]));
        str:= copy(trim(StringGrid1.Cells[stringgrid1.Col,stringgrid1.Row]),a+1,j-a);
        s:=length(trim(str));
        b:=pos('-',trim(str));
        str1:= copy(trim(str),b+1,s-b);
        if strtoint(str1)<28 then
        begin
          for i:=1 to stringgrid1.RowCount-2 do
          begin
            stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-'+str1;
            stringgrid1.Cells[1,i+1]:=edit3.Text+'-'+inttostr(i)+'-'+inttostr(strtoint(str1)+1);
          end;
         end
         else
         begin
            if strtoint(str1)=28 then
            begin
             for i:=1 to stringgrid1.RowCount-2 do
             begin
             stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-'+str1;
             stringgrid1.Cells[1,i+1]:=edit3.Text+'-'+inttostr(i)+'-'+inttostr(strtoint(str1)+1);
             end;
             //stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-'+str1;
             stringgrid1.Cells[1,3]:=edit3.Text+'-3-1';
            end;
            if strtoint(str1)=29 then
            begin
             for i:=1 to stringgrid1.RowCount-2 do
             begin
             stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-'+str1;
             stringgrid1.Cells[1,i+1]:=edit3.Text+'-'+inttostr(i)+'-'+inttostr(strtoint(str1)+1);
             end;
             stringgrid1.Cells[2,2]:=edit3.Text+'-2-28';
             stringgrid1.Cells[1,3]:=edit3.Text+'-3-1';
            end;
             if strtoint(str1)=30 then
            begin
             for i:=1 to stringgrid1.RowCount-2 do
             begin
             stringgrid1.Cells[2,i]:=edit3.Text+'-'+inttostr(i)+'-'+str1;
             stringgrid1.Cells[1,i+1]:=edit3.Text+'-'+inttostr(i)+'-'+inttostr(strtoint(str1)+1);
             end;
             stringgrid1.Cells[1,3]:=edit3.Text+'-3-1';
             stringgrid1.Cells[1,5]:=edit3.Text+'-5-1';
             stringgrid1.Cells[1,7]:=edit3.Text+'-7-1';
             stringgrid1.Cells[1,10]:=edit3.Text+'-10-1';
             stringgrid1.Cells[1,12]:=edit3.Text+'-12-1';
             stringgrid1.Cells[2,2]:=edit3.Text+'-2-28';
             stringgrid1.Cells[2,4]:=edit3.Text+'-4-30';
             stringgrid1.Cells[2,6]:=edit3.Text+'-6-30';
             stringgrid1.Cells[2,9]:=edit3.Text+'-9-30';
             stringgrid1.Cells[2,11]:=edit3.Text+'-11-30';
            end;
            if strtoint(str1)=31 then
            begin
              Stringgrid1Newll;
            end;
          end;
          stringgrid1.Cells[2,12]:=edit3.Text+'-12-31';
    //end;
end;

procedure TupdataForm.spinbutton1downclick(Sender: TObject);
begin
   edit3.Text:=inttostr(strtoint(edit3.Text)-1);
end;

procedure TupdataForm.spinbutton1upclick(Sender: TObject);
begin
    edit3.Text:=inttostr(strtoint(edit3.Text)+1);
end;

procedure TupdataForm.BitBtn1Click(Sender: TObject);
var
  i,j,unm:integer;
  //str:string;
  rsl:array[1..2] of string;
begin
   with dmdata.CreateYearADOQuery do
   begin
     close;
     sql.Clear;
     sql.Add('Select * from g_account1 where (AccountNum = :a) and (iYear = :b)' );
    // showmessage(str+trim(combobox1.Text));
     parameters.ParamByName('a').Value:=trim(combobox1.Text);
     parameters.ParamByName('b').Value:=strtoint(edit3.Text);
     open;
     if Recordcount > 0 then
     begin
       unm:=fieldbyname('ID').AsInteger;
     end
     else
     begin
       showmessage('找不能到年度账');
       exit;
     end;
    end; 
  with dmdata.CreateHDADOQuery do
  begin
    close;
    sql.Clear;
    sql.Add('update g_account set cacc_name = :b,pjlen = :c where cacc = :a');
     parameters.ParamByName('a').Value:=trim(combobox1.Text);
     parameters.ParamByName('b').Value:=trim(edit2.Text);
     parameters.ParamByName('c').Value:=strtoint(edit1.Text);
    execsql;
  end;
   //i:=pos('-',trim(datetostr(datetimepicker1.Date)));
   //str:= copy(trim(datetostr(datetimepicker1.Date)),1,i-1);
  with dmdata.CreateHDADOQuery do
  begin
    close;
    sql.Clear;
    sql.Add('update g_account1 set FullPathName = :c where (AccountNum = :a) and (iYear = :b)');
    parameters.ParamByName('a').Value:=trim(combobox1.Text);
    parameters.ParamByName('b').Value:=strtoint(edit3.Text);
    parameters.ParamByName('c').Value :=trim(edit4.Text);
    execsql;
  end;
  for i:=1 to stringgrid1.RowCount-1 do
  begin
       with dmdata.CreateYearADOQuery do
       begin
       close;
       sql.Clear;
       sql.Add('update g_period set dbegin =:d,dend =:e where (iacc_id =:a) and(iyear =:b) and (id = :c)');
       for j:=1 to stringgrid1.ColCount-1 do
        begin
          rsl[j]:=stringgrid1.Cells[j,i];
        end;
        parameters.ParamByName('a').Value:=unm;
        parameters.ParamByName('b').Value:=strtoint(edit3.Text);
        parameters.ParamByName('c').Value:=i;
        parameters.ParamByName('d').Value:=strtodate(rsl[1]);
        parameters.ParamByName('e').Value:=strtodate(rsl[2]);
        execsql;
      end;
    end;
   if (edit5.Text='') and (edit6.Text='') then
   begin
     showmessage('修改账套成功!');
     exit;
   end
   else
   begin
     with dmdata.CreateUserADOQuery do
     begin
       close;
       sql.Clear;
       sql.Add('update T_User set name =:b,PASSWD = :c where QX = :a');
       parameters.ParamByName('a').Value := trim(combobox1.Text);
       parameters.ParamByName('b').Value:=trim(edit5.Text);
       parameters.ParamByName('c').Value:=trim(edit6.Text);
       execsql;
     end;
   end;
   showmessage('修改账套成功!');

end;

procedure TupdataForm.edit3change(Sender: TObject);
begin
   Stringgrid1Newll;
end;

procedure TupdataForm.BitBtn2Click(Sender: TObject);
begin
  close;
end;

procedure TupdataForm.spinbutton2DownClick(Sender: TObject);
begin
    edit1.Text:=inttostr(strtoint(edit1.Text)-1);
end;

procedure TupdataForm.spinbutton2UpClick(Sender: TObject);
begin
    edit1.Text:=inttostr(strtoint(edit1.Text)+1);
end;

end.

⌨️ 快捷键说明

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