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) { 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("全部", "")); } } }