Example #1
0
        public ActionResult Contact()
        {
            ViewBag.Message = "與我們聯絡";

            /*
            List<string> DepartmentList = new List<string>();
            DepartmentList.Add("業務部");
            DepartmentList.Add("創意部");
            DepartmentList.Add("行銷部");

            ViewBag.DepartmentList = DepartmentList;

            return View();

            */

            List<department> departmentlist = new List<department>();

            SqlHelper hp = new SqlHelper();

            DataTable tb = hp.Sql2Table("select id,cname from dep");

            department depobj;
            foreach(DataRow r in tb.Rows)
            {
                depobj = new department();
                depobj.id = r["id"].ToString();
                depobj.departmentName = r["cname"].ToString();
                departmentlist.Add(depobj);
            }

            //return View(departmentlist);

            departmentlist.Clear();
            depobj = new department();
            depobj.id = "a001"; depobj.departmentName = "業務部";
            departmentlist.Add(depobj);

            depobj = new department();
            depobj.id = "a002"; depobj.departmentName = "創意部";
            departmentlist.Add(depobj);

            depobj = new department();
            depobj.id = "a003"; depobj.departmentName = "行銷部";
            departmentlist.Add(depobj);

            return View(departmentlist);
        }
        // GET: Department
        public ActionResult Index(string departmentid)
        {
            //ViewBag.departmentid = departmentid;
            SqlHelper hp = new SqlHelper();
            DataTable tb = hp.Sql2Table("select id,cname from dep where id=" + departmentid);
            department depobj = new department();

            if (tb.Rows.Count==1)
            {
                depobj.id = tb.Rows[0]["id"].ToString();
                depobj.departmentName = tb.Rows[0]["cname"].ToString();
            }
            else
            {
                ModelState.AddModelError("","無此編號的部門存在");
            }
            return View(depobj);
        }