yusijie
2023-04-23 e674cf9067913a1b621b45ac3560eb4a4d8eed61
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
using Model;
using Newtonsoft.Json;
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.IO;
using System.Web;
using System.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers
{
    public class Gy_SplitBarCodeController : ApiController
    {
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        public DAL.ClsGy_BarCodeBill_ChaiMa BillNew = new DAL.ClsGy_BarCodeBill_ChaiMa();   //对应单据类
 
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        /// <summary>
        /// 返回条码信息
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Gy_SplitBarCode/Info")]
        [HttpGet]
        public object BarCodeInfo(string HBarCodeNo, string HSplitBarNum)
        {
            try
            {
                //判断是否有查询权限
 
                //if (!DBUtility.ClsPub.Security_Log("Cg_POOrderBillQuery", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无权限查看!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                
                //查询条码信息
                if(HBarCodeNo != null && HSplitBarNum != null)
                {
                    SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    ds = oCn.RunProcReturn("select top 1 * from h_v_Gy_SplitBarCode where HBarCode='" + HBarCodeNo + "'", "h_v_Gy_SplitBarCode");
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "请输入条码编号或拆分条码数";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                //判断是否存在此条码
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {                   
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "条码编号不存在, 提示";
                    objJsonResult.data = ds.Tables[0];
                    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;
            }
        }
 
        #region 拆码条码生成
        [Route("Sc_BarCode/Save_SplitBarCode")]
        [HttpPost]
        public object Save_SplitBarCode([FromBody] JObject msg)
        {
            try
            {
                ListModels oListModels = new ListModels();                 
                BillNew = new DAL.ClsGy_BarCodeBill_ChaiMa();
                var _value = msg["msg"].ToString();
                string msg1 = _value.ToString();
 
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string barcode = sArray[0].ToString(); //条码编号
                Int64 splitnum = Convert.ToInt64(sArray[1]); //拆码行数
                string data = sArray[2].ToString(); //表体数据
                string user = sArray[3].ToString(); //用户名
 
                data = data.Replace("\\", "");
                data = data.Replace("\n", "");  //\n
 
                List<Model.ClsGy_BarCodeEdit_Model> lsmain = new List<Model.ClsGy_BarCodeEdit_Model>();
                lsmain = oListModels.getObjectByJson_Gy_SplitBarCode(data);
 
                oCN.BeginTran();
 
                ds = oCN.RunProcReturn("select top 1* from Gy_BarCodeBill where HBarCode='" + barcode + "'", "Gy_BarCodeBill");
 
                bool bResult = true;
 
                if (ds != null || ds.Tables[0].Rows.Count > 0) 
                {
                    Model.ClsGy_BarCodeEdit_Model model = new Model.ClsGy_BarCodeEdit_Model();
                    for (Int64 i = 0; i < splitnum; i++)
                    {
                        model.HEntryID = i + 1;
                        model.HInterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HInterID"].ToString());
                        model.HBarCode = DBUtility.ClsPub.isStrNull(lsmain[Convert.ToInt32(i)].HBarCode);
                        model.HQty = DBUtility.ClsPub.isLong(lsmain[Convert.ToInt32(i)].HSplitNum);
                        model.HQty = DBUtility.ClsPub.isInt(lsmain[Convert.ToInt32(i)].HSplitNum);
                        model.HBatchNo = DBUtility.ClsPub.isStrNull(lsmain[Convert.ToInt32(i)].HBatchNo);
                        model.HMaterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HMaterID"].ToString());
                        model.HUnitID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HUnitID"].ToString());
                        model.HSupID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSupID"].ToString());
                        model.HDeptID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HDeptID"].ToString());
                        model.HEmpID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HEmpID"].ToString());
                        model.HBarCodeType = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBarCodeType"].ToString());
                        model.HItemSubID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HItemSubID"].ToString());
                        model.HGroupID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HGroupID"].ToString());
                        model.HSourceInterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSourceInterID"].ToString());
                        model.HSourceEntryID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSourceEntryID"].ToString());
                        model.HSourceBillNo = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HSourceBillNo"].ToString());
                        model.HSourceBillType = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HSourceBillType"].ToString());
                        model.HUseFlag = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HUseFlag"].ToString());
                        model.HInitQty = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[0]["HInitQty"].ToString());
                        model.HSourceID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HInitQty"].ToString());
                        model.HCusID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HCusID"].ToString());
                        model.HSTOCKORGID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSTOCKORGID"].ToString());
                        model.HOWNERID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HOWNERID"].ToString());
                        model.HBarCodeDate = DBUtility.ClsPub.isDate(ds.Tables[0].Rows[0]["HBarCodeDate"].ToString());
                        model.HInnerBillNo = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HInnerBillNo"].ToString());
                        model.HMZ = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[0]["HMZ"].ToString());
 
                        model.HMakeDate = DateTime.Now;
                        model.HMaker = user;
 
                        BillNew.DetailColl_Mater.Add(model);
 
                        //保存
                        bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo, barcode);
 
                        BillNew.DetailColl_Mater.Remove(model);
                    }
 
                }
               
                if (bResult)
                {
                    oCN.Commit();
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }               
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
    }
}