/// <summary> /// 全选或全不选 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Checkall_CheckedChanged(object sender, EventArgs e) { foreach (ListViewRow Row in listRBRowData.Rows) { frmRBCreateLayout Layout = Row.Control as frmRBCreateLayout; Layout.setCheck(Checkall.Checked); } getAmount(); //计算报销单总金额 }
/// <summary> /// 创建消费记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Press(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(RBCC)) //判断成本中心是否已经选择 { throw new Exception("请选择成本中心!"); } else { RBInputDto RB = new RBInputDto(); //定义一个新的报销单 RB.CC_ID = RBCC; //成本中心编号 RB.RB_Note = this.TxtNote.Text; //报销单备注 //将选中的消费记录行项添加到报销单中 foreach (ListViewRow Row in listRBRowData.Rows) { frmRBCreateLayout layout = Row.Control as frmRBCreateLayout; //如果当前行项消费记录被选中 if (layout.checkNum() == 1) { //把选中行的消费记录行项的数据添加到报销单中 int RID = layout.getID(); RB_RowsDto RBRow = AutofacConfig.rBService.GetRowByRowID(RID); RB_RowsInputDto NewRBRow = new RB_RowsInputDto(); NewRBRow.R_ID = RBRow.R_ID; //消费记录编号 NewRBRow.R_TypeID = RBRow.R_TypeID; //消费类型编号 NewRBRow.R_Amount = RBRow.R_Amount; //消费记录金额 NewRBRow.R_Note = RBRow.R_Note; //消费记录日期 NewRBRow.R_ConsumeDate = RBRow.R_ConsumeDate; //消费日期 RB.RB_Rows.Add(NewRBRow); } } RB.RB_CreateUser = Client.Session["U_ID"].ToString(); //创建用户 ReturnInfo r = AutofacConfig.rBService.CreateRB(RB); if (r.IsSuccess == true) { //如果数据库添加报销记录成功 this.ShowResult = ShowResult.Yes; this.Close(); Toast("报销提交成功!"); } else { throw new Exception(r.ErrorInfo); } } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 更新全选状态 /// </summary> public void upCheckState() { int selectUserQty = 0; //设置当前选中行项为0 foreach (ListViewRow Row in listRBRowData.Rows) { frmRBCreateLayout layout = Row.Control as frmRBCreateLayout; int num = layout.checkNum(); selectUserQty += num; } if (selectUserQty == listRBRowData.Rows.Count) //当选中所有行项时 { Checkall.Checked = true; } else //当没有选中所有行项时 { Checkall.Checked = false; } }
/// <summary> ///计算报销单总金额 /// </summary> /// <remarks></remarks> public void getAmount() { try { decimal sumAmount = 0; foreach (ListViewRow Row in listRBRowData.Rows) { //判断消费记录是否选中,计算选中的消费记录总金额 frmRBCreateLayout layout = Row.Control as frmRBCreateLayout; decimal num = layout.getNum(); //获取选中行消费数量 sumAmount += num; } //将计算出来的选中的消费记录总金额显示在底部 lblAmount.Text = "¥" + sumAmount.ToString(); } catch (Exception ex) { Toast(ex.Message); } }