コード例 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] == null)
            {
                Response.Redirect("Error_404.aspx");
            }
            int id = Int32.Parse(Request.QueryString["id"]);

            using (var db = new UITestEntities())
            {
                Buyer buyer = db.Buyers.Single(u => u.ID == id);

                buyer.FirstName = fname.Text;
                buyer.LastName  = lname.Text;
                buyer.Address   = address.Text;
                buyer.Country   = country.Text;
                buyer.Telephone = telephone.Text;
                buyer.Fax       = fax.Text;
                buyer.Email     = email.Text;
                buyer.Remarks   = remarks.Text;

                db.SaveChanges();
            }

            Response.Redirect("Search_Buyer.aspx");
        }
コード例 #2
0
        protected void Submit(object sender, EventArgs e)
        {
            try
            {
                UITestEntities db = new UITestEntities();

                Suplier sup = new Suplier
                {
                    FirstName = fname.Text.ToString(),
                    LastName  = lname.Text.ToString(),
                    Address   = address.Text.ToString(),
                    Telephone = telephone.Text.ToString(),
                    Fax       = fax.Text.ToString(),
                    Email     = email.Text.ToString(),
                    Remarks   = remarks.Text.ToString()
                };

                db.Supliers.Add(sup);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #3
0
        protected void BuyerSaveBtn_Click(object sender, EventArgs e)
        {
            var buyer = new Buyer();

            using (UITestEntities DB = new UITestEntities())
            {
                try
                {
                    buyer.ID        = 1;
                    buyer.FirstName = fname.Text;
                    buyer.LastName  = lname.Text;
                    buyer.Address   = address.Text;
                    buyer.Country   = country.Text;
                    buyer.Telephone = telephone.Text;
                    buyer.Fax       = fax.Text;
                    buyer.Email     = email.Text;
                    buyer.Remarks   = remarks.Text;


                    DB.Buyers.Add(buyer);
                    DB.SaveChanges();
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                {
                    Exception raise = dbEx;
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            string message = string.Format("{0}:{1}",
                                                           validationErrors.Entry.Entity.ToString(),
                                                           validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            raise = new InvalidOperationException(message, raise);
                        }
                    }
                    throw raise;
                }
            }
        }