private void btnAnls_Click(object sender, EventArgs e) { int year = (int)numudYear.Value; short catgId = 0; if (cboxCatg.SelectedIndex != -1) { catgId = StringUtil.Obj2Short(cboxCatg.SelectedValue); } int?gId = null; if (null != autxtGoods.SelectedObj) { gId = StringUtil.Obj2Int(autxtGoods.SelectedObj); } AnlsRsltVO rsltVO = anlsManager.ProfitStatsByMonth(year, catgId, gId); if (null != rsltVO) { chartYearProfit.Series[0].Points.DataBindXY(rsltVO.Xdata, rsltVO.Ydata); decimal total = 0; if (null != rsltVO.Ydata) { foreach (decimal val in rsltVO.Ydata) { total += val; } chartYearProfit.Titles[0].Text = "总计:" + string.Format("{0:C}", total); } } }
private void btnAnls_Click(object sender, EventArgs e) { AnlsRsltVO rsltVO = anlsManager.ProfitStatsByUsr(dtpBeginDt.Value, dtpEndDt.Value); if (null != rsltVO) { chartUsrProfit.Series[0].Points.DataBindXY(rsltVO.Xdata, rsltVO.Ydata); } }
public AnlsRsltVO ProfitStatsByUsr(DateTime beginDt, DateTime endDt) { string sql = "SELECT u.UName as uname," + "SUM((sout.Num - sout.RfNum) * (sout.Price - stin.Price)) as amnt " + "FROM STOCKOUT sout," + "ORDERS ordr," + "INVENTORY inv," + "STOCKIN stin," + "Usr u " + "WHERE sout.OrderNO = ordr.OrderNO " + "AND sout.InvID = inv.InvID " + "AND inv.OrderNO = stin.OrderNO " + "AND ordr.CrtUID = u.UID " + "AND ordr.Direct =@direct "; Dictionary <string, object> values = new Dictionary <string, object>(); values.Add("direct", DIRECT.STOCK_OUT); if (null != beginDt && null != endDt) { sql += "AND ordr.CrtTmst>=@StDt AND ordr.CrtTmst<@EndDt "; endDt = ((DateTime)endDt).AddDays(1); values.Add("StDt", beginDt); values.Add("EndDt", endDt); } sql += "GROUP BY u.UID,u.UName ORDER BY u.UName"; AnlsRsltVO vo = new AnlsRsltVO(); List <object> xdata = new List <object>(); List <decimal> ydata = new List <decimal>(); DataTable dt = Connector.DbHelper.GetData(sql, values); if (null != dt) { foreach (DataRow row in dt.Rows) { xdata.Add(row["uname"]); ydata.Add(StringUtil.Obj2Decimal(row["amnt"])); } } vo.Xdata = xdata; vo.Ydata = ydata; return(vo); }
public AnlsRsltVO ProfitStatsByMonth(int year, short?subCatgId, int?goodsId) { string sql = "SELECT MONTH(ordr.CrtTmst) as mth," + "SUM((sout.Num - sout.RfNum) * (sout.Price - stin.Price)) as amnt " + "FROM STOCKOUT sout," + "ORDERS ordr," + "INVENTORY inv," + "STOCKIN stin," + "GOODS g " + "WHERE sout.OrderNO = ordr.OrderNO " + "AND sout.InvID = inv.InvID " + "AND inv.OrderNO = stin.OrderNO " + "AND inv.GID = g.GID " + "AND ordr.Direct =@direct "; Dictionary <string, object> values = new Dictionary <string, object>(); values.Add("direct", DIRECT.STOCK_OUT); if (year != 0) { sql += "AND YEAR(ordr.CrtTmst)=@year "; values.Add("year", year); } if (null != subCatgId && subCatgId != 0) { sql += "AND g.SubCatgID=@catgId "; values.Add("catgId", subCatgId); } if (null != goodsId && goodsId != 0) { sql += "AND inv.GID=@gId "; values.Add("gId", goodsId); } sql += "GROUP BY MONTH(ordr.CrtTmst)"; AnlsRsltVO vo = new AnlsRsltVO(); List <object> xdata = new List <object>(); List <decimal> ydata = new List <decimal>(); DataTable dt = Connector.DbHelper.GetData(sql, values); if (null != dt) { Dictionary <int, decimal> map = new Dictionary <int, decimal>(); int maxMth = year == DateTime.Now.Year ? DateTime.Now.Month : 12; foreach (DataRow row in dt.Rows) { map.Add(StringUtil.Obj2Int(row["mth"]), StringUtil.Obj2Decimal(row["amnt"])); } for (int i = 1; i <= maxMth; i++) { if (map.ContainsKey(i)) { ydata.Add(map[i]); } else { ydata.Add(new decimal(0)); } xdata.Add(i); } } vo.Xdata = xdata; vo.Ydata = ydata; return(vo); }