using System; using System.Collections.Generic; using System.Text; using System.Data; using SQLHelper; namespace DBUtility { public class ClsXt_CheckFlowMain { public Int64 HInterID; public string HName; public string HBillTypeID; public Int64 HDeptID; public bool HStandard; public string HRemark; private string mvarItemKey; public List DetailColl = new List(); ClsCN oCn = new ClsCN(); public ClsXt_CheckFlowMain() { mvarItemKey = "8803"; mvarReportTitle = "审批流单"; } #region 固定代码 public string MvarItemKey { get { return mvarItemKey; } set { mvarItemKey = value; } } private string mvarReportTitle; public string MvarReportTitle { get { return mvarReportTitle; } set { mvarReportTitle = value; } } ~ClsXt_CheckFlowMain() { DetailColl = null; } //删除子表 public void DeleteBillSub(Int64 lngBillKey) { oCn.RunProc("Delete From Xt_CheckFlowSub where HInterID=" + lngBillKey.ToString()); } //删除主表 public void DeleteBillMain(Int64 lngBillKey) { oCn.RunProc("Delete From Xt_CheckFlowMain where HInterID=" + lngBillKey.ToString()); } //删除单据 public bool DeleteBill(Int64 lngBillKey, ref string sReturn) { try { oCn.BeginTran(); //删除关联 DeleteRelation(ref sReturn, lngBillKey); //删除明细表 DeleteBillSub(lngBillKey); //删除主表 DeleteBillMain(lngBillKey); sReturn = "删除单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); return false; } } //是否被关联 public bool isUse(Int64 lngBillKey, ref string sReturn) { try { //查询主表 DataSet Ds ; Ds = oCn.RunProcReturn("Select HinterID from Xt_CheckFlowSub Where HInterID=" + lngBillKey.ToString() + " and isnull(HRelationQty,0)<>0 ", "Xt_CheckFlowMain"); if (Ds.Tables[0].Rows.Count != 0) { sReturn = "单据已被关联,不能操作!"; return true; } sReturn = ""; return false; } catch (Exception e) { sReturn = e.Message; return false; } } //读取下张单据 //读取首张单据 public bool GetFirstBill(ref string sReturn) { try { //查询主表 Int64 lMainID = 0; DataSet Ds ; Ds = oCn.RunProcReturn("Select Top 1 HinterID from Xt_CheckFlowMain Where HBillType='" + this.MvarItemKey + "' Order By HInterID ", "Xt_CheckFlowMain"); if (Ds.Tables[0].Rows.Count != 0) { lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()); if (lMainID != 0) { if (ShowBill(lMainID, ref sReturn)) { sReturn = "查询首张单据成功"; return true; } } } sReturn = "查询首张单据失败"; return false; } catch (Exception e) { sReturn = e.Message; return false; } } //读取末张单据 public bool GetLastBill(ref string sReturn) { try { //查询主表 Int64 lMainID = 0; DataSet Ds ; Ds = oCn.RunProcReturn("Select Top 1 HinterID from Xt_CheckFlowMain Where HBillType='" + this.MvarItemKey + "' Order By HInterID Desc", "Xt_CheckFlowMain"); if (Ds.Tables[0].Rows.Count != 0) { lMainID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()); if (lMainID != 0) { if (ShowBill(lMainID, ref sReturn)) { sReturn = "查询末张单据成功"; return true; } } } sReturn = "查询末张单据失败"; return false; } catch (Exception e) { sReturn = e.Message; return false; } } //单据号是否重复 public bool IsExistBillNo(ref string sReturn, string sBillNo, Pub_Class.ClsPub.Enum_BillStatus oBillStatus, Int64 lngBillKey) { try { string sSql = ""; if (oBillStatus == Pub_Class.ClsPub.Enum_BillStatus.BillStatus_AddNew) { sSql = "Select HInterID from Xt_CheckFlowMain where hbilltype='" + MvarItemKey + "'and HBillNO ='" + sBillNo + "'"; } else { sSql = "Select HInterID from Xt_CheckFlowMain where hbilltype='" + MvarItemKey + "'and HBillNO ='" + sBillNo + "' and HInterID<>" + lngBillKey.ToString(); } DataSet Ds ; Ds = oCn.RunProcReturn(sSql, "Xt_CheckFlowMain"); if (Ds.Tables[0].Rows.Count != 0) { sReturn = "单号重复"; return true; } sReturn = "单号未重复"; return false; } catch (Exception e) { sReturn = e.Message; return false; } } #endregion //修改单据 public bool ModifyBill(Int64 lngBillKey, ref string sReturn) { try { // oCn.BeginTran(); //更新主表 oCn.RunProc("UpDate Xt_CheckFlowMain set " + "HRemark='" + this.HRemark + "'" + ",HName='" + this.HName + "'" + ",HDeptID=" + this.HDeptID.ToString() + ",HBillTypeID='" + this.HBillTypeID + "'" + ",HStandard='" +ClsPub.BoolToString(this.HStandard) + "'" + " where HInterID=" + lngBillKey.ToString()); //删除关联 DeleteRelation(ref sReturn, lngBillKey); //删除子表 DeleteBillSub(lngBillKey); //插入子表 foreach(ClsXt_CheckFlowSub oSub in DetailColl) { oCn.RunProc("Insert into Xt_CheckFlowSub " + " (HInterID,HEntryID,HCheckMan" + ",HFlowNo,HJumpFlag,HMakerSelf,HCheckItemID" + " )values(" + lngBillKey.ToString() + "," + oSub.HEntryID.ToString() +",'"+oSub.HCheckMan+"'"+ "," + oSub.HFlowNo + "," + Convert.ToString(oSub.HJumpFlag ? 1 : 0) + "," + Convert.ToString(oSub.HMakerSelf ? 1 : 0) + "," + oSub.HCheckItemID + "" + ") "); } sReturn = "修改单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); return false; } } //新增单据 public bool AddBill( ref string sReturn) { try { //得到mainid this.HInterID = ClsPub.CreateBillID(MvarItemKey, ref ClsPub.sExeReturnInfo); //若MAINDI重复则重新获取 oCn.BeginTran(); //主表 oCn.RunProc("Insert Into Xt_CheckFlowMain " + "(HBillTypeID,HInterID,HDeptID" + ",HRemark,HStandard,HName" + ") " + " values('" + this.HBillTypeID.ToString() + "'," + this.HInterID.ToString() + "," + this.HDeptID.ToString() + ",'" + this.HRemark + "'," + Convert.ToString(this.HStandard ? 1 : 0) + ",'" + this.HName.ToString() + "') "); //插入子表 foreach (ClsXt_CheckFlowSub oSub in DetailColl) { oCn.RunProc("Insert into Xt_CheckFlowSub " + " (HInterID,HEntryID,HCheckMan" + ",HFlowNo,HJumpFlag,HMakerSelf,HCheckItemID" + " )values(" + this.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCheckMan + "'" + "," + oSub.HFlowNo + "," + Convert.ToString(oSub.HJumpFlag ? 1 : 0) + "," + Convert.ToString(oSub.HMakerSelf ? 1 : 0) + "," + oSub.HCheckItemID + "" + ") "); } sReturn = "新增单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); return false; } } //显示单据 public bool ShowBill(Int64 lngBillKey, ref string sReturn) { try { //查询主表 DataSet Ds ; Ds = oCn.RunProcReturn("Select * from Xt_CheckFlowMain Where HInterID=" + lngBillKey.ToString(), "Xt_CheckFlowMain"); if(Ds.Tables[0].Rows.Count==0) { sReturn = "单据未找到!"; return false; } //赋值 this.HInterID =ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()); this.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim(); this.HBillTypeID =ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillTypeID"].ToString().Trim()); this.HStandard = ClsPub.isBool(Ds.Tables[0].Rows[0]["HStandard"]); this.HRemark = Ds.Tables[0].Rows[0]["HRemark"].ToString().Trim(); this.HDeptID = ClsPub.isLong(Ds.Tables[0].Rows[0]["HDeptID"].ToString()); // //循环 DataSet DsSub ; DsSub = oCn.RunProcReturn("Select * from Xt_CheckFlowSub Where HInterID=" + lngBillKey.ToString(), "Xt_CheckFlowMain"); DetailColl.Clear();//清空 for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) { ClsXt_CheckFlowSub oSub = new ClsXt_CheckFlowSub(); oSub.HInterID =ClsPub.isLong( DsSub.Tables[0].Rows[i]["HInterID"].ToString()); oSub.HEntryID = ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"].ToString()); oSub.HFlowNo = ClsPub.isInt(DsSub.Tables[0].Rows[i]["HFlowNo"].ToString()); oSub.HCheckItemID = ClsPub.isLong(DsSub.Tables[0].Rows[i]["HCheckItemID"].ToString()); oSub.HJumpFlag = ClsPub.isBool(DsSub.Tables[0].Rows[i]["HJumpFlag"].ToString()); oSub.HMakerSelf = ClsPub.isBool(DsSub.Tables[0].Rows[i]["HMakerSelf"].ToString()); oSub.HCheckMan = DsSub.Tables[0].Rows[i]["HCheckMan"].ToString(); DetailColl.Add(oSub); } sReturn = "显示单据成功!"; return true; } catch (Exception e) { sReturn = e.Message; return false; } } //MAINID是否重复 public bool IsExistMainID(ref string sReturn, Int64 lngBillKey) { sReturn = ""; return false; } //删除关联 public void DeleteRelation(ref string sReturn, Int64 lngBillKey) { sReturn = ""; return; } } }