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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public class ClsK3_Material_Ctl:DBUtility.ClsGy_Base_Ctl 
    {
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        SQLHelper.ClsCNK3 oK3Cn = new SQLHelper.ClsCNK3();
 
        public Model.ClsK3_Material_Model oModel ;
        //新增
        public override bool AddNew()
        {
            try
            {
                oCn.BeginTran();
                base.DeleteByID(oModel.HItemID);
                oCn.RunProc("Insert into " + MvarItemKey + " " +
                    " (HItemID,HNumber,HhgNumber" +
                    ",HBigPackPrice,HColorMidPackPrice,HWhiteMidPackPrice,HColorSmlPackPrice" +
                    ",HWhiteSmlPackPrice,HPaperCardPrice,HPlasticBagPrice,HPlasticCardPrice" +
                    ",HPhaseFlag,HBarCode,HProcID,HMaterID,HMaterNumber) " +
                    " Values(" + oModel.HItemID.ToString() + ",'" + oModel.HNumber + "','" + oModel.HhgNumber + "'" +
                    "," + oModel.HBigPackPrice.ToString() + "," + oModel.HColorMidPackPrice.ToString() + "," + oModel.HWhiteMidPackPrice.ToString() + "," + oModel.HColorSmlPackPrice.ToString() +
                    "," + oModel.HWhiteSmlPackPrice.ToString() + "," + oModel.HPaperCardPrice.ToString() + "," + oModel.HPlasticBagPrice.ToString() + "," + oModel.HPlasticCardPrice.ToString() +
                    "," + Convert.ToString(oModel.HPhaseFlag ? 1 : 0) + ",'" + oModel.HBarCode + "'," + oModel.HProcID.ToString() + "," + oModel.HMaterID.ToString() + ",'" + oModel.HMaterNumber + "'" +
                    ")", ref DBUtility.ClsPub.sExeReturnInfo);
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                throw (e);
            }
        }
 
        //K3单据新增
        public bool AddNew_K3()
        {
            try
            {
                oK3Cn.BeginTran();
                oK3Cn.RunProc("exec h_p_K3_Gy_AddMaterial2 " + oModel.HLevel.ToString() + "," + oModel.HParentID.ToString() + "," + DBUtility.ClsPub.BoolToString(oModel.HEndFlag) + ",'" + oModel.HShortNumber + "'" +
                      ",'" + oModel.HName + "','" + oModel.HNumber + "','" + oModel.HHelpCode + "','" + oModel.HModel + "','" + oModel.HPICNo + "'" +
                      "," + oModel.HMaterTypeID.ToString() + "," + oModel.HMaterClsID.ToString() + "," + oModel.HUnitID.ToString() + "," + oModel.HUnitGroupID.ToString() + "," + oModel.HSecUnitID.ToString() +
                      "," + oModel.HWhID.ToString() + "," + oModel.HSPID.ToString() + "," + oModel.HQtyDecimal.ToString() + "," + oModel.HLowStock.ToString() + "," + oModel.HHighStock.ToString() +
                      "," + oModel.HSafeStock.ToString() + ",'" + oModel.HUseFlag + "'," + oModel.HSource.ToString() + "," + oModel.HOrderPrice.ToString() + ",'" + oModel.HRemark + "'" 
                    , ref DBUtility.ClsPub.sExeReturnInfo);
                oK3Cn.Commit();
                return true;
            }
            catch (Exception e)
            {
                oK3Cn.RollBack();
                throw (e);
            }
        }
 
 
        //根据代码判断信息
        public bool HavParentCode(string sCode, ref Int64 sItemID)
        {
            DataSet DS;
            try
            {
                DS = oK3Cn.RunProcReturn("Select FItemID from t_Item Where FDeleted=0 and fitemclassid=4 and FNumber='" + sCode + "'  ", "t_Item", ref Pub_Class.ClsPub.sExeReturnInfo);
                if (DS.Tables[0].Rows.Count == 0)
                    return false;
                else
                {
                    sItemID = Convert.ToInt64(DS.Tables[0].Rows[0]["FItemID"]);
                    return true;
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
         
        //构造函数
        public ClsK3_Material_Ctl()
        {
            MvarItemKey = "K3_Material_Extend";
            MvarReportTitle = "物料设置";
            oModel = new Model.ClsK3_Material_Model();
        }
 
 
        public bool AddMaterial(string sMaterNumber, string sRoutingFlow, ref string sReturn)
        {
            SQLHelper.ClsCNK3 oCnK3 = new SQLHelper.ClsCNK3();
            DataSet oDs = new DataSet();
            long HUserID = 0;
            string FUserName = "";
            long FParentID = 0;
            long FLevel = 0;
            string FNumber = "";
            string FShortNumber = "";
            string FName = "";
            string FModel = "";
            long FUnitGroupID = 0;
            long FUnitID = 0;
            long FErpClsID = 0;
            long FAcctID = 0;
            string HRemark = "";
            //
            oDs = oCn.RunProcReturn("select * from h_v_IF_Material  where HNumber='" + sMaterNumber + sRoutingFlow + "'", "h_v_IF_Material");
            if (oDs.Tables[0].Rows.Count > 0)
            {
                sReturn = "物料已存在!";
                return true;
            }
            //
            oDs = oCn.RunProcReturn("select * from h_v_IF_Material  where HNumber='" + sMaterNumber + "'", "h_v_IF_Material");
            if (oDs == null || oDs.Tables[0].Rows.Count == 0)
            {
                sReturn = "未查询到基础物料信息!";
                return false;
            }
            else
            {
                //得到K3操作员ID
                HUserID = DBUtility.ClsPub.GetUser_K3(DBUtility.ClsPub.CurUserName);
                FUserName = DBUtility.ClsPub.CurUserName;
                FParentID = DBUtility.ClsPub.isLong(oDs.Tables[0].Rows[0]["HParentID"]);
                FLevel = DBUtility.ClsPub.isLong(oDs.Tables[0].Rows[0]["HLevel"]);
                FNumber = DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HNumber"]) + sRoutingFlow;
                FShortNumber = DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HShortNumber"]) + sRoutingFlow;
                FName = DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HName"]) + sRoutingFlow;
                FModel = DBUtility.ClsPub.isStrNull(oDs.Tables[0].Rows[0]["HModel"]) + sRoutingFlow;
                FUnitGroupID = DBUtility.ClsPub.isLong(oDs.Tables[0].Rows[0]["HUnitGroupID"]);
                FUnitID = DBUtility.ClsPub.isLong(oDs.Tables[0].Rows[0]["HUnitID"]);
                FErpClsID = DBUtility.ClsPub.isLong(oDs.Tables[0].Rows[0]["HErpclsid"]);
                FAcctID = DBUtility.ClsPub.isLong(oDs.Tables[0].Rows[0]["HAcctID"]);
            }
            try
            {
                oCnK3.BeginTran();
                //新增物料
                oCnK3.RunProc("exec h_p_K3_Gy_AddMaterial " + HUserID.ToString() + ",'" + FUserName + "'," + FParentID.ToString() + "," + FLevel.ToString() +
                    ",'" + FNumber + "','" + FShortNumber + "','" + FName + "','" + FModel + "'," + FUnitGroupID.ToString() + "," + FUnitID.ToString() + "," + FErpClsID.ToString() + "," + FAcctID.ToString() + ",'" + HRemark + "'");
                //
                oCnK3.Commit();
                sReturn = "新增成功!";
                return true;
            }
            catch (Exception e)
            {
                oCnK3.RollBack();
                sReturn = e.Message;
                throw (e);
            }
        }
 
    }
}