[WebMethod(EnableSession=true)]
public static void ShortFall(List<Dictionary<string, string>> Data)
{
List<dynamic> RetData = new List<dynamic>();
DataTable dtstock = new DataTable();
DBHelper.DBhelpercls db = new DBHelper.DBhelpercls();
List<dynamic> ShortfallTempArray = new List<dynamic>();
List<dynamic> ShortfallTempArray2 = new List<dynamic>();
List<dynamic> ShortfallArray = new List<dynamic>();
foreach (Dictionary<string, string> EachItems in Data)
{
dtstock = db.GetTable("SELECT ISNULL(Qty,0) AS Stock_Qnty FROM TBLActualStock WHERE ItemCode='" + EachItems["ItemCode"].ToString() + "' AND Mode=1");
if (dtstock.Rows.Count == 0)
{
ShortfallTempArray.Add(new { ItemCode = EachItems["ItemCode"].ToString(), ItemDesc = EachItems["ItemDesc"].ToString(), Qty =EachItems["Qty"].ToString(), Uom = EachItems["Unit"].ToString() });
}
else if (((Convert.ToSingle(dtstock.Rows[0]["Stock_Qnty"].ToString()) - Convert.ToSingle(EachItems["Qty"].ToString())) <= 0))
{
ShortfallTempArray.Add(new { ItemCode = EachItems["ItemCode"].ToString(), ItemDesc = EachItems["ItemDesc"].ToString(), Qty = (Convert.ToSingle(dtstock.Rows[0]["Stock_Qnty"].ToString()) - Convert.ToSingle(EachItems["Qty"].ToString())).ToString(), Uom = EachItems["Unit"].ToString() });
}
}
var summary = from p in ShortfallTempArray
let k = new
{
ItemCode = p.ItemCode,
ItemDesc = p.ItemDesc,
Uom = p.Uom
}
group p by k into t
select new
{
ItemCode = t.Key.ItemCode,
ItemDesc = t.Key.ItemDesc,
Uom = t.Key.Uom,
Qty = t.Sum(p => Convert.ToInt32(p.Qty))
};
foreach (var row in summary)
{
ShortfallTempArray2.Add(new { ItemCode = row.ItemCode, ItemDesc = row.ItemDesc, Qty = row.Qty.ToString(), Uom=row.Uom });
}
HttpContext.Current.Session["Short"] = ShortfallTempArray2;
}
在上面的代码中,当Qty是一个整数时,它可以正常工作; 但如果它浮动或小数,则下面的行会出现错误。
Qty = t.Sum(p => Convert.ToInt32(p.Qty))
我只是将Convert.ToInt32
更改为Convert.ToDouble
,然后出现以下错误....
无法将类型'double'隐式转换为'int'。一个明确的 存在转换(你错过了演员吗?)
答案 0 :(得分:0)
可能错误是Qty数据类型,因为它应该是整数类型。
答案 1 :(得分:0)
你可能正在尝试:
(INT)=(双)
你应该这样做:
Qty = (int)t.Sum(p => Convert.ToDouble(p.Qty));
或者将数量类型更改为加倍