yangle
2025-04-15 9382e8326714a25e04661150d0f11ad47ca0fcac
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
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.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers.项目管理.基础建模
{
    #region 客户信息列表 新增、查询、删除
    public class PM_CustomerProInfoBillController : ApiController
    {
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        public DAL.ClsCustomerProInfoBill BillOld = new DAL.ClsCustomerProInfoBill();
        public DAL.ClsCustomerProInfoBill BillNew0 = new DAL.ClsCustomerProInfoBill();
 
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        /// <summary>
        /// 获取客户信息列表
        /// </summary>
        /// <param name="sWhere"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        [Route("PM_ProInfo/PM_ProInfolist")]
        [HttpGet]
        public object GetProInfoBillList(string sWhere, string user)
        {
            json res = new json();
            try
            {
                //权限查看
                if(!DBUtility.ClsPub.Security_Log("PM_CustomerProInfoBill_Query", 1, false, user))
                {
                    res.code = "0";
                    res.count = 0;
                    res.Message = "无查看权限!";
                    res.data = null;
                    return res;
                }
                DataSet ds = new DataSet();
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_PM_CustomerProInfoBill order by 单据号 desc", "h_v_PM_CustomerProInfoBill");
                }
                else
                {
                    string sql1 = "select * from h_v_PM_CustomerProInfoBill where 1 = 1 ";
                    string sql = sql1 + sWhere + " order by 单据号 desc";
                    ds = oCN.RunProcReturn(sql, "h_v_PM_CustomerProInfoBill");
                }
                List<object> columnNameList = new List<object>();
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
 
                res.code = "1";
                res.count = 1;
                res.Message = "Sucess!";
                res.data = ds.Tables[0];
                res.list = columnNameList;
                return res;
            }
            catch(Exception e)
            {
                res.code = "0";
                res.count = 0;
                res.Message = "Exception!" + e.ToString();
                res.data = null;
                return res;
            }
        }
 
        /// <summary>
        /// 保存或更新
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        [Route("PM_ProInfo/SavePM_ProInfoBill")]
        [HttpPost]
        public object SavePM_ProInfoBill([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();                             //子表1数据
            string refSav = sArray[2].ToString();                           //操作方式
            string msg4 = sArray[3].ToString();                             //用户
 
            DBUtility.ClsPub.CurUserName = msg4;
 
            string UserName = "";
            string s = "";
            ListModels oListModels = new ListModels();
            try
            {
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log_second("PM_CustomerProInfoBill_Edit", 1, false, msg4))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                DAL.ClsCustomerProInfoBill oBill = new DAL.ClsCustomerProInfoBill();
                List<Model.ClsPM_CustomerProInfoBillMain> lsmain = new List<Model.ClsPM_CustomerProInfoBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_ClsPM_CustomerProInfoBillMain(msg2);
                foreach (Model.ClsPM_CustomerProInfoBillMain oItem in lsmain)
                {
                    if (refSav == "Add")
                    {
                        //单据号是否重复
                        if (BillNew0.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, BillOld.omodel.HInterID))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据号重复!不允许保存!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                    }
                    if (refSav == "Update")
                    {
                        if (BillOld.ShowBill(oItem.HInterID, ref s) == false)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据有误!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        //判断是否可编辑
                        if (BillOld.omodel.HChecker != "" && BillOld.omodel.HChecker != null)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据已经被审核,不允许修改!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        if (BillOld.omodel.HBillStatus > 1)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "此单据处于不可编辑状态,不允许修改!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                        if (!DBUtility.Xt_BaseBillFun.Fun_AllowEditBill(BillOld, ref s))
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = s + ",不允许修改";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
 
                        string sql = "select count(*) PM_CustomerProInfoBillCount from PM_CustomerProInfoBillMain  where HMainSourceInterID = " + BillOld.omodel.HInterID;
                        ds = oCN.RunProcReturn(sql, "PM_CustomerProInfoBillMain");
                        if (ds != null && Int64.Parse(ds.Tables[0].Rows[0]["PM_CustomerProInfoBillCount"].ToString()) > 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "保存失败,单据存在下游单据[特批申请单]!";
                            objJsonResult.data = 1;
                            return objJsonResult;
                        }
                    }
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "4764";
                    //oItem.HBillSubType = "1401";
 
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
 
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oBill.omodel = oItem;
                }
                //表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                //msg2 = msg2.Replace("'", "’");
                //List<Model.ClsPM_CustomerProInfoBillSub> ls = new List<Model.ClsPM_CustomerProInfoBillSub>();
                //ls = oListModels.getObjectByJson_ClsPM_CustomerProInfoBillSub(msg3);
                //int i = 0;
                //foreach (Model.ClsPM_CustomerProInfoBillSub oItemSub in ls)
                //{
                //    i++;
                //    oItemSub.HEntryID = i;
 
                    //oItemSub.HCloseMan = "";       //行关闭
                    //oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    //oItemSub.HCloseType = false;   //关闭类型
                    //oItemSub.HRemark = "";         //备注
 
                    //oItemSub.HSourceInterID = 0;     // 源单主内码
                    //oItemSub.HSourceEntryID = 0;   //源单子内码
                    //oItemSub.HSourceBillNo = "";  //源单单号
                    //oItemSub.HSourceBillType = ""; //源单类型
                    //oItemSub.HRelationQty = 0;     //关联数量
                    //oItemSub.HRelationMoney = 0;   //关联金额 
 
                //    if (oItemSub.HItemSubID != 0)
                //    {
                //        oBill.DetailColl.Add(oItemSub);
                //    }
                //}
 
                //进行判断和控制
                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;
                }
 
                //保存
                //保存完毕后处理
                bool bResult;
                if (refSav == "Add")
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else if (refSav == "Update")
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = false;
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
 
 
        /// <summary>
        /// 客户项目表头信息
        /// </summary>
        /// <param name="sMsg"></param>
        /// <returns></returns>
        [Route("PM_ProInfo/GetMAXNum")]
        [HttpGet]
        public object GetMAXNum(string HBillType)
        {
            try
            {
                string HBillNo = "";
                Int64 HInterID = 0;//显示的字段
                HInterID = DBUtility.ClsPub.CreateBillID(HBillType, ref DBUtility.ClsPub.sExeReturnInfo);
                HBillNo = DBUtility.ClsPub.CreateBillCode(HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                //----------创建虚表------------------------
                DataTable dt_Main = new DataTable("Json");
                dt_Main.Columns.Add("HBillNo", typeof(string));
                dt_Main.Columns.Add("HInterID", typeof(int));
                //---------创建新行------------------------
                DataRow dr_main = dt_Main.NewRow();//创建新行 
                dt_Main.Rows.Add(dr_main);//将新行加入到表中
                dr_main["HBillNo"] = DBUtility.ClsPub.isStrNull(HBillNo);
                dr_main["HInterID"] = DBUtility.ClsPub.isLong(HInterID);
 
                if (HBillNo == null || HInterID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "获取失败";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "获取成功";
                    objJsonResult.data = dt_Main;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "获取失败" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 客户项目信息 加载编辑页面
        [Route("PM_ProInfo/loadPM_CustomerProInfoBill_Edit")]
        [HttpGet]
        public object loadPM_CustomerProInfoBill_Edit(long HInterID)
        {
            try
            {
 
                ds = oCN.RunProcReturn("select * from h_v_PM_CustomerProInfoBill where hmainid =" + HInterID , "h_v_PM_CustomerProInfoBill");
                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
    }
}