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

📄 goods_requirement.pas

📁 delphi的一个开发实例
💻 PAS
字号:
unit Goods_Requirement;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons, Grids,{ChildFrm,} XPMenu;

type
  Tfrm_Goods_Requirement = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    Panel3: TPanel;
    Label1: TLabel;
    Panel4: TPanel;
    Edit1: TLabeledEdit;
    GroupBox1: TGroupBox;
    Cmd_Select_Storage: TSpeedButton;
    Cmd_Select_Login: TSpeedButton;
    Cmd_Select_JSR: TSpeedButton;
    Cmd_Select_Shop: TSpeedButton;
    Edit_Storage_Name: TLabeledEdit;
    Edit5: TLabeledEdit;
    Edit6: TLabeledEdit;
    Edit7: TLabeledEdit;
    Edit8: TLabeledEdit;
    Edit3: TLabeledEdit;
    Edit_Shop_Name: TLabeledEdit;
    Edit4: TLabeledEdit;
    Edit2: TLabeledEdit;
    Panel9: TPanel;
    Panel5: TPanel;
    P_check: TPanel;
    P1: TPanel;
    Cmd1: TSpeedButton;
    L1: TLabel;
    P2: TPanel;
    Cmd2: TSpeedButton;
    L2: TLabel;
    P3: TPanel;
    Cmd3: TSpeedButton;
    L3: TLabel;
    P4: TPanel;
    L4: TLabel;
    Cmd4: TSpeedButton;
    P5: TPanel;
    L5: TLabel;
    Cmd5: TSpeedButton;
    Panel7: TPanel;
    SpeedButton10: TSpeedButton;
    SpeedButton5: TSpeedButton;
    Panel6: TPanel;
    Panel10: TPanel;
    Cmd_Delete: TSpeedButton;
    Cmd_Add: TSpeedButton;
    StringGrid1: TStringGrid;
    XPMenu1: TXPMenu;
    procedure Cmd_Select_ShopClick(Sender: TObject);
    procedure Cmd_Select_StorageClick(Sender: TObject);
    procedure Cmd_Select_JSRClick(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Cmd_DeleteClick(Sender: TObject);
    procedure Cmd_AddClick(Sender: TObject);
    procedure Edit1DblClick(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure StringGrid1DblClick(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure Cmd_Select_LoginClick(Sender: TObject);
    procedure Edit6KeyPress(Sender: TObject; var Key: Char);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    procedure DeleteRow(Row:Integer);
  public
    { Public declarations }
  end;

var
  frm_Goods_Requirement: Tfrm_Goods_Requirement;
  Total_Count:Integer;
  Pcol,Prow:integer;
implementation

uses ChildShop_Select, Storage_Select, Login_Man, func, Goods_Check, Data;

{$R *.dfm}

procedure Tfrm_Goods_Requirement.DeleteRow(Row:Integer);
var
    i : integer;
begin
    //最后一列直接删除
    if (Row = StringGrid1.RowCount-1) and (row >1) then
        StringGrid1.RowCount := StringGrid1.RowCount - 1;
    //自动上移
    if (Row < StringGrid1.RowCount) and (Row > StringGrid1.FixedRows-1) then
    begin
        if Row < StringGrid1.RowCount - 1 then
        begin
            for i := Row to StringGrid1.RowCount-1 do
            StringGrid1.Rows[i] := StringGrid1.Rows[i+1];
            StringGrid1.RowCount :=StringGrid1.RowCount - 1;
        end;
    end;
end;
procedure Tfrm_Goods_Requirement.Cmd_Select_ShopClick(Sender: TObject);
begin
    ChildShop_Str:='';
    ChildShop_Result_NO:='';
    ChildShop_Result_Name:='';
    ChildShop_Str:='Goods_Requirement_str';
    frm_ChildShop_Select:=Tfrm_ChildShop_Select.Create(self);
    frm_ChildShop_Select.ShowModal;
    Edit4.Text:=ChildShop_Result_NO;
    Edit_Shop_Name.Text:=ChildShop_Result_Name;
    frm_ChildShop_Select.Free;
end;

procedure Tfrm_Goods_Requirement.Cmd_Select_StorageClick(Sender: TObject);
begin
    Check_Storage:='';
    Check_Storage_Result:='';
    Check_Storage:='Goods_Requirement_str';
    frm_Storage_Select:=Tfrm_Storage_Select.Create(self);
    frm_Storage_Select.ShowModal;
    Edit_Storage_Name.Text:=Trim(Check_Storage_Result);
    Edit3.Text:=Trim(Check_Storage_Result_NO);
    frm_Storage_Select.Free;
end;

procedure Tfrm_Goods_Requirement.Cmd_Select_JSRClick(Sender: TObject);
begin
    Employe_Check:='';
    Employe_Check:='Goods_Requirement_str';
    Employe_Check_Result:='';
    frm_Login_Man:=Tfrm_Login_Man.Create(self);
    frm_Login_Man.Caption:='经手人选择';
    frm_Login_Man.ShowModal;
    Edit5.Text:=Employe_Check_Result;
    frm_Login_Man.Free;
end;

procedure Tfrm_Goods_Requirement.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
    s:string;
    r:TRect;
begin
    with sender as TStringGrid do
    begin
        if (GDFocused in state) then
        begin
            Pcol:=Acol;
            Prow:=ARow;
            String_Col:=ARow;
        end;
    end;
    //文字垂直居中
    with StringGrid1 do
    begin
        Canvas.FillRect(Rect);
        s:=Cells[ACol,ARow];
        r:=Rect;
        DrawText(Canvas.Handle,PChar(s),Length(s),r,DT_CENTER or DT_SINGLELINE or DT_VCENTER);
    end; 
end;

procedure Tfrm_Goods_Requirement.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
     Action:=Cafree;
end;

procedure Tfrm_Goods_Requirement.FormCreate(Sender: TObject);
var
    FWidth:integer;
begin
    Scaled:=TRUE;
    if(Screen.width<>1024)then
    begin
        FWidth:=Width;
        Height:=longint(Height)*longint(Screen.Height)DIV 768; //窗口大小调整
        Width:=longint(Width)*longint(Screen.Width)DIV 1024;//窗口大小调整
        ScaleBy(Screen.Width,1024); //控件大小调整
        ScaleBy(Screen.Height,768); //控件大小调整
        Font.Size:=(Width DIV FWidth)*Font.Size;//字体大小调整
    end;
end;

procedure Tfrm_Goods_Requirement.FormShow(Sender: TObject);
begin
    frm_Goods_Requirement.Left:=170 * longint(Screen.Width) div 1024;
    frm_Goods_Requirement.Width:=860 * longint(Screen.Width) div 1024;
    frm_Goods_Requirement.Top:=40 * longint(Screen.Height) div 768;
    frm_Goods_Requirement.Height:=715 * longint(Screen.Height) div 768;
    StringGrid1.ColCount:=18;
    StringGrid1.Cells[0,0]:='行号';
    StringGrid1.Cells[1,0]:='商品编号';
    StringGrid1.Cells[2,0]:='商品名称';
    StringGrid1.Cells[3,0]:='需求数量';
    StringGrid1.Cells[4,0]:='单位';
    StringGrid1.Cells[5,0]:='规格型号';
    StringGrid1.Cells[6,0]:='类别名称';
    StringGrid1.Cells[7,0]:='品牌名称';
    StringGrid1.Cells[8,0]:='品种名称';
    StringGrid1.Cells[9,0]:='商品颜色';
    StringGrid1.Cells[10,0]:='球面度数';
    StringGrid1.Cells[11,0]:='柱面度数';
    StringGrid1.Cells[12,0]:='生产厂家';
    StringGrid1.Cells[13,0]:='商品条码';
    StringGrid1.Cells[14,0]:='注册商标';
    StringGrid1.Cells[15,0]:='有效日期(月)';
    StringGrid1.Cells[16,0]:='有效日期(日)';
    StringGrid1.Cells[17,0]:='商品说明';
    if Public_Do='Goods_Requirment_Str' then
    begin
        StringGrid1.RowCount:=2;
        P_check.Visible:=False;
    end;

end;

procedure Tfrm_Goods_Requirement.Cmd_DeleteClick(Sender: TObject);
var
    i:shortint;
begin
    if StringGrid1.col<>0 then
    begin
        StringGrid1.Rows[StringGrid1.Row].Clear; //删除选中行的所有列 ,用右键弹出菜单
        DeleteRow(StringGrid1.Row);
    end;
    for i:=1 to StringGrid1.RowCount do
    StringGrid1.cells[0,i]:=inttostr(i);
end;

procedure Tfrm_Goods_Requirement.Cmd_AddClick(Sender: TObject);
var
    i:integer;
begin
    StringGrid1.RowCount:=StringGrid1.RowCount+1;
    Total_Count:=StringGrid1.RowCount;
    for i:=1 to StringGrid1.RowCount-1 do
    begin
        StringGrid1.Cells[0,i]:=IntTostr(i); //表示第0列第i行
    end;
end;

procedure Tfrm_Goods_Requirement.Edit1DblClick(Sender: TObject);
begin
    Edit1.Text:=ForMatDateTime('yyyy''-''mm''-''dd',now);
end;

procedure Tfrm_Goods_Requirement.Edit1KeyPress(Sender: TObject;
  var Key: Char);
begin
    if Key=#13 then
    begin
        Edit1.Text:=ForMatDateTime('yyyy''-''mm''-''dd',now);
    end;
end;

procedure Tfrm_Goods_Requirement.StringGrid1DblClick(Sender: TObject);
var
    SqlText:string;
begin
    if Trim(Edit2.Text)='' then
    begin
        Application.MessageBox('操作失败,【单据编号】不能为空!',pchar(application.Title),mb_iconwarning);
        Edit2.SetFocus;
        Exit;
    end;
    if Trim(Edit1.Text)='' then
    begin
        Application.MessageBox('操作失败,【录单日期】不能为空!',pchar(application.Title),mb_iconwarning);
        Edit4.SetFocus;
        Exit;
    end;
    if Trim(Edit5.Text)='' then
    begin
        Application.MessageBox('操作失败,【经手人】不能为空!',pchar(application.Title),mb_iconwarning);
        Edit5.SetFocus;
        Exit;
    end;
    SqlText:='';
    SqlText:='SELECT Goods_NO,Goods_Name,Goods_Modal,Goods_Cards,Goods_Brand,Norms_Type,Goods_Color,Goods_Sphere,Goods_Column,Goods_Coding,Enroll_Brand,Factory,Base_Monad,Valid_Month,Valid_Day,Remark From [Goods_Information]';
    if ((PCol=1) or (PCol=2))then //表示选择的是商品编号 选择的是第一列
    begin
        Goods_Check_str:='';
        frm_Goods_Check:=Tfrm_Goods_Check.Create(self);
        frm_Goods_Check.ShowModal;
        if Goods_Check_str='Goods_Requirement_str_01' then
        begin
            with frm_data.ClientDataSet_Goods_Information do
            begin
                Close;
                CommandText:='';
                CommandText:='select * from [Goods_Information] where Goods_No='''+Trim(Goods_No_Str)+'''';
                try
                    Open;
                    StringGrid1.Cells[1,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_NO').AsString;
                    StringGrid1.Cells[2,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_Name').AsString;
                    StringGrid1.Cells[4,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Base_Monad').AsString;
                    StringGrid1.Cells[5,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Norms_Type').AsString;
                    StringGrid1.Cells[6,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_Modal').AsString;
                    StringGrid1.Cells[7,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_Cards').AsString;
                    StringGrid1.Cells[8,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_Brand').AsString;
                    StringGrid1.Cells[9,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_Color').AsString;
                    StringGrid1.Cells[10,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_Sphere').AsString;
                    StringGrid1.Cells[11,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_Column').AsString;
                    StringGrid1.Cells[12,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Factory').AsString;
                    StringGrid1.Cells[13,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Goods_Coding').AsString;
                    StringGrid1.Cells[14,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Enroll_Brand').AsString;
                    StringGrid1.Cells[15,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Valid_Month').AsString;
                    StringGrid1.Cells[16,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Valid_Day').AsString;
                    StringGrid1.Cells[17,String_Col]:=frm_data.ClientDataSet_Goods_Information.FieldByName('Remark').AsString;
                except
                    Application.MessageBox('系统错误!系统在打开数据表【商品基本信息表】时出错!'+#13#10#13+'请检查远程服务器连接是否正常?请确认!',Pchar(Application.Title),MB_ICONWarning);
                    Exit;
                end;
            end;
        end;
        frm_Goods_Check.Free;
    end;
end;


procedure Tfrm_Goods_Requirement.SpeedButton4Click(Sender: TObject);
begin
   Close;
end;

procedure Tfrm_Goods_Requirement.Cmd_Select_LoginClick(Sender: TObject);
begin
    Edit6.Text:=Handle_Man;
end;

procedure Tfrm_Goods_Requirement.Edit6KeyPress(Sender: TObject;
  var Key: Char);
begin
    if Key=#13 then
        Edit6.Text:=Handle_Man;
end;

procedure Tfrm_Goods_Requirement.StringGrid1SelectCell(Sender: TObject;
  ACol, ARow: Integer; var CanSelect: Boolean);
begin
    pcol:=acol;
    prow:=arow;
end;

procedure Tfrm_Goods_Requirement.StringGrid1KeyPress(Sender: TObject;
  var Key: Char);
begin
    if pcol in [4] then
    begin
        if not (key in ['0'..'9',#8,'.']) then
        begin
            key:=#0;
        end
        else
        begin
            if key<>#8 then
            begin
                if pcol=4 then  StringGrid1.Cells[4,prow]:=StringGrid1.Cells[4,prow]+key;
            end
            else
            begin
            if pcol=4 then
            begin
                StringGrid1.Cells[4,prow]:='';  //不加退格符号;
            end;
            exit;
            end;
        end;
    end;
end;

end.

⌨️ 快捷键说明

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