zzr99
2022-03-17 26fba348f6dda10539a732dbfcec025e3bbac2c5
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
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers
{
    //生产任务单Controller
    //数据库主表Sc_ICMOBillMain
    //数据库子表Sc_ICMOBillSub
    public class Sc_ICMOBillController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        private json objJsonResult = new json(); 
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        #region 生产任务单删除功能
        [Route("Sc_ICMOBill/DeltetSc_ICMOReportBill")]
        [HttpGet]
        public object DeltetSc_ICMOReportBill(string HInterID,string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Drop", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限删除!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select * from Sc_ICMOBillMain where HInterID=" + HInterID, "Sc_ICMOBillMain");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有数据,无法删除!";
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
                oCN.RunProc("delete from Sc_ICMOBillMain  where HInterID=" + HInterID);
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "* 数据删除成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
 
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "删除失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
 
        #region 墙咔装箱单回车事件
        [Route("Sc_ICMOBill/QK_PackingBillByXSBill")]
        [HttpGet]
        public object QK_PackingBillByXSBill(string HBillNo)
        {
            try
            {
                string sql = string.Format(@"select b.HMaterID,m.HNumber HMaterCode,m.HName HMaterName,b.HUnitID,u.HName HUnitName,
                                b.HQty HQty,a.HAddress HAddress,b.HDate HDate,b.HOutStockQty HOutStockQty,b.HInvoiceQty HInvoiceQty,
                                b.HTaxPrice HTaxPrice,b.HPrice HPrice,b.HMoney HMoney,a.HCusID HCusID,c.HName HCusName,a.HEmpID,e.HName HEmpName,
                                i.HInterID,i.HBillNo
                                from Xs_SeOrderBillMain a 
                                left join  Xs_SeOrderBillSub b on a.HInterID=b.HInterID
                                left join Gy_Material m on b.HMaterID=m.HItemID
                                left join Gy_Unit u on b.HUnitID=u.HItemID
                                left join Gy_Customer c on a.HCusID=c.HItemID
                                left join Gy_Employee e on a.HEmpID=e.HItemID
                                left join Sc_ICMOBillMain i on i.HSeOrderInterID=a.HInterID
                                where a.HInterID=(select HSeOrderInterID from Sc_ICMOBillMain where HBillNo='" + HBillNo + "')");
               
                ds = oCN.RunProcReturn(sql, "Xs_SeOrderBillMain");
                if (ds.Tables[0].Rows.Count != 0 || ds != null)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "获取成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "暂无对应的销售明细!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "获取失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 墙咔装箱单整箱生成
        [Route("Sc_ICMOBill/QK_PackingBillSavePack")]
        [HttpPost]
        public object QK_PackingBillSavePack([FromBody] JObject msg)
        {
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string msg4 = sArray[2].ToString();
 
            ListModels oListModels = new ListModels();
            try
            {
                if (msg4=="ZZ")
                {
                    //表体数据
                    //按 },{来拆分数组 //去掉【和】
 
                    msg2 = msg2.Replace("\\", "");
                    msg2 = msg2.Replace("\n", "");  //\n
                                                    //msg2 = msg2.Replace("'", "’");
                    List<Models.ClsQK_PackingBill> ls = new List<Models.ClsQK_PackingBill>();
                    ls = oListModels.getObjectByJson_QK_PackingBill(msg2);
                    oCN.BeginTran();
                    foreach (Models.ClsQK_PackingBill oItemSub in ls)
                    {
                        var HInterID = DBUtility.ClsPub.CreateBillID("3783", ref DBUtility.ClsPub.sExeReturnInfo);
                        var HBillNo = DBUtility.ClsPub.CreateBillCode("3783", ref DBUtility.ClsPub.sExeReturnInfo, true);
                        string sql = string.Format(@"Insert Sc_PackUnionBillMain(HYear,HPeriod,HBillType,HInterID,HDate,HBillNo,HBillStatus,HCheckItemNowID,HCheckItemNextID,
                                                    HRemark,HBacker,HChecker,HMaker,HMakeDate,HUpDater,HCloseMan,HCloseType,HDeleteMan,
                                                    HICMOInterID,HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID,HWeight,HMWeight,HPWeight,
                                                    HProdOrgID,HDeptID,HEmpID,HSNum,HPackNum,HBarCode_Cus,HBatchNo,HBillSubType)
                                                    values('2022',1,'3783'," + HInterID + ",getdate(),'" + HBillNo + "',1,0,0," +
                                                        "'自动绑定','','', " + msg3 + ",getdate(),'','',0,''," +
                                                        oItemSub.HInterID + ",'" + oItemSub.HBillNo + "','" + HBillNo + "'," + oItemSub.HMaterID + "," + oItemSub.HUnitID + "," + oItemSub.HWeight + "," + oItemSub.HMWeight + "," + oItemSub.HPWeight + "," +
                                                        "0,0," + oItemSub.HEmpID + ",0,0,'','','')");
                        oCN.RunProc(sql);
                    }
                    oCN.Commit();
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "整装生成成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                {
                    msg2 = msg2.Replace("\\", "");
                    msg2 = msg2.Replace("\n", "");  //\n
                                                    //msg2 = msg2.Replace("'", "’");
                    List<Models.ClsQK_PackingBill> ls = new List<Models.ClsQK_PackingBill>();
                    ls = oListModels.getObjectByJson_QK_PackingBill(msg2);
 
                    var HInterID = DBUtility.ClsPub.CreateBillID("3783", ref DBUtility.ClsPub.sExeReturnInfo);
                    var HBillNo = DBUtility.ClsPub.CreateBillCode("3783", ref DBUtility.ClsPub.sExeReturnInfo, true);
                    oCN.BeginTran();
                    foreach (Models.ClsQK_PackingBill oItemSub in ls)
                    {
                        string sql = string.Format(@"insert into Sc_PackUnionBillSub(HInterID,HEntryID,HCloseMan,HCloseType,HRemark,
                                                    HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,
                                                    HRelationQty,HRelationMoney,HMaterID,HUnitID,HQty,HSourceID,HEquipID,HGroupID,HWorkerID,
                                                    HScanDate,HBarCode,HBarCode_Pack)
                                                    values("+HInterID+",'','',0,'自动绑定',"+oItemSub.HInterID+",'',"+oItemSub.HBillNo+",'3710',"+
                                                    "0,0,"+ oItemSub.HMaterID+","+ oItemSub.HUnitID+","+ oItemSub.HQty+", 0,0,0,0,"+
                                                    "getdate(),'',"+HBillNo+")");
                        oCN.RunProc(sql);
                    }
                    string sql2 = string.Format(@"Insert Sc_PackUnionBillMain(HYear,HPeriod,HBillType,HInterID,HDate,HBillNo,HBillStatus,HCheckItemNowID,HCheckItemNextID,
                                                    HRemark,HBacker,HChecker,HMaker,HMakeDate,HUpDater,HCloseMan,HCloseType,HDeleteMan,HICMOInterID,HICMOBillNo,
                                                    HBarCode_Pack,HMaterID,HUnitID,HWeight,HMWeight,HPWeight,
                                                    HProdOrgID,HDeptID,HEmpID,HSNum,HPackNum,HBarCode_Cus,HBatchNo,HBillSubType)
                                                    values('2022',1,'3783'," + HInterID + ",getdate(),'" + HBillNo + "',1,0,0," +
                                                        "'自动绑定','','', " + msg3 + ",getdate(),'','',0,'',0,0,'" +
                                                         HBillNo + "',0,0,0,0,0" + 
                                                        "0,0,0,0,0,'','','')");
                    oCN.RunProc(sql2);
                    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;
            }
        }
        #endregion
    }
}