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
using FineUIPro;
using iWareCommon.Common.Entity;
using iWareDataCore.BASE.Entity;
using iWareDataCore.BASE.Service;
using iWareDataCore.Check.Entity;
using iWareDataCore.Check.Service;
using iWareWms;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace iWareWms.View.CHECK.Plan
{
    public partial class CreatePlan : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // 删除选中行按钮
                btnDelete.OnClientClick = PlanGrid.GetNoSelectionAlertReference("请至少选择一项!") + GetDeleteScript();
 
                btCreatCode_Click(sender, e);
                //设置时间
                dpBeginTime.SelectedDate = DateTime.Now.AddDays(-10);
                dpEndTime.SelectedDate = DateTime.Now.AddDays(20);
                Query();
            }
        }
 
 
        //重新确认时间
        protected void btnRes_Click(object sender, EventArgs e)
        {
            dpBeginTime.Enabled = true;
            dpEndTime.Enabled = true;
            SearchBtn.Enabled = true;
        }
      
 
        protected void btCreatCode_Click(object sender, EventArgs e)
        {
            tbPlanNo.Text = DateTime.Now.ToFileTime().ToString();
        }
 
 
 
        /// <summary>
        /// 确认时间(同时搜索库存信息)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            dpBeginTime.Enabled = false;
            dpEndTime.Enabled = false;
            SearchBtn.Enabled = false;
            btnAdd.Enabled = true;
            string msg;
            var placematerials = PlaceMaterialViewService.GetInstance().QueryByParam(new QueryParam
            {
                Geqd = new Dictionary<string, object> { { "UpdateTime", dpBeginTime.SelectedDate } },
                Leqd = new Dictionary<string, object> { { "UpdateTime", dpEndTime.SelectedDate } }
            }, out msg);
 
            var res = new List<object>();
 
            placematerials.ForEach(x => res.Add(x));
            PlaceMaterialGrid.DataSource = res;
            PlaceMaterialGrid.DataBind();
 
        }
 
        /// <summary>
        /// 根据物料号,库位号搜索库存信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSerch_Click(object sender, EventArgs e)
        {
            string msg;
            if (dpBeginTime.Enabled == false)
            {
                var placematerials = PlaceMaterialViewService.GetInstance().QueryByParam(new QueryParam
                {
                    Search = new Dictionary<string, object> { { "MaterialCode", tbMaterialCode.Text }, { "PlaceCode", tbPlaceCode.Text } }
                }, out msg);
 
                var res = new List<object>();
 
                placematerials.ForEach(x => res.Add(x));
                PlaceMaterialGrid.DataSource = res;
                PlaceMaterialGrid.DataBind();
            }
            else
            {
                ShowNotify("请先确认时间");
            }
            
        }
 
        
 
        /// <summary>
        /// 批量添加库存信息到右侧计划表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            //取得选中行ID的集合
            List<string> selectedRowIDs = new List<string>(PlaceMaterialGrid.SelectedRowIDArray);
            if (selectedRowIDs.Count == 0)
            {
                Alert.Show("请先选择要添加的库位物料!");
                return;
            }
            var detail = PlaceMaterialGrid.Rows;
 
            var oneRowId = PlaceMaterialGrid.SelectedRow.RowID.ToString();
            var oneDetail = PlaceMaterialGrid.SelectedRow;
            if (selectedRowIDs.Count > 0)
            {
                List<PlaceMaterialViewEntity> placematerial = new List<PlaceMaterialViewEntity>();
                if (selectedRowIDs.Count == 1)
                {
                    if (selectedRowIDs.Contains(oneRowId))
                    {
                        PlaceMaterialViewEntity pmp = new PlaceMaterialViewEntity()
                        {
                            MaterialId = Convert.ToInt32(oneDetail.Values[1].ToString()),
                            PlaceId = Convert.ToInt32(oneDetail.Values[2].ToString()),
                            MaterialCode = oneDetail.Values[3].ToString(),
                            PlaceCode = oneDetail.Values[4].ToString(),
                            TypeName = oneDetail.Values[5].ToString(),
                            PlaceTypeName = oneDetail.Values[6].ToString()
                        };
                        placematerial.Add(pmp);
                    }
                        
                }
                else
                {
                    List<string> rowidList = new List<string>();
                    
                    for (int i = 0; i < selectedRowIDs.Count; i++)
                    {
 
                        var RowId = detail[i].RowID.ToString();
 
                        if (selectedRowIDs.Contains(RowId))
                        {
                            PlaceMaterialViewEntity pmp = new PlaceMaterialViewEntity()
                            {
                                MaterialId = Convert.ToInt32(detail[i].Values[1].ToString()),
                                PlaceId = Convert.ToInt32(detail[i].Values[2].ToString()),
                                MaterialCode = detail[i].Values[3].ToString(),
                                PlaceCode = detail[i].Values[4].ToString(),
                                TypeName = detail[i].Values[5].ToString(),
                                PlaceTypeName = detail[i].Values[6].ToString()
                            };
                            placematerial.Add(pmp);
                        }
                    }
                }
                
                
                var res = new List<object>();
                placematerial.ForEach(x => res.Add(x));
                PlanGrid.DataSource = res;
                PlanGrid.DataBind();
                btnReset.Enabled = true;
                btnSubmit.Enabled = true;
            }
        }
 
 
        /// <summary>
        /// 重置按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnReset_Click(object sender, EventArgs e)
        {
            PlanGrid.DataSource = null;
            PlanGrid.DataBind();
            btCreatCode_Click(null,null);
            dpBeginTime.Enabled = false;
            dpEndTime.Enabled = false;
            SearchBtn.Enabled = false;
            btnSubmit.Enabled = false;
            btnAdd.Enabled = false;
        }
 
        //
        /// <summary>
        /// 生成按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //取得选中行ID的集合
            List<string> selectedRowIDs = new List<string>(PlanGrid.SelectedRowIDArray);
 
            string msg = "";
 
            var detail = PlanGrid.Rows;
            if (selectedRowIDs.Count > 0 && detail.Count>0)
            {
                List<PlanMaterialPlaceEntity> material = new List<PlanMaterialPlaceEntity>();
                        
                for (int i = 0; i < detail.Count; i++)
                {
                    var RowId = detail[i].RowID.ToString();
 
                    if (selectedRowIDs.Contains(RowId))
                    {
                        PlanMaterialPlaceEntity pmp = new PlanMaterialPlaceEntity() 
                        {
                            MaterialId = Convert.ToInt32(detail[i].Values[1].ToString()),
                            PlaceId = Convert.ToInt32(detail[i].Values[2].ToString()),
                            Quantity = 1
                        };
                        material.Add(pmp);
                    }
                }
 
                PlanService.GetInstance().CreateCheckPlanAndDetial(
                                new PlanEntity
                                {
                                    PlanNo = tbPlanNo.Text,
                                    BeginTime = (DateTime)dpBeginTime.SelectedDate,
                                    EndTime = (DateTime)dpEndTime.SelectedDate,
                                    UpdateTime = DateTime.Now,
                                    TypeName = "",
                                    Status = 0,
                                    Remark = "",
                                    PlanMaterialPlace = material
                                }, out msg);
                Alert.ShowInTop("生成盘点计划成功!");
                btnReset_Click(null,null);
            }else
            {
                Alert.ShowInTop("还未选择物料");
                return;
            }
            
            
        }
 
        /// <summary>
        /// 删除选中行的脚本
        /// </summary>
        /// <returns></returns>
        private string GetDeleteScript()
        {
            return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, PlanGrid.GetDeleteSelectedRowsReference(), String.Empty);
        }
 
        
 
       
    }
}