using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using Pub_Class;
using System;
using System.Data;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Web.Http;
using System.Windows.Forms;
using WebAPI.Models;
//using Excel = Microsoft.Office.Interop.Excel;
namespace WebAPI.Controllers.基础资料.基础资料
{
public class Gy_SOPBillListController : ApiController
{
public DBUtility.ClsPub.Enum_BillStatus BillStatus;
private json objJsonResult = new json();
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
DataSet ds;
DAL.ClsGy_SOPBill oBill = new DAL.ClsGy_SOPBill();
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
public DataGridView grdMain = new System.Windows.Forms.DataGridView();
#region 作业指导书列表
[Route("Gy_SOPBill/list")]
[HttpGet]
public object getSOPBillList(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;
//}
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)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "Exception!" + e.ToString();
objJsonResult.data = null;
return objJsonResult;
}
}
#endregion
///
/// 作业指导书删除
///
///
[Route("Gy_SOPBill/Del")]
[HttpGet]
public object Del(string hmainid, string hsubid, string user)
{
DataSet ds;
try
{
//删除权限
if (!DBUtility.ClsPub.Security_Log("Gy_SOPBill_Drop", 1, false, user))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "无删除权限!";
objJsonResult.data = null;
return objJsonResult;
}
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
if (string.IsNullOrWhiteSpace(hmainid))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "资料内码为空!";
objJsonResult.data = null;
return objJsonResult;
}
oCN.BeginTran();//开始事务
ds = oCN.RunProcReturn("select * from Gy_SOPBillSub where HInterID=" + hmainid + " and HEntryID=" + hsubid, "Gy_SOPBillSub");
if (ds == null || ds.Tables[0].Rows.Count == 0)
{
oCN.RollBack();
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "没有数据,无法删除!";
objJsonResult.data = null;
return objJsonResult; ;
}
oCN.RunProc("delete Gy_SOPBillSub where HInterID=" + hmainid + " and HEntryID=" + hsubid);
oCN.RunProc("delete Gy_SOPBillSub2 where HInterID=" + hmainid + " and HEntryID=" + hsubid);
oCN.Commit();//提交事务
objJsonResult.code = "0";
objJsonResult.count = 1;
objJsonResult.Message = "作业指导书删除成功!";
objJsonResult.data = null;
return objJsonResult; ;
}
catch (Exception e)
{
oCN.RollBack();
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "删除失败!" + e.ToString();
objJsonResult.data = null;
return objJsonResult;
}
}
#region 引出
[Route("Gy_SOPBill/SetExcel")]
[HttpGet]
public HttpResponseMessage Sc_StationInBillSetExcel(string 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++)
{
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());
}
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")
{
FileName = System.Web.HttpUtility.UrlEncode(fileName)
};
return response;
}
#endregion
//
private Int32 Fun_GetCol(string sCol)
{
return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
}
#region 使用
[Route("Gy_SOPBill/BatchUse")]
[HttpGet]
public object sy_Click()
{
long sOldInterID = 0;
for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
{
long HInterID = DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("HMainID")].Value);
if (HInterID == 0 || HInterID == sOldInterID)
{
continue;
}
else
{
sOldInterID = HInterID;
}
if (!oBill.Sub_RoutingCheckAndUsed(HInterID))
{
continue;
}
}
objJsonResult.count = 1;
objJsonResult.Message = "批量使用完毕!";
return objJsonResult;
}
#endregion
#region 打印查询数据
[Route("Gy_SOPBillList/WindowPrintList")]
[HttpGet]
public object WindowPrintList(string sWhere)
{
try
{
ds = oCN.RunProcReturn(sWhere, "WindowPrint");
//客户制定
string sErr = "";
if (oSystemParameter.ShowBill(ref sErr))
{
if (oSystemParameter.omodel.WMS_CampanyName == "乔一")
{
if (ds.Tables[0].Columns.Count > 8) {
LogService.CustomWriteLog("单据号:"+ ds.Tables[0].Rows[0][7].ToString(),"CS"+ DateTime.Now.ToString("yyyyMMdd"));
}
}
}
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;
}
}
///
/// 对数据库进行操作
///
///
///
[Route("Gy_SOPBillList/UpDelSQL")]
[HttpGet]
public object UpDelSQL(string sWhere)
{
try
{
oCN.BeginTran();
oCN.RunProc(sWhere);
oCN.Commit();
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = "Sucess!";
objJsonResult.data = null;
return objJsonResult;
}
catch (Exception e)
{
oCN.RollBack();
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "Exception!" + e.ToString();
objJsonResult.data = null;
return objJsonResult;
}
}
#endregion
}
}