using MVCOne.Models;
using System.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Mvc;
using MVC;
using GrapeCity.ActiveReports;

namespace MVCOne.Controllers
{
    
    public class HomeController : Controller
    {
        public static string name = "";
        public static string ID = "";
        //public ActionResult Index()
        //{
        //    return View();
        //}
        //[ValidateAntiForgeryToken]
        public ActionResult Index(Customer register)
        {


            name = ((register.UserName == null)? "0": register.UserName.ToString());

            ID = ((register.DisplayName == null) ? "0" : register.DisplayName.ToString());

            return View(register);
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public DataTable returndata1()
        {


            string nameone  = name;
            DataTable dt = new DataTable();           

            dt.Columns.Add("产品编号");
            dt.Columns.Add("产品名称");
            dt.Columns.Add("单价");
            dt.Columns.Add("库存量");
            dt.Rows.Add("A001", "苹果", 10, 300);
            dt.Rows.Add("A002", "葡萄", 20, 200);
            dt.Rows.Add("A003", "荔枝", 30, 600);
            dt.Rows.Add("A004", "芒果", 40, 300);
            dt.Rows.Add("A005", "油桃", 20, 330);
            dt.Rows.Add("A006", "猕猴桃", 30, 410);
            dt.Rows.Add("A007", "菠萝", 70, 360);
            dt.Rows.Add("A008", "提子", 25, 280);
            dt.Rows.Add("A009", "西瓜", 80, 500);
            dt.Rows.Add("A010", "香蕉", 30, 400);
            return dt;
        }

        public DataTable returndata( string connStr)
        {
            DataTable dt = new DataTable();          
            Access dl = new Access(connStr);
            string nameone = name;
            string Id = ID;                              
            if (ID != "0" && nameone != "0")
            {
                string productSql = string.Format("select 订单.* from 订单 where 货主名称='{0}' and 货主城市='{1}'", nameone, Id);
                dt = dl.ExecuteDataset(productSql);
                return dt;
            }
            if (nameone != "0" && ID == "0")
            {
                string productSql = string.Format("select 订单.* from 订单 where 货主名称='{0}' ", nameone);
                dt = dl.ExecuteDataset(productSql);
                return dt;
            }
            if (nameone =="0" && ID != "0")
            {
                string productSql = string.Format("select 订单.* from 订单 where 货主城市='{0}' ", ID);
                dt = dl.ExecuteDataset(productSql);
                return dt;
            }
            if (nameone == "0" && ID == "0")
            {
                string productSql = string.Format("select 订单.* from 订单 ");
                dt = dl.ExecuteDataset(productSql);
                return dt;
            }
            else
            {
                return dt;
            }
        }
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}