/// <summary>
        /// 查询称重单列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsb_query_Click(object sender, EventArgs e)
        {
            Expression <Func <WeighingSettlementModel, bool> > expr =
                n => GetCondition(n, cmb_custName.SelectedValue.ToString(),
                                  Convert.ToInt32(cmbVoucherState.SelectedValue),
                                  dtp_DateStart.Value.Date, dtp_DateEnd.Value.Date
                                  );

            try
            {
                WeightListService w = new WeightListService();
                var q = w.GetWeighingList(expr);
                lbl_money.Text = q.ToList().Sum(s => s.settleAmount).ToString("C", CultureInfo.CreateSpecificCulture("ZH-HANS"));

                #region add amount

                WeighingViewModel m = new WeighingViewModel();
                m.WeighingDate = "合计";
                m.netWeight    = q.Sum(x => x.netWeight);
                m.settleAmount = q.Sum(x => x.settleAmount);

                q.Add(m);

                dgv_content.DataSource = q;

                #endregion

                #region apperance

                this.FontBond();
                this.BlankCell();
                this.ThoundSeparate();

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show("数据查询错误:" + ex.Message + ex.InnerException, "数据查询提示");
                return;
            }



            //处理数据为空示和时的数据转换错误,可先转成泛型再求和
            //ToString("C",CultureInfo.CreateSpecificCulture("ZH-HANS"),如果只选择参数“C”,
            //则只显示千分符与默认文化区域为货币符号,如是区域选择美国,则货币符号则显示为“$”



            if (dgv_content.RowCount > 0)
            {
                tsb_delete.Enabled = true;
            }
        }
Exemple #2
0
        public List <WeighingViewModel> GetWeighingList(Expression <Func <WeighingSettlementModel, bool> > expr)
        {
            List <WeighingViewModel> list = new List <WeighingViewModel>();

            using (var db = new ScrapSettleContext())
            {
                var query = from d in new EnumService().GetVoucherState()
                            join q in db.WeighingSettlement.Where(expr.Compile()) on d.Key equals q.auditFlag
                            join c in db.Customers
                            on q.CustmerCode equals c.CusCode.ToString()
                            join p in db.Peple on q.personCode equals p.Code.ToString()
                            join s in db.Scraps on q.scrapCode equals s.ScrapCode.ToString()


                            select new
                {
                    q.WeighingDate,
                    q.vocherNO,
                    c.CusName,
                    s.ScrapName,
                    q.proportion,
                    q.webUnitPrice,
                    q.settleUnitPrice,
                    q.netWeight,
                    q.settleAmount,
                    voucherState = d.Value,
                    note         = q.note
                };

                foreach (var item in query)
                {
                    WeighingViewModel m = new WeighingViewModel();
                    m.WeighingDate    = item.WeighingDate.ToString();
                    m.vocherNO        = item.vocherNO;
                    m.CusName         = item.CusName;
                    m.ScrapName       = item.ScrapName;
                    m.proportion      = item.proportion;
                    m.webUnitPrice    = item.webUnitPrice;
                    m.settleUnitPrice = item.settleUnitPrice;
                    m.netWeight       = item.netWeight;
                    m.settleAmount    = item.settleAmount;
                    m.voucherState    = item.voucherState;
                    m.note            = item.note;

                    list.Add(m);
                }

                return(list);
            }
        }