using System; 
 | 
using System.Collections.Generic; 
 | 
using System.Text; 
 | 
using System.Data; 
 | 
  
 | 
namespace Pub_Control 
 | 
{ 
 | 
    public  class Clsxt_ICSchemeMain 
 | 
    { 
 | 
        public Int64  HInterID; 
 | 
        public string HName; 
 | 
        public string HUserCode; 
 | 
        public string HBillName; 
 | 
        public string HBillType; 
 | 
        public bool HStopflag; 
 | 
        public Int16 HRowHeight;//内容行高 
 | 
        public Int16 HFixRowHeight;//标题行高 
 | 
        public Int16 HFontSize;//字体大小 
 | 
        private string mvarItemKey; 
 | 
        public  List<Clsxt_ICSchemeSub> DetailColl = new List<Clsxt_ICSchemeSub>(); 
 | 
        public List<Clsxt_ICSchemeMain> MainColl; 
 | 
        Pub_Class.ClsSqlHelper oCn = new Pub_Class.ClsSqlHelper(); 
 | 
  
 | 
        public Clsxt_ICSchemeMain() 
 | 
        { 
 | 
            mvarItemKey = "0001"; 
 | 
            mvarReportTitle = "过滤方案"; 
 | 
        } 
 | 
  
 | 
        #region 固定代码 
 | 
        public string MvarItemKey 
 | 
        { 
 | 
            get { return mvarItemKey; } 
 | 
            set { mvarItemKey = value; } 
 | 
        } 
 | 
        private string mvarReportTitle; 
 | 
  
 | 
        public string MvarReportTitle 
 | 
        { 
 | 
            get { return mvarReportTitle; } 
 | 
            set { mvarReportTitle = value; } 
 | 
        } 
 | 
  
 | 
        ~Clsxt_ICSchemeMain() 
 | 
        { 
 | 
            DetailColl = null; 
 | 
        } 
 | 
        
 | 
        //删除子表 
 | 
        public void DeleteBillSub(Int64 lngBillKey) 
 | 
        { 
 | 
            oCn.RunProc("Delete From xt_ICSchemeSub where HInterID=" + lngBillKey.ToString()); 
 | 
        } 
 | 
        //删除主表 
 | 
        public void DeleteBillMain(Int64 lngBillKey) 
 | 
        { 
 | 
            oCn.RunProc("Delete From xt_ICSchemeMain 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 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_ICSchemeMain where hbilltype='" + MvarItemKey + "'and HName ='" + sBillNo + "'"; 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    sSql = "Select HInterID from xt_ICSchemeMain where hbilltype='" + MvarItemKey + "'and HName ='" + sBillNo + "' and HInterID<>" + lngBillKey.ToString(); 
 | 
                } 
 | 
                DataSet Ds ; 
 | 
                Ds = oCn.RunProcReturn(sSql, "xt_ICSchemeMain"); 
 | 
                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(); 
 | 
                //更新主表 
 | 
                //主表 
 | 
                DeleteBillMain(lngBillKey); 
 | 
                oCn.RunProc("Insert Into xt_ICSchemeMain   " + 
 | 
                "(HBillType,HInterID,HName,HUserCode" + 
 | 
                ",HBillName,HStopflag" + 
 | 
                ") " + 
 | 
                " values('" + this.MvarItemKey + "'," + lngBillKey.ToString() + ",'" + this.HName + "','" + this.HUserCode + "'" + 
 | 
                ",'" + this.HBillName.ToString() + "',0" + 
 | 
                ") "); 
 | 
                //删除关联 
 | 
                DeleteRelation(ref sReturn, lngBillKey); 
 | 
                //删除子表 
 | 
                DeleteBillSub(lngBillKey); 
 | 
                //插入子表 
 | 
                foreach(Clsxt_ICSchemeSub oSub in DetailColl) 
 | 
                { 
 | 
                    oCn.RunProc("Insert into xt_ICSchemeSub " + 
 | 
                        " (HInterID,HKey,HValue)" + 
 | 
                        " values(" 
 | 
                        + this.HInterID.ToString() + ",'" + oSub.HKey.ToString() + "','" + oSub.HValue.ToString() + "') "); 
 | 
                } 
 | 
                sReturn = "修改单据成功!"; 
 | 
                oCn.Commit(); 
 | 
                return true; 
 | 
            } 
 | 
            catch (Exception e) 
 | 
            { 
 | 
                sReturn = e.Message; 
 | 
                oCn.RollBack(); 
 | 
                return false; 
 | 
            } 
 | 
        } 
 | 
        //新增单据 
 | 
        public bool AddBill( ref string sReturn,Int64 sInterID) 
 | 
        { 
 | 
            try 
 | 
            { 
 | 
                //得到mainid 
 | 
                this.HInterID = Pub_Class.ClsPub.CreateBillID(MvarItemKey, ref Pub_Class.ClsPub.sExeReturnInfo); 
 | 
                sInterID = HInterID; 
 | 
                //若MAINDI重复则重新获取 
 | 
                oCn.BeginTran(); 
 | 
                //主表 
 | 
                oCn.RunProc("Insert Into xt_ICSchemeMain   " + 
 | 
                "(HBillType,HInterID,HName,HUserCode" + 
 | 
                ",HBillName,HStopflag" + 
 | 
                ") " + 
 | 
                " values('" + this.MvarItemKey + "'," + this.HInterID.ToString() + ",'" + this.HName + "','" + this.HUserCode + "'" + 
 | 
                ",'" + this.HBillName.ToString() + "',0" +  
 | 
                ") "); 
 | 
                //插入子表 
 | 
                foreach (Clsxt_ICSchemeSub oSub in DetailColl) 
 | 
                { 
 | 
                    oCn.RunProc("Insert into xt_ICSchemeSub " + 
 | 
                        " (HInterID,HKey,HValue)" + 
 | 
                        " values(" 
 | 
                        + this.HInterID.ToString() + ",'" + oSub.HKey.ToString() + "','" + oSub.HValue.ToString() + "') "); 
 | 
                } 
 | 
                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_ICSchemeMain Where HInterID=" + lngBillKey.ToString(), "xt_ICSchemeMain"); 
 | 
                if(Ds.Tables[0].Rows.Count==0) 
 | 
                { 
 | 
                    sReturn = "单据未找到!"; 
 | 
                    return false; 
 | 
                } 
 | 
                //赋值 
 | 
                this.HInterID = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()); 
 | 
                this.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim(); 
 | 
                this.HUserCode = Ds.Tables[0].Rows[0]["HUserCode"].ToString().Trim(); 
 | 
                this.HBillType = Ds.Tables[0].Rows[0]["HBillType"].ToString().Trim(); 
 | 
                this.HBillName = Ds.Tables[0].Rows[0]["HBillName"].ToString().Trim(); 
 | 
                this.HStopflag = false; 
 | 
                //循环 
 | 
                DataSet DsSub; 
 | 
                DsSub = oCn.RunProcReturn("Select * from xt_ICSchemeSub Where HInterID=" + this.HInterID, "xt_ICSchemeMain"); 
 | 
                DetailColl.Clear();//清空 
 | 
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) 
 | 
                { 
 | 
                    Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub(); 
 | 
                    oSub.HInterID = Pub_Class.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"].ToString()); 
 | 
                    oSub.HEntryID = Pub_Class.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"].ToString()); 
 | 
                    oSub.HKey = DsSub.Tables[0].Rows[i]["HKey"].ToString().Trim(); 
 | 
                    oSub.HValue = DsSub.Tables[0].Rows[i]["HValue"].ToString().Trim(); 
 | 
                    DetailColl.Add(oSub); 
 | 
                } 
 | 
                sReturn = "显示单据成功!"; 
 | 
                return true; 
 | 
            } 
 | 
            catch (Exception e) 
 | 
            { 
 | 
                sReturn = e.Message; 
 | 
                return false; 
 | 
            } 
 | 
        } 
 | 
        //显示默认方案 
 | 
        public bool ShowDefault(string HBillName) 
 | 
        { 
 | 
            try 
 | 
            { 
 | 
                //查询主表 
 | 
                DataSet Ds ; 
 | 
                Ds = oCn.RunProcReturn("Select * from xt_ICSchemeMain Where HName='默认方案' and HBillName='" + HBillName + "'and HUserCode='" + Pub_Class.ClsPub.CurUserName + "'", "xt_ICSchemeMain"); 
 | 
                if (Ds.Tables[0].Rows.Count == 0) 
 | 
                { 
 | 
                     
 | 
                    return false; 
 | 
                } 
 | 
                //赋值 
 | 
                this.HInterID = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()); 
 | 
                this.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim(); 
 | 
                this.HUserCode = Ds.Tables[0].Rows[0]["HUserCode"].ToString().Trim(); 
 | 
                this.HBillType = Ds.Tables[0].Rows[0]["HBillType"].ToString().Trim(); 
 | 
                this.HBillName = Ds.Tables[0].Rows[0]["HBillName"].ToString().Trim(); 
 | 
                this.HStopflag = false; 
 | 
                //循环 
 | 
                DataSet DsSub ; 
 | 
                DsSub = oCn.RunProcReturn("Select * from xt_ICSchemeSub Where HInterID=" + this.HInterID, "xt_ICSchemeMain"); 
 | 
                DetailColl.Clear();//清空 
 | 
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) 
 | 
                { 
 | 
                    Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub(); 
 | 
                    oSub.HInterID = Pub_Class.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"].ToString()); 
 | 
                    oSub.HEntryID = Pub_Class.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"].ToString()); 
 | 
                    oSub.HKey = DsSub.Tables[0].Rows[i]["HKey"].ToString().Trim(); 
 | 
                    oSub.HValue = DsSub.Tables[0].Rows[i]["HValue"].ToString().Trim(); 
 | 
                    DetailColl.Add(oSub); 
 | 
                } 
 | 
                
 | 
                return true; 
 | 
            } 
 | 
            catch (Exception e) 
 | 
            { 
 | 
                
 | 
                return false; 
 | 
            } 
 | 
        } 
 | 
        //MAINID是否重复 
 | 
        public bool IsExistMainID(ref string sReturn, Int64 lngBillKey) 
 | 
        { 
 | 
            sReturn = ""; 
 | 
            return false; 
 | 
        } 
 | 
        //删除关联 
 | 
        public void  DeleteRelation(ref string sReturn, Int64 lngBillKey) 
 | 
        { 
 | 
            sReturn = ""; 
 | 
            return; 
 | 
        } 
 | 
  
 | 
  
 | 
        //获取方案列表 
 | 
        public bool GetBillList(string sViewName,ref string sReturn) 
 | 
        { 
 | 
            try 
 | 
            { 
 | 
                //查询主表 
 | 
                DataSet Ds; 
 | 
                Ds = oCn.RunProcReturn("Select * from xt_ICSchemeMain Where Hname<>'默认方案' and HBillName='" + sViewName + "' and HUserCode='" + Pub_Class.ClsPub.CurUserName + "'", "xt_ICSchemeMain"); 
 | 
                if (Ds.Tables[0].Rows.Count == 0) 
 | 
                { 
 | 
                    sReturn = "单据未找到!"; 
 | 
                    return false; 
 | 
                } 
 | 
                MainColl = new List<Clsxt_ICSchemeMain>(); 
 | 
                MainColl.Clear(); 
 | 
                //赋值 
 | 
                for (int i = 0; i < Ds.Tables[0].Rows.Count; i++) 
 | 
                { 
 | 
                    Clsxt_ICSchemeMain oMain = new Clsxt_ICSchemeMain(); 
 | 
                    oMain.HInterID = Pub_Class.ClsPub.isLong(Ds.Tables[0].Rows[i]["HInterID"].ToString()); 
 | 
                    oMain.HName = Ds.Tables[0].Rows[i]["HName"].ToString().Trim(); 
 | 
                    oMain.HUserCode = Ds.Tables[0].Rows[i]["HUserCode"].ToString().Trim(); 
 | 
                    oMain.HBillType = Ds.Tables[0].Rows[i]["HBillType"].ToString().Trim(); 
 | 
                    oMain.HBillName = Ds.Tables[0].Rows[i]["HBillName"].ToString().Trim(); 
 | 
                    oMain.HStopflag = false; 
 | 
                    MainColl.Add(oMain); 
 | 
                } 
 | 
                sReturn = "显示单据成功!"; 
 | 
                return true; 
 | 
            } 
 | 
            catch (Exception e) 
 | 
            { 
 | 
                sReturn = e.Message; 
 | 
                return false; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
  
 | 
} 
 |