1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public  class ClsGy_CostItemAverageType:DBUtility.ClsXt_BaseBill
    {
        //public Model.ClsGy_CostItemAverageType_Model omodel = new Model.ClsGy_CostItemAverageType_Model();
        public DBUtility.ClsXt_BaseBillMain omodel = new DBUtility.ClsXt_BaseBillMain();
       
        public List<Model.ClsGy_CostItemAverageType_Model> DetailColl = new List<Model.ClsGy_CostItemAverageType_Model>();
 
        public ClsGy_CostItemAverageType()
        {
            base.MvarItemKeySub = "Gy_CostItemAverageType";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey = "Gy_CostItemAverageType";
            base.MvarReportTitle = "成本项目分配标准";
            base.BillType="0"; 
        }
 
        #region 固定代码
 
        ~ClsGy_CostItemAverageType()
        {
            DetailColl = null;
        }
       
        #endregion   自定义方法
        //修改单据
        public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //
                oCn.BeginTran();
                //
                //DeleteRelation(ref sReturn, lngBillKey);
                //删除子表
                //DeleteBillSub(lngBillKey);
                oCn.RunProc("delete from  Gy_CostItemAverageType where Hitemid=" + lngBillKey.ToString());
                //插入子表
                omodel.HInterID = lngBillKey;
                foreach (Model.ClsGy_CostItemAverageType_Model oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Gy_CostItemAverageType " +
                  " (HCostItemID,HAverageTypeID,HWIPFlag,HProcName" +
                  ") values("
                  + oSub.HCostItemID.ToString() + "," + oSub.HAverageTypeID.ToString() + ",'" + oSub.HWIPFlag.ToString() + "','" + oSub.HProcName + "'" +
                  ") ");
                }
                sReturn = "修改成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw (e);
            }
        }
        //新增单据
        public override bool AddBill(ref string sReturn)
        {
            try
            {
                //得到mainid
                //omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
                //若MAINDI重复则重新获取
                oCn.BeginTran();
                //插入子表
                foreach (Model.ClsGy_CostItemAverageType_Model oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Gy_CostItemAverageType " +
                     " (HCostItemID,HAverageTypeID,HWIPFlag,HProcName" +
                     ") values("
                     + oSub.HCostItemID.ToString() + "," + oSub.HAverageTypeID.ToString() + ",'" + oSub.HWIPFlag.ToString() + "','" + oSub.HProcName + "'" +
                     ") ");
                }
 
                sReturn = "新增成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw (e);
            }
        }
        //显示单据
        public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //查询主表
                //循环
                DataSet DsSub ;
                omodel.HInterID = lngBillKey;
                DsSub = oCn.RunProcReturn("Select * from Gy_CostItemAverageType Where HItemID=" + lngBillKey.ToString(), "Gy_CostItemAverageType");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Model.ClsGy_CostItemAverageType_Model oSub = new Model.ClsGy_CostItemAverageType_Model();
 
 
                    oSub.HCostItemID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HCostItemID"]);
                    oSub.HAverageTypeID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HAverageTypeID"]);
                    oSub.HWIPFlag = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HWIPFlag"]);
                    oSub.HProcName = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HProcName"]);
                    //
                    DetailColl.Add(oSub);
                }
                sReturn = "显示成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //delete
        public override bool DeleteBill(long lngBillKey, ref string sReturn)
        {
            try
            {
                //
                oCn.BeginTran();
                //
                //DeleteRelation(ref sReturn, lngBillKey);
                //删除子表
                //DeleteBillSub(lngBillKey);
                oCn.RunProc("delete from  Gy_CostItemAverageType where Hitemid=" + lngBillKey.ToString());
                sReturn = "删除成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw (e);
            }    
        }
 
 
    }
 
}