yangle
2024-07-11 39a43039bbb6491f33783fb675a111c61e749891
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
using DBUtility;
using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Http;
using WebAPI.Models;
 
 
namespace WebAPI.Controllers.仓存管理.领料发货
{
    public class Kf_StockOutRequestBillController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
 
        #region 出库申请单列表
        [Route("Kf_StockOutRequestBill/GetStockOutRequestBillList")]
        [HttpGet]
        public object GetMoveStockRequestBillList(string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();  //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
                ////判断是否有查询权限
                //if (!DBUtility.ClsPub.Security_Log("Kf_MoveStockRequestBill_Query", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无权限查询!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
 
                string sql1 = string.Format("select * from h_v_IF_StockOutRequestBillList where 1=1 ");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCn.RunProcReturn(sql1 + " order by hmainid desc", "h_v_IF_StockOutRequestBillList");
                }
                else
                {
                    string sql = sql1 + sWhere + " order by hmainid desc";
                    ds = oCn.RunProcReturn(sql, "h_v_IF_StockOutRequestBillList");
                }
                foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                {
                    Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // 将列名和数据类型信息拼接成一个JSON格式的字符串
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];//代码将第一个DataTable(索引为0)赋值给objJsonResult的data属性
                objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 出库申请单 保存/编辑功能
        [Route("Kf_StockOutRequestBill/StockOutRequestBillEdit")]
        [HttpPost]
        public object StockOutRequestBillEdit([FromBody] JObject sMainSub)
        {
            try
            {
                var _value = sMainSub["sMainSub"].ToString();
                string msg1 = _value.ToString();
                oCn.BeginTran();
                //保存主表
                objJsonResult = AddBillMain(msg1);
                if (objJsonResult.code == "0")
                {
                    oCn.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCn.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "单据保存成功!";
                objJsonResult.data = null;
                return objJsonResult;
 
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        public json AddBillMain(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString(); //主表数据
            string msg3 = sArray[1].ToString(); //子表数据
            int OperationType = int.Parse(sArray[2].ToString()); // 数据类型 1添加 3修改
            string user = sArray[3].ToString();
            string msg_allVal = sArray[4].ToString(); //主表+子表所有数据
 
            try
            {
                msg2 = "[" + msg2.ToString() + "]";
                List<ClsKf_StockOutRequestBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_StockOutRequestBillMain>>(msg2);
 
                long HInterID = mainList[0].HInterID;//递入type得到的单据ID
                string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                long HPRDORGID = mainList[0].HPRDORGID;//组织
                DateTime HDate = mainList[0].HDate;//日期
                string HRemark = mainList[0].HRemark;//备注
                long HSupID = mainList[0].HSupID;//往来单位
                long HEmpID = mainList[0].HEmpID;//业务员
                long HDeptID = mainList[0].HDeptID;//部门
                long HWHID = mainList[0].HWHID;//仓库
                long HMangerID = mainList[0].HMangerID;//主管
                long HSecManagerID = mainList[0].HSecManagerID;//验收
                long HKeeperID = mainList[0].HKeeperID;//保管员
                string HMaker = user;//制单人
                string HExplanation = mainList[0].HExplanation;//摘要
                string HInnerBillNo = mainList[0].HInnerBillNo;//内部单据号 
 
                string HBillType = mainList[0].HBillType;
                string HBillSubType = mainList[0].HBillSubType;
                long HBillStatus = mainList[0].HBillStatus;
                string HMakeDate = mainList[0].HMakeDate;
                string HChecker = mainList[0].HChecker;
                string HCheckDate = mainList[0].HCheckDate;
                string HUpDater = mainList[0].HUpDater;
                string HUpDateDate = mainList[0].HUpDateDate;
                string HDeleteMan = mainList[0].HDeleteMan;
                string HDeleteDate = mainList[0].HDeleteDate;
                string HCloseMan = mainList[0].HCloseMan;
                string HCloseDate = mainList[0].HCloseDate;
                long HERPInterID = mainList[0].HERPInterID;
                string HERPBillType = mainList[0].HERPBillType;
                long HSTOCKORGID = mainList[0].HSTOCKORGID;
                string HAPPLYTYPE = mainList[0].HAPPLYTYPE;
                long HOWNERTYPEIDHEAD = mainList[0].HOWNERTYPEIDHEAD;
                string HBIZTYPE = mainList[0].HBIZTYPE;
 
                //进行 会计期间 结账 的判断和控制
                string s = "";
                int sYear = 0;
                int sPeriod = 0;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    objJsonResult.Message = s;
                    return objJsonResult;
                }
 
                ds = oCn.RunProcReturn("select * from h_v_IF_StockOutRequestBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_IF_StockOutRequestBillList");
 
                if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增
                {
                    //主表
                    oCn.RunProc(@"Insert Into Kf_StockOutRequestBillMain   
                        (HInterID,HBillNo,HDate,HBillType,HBillSubType,HBillStatus,HYear,HPeriod
                        ,HSupID,HWHID,HEmpID,HMangerID,HSecManagerID,HKeeperID,HDeptID
                        ,HMaker,HMakeDate,HChecker,HCheckDate,HUpDater,HUpDateDate
                        ,HDeleteMan,HDeleteDate,HCloseMan,HCloseDate
                        ,HRemark,HExplanation,HInnerBillNo,HERPInterID,HERPBillType
                        ,HSTOCKORGID,HAPPLYTYPE,HOWNERTYPEIDHEAD,HBIZTYPE)
                        values(" + HInterID + ",'" + HBillNo + "','" + HDate + "','" + 1242 + "','" + 1242 + "'," + HBillStatus + "," + DateTime.Now.Year + "," + DateTime.Now.Month + "," + HSupID +
                    "," + HWHID + "," + HEmpID + "," + HMangerID + "," + HSecManagerID + "," + HKeeperID +
                    "," + HDeptID + ",'" + HMaker + "','" + HMakeDate + "','" + HChecker + "','" + HCheckDate + "','" + HUpDater + "','" +
                    HUpDateDate + "','" + HDeleteMan + "','" + HDeleteDate + "','" + HCloseMan + "','" + HCloseDate + "','"
                    + HRemark + "','" + HExplanation + "','" + HInnerBillNo + "'," + HERPInterID + ",'" + HERPBillType + "',"
                    + HSTOCKORGID + ",'" + HAPPLYTYPE + "'," + HOWNERTYPEIDHEAD + ",'" + HBIZTYPE + "'" + ")");
                }
                else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
                { //修改
                    oCn.RunProc("update Kf_StockOutRequestBillMain  set " +
                                "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" + " where HInterID=" + HInterID);
 
                    //删除子表
                    oCn.RunProc("delete from Kf_StockOutRequestBillSub where HInterID='" + HInterID + "'");
                }
                //保存子表
                objJsonResult = AddBillSub(msg3, HInterID, OperationType);
 
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = null;
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        public json AddBillSub(string msg3, long HInterID, int OperationType)
        {
            List<ClsKf_StockOutRequestBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_StockOutRequestBillSub>>(msg3);
 
            int i = 0;
            foreach (ClsKf_StockOutRequestBillSub oSub in DetailColl)
            {
                i++;
                if (oSub.HQty <= 0 || oSub.HQty == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "第" + i + "行,数量不能为0或者小于0";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (oSub.HMaterID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "第" + i + "行,物料不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                //if (oSub.HSourceID == 0)
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "第" + i + "行,生产资源不能为空";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
 
                if (oSub.HUnitID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "第" + i + "行,计量单位不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                DataSet Cs;
                Int64 NewHEntryID = 1;
                Cs = oCn.RunProcReturn("select MAX(HEntryID)HEntryID from Kf_StockOutRequestBillSub", "Kf_StockOutRequestBillSub");
                if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()) != 0)
                {
                    NewHEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString());
                    NewHEntryID += 1;
                }
 
                oCn.RunProc($@"Insert into Kf_StockOutRequestBillSub 
                (HInterID,HEntryID,HBillNo_bak,HRemark,HMTONo,HPlanMode,HERPInterID,HERPEntryID
                ,HMaterID,HUnitID,HSecUnitID,HPropertyID,HAuxPropID,HBatchNO,HWHID,HSPID
                ,HQtyMust,HQty,HRelationQty,HRelationMoney,HSecUnitRate,HPrice,HMoney
                ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType
                ,HICMOInterID,HICMOEntryID,HICMOBillNo,HPOOrderInterID,HPOOrderEntryID,HPOOrderBillNo
                ,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo
                ,HSEQ,HSTOCKORGID,HSTOCKSTATUSID,HOWNERTYPEID,HEXTAUXUNITID
                ,HOWNERID,HBOMID,HBASEUNITID,HPRODUCEDATE,HEXPIRYDATE) 
                 values({HInterID},{NewHEntryID},'{oSub.HBillNo_bak}','{oSub.HRemark}','{oSub.HMTONo}'
                ,'{oSub.HPlanMode}',{oSub.HERPInterID},{oSub.HERPEntryID},{oSub.HMaterID},{oSub.HUnitID},{oSub.HSecUnitID},{oSub.HPropertyID},{oSub.HAuxPropID},'{oSub.HBatchNO}',{oSub.HWHID},{oSub.HSPID},{oSub.HQtyMust},{(oSub.HQty == null ? 0 : oSub.HQty)},{oSub.HRelationQty},{oSub.HRelationMoney},{oSub.HSecUnitRate},{oSub.HPrice},{oSub.HMoney}
                ,{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HICMOInterID},{oSub.HICMOEntryID},'{oSub.HICMOBillNo}',{oSub.HPOOrderInterID},{oSub.HPOOrderEntryID}
                ,'{oSub.HPOOrderBillNo}',{oSub.HSeOrderInterID},{oSub.HSeOrderEntryID},'{oSub.HSeOrderBillNo}',{oSub.HSEQ},{oSub.HSTOCKORGID},{oSub.HSTOCKSTATUSID},'{oSub.HOWNERTYPEID}',{oSub.HEXTAUXUNITID},{oSub.HOWNERID}
                ,{oSub.HBOMID},{oSub.HBASEUNITID},'{oSub.HPRODUCEDATE}','{oSub.HEXPIRYDATE}')");
            }
 
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = null;
            objJsonResult.data = null;
            return objJsonResult;
        }
 
        #endregion
 
        #region 出库申请单列表
        [Route("Kf_StockOutRequestBill/cx")]
        [HttpGet]
        public object cx(long HInterID)
        {
            try
            {
 
                ds = oCn.RunProcReturn("select * from h_v_IF_StockOutRequestBillList where hmainid =" + HInterID, "h_v_IF_StockOutRequestBillList");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "false!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        /// <summary>
        ///删除功能
        /// </summary>
        /// <returns></returns>
        [Route("Kf_StockOutRequestBill/DeltetKf_StockOutRequestBill")]
        [HttpGet]
        public object DeltetKf_StockOutRequestBill(string HInterID)
        {
            try
            {
                //进行 会计期间 结账 的判断和控制
                string s = "";
                int sYear = 0;
                int sPeriod = 0;
                DateTime HDate = DateTime.Now;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    objJsonResult.Message = s;
                    return objJsonResult;
                }
 
                oCn.BeginTran();
                oCn.RunProc("Delete From Kf_StockOutRequestBillMain where HInterID = " + HInterID);
                oCn.RunProc("Delete From Kf_StockOutRequestBillSub where HInterID = " + HInterID);
                oCn.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "删除成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
    }
}