我正在使用 WCF引用来调用Quote
表中的最后一行。现在我在我的WCF应用程序中编写了这个方法以获取最后一行,但我不知道它是否有效(我正在尝试测试它):
public void GetLastQuote()
{
using (TruckDb db = new TruckDb())
{
var quote = (from qData in db.Quotes
where qData.Id == qData.RepresetativeId
orderby qData.Id descending
select qData).First();
}
}
在我的WPF应用程序中,我正在使用WCF引用并调用GetLastQuoteAsync()
方法,但它给出了以下错误:
无法将void分配给隐式类型的局部变量
以下是我在WPF应用程序中尝试调用GetLastQuoteAsync()
引用的方法。
private async void wListOfBills_Loaded(object sender, RoutedEventArgs e)
{
using (TruckServiceClient client = new TruckServiceClient())
{
var quote = await client.GetLastQuoteAsync(); // -> This is where the error lies.
var bills = await client.GetListOfBillsAsync(quote.Item.Id);
if (bills == null)
{
dgFloor.IsEnabled = true;
return;
}
dgFloor.ItemsSource = bills.Select(x => new ListOfBillsView
{
Code = x.StockCode,
Group = x.GroupName,
Description = x.StockDescription,
Qty = x.Quantity,
Length = x.Length,
Width = x.Width,
Weight = x.Weight,
Price_m = x.PricePerMeter,
Cost = x.Cost,
Section = x.TruckSection.ToString()
}).ToList();
}
}
我看到有些人有同样的问题,但我不完全了解如何在我自己的问题中实施解决方案。如果有人可以提供帮助,我将不胜感激! :)
答案 0 :(得分:2)
你想调用你的查询返回的内容,但是围绕该查询的方法没有返回任何内容,因为它的类型是无效的。
我假设您要返回public static void main(String[] args) {
try {
File firstFile = new File("/Users/TLQ/Desktop/report-12689-M2398-1.xlsx");
File secondFile = new File("/Users/TLQ/Desktop/report-12695-M2390-1.xlsx");
FileInputStream excellFile1 = new FileInputStream(firstFile);
FileInputStream excellFile2 = new FileInputStream(secondFile);
org.apache.poi.ss.usermodel.Workbook workbook1 = WorkbookFactory.create(excellFile1);
org.apache.poi.ss.usermodel.Workbook workbook2 = WorkbookFactory.create(excellFile2);
org.apache.poi.ss.usermodel.Sheet sheet1a = workbook1.getSheetAt(0);
org.apache.poi.ss.usermodel.Sheet sheet2a = workbook2.getSheetAt(0);
addSheet(sheet1a, sheet2a,secondFile.getAbsolutePath().substring(secondFile.getAbsolutePath().lastIndexOf("/")+1, secondFile.getAbsolutePath().indexOf(".")));
excellFile1.close();
// save merged file
File mergedFile = new File(
"/Users/TLQ/Desktop/Albert_1.xlsx");
if (!mergedFile.exists()) {
mergedFile.createNewFile();
}
FileOutputStream out = new FileOutputStream(mergedFile);
workbook1.write(out);
out.close();
System.out.println(firstFile.getAbsolutePath().substring(firstFile.getAbsolutePath().lastIndexOf("/")+1, firstFile.getAbsolutePath().indexOf(".")));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void addSheet(org.apache.poi.ss.usermodel.Sheet mergedSheet, org.apache.poi.ss.usermodel.Sheet sheet,String name) {
// map for cell styles
Map<Integer, org.apache.poi.ss.usermodel.CellStyle> styleMap = new HashMap<Integer, org.apache.poi.ss.usermodel.CellStyle>();
org.apache.poi.ss.usermodel.Row row2 = mergedSheet.createRow((short) 0);
org.apache.poi.ss.usermodel.Cell mcell2 = row2.createCell((short) 0);
mcell2.setCellValue("report-12689-M2398-1.xlsx");
// This parameter is for appending sheet rows to mergedSheet in the end
org.apache.poi.ss.usermodel.Row row1 = sheet.createRow((short) 0);
org.apache.poi.ss.usermodel.Cell mcell = row1.createCell((short) 0);
mcell.setCellValue(name);
org.apache.poi.ss.usermodel.Row row1Empty = sheet.createRow((short) 0);
org.apache.poi.ss.usermodel.Cell mcellEmpty = row1.createCell((short) 0);
int len = mergedSheet.getLastRowNum();
for (int j = sheet.getFirstRowNum(); j <= sheet.getLastRowNum(); j++) {
org.apache.poi.ss.usermodel.Row row = sheet.getRow(j);
org.apache.poi.ss.usermodel.Row mrow = mergedSheet.createRow(len + j + 1);
try {
for (int k = row.getFirstCellNum(); k < row.getLastCellNum(); k++) {
org.apache.poi.ss.usermodel.Cell cell=null;
if(row.getCell(k)!=null){
cell = row.getCell(k);
}else{
cell= row.createCell(k);
}
mcell = mrow.createCell(k);
if (cell.getSheet().getWorkbook() == mcell.getSheet()
.getWorkbook()) {
mcell.setCellStyle(cell.getCellStyle());
} else {
int stHashCode = cell.getCellStyle().hashCode();
org.apache.poi.ss.usermodel.CellStyle newCellStyle = styleMap.get(stHashCode);
if (newCellStyle == null) {
newCellStyle = mcell.getSheet().getWorkbook()
.createCellStyle();
newCellStyle.cloneStyleFrom(cell.getCellStyle());
styleMap.put(stHashCode, newCellStyle);
}
mcell.setCellStyle(newCellStyle);
}
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
mcell.setCellFormula(cell.getCellFormula());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
mcell.setCellValue(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
mcell.setCellValue(cell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
mcell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
mcell.setCellValue(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
mcell.setCellErrorValue(cell.getErrorCellValue());
break;
default:
mcell.setCellValue(cell.getStringCellValue());
break;
}
}
} catch (Exception e) {
}
}
}
类型的对象,因此您需要将方法更改为:
Quote
同样//change from void to Quote
public Quote GetLastQuote()
{
using (TruckDb db = new TruckDb())
{
var quote = (from qData in db.Quotes
where qData.Id == qData.RepresetativeId
orderby qData.Id descending
select qData).First();
//new
return quote;
}
}
与GetLastQuote()
不同您是否发布了错误的方法,会产生同样的错误?
如果还有此方法的异步版本,它应该看起来类似于:
GetLastQuoteAsync()