chengsc
2024-07-23 f575652587d4160ab42e75acb2bc26b4f60fb7c3
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
using BLL;
using Common;
using Model;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using wms;
using Json;
using Lib;
using System.Collections;
using System.Data;
using Commom.BarCodePrint;
 
namespace wms.Areas.BasicInfo.Controllers
{
    public class TrayAjaxController : AjaxPage
    {
        // GET: BasicInfo/TrayAjax
 
        /// <summary>
        /// 查询托盘
        /// </summary>
        /// <returns></returns>
        public ActionResult GetTrayList()
        {
            try
            {
                var dd = Request["ajaxdata"];
                var trayModels = new JavaScriptSerializer().Deserialize<TrayList>(dd);
                if (trayModels != null)
                {
                    // 实例化分页信息
                    PageInfo pageInfo = new PageInfo()
                    {
                        PageIndex = trayModels.pageIndex,
                        PageSize = trayModels.pageSize
                    };
 
                    // 数据库交互,获取托盘信息and分页信息。
                    DALTray provider = new DALTray();
                    List<Tray> entity = provider.GetList(trayModels, ref pageInfo).ToList();
 
                    // Data =》json
                    string json = JsonHelper.IListToJson<Tray>(entity, "List");
                    string pjson = ConvertJson.Serializer(pageInfo);
 
                    // controller => view
                    ReturnJson.AddProperty("Result", new JsonObject(json));
                    ReturnJson.AddProperty("PageInfo", new JsonObject(pjson));
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "加载托盘信息成功!");
                    return Content(this.ReturnJson.ToString());
                }
 
                return Content(null);
            }
            catch (System.Exception)
            {
                return Content(null);
            }
        }
 
        /// <summary>
        /// 新增编辑托盘信息
        /// </summary>
        /// <returns></returns>
        public ActionResult AddEdit() 
        {
            try
            {
                var dd = Request["ajaxdata"];
                var trayModels = new JavaScriptSerializer().Deserialize<Tray>(dd);
                if (trayModels != null) 
                {
                    // 数据库交互
                    DALTray provider = new DALTray();
                    if (provider.AddEdit(trayModels))
                    {
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "保存成功!");
                    }
                    else 
                    {
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "保存失败!");
                    }
                }
 
                return Content(this.ReturnJson.ToString());
            }
            catch (System.Exception)
            {
                return Content(null);
            }
        }
 
        /// <summary>
        /// 删除托盘
        /// </summary>
        /// <returns></returns>
        public ActionResult Delete() 
        {
            try
            {
                string dd = Request["list"];
                ArrayList models = new JavaScriptSerializer().Deserialize<ArrayList>(dd);
                string[] list = (string[])models.ToArray(typeof(string));
 
                if (models != null)
                {
                    // 数据库交互
                    DALTray provider = new DALTray();
                    if (provider.Delete(list))
                    {
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "删除成功!");
                    }
                    else
                    {
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "删除失败!");
                    }
                }
 
                return Content(this.ReturnJson.ToString());
            }
            catch (System.Exception)
            {
                return Content(null);
            }
        }
 
        /// <summary>
        /// 打印托盘条形码
        /// </summary>
        /// <returns></returns>
        public ActionResult PrintBarCode()
        {
            ReturnJson.AddProperty("SubCode", 0);
            ReturnJson.AddProperty("SubMessage", "");
 
            try
            {
                var dd = Request["list"];
                ArrayList models = new JavaScriptSerializer().Deserialize<ArrayList>(dd);
                string[] list = (string[])models.ToArray(typeof(string));
 
                if (models != null)
                {
                    string palno = list[0];
 
                    DALTray provider = new DALTray();
                    DataTable trayDt = provider.GetTrayPrint("", palno);
                    string StorageName = trayDt.Rows[0]["StorageName"].ToString();
                    string addre = trayDt.Rows[0]["Addre"].ToString();
 
                    TSC1.TSCPrint(StorageName + "-" + addre, palno);
 
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "条码打印完成!");
                }
 
                return Content(this.ReturnJson.ToString());
            }
            catch (System.Exception ex)
            {
                ReturnJson.AddProperty("Code", -1);
                ReturnJson.AddProperty("Message", "条码打印失败!  " + ex.Message);
                return Content(this.ReturnJson.ToString());
            }
        }
    }
}