public ActionResult AddCustomer(Customer_reltab newobj)
        {
            using (var db = new DBSession("default"))
            {
                ISession session = db.Session;

                try
                {
                    session.Save(newobj);
                }
                catch (Exception eX)
                {
                    db.Rollback = true;
                    return ErrorContent(eX.Message);
                }

                return Json(newobj);
            }
        }
        public ActionResult InitialTestData()
        {
            Stock_reltab sr1 = new Stock_reltab()
            {
                StockNo = 1004,
                Price = 6750.00M,
                TaxRate = 2,
            };

            Stock_reltab sr2 = new Stock_reltab()
            {
                StockNo = 1011,
                Price = 4500.23M,
                TaxRate = 2
            };

            Stock_reltab sr3 = new Stock_reltab()
            {
                StockNo = 1534,
                Price = 2234.00M,
                TaxRate = 2
            };

            Stock_reltab sr4 = new Stock_reltab()
            {
                StockNo = 1535,
                Price = 3456.23M,
                TaxRate = 2
            };

            Stock_reltab[] srs = new Stock_reltab[] {
                sr1,
                sr2,
                sr3,
                sr4
            };

            Customer_reltab cr1 = new Customer_reltab()
            {
                CustNo = 1,
                CustName = "Jean Nance",
                Street = "2 Avocet Drive",
                City = "Redwood Shores",
                State = "CA",
                Zip = "95054",
                Phone1 = "415-555-1212",
                Phone2 = "",
                Phone3 = ""
            };

            Customer_reltab cr2 = new Customer_reltab()
            {
                CustNo = 2,
                CustName = "John Nike",
                Street = "323 College Drive",
                City = "Edison",
                State = "NJ",
                Zip = "08820",
                Phone1 = "609-555-1212",
                Phone2 = "201-555-1212",
                Phone3 = ""
            };

            Customer_reltab[] crs = new Customer_reltab[]{
                cr1,
                cr2
            };

            using (ISession session = this.CreateSessionFactory().OpenSession())
            {
                using (ITransaction trans = session.BeginTransaction())
                {
                    try
                    {
                        foreach (var c in crs)
                        {
                            session.Save(c);
                        }

                        foreach (var sr in srs)
                        {
                            session.Save(sr);
                        }
                        trans.Commit();
                        session.Close();

                        ViewBag.message = "初始化数据完成";
                    }
                    catch (Exception eX)
                    {
                        trans.Rollback();
                        session.Close();
                        ViewBag.message = "初始化数据失败:" + eX.Message;
                    }
                }
            }

            return View("Index");
        }
        public ActionResult UpdateCustomer(Customer_reltab updobj)
        {
            using (var db = new DBSession("default"))
            {
                ISession session = db.Session;
                Customer_reltab old = session.Get<Customer_reltab>(updobj.CustNo);

                if (null != old)
                {
                    try
                    {
                        session.Evict(old);

                        session.Update(updobj);

                    }
                    catch (Exception eX)
                    {
                        db.Rollback = true;
                        return ErrorContent(eX.Message);
                    }

                    return Content("更新成功");
                }
                else
                {
                    return ErrorContent("要更新的客户信息不存在");
                }
            }
        }