1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
| create procedure Push(in ComputerName varchar(30), in WarehouseName varchar(30), in PushNumber int) begin declare ComputerID varchar(6); declare WarehouseID varchar(6); declare RecordsID int(7) zerofill; declare CurrentNumber int; declare UnitPrice float; declare TotalMoney float;
PUSH: begin CheckOut: begin select Computer_ID into ComputerID from Computer where Computer_Name = ComputerName limit 1;
select Warehouse_ID into WarehouseID from Warehouse where Warehouse_Name = WarehouseName limit 1;
if ComputerID is null then set @isSuccess = false; leave PUSH; end if;
if WarehouseID is null then set @isSuccess = false; leave PUSH; end if;
select Number INTO CurrentNumber from Stock where Stock.Computer_ID = ComputerID and Stock.Warehouse_ID = WarehouseID;
select Computer_Unit_Price into UnitPrice from Computer where Computer_Name = ComputerName;
set TotalMoney = UnitPrice * PushNumber; end CheckOut;
PushProcedure: begin set @isSuccess = true; if CurrentNumber is null then begin declare StockID int(5) zerofill; set @isNew = true; select max(cast(substr(Stock_ID, 2) as signed integer)) into StockID from Stock; if StockID is null then set StockID = 1; else set StockID = StockID + 1; end if; insert into Stock value (concat('S', StockID), ComputerID, WarehouseID, PushNumber); end; else begin select Stock_ID into @CurrentID from Stock where Stock.Computer_ID = ComputerID and Stock.Warehouse_ID = WarehouseID; update Stock set Number = Number + PushNumber where Stock_ID = @CurrentID; set @isNew = false; end; end if; end PushProcedure; end PUSH;
ReturnInfo: begin select max(cast(substr(InputRecords_ID, 2) as signed integer)) into RecordsID from InputRecords; if RecordsID is null then set RecordsID = 1; else set RecordsID = RecordsID + 1; end if;
if @isSuccess = true then insert into InputRecords values (concat('I', RecordsID), ComputerName, WarehouseName, PushNumber, TotalMoney, sysdate(), @isNew, true);
select concat('I', RecordsID) 记录编号, ComputerName 请求入库电脑, WarehouseName 仓库, PushNumber 入库数量, TotalMoney 总金额, sysdate() 操作日期时间, if(@isNew = true, '是', '否') 是否为新型号电脑, '是' 是否成功入库; else insert into InputRecords values (concat('I', RecordsID), ComputerName, WarehouseName, PushNumber, null, sysdate(), null, false);
select concat('I', RecordsID) 记录编号, ComputerName 请求入库电脑, WarehouseName 仓库, PushNumber 入库数量, sysdate() 操作日期时间, '否' 是否成功入库; end if; end ReturnInfo;
commit; end;
|