using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Data;
|
|
namespace DAL
|
{
|
public class ClsSc_ICMOBill_K3 : DBUtility.ClsXt_BaseBill
|
{
|
public Model.ClsSc_ICMOBillMain_K3 omodel = new Model.ClsSc_ICMOBillMain_K3();
|
//public List<Model.ClsSc_ICMOBill_K3Sub> DetailColl = new List<Model.ClsSc_ICMOBill_K3Sub>();
|
|
public ClsSc_ICMOBill_K3()
|
{
|
base.MvarItemKeySub = "";
|
base.MvarItemKeySub2 = "";
|
base.MvarItemKeySub3 = "";
|
base.MvarItemKeySub4 = "";
|
base.MvarItemKey = "ICMO";
|
base.MvarReportTitle = "生产任务单";
|
base.BillType = "85";
|
}
|
|
#region 固定代码
|
|
~ClsSc_ICMOBill_K3()
|
{
|
//DetailColl = null;
|
}
|
|
#endregion 自定义方法
|
|
//单据号是否重复
|
public bool IsExistBillNo(ref string sReturn, string sBillNo, DBUtility.ClsPub.Enum_BillStatus oBillStatus, Int64 lngBillKey)
|
{
|
try
|
{
|
string sSql = "";
|
if (oBillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew)
|
{
|
sSql = "Select FInterID from ICMO where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "'";
|
}
|
else
|
{
|
sSql = "Select FInterID from ICMO where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
|
}
|
DataSet Ds;
|
Ds = oCnK3.RunProcReturn(sSql, "ICMO");
|
if (Ds.Tables[0].Rows.Count != 0)
|
{
|
sReturn = "单号重复";
|
return true;
|
}
|
sReturn = "单号未重复";
|
return false;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
return false;
|
}
|
}
|
|
//删除主表
|
public void DeleteBillMain(Int64 lngBillKey)
|
{
|
oCnK3.RunProc("Delete From ICMO where FInterID=" + lngBillKey.ToString());
|
}
|
//删除单据
|
public bool DeleteBill(Int64 lngBillKey, ref string sReturn)
|
{
|
DataSet Ds = new DataSet();
|
try
|
{
|
oCnK3.BeginTran();
|
//删除关联
|
//DeleteRelation(ref sReturn, lngBillKey);
|
//删除明细表
|
//删除主表
|
DeleteBillMain(lngBillKey);
|
//删除关联
|
|
sReturn = "删除单据成功!";
|
oCnK3.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCnK3.RollBack();
|
return false;
|
}
|
}
|
|
//修改单据
|
public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
|
{
|
try
|
{
|
//得到用户ID
|
DataSet DsBiller;
|
DsBiller = oCnK3.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
|
if (DsBiller.Tables[0].Rows.Count != 0)
|
{
|
omodel.HBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
|
}
|
else
|
{
|
omodel.HBillerID = 16394;
|
}
|
omodel.HBillType = this.BillType;
|
//
|
//得到mainid
|
omodel.HInterID = lngBillKey;
|
|
//若MAINDI重复则重新获取
|
oCnK3.BeginTran();
|
//主表
|
oCnK3.RunProc(K3_BaseFun.Fun_GetAddBillMainSQL_ICMO(omodel, DBUtility.ClsPub.VersionNum));
|
//
|
sReturn = "修改单据成功!";
|
oCnK3.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCnK3.RollBack();
|
throw (e);
|
}
|
}
|
//新增单据
|
public override bool AddBill(ref string sReturn)
|
{
|
try
|
{
|
//得到用户ID
|
DataSet DsBiller;
|
DsBiller = oCnK3.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
|
if (DsBiller.Tables[0].Rows.Count != 0)
|
{
|
omodel.HBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
|
}
|
else
|
{
|
omodel.HBillerID = 16394;
|
}
|
omodel.HBillType = this.BillType;
|
//
|
DataSet Ds;
|
//得到mainid
|
Ds = oCnK3.RunProcReturn("declare @InterID int set @InterID=0 exec GetICMaxNum 'ICMO', @InterID output, 1, 16394 select ltrim(@InterID)", "GetICMaxNum");
|
omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
|
|
//若MAINDI重复则重新获取
|
oCnK3.BeginTran();
|
//主表
|
oCnK3.RunProc(K3_BaseFun.Fun_GetAddBillMainSQL_ICMO(omodel, DBUtility.ClsPub.VersionNum));
|
//
|
sReturn = "新增单据成功!";
|
oCnK3.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCnK3.RollBack();
|
throw (e);
|
}
|
}
|
//显示单据
|
public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
|
{
|
try
|
{
|
//查询主表
|
DataSet Ds;
|
Ds = oCnK3.RunProcReturn("Select * from ICMO Where FInterID=" + lngBillKey.ToString(), "ICMO");
|
if (Ds.Tables[0].Rows.Count == 0)
|
{
|
sReturn = "单据未找到!";
|
return false;
|
}
|
//赋值
|
omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FInterID"]);
|
omodel.HBillNo = Ds.Tables[0].Rows[0]["FBillNo"].ToString().Trim();
|
omodel.HDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FCheckDate"]);
|
//=================
|
omodel.HRemark = Ds.Tables[0].Rows[0]["Fnote"].ToString().Trim();
|
|
omodel.HBatchNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FGMPBatchNo"]);
|
//omodel.HBatchNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FHeadSelfJ0187"]);
|
omodel.HSeOrderBillNo = "";
|
omodel.HSeOrderInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FOrderInterID"]);
|
omodel.HSeOrderEntryID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSourceEntryID"]);
|
//omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HEmpID"]);
|
omodel.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCustID"]);
|
omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FWorkShop"]);
|
//omodel.HCenterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCenterID"]);
|
omodel.HMaterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FItemID"]);
|
omodel.HUnitID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FUnitID"]);
|
omodel.HBomID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FBomInterID"]);
|
//omodel.HMainBomID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FHeadSelfj0194"]);
|
//omodel.HMainBomNumber = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FHeadSelfj0194"]);
|
omodel.HRoutingInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FRoutingID"]);
|
//
|
//omodel.HLevNum = DBUtility.ClsPub.isInt(Ds.Tables[0].Rows[0]["HLevNum"]);
|
//omodel.HReadyQty = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HReadyQty"]);
|
omodel.HPlanQty = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["Fauxqty"]);
|
//omodel.HStockType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FHeadSelfJ0187"]);
|
//
|
omodel.HPlanBeginDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FPlanCommitDate"]);
|
omodel.HPlanEndDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FPlanFinishDate"]);
|
//omodel.HBeginDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"]);
|
//omodel.HEndDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"]);
|
//
|
omodel.HMaker = Ds.Tables[0].Rows[0]["FBillerID"].ToString().Trim();
|
omodel.HMakeDate = Ds.Tables[0].Rows[0]["FCheckDate"].ToString().Trim();
|
|
sReturn = "显示单据成功!";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
/// <summary>
|
/// 生成工序计划单
|
/// </summary>
|
/// <param name="HICMOID"></param>
|
/// <param name="sReturn"></param>
|
/// <returns></returns>
|
public bool ProcessPlanBill_Add(long HICMOID, ref string sReturn)
|
{
|
try
|
{
|
DataSet Ds;
|
//单据ID
|
long HInterID = DBUtility.ClsPub.CreateBillID("3715", ref DBUtility.ClsPub.sExeReturnInfo);
|
string sHBillNo = DBUtility.ClsPub.CreateBillCode("3715", ref DBUtility.ClsPub.sExeReturnInfo, true);
|
//
|
oCn.BeginTran();
|
//增加主表
|
Ds = oCn.RunProcReturn("exec h_p_Sc_ProcessPlanBill_Add " + HICMOID.ToString() + "," + HInterID.ToString() + ",'" + sHBillNo + "','" + DBUtility.ClsPub.CurUserName + "'", "h_p_Sc_ProcessPlanBill_Add");
|
if (Ds == null || Ds.Tables[0].Rows.Count == 0)
|
{
|
oCn.RollBack();
|
return false;
|
}
|
if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]) != 9)
|
{
|
sReturn = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][1]);
|
oCn.RollBack();
|
return false;
|
}
|
//
|
oCn.Commit();
|
//回填关联数量
|
//oCnK3.RunProc("update ICMO set FCardClosed=1 where finterid=" + HICMOID.ToString());
|
//
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 生成工序计划单
|
/// </summary>
|
/// <param name="HICMOID"></param>
|
/// <param name="sReturn"></param>
|
/// <returns></returns>
|
public bool ProcessPlanBill_Add(long HICMOID, long HRoutingID, ref string sReturn)
|
{
|
try
|
{
|
DataSet Ds;
|
//单据ID
|
long HInterID = DBUtility.ClsPub.CreateBillID("3715", ref DBUtility.ClsPub.sExeReturnInfo);
|
string sHBillNo = DBUtility.ClsPub.CreateBillCode("3715", ref DBUtility.ClsPub.sExeReturnInfo, true);
|
//
|
oCn.BeginTran();
|
//增加主表
|
Ds = oCn.RunProcReturn("exec h_p_Sc_ProcessPlanBill_Add2 " + HICMOID.ToString() + "," + HRoutingID.ToString() + "," + HInterID.ToString() + ",'" + sHBillNo + "','" + DBUtility.ClsPub.CurUserName + "'", "h_p_Sc_ProcessPlanBill_Add");
|
if (Ds == null || Ds.Tables[0].Rows.Count == 0)
|
{
|
oCn.RollBack();
|
return false;
|
}
|
if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]) != 9)
|
{
|
sReturn = "工序计划单,单据号:" + sHBillNo + DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][1]);
|
oCn.RollBack();
|
return false;
|
}
|
//
|
oCn.Commit();
|
//回填关联数量
|
//oCnK3.RunProc("update ICMO set FCardClosed=1 where finterid=" + HICMOID.ToString());
|
//
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 得到成本对象
|
/// </summary>
|
/// <param name="HICMOID"></param>
|
/// <param name="sReturn"></param>
|
/// <returns></returns>
|
public long GetCostObjByHMaterID(long HMaterID)
|
{
|
DataSet Ds;
|
//
|
//增加主表
|
Ds = oCnK3.RunProcReturn("select cb.FCostObjID HCostObjID from t_icitem m inner join cb_CostObj_Product cb on m.FItemID=cb.FProductID "+
|
"where FItemID=" + HMaterID.ToString(), "cb_CostObj_Product");
|
if (Ds == null || Ds.Tables[0].Rows.Count == 0)
|
{
|
return 0;
|
}
|
long HCostObjID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
|
return HCostObjID;
|
}
|
|
/// <summary>
|
/// 下达
|
/// </summary>
|
/// <param name="HMaterID"></param>
|
/// <returns></returns>
|
public bool CheckICMOBill(Int64 HInterID, ref string sReturn)
|
{
|
try
|
{
|
oCn.RunProc("exec h_p_Sc_ICMOCheck_K3 " + HInterID.ToString());
|
sReturn = "";
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
throw (e);
|
}
|
}
|
|
/// <summary>
|
/// 修改任务单 测试状态
|
/// </summary>
|
/// <param name="HICMOID"></param>
|
/// <param name="sReturn"></param>
|
/// <returns></returns>
|
public bool UpdateTestStatus(long HICMOID, string sStatus, ref string sReturn)
|
{
|
try
|
{
|
oCn.BeginTran();
|
//增加主表
|
oCn.RunProc("update h_v_K3_ICMOBill set HTestStatus='" + sStatus + "' where HInterID=" + HICMOID.ToString());
|
//
|
sReturn = "修改状态成功!";
|
oCn.Commit();
|
return true;
|
}
|
catch (Exception e)
|
{
|
sReturn = e.Message;
|
oCn.RollBack();
|
return false;
|
}
|
}
|
|
}
|
|
}
|