Ejemplo n.º 1
0
        //private void cmbSupplier_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    if (isLoading == true)
        //        return;
        //    if (cmbSupplier.SelectedIndex < 0)
        //        return;
        //    //显示供应商的第一个联系人
        //    DaSupplierContact mDaSupplierContact;
        //    ICollection<DaSupplierContact> mDaSupplierContacts = ((DaSupplier)DaSupplierBindingSource[cmbSupplier.SelectedIndex]).DaSupplierContacts;
        //    if (mDaSupplierContacts.Count() < 1)
        //    {
        //        return;
        //    }
        //    mDaSupplierContact = mDaSupplierContacts.Take(1).SingleOrDefault();
        //    txtLinkMan.Text = mDaSupplierContact.VcName;
        //    txtTel.Text = mDaSupplierContact.VcTel;
        //    txtFax.Text = mDaSupplierContact.VcFax;
        //    txtMobile.Text = mDaSupplierContact.VcMobile;

        //    mDaPurchaseContract.VcLinkMan = mDaSupplierContact.VcName;
        //    mDaPurchaseContract.VcTel = mDaSupplierContact.VcTel;
        //    mDaPurchaseContract.VcFax = mDaSupplierContact.VcFax;
        //    mDaPurchaseContract.VcMobile = mDaSupplierContact.VcMobile;
        //}



        private void btnSupplier_Click(object sender, EventArgs e)
        {
            if (goodsTable.Rows.Count > 0)
            {
                MessageBox.Show(@"更换供应商需先清除采购物品!");
                return;
            }
            using (var mForm = new  择供应商())
            {
                if (mForm.ShowDialog() == DialogResult.OK)
                {
                    //选择供应商
                    mDaSupplierId = mForm.mDaSupplierID[0];
                    var singleOrDefault = myEntity.DaSuppliers.SingleOrDefault(d => d.IntID == mDaSupplierId);
                    if (singleOrDefault != null)
                    {
                        txtSupplier.Text = singleOrDefault.VcName;
                        DaSupplierContact dsc = singleOrDefault.DaSupplierContacts.SingleOrDefault();
                        if (dsc != null)
                        {
                            txtLinkMan.Text = dsc.VcName;
                            mDaPurchaseContract.VcLinkMan = dsc.VcName;
                            txtMobile.Text = dsc.VcMobile;
                            mDaPurchaseContract.VcMobile = dsc.VcMobile;
                            txtTel.Text = dsc.VcTel;
                            mDaPurchaseContract.VcTel = dsc.VcTel;
                            txtFax.Text = dsc.VcFax;
                            mDaPurchaseContract.VcFax = dsc.VcFax;
                        }
                    }
                }
            }
        }
        private void llSelectSupplier_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (dgvDaGoods.SelectedRows.Count < 1)
            {
                MessageBox.Show("请选择采购物品");
                return;
            }
            using (择供应商 mForm = new  择供应商())
            {
                mForm.MultiSelect = true;
                mForm.mDaGoodsID  = ((DaGoods)DaGoodsBindingSource[dgvDaGoods.SelectedRows[0].Index]).IntID;
                //mForm.myEntity = myEntity;// = ((DaSupplier)DaSupplierBindingSource.Current).IntID;
                if (mForm.ShowDialog() == DialogResult.OK)
                {
                    //((System.Data.Entity.Infrastructure.IObjectContextAdapter)myEntity).ObjectContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, myEntity.DaSupplierContacts);
                    //((System.Data.Entity.Infrastructure.IObjectContextAdapter)myEntity).ObjectContext.AcceptAllChanges();
                    try
                    {
                        foreach (int suppilerId in mForm.mDaSupplierID)
                        {
                            DaGoodsSupplier mDaGoodsSupplier = new DaGoodsSupplier {
                                IntGoodsID = mForm.mDaGoodsID, IntSuppilerID = suppilerId
                            };
                            myEntity.DaGoodsSuppliers.Add(mDaGoodsSupplier);
                        }


                        int ret = myEntity.SaveChanges();

                        if (ret > 0)
                        {
                            MessageBox.Show("添加成功");
                        }
                        else
                        {
                            MessageBox.Show("添加失败");
                            return;
                        }

                        InitDaGoodsSupplier();
                    }
                    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));
                            }
                        }
                    }
                }
            }
        }