zzr99
2021-10-20 04a6967c9e4f4b83213fa90cee66b48e855c818c
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
using DBUtility;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers.SBGL
{
    public class Gy_EquipTypeController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        public DLL.ClsGy_EquipTypeBill BillNew0 = new DLL.ClsGy_EquipTypeBill();   //模具报废入库对应单据类
        public DLL.ClsGy_EquipTypeBill BillOld0 = new DLL.ClsGy_EquipTypeBill();   //模具报废入库对应单据类
 
        #region 设备分类列表
 
        [Route("Gy_EquipType/GetList")]
        [HttpGet]
        public object GetList(string sWhere)
        {
            try
            {
                ds = Sc_GetEquipTypeList(sWhere);
                if (ds == null)
                {
                    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;
            }
        }
 
        public static DataSet Sc_GetEquipTypeList(string sWhere)
        {
            string sql1 = string.Format(@"select * from h_v_Gy_EquipTypeList");
            if (sWhere == null || sWhere.Equals(""))
            {
                return new SQLHelper.ClsCN().RunProcReturn(sql1 + sWhere + " order by HItemID desc", "h_v_Gy_EquipTypeList");
            }
            else
            {
                string sql = sql1 + sWhere + " order by HItemID desc";
                return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_Gy_EquipTypeList");
            }
 
        }
 
        #endregion
 
        #region [设备分类删除功能]
        [Route("Gy_EquipType/Delete_EquipType")]
        [HttpGet]
        public object Delete_EquipType(string HItemID)
        {
            string s = "";
            Int64 lngBillKey = 0;
            lngBillKey = DBUtility.ClsPub.isLong(HItemID);
            if (lngBillKey == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据ID为空!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            DLL.ClsGy_EquipTypeBill oBill = new DLL.ClsGy_EquipTypeBill();
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
            {
                bool IsDete = oBill.DeleteBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo);
                if (IsDete)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据未找到";
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        #endregion
 
        #region 设备分类保存/编辑
        [Route("Gy_EquipType/SaveEquipTypeList")]
        [HttpPost]
        public object SaveEquipTypeList([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 refSav = sArray[1].ToString();
 
            ListModels oListModels = new ListModels();
            try
            {
                DLL.ClsGy_EquipTypeBill oBill = new DLL.ClsGy_EquipTypeBill();
                List<Models.ClsGy_EquipFileType> lsmain = new List<Models.ClsGy_EquipFileType>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Gy_EquipFileType(msg2);
 
                long HItemID = lsmain[0].HItemID;
                string HNumber = lsmain[0].HNumber;
                string HName = lsmain[0].HName;
                string HShortNumber = lsmain[0].HNumber;
                long HParentID = lsmain[0].HParentID;
                long HLevel = lsmain[0].HLevel;
                string HHelpCode = lsmain[0].HHelpCode;
                string HRemark = lsmain[0].HRemark;
                bool HStopflag = lsmain[0].HStopflag;
                string HUseFlag = lsmain[0].HUseFlag;
                bool HEndFlag = lsmain[0].HEndFlag;
 
                if (refSav == "Add")
                {
                        //若MAINDI重复则重新获取
                        oCN.BeginTran();
                        //主表
                        oCN.RunProc("Insert into Gy_EquipFileType " +
                           " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                           ",HLevel,HEndFlag,HStopflag,HRemark,HMakeTime) " +
                           " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + HShortNumber + "'," + HParentID +
                           "," + HLevel + "," + Convert.ToString(HEndFlag ? 1 : 0) + "," + Convert.ToString(HStopflag ? 1 : 0) + ",'" + HRemark + "',getdate())", ref DBUtility.ClsPub.sExeReturnInfo);
                        //修改上级为非末级代码
                        oCN.RunProc("Update Gy_EquipFileType set HEndflag=0 where HItemID=" + HParentID, ref DBUtility.ClsPub.sExeReturnInfo);
                        oCN.Commit();
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "新增成功!";
                        //objJsonResult.data = null;
                        return objJsonResult;
                }
                if (refSav == "Update")
                {
                        oCN.BeginTran();
                        //主表
                        oCN.RunProc("Update Gy_EquipFileType set " +
                            " HNumber='" + HNumber + "'" +
                            ",HName='" + HName + "'" +
                            ",HShortNumber='" +HShortNumber + "'" +
                            ",HHelpCode='" + HHelpCode + "'" +
                            ",HParentID=" + HParentID +
                            ",HStopflag='" + HStopflag + "'" +
                            ",HRemark= '" + HRemark + "' Where HItemID=" + HItemID, ref DBUtility.ClsPub.sExeReturnInfo);
                        //修改子项目代码
                        //oCN.RunProc("exec h_p_Gy_UpdateNumber Gy_RepairCheck,'" + HNumber + ".','" + this.HOldNumber + ".'", ref DBUtility.ClsPub.sExeReturnInfo);
                        //将上级 为非末级
                        oCN.RunProc("Update Gy_EquipFileType set HEndflag=0 where HItemID=" + HParentID, ref DBUtility.ClsPub.sExeReturnInfo);
                        //
                        oCN.Commit();
                        objJsonResult.code = "1";
                        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 = 1;
                return objJsonResult;
            }
            return false;
        }
        #endregion
 
        #region[设备分类编辑时获取表头数据]
        [Route("Gy_EquipType/Gy_EquipTypeCheckDetai")]
        [HttpGet]
        public object Gy_EquipTypeCheckDetai(long HInterID)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from Gy_EquipFileType where HItemID=" + HInterID, "Gy_EquipFileType");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                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
    }
}