private void InitData() { //根据物品编号 找到物品id; DaGoods dg = mydb.DaGoods1.SingleOrDefault(a => a.VcNum == GoodsNum); if (dg != null) { var goodsHistory = mydb.DaContractGoods.Where(a => a.DaPurchaseContract.IntStatus >= 5 && a.IntGoodsID == dg.IntID); if (goodsHistory.Any(c => c != null)) { bsHistory.DataSource = goodsHistory.Select(a => new { 编号 = a.IntID, 物料编码 = a.DaGood.VcNum, 物品名称 = a.DaGood.VcName, 规格型号 = a.DaGood.VcNorms, 供应商 = a.DaPurchaseContract.DaSupplier.VcName, 采购单价 = a.MonPrice, 数量 = a.NumCount, 申请时间 = a.DaPurchaseContract.DtCreate, 采购人 = a.DaPurchaseContract.T_Users.UserName }).ToList(); } else { bsHistory.DataSource = new { 记录 = "无" }; } } }
private void InitDaGoodsSupplier() { if (dgvDaGoods.SelectedRows.Count < 1) { return; } var rowIndex = dgvDaGoods.SelectedRows[0].Index; DaGoods mDaGoods = (DaGoods)DaGoodsBindingSource[rowIndex]; DaSupplierBindingSource.DataSource = myEntity.DaGoodsSuppliers.Where(d => d.IntGoodsID == mDaGoods.IntID).Select(d => d.DaSupplier).AsNoTracking().ToList();// mDaGoods.DaGoodsSuppliers.Select(d => d.DaSupplier).ToList(); }
private void dgvDaGoods_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (e.ColumnIndex == dg删除.Index) { //删除 int daGoodsId = ((DaGoods)DaGoodsBindingSource[e.RowIndex]).IntID; DaGoods mDaGoods = myEntity.DaGoods1.SingleOrDefault(a => a.IntID == daGoodsId); if (mDaGoods.DaContractGoods.Count > 0) { MessageBox.Show("该物品已有采购订单,不能删除"); return; } if (MessageBox.Show("是否确认删除" + mDaGoods.VcName, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { return; } //myEntity.DaGoods1.Attach(mDaGoods); mDaGoods.DaGoodsSuppliers.Clear(); myEntity.DaGoods1.Remove(mDaGoods); int ret = myEntity.SaveChanges(); if (ret > 0) { InitDaGoods(); MessageBox.Show("删除成功"); } else { MessageBox.Show("删除失败"); } } if (e.ColumnIndex == dg修改.Index) { //修改 using (采购物品编辑 mForm = new 采购物品编辑()) { mForm.mDaGoodsID = ((DaGoods)DaGoodsBindingSource[e.RowIndex]).IntID; if (mForm.ShowDialog() == DialogResult.OK) { InitDaGoods(); } } } }
private void InitData() { if (myEntity == null) { myEntity = new MYDBEntities2(); } ZDUnitBindingSource.DataSource = myEntity.ZdGoodsUnits.ToList(); cmbUnit.DataSource = ZDUnitBindingSource; cmbUnit.DisplayMember = "VcDesc"; cmbUnit.ValueMember = "ID"; if (mDaGoodsID > 0) { //修改 mDaGoods = myEntity.DaGoods1.SingleOrDefault(d => d.IntID == mDaGoodsID); oldNum = mDaGoods.VcNum; //mDaGoodsTypeID = mda //cmbUnit.SelectedValue = mDaGoods.IntUnit; } else { //新增 string maxNum; GetMaxNum("1", out maxNum); mDaGoods = new DaGoods() { IntTypeID = mDaGoodsTypeID, VcNum = maxNum, IntStatus = 0 }; } txtNum.DataBindings.Add("Text", mDaGoods, "VcNum"); txtName.DataBindings.Add("Text", mDaGoods, "VcName"); txtNorms.DataBindings.Add("Text", mDaGoods, "VcNorms"); txtRemark.DataBindings.Add("Text", mDaGoods, "VcRemark"); txtTypeName.Text = myEntity.DaGoodsTypes.SingleOrDefault(d => d.IntID == mDaGoods.IntTypeID).VcType;// mDaGoodsTypeName; txtPrice.DataBindings.Add("Text", mDaGoods, "MonPrice", true); cmbUnit.DataBindings.Add("SelectedValue", mDaGoods, "IntUnit"); }