private void summeryExpenseDteail(List <TB_EXPENSE> detail) { dic = new Dictionary <TB_EXPENSE_SUMMERY, List <TB_EXPENSE> >(); for (int i = 0; i < detail.Count; i++) { string opname = detail[i].OPNAME; bool isExit = false; foreach (KeyValuePair <TB_EXPENSE_SUMMERY, List <TB_EXPENSE> > kvp in dic) { if ((kvp.Key as TB_EXPENSE_SUMMERY).opname == opname) { isExit = true; break; } } if (isExit == false) { TB_EXPENSE_SUMMERY es = new TB_EXPENSE_SUMMERY(); es.opname = opname; es.year = cmbYear.Text; es.month = cmbMonth.Text; es.id = detail[i].OBJECTID; List <TB_EXPENSE> ls = detail.FindAll(a => a.OPNAME == opname); decimal money = (from m in ls select m.MONEY).Sum(); es.money = money; dic.Add(es, ls); } } List <TB_EXPENSE_SUMMERY> lses = new List <TB_EXPENSE_SUMMERY>(); foreach (KeyValuePair <TB_EXPENSE_SUMMERY, List <TB_EXPENSE> > kvp in dic) { TB_EXPENSE_SUMMERY es = new TB_EXPENSE_SUMMERY(); es = kvp.Key as TB_EXPENSE_SUMMERY; lses.Add(es); } this.dgSummery.ItemsSource = null; this.dgSummery.ItemsSource = lses; }
private void dgSummery_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (dgSummery.SelectedItem != null) { TB_EXPENSE_SUMMERY item = dgSummery.SelectedItem as TB_EXPENSE_SUMMERY; foreach (KeyValuePair <TB_EXPENSE_SUMMERY, List <TB_EXPENSE> > kvp in dic) { if (kvp.Key as TB_EXPENSE_SUMMERY == item) { TB_PROJECT proj = this.txtProj.Tag as TB_PROJECT; //工程类型 List <TB_EXPENSE> ls = new List <TB_EXPENSE>(); if (proj != null && (proj.CREATEUSER != Global.g_usercode || Global.g_userrole == 8 || Global.g_userrole == 9)) { ls = screening(kvp.Value as List <TB_EXPENSE>); } else { ls = kvp.Value as List <TB_EXPENSE>; } var sortedList = from items in ls orderby items.GROUPNO, items.Id descending select items; ls = sortedList.ToList(); //这个时候会排序 decimal totalmoney = 0; int _groupno = -1; List <string> kmls = new List <string>(); //科目名称 for (int i = 0; i < ls.Count; i++) { string _km = ls[i].EXPENS; if (!kmls.Contains(_km)) { kmls.Add(_km); } //处理成组 if (ls[i].GROUPNO > 0 && _groupno != ls[i].GROUPNO) { _groupno = ls[i].GROUPNO; ls[i].STRGROUPNO = "┓"; ls[i].grouptotal = getGroupTotal(ls, _groupno); } else if (_groupno == ls[i].GROUPNO) { ls[i].STRGROUPNO = "┃"; if (i + 1 < ls.Count && _groupno != ls[i + 1].GROUPNO) { ls[i].STRGROUPNO = "┛"; } if (i + 1 == ls.Count) { ls[i].STRGROUPNO = "┛"; } } if (ls[i].GROUPNO == 0) { ls[i].STRGROUPNO = ""; } totalmoney += ls[i].MONEY; if (ls[i].RESPONSESTATUS == 1) { ls[i].StrResponseStatus = "驳回"; } else if (ls[i].RESPONSESTATUS == 0) { ls[i].StrResponseStatus = "待审"; } else if (ls[i].RESPONSESTATUS == 2) { ls[i].StrResponseStatus = "已审"; } if (ls[i].LEADERRESPONSESTATUS == 1) { ls[i].StrLeaderResponseStatus = "驳回"; } else if (ls[i].LEADERRESPONSESTATUS == 0) { ls[i].StrLeaderResponseStatus = "待审"; } else if (ls[i].LEADERRESPONSESTATUS == 2) { ls[i].StrLeaderResponseStatus = "已审"; } } this.dgExpense.ItemsSource = ls; if (ls != null) { dgExpense.SelectedIndex = 0; } string foot = ""; for (int i = 0; i < kmls.Count; i++) { string _km = kmls[i]; List <TB_EXPENSE> _expls = ls.FindAll(a => a.EXPENS == _km); if (_expls.Count > 0) { int counts = _expls.Count; decimal kmtotal = 0; for (int j = 0; j < _expls.Count; j++) { kmtotal += _expls[j].MONEY; } foot += " " + _km + ": 共" + counts.ToString() + "张 合计金额" + kmtotal.ToString() + "元;"; } } this.labFoot.Content = foot; this.labTotal.Content = "共:" + ls.Count + "张 合计:" + totalmoney.ToString() + "元"; } } } }