using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Web.UI.WebControls; using System.Windows.Forms; using System.Globalization; using LYFZ.ComponentLibrary; using System.Collections; namespace LYFZ.Software.MainBusiness.Customers { public partial class FrmOrdersCustomer : LYFZ.Software.UI.Customers.FrmOrdersCustomer { List Versions = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessTypeList(); LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder(); private delegate void UpdateControl(); public FrmOrdersCustomer() { this.ucOld.EventPaging += ucOld_EventPaging; this.dgvData.CellDoubleClick += dgvData_CellDoubleClick; this.dgvData.RowsAdded += dgvData_RowsAdded; this.btnConditionQuery.Click += btnConditionQuery_Click; foreach (Control chkBtn in flowLayoutPanel1.Controls) { chkBtn.Click += chkBtn_Click; } orbll.UpdateNullDataToLunar(); } Hashtable htData = new Hashtable(); /// /// 当前订单类型 /// string Ord_Type = ""; void chkBtn_Click(object sender, EventArgs e) { this.Ord_Type = ""; CheckBoxEx chkSender = (CheckBoxEx)sender; if (chkSender.Checked) { this.Ord_Type = chkSender.Tag.ToString(); } foreach (Control chkBtn in this.flowLayoutPanel1.Controls) { if (!chkBtn.Equals(sender)) { CheckBoxEx chkObj = (CheckBoxEx)chkBtn; chkObj.Checked = false; } } this.PublicFunctionRows(); } /// /// 窗体加载事件 /// /// /// protected override void FrmOrdersCustomer_Shown(object sender, EventArgs e) { try { this.chkEt.Visible = false; this.chkXz.Visible = false; this.chkHs.Visible = false; for (int i = 0; i < this.Versions.Count; i++) { LYFZ.Software.MainBusiness.EnumPermissions.BusinessType Version = this.Versions[i]; if (Version.ToString() == EnumPermissions.BusinessType.写真版.ToString()) { this.chkXz.Visible = true; } if (Version.ToString() == EnumPermissions.BusinessType.婚纱版.ToString()) { this.chkHs.Visible = true; } if (Version.ToString() == EnumPermissions.BusinessType.儿童版.ToString()) { this.chkEt.Visible = true; } } this.PublicFunctionRows(); this.btnUpdate.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OrdersCustomerCompetence, CustomAttributes.OperatingAuthority.Update); this.btnExport.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OrdersCustomerCompetence, CustomAttributes.OperatingAuthority.DataExport); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 获取订单客户表 /// public void PublicFunctionRows() { this.ucOld.PageCurrent = 1; this.ucOld.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数 this.ucOld.Bind(); } /// /// 查询 /// /// /// protected override void btnSlect_Click(object sender, EventArgs e) { try { PublicFunctionRows(); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 条件查询 /// /// /// void btnConditionQuery_Click(object sender, EventArgs e) { LYFZ.Software.MainBusiness.Customers.SetSmallForm.ConditionQuerySamllForm frm = new SetSmallForm.ConditionQuerySamllForm(); frm.StrLoadType = this.Ord_Type; frm.ShowDialog(); if (frm.IsSaveed) { htData = frm.htData; this.PublicFunctionRows(); } } /// /// 关闭 /// /// /// protected override void btnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 导出 /// /// /// protected override void btnExport_Click(object sender, EventArgs e) { try { this.dgvData.ExportDataTable(); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } /// /// 查看订单记录数据 /// /// /// void dgvData_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { this.btnUpdate_Click(this, null); } } /// /// 更新 /// /// /// protected override void btnUpdate_Click(object sender, EventArgs e) { if (this.dgvData.SelectedRows.Count == 0) { MessageBoxCustom.Show("请选择你要修改的客户!"); return; } if (this.dgvData.Rows.Count > 0) { if (this.dgvData.CurrentRow != null) { if (this.dgvData.CurrentRow.Index >= 0 && this.dgvData.CurrentCell.RowIndex >= 0) { if (!LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OrdersCustomerCompetence, CustomAttributes.OperatingAuthority.Update)) { return; } if (this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString().Trim() == "婚纱订单" || this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString().Trim() == "写真订单" || this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString().Trim() == "服务订单" || this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString().Trim() == "写真订单") { FrmOldCustomerRecord from_HS = new FrmOldCustomerRecord(); from_HS.Theorderno = this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["Ord_Number"].Value.ToString(); from_HS.Owner = this; from_HS.ShowDialog(); if (from_HS.IsSaved) { this.PublicFunctionRows(); } return; } else if (this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["订单类型"].Value.ToString() == "儿童订单") { FrmOldCustomerRecordBaby from_Et = new FrmOldCustomerRecordBaby(); from_Et.Theorderno = this.dgvData.Rows[this.dgvData.CurrentRow.Index].Cells["Ord_Number"].Value.ToString(); from_Et.Owner = this; from_Et.ShowDialog(); if (from_Et.IsSaved) { this.PublicFunctionRows(); } } } } } } /// /// 列表添加行时发生事件 /// /// /// void dgvData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { /* if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["客户类型"].Value.ToString().Trim())) { this.dgvData.Rows[e.RowIndex].Cells["客户类型"].Value = GroupType(this.dgvData.Rows[e.RowIndex].Cells["客户类型"].Value.ToString().Trim()); } if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["婚期"].Value.ToString().Trim())) { this.dgvData.Rows[e.RowIndex].Cells["婚期"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells["婚期"].Value, "yyyy-MM-dd"); } if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["生日"].Value.ToString().Trim())) { this.dgvData.Rows[e.RowIndex].Cells["生日"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells["生日"].Value, "yyyy-MM-dd"); } if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["订单时间"].Value.ToString().Trim())) { this.dgvData.Rows[e.RowIndex].Cells["订单时间"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells["订单时间"].Value, "yyyy-MM-dd HH:mm"); } */ } /// /// 画分页 /// /// /// private int ucOld_EventPaging(UCPager.EventPagingArg e) { this.dgvData.Rows.Clear(); DataTable dt = new DataTable(); StringBuilder str = new StringBuilder(); str.Append(" 1=1 and GP_GroupType=0 "); if (this.Ord_Type.Trim().Length > 0) { str.Append(" and Ord_Type='" + Ord_Type.Trim() + "' "); } if (htData.Count > 0) { if (htData.ContainsKey("ClientRegion") && htData["ClientRegion"].ToString().Trim().Length > 0) { str.Append(" and Cus_Region like '%" + htData["ClientRegion"].ToString().Trim() + "%' "); } if (htData.ContainsKey("AgesStart") && htData["AgesStart"].ToString().Trim().Length > 0 && htData.ContainsKey("AgesEnd") && htData["AgesEnd"].ToString().Trim().Length > 0) { if (htData["AgesType"].ToString().Trim() == "Order") { if (htData["OrderAges"].ToString().Trim() == "岁") { str.Append(" and (DATEDIFF(year, GregorianCalendar_Birthday, Ord_CreateDateTime) between '" + htData["AgesStart"].ToString().Trim() + "' And '" + htData["AgesEnd"].ToString().Trim() + "')"); } else if (htData["OrderAges"].ToString().Trim() == "天") { str.Append(" and (DATEDIFF(day, GregorianCalendar_Birthday, Ord_CreateDateTime) between '" + htData["AgesStart"].ToString().Trim() + "' And '" + htData["AgesEnd"].ToString().Trim() + "')"); } } else if (htData["AgesType"].ToString().Trim() == "Grow") { str.Append(" and (" + htData["GrowAges"].ToString().Trim() + " between '" + htData["AgesStart"].ToString().Trim() + "' And '" + htData["AgesEnd"].ToString().Trim() + "')"); } } else if (htData.ContainsKey("AgesStart") && !htData.ContainsKey("AgesEnd")) { if (htData["AgesType"].ToString().Trim() == "Order") { if (htData["OrderAges"].ToString().Trim() == "岁") { str.Append(" and DATEDIFF(year, GregorianCalendar_Birthday, Ord_CreateDateTime) = '" + htData["AgesStart"].ToString().Trim() + "' "); } else if (htData["OrderAges"].ToString().Trim() == "天") { str.Append(" and DATEDIFF(day, GregorianCalendar_Birthday, Ord_CreateDateTime) = '" + htData["AgesStart"].ToString().Trim() + "' "); } } else if (htData["AgesType"].ToString().Trim() == "Grow") { str.Append(" and " + htData["GrowAges"].ToString().Trim() + " = '" + htData["AgesStart"].ToString().Trim() + "'"); } } else if (!htData.ContainsKey("AgesStart") && htData.ContainsKey("AgesEnd")) { if (htData["AgesType"].ToString().Trim() == "Order") { if (htData["OrderAges"].ToString().Trim() == "岁") { str.Append(" and DATEDIFF(year, GregorianCalendar_Birthday, Ord_CreateDateTime) = '" + htData["AgesEnd"].ToString().Trim() + "')"); } else if (htData["OrderAges"].ToString().Trim() == "天") { str.Append(" and DATEDIFF(day, GregorianCalendar_Birthday, Ord_CreateDateTime) = '" + htData["AgesEnd"].ToString().Trim() + "')"); } } else if (htData["AgesType"].ToString().Trim() == "Grow") { str.Append(" and " + htData["GrowAges"].ToString().Trim() + " = '" + htData["AgesEnd"].ToString().Trim() + "'"); } } } string keyword = this.txtContent.Text.Trim(); if (!string.IsNullOrEmpty(keyword)) { str.Append("and (Ord_Number like '%" + keyword + "%' or Cus_Name like '%" + keyword + "%' or Cus_Sex_cs like '%" + keyword + "%' or Cus_Telephone like '%" + keyword + "%' or Cus_Region like '%" + keyword + "%' ) "); } this.htData.Clear(); this.dgvData.DataColumns("Ord_Number,订单号,客户类型,客户名称,客户电话,性别,区域,婚期,生日,岁(订单),天(订单),岁(成长),天(成长),套系类别,套系名称,套系价格,消费总额,订单类型,订单时间,客户组ID", strHideField: "Ord_Number,客户组ID"); LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData(); string StrStatistics = ""; LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { pageData.TableName = "Vw_OrderCustomerList"; pageData.QueryCondition = str.ToString(); DataTable tbl = orbll.GetView_Custom(pageData.TableName, StrWhere: pageData.QueryCondition, ShowColumnName: "Count(ID) AS 总订单量,(sum(Ord_SeriesPrice)/Count(ID)) AS 套系平均值,(sum(OrderLateConsume)/Count(ID)) AS 后期消费平均值,(sum(yingFuPrice)/Count(ID)) AS 总消费平均值").Tables[0]; if (tbl.Rows.Count > 0) { StrStatistics = "总订单量:" + tbl.Rows[0]["总订单量"].ToString().Trim() + " 套系平均值:" + tbl.Rows[0]["套系平均值"].ToString().Trim() + " 后期消费平均值:" + tbl.Rows[0]["后期消费平均值"].ToString().Trim() + " 总消费平均值:" + tbl.Rows[0]["总消费平均值"].ToString().Trim() + ""; } else { StrStatistics = "总订单量:0 套系平均值:0 后期消费平均值:0 总消费平均值:0"; } pageData.PageIndex = this.ucOld.PageCurrent; pageData.PageSize = this.ucOld.PageSize; pageData.QueryFieldName = "Ord_Number"+ ", Ord_SinceOrderNumber"+ ", (case [GP_GroupType] when '0' then '订单客户' when '1' then '老客户' else '意向客户' end) as [GP_GroupType]" + ", Cus_Name"+ ", Cus_Telephone"+ ", Cus_Sex_cs"+ ", Cus_Region"+ ", convert(char(10),dbo.fn_CheckDateTime(Gregoriancalendar_DayForMarriage),120) as Gregoriancalendar_DayForMarriage" + ", convert(char(10),dbo.fn_CheckDateTime(GregorianCalendar_Birthday),120) as GregorianCalendar_Birthday" + ", OrderAgesYear"+ ", OrderAgesDay"+ ", Age_Year"+ ", Age_Day"+ ", Ord_PhotographyCategory"+ ", Ord_SeriesName"+ ", Ord_SeriesPrice"+ ", yingFuPrice"+ ", Ord_Type_CH"+ ", Ord_CreateDateTime"+ ",GM_CustomerGroupID"; pageData.OrderStr = "ID desc"; pageData.OrderType = 1; DataSet da = pageData.QueryDataTable(); dt = da.Tables[0]; if (dt.Rows.Count > 0) { this.Invoke(new UpdateControl(delegate() { this.dgvData.DataSource(dt, IsBindColumns: false); this.dgvData.ClearSelection(); })); } }); this.txtStatistics.Text = StrStatistics; try { this.ucOld.TbDataSource = dt; } catch { } this.dgvData.Columns["订单时间"].Width = 110; return pageData.TotalCount; } /// /// 客户类型 客户组类型 0 为其它客户/订单客户 1 为老客户 2 为意向客户 /// /// /// string GroupType(string Type) { string type = ""; switch (Type) { case "0": type = "订单客户"; break; case "1": type = "老客户"; break; case "2": type = "意向客户"; break; case null: break; } return type; } } }