编辑:我在另一个论坛的帮助下解决了我的问题。这是我的变量,也是我从未让while循环定义它们的方式,我只在顶部声明了它们,因此循环将其视为一个常量值,这是导入的第一条记录。
因此,我试图用txt文件中的信息填写我制作的Acrobat PDF表单,然后根据表单中的信息将其保存到多个文件夹之一。我有一系列以数字范围(即1-49、50-99、100-149等)命名的文件夹设置,并且某些文件夹前面带有字母“ z”,因为我们的编号系统使用这些表格进行跟踪时,会包含一些名称的末尾带有Z的名称(在我之前的这里的人有点烂)。
我要纠正的代码逻辑是这样的(如果您只想查看下面的代码):
在while循环中导入文本数据->使用indexOf在目标字段值中搜索字母Z->使用switch设置2个代码块,1个包含“ z”的值,1个不含“ z”的值“->根据” z“确定要运行哪个代码块->使用substr(0,3)从值中提取前三个字符,并使用代码块中的字符与我们的数字范围进行比较,以查看哪个范围数字落入->根据其落入的范围使用字符串设置变量(即“ 100-149 /”)->保存PDF->使用先前设置的变量将saveAs的输出目录修改为它将变量切换到哪个范围,并将PDF保存在名为数字范围的相应文件夹中->增加变量并重复循环
我现在的问题是,我们使用开关代码设置的变量只是一个零。因此,与其添加我的字符串并使其在正确的子文件夹中创建PDF,不如将其添加到文件名的开头并将其保存在顶级文件夹中。我以为我在switch部分的逻辑正确,但是也许我对JS不够熟悉,无法看到我的问题。
代码: ImportES = app.trustedFunction(function(){
var fileName = "/c/Users/jcoleman/Desktop/Endless Slings/Endless Sling Data.txt";
var outputDir = "/c/Users/jcoleman/Desktop/Endless Slings/";
var whichCert = this.getField("PFFSID").value;
var firstThree = whichCert.substr(0,3);
var whichFolder = "0";
var whichCase = whichCert.indexOf("Z");
var err = 0;
var idx = 0;
while (err == 0) {
err = this.importTextData(fileName, idx);
switch (whichCase) {
case 3: {
if (0 < firstThree && firstThree <49)
whichFolder = "z1-49/";
else if (49 < firstThree && firstThree <99)
whichFolder = "z50-99/";
else if (99 < firstThree && firstThree <149)
whichFolder = "z100-149/";
else if (149 < firstThree && firstThree <199)
whichFolder = "z150-199/";
else if (199 < firstThree && firstThree <249)
whichFolder = "z200-249/";
else if (249 < firstThree && firstThree <299)
whichFolder = "z250-299/";
else if (299 < firstThree && firstThree <349)
whichFolder = "z300-349/";
else if (349 < firstThree && firstThree <399)
whichFolder = "z350-399/";
else if (399 < firstThree && firstThree <449)
whichFolder = "z400-449/";
else if (449 < firstThree && firstThree <499)
whichFolder = "z450-499/";
else if (499 < firstThree && firstThree <549)
whichFolder = "z500-549/";
else if (549 < firstThree && firstThree <599)
whichFolder = "z550-599/";
else if (599 < firstThree && firstThree <649)
whichFolder = "z600-649/";
else if (649 < firstThree && firstThree <699)
whichFolder = "z650-699/";
else if (699 < firstThree && firstThree <749)
whichFolder = "z700-749/";
else if (749 < firstThree && firstThree <799)
whichFolder = "z750-799/";
else if (799 < firstThree && firstThree <849)
whichFolder = "z800-849/";
else if (849 < firstThree && firstThree <899)
whichFolder = "z850-899/";
else if (899 < firstThree && firstThree <949)
whichFolder = "z900-949/";
else if (949 < firstThree && firstThree <999)
whichFolder = "z950-999/";
break;
}
case -1: {
if (0 < firstThree && firstThree <49)
whichFolder = "1-49/";
else if (49 < firstThree && firstThree <99)
whichFolder = "50-99/";
else if (99 < firstThree && firstThree <149)
whichFolder = "100-149/";
else if (149 < firstThree && firstThree <199)
whichFolder = "150-199/";
else if (199 < firstThree && firstThree <249)
whichFolder = "200-249/";
else if (249 < firstThree && firstThree <299)
whichFolder = "250-299/";
else if (299 < firstThree && firstThree <349)
whichFolder = "300-349/";
else if (349 < firstThree && firstThree <399)
whichFolder = "350-399/";
else if (399 < firstThree && firstThree <449)
whichFolder = "400-449/";
else if (449 < firstThree && firstThree <499)
whichFolder = "450-499/";
else if (499 < firstThree && firstThree <549)
whichFolder = "500-549/";
else if (549 < firstThree && firstThree <599)
whichFolder = "550-599/";
else if (599 < firstThree && firstThree <649)
whichFolder = "600-649/";
else if (649 < firstThree && firstThree <699)
whichFolder = "650-699/";
else if (699 < firstThree && firstThree <749)
whichFolder = "700-749/";
else if (749 < firstThree && firstThree <799)
whichFolder = "750-799/";
else if (799 < firstThree && firstThree <849)
whichFolder = "800-849/";
else if (849 < firstThree && firstThree <899)
whichFolder = "850-899/";
else if (899 < firstThree && firstThree <949)
whichFolder = "900-949/";
else if (949 < firstThree && firstThree <999)
whichFolder = "950-999/";
}
}
if (err == -1)
app.alert("Error: Cannot Open File");
else if (err == -2)
app.alert("Error: Cannot Load Data");
else if (err == 1)
app.alert("Warning: User Cancelled File Select");
else if (err == 2)
app.alert("Warning: User Cancelled Row Select");
else if (err == 3)
app.alert("Warning: Missing Data");
else if (err == 0) {
this.saveAs(outputDir + whichFolder + "ES-" + this.getField("PFFSID").value + ".pdf");
idx++;
}
}
});
// menu item
app.addMenuItem({
cName: "ImportES",
cUser: "Import Endless Slings",
cParent: "Edit",
cExec: "ImportES()",
cEnable: "event.rc = (event.target != null);",
nPos: 1
});
答案 0 :(得分:0)
您似乎遇到了上下文问题。如果没有您的文件,我将无法进行测试,但这是我认为应该起作用的...
;WITH CTE AS
(
SELECT SUM(ISNULL(TRY_CAST(II.quantity AS INT), 1) * I.cost) * 1.0000 S,
II.itemnum
FROM inventory_ingredients II JOIN inventory I ON I.itemnum = II.ingredient
GROUP BY II.itemnum
)
UPDATE inventory
SET inventory.cost = CTE.S
FROM inventory JOIN CTE ON inventory.itemnum = CTE.itemnum;
答案 1 :(得分:0)
我在另一个论坛的帮助下解决了我的问题。这是我的变量,也是我从不让while循环定义它们的方式,我只在顶部声明了它们,因此循环仅将其视为一个常量值,这是导入的第一条记录。
所有人都要保持均衡饮食,不要忽视自己的水果和变量。