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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CY.BLL;
using CY.Model;
using CY.Infrastructure.Query;
using CY.Infrastructure.Common;
using CY.BLL.Sys;
using System.Data;
using CY.BLL.OA;
using CY.BLL.EC;
 
namespace CY.WebForm.Pages.business
{
    //吴辉
    //合版施工单列表
    public partial class AgMergerOrderList : BasePage
    {
        EC_MergerSingleBLL bll_EC_MergerSingleBLL = null;
        OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null;
        EC_OrderBasicBLL _eC_OrderBasicBLL   = null;
        OA_OutOfStorageBLL _OA_OutOfStorageBLL = null;
        OA_InventoryBLL _OA_InventoryBLL = null;
 
 
        //初始化
        public AgMergerOrderList()
        {
            bll_EC_MergerSingleBLL = new EC_MergerSingleBLL();
            bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL();
            _eC_OrderBasicBLL = new EC_OrderBasicBLL();
            _OA_OutOfStorageBLL = new OA_OutOfStorageBLL();
            _OA_InventoryBLL = new OA_InventoryBLL();
        }
 
        //页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            UCPager1.AspNetPager.PageChanged += AspNetPager1_PageChanged;
            if (!IsPostBack)
            {
                Page_Load_Default();
                BindOutFirm();
                BindList();
            }
            if (Request["delete"] != null)
            {
                EC_MergerSingle model = bll_EC_MergerSingleBLL.GetModelByKeyid(Request["delete"].ToInt32());
                if (model != null && model.Keyid != null)
                {
                    //退回库存
                    var oA_OutOfStorages = _OA_OutOfStorageBLL.getModelListByRemark(model.Member_id, "<span class=''a_under'' title=''点击查看施工单详情'' onclick=\"ViewModel_Merger(''" + model.Keyid + "'')\">合版:" + model.PMS_OrderNum + "</span>").ToList();
                    if (oA_OutOfStorages != null && oA_OutOfStorages.Count > 0)
                    {
                        foreach (var outOfStorage in oA_OutOfStorages)
                        {
                            if (outOfStorage.InfoType == "确认出库")
                            {
                                _OA_OutOfStorageBLL.DeleteModel(outOfStorage);
                            }
                            else if (outOfStorage.InfoType == "出库")
                            {
 
 
                                OA_Inventory Inventory = new OA_Inventory();
                                Inventory.BrandId = outOfStorage.BrandId;
                                Inventory.FirmId = outOfStorage.FirmId;
                                Inventory.GoodsId = outOfStorage.GoodsId;
                                Inventory.LastUpdateTime = DateTime.Now;
                                Inventory.WarehouseId = outOfStorage.WarehouseId;
                                Inventory.SpecificationId = outOfStorage.SpecificationId;
                                Inventory.PaperWeightId = outOfStorage.PaperWeightId;
 
                                var m_OA_Inventory = _OA_InventoryBLL.IfHasModel(Inventory);
                                if (m_OA_Inventory != null)//如果所选货位存在此产品
                                {
 
                                    m_OA_Inventory.InventoryCount = m_OA_Inventory.InventoryCount + outOfStorage.Quantity;
                                    bool isSuccess = _OA_InventoryBLL.UpdateModel(m_OA_Inventory);
                                }
                                _OA_OutOfStorageBLL.DeleteModel(outOfStorage);
                            }
                        }
                    }
                    bll_EC_MergerSingleBLL.DeleteModel(model);
                    JavaScript.MessageBox("删除成功", this);
                    Response.Redirect("/Pages/business/AgMergerOrderList.aspx");
                }
                else
                {
                    JavaScript.MessageBox("删除失败", this);
                }
            }
            if (Request["chedan"] != null)
            {
                EC_MergerSingle model = bll_EC_MergerSingleBLL.GetModelByKeyid(Request["chedan"].ToInt32());
                if (model != null && model.Keyid != null)
                {
                  var  strOrderIdTemp = model.PMS_OldId.ToString2();
                    var strOrderId = strOrderIdTemp.Replace("<br/>", ",");
                    var orderId = strOrderId.Trim(',').Split(',');
                    foreach (var item in orderId)
                    {
                        EC_OrderBasic _eC_OrderBasic = _eC_OrderBasicBLL.SelectModelById(item.ToInt32().Value);
                        if (null == _eC_OrderBasic)
                        {
 
                        }
                        else
                        {
                            //修改订单状态
                            List<EC_OrderOperate> oprates = new List<EC_OrderOperate>();
                            oprates.Add(new EC_OrderOperate()
                            {
                                OperateType = 1,
                                OrderId = _eC_OrderBasic.Keyid,
                                Operator = CurrentUser.ShortName,
                                Remark = ""
                            });
                            _eC_OrderBasicBLL.UpdateOrderState(oprates[0]);
                            //修改订单数量
                            _eC_OrderBasicBLL.UpSurplusPrintNum(_eC_OrderBasic.Keyid, _eC_OrderBasic.OrderExtend.PrintNum, CurrentUser.ShortName);
 
                            
 
                        }
                    }
 
                    //退回库存
                    var oA_OutOfStorages = _OA_OutOfStorageBLL.getModelListByRemark(model.Member_id, "<span class=''a_under'' title=''点击查看施工单详情'' onclick=\"ViewModel_Merger(''" + model.Keyid + "'')\">合版:" + model.PMS_OrderNum + "</span>").ToList();
                    if (oA_OutOfStorages != null && oA_OutOfStorages.Count > 0)
                    {
                        foreach (var outOfStorage in oA_OutOfStorages)
                        {
                            if (outOfStorage.InfoType == "确认出库")
                            {
                                _OA_OutOfStorageBLL.DeleteModel(outOfStorage);
                            }
                            else if (outOfStorage.InfoType == "出库")
                            {
 
 
                                OA_Inventory Inventory = new OA_Inventory();
                                Inventory.BrandId = outOfStorage.BrandId;
                                Inventory.FirmId = outOfStorage.FirmId;
                                Inventory.GoodsId = outOfStorage.GoodsId;
                                Inventory.LastUpdateTime = DateTime.Now;
                                Inventory.WarehouseId = outOfStorage.WarehouseId;
                                Inventory.SpecificationId = outOfStorage.SpecificationId;
                                Inventory.PaperWeightId = outOfStorage.PaperWeightId;
 
                                var m_OA_Inventory = _OA_InventoryBLL.IfHasModel(Inventory);
                                if (m_OA_Inventory != null)//如果所选货位存在此产品
                                {
 
                                    m_OA_Inventory.InventoryCount = m_OA_Inventory.InventoryCount + outOfStorage.Quantity;
                                    bool isSuccess = _OA_InventoryBLL.UpdateModel(m_OA_Inventory);
                                }
                                _OA_OutOfStorageBLL.DeleteModel(outOfStorage);
                            }
                        }
                    }
 
                    bll_EC_MergerSingleBLL.DeleteModel(model);
                    JavaScript.MessageBox("撤单成功", this);
                    Response.Redirect("/Pages/business/AgMergerOrderList.aspx");
                }
                else
                {
                    JavaScript.MessageBox("撤单失败", this);
                }
            }
            
        }
 
        //绑定外协厂商
        public void BindOutFirm()
        {
            Pagination pa = new Pagination();
            pa.PageSize = 500;
            pa.PageIndex = 1;
            this.txtPMS_Printers.DataSource = bll_OA_CorporateClientsBLL.SelectModelPage(pa, CurrentUser.MemberId, "");
            this.txtPMS_Printers.DataTextField = "OutVendorName";
            this.txtPMS_Printers.DataValueField = "OutVendorName";
            this.txtPMS_Printers.DataBind();
            this.txtPMS_Printers.Items.Insert(0, new ListItem("全部", ""));
        }
 
        //初始化
        private void Page_Load_Default()
        {
            Sys_DictionaryBLL _sys_DictionaryBLL = new Sys_DictionaryBLL();//字典业务逻辑操作类对象
            this.selPayStates.DataSource = _sys_DictionaryBLL.GetDataByType("EC_订单支付状态");
            this.selPayStates.DataTextField = "Name";
            this.selPayStates.DataValueField = "MeanValue";
            this.selPayStates.DataBind();
            this.selPayStates.Items.Insert(0, new ListItem("全部", ""));
 
            this.selPrintStates.DataSource = _sys_DictionaryBLL.GetDataByType("打印状态");
            this.selPrintStates.DataTextField = "Name";
            this.selPrintStates.DataValueField = "MeanValue";
            this.selPrintStates.DataBind();
            this.selPrintStates.Items.Insert(0, new ListItem("全部", ""));
        }
 
        //绑定数据
        private void BindList()
        {
 
            DateTime? beginTime = null;
            DateTime? endTime = null; 
            Pagination pa = new Pagination();
            pa.PageSize = UCPager1.AspNetPager.PageSize;
            pa.PageIndex = UCPager1.AspNetPager.CurrentPageIndex;
 
            this.RepClientList.DataSource = bll_EC_MergerSingleBLL.SelectModelPage(pa, CurrentUser.MemberId, this.txtPrintName.Value, this.txtCustormerName.Value, this.txtPSO_OrderNum.Value, string.IsNullOrEmpty(this.txtBeginDate.Value) ? beginTime : Convert.ToDateTime(this.txtBeginDate.Value), string.IsNullOrEmpty(this.txtEndDate.Value) ? endTime : MyConvert.GetDateTime(this.txtEndDate.Value), this.txtPMS_Printers.Value, this.txtPO_OrderNum.Value, this.selPayStates.Value, this.selPrintStates.Value);
            this.RepClientList.DataBind();
            UCPager1.AspNetPager.RecordCount = pa.RecordCount;
        }
 
        //分页事件
        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindList();
        }
 
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            BindList();
        }
      
    }
}