ch
2021-12-23 fe4782024b58742f763989b457973b95382adf7b
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
157
158
159
160
161
162
163
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public class ClsKf_CheckStockOutBill_K3 : DBUtility.ClsXt_BaseBill
    {
        public Model.ClsKf_CheckStockBillMain_K3 omodel = new Model.ClsKf_CheckStockBillMain_K3();
        public List<Model.ClsKf_CheckStockBillSub_K3> DetailColl = new List<Model.ClsKf_CheckStockBillSub_K3>();
        public SQLHelper.ClsCNK3 oCnK3 = new SQLHelper.ClsCNK3();
 
        public ClsKf_CheckStockOutBill_K3()
        {
            base.MvarItemKeySub = "ICStockBillEntry";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey = "ICStockBill";
            base.MvarReportTitle = "盘亏毁损";
            base.BillType = "43";
        }
 
        #region 固定代码
 
        ~ClsKf_CheckStockOutBill_K3()
        {
            DetailColl = null;
        }
       
        #endregion   自定义方法
 
 
        //单据号是否重复
        public virtual 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 ICStockBill where FTranType='" + MvarItemKey + "' and FBillNo ='" + sBillNo + "'";
                }
                else
                {
                    sSql = "Select FInterID from ICStockBill where FTranType='" + MvarItemKey + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
                }
                DataSet Ds;
                Ds = oCnK3.RunProcReturn(sSql, "ICStockBill");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单号重复";
                    return true;
                }
                sReturn = "单号未重复";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
 
 
 
        //删除单据
        public virtual bool DeleteBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                DataSet Ds;
                oCnK3.BeginTran();
                //
                Ds = oCnK3.RunProcReturn("select FSourceInterID from  ICStockBillEntry where finterid=" + lngBillKey, "ICStockBillEntry");
                //删除关联 
                //删除明细表 
                oCnK3.RunProc("Delete From  ICStockBillEntry where FInterID=" + lngBillKey.ToString());
                //删除主表 
                oCnK3.RunProc("Delete From  icstockbill where FInterID=" + lngBillKey.ToString());
                //删除关联 
                sReturn = "删除单据成功!";
                oCnK3.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
        //删除关联
        public override  void DeleteRelation(ref string sReturn, Int64 lngBillKey)
        {
            //oCn.RunProc("exec h_p_K3_MateOutRequestRelationQtyBack " + lngBillKey + ",'376001'");
            //sReturn = "";
            return;
        }
 
        //条码扫描记录,新增到盘亏
        public bool AddBill_PDA(string sHMaker, ref string sReturn)
        {
            try
            {
                DataSet Ds;
                DataSet Ds1;
                long sNewInterID = 0;
                string sNewBillNo = "";
                oCnK3.BeginTran();
                Ds1 = oCnK3.RunProcReturn("declare @InterID int set @InterID=0 exec GetICMaxNumOld  'ICStockBill',@InterID output select ltrim(@InterID)", "xt_xtgnb");
                if (Ds1.Tables[0].Rows.Count != 0)
                {
                    sNewInterID = DBUtility.ClsPub.isLong(Ds1.Tables[0].Rows[0][0]);
                }
                sNewBillNo = DBUtility.Xt_BaseBillFun.get_MaxBillNo_K3(this.BillType, oCnK3);
                //删除主表
                //oCnK3.RunProc("Delete From ICStockBill  where FInterID=" + sNewInterID.ToString());
                //插入子表
                oCnK3.RunProc("EXEC h_p_Kf_CheckStockOutBillSub_Insert_K3 " + omodel.HInterID.ToString() + "," + sNewInterID.ToString() + "," + omodel.HWHID.ToString() + "," + omodel.HSPID.ToString() + ",'" + sHMaker + "'");
                //插入主表
                oCnK3.RunProc("INSERT INTO ICStockBill" +
                           "(FInterID,FBillNo,FBrNo,FTranType,FCancellation" +
                           ",FStatus,FUpStockWhenSave,FHookStatus,Fdate" +
                           ",FCheckDate,FFManagerID,FBillerID" +
                           ",FMultiCheckDate1,FMultiCheckDate2,FMultiCheckDate3" +
                           ",FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" +
                           ",FBrID,FManagerID,FEmpID,FProcID" +
                           ",FVchInterID,FPrintCount,FInventoryType) " +
                           "VALUES " +
                           "(" + sNewInterID.ToString() + ",'" + sNewBillNo + "','0'," + this.BillType + ",0" +
                           ",0,0,0,convert(varchar(10),getdate(),120)" +
                           ",Null," + omodel.HFManagerID + "," + omodel.HBillerID + "" +
                           ",Null,Null,Null" +
                           ",Null,Null,Null" +
                           ",0,0,0,0" +
                           ",0,0,36700" +
                           ") ");
                //更新K3关联数量
                //oCnK3.RunProc("EXEC p_UpdateBillRelateData " + this.BillType + "," + omodel.HInterID.ToString() + ",'ICStockBill','ICStockBillEntry'");
                //oCnK3.RunProc("EXEC h_p_K3_UpdateBillRelateData_ProdIn_New " + omodel.HInterID.ToString());
                //更新单据NEWid
                oCnK3.RunProc("UPDATE ICStockBill SET FUUID=NEWID() WHERE FInterID=" + sNewInterID.ToString());
                //审核单据
                oCnK3.RunProc("EXEC h_p_Kf_CheckStockOutBill_Check_K3 " + sNewInterID.ToString() + "," + omodel.HBillerID.ToString());
                sReturn = "新增单据成功!";
                oCnK3.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
 
 
 
 
    }
}