yusijie
2024-12-17 feec6d0e153a8435ead4383a2a8f988b47003191
WebAPI/Controllers/»ù´¡×ÊÁÏ/»ù´¡×ÊÁÏ/Gy_SOPBillController.cs
@@ -1,17 +1,14 @@
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Data.SqlClient;
using System.Web.Http;
using System.Windows.Forms;
using WebAPI.Models;
//using Excel = Microsoft.Office.Interop.Excel;
using WebAPI.Service;
namespace WebAPI.Controllers.基础资料.基础资料
{
@@ -22,54 +19,28 @@
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        DAL.ClsGy_SOPBill oBill = new DAL.ClsGy_SOPBill();
        public DataGridView grdMain = new System.Windows.Forms.DataGridView();
        #region ä½œä¸šæŒ‡å¯¼ä¹¦åˆ—表
        [Route("Gy_SOPBill/list")]
        /// <summary>
        /// è¿”回生产资源生产状态工单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_ICMOBillStatus_Tmp/list")]
        [HttpGet]
        public object getSOPBillList(string sWhere, string user)
        public object list(string sWhere, string user)
        {
            try
            {
                //查看权限
                //if (!DBUtility.ClsPub.Security_Log("Gy_SOPBillMain", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无查看权限!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                string sql1 = string.Format(@"select * from h_v_Sc_WorkOrderList where å¼€å·¥æ ‡è®° = 1 and HMainID='" + sWhere + "'");
                ds = oCN.RunProcReturn(sql1, "h_v_Sc_WorkOrderList");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Gy_SOPBillList order by hmainid ", "h_v_Gy_SOPBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_Gy_SOPBillList where 1 = 1 ";
                    string sql = sql1 + sWhere + " order by hmainid ";
                    ds = oCN.RunProcReturn(sql, "h_v_Gy_SOPBillList");
                }
                //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)
            {
@@ -80,165 +51,221 @@
                return objJsonResult;
            }
        }
        #endregion
        #region å¼•出
        [Route("Gy_SOPBill/SetExcel")]
        /// <summary>
        /// è¿”回文件清单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_ICMOBillStatus_Tmp/Filelist")]
        [HttpGet]
        public HttpResponseMessage Sc_StationInBillSetExcel(string sWhere)
        public object Filelist(int sWhere)
        {
            HSSFWorkbook workbook = new HSSFWorkbook();
            ISheet sheet = workbook.CreateSheet("sheet1");
            IRow row = sheet.CreateRow(0);
            row.CreateCell(0).SetCellValue("单据号");
            row.CreateCell(1).SetCellValue("单据类型");
            row.CreateCell(2).SetCellValue("工艺名称");
            row.CreateCell(3).SetCellValue("物料代码");
            row.CreateCell(4).SetCellValue("物料名称");
            row.CreateCell(5).SetCellValue("规格型号");
            row.CreateCell(6).SetCellValue("计量单位代码");
            row.CreateCell(7).SetCellValue("计量单位");
            row.CreateCell(8).SetCellValue("默认指导书");
            row.CreateCell(9).SetCellValue("表头备注");
            row.CreateCell(10).SetCellValue("工序号");
            row.CreateCell(11).SetCellValue("工序代码");
            row.CreateCell(12).SetCellValue("工序");
            row.CreateCell(13).SetCellValue("工作中心代码");
            row.CreateCell(14).SetCellValue("工作中心名称");
            row.CreateCell(15).SetCellValue("工位代码");
            row.CreateCell(16).SetCellValue("工位");
            row.CreateCell(17).SetCellValue("表体备注");
            row.CreateCell(18).SetCellValue("使用标记");
            row.CreateCell(19).SetCellValue("启用人");
            row.CreateCell(20).SetCellValue("启用日期");
            row.CreateCell(21).SetCellValue("制单人");
            row.CreateCell(22).SetCellValue("制单日期");
            row.CreateCell(23).SetCellValue("审核人");
            row.CreateCell(24).SetCellValue("审核日期");
            row.CreateCell(25).SetCellValue("修改人");
            row.CreateCell(26).SetCellValue("修改日期");
            row.CreateCell(27).SetCellValue("作废人");
            row.CreateCell(28).SetCellValue("作废日期");
            //精确控制列宽
            sheet.SetColumnWidth(1, 5000);
            sheet.SetColumnWidth(2, 5000);
            sheet.SetColumnWidth(3, 5000);
            sheet.SetColumnWidth(4, 5000);
            sheet.SetColumnWidth(5, 5000);
            sheet.SetColumnWidth(6, 5000);
            sheet.SetColumnWidth(7, 5000);
            sheet.SetColumnWidth(8, 5000);
            sheet.SetColumnWidth(9, 5000);
            sheet.SetColumnWidth(10, 5000);
            sheet.SetColumnWidth(11, 5000);
            sheet.SetColumnWidth(12, 5000);
            sheet.SetColumnWidth(13, 5000);
            sheet.SetColumnWidth(14, 5000);
            sheet.SetColumnWidth(15, 5000);
            sheet.SetColumnWidth(16, 5000);
            sheet.SetColumnWidth(17, 5000);
            sheet.SetColumnWidth(18, 5000);
            sheet.SetColumnWidth(19, 5000);
            sheet.SetColumnWidth(20, 5000);
            sheet.SetColumnWidth(21, 5000);
            sheet.SetColumnWidth(22, 5000);
            sheet.SetColumnWidth(23, 5000);
            sheet.SetColumnWidth(24, 5000);
            sheet.SetColumnWidth(25, 5000);
            sheet.SetColumnWidth(26, 5000);
            sheet.SetColumnWidth(27, 5000);
            sheet.SetColumnWidth(28, 5000);
            sheet.SetColumnWidth(29, 5000);
            DataSet ds = oCN.RunProcReturn("select * from h_v_Gy_SOPBillList" + sWhere + " order by hmainid desc", "h_v_Gy_SOPBillList");
            for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
            try
            {
                IRow row1 = sheet.CreateRow(i + 1);
                row1.CreateCell(0).SetCellValue(ds.Tables[0].Rows[i]["单据号"].ToString());
                row1.CreateCell(1).SetCellValue(ds.Tables[0].Rows[i]["单据类型"].ToString());
                row1.CreateCell(2).SetCellValue(ds.Tables[0].Rows[i]["工艺名称"].ToString());
                row1.CreateCell(3).SetCellValue(ds.Tables[0].Rows[i]["物料代码"].ToString());
                row1.CreateCell(4).SetCellValue(ds.Tables[0].Rows[i]["物料名称"].ToString());
                row1.CreateCell(5).SetCellValue(ds.Tables[0].Rows[i]["规格型号"].ToString());
                row1.CreateCell(6).SetCellValue(ds.Tables[0].Rows[i]["计量单位代码"].ToString());
                row1.CreateCell(7).SetCellValue(ds.Tables[0].Rows[i]["计量单位"].ToString());
                row1.CreateCell(8).SetCellValue(ds.Tables[0].Rows[i]["默认指导书"].ToString());
                row1.CreateCell(9).SetCellValue(ds.Tables[0].Rows[i]["表头备注"].ToString());
                row1.CreateCell(10).SetCellValue(ds.Tables[0].Rows[i]["工序号"].ToString());
                row1.CreateCell(11).SetCellValue(ds.Tables[0].Rows[i]["工序代码"].ToString());
                row1.CreateCell(12).SetCellValue(ds.Tables[0].Rows[i]["工序"].ToString());
                row1.CreateCell(13).SetCellValue(ds.Tables[0].Rows[i]["工作中心代码"].ToString());
                row1.CreateCell(14).SetCellValue(ds.Tables[0].Rows[i]["工作中心名称"].ToString());
                row1.CreateCell(15).SetCellValue(ds.Tables[0].Rows[i]["工位代码"].ToString());
                row1.CreateCell(16).SetCellValue(ds.Tables[0].Rows[i]["工位"].ToString());
                row1.CreateCell(17).SetCellValue(ds.Tables[0].Rows[i]["表体备注"].ToString());
                row1.CreateCell(18).SetCellValue(ds.Tables[0].Rows[i]["使用标记"].ToString());
                row1.CreateCell(19).SetCellValue(ds.Tables[0].Rows[i]["启用人"].ToString());
                row1.CreateCell(20).SetCellValue(ds.Tables[0].Rows[i]["启用日期"].ToString());
                row1.CreateCell(21).SetCellValue(ds.Tables[0].Rows[i]["制单人"].ToString());
                row1.CreateCell(22).SetCellValue(ds.Tables[0].Rows[i]["制单日期"].ToString());
                row1.CreateCell(23).SetCellValue(ds.Tables[0].Rows[i]["审核人"].ToString());
                row1.CreateCell(24).SetCellValue(ds.Tables[0].Rows[i]["审核日期"].ToString());
                row1.CreateCell(25).SetCellValue(ds.Tables[0].Rows[i]["修改人"].ToString());
                row1.CreateCell(26).SetCellValue(ds.Tables[0].Rows[i]["修改日期"].ToString());
                row1.CreateCell(27).SetCellValue(ds.Tables[0].Rows[i]["作废人"].ToString());
                row1.CreateCell(28).SetCellValue(ds.Tables[0].Rows[i]["作废日期"].ToString());
                //编辑权限
                //if (!DBUtility.ClsPub.Security_Log_second("Gy_Material", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无查看权限!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                string sql1 = string.Format(@"select * from h_v_Sc_GetFileList where æ–‡ä»¶ID = " + sWhere);
                ds = oCN.RunProcReturn(sql1, "h_v_Sc_GetFileList");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            workbook.Write(ms);
            ms.Position = 0;
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StreamContent(ms);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            var fileName = "作业指导书列表.xls";
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            catch (Exception e)
            {
                FileName = System.Web.HttpUtility.UrlEncode(fileName)
            };
            return response;
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        //
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
        }
        #region ä½¿ç”¨
        [Route("Gy_SOPBill/BatchUse")]
        /// <summary>
        /// è¿”回当前生产资源生产状态下的工单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_ICMOBill/list2")]
        [HttpGet]
        public object sy_Click()
        public object list2(string HSourceID, string user,string HMainID)
        {
            long sOldInterID = 0;
            for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
            try
            {
                long HInterID = DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("HMainID")].Value);
                if (HInterID == 0 || HInterID == sOldInterID)
                var sWhere = "";
                if (Convert.ToInt32(HMainID) != 0 && HMainID.ToString() != "")
                {
                    continue;
                    sWhere += " and HMainID = " + HMainID;
                }
                string sql1 = string.Format(@"select * from h_v_Sc_ICMOBillList_ToSop where çŠ¶æ€ = '开工' and HSourceID='" + HSourceID + "'" + sWhere);
                ds = oCN.RunProcReturn(sql1, "h_v_Sc_ICMOBillList_ToSop");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        /// <summary>
        /// è¿”回生产工位列表信息
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Gy_SourceWorkStationSet_ToSop/Soplist")]
        [HttpGet]
        public object Soplist(string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                string sql1 = string.Format(@"select * from h_v_Gy_SourceWorkStationSetList where 1 = 1");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn(sql1 + sWhere + " order by HItemID ", "h_v_Gy_SourceWorkStationSetList");
                }
                else
                {
                    sOldInterID = HInterID;
                    string sql = sql1 + sWhere + " order by HItemID ";
                    ds = oCN.RunProcReturn(sql, "h_v_Gy_SourceWorkStationSetList");
                }
                if (!oBill.Sub_RoutingCheckAndUsed(HInterID))
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    continue;
                    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;
            }
            objJsonResult.count = 1;
            objJsonResult.Message = "批量使用完毕!";
            return objJsonResult;
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        /// <summary>
        /// æ ¹æ®ç‰©æ–™ï¼Œå·¥å•查找作业指导书
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Gy_SopBill/getListByMaterID")]
        [HttpGet]
        public object getListByMaterID(Int64 HMaterID, string HSourceNo)
        {
            try
            {
                var sWhere = "";
                if (Convert.ToInt32(HMaterID) != 0 && HMaterID.ToString() != "" && HSourceNo != null && HSourceNo.ToString() != "" )
                {
                    sWhere += " and HMaterID = " + HMaterID + " and HSourceNo = '" + HSourceNo + "'";
                }
                string sql1 = string.Format(@"select * from h_v_Sc_ICMOBillList_ToSop where 1 = 1 " + sWhere);
                ds = oCN.RunProcReturn(sql1, "h_v_Sc_ICMOBillList_ToSop");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        /// <summary>
        /// æ ¹æ®ç‰©æ–™+工序查找作业指导书
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Gy_SopBill/getListByMaterProc")]
        [HttpGet]
        public object getListByMaterProc(Int64 HMaterID, Int64 HProcID,string HType)
        {
            try
            {
                var sWhere = "";
                if (HType != "")
                {
                    if (Convert.ToInt32(HMaterID) != 0 && HMaterID.ToString() != "" && Convert.ToInt32(HProcID) != 0 && HProcID.ToString() != "")
                    {
                        sWhere += " and HMaterID = " + HMaterID + " and HProcID = " + HProcID + " and HProcID2 = " + HProcID + " and æŒ‡å¯¼ä¹¦ç±»åž‹ = '"+ HType + "'";
                    }
                }
                else
                {
                    if (Convert.ToInt32(HMaterID) != 0 && HMaterID.ToString() != "" && Convert.ToInt32(HProcID) != 0 && HProcID.ToString() != "")
                    {
                        sWhere += " and HMaterID = " + HMaterID + " and HProcID = " + HProcID + " and HProcID2 = " + HProcID + " ";
                    }
                }
                //if (Convert.ToInt32(HMaterID) != 0 && HMaterID.ToString() != "" && Convert.ToInt32(HProcID) != 0 && HProcID.ToString() != "")
                //{
                //    sWhere += " and HMaterID = " + HMaterID + " and HProcID = " + HProcID + " and HProcID2 = " + HProcID ;
                //}
                string sql1 = string.Format(@"select * from h_v_Sc_ICMOBillStatus_Tmp_SOP where 1 = 1 " + sWhere);
                ds = oCN.RunProcReturn(sql1, "h_v_Sc_ICMOBillStatus_Tmp_SOP");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
    }
}