using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Collections;
using LYFZ.ComponentLibrary;
namespace LYFZ.Software.MainBusiness.SMSManagement.ShortSmsMessage
{
public partial class FrmScreening : LYFZ.Software.UI.SMSManagement.ShortSmsMessage.FrmScreening
{
private delegate void UpdateControl();
public FrmScreening()
{
this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
this.IsCustomScrollBar = true;
this.Load += FrmScreening_Load;
this.btnSelcet.Click += btnSelcet_Click;
this.btnOk.Click += btnOk_Click;
this.Shown += FrmScreening_Shown;
this.btnHightSelect.Click += btnHightSelect_Click;
this.SQueryTableName = orderCustomerTableName;
this.rdoAll.Click += rdoAll_Click;
this.rdoMan.Click += rdoMan_Click;
this.rdoWoman.Click += rdoWoman_Click;
this.cmbCustomerType.SelectedIndexChanged += cmbCustomerType_SelectedIndexChanged;
this.cmbCustomerType.Click += cmbCustomerType_Click;
this.dgvCustomerList.Sorted += dgvCustomerList_Sorted;
this.tlsAllSelect.Click += tlsAllSelect_Click;
this.tlsFangSelect.Click += tlsFangSelect_Click;
this.tlsAddSelect.Click += tlsAddSelect_Click;
this.btnExport.Click += btnExport_Click;
if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.ShortSmsMessageCompetence, CustomAttributes.OperatingAuthority.DataExport))
{
this.btnExport.Enabled = true;
}
else
{
this.btnExport.Enabled = false;
}
CurrentBusinessType = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessType();
bindCmbCustomerType(this.cmbCustomerType);
}
///
/// 当前软件业务类型
///
LYFZ.Software.MainBusiness.EnumPermissions.BusinessType CurrentBusinessType = EnumPermissions.BusinessType.旗舰版;
public static void bindCmbCustomerType(ComponentLibrary.ComboBoxEx _cmbCustomerType)
{
List customerTypeList = new List();
customerTypeList.AddRange(Enum.GetNames(typeof(SQueryCustomerType)));
switch (LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetBusinessType())
{
case EnumPermissions.BusinessType.婚纱版:
customerTypeList.Remove(SQueryCustomerType.儿童客户.ToString());
break;
case EnumPermissions.BusinessType.儿童版:
customerTypeList.Remove(SQueryCustomerType.婚纱客户.ToString());
break;
}
_cmbCustomerType.DataSource = customerTypeList;
_cmbCustomerType.SelectedItem = SQueryCustomerType.全部.ToString();
}
void btnExport_Click(object sender, EventArgs e)
{
this.dgvCustomerList.ExportDataTable();
}
void tlsAddSelect_Click(object sender, EventArgs e)
{
if (this.dgvCustomerList.SelectedRows != null && this.dgvCustomerList.SelectedRows.Count > 0)
{
bool isNullTelephone = false;
this.SelectPhoneNumbers.Clear();
foreach (DataGridViewRow row in this.dgvCustomerList.SelectedRows)
{
if (row.Cells["Cus_Telephone"].Value.ToString().Length >= 11)
{
this.SelectPhoneNumbers.Add(new ItemValue(row.Cells["Cus_Telephone"].Value.ToString(), row.Cells["Cus_Name"].Value.ToString()));
}
else
{
isNullTelephone = true;
}
}
SelectPhoneNumbersMessageBox(isNullTelephone);
}
else {
MessageBoxCustom.Show("请选择客户");
}
}
void tlsFangSelect_Click(object sender, EventArgs e)
{
Unselected();
}
//反选
private void Unselected()
{
if (dgvCustomerList.Rows.Count > 0)
{
for (int i = 0; i < dgvCustomerList.Rows.Count; i++)
{
dgvCustomerList.Rows[i].Selected = !dgvCustomerList.Rows[i].Selected;
}
}
}
void tlsAllSelect_Click(object sender, EventArgs e)
{
this.dgvCustomerList.SelectAll();
}
void dgvCustomerList_Sorted(object sender, EventArgs e)
{
Bind();
}
void cmbCustomerType_Click(object sender, EventArgs e)
{
this.CurrentQueryObject = null;
}
void cmbCustomerType_SelectedIndexChanged(object sender, EventArgs e)
{
this.QCustomerType = (SQueryCustomerType)Enum.Parse(typeof(SQueryCustomerType), this.cmbCustomerType.Text);
this.plCurrentQuerySex.Visible = true;
SetSQueryWhereString();
}
void rdoWoman_Click(object sender, EventArgs e)
{
if (this.CurrentQuerySex.Trim() != "女")
{
this.CurrentQuerySex = "女";
this.SQueryTableName = this.personalCustomerTableName;
Bind();
}
}
void rdoMan_Click(object sender, EventArgs e)
{
if (this.CurrentQuerySex.Trim()!="男")
{
this.CurrentQuerySex = "男";
this.SQueryTableName = this.personalCustomerTableName;
Bind();
}
}
void rdoAll_Click(object sender, EventArgs e)
{
if (this.CurrentQuerySex.Trim().Length > 0)
{
this.CurrentQuerySex = "";
if (this.CurrentQueryObject != null)
{
this.SQueryTableName = this.CurrentQueryObject.SQueryTableName;
}
else {
this.SQueryTableName = this.orderCustomerTableName;
}
Bind();
}
}
string currentQuerySex = "";
///
/// 当前查询性别
///
public string CurrentQuerySex
{
get { return currentQuerySex; }
set { currentQuerySex = value; }
}
void btnOk_Click(object sender, EventArgs e)
{
GetAllPhoneNumbers();
}
void btnSelcet_Click(object sender, EventArgs e)
{
this.currentQueryObject = null;
SetSQueryWhereString();
Bind();
}
///
/// 设置查询条件
///
void SetSQueryWhereString()
{
string keyWords = this.txtKeyWords.Text.Trim();
if (keyWords.Length > 0)
{
this.SQueryWhereString = " Ord_Number like '%" + keyWords + "%' "
+ " or Cus_Name like '%" + keyWords + "%'"
+ " or Cus_Name_py like '%" + keyWords + "%'"
+ " or Cus_Telephone like '%" + keyWords + "%'"
+ " or Cus_Region like '%" + keyWords + "%'";
}
else {
this.SQueryWhereString = "1=1";
}
this.SQueryTableName = orderCustomerTableName;
}
void FrmScreening_Load(object sender, EventArgs e)
{
}
#region 加载
protected void FrmScreening_Shown(object sender, EventArgs e)
{
//绑定门店
BindStoreList(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.IsGroupEdition);
try
{
Bind();
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
public void Bind()
{
this.ucPagerEx1.PageCurrent = 1;
this.ucPagerEx1.Bind();
HideColumn();
}
LYFZ.Software.MainBusiness.SMSManagement.ShortSmsMessage.FrmHigehrSelect higeSelect = new FrmHigehrSelect();
#region 高级查询
SQueryObject currentQueryObject = null;
///
/// 当前查询对象
///
public SQueryObject CurrentQueryObject
{
get { return currentQueryObject; }
set { currentQueryObject = value; }
}
protected void btnHightSelect_Click(object sender, EventArgs e)
{
try
{
if (higeSelect.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.QCustomerType = higeSelect.CurrentQueryObject.QCustomerType;
this.cmbCustomerType.SelectedItem = this.QCustomerType.ToString();
this.SQueryTableName = higeSelect.CurrentQueryObject.SQueryTableName;
this.SQueryWhereString = higeSelect.CurrentQueryObject.SQueryWhereString;
this.CurrentQueryObject = higeSelect.CurrentQueryObject;
Bind();
}
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
#endregion
///
/// 按订单查询客户的表名
///
string orderCustomerTableName = "Vw_OrderCustomerList";
///
/// 按人查询客户的表名
///
string personalCustomerTableName = "Vw_PersonalCustomerList";
string _SQueryTableName = "";
///
/// 查询表名
///
public string SQueryTableName
{
get { return _SQueryTableName; }
set { _SQueryTableName = value; }
}
string _SQueryWhereString = "1=1";
///
/// 查询条件语句
///
public string SQueryWhereString
{
get { return _SQueryWhereString; }
set { _SQueryWhereString = value; }
}
SQueryCustomerType _QCustomerType = SQueryCustomerType.全部;
///
/// 查询的客户类型
///
public SQueryCustomerType QCustomerType
{
get { return _QCustomerType; }
set { _QCustomerType = value; }
}
List selectPhoneNumbers = new List();
///
///
///
public List SelectPhoneNumbers
{
get { return selectPhoneNumbers; }
set { selectPhoneNumbers = value; }
}
#region 画分页
///
/// 获取筛选的所有号码
///
void GetAllPhoneNumbers()
{
DataTable retTable = new DataTable();
if (this.ucPagerEx1.NMax <= LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ReportFormPageSize)
{
retTable = this.ucPagerEx1.TbDataSource;
}
else
{
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
DataSet da = LYFZ.Helper.SQLHelper.Query("select Cus_Name,Cus_Telephone from " + SQueryTableName + " where (len(Cus_Telephone)>10) and " + getWhereString()); //pageData.QueryDataTable();
retTable = da.Tables[0];
});
}
bool isNullTelephone = false;
this.SelectPhoneNumbers.Clear();
if (retTable.Rows.Count > 0)
{
#region
for (int i = 0; i < retTable.Rows.Count; i++)
{
if (retTable.Rows[i]["Cus_Telephone"].ToString().Length >= 11)
{
this.SelectPhoneNumbers.Add(new ItemValue(retTable.Rows[i]["Cus_Telephone"].ToString(), retTable.Rows[i]["Cus_Name"].ToString()));
}
else {
isNullTelephone = true;
}
}
#endregion
}
SelectPhoneNumbersMessageBox(isNullTelephone);
}
void SelectPhoneNumbersMessageBox(bool isNullTelephone)
{
if (this.SelectPhoneNumbers.Count > 0)
{
if (isNullTelephone)
{
MessageBoxCustom.Show("选择的客户中发现无效手机号已被自动忽略!");
}
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
else
{
MessageBoxCustom.Show("选择的客户中没有找到有效的手机号!");
}
}
string GetStoreWhere()
{
if (this.cbxStoreList.Items.Count > 0)
{
ItemValue itemStore = (ItemValue)this.cbxStoreList.SelectedItem;
if (itemStore.Value.ToString() != "0")
{
return String.Format("Ord_DividedShop='{0}' and ", itemStore.Value.ToString());
}
}
return "";
}
///
/// 获取条件语句
///
///
string getWhereString()
{
string retWherestr = SQueryWhereString;
if (this.CurrentQuerySex.Trim().Length > 0)
{
if (this.QCustomerType == SQueryCustomerType.全部)
{
retWherestr = "(" + SQueryWhereString + ") and ( Ord_Type<>1 or (Ord_Type=1 and GM_Relation<>'本人')) and Cus_Sex_cs='" + this.CurrentQuerySex.Trim() + "'";
}
else if (this.QCustomerType == SQueryCustomerType.儿童客户)
{
retWherestr = "(" + SQueryWhereString + ") and (Ord_Type=1 and GM_Relation<>'本人') and Cus_Sex_cs='" + this.CurrentQuerySex.Trim() + "'";
}
else {
retWherestr = "(" + SQueryWhereString + ") and Cus_Sex_cs='" + this.CurrentQuerySex.Trim() + "'";
}
}
if (!SQueryWhereString.ToLower().Contains("Ord_Type="))
{
switch (this.QCustomerType)
{
case SQueryCustomerType.婚纱客户:
retWherestr = "(" + retWherestr + ") and Ord_Type='0' ";
break;
case SQueryCustomerType.儿童客户:
retWherestr = "(" + retWherestr + ") and Ord_Type='1' ";
break;
case SQueryCustomerType.写真客户:
retWherestr = "(" + retWherestr + ") and (Ord_Type='2')";
break;
case SQueryCustomerType.其它客户:
retWherestr = "(" + retWherestr + ") and (Ord_Type='3')";
break;
}
}
return GetStoreWhere()+"("+retWherestr+")";
}
///
/// 画分页
///
///
///
private int ucPagerEx1_EventPaging(UCPager.EventPagingArg e)
{
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
pageData.TableName = SQueryTableName;
pageData.PageIndex = this.ucPagerEx1.PageCurrent;
pageData.PageSize = LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ReportFormPageSize;
this.ucPagerEx1.PageSize = pageData.PageSize;
pageData.QueryCondition = getWhereString();
pageData.QueryFieldName = "id"
+",Ord_Number"
+",Ord_Type"
+",Ord_Type_CH"
+",Cus_Name"
+",Cus_Telephone"
+",Cus_Sex_cs"
+",Cus_Region"
+",GregorianCalendar_Birthday"
+",Age_String"
+",Age_Day"
+",GregorianCalendar_DayForMarriage"
+",Ord_PhotographyCategory"
+",Ord_SeriesName"
+",Ord_SeriesPrice"
+",yingFuPrice"
+",Ord_OrderClass"
+",Ord_CustomerSource"
+",Ord_CreateDateTime";
pageData.OrderStr = " ID desc ";
LYFZ.ComponentLibrary.DataGridViewEx.SortedColumnModel sortModel
= this.dgvCustomerList.GetSortedColumnModel("Ord_CreateDateTime", ListSortDirection.Descending);
pageData.OrderStr = sortModel.OrderStr.TrimStart();
dgvCustomerList.Rows.Clear();
DataTable dt = null;
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
dt = pageData.QueryDataTable().Tables[0];
});
if (dt != null)
{
if (dt.Rows.Count > 0)
{
try
{
this.ucPagerEx1.TbDataSource = dt;
}
catch { }
#region
for (int i = 0; i < dt.Rows.Count; i++)
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(this.dgvCustomerList);
row.Cells[0].Value = dt.Rows[i]["Ord_Number"].ToString();
row.Cells[1].Value = dt.Rows[i]["Ord_Type_CH"].ToString();
row.Cells[2].Value = dt.Rows[i]["Cus_Name"].ToString();
row.Cells[3].Value = dt.Rows[i]["Cus_Telephone"].ToString();
row.Cells[4].Value = dt.Rows[i]["Cus_Sex_cs"].ToString();
row.Cells[5].Value = dt.Rows[i]["Cus_Region"].ToString();
DateTime birthday = LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime();
DateTime.TryParse(dt.Rows[i]["GregorianCalendar_Birthday"].ToString(), out birthday);
if (birthday > LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime())
{
row.Cells[6].Value = birthday.ToString("yyyy-MM-dd");
}
row.Cells[7].Value = dt.Rows[i]["Age_String"].ToString();
row.Cells[8].Value = dt.Rows[i]["Age_Day"].ToString();
DateTime dayForMarriage = LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime();
DateTime.TryParse(dt.Rows[i]["GregorianCalendar_DayForMarriage"].ToString(), out dayForMarriage);
if (dayForMarriage > LYFZ.WinAPI.CustomPublicMethod.GetNullDateTime())
{
row.Cells[9].Value = dayForMarriage.ToString("yyyy-MM-dd");
}
row.Cells[10].Value = dt.Rows[i]["Ord_PhotographyCategory"].ToString();
row.Cells[11].Value = dt.Rows[i]["Ord_SeriesName"].ToString();
row.Cells[12].Value = dt.Rows[i]["Ord_SeriesPrice"].ToString();
row.Cells[13].Value = dt.Rows[i]["yingFuPrice"].ToString();
row.Cells[14].Value = dt.Rows[i]["Ord_OrderClass"].ToString();
row.Cells[15].Value = dt.Rows[i]["Ord_CustomerSource"].ToString();
row.Cells[16].Value = dt.Rows[i]["Ord_CreateDateTime"].ToString();
this.dgvCustomerList.Rows.Add(row);
}
#endregion
}
}
return pageData.TotalCount;
}
///
/// 邦定门店
///
void BindStoreList(bool isGroupEdition)
{
DataRowCollection rows = null;
int allValue = 0;
if (isGroupEdition)
{
this.cbxStoreList.Show();
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
{
rows = LYFZ.DAL.DAL_ErpCompanyInfo.GetCompanyBasicInfoList(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.SDomainName.Trim());
});
if (rows == null)
{
MessageBoxCustom.Show("获取门店信息失败!");
return;
}
else
{
if (rows.Count > 1)
{
ItemValue itemAll = new ItemValue(allValue, "全部");
this.cbxStoreList.Items.Add(itemAll);
this.cbxStoreList.SelectedIndex = 0;
}
//是否找到当前店
bool isCurrentStore = false;
foreach (DataRow row in rows)
{
ItemValue itemStore = new ItemValue(row["Company_DividedShop"].ToString(), row["Company_Name"].ToString());
itemStore.Tag = row;
this.cbxStoreList.Items.Add(itemStore);
if (row["Company_JMGDomain"].ToString().Trim().ToLower() == LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.SDomainName.Trim().ToLower())
{
isCurrentStore = true;
this.cbxStoreList.SelectedItem = itemStore;
}
}
if (!isCurrentStore)
{
MessageBoxCustom.Show("没有找到当前门店信息");
this.cbxStoreList.Items.Clear();
return;
}
}
}
else
{
ItemValue itemAll = new ItemValue(allValue, "全部");
this.cbxStoreList.Items.Add(itemAll);
this.cbxStoreList.SelectedIndex = 0;
this.cbxStoreList.Hide();
}
}
///
/// 隐藏列
///
void HideColumn()
{
switch (this.QCustomerType)
{
case SQueryCustomerType.婚纱客户:
if (this.SQueryTableName.ToLower() == this.orderCustomerTableName.ToLower())
{
SetHideColumn("GregorianCalendar_Birthday,Age_String,Age_Day");
}
else {
SetHideColumn("Age_Day,GregorianCalendar_DayForMarriage");
}
break;
case SQueryCustomerType.儿童客户:
SetHideColumn("GregorianCalendar_DayForMarriage");
break;
case SQueryCustomerType.全部:
SetHideColumn("GregorianCalendar_Birthday,Age_String,Age_Day,GregorianCalendar_DayForMarriage");
break;
default:
SetHideColumn("Age_Day,GregorianCalendar_DayForMarriage");
break;
}
}
void SetHideColumn(string hideCloumnList)
{
foreach (DataGridViewColumn column in this.dgvCustomerList.Columns)
{
if (hideCloumnList.ToLower().Contains(column.Name.ToLower()))
{
column.Visible = false;
}
else {
column.Visible = true;
}
}
}
#endregion
}
}