22
schangxiang@126.com
2025-08-23 69998137982a3476c5967f2af1a497dd9aa3f11c
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
using FineUIPro;
using iWareCommon.Common.Entity;
using iWareDataCore.BASE.Entity;
using iWareDataCore.BASE.EnumType;
using iWareDataCore.BASE.Service;
using iWareDataCore.TASK.Entity;
using iWareDataCore.TASK.Service;
using iWareExcel.EXCEL.Service;
using iWareWms;
using iWareWms.Code.Excel.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
 
namespace iWareWms.View.InOut
{
    public partial class InOutList : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //dpBeginTime.Text = DateTime.Now.AddDays(-10).ToString();
            //dpEndTime.Text = DateTime.Now.AddDays(20).ToString();
            if (!IsPostBack)
            {
                BtnAddInOutListDetail.OnClientClick = Window1.GetShowReference("~/View/InOut/AddInOutDetail.aspx", "新增物料");
            }
        }
 
        protected override Grid GetGrid()
        {
            return ListNoGrid;
        }
 
        /// <summary>
        /// 出入库类型,枚举前台显示
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        protected string GetStatus(object status)
        {
            return ((EInOutListStatus)Convert.ToInt32(status)).ToString();
        }
 
        /// <summary>
        /// 查询未生成的出入库单号,状态 “0”或“1”(0,未生成(无物料),1,已生成(已添加物料))
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSerch_Click(object sender, EventArgs e)
        {
            if (dpBeginTime.SelectedDate == null)
            {
                dpBeginTime.SelectedDate = DateTime.Now.AddDays(-10);
            }
            if (dpEndTime.SelectedDate == null)
            {
                dpEndTime.SelectedDate = DateTime.Now.AddDays(20);
            }
            
            string msg;
            DateTime endTime = (DateTime)dpEndTime.SelectedDate;
            DateTime beginTime = (DateTime)dpBeginTime.SelectedDate;
 
            var plans = InOutListService.GetInstance().QueryByParam(new QueryParam
            {
                Leqd = new Dictionary<string, object> { { "CreateTime", endTime } },
                Geqd = new Dictionary<string, object> { { "CreateTime", beginTime } },
                Search = new Dictionary<string, object> { { "ListNo", tbListNo.Text } },
                Lt = new Dictionary<string, object> { { "Status", 1 } }
            }, out msg);
 
            var res = new List<object>();
 
            plans.ForEach(x => res.Add(x));
            ListNoGrid.DataSource = res;
            ListNoGrid.DataBind();
 
        }
 
        /// <summary>
        /// 保存计划单,状态改为已经生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            
            List<PlaceViewEntity> emptyPlace = new List<PlaceViewEntity>();
            List<PlaceViewEntity> place = PlaceService.GetInstance().GetEmptyAndInOutGate();
            emptyPlace = place.FindAll(x => x.PlaceTypeName == EPlaceType.普通库位.ToString());
            string msg;
            string lno = lbListNo.Text;
            var inoutdetails = InOutListDetailViewService.GetInstance().GetListDetailByListNo(lno, out msg);
            if (inoutdetails==null)
            {
                Alert.ShowInTop("物料明细不能为空!");
                return;
            }
            var placeMaterial = PlaceMaterialViewService.GetInstance().QueryByParam(new QueryParam { }, out msg);
            List<MainTaskEntity> mtasklst = new List<MainTaskEntity>();
            int islots = int.Parse(ddlLots.SelectedValue);
            for (int i = 0; i < inoutdetails.Count; i++)
            {
                MainTaskEntity mtask = new MainTaskEntity()
                {
                    TaskNo = DateTime.Now.ToFileTime().ToString(),
                    MaterialCode = inoutdetails[i].MaterialCode,
                    SysCode = "1",
                    SendTime = DateTime.Now,
                    ProcessCardNumber = "",
                    Quantity = 1,
                    Status = 0,
                    DecompositionTime = DateTime.Now,
                    WipStatus = 0,
                    DecompositionTimes = 0,
                    PackageNo = "",
                    IsLots = islots,
                    Priority = 0,
                };
                if (inoutdetails[i].TypeName == "入库")
                {
                    mtask.TaskType = 0;
                    mtask.SourcePlace = "100101";
                    mtask.ToPlace = emptyPlace[i].Code; 
                }
                else
                {
                    var palcecode = placeMaterial.FirstOrDefault(x => x.MaterialCode == inoutdetails[i].MaterialCode);
                    mtask.TaskType = 1;
                    mtask.SourcePlace = palcecode.PlaceCode;
                    mtask.ToPlace = "100202";
                }
                mtasklst.Add(mtask);
            }
 
            MainTaskService.GetInstance().SaveMainTaskList(mtasklst, out msg);
           if (string.IsNullOrEmpty(msg))
           {
               string listno = lbListNo.Text;
               int count = InOutListDetailViewService.GetInstance().UpdateByListNo(listno, islots);
               if (count > 0)
               {
                   Alert.ShowInTop("出入库单生成成功!");
               }
               ListNoMaterialGrid.DataSource = null;
               ListNoMaterialGrid.DataBind();
               ListNoGrid.DataSource = null;
               ListNoGrid.DataBind();
           }
           else 
           {
               Alert.ShowInTop("出入库单生成失败!");
           }
        }
 
 
        /// <summary>
        /// 绑定查看物料
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void GridRowCommand(object sender, GridCommandEventArgs e)
        {
            btnSubmit.Enabled = true;
 
 
            var grid = ListNoGrid;
 
            if (e.CommandName == "Confirm")
            {
                var lno = grid.Rows[e.RowIndex].DataKeys[2].ToString();
                string msg;
                var inoutdetails = InOutListDetailViewService.GetInstance().GetListDetailByListNo(lno, out msg);
                //if (inoutdetails.Count <= 0)
                //{
                //    Alert.ShowInTop("此单号还未添加物料。");
                //    return;
                //}
                List<string> listno = new List<string>();
 
                inoutdetails.ForEach(x => listno.Add(x.ListNo));
                if (listno.Count == 0)
                    return;
                lbListNo.Text = listno[0];
 
                ListNoMaterialGrid.DataSource = inoutdetails;
                ListNoMaterialGrid.DataBind();
            }
            //删除出入库单号
            if (e.CommandName == "Delete")
            {
                int id = Convert.ToInt32(grid.Rows[e.RowIndex].DataKeys[1].ToString());
                string msg;
                int count = InOutListService.GetInstance().Delete(id, out msg);
                if (count >= 0)
                {
                    Alert.ShowInTop("删除成功!");
                    btnSerch_Click(null,null);
                    ListNoMaterialGrid.DataSource = null;
                    ListNoMaterialGrid.DataBind();
                }
            }
        }
 
        /// <summary>
        /// 删除物料单按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDeleteInOut_Click(object sender, EventArgs e)
        {
            List<object> selectedRowIDs = new List<object>(ListNoGrid.SelectedRowIDArray);
            int[] selections = ListNoGrid.SelectedRowIndexArray;
            var detail = ListNoGrid.Rows;
 
            int selectRowId = -1;
 
            for (int i = 0; i < selections.Length; i++)
            {
                string RowId = detail[selections[i]].RowID.ToString();
                int id = Convert.ToInt32(detail[selections[i]].Values[1].ToString());
 
                if (selectedRowIDs.Contains(RowId))
                {
                    selectRowId = id;
                    break;
                }
            }
            if (selectRowId>-1)
            {
                string msg;
                int count = InOutListService.GetInstance().DeleteInOut(selectRowId, out msg);
                if (count >= 0)
                {
                    Alert.ShowInTop("删除成功!");
                    btnSerch_Click(null, null);
                    ListNoMaterialGrid.DataSource = null;
                    ListNoMaterialGrid.DataBind();
                }
                else
                    Alert.ShowInTop("删除失败!");
            }
            else
                Alert.ShowInTop("请选择单据!");
        }
 
        /// <summary>
        /// 物料明细删除按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            //取得选中行ID的集合
            List<object> selectedRowIDs = new List<object>(ListNoMaterialGrid.SelectedRowIDArray);
 
            int[] selections = ListNoMaterialGrid.SelectedRowIndexArray;
 
            string msg = "";
 
            var detail = ListNoMaterialGrid.Rows;
            List<int> idlist = new List<int>();
            for (int i = 0; i < selections.Length; i++)
            {
                string RowId = detail[selections[i]].RowID.ToString();
                int id = Convert.ToInt32(detail[selections[i]].Values[1].ToString());
 
                if (selectedRowIDs.Contains(RowId))
                {
                    idlist.Add(id);
                }
            }
            int count = InOutListDetailService.GetInstance().Delete(idlist, out msg);
            if (count >= 0)
            {
                Alert.ShowInTop("删除成功!");
                var inoutdetails = InOutListDetailViewService.GetInstance().GetListDetailByListNo(lbListNo.Text, out msg);
                List<string> listno = new List<string>();
                inoutdetails.ForEach(x => listno.Add(x.ListNo));
                ListNoMaterialGrid.DataSource = inoutdetails;
                ListNoMaterialGrid.DataBind();
            }
        }
 
 
        protected override void GetPath(object userName)
        {
            string msg;
 
            string listno = tbListNo.Text;
 
            var placematerial = InOutListDetailViewService.GetInstance().QueryByParam(new QueryParam
            {
                Filter = new Dictionary<string, object> { { "ListNo", listno } }
            }, out msg);
            var inoutdetails = new List<object>();
            placematerial.ForEach(x => inoutdetails.Add(x));
 
            var workBooks = WorkBookService.GetInstance().QueryByParam(new QueryParam { Filter = new Dictionary<string, object> { { "Name", "出入库单管理" } } }, out msg);
 
            var path = ExcelService.GetInstance().ToExcelByEPPlus(workBooks[0], new Dictionary<string, List<object>> { { "出入库单管理", inoutdetails } }, out msg);
 
            Session["ExcelPath"] = path;
        }
        protected override Window GetWindow()
        {
            if (string.IsNullOrEmpty(lbListNo.Text))
            {
                return null;
            }
            return Window2;
        }
 
        protected override FineUIPro.Timer GetTimer()
        {
            return timer1;
        }
    }
}