zzr99
2022-01-19 dfd0831df7b8245b7af6b6be28efd18b29fab17d
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public class ClsK3_PrjGroup_Extend : DBUtility.ClsXt_BaseBill
    {
        public Model.ClsK3_PrjGroupMain_Extend omodel = new Model.ClsK3_PrjGroupMain_Extend();
        public List<Model.ClsK3_PrjGroupSub_Extend> DetailColl = new List<Model.ClsK3_PrjGroupSub_Extend>();
 
        public ClsK3_PrjGroup_Extend()
        {
            base.MvarItemKeySub = "K3_PrjGroupMain_Extend";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey = "K3_PrjGroupSub_Extend";
            base.MvarReportTitle = "方案组";
            base.BillType = "";
        }
 
        #region 固定代码
 
        ~ClsK3_PrjGroup_Extend()
        {
            DetailColl = null;
        }
 
        #endregion   自定义方法
        //修改单据
        public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //
                oCn.BeginTran();
                //删除主表
                DeleteBillMain(lngBillKey);
                //删除子表
                DeleteBillSub(lngBillKey);
                //主表
                oCn.RunProc("INSERT INTO K3_PrjGroupMain_Extend " +
                           "(HInterID,HName,HRemark)" +
                           " VALUES " +
                           "(" + omodel.HInterID.ToString() + ",'" + omodel.HName + "','" + omodel.HRemark + "') ");
                //删除关联
                DeleteRelation(ref sReturn, lngBillKey);
                //插入子表
                omodel.HInterID = lngBillKey;
                foreach (Model.ClsK3_PrjGroupSub_Extend oSub in DetailColl)
                {
                    oCn.RunProc("INSERT INTO K3_PrjGroupSub_Extend " +
                           "(HInterID,HEntryID,HBQty,HEQty,HPrjID,HPrjName)" +
                           " VALUES " +
                           "(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HBQty.ToString() + "," + oSub.HEQty.ToString() +
                           "," + oSub.HPrjID.ToString() + ",'" + oSub.HPrjName + "')");
                }
                sReturn = "修改单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw (e);
            }
        }
 
        //新增单据
        public override bool AddBill(ref string sReturn)
        {
            try
            {
                //得到mainid
 
                //若MAINDI重复则重新获取
                oCn.BeginTran();
                //主表
                oCn.RunProc("INSERT INTO K3_PrjGroupMain_Extend " +
                           "(HInterID,HName,HRemark)" +
                           " VALUES " +
                           "(" + omodel.HInterID.ToString() + ",'" + omodel.HName + "','" + omodel.HRemark + "') ");
                //插入子表
                foreach (Model.ClsK3_PrjGroupSub_Extend oSub in DetailColl)
                {
                    oCn.RunProc("INSERT INTO K3_PrjGroupSub_Extend " +
                           "(HInterID,HEntryID,HBQty,HEQty,HPrjID,HPrjName)" +
                           " VALUES " +
                           "(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HBQty.ToString() + "," + oSub.HEQty.ToString() +
                           "," + oSub.HPrjID.ToString() + ",'" + oSub.HPrjName + "')");
                }
                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 Ds;
                Ds = oCn.RunProcReturn("Select * from h_v_K3_PrjGroup_ExtendList Where HMainID=" + lngBillKey.ToString(), "h_v_K3_PrjGroup_ExtendList");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
                //固定赋值===========================================
                omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMainID"]);
                omodel.HName = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["方案组"]);
                omodel.HRemark = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["备注"]);
                //
 
                //循环
                DataSet DsSub;
                DsSub = oCn.RunProcReturn("Select * from h_v_K3_PrjGroup_ExtendList Where HMainID=" + lngBillKey.ToString(), "h_v_K3_PrjGroup_ExtendList");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Model.ClsK3_PrjGroupSub_Extend oSub = new Model.ClsK3_PrjGroupSub_Extend();
                    // 固定赋值===============================================
                    oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HMainID"]);
                    oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSubID"]);
                    oSub.HBQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["起始数量"]);
                    oSub.HEQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["截至数量"]);
                    oSub.HPrjID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["方案编号"]);
                    oSub.HPrjName = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["计算方式"]);
                    DetailColl.Add(oSub);
                }
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
 
 
 
    }
}