using NFine.Application.WMS;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NFine.Code;
using System.Data.SqlClient;
using NFine.Data.Extensions;
using System.Data.OleDb;
using System.Configuration;
using ICS.Application.Entity;

namespace NFine.Web.Areas.WMS.Controllers
{
    public class ICSDisassemblyDocController : ControllerBase
    {
        // GET: WMS/ICSDisassemblyDoc
        ICSDisassemblyDocApp App = new ICSDisassemblyDocApp();
        public ActionResult ICSDisassem()
        {
            return View();
        }

        
        public ActionResult ICSDisassemblyDocAdd()
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string queryJson)
        {
            DataTable ListData = App.GetGridJson(queryJson, ref pagination);
            var JsonData = new
            {
                total = pagination.total,
                page = pagination.page,
                records = pagination.records,
                rows = ListData,
            };
            return Content(JsonData.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetSubGridJson(string Code)
        {
            DataTable ListData = App.GetSubGridJson(Code);
            var JsonData = new
            {

                rows = ListData,
            };
            return Content(JsonData.ToJson());
        }

        //查询符合套件的在库条码
        public ActionResult GetLotNoByKit(string InvCode, string WHCode, string ExtensionID, Pagination pagination)
        {
            DataTable ListData = App.GetLotNoByKit(InvCode, WHCode, ExtensionID, ref pagination);
            var JsonData = new
            {
                total = pagination.total,
                page = pagination.page,
                records = pagination.records,
                rows = ListData,
            };
            return Content(JsonData.ToJson());
        }

        //绑定套件
        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult CreateLogByKit(string Code, string Parameter)
        {
            string msg = App.CreateLogByKit(Code,Parameter);
            if (!string.IsNullOrEmpty(msg))
            {
                return Error(msg);
            }
            else
            {
                return Success("添加成功!");
            }
        }


        //批量生成散件条码
        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult CreateInventoryLot(string Code)
        {
            string msg = App.CreateInventoryLot(Code);
            if (!string.IsNullOrEmpty(msg))
            {
                return Error(msg);
            }
            else
            {
                return Success("生成成功!");
            }
        }

        //删除条码
        [HttpPost]
        [HandlerAjaxOnly]

        public ActionResult DeleteInventoryLot(string Code)
        {
            string msg = App.DeleteInventoryLot(Code);
            if (string.IsNullOrWhiteSpace(msg))
            {
                return Success("删除成功!");
            }
            else
            {
                return Error(msg);
            }
        }







    }
}