using BLL;
using Model;
using Lib;
using System.Data;
using System.Web.Mvc;
using FastReport.Web;
using System;
using BLL.DAL;
using FastReport;

namespace WMS.Areas.Data.Controllers
{
    public class StoreController : MasterPage
    {

        // GET: Data/Stroe
        [LoginFilter]
        public ActionResult StoreBasic()
        {
            //ViewBag.AreaList = LocalHelper.GetAreaList(string.Empty);
            //ViewBag.AddreList = LocalHelper.GetAddreList(string.Empty,string.Empty);
            ViewBag.MatType = LocalHelper.GetDictionaryHtml("MatType");
            ViewBag.Brand = LocalHelper.GetBrandItemsHtml();

            return View();
        }

        public ActionResult StoreDetail()
        {
            ViewBag.MatNo = Request.QueryString.Get("MatNo");

            if (Request.QueryString.Get("MatNo") != "")
            {
                DALStore dALStore = new DALStore();
                DataTable dt = dALStore.GetStoreDetail(Request.QueryString.Get("MatNo"), this.LoginDepartNum);
                string json = Common.JsonHelper.DataTableToJson(dt);

                ViewBag.Detail = json;
            }
            return View();
        }

        public ActionResult ReportShow()
        {
            string statu = Request.QueryString.Get("type");

            WebReport webReport = new WebReport();
            webReport.Width = System.Web.UI.WebControls.Unit.Percentage(150);
            webReport.Height = System.Web.UI.WebControls.Unit.Percentage(100);
            webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;
            webReport.PrintInBrowser = false;
            webReport.PrintInPdf = false;
            webReport.ShowExports = false;
            webReport.SinglePage = false;
            //webReport.ToolbarStyle = ToolbarStyle.Small;
            webReport.PrintInPdf = true;
            webReport.ShowPrint = true;
            webReport.PreviewMode = true;

            if (statu == "A")
            {
                StroeItems models = Session["Stitems"] as StroeItems;
                string path = "~/Report/库存明细报表.frx";
                path = Server.MapPath(path);
                webReport.Report.Load(path);

                DALStroeMat dALStroeMat = new DALStroeMat();
                DataSet ds = new DataSet();
                DataTable dt1 = new DataTable();
                dt1.Columns.Add("UserName");
                dt1.Columns.Add("CreatTime");
                DataRow row = dt1.NewRow();
                row["UserName"] = this.LoginName;
                row["CreatTime"] = DateTime.Now.ToString("yyyy-MM-dd");
                dt1.Rows.Add(row);
                dt1.TableName = "TbTitle";
                DataTable dt = dALStroeMat.GetStroeItems(models);
                ds.Tables.Add(dt);
                ds.Tables.Add(dt1);
                if (ds != null && ds.Tables != null && ds.Tables.Count > 0)
                {
                    webReport.Report.RegisterData(ds);

                    webReport.Report.GetDataSource("TbTitle").Enabled = true;
                    webReport.Report.GetDataSource("TbItems").Enabled = true;
                }
                webReport.ID = "库存明细报表";
                ViewBag.WebReport = webReport;
            }
            else
            {
                #region 库存报表
                StroeMat models = Session["Stm"] as StroeMat;

                string path = "~/Report/库存统计.frx";
                path = Server.MapPath(path);
                webReport.Report.Load(path);

                DALStroeMat dALStroeMat = new DALStroeMat();
                DataSet ds = new DataSet();
                DataTable dt1 = new DataTable();
                dt1.Columns.Add("UserName");
                dt1.Columns.Add("CreatTime");
                DataRow row = dt1.NewRow();
                row["UserName"] = this.LoginName;
                row["CreatTime"] = DateTime.Now.ToString("yyyy-MM-dd");
                dt1.Rows.Add(row);
                dt1.TableName = "UserInfo";
                DataTable dt = dALStroeMat.GetStroeMatDetail(models);
                ds.Tables.Add(dt);
                ds.Tables.Add(dt1);
                if (ds != null && ds.Tables != null && ds.Tables.Count > 0)
                {
                    webReport.Report.RegisterData(ds);

                    webReport.Report.GetDataSource("UserInfo").Enabled = true;
                    webReport.Report.GetDataSource("View_StroeMat_Material").Enabled = true;
                }
                webReport.ID = "库存统计";
                ViewBag.WebReport = webReport;
                #endregion
            }

            return View();
        }

        public ActionResult Dialog()
        {
            if (Request.QueryString.Get("type") == "2")
            {
                //ViewBag.PackFormat = LocalHelper.GetDictionaryHtml("Type");
                ViewBag.PackFormat = LocalHelper.PalletStore("Type");
                ViewBag.type = Request.QueryString.Get("type");
            }
            else
            {
                ViewBag.type = "1";
            }
            return View();
        }
    }
}