示例#1
0
        private void InitData()
        {
            if (MDaStockInId > 0)
            {
                //修改
                _mDaStockIn = myEntity.DaStockIns.SingleOrDefault(d => d.IntID == MDaStockInId);
            }
            else
            {
                //新增

                _mDaStockIn = new DaStockIn()
                {
                    IntContractGoodsID = MContractGoodsId,
                    IntEmpNum          = Classes.PubClass.UserId,
                    IntStatus          = 1 // 等待产品部检验
                };
            }

            //获取已入库数量
            txtHasStockInCount.Text =
                myEntity.DaStockIns.Where(d => d.IntContractGoodsID == MContractGoodsId && d.IntStatus != 3)
                .Sum(d => d.NumCount).ToString();

            DaContractGood daContractGood = myEntity.DaContractGoods.SingleOrDefault(d => d.IntID == MContractGoodsId);

            if (daContractGood != null)
            {
                //获取合同编号
                txtContractNum.Text = daContractGood.DaPurchaseContract.VcNum;
                //获取合同单价
                _mDaStockIn.MonPrice = daContractGood.MonPrice;
                //获取采购物品名称
                txtStockInName.Text = daContractGood.DaGood.VcName;
                //获取合同采购数量
                txtContractCount.Text = daContractGood.NumCount.ToString();
                //获取物品ID
                _mDaStockIn.IntGoodsID = daContractGood.IntGoodsID;
                //获取物品单位
                _mDaStockIn.VcUnit = daContractGood.DaGood.ZdGoodsUnit.VcDesc;
            }


            txtStockInCount.DataBindings.Add("Text", _mDaStockIn, "NumCount", true);
            txtPrice.DataBindings.Add("Text", _mDaStockIn, "MonPrice");
            txtUnit.DataBindings.Add("Text", _mDaStockIn, "VcUnit");
            txtSum.DataBindings.Add("Text", _mDaStockIn, "MonSum");
        }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (mDaPurchaseContractID != 0)
                {
                    //修改
                    if (mDaPurchaseContract.IntStatus == 2 || mDaPurchaseContract.IntStatus == 4)
                    {
                        mDaPurchaseContract.IntStatus = 1;
                    }
                }
                else
                {
                    //新增
                    //mDaPurchaseContract.IntGoodsID = mDaGoods.IntID;
                    //获取最新合同号
                    string strDateMonth = DateTime.Now.ToString("yyyyMMdd");
                    string mMaxNum      = myEntity.DaPurchaseContracts.Where(d => d.VcNum.Contains(strDateMonth)).Max(d => d.VcNum);
                    mMaxNum                           = string.IsNullOrEmpty(mMaxNum) ? strDateMonth + "001" : (Convert.ToInt64(mMaxNum) + 1).ToString();
                    txtContractNum.Text               = mMaxNum;
                    mDaPurchaseContract.VcNum         = mMaxNum;
                    mDaPurchaseContract.IntSupplierID = mDaSupplierId;
                    myEntity.DaPurchaseContracts.Add(mDaPurchaseContract);
                }
                //mDaPurchaseContract.IntGoodsID = mDaGoods.IntID;

                using (var mTrans = new TransactionScope())
                {
                    int ret = myEntity.SaveChanges();
                    if (ret > 0)
                    {
                        //添加 合同物品明细
                        foreach (DataRow mRow in goodsTable.Rows)
                        {
                            var mdcg = new DaContractGood()
                            {
                                IntContractID = mDaPurchaseContract.IntID,
                                IntGoodsID    = Convert.ToInt32(mRow["IntID"]),
                                IntEmpNum     = Classes.PubClass.UserId,
                                MonPrice      = Convert.ToDecimal(mRow["MonPrice"]),
                                NumCount      = Convert.ToInt32(mRow["NumCount"]),
                                MonSum        = Convert.ToDecimal(mRow["MonSum"])
                            };
                            myEntity.DaContractGoods.Add(mdcg);
                        }
                        ret = myEntity.SaveChanges();
                        if (ret > 0)
                        {
                            mTrans.Complete();
                            MessageBox.Show(@"保存成功");
                            DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            MessageBox.Show(@"保存失败");
                        }
                    }
                    else
                    {
                        MessageBox.Show(@"保存失败");
                    }
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                foreach (var item in ex.EntityValidationErrors)
                {
                    foreach (var item2 in item.ValidationErrors)
                    {
                        //MessageBox.Show(string.Format("{0}:{1}\r\n", item2.PropertyName, item2.ErrorMessage));
                        MessageBox.Show(string.Format("{0}\r\n", item2.ErrorMessage));
                    }
                }
            }
        }