using DBUtility;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ViewAPI;
using WebAPI.Models;
namespace WebAPI.Controllers.MJGL
{
public class Sc_MouldProdInBillController : ApiController
{
public DBUtility.ClsPub.Enum_BillStatus BillStatus;
public const string ModName = "3801"; //单据类型
public const string ModCaption = "器具采购入库单"; //单据名称
public const string ModRightName = "Sc_MouldProdInBill";
public const string ModRightNameList = ModRightName + "List"; //列表
public const string ModRightNameEdit = ModRightName + "_Edit"; //编辑
public const string ModRightNameCheck = ModRightName + "_Check"; //审核
public const string ModRightNameClose = ModRightName + "_Close"; //关闭
public const string ModRightNameDelete = ModRightName + "_Delete"; //作废
public const string ModRightNameDrop = ModRightName + "_Drop"; //删除
public const string ModRightNameMoney = ModRightName + "_Money"; //金额
public const string ModRightNameQty = ModRightName + "_Qty"; //数量
public DataSet ds = new DataSet();
private json objJsonResult = new json();
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
public DAL.ClsSc_MouldProdInBill oBill = new DAL.ClsSc_MouldProdInBill();
public DLL.ClsSc_MouldProdInBill BillNew0 = new DLL.ClsSc_MouldProdInBill(); //模具报废入库对应单据类
public DLL.ClsSc_MouldProdInBill BillOld0 = new DLL.ClsSc_MouldProdInBill(); //模具报废入库对应单据类
#region 模具采购入库单列表
[Route("Sc_MouldProdInBill/Get_MouldProdInBillList")]
[HttpGet]
public object Get_MouldProdInBillList(string sWhere,string user, string Organization)
{
try
{
Log.LogInfo("成功!"); //记录提交数据
//编辑权限
if (!DBUtility.ClsPub.Security_Log_second("Sc_MouldProdInBillList", 1, false, user))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "无查看权限!";
objJsonResult.data = null;
return objJsonResult;
}
Log.LogInfo("有权限");
ds = Sc_GetMouldProdInHouseBill(sWhere,Organization);
//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 ex)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
objJsonResult.data = null;
return objJsonResult;
}
}
public static DataSet Sc_GetMouldProdInHouseBill(string sWhere, string Organization)
{
LogService.Write(sWhere+";"+ Organization);
string sql1 = string.Format(@"select * from h_v_Sc_MouldProdInHouseBillList where 库存组织='" + Organization + "'");
if (sWhere == null || sWhere.Equals(""))
{
return new SQLHelper.ClsCN().RunProcReturn(sql1+ sWhere + "order by 制单日期 desc", "h_v_Sc_MouldProdInHouseBillList");
}
else
{
string sql = sql1 + sWhere+ "order by 制单日期 desc";
Log.LogInfo(sql);
return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_Sc_MouldProdInHouseBillList");
}
}
#endregion
#region 模具采购入库单列表 查询-分页
///
/// 返回应收单列表
///参数:string sql。
///返回值:object。
///
[Route("Sc_MouldProdInBill/list_byPage")]
[HttpGet]
public object getSc_MouldProdInBill_byPage(string sWhere, string user, string Organization, int page, int size)
{
try
{
Log.LogInfo("成功!"); //记录提交数据
//查看权限
if (!DBUtility.ClsPub.Security_Log("Sc_MouldProdInBillList", 1, false, user))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "无查看权限!";
objJsonResult.data = null;
return objJsonResult;
}
Log.LogInfo("有权限");
LogService.Write(sWhere + ";" + Organization);
string sql = "";
if (sWhere == null || sWhere.Equals(""))
{
sWhere = " and 库存组织='" + Organization + "'";
sWhere = sWhere.Replace("'", "''");
sql = "exec h_p_Sc_MouldProdInHouseBillList_Query " + page + "," + size + ",'" + Organization + "','" + sWhere + "'";
Log.LogInfo(sql);
ds = new SQLHelper.ClsCN().RunProcReturn(sql, "h_p_Sc_MouldProdInHouseBillList_Query");
}
else
{
sWhere += " and 库存组织='" + Organization + "'";
sWhere = sWhere.Replace("'", "''");
sql = "exec h_p_Sc_MouldProdInHouseBillList_Query " + page + "," + size + ",'" + Organization + "','" + sWhere + "'";
Log.LogInfo(sql);
ds = new SQLHelper.ClsCN().RunProcReturn(sql, "h_p_Sc_MouldProdInHouseBillList_Query");
}
objJsonResult.code = "1";
objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
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;
}
}
#endregion
#region [模具采购入库单删除功能]
///
/// 模具采购入库单删除功能
///
///
[Route("Sc_MouldProdInBill/set_DeleteBill")]
[HttpGet]
public object set_DeleteBill(string HInterID,string user)
{
//编辑权限
if (!DBUtility.ClsPub.Security_Log_second("Sc_MouldProdInBill_Delete", 1, false, user))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "无删除权限!";
objJsonResult.data = null;
return objJsonResult;
}
string s = "";
Int64 lngBillKey = 0;
lngBillKey = DBUtility.ClsPub.isLong(HInterID);
if (lngBillKey == 0)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据ID为空!";
objJsonResult.data = null;
return objJsonResult;
}
DLL.ClsSc_MouldProdInBill oBill = new DLL.ClsSc_MouldProdInBill();
if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
{
if (oBill.omodel.HBillStatus > 1)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据当前处于不能删除状态,不能删除!";
objJsonResult.data = null;
return objJsonResult;
}
if (oBill.omodel.HChecker != ""&& oBill.omodel.HChecker !=null)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据已经审核,不能删除!";
objJsonResult.data = null;
return objJsonResult;
}
if (!DBUtility.Xt_BaseBillFun.Fun_AllowDeleteBill(oBill, ref s))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = s + ",不允许删除";
objJsonResult.data = null;
return objJsonResult;
}
//删除前查找当前单据的所有器具ID
//string swhere = "";
//DataSet ds = oCn.RunProcReturn("select HMaterID from Sc_MouldStockBillSub where HinterID=" + HInterID, "Sc_MouldStockBillSub");
//for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
//{
// swhere = swhere + ds.Tables[0].Rows[i]["HMaterID"].ToString() + ",";
//}
//swhere = swhere.Substring(0, swhere.Length - 1);
bool IsDete = oBill.DeleteBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo);
if (IsDete)
{
//删除成功修改器具档案位置
//string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID 0,0,'{swhere}' ");
string sql = string.Format($"exec h_p_Sc_MouldChangeNowWHID ");
oCn.RunProc(sql);
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
objJsonResult.data = null;
return objJsonResult;
}
else
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
objJsonResult.data = null;
return objJsonResult;
}
}
else
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
objJsonResult.data = null;
return objJsonResult;
}
}
#endregion
#region [模具采购入库单审核、反审核]
///
/// 审核
///
/// 单据ID
/// 审核人
///
[Route("Sc_MouldProdInBill/set_CheckBill")]
[HttpGet]
public object set_CheckBill(int HInterID, string CurUserName)
{
string ModRightNameCheck = "Sc_MouldProdInBill_Check";
DBUtility.ClsPub.CurUserName = CurUserName;
DLL.ClsSc_MouldProdInBill oBill = new DLL.ClsSc_MouldProdInBill();
try
{
//审核权限
if (!DBUtility.ClsPub.Security_Log_second(ModRightNameCheck, 1, false, CurUserName))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "审核失败!无权限!";
objJsonResult.data = null;
return objJsonResult;
}
//审核前判断是否允许
string s = "";
if (!DBUtility.Xt_BaseBillFun.Fun_AllowCheckBill(oBill, ref s))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = s + ",不允许审核";
objJsonResult.data = null;
return objJsonResult;
}
if (HInterID <= 0)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "HInterID小于0!";
objJsonResult.data = null;
return objJsonResult;
}
Int64 lngBillKey = 0;
lngBillKey = DBUtility.ClsPub.isLong(HInterID);
//查看是否已审核,关闭,作废
if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
{
if (oBill.omodel.HCloseMan.Trim() != "")
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据已关闭!不能再次审核!";
objJsonResult.data = null;
return objJsonResult;
}
if (oBill.omodel.HDeleteMan.Trim() != "")
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据已作废!不能再次审核!";
objJsonResult.data = null;
return objJsonResult;
}
if (oBill.omodel.HChecker.Trim() != "")
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据已审核!不能再次审核!";
objJsonResult.data = null;
return objJsonResult;
}
}
else
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo;
objJsonResult.data = null;
return objJsonResult;
}
//审核提交
if (oBill.CheckBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo) == true)
{
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = "审核成功";
objJsonResult.data = null;
return objJsonResult;
}
else
{
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = "审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
objJsonResult.data = null;
return objJsonResult;
}
}
catch (Exception e)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "审核失败!" + e.ToString();
objJsonResult.data = null;
return objJsonResult;
}
}
///
/// 反审核
///
/// 单据ID
/// 审核人
///
[Route("Sc_MouldProdInBill/set_AbandonCheck")]
[HttpGet]
public object set_AbandonCheck(int HInterID, string CurUserName)
{
string ModRightNameCheck = "Sc_MouldProdInBill_Check";
DBUtility.ClsPub.CurUserName = CurUserName;
DLL.ClsSc_MouldProdInBill oBill = new DLL.ClsSc_MouldProdInBill();
try
{
//审核权限
if (!DBUtility.ClsPub.Security_Log_second(ModRightNameCheck, 1, false, CurUserName))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "反审核失败!无权限!";
objJsonResult.data = null;
return objJsonResult;
}
//反审核前判断
string s = "";
if (!DBUtility.Xt_BaseBillFun.Fun_AllowCheckBill(oBill, ref s))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = s + ",不允许反审核";
objJsonResult.data = null;
return objJsonResult;
}
if (HInterID <= 0)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "HInterID小于0!";
objJsonResult.data = null;
return objJsonResult;
}
Int64 lngBillKey = 0;
lngBillKey = DBUtility.ClsPub.isLong(HInterID);
//查看是否已审核,关闭,作废
if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
{
if (oBill.omodel.HCloseMan.Trim() != "")
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据已关闭!不能再次反审核!";
objJsonResult.data = null;
return objJsonResult;
}
if (oBill.omodel.HDeleteMan.Trim() != "")
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据已作废!不能再次反审核!";
objJsonResult.data = null;
return objJsonResult;
}
if (oBill.omodel.HChecker.Trim() == "")
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据未审核!不需要反审核!";
objJsonResult.data = null;
return objJsonResult;
}
}
else
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo;
objJsonResult.data = null;
return objJsonResult;
}
//反审核提交AbandonCheck
if (oBill.AbandonCheck(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo) == true)
{
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = "反审核成功";
objJsonResult.data = null;
return objJsonResult;
}
else
{
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = "反审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
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("Sc_MouldProdInBill/Sc_MouldProdInHouseBillListCheckDetai")]
[HttpGet]
public ApiResult Sc_MouldProdInHouseBillListCheckDetai(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_MouldProdInHouseBillList where hmainid= " + HID + " ", "h_v_Sc_MouldProdInHouseBillList");
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_MouldProdInBill/Sc_MouldScrapInProdBillListProjectDetai")]
[HttpGet]
public object Sc_MouldScrapInProdBillListProjectDetai(string sqlWhere)
{
DataSet ds;
DataSet ds1;
List