using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Http;
using WebAPI.Models;
namespace WebAPI.Controllers
{
    /**
     * 找货单单
     */
    public class Sc_MouldProdMoveBillListController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public WebServer webserver = new WebServer();
        public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        public DAL.ClsSc_MouldScrapInBill BillNew0 = new DAL.ClsSc_MouldScrapInBill();   //模具报废入库对应单据类
        public DAL.ClsSc_MouldScrapInBill BillOld0 = new DAL.ClsSc_MouldScrapInBill();   //模具报废入库对应单据类
        /// 
        /// 根据包装单 返回此包装单内的相关信息
        /// 
        /// 
        /// 
        /// 检具维修工单列表
        /// 
        /// 
        [Route("Sc_CheckToolsRepair/GetCheckToolsRepairWorkBillList")]
        [HttpGet]
        public object GetCheckToolsRepairWorkBillList(string sWhere)
        {
            try
            {
                ds = Sc_CheckToolsRepairWorkBillList_s(sWhere);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "返回记录成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #region sql语句
        public static DataSet Sc_CheckToolsRepairWorkBillList_s(string sWhere)
        {
            return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_Sc_CheckToolsRepairWorkBillList ", "h_v_Sc_CheckToolsRepairWorkBillList");
        }
        #region 器具直接调拨单
        #region 器具直接调拨单列表
        [Route("Sc_MouldProdMoveBill/GetMouldProdMoveBill")]
        [HttpGet]
        public object GetMouldProdMoveBill(string sWhere,string user, string Organization)
        {
            try
            {
                //编辑权限 
                if (!DBUtility.ClsPub.Security_Log_second("Sc_MouldProdMoveBillList", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = Sc_GetMouldProdMoveBill(sWhere,Organization);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "返回记录成功!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public static DataSet Sc_GetMouldProdMoveBill(string sWhere, string Organization)
        {
            string sql1 = string.Format(@"select * from h_v_Sc_MouldProdMoveBillList where (调入组织='" + Organization + "' or 调出组织='" + Organization + "')");
            if (sWhere == null || sWhere.Equals(""))
            {
                return new SQLHelper.ClsCN().RunProcReturn(sql1+ "order by 制单日期 desc", "h_v_Sc_MouldProdMoveBillList");
            }
            else
            {
                string sql = sql1 + sWhere+ "order by 制单日期 desc";
                return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_Sc_MouldProdMoveBillList");
            }
        }
        #endregion
        #region[器具直接调拨单编辑时获取表头数据]
        [Route("Sc_MouldProdMoveBill/Sc_MouldProdMoveBillListCheckDetai")]
        [HttpGet]
        public ApiResult Sc_MouldProdMoveBillListCheckDetai(string HID)
        {
            if (string.IsNullOrEmpty(HID))
                return new ApiResult { code = -1, msg = "ID不能为空" };
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_Sc_MouldProdMoveBillList  where hmainid= " + HID + " ", "h_v_Sc_MouldProdMoveBillList");
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult { code = -1, msg = "不存在退库单号" };
            return new ApiResult { code = 1, msg = "查询成功", data = dataSet };
        }
        #endregion
        #region[器具直接调拨单编辑时获取表体数据]
        [Route("Sc_MouldProdMoveBill/Sc_MouldProdMoveBillListProjectDetai")]
        [HttpGet]
        public object Sc_MouldProdMoveBillListProjectDetai(string sqlWhere)
        {
            DataSet ds;
            DataSet ds1;
            List