username@email.com
2026-03-05 d1b1d6703fda926f5b80682d64c26833338a1082
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
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 CY.BLL.OA;
using CY.SQLDAL;
using System.Data.SqlClient;
 
namespace CY.WebForm.Pages.business
{
    //吴辉
    //合作客户管理
    public partial class CorporateClientsList : BasePage
    {
        OA_CorporateClientsBLL bll_OA_CorporateClientsBLL = null;
        Sys_DictionaryBLL _Sys_DictionaryBLL = null;
        OA_StaffBLL bll_OA_StaffBLL = null;
        OA_CustomerApplyBLL bll_OA_CustomerApplyBLL = null;
        EC_MemberBasicBLL bll_EC_MemberBasicBLL = null;
        Sys_CitySiteBLL bll_Sys_CitySiteBLL = null;
        //增加订单查询
        EC_OrderBasicDAL bll_eC_OrderBasicDAL = null;
        //初始化
        public CorporateClientsList()
        {
            _Sys_DictionaryBLL = new Sys_DictionaryBLL();
            bll_OA_CorporateClientsBLL = new OA_CorporateClientsBLL();
            bll_OA_StaffBLL = new OA_StaffBLL();
            bll_OA_CustomerApplyBLL = new OA_CustomerApplyBLL();
            bll_EC_MemberBasicBLL = new EC_MemberBasicBLL();
            bll_Sys_CitySiteBLL = new Sys_CitySiteBLL();
            bll_eC_OrderBasicDAL = new EC_OrderBasicDAL();
        }
 
        //页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            UCPager1.AspNetPager.PageChanged += AspNetPager1_PageChanged;
            if (!IsPostBack)
            {
                BindProvince();
                InitialSelectData();
                BindList();
                //InitialSelectData();
            }
           
 
            if (!string.IsNullOrEmpty(Request["delete"]))
            {
                OA_CorporateClients model = bll_OA_CorporateClientsBLL.GetModel(Request["delete"].ToGuid2());
                if (model != null && model.Keyid != null)
                {
                    if (bll_OA_CorporateClientsBLL.DeleteModel(model))
                        Response.Redirect("/Pages/business/CorporateClientsList.aspx");
                    else
                        JavaScript.MessageBox("删除失败", this);
                }
                else
                    JavaScript.MessageBox("删除失败", this);
            }
 
        }
 
        //加载查询条件
        protected void InitialSelectData()
        {
            this.selSourcesInfoId.DataSource = _Sys_DictionaryBLL.GetDataByType("客户来源");
            this.selSourcesInfoId.DataBind();
            this.selSourcesInfoId.Items.Insert(0, new ListItem("全部", ""));
 
            this.selCustomerIndustriesId.DataSource = _Sys_DictionaryBLL.GetDataByType("客户所属行业");
            this.selCustomerIndustriesId.DataBind();
            this.selCustomerIndustriesId.Items.Insert(0, new ListItem("全部", ""));
 
            this.selCustomerTypeId.DataSource = _Sys_DictionaryBLL.GetDataByType("客户类型");
            this.selCustomerTypeId.DataBind();
            this.selCustomerTypeId.Items.Insert(0, new ListItem("全部", ""));
 
            this.selDegreeImportanId.DataSource = _Sys_DictionaryBLL.GetDataByType("客户重要程度");
            this.selDegreeImportanId.DataBind();
            this.selDegreeImportanId.Items.Insert(0, new ListItem("全部", ""));
 
            this.selTurnoverIntentionId.DataSource = _Sys_DictionaryBLL.GetDataByType("客户信誉");
            this.selTurnoverIntentionId.DataBind();
            this.selTurnoverIntentionId.Items.Insert(0, new ListItem("全部", ""));
 
            //业务经理  
            this.selBusinessManagerId.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, true, false);
            this.selBusinessManagerId.DataTextField = "Name";
            this.selBusinessManagerId.DataValueField = "Keyid";
            this.selBusinessManagerId.DataBind();
            this.selBusinessManagerId.Items.Insert(0, new ListItem("全部", ""));
 
            //客户经理
            this.selAccountManagerId.DataSource = bll_OA_StaffBLL.SelectListByFirmId(CurrentUser.MemberId, false, true);
            this.selAccountManagerId.DataTextField = "Name";
            this.selAccountManagerId.DataValueField = "Keyid";
            this.selAccountManagerId.DataBind();
            this.selAccountManagerId.Items.Insert(0, new ListItem("全部", ""));
 
            //完结状态
            this.selShifouwanjie.DataSource  = _Sys_DictionaryBLL.GetDataByType("客户完结状态").OrderByDescending(x => x.MeanValue);
            this.selShifouwanjie.DataTextField = "Name";
            this.selShifouwanjie.DataValueField = "MeanValue";
           
            this.selShifouwanjie.DataBind();
            this.selShifouwanjie.Items.Insert(0, new ListItem("全部", ""));
            this.selShifouwanjie.SelectedIndex=1;
 
 
        }
 
        //绑定列表
        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_OA_CorporateClientsBLL.GetModelPageList(pa,
                CurrentUser.MemberId,
                this.txtquery_userName.Value,
                string.IsNullOrEmpty(this.txtRegTimeStart.Value) ? beginTime : Convert.ToDateTime(this.txtRegTimeStart.Value),
                string.IsNullOrEmpty(this.txtRegTimeEnd.Value) ? endTime : Convert.ToDateTime(this.txtRegTimeEnd.Value),
                this.selAccountManagerId.Value,
                this.selBusinessManagerId.Value,
                this.selCustomerIndustriesId.Value,
                this.selCustomerTypeId.Value,
                this.selDegreeImportanId.Value,
                this.selLastOrderTime.Value,
                this.selOrderCount.Value,
                this.selOrderMoney.Value,
                this.selSourcesInfoId.Value,
                this.selTurnoverIntentionId.Value,
                this.txtOrderCount.Value,
                this.txtOrderMoney.Value,
                this.txtUserNum.Value,
                this.txtLastOrderTime.Value,
                this.selectProvince.SelectedItem.Text.Replace("全部", ""), 
                this.selectCity.SelectedItem.Text.Replace("全部", ""), 
                this.selectCounty.SelectedItem.Text.Replace("全部", ""),
                (CurrentUser.TrueType == "员工"),
                CurrentUser.TrueMemberId,
                CurrentUser.StaffId,
                this.selShifouwanjie.Value,null,null, this.selHetongshangchuan.Value);
            foreach (var item in this.RepClientList.DataSource as IEnumerable<OA_CorporateClients>)
            {
                item.LessOrderMoneyProperty = item.Contractmoney-item.OrderMoney;
                var ssss = bll_eC_OrderBasicDAL.GetOrderById(item.Keyid, -1, CurrentUser.MemberId);
                item.NoOverOderCount = ssss.Count;
                if (ssss.Count > 0)
                {
                    string ids = "";
 
                    foreach(var c_OrderBasic in ssss)
                    {
                        ids += c_OrderBasic.Keyid + ",";
                    }
                    ids = ids.Trim(',');
                    var eC_OrderBasics = bll_eC_OrderBasicDAL.GetOrderByIds(ids);
 
 
                    item.Weishoukuanjine = eC_OrderBasics.Sum(x => x.UnPayedMoney);
 
 
                    var sssssss = item.Paytime;
                    var Paydays = item.Paydays.HasValue? item.Paydays.Value:0;
                    var Shifouwanjie = item.Shifouwanjie.HasValue ? item.Shifouwanjie.Value : 2;
                    item.Yuqijine = 0;
                    foreach (var eC_OrderBasic in eC_OrderBasics)
                    {
                        //判断订单是否逾期
                        var yuqi = false;
                        var ssdfsdf = eC_OrderBasic.CreateTime.Value.Date;
 
                        if(sssssss == 1)
                        {
                            // 步骤1:获取当前时间的“本月第一天”
                            DateTime currentMonthFirstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
 
                           if(ssdfsdf < currentMonthFirstDay)
                            {
                                yuqi = true;
                            }
                        }
                        else if (sssssss == 2)
                        {
                            // 步骤1:提取日期的年份和月份(忽略时分秒)
                            int year = DateTime.Now.Year;
                            int month = DateTime.Now.Month;
 
                            // 步骤2:计算当前月份所属季度的起始月份(核心公式)
                            // 逻辑:(月份-1)/3 得到季度索引(0=Q1,1=Q2,2=Q3,3=Q4),再×3+1得到起始月
                            int quarterStartMonth = ((month - 1) / 3) * 3 + 1;
 
                            // 步骤3:组合成本季度第一天(仅日期,时分秒为00:00:00)
                            DateTime quarterFirstDay = new DateTime(year, quarterStartMonth, 1);
                            if (ssdfsdf < quarterFirstDay)
                            {
                                yuqi = true;
                            }
                        }
                        else if (sssssss == 3)
                        {
                            // 步骤1:提取日期的年份和月份(忽略时分秒)
                            int year = DateTime.Now.Year;
                            int month = DateTime.Now.Month;
 
                            // 判断所属半年,确定起始月份
                            int halfYearStartMonth = month <= 6 ? 1 : 7;
 
                            // 组合成本半年第一天(时分秒默认00:00:00)
                            DateTime halfYearFirstDay = new DateTime(year, halfYearStartMonth, 1);
                            if (ssdfsdf < halfYearFirstDay)
                            {
                                yuqi = true;
                            }
                        }
                        else if (sssssss == 4)
                        {
                            // 步骤1:提取日期的年份和月份(忽略时分秒)
                            int year = DateTime.Now.Year;
                            int month = DateTime.Now.Month;
 
                            // 核心逻辑:提取年份,直接构造1月1日
                            DateTime yearFirstDay = new DateTime(year, 1, 1);
 
                            if (ssdfsdf < yearFirstDay)
                            {
                                yuqi = true;
                            }
                        }
                        else if (sssssss == 5)
                        {
                            // 步骤1:提取日期的年份和月份(忽略时分秒)
                            int year = DateTime.Now.Year;
                            int month = DateTime.Now.Month;
 
                            DateTime semesterFirstDay;
                            if (month >= 3 && month <= 8)
                            {
                                // 3-8月:当年第一学期,首日=当年3月1日
                                semesterFirstDay = new DateTime(year, 3, 1);
                            }
                            else if (month >= 9 && month <= 12)
                            {
                                // 9-12月:当年第二学期,首日=当年9月1日
                                semesterFirstDay = new DateTime(year, 9, 1);
                            }
                            else // 1-2月
                            {
                                // 1-2月:上一年第二学期,首日=上一年9月1日
                                semesterFirstDay = new DateTime(year - 1, 9, 1);
                            }
 
                            if (ssdfsdf < semesterFirstDay)
                            {
                                yuqi = true;
                            }
                        }
                        else if (sssssss == 6)
                        {
                            if (Shifouwanjie == 1)
                            {
                                yuqi = true;
                            }
                        }
                        else if (sssssss == 7)
                        {
                            // 第二步:计算时间差,取Days属性(已取整),绝对值保证结果为正
                            TimeSpan timeSpan = DateTime.Now.Date.Subtract(ssdfsdf);
 
                            var  sss = Math.Abs(timeSpan.Days);
 
                            if (sss > Paydays)
                            {
                                yuqi = true;
                            }
                        }
 
 
 
 
                        if (yuqi)
                        {
                            if (eC_OrderBasic.UnPayedMoney >= 0)
                            {
                                item.Yuqijine += eC_OrderBasic.UnPayedMoney;
                            }
                        }  
                    }
                }
                
 
                
 
                
 
                Database DC = new Database();
                try
                {
                  
                    string sqlStr = string.Format("select  count(*) from [dbo].[OA_CorporateClientContract] where CorporateClientsid='{0}'", item.Keyid);
                    SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection);
                    item.ContractCount = (int)myCmd.ExecuteScalar();
                }
                catch (Exception)
                {
 
                    item.ContractCount = 0;
                }
                finally
                {
                    if (DC.Connection.State != System.Data.ConnectionState.Closed)
                        DC.Connection.Close();
                }
                item.Yanse = "";
               
 
                //if (item.Keyid == item.MemberId)
                //{
                //    item.Yanse = "green";
                //}
                //有到期时间的,到期前3个月变成红色(像人事管理那样);
                if (item.Expiretype.HasValue && item.Expiretype == 1)
                {
                    if (item.ExpireTime.HasValue)
                    {
                        if (item.ExpireTime.Value < DateTime.Now.AddMonths(3))
                        {
                            item.Yanse = "red";
                        }
                    }
 
                }
               
                if (item.CreateTime.HasValue)
                {
                    //没有到期时间的,从建档时间起算,9个月后变成红色。
                    if (item.CreateTime.Value < DateTime.Now.AddMonths(-9))
                    {
                        item.Yanse = "red";
                    }
                    //建档后1个月没有下单,变成血红色。
                    if (item.CreateTime.Value < DateTime.Now.AddMonths(-1))
                    {
                        if (!item.OrderCount.HasValue || item.OrderCount.Value <= 0)
                        {
                            item.Yanse = "maroon";
                        }
                    }
 
 
 
                   
                }
 
            }
            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();
        }
 
        //绑定省
        protected void BindProvince()
        {
            this.selectProvince.Items.Clear();
            if (CurrentUser.TrueType == "员工")
                this.selectProvince.DataSource = bll_Sys_CitySiteBLL.SelectStaffManageProvinceList(CurrentUser.TrueMemberId);
            else
                this.selectProvince.DataSource = bll_Sys_CitySiteBLL.SelectAllNextModel(0, 0, 1);
 
            this.selectProvince.DataTextField = "Name";
            this.selectProvince.DataValueField = "Keyid";
            this.selectProvince.DataBind();
            this.selectProvince.Items.Insert(0, new ListItem("全部", ""));
            this.selectCity.Items.Insert(0, new ListItem("全部", ""));
            this.selectCounty.Items.Insert(0, new ListItem("全部", ""));
        }
 
        //改变省绑定市
        protected void ChangeProvince(object sender, EventArgs e)
        {
            this.selectCity.Items.Clear();
            this.selectCounty.Items.Clear();
            Sys_CitySite m_Sys_CitySite = bll_Sys_CitySiteBLL.GetModelByKeyid(this.selectProvince.SelectedValue.ToInt32()??0);
            if (m_Sys_CitySite != null)
            {
                if (CurrentUser.TrueType == "员工")
                    this.selectCity.DataSource = bll_Sys_CitySiteBLL.SelectStaffManageCityList(m_Sys_CitySite.Keyid, CurrentUser.TrueMemberId);
                else
                    this.selectCity.DataSource = bll_Sys_CitySiteBLL.SelectAllNextModel(m_Sys_CitySite.Keyid, 0, 2);
 
                this.selectCity.DataTextField = "Name";
                this.selectCity.DataValueField = "Keyid";
                this.selectCity.DataBind();
            }
            this.selectCity.Items.Insert(0, new ListItem("全部", ""));
            this.selectCounty.Items.Insert(0, new ListItem("全部", ""));
        }
 
        //改变市绑定区
        protected void ChangeCity(object sender, EventArgs e)
        {
            this.selectCounty.Items.Clear();
            Sys_CitySite m_Sys_CitySite = bll_Sys_CitySiteBLL.GetModelByKeyid(this.selectCity.SelectedValue.ToInt32() ?? 0);
            if (m_Sys_CitySite != null)
            {
                if (CurrentUser.TrueType == "员工")
                    this.selectCounty.DataSource = bll_Sys_CitySiteBLL.SelectStaffManageCountryList(m_Sys_CitySite.ProvinceId, m_Sys_CitySite.Keyid, CurrentUser.TrueMemberId);
                else
                    this.selectCounty.DataSource = bll_Sys_CitySiteBLL.SelectProxyNextModel(m_Sys_CitySite.ProvinceId, m_Sys_CitySite.Keyid, 3);
 
                this.selectCounty.DataTextField = "Name";
                this.selectCounty.DataValueField = "Keyid";
                this.selectCounty.DataBind();
            }
            this.selectCounty.Items.Insert(0, new ListItem("全部", ""));
        }
    }
}