zgq
2021-06-30 ad7bec1313df110892242c6dab7848b8df61a1e0
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
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Http;
using WebAPI.Models;
namespace WebAPI.Controllers
{
    /**
     * 裁切派工单
     */
    public class Xs_CutWorkSendBillController : ApiController
    {
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public WebServer webserver = new WebServer();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
 
 
        /// <summary>
        /// 扫描找货单号获取相关信息
        /// </summary>
        /// <returns></returns>
        [Route("Xs_CutWorkSendBill/getHSEOrderBillNo")]
        [HttpGet]
        public object getHSEOrderBillNo(string HSEOrderBillNo)
        {
            if (HSEOrderBillNo == null || ("").Equals(HSEOrderBillNo))
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "请输入找货单号!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            try
            {
                ds = getHSEOrderBillNo_s(HSEOrderBillNo);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "返回记录成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception ex)
            { 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 生成裁切派工单
        /// </summary>
        /// <returns></returns>
        [Route("Xs_CutWorkSendBill/set_SaveCutWorkSendBill")]
        [HttpPost]
        public object set_SaveCutWorkSendBill([FromBody] JObject oMain)
        {
            string oMainData = oMain["oMain"].ToString();
            oMainData = oMainData.Substring(8, oMainData.Length - 9);
            try
            {
                List<Xs_CutWorkSendBill> lsmain = new List<Xs_CutWorkSendBill>();
                ListModels oListModels = new ListModels();
                List<Xs_CutWorkSendBill> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Xs_CutWorkSendBill>>(oMainData);
                int HYear = Pub_Class.ClsPub.isInt(DateTime.Now.Year);
                int HPeriod = Pub_Class.ClsPub.isInt(DateTime.Now.Month);
                string HBillType = "9191";
                oCN.BeginTran();
                var mainSql = "Insert Into Xs_CutWorkSendBillMain " +
                    "(HYear,HPeriod,HBillType,HInterID,HDate" +
                    ",HBillNo,HMaker,HMakeDate,HMainSourceBillType" +
                    ",HGroupID)" +
                    " values" +
                    "(" + HYear + "," + HPeriod + ",'" + HBillType + "'," + list[0].HInterID + ",GETDATE(),'" 
                    + list[0].HBillNo + "','" + list[0].HMaker + "',GETDATE(),'1401',"
                    + list[0].HGroupID + ")";
                oCN.RunProc(mainSql);
                for (int i = 0; i < list.Count; i++)
                {
                    var subSql = "Insert Into Xs_CutWorkSendBillSub " +
                    "(HInterID,HBillNo_bak,HSourceInterID,HSourceBillNo,HSourceBillType" +
                    ",HSEOrderBillNo,HSEOrderInterID)" +
                    " values" +
                    "(" + list[i].HInterID + ",'" + list[i].HBillNo + "'," + list[i].HMainSourceInterID + ",'" + list[i].HMainSourceBillNo + "','1401','"
                    + list[i].HMainSourceBillNo + "'," + list[i].HMainSourceInterID + ")";
                    oCN.RunProc(subSql);
                    //反写金蝶销售订单的裁切派工班组
                    var HGroupSql = "update AIS20200908101915zs..T_SAL_ORDERENTRY set F_XSDD_PGSJ=GETDATE(),F_XSDD_PGBZ=(select HName from Gy_Group where HItemID=" + list[i].HGroupID + ") where FID = " + list[i].HMainSourceInterID + "";
                    oCN.RunProc(HGroupSql);
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "生成找货单成功!单据号为:" + list[0].HBillNo;
                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;
            }
        }
 
        /// <summary>
        /// 上下架单列表
        /// </summary>
        /// <returns></returns>
        [Route("Xs_CutWorkSendBill/List")]
        [HttpGet]
        public object List(string sWhere)
        {
            try
            {
                ds = List_s(sWhere);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "返回记录成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
 
 
        #region sql语句
 
        public static DataSet getHSEOrderBillNo_s(string HSEOrderBillNo)
        {
            return new SQLHelper.ClsCN().RunProcReturn(
                "select FID HMainSourceInterID,FBILLNO HMainSourceBillNo,1 pages,'' HMaker from AIS20200908101915zs..T_SAL_ORDER where FBILLNO ='" + HSEOrderBillNo + "'"
                , "AIS20200908101915zs..T_SAL_ORDER");
        }
        public static DataSet List_s(string sWhere)
        {
            return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_Xs_CutWorkSendBillList where 1=1 " + sWhere , "h_v_Xs_CutWorkSendBillList");
        }
 
 
        #endregion
 
    }
}