wtt
2024-06-27 fd0dd6012b6d710896232f983a738f4b08525a8f
WebAPI/Controllers/SBGL/Gy_EquipFileMainController.cs
@@ -1,4 +1,6 @@
using Newtonsoft.Json.Linq;
using DBUtility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
@@ -18,6 +20,7 @@
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        public DLL.ClsGy_EquipFileMain BillNew0 = new DLL.ClsGy_EquipFileMain();
        public DLL.ClsGy_EquipFileMain BillOld0 = new DLL.ClsGy_EquipFileMain();
        public DAL.ClsGy_EquipFileMain BillOld = new DAL.ClsGy_EquipFileMain();
        #region 设备档案列表
@@ -46,22 +49,12 @@
                    ds = oCN.RunProcReturn(sql, "h_v_Gy_EquipFileMainList");
                }
                //if (ds.Tables[0].Rows.Count != 0 || ds != null)
                //{
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
                //}
                //else
                //{
                //objJsonResult.code = "0";
                //objJsonResult.count = 0;
                //objJsonResult.Message = "无数据";
                //objJsonResult.data = null;
                //return objJsonResult;
                //}
            }
            catch (Exception e)
            {
@@ -101,9 +94,23 @@
                return objJsonResult;
            }
            DLL.ClsGy_EquipFileMain oBill = new DLL.ClsGy_EquipFileMain();
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
            oCN.BeginTran();
            ds = oCN.RunProcReturn("select * from Gy_EquipFileBillMain where HInterID=" + HItemID, "Gy_EquipFileBillMain");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (int.Parse(ds.Tables[0].Rows[0]["HBillStatus"].ToString()) > 1)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据当前处于不能删除状态!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.RunProc("Delete From Gy_EquipFileBillMain  where HInterID=" + lngBillKey);
                oCN.RunProc("Delete From Gy_EquipFileBillSub_MaintainRule  where HInterID=" + lngBillKey);
                oCN.RunProc("Delete From Gy_EquipFileBillSub_DotCheckRule  where HInterID=" + lngBillKey);
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "删除成功";
@@ -118,6 +125,7 @@
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
@@ -148,6 +156,35 @@
        }
        #endregion
        #region[设备档案编辑时获取子表数据]
        [Route("Gy_EquipFileMain/Gy_EquipFileSubDetai")]
        [HttpGet]
        public object Gy_EquipFileSubDetai(long HInterID)
        {
            try
            {
                List<DataTable> tableList = new List<DataTable>();
                ds = oCN.RunProcReturn("select a.*,b.HBillNo from Gy_EquipFileBillSub_MaintainRule AS a left join Sb_EquipMaintainRuleBillMain as b on b.HInterID = a.HMaintainRuleID where a.HInterID = " + HInterID, "Gy_EquipFileBillSub_MaintainRule");
                tableList.Add(ds.Tables[0]);
                ds = oCN.RunProcReturn("select a.*,b.HBillNo from Gy_EquipFileBillSub_DotCheckRule AS a left join Sb_EquipDotCheckRuleBillMain as b on b.HInterID = a.HDotCheckRuleID where a.HInterID = " + HInterID, "Gy_EquipFileBillSub_DotCheckRule");
                tableList.Add(ds.Tables[0]);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = tableList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 设备档案新增保存
        /// <summary>
        /// 模治具分类-保存按钮
@@ -163,11 +200,12 @@
                var _value = oMain["oMain"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg2 = sArray[0].ToString();
                string msg3 = sArray[1].ToString();
                string msg4 = sArray[2].ToString();
                string msg2 = sArray[0].ToString(); //主表数据
                string msg3 = sArray[1].ToString(); //子表1
                string msg4 = sArray[2].ToString(); //子表2
                string msg5 = sArray[3].ToString(); //用户
                if (!DBUtility.ClsPub.Security_Log("Gy_EquipFile_Edit", 1, false, msg4))
                if (!DBUtility.ClsPub.Security_Log("Gy_EquipFile_Edit", 1, false, msg5))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -208,7 +246,10 @@
                string HLogo = list[0].HLogo;                //√      varchar(50)   //品牌
                int HSellSupID = list[0].HSellSupID;              // √   int      //供应商(Gy_Supplier)
                int HMakeSupID = list[0].HMakeSupID;              // int      //制造商 (Gy_Supplier) 
                string HMaker = msg4;
                string HMainSourceFlag = list[0].HMainSourceFlag;             //varchar(10) //是否主生产设备(否,是)
                string HMacAddress = list[0].HMacAddress;   // varchar(50) //数采物理地址
                int HMainSourceID = list[0].HMainSourceID;  //int //所属主生产设备(Gy_EquipFileBillMain)
                string HMaker = msg5;
                string HMakeDate = DateTime.Now.Date.ToString();
                int HEquipDotCheckRuleInterID = list[0].HEquipDotCheckRuleInterID;
                int HEquipMaintainRuleInterID = list[0].HEquipMaintainRuleInterID;
@@ -222,22 +263,30 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DataSet DS = oCN.RunProcReturn("Select * from Gy_EquipFileBillMain Where  HEquipFileNumber='" + HEquipFileNumber + "' and HInterID<>" + HInterID, "Gy_EquipFileBillMain", ref Pub_Class.ClsPub.sExeReturnInfo);
                if (DS.Tables[0].Rows.Count != 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "代码重复!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //若MAINDI重复则重新获取
                oCN.BeginTran();
                //主表
                oCN.RunProc("Insert into Gy_EquipFileBillMain " +
                   " (hbillno,HEquipFileNumber,HEquipFileNo,HName,HModel,HModel2,HMaterID,HUnitID,HOutComDate" +
                   " (HInterID,hbillno,HEquipFileNumber,HEquipFileNo,HName,HModel,HModel2,HMaterID,HUnitID,HOutComDate" +
                   ",HOutComNo,HDeptID,HUseEmpID,HRepairEmpID,HAddress,HSetupDate,HStartupDate,HStatus," +
"HEquipFileTypeID,HProNum,HBarCode,HWorkArea,HLogo,HSellSupID,HMakeSupID,hbilltype,HDate,HYear,HMaker,HMakeDate,HEquipMaintainRuleInterID,HEquipDotCheckRuleInterID,HSourceID) " +
                   " Values('" + hbillno + "','" + HEquipFileNumber + "','" + HEquipFileNo + "','" + HName + "','" + HModel + "','" + HModel2 + "'," + HMaterID + "," + HUnitID +
"HEquipFileTypeID,HProNum,HBarCode,HWorkArea,HLogo,HSellSupID,HMakeSupID,hbilltype,HDate,HYear,HMaker,HMakeDate,HEquipMaintainRuleInterID,HEquipDotCheckRuleInterID,HSourceID,HMainSourceFlag,HMacAddress,HMainSourceID) " +
                   " Values("+ HInterID+",'" + hbillno + "','" + HEquipFileNumber + "','" + HEquipFileNo + "','" + HName + "','" + HModel + "','" + HModel2 + "'," + HMaterID + "," + HUnitID +
                   ",'" + HOutComDate + "','" + HOutComNo + "'," + HDeptID + "," + HUseEmpID + "," + HRepairEmpID + ",'" + HAddress +
                   "','" + HSetupDate + "','" + HStartupDate + "','" + HStatus + "'," + HEquipFileTypeID + ",'" + HProNum +
                   "','" + HBarCode + "','" + HWorkArea + "','" + HLogo + "'," + HSellSupID + "," + HMakeSupID + ",'3308','" + HDate + "','" + HYear + "','" + HMaker + "','" + HMakeDate + "','" + HEquipMaintainRuleInterID + "','" + HEquipDotCheckRuleInterID +"'," + HSourceID + ")", ref DBUtility.ClsPub.sExeReturnInfo);
                   "','" + HBarCode + "','" + HWorkArea + "','" + HLogo + "'," + HSellSupID + "," + HMakeSupID + ",'3308','" + HDate + "','" + HYear + "','" + HMaker + "','" + HMakeDate + "','" + HEquipMaintainRuleInterID + "','" + HEquipDotCheckRuleInterID +"'," + HSourceID + ",'" + HMainSourceFlag + "','" + HMacAddress + "','" + HMainSourceID + "')", ref DBUtility.ClsPub.sExeReturnInfo);
                //修改上级为非末级代码
                objJsonResult = AddBillSub(msg3, msg4, HInterID, hbillno, 1);
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "新增成功!";
                //objJsonResult.data = null;
                return objJsonResult;
            }
@@ -265,11 +314,12 @@
                var _value = oMain["oMain"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg2 = sArray[0].ToString();
                string msg3 = sArray[1].ToString();
                string msg4 = sArray[2].ToString();
                string msg2 = sArray[0].ToString(); //主表数据
                string msg3 = sArray[1].ToString(); //子表1
                string msg4 = sArray[2].ToString(); //子表2
                string msg5 = sArray[3].ToString(); //用户
                if (!DBUtility.ClsPub.Security_Log("Gy_EquipFile_Edit", 1, false, msg4))
                if (!DBUtility.ClsPub.Security_Log("Gy_EquipFile_Edit", 1, false, msg5))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -306,7 +356,10 @@
                string HLogo = list[0].HLogo;                //√      varchar(50)   //品牌
                int HSellSupID = list[0].HSellSupID;              // √   int      //供应商(Gy_Supplier)
                int HMakeSupID = list[0].HMakeSupID;              // int      //制造商 (Gy_Supplier)
                string HUpDater = msg4;
                string HMainSourceFlag = list[0].HMainSourceFlag;             //varchar(10) //是否主生产设备(否,是)
                string HMacAddress = list[0].HMacAddress;   // varchar(50) //数采物理地址
                int HMainSourceID = list[0].HMainSourceID;  //int //所属主生产设备(Gy_EquipFileBillMain)
                string HUpDater = msg5;
                string HUpDateDate = DateTime.Now.Date.ToString();
                int HEquipDotCheckRuleInterID = list[0].HEquipDotCheckRuleInterID;
                int HEquipMaintainRuleInterID = list[0].HEquipMaintainRuleInterID;
@@ -361,19 +414,20 @@
                    ",HLogo='" + HLogo + "'" +
                    ",HSellSupID=" + HSellSupID +
                    ",HMakeSupID= " + HMakeSupID +
                    ",HUpDater= '" + HUpDater + "'" +
                    ",HUpDater= '" + HUpDater + "'" +
                    ",HUpDateDate= '" + HUpDateDate + "'" +
                    ",HEquipDotCheckRuleInterID='" + HEquipDotCheckRuleInterID + "'" +
                    ",HEquipMaintainRuleInterID='" + HEquipMaintainRuleInterID + "'" +
                    ",HSourceID='" + HSourceID + "'" +
                    ",HMainSourceFlag= '" + HMainSourceFlag + "'" +
                    ",HMacAddress= '" + HMacAddress + "'" +
                    ",HMainSourceID = '" + HMainSourceID + "'" +
                    " Where HInterID=" + HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                //修改子项目代码
                //oCN.RunProc("exec h_p_Gy_UpdateNumber Gy_RepairCheck,'" + HNumber + ".','" + this.HOldNumber + ".'", ref DBUtility.ClsPub.sExeReturnInfo);
                //
                objJsonResult = AddBillSub(msg3, msg4, HInterID, list[0].HBillNo, 2);
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "修改成功!";
                //objJsonResult.data = null;
                return objJsonResult;
            }
@@ -389,13 +443,117 @@
        }
        #endregion
        #region 设备档案保存子表数据
        /// <summary>
        /// 子表数据新增或者编辑
        /// </summary>
        /// <param name="msg3"></param>
        /// <param name="msg4"></param>
        /// <param name="HInterID"></param>
        /// <param name="HBillNo"></param>
        /// <param name="OperationType">1为添加2为编辑</param>
        /// <returns></returns>
        public json AddBillSub(string msg3, string msg4, long HInterID, string HBillNo, int OperationType)
        {
                List<ClsGy_EquipFileBillSub_MaintainRule> MaintainRuleColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsGy_EquipFileBillSub_MaintainRule>>(msg3);
                List<ClsGy_EquipFileBillSub_DotCheckRule> DotCheckRuleColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsGy_EquipFileBillSub_DotCheckRule>>(msg4);
                if (OperationType == 2)
                {
                    //删除子表
                    oCN.RunProc("delete from Gy_EquipFileBillSub_MaintainRule where HInterID = " + HInterID );
                    oCN.RunProc("delete from Gy_EquipFileBillSub_DotCheckRule where HInterID = " + HInterID );
                }
                int i = 0;
                //保存保养规格
                foreach (ClsGy_EquipFileBillSub_MaintainRule oSub in MaintainRuleColl)
                {
                    i++;
                    if (oSub.HMaintainRuleID <= 0 || oSub.HMaintainRuleID == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + i + "行,保养规格不能为空";
                        objJsonResult.data = null;
                        throw new Exception("保养规格不能为空");
                }
                    DataSet Cs;
                    Int64 NewHEntryID = 1;
                    Int64 newHFlag = 1;
                    Cs = oCN.RunProcReturn("select MAX(HEntryID)HEntryID from Gy_EquipFileBillSub_MaintainRule", "Gy_EquipFileBillSub_MaintainRule");
                    if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()) != 0)
                    {
                        NewHEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString());
                        NewHEntryID += 1;
                    }
                    if(oSub.HStdFlag == true)
                    {
                        newHFlag = 1;
                    }
                    else
                    {
                        newHFlag = 0;
                    }
                    oCN.RunProc($@"Insert into Gy_EquipFileBillSub_MaintainRule
                (HInterID,HBillNo_bak,HEntryID,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,
                 HMaintainRuleID,HStdFlag
               )
                 values({HInterID},'{HBillNo}',{NewHEntryID},'{oSub.HRemark}',{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HRelationQty},{oSub.HRelationMoney}
                ,{oSub.HMaintainRuleID},{newHFlag})");
                }
                i = 0;
                //保存点检规程
                foreach (ClsGy_EquipFileBillSub_DotCheckRule oSub in DotCheckRuleColl)
                {
                    i++;
                    if (oSub.HDotCheckRuleID <= 0 || oSub.HDotCheckRuleID == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + i + "行,点检规程不能为空";
                        objJsonResult.data = null;
                        throw new Exception("点检规程不能为空");
                    }
                    DataSet Cs;
                    Int64 NewHEntryID = 1;
                    Int64 newHFlag = 1;
                    Cs = oCN.RunProcReturn("select MAX(HEntryID)HEntryID from Gy_EquipFileBillSub_DotCheckRule", "Gy_EquipFileBillSub_DotCheckRule");
                    if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()) != 0)
                    {
                        NewHEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString());
                        NewHEntryID += 1;
                    }
                    if (oSub.HStdFlag == true)
                    {
                        newHFlag = 1;
                    }
                    else
                    {
                        newHFlag = 0;
                    }
                    oCN.RunProc($@"Insert into Gy_EquipFileBillSub_DotCheckRule
                (HInterID,HBillNo_bak,HEntryID,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,
                 HDotCheckRuleID,HStdFlag
               )
                 values({HInterID},'{HBillNo}',{NewHEntryID},'{oSub.HRemark}',{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HRelationQty},{oSub.HRelationMoney}
                ,{oSub.HDotCheckRuleID},{newHFlag})");
                }
                //修改上级为非末级代码
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "保存子表成功!";
                //objJsonResult.data = null;
                return objJsonResult;
        }
        #endregion
        #region[设备履历(点击主表带出从表)]
        [Route("Gy_EquipFileMain/Sb_EquipFileBillResumeDate")]
        [HttpGet]
        public object Sb_EquipFileBillResumeDate(string HInterID)
        {
            DataTable ds, ds1;
            DataTable ds, ds1,ds2;
            long HInterID1 = long.Parse(HInterID);
            List<object> list = new List<object>();
            try
@@ -405,9 +563,11 @@
                string sql1 = string.Format($"exec h_p_Gy_EquipRecord {HInterID1}");
                ds = oCN.RunProcReturn(sql1, "h_p_Gy_EquipRecord").Tables[0];
                ds1 = oCN.RunProcReturn(sql1, "h_p_Gy_EquipRecord").Tables[1];
                ds2 = oCN.RunProcReturn(sql1, "h_p_Gy_EquipRecord").Tables[2];
                list.Add(ds);//日常记录
                list.Add(ds1);//维修记录
                list.Add(ds2);//配件更换清单
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "获取信息成功!";
@@ -496,5 +656,493 @@
            return objJsonResult;
        }
        #endregion
        #region 设备档案审核/反审核功能
        [Route("Gy_EquipFileBill/CheckGy_EquipFileBill")]
        [HttpGet]
        public object CheckGy_EquipFileBill(string HInterID, int Type, string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Gy_EquipFileBill_Check", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限审核!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                oCN.BeginTran();//开始事务
                //Type 1 审核  2  反审核
                if (Type == 1)
                {
                    if (!BillOld.CheckBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    if (BillOld.AbandonCheck(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 设备档案关闭/反关闭功能
        [Route("Gy_EquipFileBill/CloseGy_EquipFileBill")]
        [HttpGet]
        public object CloseGy_EquipFileBill(string HInterID, int Type, string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Gy_EquipFileBill_Close", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限关闭!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                oCN.BeginTran();//开始事务
                //Type 1 关闭  2  反关闭
                if (Type == 1)
                {
                    if (!BillOld.CloseBill(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    if (!BillOld.CancelClose(int.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 设备档案列表 树状图 设备分类查询
        public class TreeModel
        {
            public string id { get; set; }
            public string title { get; set; }
            public List<TreeModel> children = new List<TreeModel>();
        }
        [Route("Gy_EquipFileMain/TreeGetList")]
        [HttpGet]
        public object TreeGetList(string sWhere, string user)
        {
            try
            {
                ds = oCN.RunProcReturn("select HItemID,HNumber,HName  from Gy_EquipFileType", "Gy_EquipFileType");
                List<TreeModel> treeModels = new List<TreeModel>();
                TreeModel first = new TreeModel();
                first.id = "0";
                first.title = "设备分类设置";
                treeModels.Add(first);
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    var strLen = row["hitemid"].ToString().Split('.');
                    if (strLen.Length == 1)
                    {
                        TreeModel tree = new TreeModel();
                        tree.id = row["HItemID"].ToString();
                        tree.title = row["HName"].ToString();
                        treeModels[0].children.Add(tree);
                    }
                }
                digui(ds.Tables[0], treeModels[0].children, 2);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = Newtonsoft.Json.JsonConvert.SerializeObject(treeModels);
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        /// <summary>
        /// 递归函数
        /// </summary>
        public void digui(DataTable dt, List<TreeModel> tree, int num)
        {
            for (int m = 0; m < tree.Count; m++)
            {
                tree[m].children = new List<TreeModel>();
                for (int i = 0; i < dt.Rows.Count; i++)//第一次循环,得到所有根节点的子集
                {
                    var strLen = dt.Rows[i]["HNumber"].ToString().Split('.');
                    if (strLen.Length == num && dt.Rows[i]["HNumber"].ToString().Contains(tree[m].id + "."))
                    {
                        TreeModel tbjson = new TreeModel();
                        tbjson.id = dt.Rows[i]["HItemID"].ToString();
                        tbjson.title = dt.Rows[i]["HName"].ToString();
                        tree[m].children.Add(tbjson);
                    }
                }
                var strLens = tree[m].id.Split('.');
                for (int i = 0; i < tree[m].children.Count; i++)
                {
                    digui(dt, tree[m].children, strLens.Length + 2);//再次用子集去循环,拿出子集的子集
                }
            }
        }
        #endregion
        #region 设备运行状态报表
        [Route("SB_EquipRunningStatus/Report")]
        [HttpGet]
        public object Report(string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //if (!DBUtility.ClsPub.Security_Log("Gy_EquipFileList", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "没有查看权限";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Sb_EquipRunningStatusReport " + sWhere + " order by 所属日期 desc", "h_v_Sb_EquipRunningStatusReport");
                }
                else
                {
                    string sql1 = "select * from h_v_Sb_EquipRunningStatusReport where 1 = 1 ";
                    string sql = sql1 + sWhere + " order by 所属日期 desc";
                    ds = oCN.RunProcReturn(sql, "h_v_Sb_EquipRunningStatusReport");
                }
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
                //if (ds.Tables[0].Rows.Count != 0 && ds != null)
                //{
                //}
                //else
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无数据";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 设备运行状态报表 树状图 部门分类查询
        public class TreeModel_Report
        {
            public string id { get; set; }
            public string title { get; set; }
            public string type { get; set; }
            public List<TreeModel_Report> children = new List<TreeModel_Report>();
        }
        [Route("SB_EquipRunningStatus/ReportTreeGetList")]
        [HttpGet]
        public object ReportTreeGetList(string sWhere, string user)
        {
            try
            {
                ds = oCN.RunProcReturn("select HItemID,HNumber,HName  from Gy_Department", "Gy_Department");
                List<TreeModel_Report> treeModels = new List<TreeModel_Report>();
                TreeModel_Report first = new TreeModel_Report();
                DataSet Ds;
                string HCampanyName = "";
                Ds = oCN.RunProcReturn("select HValue from Xt_SystemParameter where HCaption = '客户名称'", "Xt_SystemParameter");
                if (Ds.Tables[0].Rows.Count != 0 && Ds != null)
                {
                    HCampanyName = Ds.Tables[0].Rows[0]["HValue"].ToString();
                }
                first.id = "0";
                first.title = HCampanyName;
                treeModels.Add(first);
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    var strLen = row["hitemid"].ToString().Split('.');
                    if (strLen.Length == 1)
                    {
                        TreeModel_Report tree = new TreeModel_Report();
                        tree.id = row["HItemID"].ToString();
                        tree.title = row["HName"].ToString();
                        tree.type = "Department";
                        treeModels[0].children.Add(tree);
                    }
                }
                getWorkCenter_Level2(ds.Tables[0], treeModels[0].children);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = Newtonsoft.Json.JsonConvert.SerializeObject(treeModels);
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        /// <summary>
        /// 第二级工作中心
        /// </summary>
        public void getWorkCenter_Level2(DataTable dt, List<TreeModel_Report> tree)
        {
            for (int i = 0;i < dt.Rows.Count;i++)
            {
                var HDeptID = dt.Rows[i]["HItemID"].ToString();
                ds = oCN.RunProcReturn("select distinct HItemID,HNumber,HName from Gy_WorkCenter where HDeptID = " + HDeptID, "Gy_WorkCenter");
                if (ds.Tables[0].Rows.Count != 0 && ds != null)
                {
                    for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                    {
                        TreeModel_Report tbjson = new TreeModel_Report();
                        tbjson.id = ds.Tables[0].Rows[j]["HItemID"].ToString();
                        tbjson.title = ds.Tables[0].Rows[j]["HName"].ToString();
                        tbjson.type = "WorkCenter";
                        tree[i].children.Add(tbjson);
                    }
                }
                //digui_Report(ds.Tables[0], tree[i].children, 2);
            }
        }
        /// <summary>
        /// 递归函数
        /// </summary>
        public void digui_Report(DataTable dt, List<TreeModel_Report> tree, int num)
        {
            for (int m = 0; m < tree.Count; m++)
            {
                tree[m].children = new List<TreeModel_Report>();
                for (int i = 0; i < dt.Rows.Count; i++)//第一次循环,得到所有根节点的子集
                {
                    var HWorkCenterNumber = dt.Rows[i]["HNumber"].ToString();
                    DataSet Ds;
                    Ds = oCN.RunProcReturn("select distinct HItemID,HNumber,HName from Gy_WorkCenter where HNumber like '" + HWorkCenterNumber + "%'", "Gy_WorkCenter");
                    if (Ds.Tables[0].Rows.Count != 0 && Ds != null)
                    {
                        for (int j = 0;j < Ds.Tables[0].Rows.Count;j++)
                        {
                            var strLen = Ds.Tables[0].Rows[j]["HNumber"].ToString().Split('.');
                            if (strLen.Length == num && Ds.Tables[0].Rows[j]["HNumber"].ToString().Contains(tree[m].id + "."))
                            {
                                TreeModel_Report tbjson = new TreeModel_Report();
                                tbjson.id = Ds.Tables[0].Rows[j]["HItemID"].ToString();
                                tbjson.title = Ds.Tables[0].Rows[j]["HName"].ToString();
                                tbjson.type = "WorkCenter";
                                tree[m].children.Add(tbjson);
                            }
                        }
                    }
                }
                var strLens = tree[m].id.Split('.');
                for (int i = 0; i < tree[m].children.Count; i++)
                {
                    digui_Report(dt, tree[m].children, strLens.Length + 2);//再次用子集去循环,拿出子集的子集
                }
            }
        }
        #endregion
        #region 设备PDA模块 扫码
        [Route("Gy_EquipFileBill/txtHBarCode_KeyDown")]
        [HttpGet]
        public object txtHBarCode_KeyDown(string HBarCode, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                if (HBarCode == null || HBarCode.Equals(""))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "条码信息为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    string sql = "select * from h_v_Gy_EquipFileBill_KeyDown_PDA where 条形码 = '" + HBarCode + "'";
                    ds = oCN.RunProcReturn(sql, "h_v_Gy_EquipFileBill_KeyDown_PDA");
                }
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //添加列名
                    foreach (DataColumn col in ds.Tables[0].Columns)
                    {
                        Type dataType = col.DataType;
                        string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                        columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    objJsonResult.list = columnNameList;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "设备条码:" + HBarCode + " ,没有创建此设备档案";
                    objJsonResult.data = ds.Tables[0];
                    objJsonResult.list = columnNameList;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}